TileSet and Map are now in Rules, not Game
This commit is contained in:
@@ -19,7 +19,6 @@ namespace OpenRa.Game
|
||||
public static readonly int CellSize = 24;
|
||||
|
||||
public static World world;
|
||||
public static Map map;
|
||||
static TreeCache treeCache;
|
||||
public static Viewport viewport;
|
||||
public static PathFinder PathFinder;
|
||||
@@ -56,29 +55,26 @@ namespace OpenRa.Game
|
||||
|
||||
localPlayerIndex = localPlayer;
|
||||
|
||||
var mapFile = new IniFile(FileSystem.Open(mapName));
|
||||
map = new Map(mapFile);
|
||||
map.InitOreDensity();
|
||||
FileSystem.Mount(new Package(map.Theater + ".mix"));
|
||||
Rules.Map.InitOreDensity();
|
||||
|
||||
viewport = new Viewport(clientSize, map.Offset, map.Offset + map.Size, renderer);
|
||||
viewport = new Viewport(clientSize, Rules.Map.Offset, Rules.Map.Offset + Rules.Map.Size, renderer);
|
||||
|
||||
world = new World();
|
||||
treeCache = new TreeCache(map);
|
||||
treeCache = new TreeCache(Rules.Map);
|
||||
|
||||
foreach (TreeReference treeReference in map.Trees)
|
||||
foreach (TreeReference treeReference in Rules.Map.Trees)
|
||||
world.Add(new Actor(treeReference, treeCache));
|
||||
|
||||
BuildingInfluence = new BuildingInfluenceMap();
|
||||
UnitInfluence = new UnitInfluenceMap();
|
||||
|
||||
LoadMapBuildings(mapFile);
|
||||
LoadMapUnits(mapFile);
|
||||
LoadMapBuildings(Rules.AllRules);
|
||||
LoadMapUnits(Rules.AllRules);
|
||||
|
||||
controller = new Controller();
|
||||
worldRenderer = new WorldRenderer(renderer);
|
||||
|
||||
PathFinder = new PathFinder(map, worldRenderer.terrainRenderer.tileSet);
|
||||
PathFinder = new PathFinder(Rules.Map);
|
||||
|
||||
soundEngine = new ISoundEngine();
|
||||
sounds = new Cache<string, ISoundSource>(LoadSound);
|
||||
@@ -178,7 +174,7 @@ namespace OpenRa.Game
|
||||
if (--oreTicks == 0)
|
||||
{
|
||||
using (new PerfSample("ore"))
|
||||
map.GrowOre(SharedRandom);
|
||||
Rules.Map.GrowOre(SharedRandom);
|
||||
oreTicks = oreFrequency;
|
||||
}
|
||||
|
||||
@@ -214,16 +210,16 @@ namespace OpenRa.Game
|
||||
if (BuildingInfluence.GetBuildingAt(a) != null) return false;
|
||||
if (UnitInfluence.GetUnitAt(a) != null && UnitInfluence.GetUnitAt(a) != toIgnore) return false;
|
||||
|
||||
return map.IsInMap(a.X, a.Y) &&
|
||||
return Rules.Map.IsInMap(a.X, a.Y) &&
|
||||
TerrainCosts.Cost(umt,
|
||||
worldRenderer.terrainRenderer.tileSet.GetWalkability(map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||
Rules.TileSet.GetWalkability(Rules.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||
}
|
||||
|
||||
public static bool IsWater(int2 a)
|
||||
{
|
||||
return map.IsInMap(a.X, a.Y) &&
|
||||
return Rules.Map.IsInMap(a.X, a.Y) &&
|
||||
TerrainCosts.Cost(UnitMovementType.Float,
|
||||
worldRenderer.terrainRenderer.tileSet.GetWalkability(map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||
Rules.TileSet.GetWalkability(Rules.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||
}
|
||||
|
||||
static IEnumerable<Actor> FindUnits(float2 a, float2 b)
|
||||
@@ -303,7 +299,7 @@ namespace OpenRa.Game
|
||||
public static bool CanPlaceBuilding(UnitInfo.BuildingInfo building, int2 xy, Actor toIgnore, bool adjust)
|
||||
{
|
||||
return !Footprint.Tiles(building, xy, adjust).Any(
|
||||
t => Game.map.ContainsResource(t) || !Game.IsCellBuildable(t,
|
||||
t => Rules.Map.ContainsResource(t) || !Game.IsCellBuildable(t,
|
||||
building.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel,
|
||||
toIgnore));
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ namespace OpenRa.Game
|
||||
public static InfoLoader<ProjectileInfo> ProjectileInfo;
|
||||
public static GeneralInfo General;
|
||||
public static TechTree TechTree;
|
||||
public static Map Map;
|
||||
public static TileSet TileSet;
|
||||
|
||||
public static void LoadRules(string mapFileName)
|
||||
{
|
||||
@@ -61,6 +63,9 @@ namespace OpenRa.Game
|
||||
Pair.New<string, Func<string, ProjectileInfo>>("Projectile", _ => new ProjectileInfo()));
|
||||
|
||||
TechTree = new TechTree();
|
||||
Map = new Map( AllRules );
|
||||
FileSystem.Mount( new Package( Rules.Map.Theater + ".mix" ) );
|
||||
TileSet = new TileSet( Map.TileSuffix );
|
||||
}
|
||||
|
||||
static void LoadCategories(params string[] types)
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace OpenRa.Game.Graphics
|
||||
FvfVertexBuffer<Vertex> vertexBuffer;
|
||||
IndexBuffer indexBuffer;
|
||||
Sheet terrainSheet;
|
||||
public TileSet tileSet;
|
||||
|
||||
Renderer renderer;
|
||||
Map map;
|
||||
@@ -23,14 +22,12 @@ namespace OpenRa.Game.Graphics
|
||||
this.map = map;
|
||||
overlayRenderer = new OverlayRenderer( renderer, map );
|
||||
|
||||
tileSet = new TileSet( map.TileSuffix );
|
||||
|
||||
Size tileSize = new Size( Game.CellSize, Game.CellSize );
|
||||
|
||||
SheetBuilder.ForceNewSheet();
|
||||
|
||||
var tileMapping = new Cache<TileReference, Sprite>(
|
||||
x => SheetBuilder.Add(tileSet.GetBytes(x), tileSize));
|
||||
x => SheetBuilder.Add(Rules.TileSet.GetBytes(x), tileSize));
|
||||
|
||||
Vertex[] vertices = new Vertex[4 * map.Height * map.Width];
|
||||
ushort[] indices = new ushort[6 * map.Height * map.Width];
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace OpenRa.Game.Graphics
|
||||
|
||||
public WorldRenderer(Renderer renderer)
|
||||
{
|
||||
terrainRenderer = new TerrainRenderer(renderer, Game.map);
|
||||
terrainRenderer = new TerrainRenderer(renderer, Rules.Map);
|
||||
|
||||
this.renderer = renderer;
|
||||
spriteRenderer = new SpriteRenderer(renderer, true);
|
||||
|
||||
@@ -58,18 +58,18 @@ namespace OpenRa.Game
|
||||
|
||||
SequenceProvider.ForcePrecache();
|
||||
|
||||
Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 5, 5 ), Game.players[ 1 ]) );
|
||||
Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 7, 5 ), Game.players[ 2 ] ) );
|
||||
Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 9, 5 ), Game.players[ 0 ] ) );
|
||||
Game.world.Add( new Actor( "jeep", Game.map.Offset + new int2( 9, 14 ), Game.players[ 1 ] ) );
|
||||
Game.world.Add( new Actor( "3tnk", Game.map.Offset + new int2( 12, 7 ), Game.players[ 1 ] ) );
|
||||
Game.world.Add(new Actor("apc", Game.map.Offset + new int2(13, 7), Game.players[1]));
|
||||
Game.world.Add(new Actor("ca", Game.map.Offset + new int2(40, 7), Game.players[1]));
|
||||
Game.world.Add(new Actor("e1", Game.map.Offset + new int2(9, 13), Game.players[1]));
|
||||
Game.world.Add(new Actor("arty", Game.map.Offset + new int2(10, 13), Game.players[1]));
|
||||
Game.world.Add(new Actor("heli", Game.map.Offset + new int2(11, 12), Game.players[1]));
|
||||
Game.world.Add( new Actor( "mcv", Rules.Map.Offset + new int2( 5, 5 ), Game.players[ 1 ] ) );
|
||||
Game.world.Add( new Actor( "mcv", Rules.Map.Offset + new int2( 7, 5 ), Game.players[ 2 ] ) );
|
||||
Game.world.Add( new Actor( "mcv", Rules.Map.Offset + new int2( 9, 5 ), Game.players[ 0 ] ) );
|
||||
Game.world.Add( new Actor( "jeep", Rules.Map.Offset + new int2( 9, 14 ), Game.players[ 1 ] ) );
|
||||
Game.world.Add( new Actor( "3tnk", Rules.Map.Offset + new int2( 12, 7 ), Game.players[ 1 ] ) );
|
||||
Game.world.Add( new Actor( "apc", Rules.Map.Offset + new int2( 13, 7 ), Game.players[ 1 ] ) );
|
||||
Game.world.Add( new Actor( "ca", Rules.Map.Offset + new int2( 40, 7 ), Game.players[ 1 ] ) );
|
||||
Game.world.Add( new Actor( "e1", Rules.Map.Offset + new int2( 9, 13 ), Game.players[ 1 ] ) );
|
||||
Game.world.Add( new Actor( "arty", Rules.Map.Offset + new int2( 10, 13 ), Game.players[ 1 ] ) );
|
||||
Game.world.Add( new Actor( "heli", Rules.Map.Offset + new int2( 11, 12 ), Game.players[ 1 ] ) );
|
||||
|
||||
renderer.BuildPalette(Game.map);
|
||||
renderer.BuildPalette( Rules.Map );
|
||||
ShowCursor(false);
|
||||
Game.ResetTimer();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace OpenRa.Game
|
||||
return false;
|
||||
|
||||
return TerrainCosts.Cost(UnitMovementType.Wheel,
|
||||
Game.worldRenderer.terrainRenderer.tileSet.GetWalkability(Game.map.MapTiles[i, j]))
|
||||
Rules.TileSet.GetWalkability(Rules.Map.MapTiles[i, j]))
|
||||
< double.PositiveInfinity;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace OpenRa.Game
|
||||
float[][,] passableCost = new float[4][,];
|
||||
Map map;
|
||||
|
||||
public PathFinder(Map map, TileSet tileSet)
|
||||
public PathFinder(Map map)
|
||||
{
|
||||
this.map = map;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRa.Game
|
||||
for( int y = 0 ; y < 128 ; y++ )
|
||||
for (var umt = UnitMovementType.Foot; umt <= UnitMovementType.Float; umt++ )
|
||||
passableCost[(int)umt][ x, y ] = ( map.IsInMap( x, y ) )
|
||||
? (float)TerrainCosts.Cost( umt, tileSet.GetWalkability( map.MapTiles[ x, y ] ) )
|
||||
? (float)TerrainCosts.Cost( umt, Rules.TileSet.GetWalkability( map.MapTiles[ x, y ] ) )
|
||||
: float.PositiveInfinity;
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace OpenRa.Game
|
||||
continue;
|
||||
if (ignoreTerrain)
|
||||
{
|
||||
if (!Game.map.IsInMap(newHere.X, newHere.Y)) continue;
|
||||
if (!Rules.Map.IsInMap(newHere.X, newHere.Y)) continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -50,7 +50,7 @@ namespace OpenRa.Game
|
||||
continue;
|
||||
if (!Game.BuildingInfluence.CanMoveHere(newHere))
|
||||
continue;
|
||||
if (Game.map.IsOverlaySolid(newHere))
|
||||
if (Rules.Map.IsOverlaySolid(newHere))
|
||||
continue;
|
||||
}
|
||||
if( checkForBlocked && Game.UnitInfluence.GetUnitAt( newHere ) != null )
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace OpenRa.Game.Traits.Activities
|
||||
return new DeliverOre { NextActivity = NextActivity };
|
||||
|
||||
var isGem = false;
|
||||
if( Game.map.ContainsResource( self.Location ) &&
|
||||
Game.map.Harvest( self.Location, out isGem ) )
|
||||
if( Rules.Map.ContainsResource( self.Location ) &&
|
||||
Rules.Map.Harvest( self.Location, out isGem ) )
|
||||
{
|
||||
var harvestAnim = "harvest" + Util.QuantizeFacing( mobile.facing, 8 );
|
||||
var renderUnit = self.traits.WithInterface<RenderUnit>().First(); /* better have one of these! */
|
||||
@@ -43,7 +43,7 @@ namespace OpenRa.Game.Traits.Activities
|
||||
{
|
||||
var search = new PathSearch
|
||||
{
|
||||
heuristic = loc => ( Game.map.ContainsResource( loc ) ? 0 : 1 ),
|
||||
heuristic = loc => ( Rules.Map.ContainsResource( loc ) ? 0 : 1 ),
|
||||
umt = UnitMovementType.Wheel,
|
||||
checkForBlocked = true
|
||||
};
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRa.Game.Traits
|
||||
&& underCursor.traits.Contains<AcceptsOre>() && !IsEmpty)
|
||||
return OpenRa.Game.Order.DeliverOre(self, underCursor);
|
||||
|
||||
if (underCursor == null && Game.map.ContainsResource(xy))
|
||||
if (underCursor == null && Rules.Map.ContainsResource(xy))
|
||||
return OpenRa.Game.Order.Harvest(self, xy);
|
||||
|
||||
return null;
|
||||
|
||||
@@ -55,11 +55,11 @@ namespace OpenRa.Game.Traits
|
||||
var p = self.Location + new int2(i % size, i / size + bibOffset);
|
||||
if (isRemove)
|
||||
{
|
||||
if (Game.map.MapTiles[p.X, p.Y].smudge == (byte)(i + startIndex))
|
||||
Game.map.MapTiles[p.X, p.Y].smudge = 0;
|
||||
if (Rules.Map.MapTiles[p.X, p.Y].smudge == (byte)(i + startIndex))
|
||||
Rules.Map.MapTiles[ p.X, p.Y ].smudge = 0;
|
||||
}
|
||||
else
|
||||
Game.map.MapTiles[p.X, p.Y].smudge = (byte)(i + startIndex);
|
||||
Rules.Map.MapTiles[p.X, p.Y].smudge = (byte)(i + startIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace OpenRa.Game
|
||||
|
||||
foreach( var t in Footprint.Tiles( bi, position ) )
|
||||
spriteRenderer.DrawSprite( ( isCloseEnough && Game.IsCellBuildable( t, bi.WaterBound
|
||||
? UnitMovementType.Float : UnitMovementType.Wheel ) && !Game.map.ContainsResource( t ) )
|
||||
? UnitMovementType.Float : UnitMovementType.Wheel ) && !Rules.Map.ContainsResource( t ) )
|
||||
? buildOk : buildBlocked, Game.CellSize * t, 0 );
|
||||
|
||||
spriteRenderer.Flush();
|
||||
|
||||
Reference in New Issue
Block a user