ActorInitializer, in preparation for next change (bob)

This commit is contained in:
Chris Forbes
2010-06-19 14:28:30 +12:00
parent 572cdc9dbf
commit db465e1fdd
106 changed files with 174 additions and 227 deletions

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Traits
{
public readonly string[] BibTypes = {"bib3", "bib2", "bib1"};
public readonly int[] BibWidths = {2,3,4};
public object Create(Actor self) { return new BibLayer(self, this); }
public object Create(ActorInitializer init) { return new BibLayer(init.self, this); }
}
class BibLayer: IRenderOverlay, ILoadWorldHook

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Traits
{
public class BuildingInfluenceInfo : ITraitInfo
{
public object Create( Actor self ) { return new BuildingInfluence( self ); }
public object Create( ActorInitializer init ) { return new BuildingInfluence( init.world ); }
}
public class BuildingInfluence
@@ -34,17 +34,17 @@ namespace OpenRA.Traits
Actor[,] influence;
Map map;
public BuildingInfluence( Actor self )
public BuildingInfluence( World world )
{
map = self.World.Map;
map = world.Map;
blocked = new bool[map.MapSize.X, map.MapSize.Y];
influence = new Actor[map.MapSize.X, map.MapSize.Y];
self.World.ActorAdded +=
world.ActorAdded +=
a => { if (a.traits.Contains<Building>())
ChangeInfluence(a, a.traits.Get<Building>(), true); };
self.World.ActorRemoved +=
world.ActorRemoved +=
a => { if (a.traits.Contains<Building>())
ChangeInfluence(a, a.traits.Get<Building>(), false); };
}

View File

@@ -20,15 +20,13 @@
namespace OpenRA.Traits
{
public class CountryInfo : ITraitInfo
public class CountryInfo : TraitInfo<Country>
{
public readonly string Name = null;
public readonly string Race = null;
/* todo: icon,... */
public object Create(Actor self) { return new CountryInfo(); }
}
class Country { /* we're only interested in the Info */ }
public class Country { /* we're only interested in the Info */ }
}

View File

@@ -36,16 +36,16 @@ namespace OpenRA.Traits
public readonly int[] DisplayColor = null;
public readonly bool Playable = true;
public object Create(Actor self) { return new PlayerColorPalette(self, this); }
public object Create(ActorInitializer init) { return new PlayerColorPalette(init.world, this); }
public Color Color { get { return Util.ArrayToColor(DisplayColor); } }
}
public class PlayerColorPalette
{
public PlayerColorPalette(Actor self, PlayerColorPaletteInfo info)
public PlayerColorPalette(World world, PlayerColorPaletteInfo info)
{
var wr = self.World.WorldRenderer;
var wr = world.WorldRenderer;
var pal = wr.GetPalette(info.BasePalette);
var newpal = new Palette(pal, new PlayerColorRemap(
Util.ArrayToColor(info.Color1),

View File

@@ -26,10 +26,7 @@ using System.Drawing;
namespace OpenRA.Traits
{
public class ResourceLayerInfo : ITraitInfo
{
public object Create(Actor self) { return new ResourceLayer(self); }
}
public class ResourceLayerInfo : TraitInfo<ResourceLayer> { }
public class ResourceLayer: IRenderOverlay, ILoadWorldHook, ICustomTerrain
{
@@ -39,7 +36,7 @@ namespace OpenRA.Traits
public ResourceType[] resourceTypes;
CellContents[,] content;
public ResourceLayer(Actor self)
public ResourceLayer()
{
sr = Game.renderer.SpriteRenderer;
}

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Traits
public Sprite[][] Sprites;
public object Create(Actor self) { return new ResourceType(this); }
public object Create(ActorInitializer init) { return new ResourceType(this); }
}
public class ResourceType

View File

@@ -24,10 +24,7 @@ using System.Linq;
namespace OpenRA.Traits
{
class ScreenShakerInfo : ITraitInfo
{
public object Create( Actor self ) { return new ScreenShaker(); }
}
class ScreenShakerInfo : TraitInfo<ScreenShaker> {}
public class ScreenShaker : ITick
{

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Traits
{
public class ShroudInfo : ITraitInfo
{
public object Create(Actor self) { return new Shroud(self); }
public object Create(ActorInitializer init) { return new Shroud(init.world); }
}
public class Shroud
@@ -41,14 +41,14 @@ namespace OpenRA.Traits
public Rectangle? exploredBounds;
public event Action Dirty = () => { };
public Shroud(Actor self)
public Shroud(World world)
{
map = self.World.Map;
map = world.Map;
visibleCells = new int[map.MapSize.X, map.MapSize.Y];
exploredCells = new bool[map.MapSize.X, map.MapSize.Y];
self.World.ActorAdded += AddActor;
self.World.ActorRemoved += RemoveActor;
world.ActorAdded += AddActor;
world.ActorRemoved += RemoveActor;
}
// cache of positions that were added, so no matter what crazy trait code does, it

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Traits
public readonly string Type = "Scorch";
public readonly string[] Types = {"sc1", "sc2", "sc3", "sc4", "sc5", "sc6"};
public readonly int[] Depths = {1,1,1,1,1,1};
public object Create(Actor self) { return new SmudgeLayer(self, this); }
public object Create(ActorInitializer init) { return new SmudgeLayer(this); }
}
class SmudgeLayer: IRenderOverlay, ILoadWorldHook
@@ -42,7 +42,7 @@ namespace OpenRA.Traits
Sprite[][] smudgeSprites;
World world;
public SmudgeLayer(Actor self, SmudgeLayerInfo info)
public SmudgeLayer(SmudgeLayerInfo info)
{
spriteRenderer = Game.renderer.SpriteRenderer;
this.Info = info;

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Traits
class SpatialBinsInfo : ITraitInfo
{
public readonly int BinSize = 8;
public object Create(Actor self) { return new SpatialBins( self, this ); }
public object Create(ActorInitializer init) { return new SpatialBins( init.self, this ); }
}
class SpatialBins : ITick

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Traits
{
public class UnitInfluenceInfo : ITraitInfo
{
public object Create( Actor self ) { return new UnitInfluence( self ); }
public object Create( ActorInitializer init ) { return new UnitInfluence( init.world ); }
}
public class UnitInfluence : ITick
@@ -36,15 +36,15 @@ namespace OpenRA.Traits
List<Actor>[,] influence;
Map map;
public UnitInfluence( Actor self )
public UnitInfluence( World world )
{
map = self.World.Map;
influence = new List<Actor>[self.World.Map.MapSize.X, self.World.Map.MapSize.Y];
for (int i = 0; i < self.World.Map.MapSize.X; i++)
for (int j = 0; j < self.World.Map.MapSize.Y; j++)
map = world.Map;
influence = new List<Actor>[world.Map.MapSize.X, world.Map.MapSize.Y];
for (int i = 0; i < world.Map.MapSize.X; i++)
for (int j = 0; j < world.Map.MapSize.Y; j++)
influence[ i, j ] = new List<Actor>();
self.World.ActorRemoved += a => Remove( a, a.traits.GetOrDefault<IOccupySpace>() );
world.ActorRemoved += a => Remove( a, a.traits.GetOrDefault<IOccupySpace>() );
}
public void Tick( Actor self )