From 578d42614b87d38e1da6920558f1271509a16079 Mon Sep 17 00:00:00 2001 From: alzeih Date: Mon, 2 Aug 2010 01:28:07 +1200 Subject: [PATCH] Convert all CreateActor calls to use TypeDictionary --- OpenRA.Game/Player.cs | 4 ++-- OpenRA.Game/Traits/Mobile.cs | 4 +++- OpenRA.Game/Traits/Player/PlaceBuilding.cs | 14 +++++++++++-- OpenRA.Game/World.cs | 15 ------------- OpenRA.Mods.Cnc/ProductionAirdrop.cs | 14 +++++++++---- OpenRA.Mods.RA/Activities/LayMines.cs | 8 +++++-- OpenRA.Mods.RA/Activities/Transform.cs | 14 +++++++------ OpenRA.Mods.RA/BridgeLayer.cs | 8 ++++++- OpenRA.Mods.RA/Crate.cs | 4 +++- OpenRA.Mods.RA/CrateDrop.cs | 13 ++++++++---- OpenRA.Mods.RA/CrateSpawner.cs | 7 ++++++- OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs | 7 ++++++- OpenRA.Mods.RA/EmitInfantryOnSell.cs | 7 ++++++- OpenRA.Mods.RA/FreeActor.cs | 13 ++++++------ OpenRA.Mods.RA/ProducesHelicopters.cs | 10 ++++++--- OpenRA.Mods.RA/ReplaceWithActor.cs | 9 ++++++-- OpenRA.Mods.RA/SpawnDefaultUnits.cs | 6 +++++- .../SupportPowers/AirstrikePower.cs | 21 +++++++++++++------ .../SupportPowers/ParatroopersPower.cs | 9 +++++--- OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs | 7 ++++++- 20 files changed, 131 insertions(+), 63 deletions(-) diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index a09b9fff57..344500f687 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -44,7 +44,7 @@ namespace OpenRA World = world; Shroud = new ShroudRenderer(this, world.Map); - PlayerActor = world.CreateActor("Player", new int2(int.MaxValue, int.MaxValue), this); + PlayerActor = world.CreateActor("Player", new TypeDictionary{ new OwnerInit( this ) }); Index = index; Palette = "player"+index; @@ -64,7 +64,7 @@ namespace OpenRA World = world; Shroud = new ShroudRenderer(this, world.Map); - PlayerActor = world.CreateActor("Player", new int2(int.MaxValue, int.MaxValue), this); + PlayerActor = world.CreateActor("Player", new TypeDictionary{ new OwnerInit( this ) }); Index = client.Index; Palette = "player"+client.Index; diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index cf58134c27..f7456b0ae1 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -76,7 +76,9 @@ namespace OpenRA.Traits { this.self = init.self; this.Info = info; - this.__fromCell = this.__toCell = init.Get(); + if (init.Contains()) + this.__fromCell = this.__toCell = init.Get(); + this.Facing = init.Contains() ? init.Get() : info.InitialFacing; this.Altitude = init.Contains() ? init.Get() : 0; diff --git a/OpenRA.Game/Traits/Player/PlaceBuilding.cs b/OpenRA.Game/Traits/Player/PlaceBuilding.cs index 6d0ca7cae2..df12436cf1 100644 --- a/OpenRA.Game/Traits/Player/PlaceBuilding.cs +++ b/OpenRA.Game/Traits/Player/PlaceBuilding.cs @@ -11,6 +11,7 @@ using System.Linq; using OpenRA.Effects; using OpenRA.GameRules; +using OpenRA.FileFormats; namespace OpenRA.Traits { @@ -40,7 +41,12 @@ namespace OpenRA.Traits bool playSounds = true; foreach (var t in LineBuildUtils.GetLineBuildCells(w, order.TargetLocation, order.TargetString, buildingInfo)) { - var building = w.CreateActor(order.TargetString, t, order.Player); + var building = w.CreateActor(order.TargetString, new TypeDictionary + { + new LocationInit( t ), + new OwnerInit( order.Player ), + }); + if (playSounds) foreach (var s in buildingInfo.BuildSounds) Sound.PlayToPlayer(order.Player, s, building.CenterLocation); @@ -49,7 +55,11 @@ namespace OpenRA.Traits } else { - var building = w.CreateActor(order.TargetString, order.TargetLocation, order.Player); + var building = w.CreateActor(order.TargetString, new TypeDictionary + { + new LocationInit( order.TargetLocation ), + new OwnerInit( order.Player ), + }); foreach (var s in buildingInfo.BuildSounds) Sound.PlayToPlayer(order.Player, s, building.CenterLocation); } diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 733bc8e579..b875d586d7 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -125,21 +125,6 @@ namespace OpenRA Timer.Time( "----end World.ctor" ); } - public Actor CreateActor( string name, int2 location, Player owner ) - { - return CreateActor( true, name, location, owner ); - } - - public Actor CreateActor( bool addToWorld, string name, int2 location, Player owner ) - { - var initDict = new TypeDictionary - { - new LocationInit( location ), - new OwnerInit( owner ), - }; - return CreateActor( addToWorld, name, initDict ); - } - public Actor CreateActor( string name, TypeDictionary initDict ) { return CreateActor( true, name, initDict ); diff --git a/OpenRA.Mods.Cnc/ProductionAirdrop.cs b/OpenRA.Mods.Cnc/ProductionAirdrop.cs index 73dc254070..aedf1ceb6f 100644 --- a/OpenRA.Mods.Cnc/ProductionAirdrop.cs +++ b/OpenRA.Mods.Cnc/ProductionAirdrop.cs @@ -15,6 +15,7 @@ using OpenRA.Mods.RA; using OpenRA.Mods.RA.Activities; using OpenRA.Traits; using OpenRA.Traits.Activities; +using OpenRA.FileFormats; namespace OpenRA.Mods.Cnc { @@ -38,12 +39,17 @@ namespace OpenRA.Mods.Cnc var rp = self.traits.GetOrDefault(); owner.World.AddFrameEndTask(w => { - var a = w.CreateActor("C17", startPos, owner); + var a = w.CreateActor("C17", new TypeDictionary + { + new LocationInit( startPos ), + new OwnerInit( owner ), + new FacingInit( 64 ), + new AltitudeInit( Rules.Info["c17"].Traits.Get().CruiseAltitude ), + }); + var cargo = a.traits.Get(); - a.traits.Get().Facing = 64; - a.traits.Get().Altitude = a.Info.Traits.Get().CruiseAltitude; - var newUnit = self.World.CreateActor(false, producee.Name, new int2(0, 0), self.Owner); + var newUnit = self.World.CreateActor(false, producee.Name, new TypeDictionary{ new OwnerInit( self.Owner ) }); cargo.Load(a, newUnit); a.CancelActivity(); diff --git a/OpenRA.Mods.RA/Activities/LayMines.cs b/OpenRA.Mods.RA/Activities/LayMines.cs index 5670133e37..15489aa91d 100644 --- a/OpenRA.Mods.RA/Activities/LayMines.cs +++ b/OpenRA.Mods.RA/Activities/LayMines.cs @@ -11,6 +11,7 @@ using System.Linq; using OpenRA.Traits; using OpenRA.Traits.Activities; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA.Activities { @@ -73,8 +74,11 @@ namespace OpenRA.Mods.RA.Activities if (limitedAmmo != null) limitedAmmo.Attacking(self); self.World.AddFrameEndTask( - w => w.CreateActor( - self.Info.Traits.Get().Mine, self.Location, self.Owner)); + w => w.CreateActor(self.Info.Traits.Get().Mine, new TypeDictionary + { + new LocationInit( self.Location ), + new OwnerInit( self.Owner ), + })); } public void Cancel( Actor self ) { canceled = true; NextActivity = null; } diff --git a/OpenRA.Mods.RA/Activities/Transform.cs b/OpenRA.Mods.RA/Activities/Transform.cs index 8c4c0abb59..b4fada1bf7 100644 --- a/OpenRA.Mods.RA/Activities/Transform.cs +++ b/OpenRA.Mods.RA/Activities/Transform.cs @@ -13,6 +13,7 @@ using System.Linq; using System.Collections.Generic; using OpenRA.Traits; using OpenRA.Mods.RA.Render; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA.Activities { @@ -51,17 +52,18 @@ namespace OpenRA.Mods.RA.Activities self.World.Remove(self); foreach (var s in sounds) Sound.PlayToPlayer(self.Owner, s, self.CenterLocation); - - var a = w.CreateActor(actor, self.Location + offset, self.Owner); + + var a = w.CreateActor( actor, new TypeDictionary + { + new LocationInit( self.Location + offset ), + new OwnerInit( self.Owner ), + new FacingInit( facing ), + }); var oldHealth = self.traits.GetOrDefault(); var newHealth = a.traits.GetOrDefault(); if (oldHealth != null && newHealth != null) newHealth.HPFraction = oldHealth.HPFraction; - var ifacing = a.traits.GetOrDefault(); - if (ifacing != null) - ifacing.Facing = facing; - if (selected) w.Selection.Add(w, a); }); diff --git a/OpenRA.Mods.RA/BridgeLayer.cs b/OpenRA.Mods.RA/BridgeLayer.cs index 980ebe5267..ec1484f9dc 100644 --- a/OpenRA.Mods.RA/BridgeLayer.cs +++ b/OpenRA.Mods.RA/BridgeLayer.cs @@ -11,6 +11,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Traits; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA { @@ -80,7 +81,12 @@ namespace OpenRA.Mods.RA var nj = j - image / template.Size.X; // Create a new actor for this bridge and keep track of which subtiles this bridge includes - var bridge = w.CreateActor(BridgeTypes[tile], new int2(ni, nj), w.WorldActor.Owner).traits.Get(); + var bridge = w.CreateActor(BridgeTypes[tile], new TypeDictionary + { + new LocationInit( new int2(ni, nj) ), + new OwnerInit( w.WorldActor.Owner ), + }).traits.Get(); + Dictionary subTiles = new Dictionary(); // For each subtile in the template diff --git a/OpenRA.Mods.RA/Crate.cs b/OpenRA.Mods.RA/Crate.cs index ec9bc351a5..6fb2a660ef 100644 --- a/OpenRA.Mods.RA/Crate.cs +++ b/OpenRA.Mods.RA/Crate.cs @@ -49,7 +49,9 @@ namespace OpenRA.Mods.RA public Crate(ActorInitializer init, CrateInfo info) { this.self = init.self; - this.Location = init.Get(); + if (init.Contains()) + this.Location = init.Get(); + this.Info = info; self.World.WorldActor.traits.Get().Add(self, this); diff --git a/OpenRA.Mods.RA/CrateDrop.cs b/OpenRA.Mods.RA/CrateDrop.cs index cd855741aa..f85ff5cd54 100644 --- a/OpenRA.Mods.RA/CrateDrop.cs +++ b/OpenRA.Mods.RA/CrateDrop.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Mods.RA.Activities; using OpenRA.Traits; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA { @@ -67,13 +68,17 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask(w => { - var crate = w.CreateActor(false, "crate", new int2(0, 0), w.WorldActor.Owner); + var crate = w.CreateActor(false, "crate", new TypeDictionary { new OwnerInit(w.WorldActor.Owner) }); crates.Add(crate); var startPos = w.ChooseRandomEdgeCell(); - var plane = w.CreateActor("BADR", startPos, w.WorldActor.Owner); - var aircraft = plane.traits.Get(); - aircraft.Facing = Util.GetFacing(p - startPos, 0); + var plane = w.CreateActor("badr", new TypeDictionary + { + new LocationInit( startPos ), + new OwnerInit( w.WorldActor.Owner), + new FacingInit( Util.GetFacing(p - startPos, 0) ), + new AltitudeInit( Rules.Info["badr"].Traits.Get().CruiseAltitude ), + }); plane.CancelActivity(); plane.QueueActivity(new FlyCircle(p)); plane.traits.Get().SetLZ(p, null); diff --git a/OpenRA.Mods.RA/CrateSpawner.cs b/OpenRA.Mods.RA/CrateSpawner.cs index c5dd0ab6f1..ec312a78e2 100644 --- a/OpenRA.Mods.RA/CrateSpawner.cs +++ b/OpenRA.Mods.RA/CrateSpawner.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.Linq; using OpenRA.Traits; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA { @@ -65,7 +66,11 @@ namespace OpenRA.Mods.RA if (self.World.WorldActor.traits.Get().GetUnitsAt(p).Any()) continue; self.World.AddFrameEndTask( - w => crates.Add(w.CreateActor("crate", p, self.World.WorldActor.Owner))); + w => crates.Add(w.CreateActor("crate", new TypeDictionary + { + new LocationInit( p ), + new OwnerInit( self.World.WorldActor.Owner ), + }))); return; } } diff --git a/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs b/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs index 053fc303a3..53bad5b965 100644 --- a/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs @@ -10,6 +10,7 @@ using System.Linq; using OpenRA.Traits; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA.Crates { @@ -41,7 +42,11 @@ namespace OpenRA.Mods.RA.Crates var location = ChooseEmptyCellNear(collector); if (location != null) collector.World.AddFrameEndTask( - w => w.CreateActor(Info.Unit, location.Value, collector.Owner)); + w => w.CreateActor(Info.Unit, new TypeDictionary + { + new LocationInit( location.Value ), + new OwnerInit( collector.Owner ) + })); base.Activate(collector); } diff --git a/OpenRA.Mods.RA/EmitInfantryOnSell.cs b/OpenRA.Mods.RA/EmitInfantryOnSell.cs index 9105a0c02a..11d3fe041b 100644 --- a/OpenRA.Mods.RA/EmitInfantryOnSell.cs +++ b/OpenRA.Mods.RA/EmitInfantryOnSell.cs @@ -12,6 +12,7 @@ using System; using System.Linq; using OpenRA.GameRules; using OpenRA.Traits; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA { @@ -49,7 +50,11 @@ namespace OpenRA.Mods.RA eligibleLocations.Remove(loc); dudesValue -= at.Cost; - self.World.AddFrameEndTask(w => w.CreateActor(at.Name, loc, self.Owner)); + self.World.AddFrameEndTask(w => w.CreateActor(at.Name, new TypeDictionary + { + new LocationInit( loc ), + new OwnerInit( self.Owner ), + })); } } diff --git a/OpenRA.Mods.RA/FreeActor.cs b/OpenRA.Mods.RA/FreeActor.cs index 2aa79d202b..fc3e818588 100644 --- a/OpenRA.Mods.RA/FreeActor.cs +++ b/OpenRA.Mods.RA/FreeActor.cs @@ -10,6 +10,7 @@ using System.Linq; using OpenRA.Traits; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA { @@ -31,12 +32,12 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask( w => { - var a = w.CreateActor(info.Actor, self.Location - + info.SpawnOffset, self.Owner); - - var facing = a.traits.GetOrDefault(); - if (facing != null) - facing.Facing = info.Facing; + var a = w.CreateActor(info.Actor, new TypeDictionary + { + new LocationInit( self.Location + info.SpawnOffset ), + new OwnerInit( self.Owner ), + new FacingInit( info.Facing ), + }); if (info.InitialActivity != null) a.QueueActivity(Game.CreateObject(info.InitialActivity)); diff --git a/OpenRA.Mods.RA/ProducesHelicopters.cs b/OpenRA.Mods.RA/ProducesHelicopters.cs index 40350e849e..b19c9e1ed5 100644 --- a/OpenRA.Mods.RA/ProducesHelicopters.cs +++ b/OpenRA.Mods.RA/ProducesHelicopters.cs @@ -11,6 +11,7 @@ using System.Linq; using OpenRA.GameRules; using OpenRA.Traits; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA { @@ -28,9 +29,12 @@ namespace OpenRA.Mods.RA if( location == null || self.World.WorldActor.traits.Get().GetUnitsAt( location.Value ).Any() ) return false; - var newUnit = self.World.CreateActor( producee.Name, location.Value, self.Owner ); - newUnit.traits.Get().Facing = CreationFacing( self, newUnit ); ; - + var newUnit = self.World.CreateActor( producee.Name, new TypeDictionary + { + new LocationInit( location.Value ), + new OwnerInit( self.Owner ), + }); + var pi = self.Info.Traits.Get(); var rp = self.traits.GetOrDefault(); if( rp != null || pi.ExitOffset != null) diff --git a/OpenRA.Mods.RA/ReplaceWithActor.cs b/OpenRA.Mods.RA/ReplaceWithActor.cs index 595deb5d5a..768e7bad5c 100644 --- a/OpenRA.Mods.RA/ReplaceWithActor.cs +++ b/OpenRA.Mods.RA/ReplaceWithActor.cs @@ -8,7 +8,8 @@ */ #endregion -using OpenRA.Traits; +using OpenRA.Traits; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA { @@ -27,7 +28,11 @@ namespace OpenRA.Mods.RA self.World.AddFrameEndTask(w => { w.Remove(self); - w.CreateActor(info.Actor, self.Location, self.Owner); + w.CreateActor(info.Actor, new TypeDictionary + { + new LocationInit( self.Location ), + new OwnerInit( self.Owner ), + }); }); } } diff --git a/OpenRA.Mods.RA/SpawnDefaultUnits.cs b/OpenRA.Mods.RA/SpawnDefaultUnits.cs index 9514d482f0..60ce4bc846 100644 --- a/OpenRA.Mods.RA/SpawnDefaultUnits.cs +++ b/OpenRA.Mods.RA/SpawnDefaultUnits.cs @@ -41,7 +41,11 @@ namespace OpenRA.Mods.RA void SpawnUnitsForPlayer(Player p, int2 sp) { - p.World.CreateActor("mcv", sp, p); + p.World.CreateActor("mcv", new TypeDictionary + { + new LocationInit( sp ), + new OwnerInit( p ), + }); if (p == p.World.LocalPlayer || p.Stances[p.World.LocalPlayer] == Stance.Ally) p.World.WorldActor.traits.Get().Explore(p.World, sp, diff --git a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs index 16b79fd37f..8b1ee06809 100755 --- a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs @@ -12,6 +12,7 @@ using OpenRA.Mods.RA.Activities; using OpenRA.Orders; using OpenRA.Traits; using OpenRA.Traits.Activities; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA { @@ -44,12 +45,20 @@ namespace OpenRA.Mods.RA Owner.World.AddFrameEndTask(w => { - var flareType = (Info as AirstrikePowerInfo).FlareType; - var flare = flareType != null ? w.CreateActor(flareType, order.TargetLocation, Owner) : null; - - var a = w.CreateActor((Info as AirstrikePowerInfo).UnitType, startPos, Owner); - a.traits.Get().Facing = Util.GetFacing(order.TargetLocation - startPos, 0); - a.traits.Get().Altitude = a.Info.Traits.Get().CruiseAltitude; + var info = (Info as AirstrikePowerInfo); + var flare = info.FlareType != null ? w.CreateActor(info.FlareType, new TypeDictionary + { + new LocationInit( order.TargetLocation ), + new OwnerInit( Owner ), + }) : null; + + var a = w.CreateActor(info.UnitType, new TypeDictionary + { + new LocationInit( startPos ), + new OwnerInit( Owner ), + new FacingInit( Util.GetFacing(order.TargetLocation - startPos, 0) ), + new AltitudeInit( Rules.Info[info.UnitType].Traits.Get().CruiseAltitude ), + }); a.traits.Get().SetTarget(order.TargetLocation); a.CancelActivity(); diff --git a/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs b/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs index bb5c051996..a4a206fbb2 100755 --- a/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ParatroopersPower.cs @@ -59,7 +59,11 @@ namespace OpenRA.Mods.RA owner.World.AddFrameEndTask(w => { var info = (Info as ParatroopersPowerInfo); - var flare = info.FlareType != null ? w.CreateActor(info.FlareType, p, owner) : null; + var flare = info.FlareType != null ? w.CreateActor(info.FlareType, new TypeDictionary + { + new LocationInit( p ), + new OwnerInit( owner ), + }) : null; var a = w.CreateActor(info.UnitType, new TypeDictionary { @@ -75,8 +79,7 @@ namespace OpenRA.Mods.RA var cargo = a.traits.Get(); foreach (var i in items) - cargo.Load(a, owner.World.CreateActor(false, i.ToLowerInvariant(), - new int2(0,0), a.Owner)); + cargo.Load(a, owner.World.CreateActor(false, i.ToLowerInvariant(), new TypeDictionary { new OwnerInit( a.Owner ) })); }); } } diff --git a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs index 3c7b2af3fe..2a34e5feb9 100755 --- a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs @@ -58,7 +58,12 @@ namespace OpenRA.Mods.RA plane.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation))); plane.QueueActivity(new CallFunc(() => plane.World.AddFrameEndTask( w => { - var camera = w.CreateActor("camera", order.TargetLocation, Owner); + var camera = w.CreateActor("camera", new TypeDictionary + { + new LocationInit( order.TargetLocation ), + new OwnerInit( Owner ), + }); + camera.QueueActivity(new Wait((int)(25 * 60 * (Info as SpyPlanePowerInfo).RevealTime))); camera.QueueActivity(new RemoveSelf()); })));