Fix vehicle production; Basic 5-to-a-cell logic. cnc only. Infantry stack; need to give a graphical offset.

This commit is contained in:
Paul Chote
2010-06-23 20:23:47 +12:00
parent b7c8e55d14
commit b42589b479
7 changed files with 74 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -240,6 +240,7 @@
<Compile Include="GameRules\MusicInfo.cs" /> <Compile Include="GameRules\MusicInfo.cs" />
<Compile Include="Widgets\PowerBinWidget.cs" /> <Compile Include="Widgets\PowerBinWidget.cs" />
<Compile Include="Widgets\ImageWidget.cs" /> <Compile Include="Widgets\ImageWidget.cs" />
<Compile Include="Traits\SharesCell.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
@@ -275,4 +276,7 @@
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
<ItemGroup>
<Folder Include="Traits\" />
</ItemGroup>
</Project> </Project>

View File

@@ -116,7 +116,7 @@ namespace OpenRA
continue; continue;
var mobile = self.traits.Get<Mobile>(); var mobile = self.traits.Get<Mobile>();
if (checkForBlocked && !mobile.CanEnterCell(newHere)) if (checkForBlocked && !mobile.CanEnterCell(newHere, ignoreBuilding))
continue; continue;
if (customBlock != null && customBlock(newHere)) if (customBlock != null && customBlock(newHere))

View File

@@ -168,7 +168,7 @@ namespace OpenRA.Traits.Activities
{ {
if( path.Count == 0 ) return null; if( path.Count == 0 ) return null;
var nextCell = path[ path.Count - 1 ]; var nextCell = path[ path.Count - 1 ];
if( !mobile.CanEnterCell( nextCell ) ) if( !mobile.CanEnterCell( nextCell, ignoreBuilding ) )
{ {
if( ( mobile.toCell - destination.Value ).LengthSquared <= nearEnough ) if( ( mobile.toCell - destination.Value ).LengthSquared <= nearEnough )
{ {
@@ -244,7 +244,6 @@ namespace OpenRA.Traits.Activities
var frac = (float)moveFraction / moveFractionTotal; var frac = (float)moveFraction / moveFractionTotal;
self.CenterLocation = float2.Lerp( from, to, frac ); self.CenterLocation = float2.Lerp( from, to, frac );
// + self.traits.WithInterface<IOffsetCenterLocation>().Aggregate(float2.Zero, (a, x) => a + x.CenterOffset);
if( moveFraction >= moveFractionTotal ) if( moveFraction >= moveFractionTotal )
unit.Facing = toFacing & 0xFF; unit.Facing = toFacing & 0xFF;

View File

@@ -121,12 +121,28 @@ namespace OpenRA.Traits
public bool CanEnterCell(int2 p) public bool CanEnterCell(int2 p)
{ {
if (!self.World.WorldActor.traits.Get<BuildingInfluence>().CanMoveHere(p)) return false; return CanEnterCell(p, null);
}
public bool CanEnterCell(int2 p, Actor ignoreBuilding)
{
if (!self.World.WorldActor.traits.Get<BuildingInfluence>().CanMoveHere(p, ignoreBuilding)) return false;
if (self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(p).Any( var canShare = self.traits.Contains<SharesCell>();
a => a != self && !self.World.IsActorCrushableByActor(a, self))) var actors = self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(p);
var nonshareable = actors.Where(a => a != self && !(canShare && a.traits.Contains<SharesCell>()));
var shareable = actors.Where(a => a != self && canShare && a.traits.Contains<SharesCell>());
// only allow 5 in a cell
if (shareable.Count() >= 5)
return false; return false;
// We can enter a cell with nonshareable units if we can crush all of them
if (nonshareable.Any(
a => !self.World.IsActorCrushableByActor(a, self)))
return false;
return self.World.Map.IsInMap(p.X, p.Y) && return self.World.Map.IsInMap(p.X, p.Y) &&
Rules.TerrainTypes[self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[p.X, p.Y])] Rules.TerrainTypes[self.World.TileSet.GetTerrainType(self.World.Map.MapTiles[p.X, p.Y])]
.GetCost(GetMovementType()) < float.PositiveInfinity; .GetCost(GetMovementType()) < float.PositiveInfinity;

View File

@@ -0,0 +1,46 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
namespace OpenRA.Traits
{
class SharesCellInfo : TraitInfo<SharesCell> {}
public class SharesCell : IOffsetCenterLocation
{
[Sync]
public int Position;
public float2 CenterOffset
{ get {
switch (Position)
{
case 1:
return new float2(-5f,-5f);
case 2:
return new float2(5f,-5f);
case 3:
return new float2(-5f,5f);
case 4:
return new float2(5f,5f);
default:
return new float2(-5f, -5f);
}
}}
}
}

View File

@@ -103,6 +103,7 @@ namespace OpenRA.Traits
IEnumerable<float2> GetCurrentPath(Actor self); IEnumerable<float2> GetCurrentPath(Actor self);
} }
public interface IOffsetCenterLocation { float2 CenterOffset { get; } }
public interface ICrushable public interface ICrushable
{ {
void OnCrush(Actor crusher); void OnCrush(Actor crusher);

View File

@@ -31,6 +31,7 @@
RevealsShroud: RevealsShroud:
GainsExperience: GainsExperience:
GivesExperience: GivesExperience:
SharesCell:
^Ship: ^Ship:
Category: Ship Category: Ship