This commit is contained in:
Chris Forbes
2010-01-11 22:26:14 +13:00
parent 9c520e07b1
commit e6e5275f05
10 changed files with 28 additions and 32 deletions

View File

@@ -26,10 +26,10 @@ namespace OpenRa.Game
public int Health; public int Health;
IActivity currentActivity; IActivity currentActivity;
public Actor( ActorInfo info, int2 location, Player owner ) public Actor( string name, int2 location, Player owner )
{ {
ActorID = Game.world.NextAID(); ActorID = Game.world.NextAID();
LegacyInfo = (LegacyUnitInfo)info; // temporary LegacyInfo = name != null ? Rules.UnitInfo[name.ToLowerInvariant()] : null; // temporary
Location = location; Location = location;
CenterLocation = Traits.Util.CenterOfCell(Location); CenterLocation = Traits.Util.CenterOfCell(Location);
Owner = owner; Owner = owner;
@@ -38,10 +38,7 @@ namespace OpenRa.Game
Health = LegacyInfo.Strength; /* todo: fix walls, etc so this is always true! */ Health = LegacyInfo.Strength; /* todo: fix walls, etc so this is always true! */
if( LegacyInfo.Traits == null ) Info = Rules.NewUnitInfo[name.ToLowerInvariant()];
throw new InvalidOperationException( "No Actor traits for {0}; add Traits= to units.ini for appropriate unit".F(LegacyInfo.Name) );
Info = Rules.NewUnitInfo[LegacyInfo.Name.ToLowerInvariant()];
foreach (var trait in Info.Traits.WithInterface<ITraitInfo>()) foreach (var trait in Info.Traits.WithInterface<ITraitInfo>())
traits.Add(trait.Create(this)); traits.Add(trait.Create(this));
@@ -66,12 +63,13 @@ namespace OpenRa.Game
} }
public float2 CenterLocation; public float2 CenterLocation;
public float2 SelectedSize float2 SelectedSize
{ {
get get // todo: inline into GetBounds
{ {
if (LegacyInfo != null && LegacyInfo.SelectionSize != null) var si = Info != null ? Info.Traits.GetOrDefault<SelectableInfo>() : null;
return new float2(LegacyInfo.SelectionSize[0], LegacyInfo.SelectionSize[1]); if (si != null && si.Bounds != null)
return new float2(si.Bounds[0], si.Bounds[1]);
var firstSprite = Render().FirstOrDefault(); var firstSprite = Render().FirstOrDefault();
if (firstSprite.Sprite == null) return float2.Zero; if (firstSprite.Sprite == null) return float2.Zero;
@@ -97,7 +95,7 @@ namespace OpenRa.Game
var loc = mi.Location + Game.viewport.Location; var loc = mi.Location + Game.viewport.Location;
var underCursor = Game.FindUnits(loc, loc).FirstOrDefault(); var underCursor = Game.FindUnits(loc, loc).FirstOrDefault();
if (underCursor != null && !underCursor.LegacyInfo.Selectable) if (underCursor != null && !underCursor.traits.Contains<Selectable>())
underCursor = null; underCursor = null;
return traits.WithInterface<IIssueOrder>() return traits.WithInterface<IIssueOrder>()
@@ -107,10 +105,13 @@ namespace OpenRa.Game
public RectangleF GetBounds(bool useAltitude) public RectangleF GetBounds(bool useAltitude)
{ {
var si = Info != null ? Info.Traits.GetOrDefault<SelectableInfo>() : null;
var size = SelectedSize; var size = SelectedSize;
var loc = CenterLocation - 0.5f * size; var loc = CenterLocation - 0.5f * size;
if (LegacyInfo != null && LegacyInfo.SelectionSize != null && LegacyInfo.SelectionSize.Length > 2)
loc += new float2(LegacyInfo.SelectionSize[2], LegacyInfo.SelectionSize[3]); if (si != null && si.Bounds != null && si.Bounds.Length > 2)
loc += new float2(si.Bounds[2], si.Bounds[3]);
if (useAltitude) if (useAltitude)
{ {

View File

@@ -78,8 +78,8 @@ namespace OpenRa.Game
} }
var worldActor = new Actor(null, new int2(int.MaxValue, int.MaxValue), null); var worldActor = new Actor(null, new int2(int.MaxValue, int.MaxValue), null);
worldActor.traits.Add(new Traits.WaterPaletteRotation(worldActor)); worldActor.traits.Add(new WaterPaletteRotation(worldActor));
worldActor.traits.Add(new Traits.ChronoshiftPaletteEffect(worldActor)); worldActor.traits.Add(new ChronoshiftPaletteEffect(worldActor));
Game.world.Add(worldActor); Game.world.Add(worldActor);
Rules.Map.InitOreDensity(); Rules.Map.InitOreDensity();
@@ -95,9 +95,7 @@ namespace OpenRa.Game
skipMakeAnims = true; skipMakeAnims = true;
foreach (var treeReference in Rules.Map.Trees) foreach (var treeReference in Rules.Map.Trees)
world.Add(new Actor(Rules.UnitInfo[treeReference.Image], world.Add(new Actor(treeReference.Image, new int2(treeReference.Location), null));
new int2(treeReference.Location),
null));
LoadMapActors(Rules.AllRules); LoadMapActors(Rules.AllRules);
skipMakeAnims = false; skipMakeAnims = false;
@@ -148,7 +146,7 @@ namespace OpenRa.Game
//num=owner,type,health,location,facing,... //num=owner,type,health,location,facing,...
var parts = s.Value.Split( ',' ); var parts = s.Value.Split( ',' );
var loc = int.Parse(parts[3]); var loc = int.Parse(parts[3]);
world.Add(new Actor(Rules.UnitInfo[parts[1].ToLowerInvariant()], new int2(loc % 128, loc / 128), world.Add(new Actor(parts[1].ToLowerInvariant(), new int2(loc % 128, loc / 128),
players.Values.FirstOrDefault(p => p.InternalName == parts[0]) ?? players[0])); players.Values.FirstOrDefault(p => p.InternalName == parts[0]) ?? players[0]));
} }
} }

View File

@@ -220,7 +220,7 @@ namespace OpenRa.Game.Graphics
spriteRenderer.DrawSprite(pipImages.Image, pipxyBase + pipxyOffset, PaletteType.Chrome); spriteRenderer.DrawSprite(pipImages.Image, pipxyBase + pipxyOffset, PaletteType.Chrome);
pipxyOffset += new float2(4, 0); pipxyOffset += new float2(4, 0);
if (pipxyOffset.X+5 > selectedUnit.SelectedSize.X) if (pipxyOffset.X+5 > selectedUnit.GetBounds(false).Width)
{ {
pipxyOffset.X = 0; pipxyOffset.X = 0;
pipxyOffset.Y -= 4; pipxyOffset.Y -= 4;

View File

@@ -15,22 +15,19 @@ namespace OpenRa.Game.Orders
{ {
Game.world.AddFrameEndTask( _ => Game.world.AddFrameEndTask( _ =>
{ {
var queue = order.Player.PlayerActor.traits.Get<Traits.ProductionQueue>(); var queue = order.Player.PlayerActor.traits.Get<ProductionQueue>();
var building = (LegacyBuildingInfo)Rules.UnitInfo[ order.TargetString ];
var producing = queue.CurrentItem(Rules.UnitCategory[order.TargetString]); var producing = queue.CurrentItem(Rules.UnitCategory[order.TargetString]);
if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 ) if( producing == null || producing.Item != order.TargetString || producing.RemainingTime != 0 )
return; return;
Log.Write( "Player \"{0}\" builds {1}", order.Player.PlayerName, building.Name ); Game.world.Add( new Actor( order.TargetString, order.TargetLocation - Footprint.AdjustForBuildingSize( (LegacyBuildingInfo)Rules.UnitInfo[ order.TargetString ] ), order.Player ) );
Game.world.Add( new Actor( building, order.TargetLocation - GameRules.Footprint.AdjustForBuildingSize( building ), order.Player ) );
if (order.Player == Game.LocalPlayer) if (order.Player == Game.LocalPlayer)
{ {
Sound.Play("placbldg.aud"); Sound.Play("placbldg.aud");
Sound.Play("build5.aud"); Sound.Play("build5.aud");
} }
queue.FinishProduction(Rules.UnitCategory[building.Name]); queue.FinishProduction(Rules.UnitCategory[order.TargetString]);
} ); } );
break; break;
} }

View File

@@ -14,7 +14,7 @@ namespace OpenRa.Game.Traits
Game.world.AddFrameEndTask( Game.world.AddFrameEndTask(
w => w =>
{ /* create the free harvester! */ { /* create the free harvester! */
var harvester = new Actor(Rules.UnitInfo["harv"], self.Location + new int2(1, 2), self.Owner); var harvester = new Actor("harv", self.Location + new int2(1, 2), self.Owner);
var unit = harvester.traits.Get<Unit>(); var unit = harvester.traits.Get<Unit>();
var mobile = harvester.traits.Get<Mobile>(); var mobile = harvester.traits.Get<Mobile>();
unit.Facing = 64; unit.Facing = 64;

View File

@@ -17,7 +17,7 @@ namespace OpenRa.Game.Traits.Activities
Sound.Play("placbldg.aud"); Sound.Play("placbldg.aud");
Sound.Play("build5.aud"); Sound.Play("build5.aud");
} }
Game.world.Add( new Actor( Rules.UnitInfo["fact"], self.Location - new int2( 1, 1 ), self.Owner ) ); Game.world.Add( new Actor( "fact", self.Location - new int2( 1, 1 ), self.Owner ) );
} ); } );
return this; return this;
} }

View File

@@ -14,7 +14,7 @@ namespace OpenRa.Game.Traits.Activities
ns.Sold(self); ns.Sold(self);
w.Remove(self); w.Remove(self);
var mcv = new Actor(Rules.UnitInfo["MCV"], self.Location + new int2(1, 1), self.Owner); var mcv = new Actor("mcv", self.Location + new int2(1, 1), self.Owner);
mcv.traits.Get<Unit>().Facing = 96; mcv.traits.Get<Unit>().Facing = 96;
w.Add(mcv); w.Add(mcv);
} }

View File

@@ -48,7 +48,7 @@ namespace OpenRa.Game.Traits
return inRange return inRange
.Where(a => a.Owner == self.Owner && a != self) /* todo: one day deal with friendly players */ .Where(a => a.Owner == self.Owner && a != self) /* todo: one day deal with friendly players */
.Where(a => Combat.HasAnyValidWeapons(self, a)) .Where(a => Combat.HasAnyValidWeapons(self, a))
.Where(a => a.Health < a.LegacyInfo.Strength) .Where(a => a.Health < a.Info.Traits.WithInterface<OwnedActorInfo>().First().HP)
.OrderBy(a => (a.Location - self.Location).LengthSquared) .OrderBy(a => (a.Location - self.Location).LengthSquared)
.FirstOrDefault(); .FirstOrDefault();
} }

View File

@@ -33,7 +33,7 @@ namespace OpenRa.Game.Traits
// todo: delay a bit? (req making deploy-mine an activity) // todo: delay a bit? (req making deploy-mine an activity)
Game.world.AddFrameEndTask( Game.world.AddFrameEndTask(
w => w.Add(new Actor(Rules.UnitInfo[self.LegacyInfo.Primary], self.Location, self.Owner))); w => w.Add(new Actor(self.LegacyInfo.Primary, self.Location, self.Owner)));
} }
} }
} }

View File

@@ -35,7 +35,7 @@ namespace OpenRa.Game.Traits
if( location == null || Game.UnitInfluence.GetUnitsAt( location.Value ).Any() ) if( location == null || Game.UnitInfluence.GetUnitsAt( location.Value ).Any() )
return false; return false;
var newUnit = new Actor( producee, location.Value, self.Owner ); var newUnit = new Actor( producee.Name, location.Value, self.Owner );
newUnit.traits.Get<Unit>().Facing = CreationFacing( self, newUnit ); ; newUnit.traits.Get<Unit>().Facing = CreationFacing( self, newUnit ); ;
var rp = self.traits.GetOrDefault<RallyPoint>(); var rp = self.traits.GetOrDefault<RallyPoint>();