moving Map, TileSet from Rules to World
This commit is contained in:
@@ -85,7 +85,7 @@ namespace OpenRa
|
||||
if (Owner != Game.LocalPlayer)
|
||||
return null;
|
||||
|
||||
if (!Rules.Map.IsInMap(xy.X, xy.Y))
|
||||
if (!Game.world.Map.IsInMap(xy.X, xy.Y))
|
||||
return null;
|
||||
|
||||
var loc = mi.Location + Game.viewport.Location;
|
||||
|
||||
@@ -64,7 +64,6 @@ namespace OpenRa
|
||||
SpriteSheetBuilder.Initialize();
|
||||
FileSystem.UnmountTemporaryPackages();
|
||||
Rules.LoadRules(mapName, usingAftermath);
|
||||
palette = new HardwarePalette(renderer, Rules.Map);
|
||||
|
||||
world = new World();
|
||||
Game.world.ActorAdded += a =>
|
||||
@@ -73,6 +72,8 @@ namespace OpenRa
|
||||
a.Owner.Shroud.Explore(a);
|
||||
};
|
||||
|
||||
palette = new HardwarePalette(renderer, world.Map);
|
||||
|
||||
var worldActor = new Actor("World", new int2(int.MaxValue, int.MaxValue), null);
|
||||
Game.world.Add(worldActor);
|
||||
|
||||
@@ -83,11 +84,11 @@ namespace OpenRa
|
||||
players[i] = new Player(i, LobbyInfo.Clients.FirstOrDefault(a => a.Index == i));
|
||||
}
|
||||
|
||||
Rules.Map.InitOreDensity();
|
||||
Game.world.Map.InitOreDensity();
|
||||
worldRenderer = new WorldRenderer(renderer);
|
||||
|
||||
SequenceProvider.Initialize(usingAftermath);
|
||||
viewport = new Viewport(clientSize, Rules.Map.Offset, Rules.Map.Offset + Rules.Map.Size, renderer);
|
||||
viewport = new Viewport(clientSize, Game.world.Map.Offset, Game.world.Map.Offset + Game.world.Map.Size, renderer);
|
||||
|
||||
minimap = new Minimap(renderer);
|
||||
|
||||
@@ -95,7 +96,7 @@ namespace OpenRa
|
||||
UnitInfluence = new UnitInfluenceMap();
|
||||
|
||||
skipMakeAnims = true;
|
||||
foreach (var treeReference in Rules.Map.Trees)
|
||||
foreach (var treeReference in Game.world.Map.Trees)
|
||||
world.Add(new Actor(treeReference.Image, new int2(treeReference.Location), null));
|
||||
|
||||
LoadMapActors(Rules.AllRules);
|
||||
@@ -202,7 +203,7 @@ namespace OpenRa
|
||||
if (--oreTicks == 0)
|
||||
using (new PerfSample("ore"))
|
||||
{
|
||||
Rules.Map.GrowOre(SharedRandom);
|
||||
Game.world.Map.GrowOre(SharedRandom);
|
||||
minimap.InvalidateOre();
|
||||
oreTicks = oreFrequency;
|
||||
}
|
||||
@@ -250,9 +251,9 @@ namespace OpenRa
|
||||
if (BuildingInfluence.GetBuildingAt(a) != null) return false;
|
||||
if (UnitInfluence.GetUnitsAt(a).Any(b => b != toIgnore)) return false;
|
||||
|
||||
return Rules.Map.IsInMap(a.X, a.Y) &&
|
||||
return Game.world.Map.IsInMap(a.X, a.Y) &&
|
||||
TerrainCosts.Cost(umt,
|
||||
Rules.TileSet.GetWalkability(Rules.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||
Game.world.TileSet.GetWalkability(Game.world.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||
}
|
||||
|
||||
public static bool IsActorCrushableByActor(Actor a, Actor b)
|
||||
@@ -276,9 +277,9 @@ namespace OpenRa
|
||||
|
||||
public static bool IsWater(int2 a)
|
||||
{
|
||||
return Rules.Map.IsInMap(a.X, a.Y) &&
|
||||
return Game.world.Map.IsInMap(a.X, a.Y) &&
|
||||
TerrainCosts.Cost(UnitMovementType.Float,
|
||||
Rules.TileSet.GetWalkability(Rules.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||
Game.world.TileSet.GetWalkability(Game.world.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||
}
|
||||
|
||||
public static IEnumerable<Actor> FindUnits(float2 a, float2 b)
|
||||
@@ -336,7 +337,7 @@ namespace OpenRa
|
||||
public static bool CanPlaceBuilding(string name, BuildingInfo building, int2 xy, Actor toIgnore, bool adjust)
|
||||
{
|
||||
return !Footprint.Tiles(name, building, xy, adjust).Any(
|
||||
t => !Rules.Map.IsInMap(t.X, t.Y) || Rules.Map.ContainsResource(t) || !Game.IsCellBuildable(t,
|
||||
t => !Game.world.Map.IsInMap(t.X, t.Y) || Game.world.Map.ContainsResource(t) || !Game.IsCellBuildable(t,
|
||||
building.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel,
|
||||
toIgnore));
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ namespace OpenRa
|
||||
public static GeneralInfo General;
|
||||
public static AftermathInfo Aftermath;
|
||||
public static TechTree TechTree;
|
||||
public static Map Map;
|
||||
public static TileSet TileSet;
|
||||
|
||||
public static Dictionary<string, ActorInfo> ActorInfo;
|
||||
|
||||
@@ -75,9 +73,6 @@ namespace OpenRa
|
||||
ActorInfo.Add(kv.Key.ToLowerInvariant(), new ActorInfo(kv.Key.ToLowerInvariant(), kv.Value, yamlRules));
|
||||
|
||||
TechTree = new TechTree();
|
||||
Map = new Map( AllRules );
|
||||
FileSystem.MountTemporary( new Package( Rules.Map.Theater + ".mix" ) );
|
||||
TileSet = new TileSet( Map.TileSuffix );
|
||||
}
|
||||
|
||||
static void LoadCategories(params string[] types)
|
||||
|
||||
@@ -23,12 +23,12 @@ namespace OpenRa.Graphics
|
||||
mapOnlySheet = new Sheet(r, new Size(128, 128));
|
||||
|
||||
rgbaRenderer = new SpriteRenderer(r, true, r.RgbaSpriteShader);
|
||||
var size = Math.Max(Rules.Map.Width, Rules.Map.Height);
|
||||
var dw = (size - Rules.Map.Width) / 2;
|
||||
var dh = (size - Rules.Map.Height) / 2;
|
||||
var size = Math.Max(Game.world.Map.Width, Game.world.Map.Height);
|
||||
var dw = (size - Game.world.Map.Width) / 2;
|
||||
var dh = (size - Game.world.Map.Height) / 2;
|
||||
|
||||
sprite = new Sprite(sheet, new Rectangle(Rules.Map.Offset.X+dw, Rules.Map.Offset.Y+dh, size, size), TextureChannel.Alpha);
|
||||
mapOnlySprite = new Sprite(mapOnlySheet, new Rectangle(Rules.Map.Offset.X + dw, Rules.Map.Offset.Y + dh, size, size), TextureChannel.Alpha);
|
||||
sprite = new Sprite(sheet, new Rectangle(Game.world.Map.Offset.X+dw, Game.world.Map.Offset.Y+dh, size, size), TextureChannel.Alpha);
|
||||
mapOnlySprite = new Sprite(mapOnlySheet, new Rectangle(Game.world.Map.Offset.X + dw, Game.world.Map.Offset.Y + dh, size, size), TextureChannel.Alpha);
|
||||
}
|
||||
|
||||
Color[] terrainTypeColors;
|
||||
@@ -40,15 +40,15 @@ namespace OpenRa.Graphics
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Rules.Map.Theater != theater)
|
||||
if (Game.world.Map.Theater != theater)
|
||||
{
|
||||
terrainTypeColors = null;
|
||||
theater = Rules.Map.Theater;
|
||||
theater = Game.world.Map.Theater;
|
||||
}
|
||||
|
||||
if (terrainTypeColors == null)
|
||||
{
|
||||
var pal = new Palette(FileSystem.Open(Rules.Map.Theater + ".pal"));
|
||||
var pal = new Palette(FileSystem.Open(Game.world.Map.Theater + ".pal"));
|
||||
terrainTypeColors = new[] {
|
||||
Color.FromArgb(alpha, pal.GetColor(theater.ToLowerInvariant() == "snow" ? 0xe3 :0x1a)),
|
||||
Color.FromArgb(alpha, pal.GetColor(0x63)),
|
||||
@@ -71,8 +71,8 @@ namespace OpenRa.Graphics
|
||||
terrain = new Bitmap(128, 128);
|
||||
for (var y = 0; y < 128; y++)
|
||||
for (var x = 0; x < 128; x++)
|
||||
terrain.SetPixel(x, y, Rules.Map.IsInMap(x, y)
|
||||
? terrainTypeColors[Rules.TileSet.GetWalkability(Rules.Map.MapTiles[x, y])]
|
||||
terrain.SetPixel(x, y, Game.world.Map.IsInMap(x, y)
|
||||
? terrainTypeColors[Game.world.TileSet.GetWalkability(Game.world.Map.MapTiles[x, y])]
|
||||
: shroudColor);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace OpenRa.Graphics
|
||||
oreLayer = new Bitmap(terrain);
|
||||
for (var y = 0; y < 128; y++)
|
||||
for (var x = 0; x < 128; x++)
|
||||
if (Rules.Map.ContainsResource(new int2(x, y)))
|
||||
if (Game.world.Map.ContainsResource(new int2(x, y)))
|
||||
oreLayer.SetPixel(x, y, terrainTypeColors[(int)TerrainMovementType.Ore]);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRa.Graphics
|
||||
Size tileSize = new Size( Game.CellSize, Game.CellSize );
|
||||
|
||||
var tileMapping = new Cache<TileReference, Sprite>(
|
||||
x => SheetBuilder.Add(Rules.TileSet.GetBytes(x), tileSize));
|
||||
x => SheetBuilder.Add(Game.world.TileSet.GetBytes(x), tileSize));
|
||||
|
||||
Vertex[] vertices = new Vertex[4 * map.Height * map.Width];
|
||||
ushort[] indices = new ushort[6 * map.Height * map.Width];
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace OpenRa.Graphics
|
||||
|
||||
internal WorldRenderer(Renderer renderer)
|
||||
{
|
||||
terrainRenderer = new TerrainRenderer(renderer, Rules.Map);
|
||||
terrainRenderer = new TerrainRenderer(renderer, Game.world.Map);
|
||||
|
||||
this.renderer = renderer;
|
||||
spriteRenderer = new SpriteRenderer(renderer, true);
|
||||
|
||||
@@ -19,10 +19,10 @@ namespace OpenRa
|
||||
|
||||
public static void Destroy(int i, int j)
|
||||
{
|
||||
if (Rules.Map.ContainsResource(new int2(i, j)))
|
||||
if (Game.world.Map.ContainsResource(new int2(i, j)))
|
||||
{
|
||||
Rules.Map.MapTiles[i, j].density = 0;
|
||||
Rules.Map.MapTiles[i, j].overlay = 0xff;
|
||||
Game.world.Map.MapTiles[i, j].density = 0;
|
||||
Game.world.Map.MapTiles[i, j].overlay = 0xff;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRa
|
||||
return false;
|
||||
|
||||
return TerrainCosts.Cost(UnitMovementType.Wheel,
|
||||
Rules.TileSet.GetWalkability(Rules.Map.MapTiles[i, j]))
|
||||
Game.world.TileSet.GetWalkability(Game.world.Map.MapTiles[i, j]))
|
||||
< double.PositiveInfinity;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ namespace OpenRa
|
||||
for( int x = 0 ; x < 128 ; x++ )
|
||||
for( int y = 0 ; y < 128 ; y++ )
|
||||
for (var umt = UnitMovementType.Foot; umt <= UnitMovementType.Float; umt++ )
|
||||
passableCost[(int)umt][ x, y ] = ( Rules.Map.IsInMap( x, y ) )
|
||||
? (float)TerrainCosts.Cost( umt, Rules.TileSet.GetWalkability( Rules.Map.MapTiles[ x, y ] ) )
|
||||
passableCost[(int)umt][ x, y ] = ( Game.world.Map.IsInMap( x, y ) )
|
||||
? (float)TerrainCosts.Cost( umt, Game.world.TileSet.GetWalkability( Game.world.Map.MapTiles[ x, y ] ) )
|
||||
: float.PositiveInfinity;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace OpenRa
|
||||
{
|
||||
int2 newHere = p.Location + d;
|
||||
|
||||
if (!Rules.Map.IsInMap(newHere.X, newHere.Y)) continue;
|
||||
if (!Game.world.Map.IsInMap(newHere.X, newHere.Y)) continue;
|
||||
if( cellInfo[ newHere.X, newHere.Y ].Seen )
|
||||
continue;
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace OpenRa
|
||||
if (!Game.BuildingInfluence.CanMoveHere(newHere) &&
|
||||
Game.BuildingInfluence.GetBuildingAt(newHere) != ignoreBuilding)
|
||||
continue;
|
||||
if (Rules.Map.IsOverlaySolid(newHere))
|
||||
if (Game.world.Map.IsOverlaySolid(newHere))
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace OpenRa
|
||||
|
||||
public void AddInitialCell( int2 location )
|
||||
{
|
||||
if (!Rules.Map.IsInMap(location.X, location.Y))
|
||||
if (!Game.world.Map.IsInMap(location.X, location.Y))
|
||||
return;
|
||||
|
||||
cellInfo[ location.X, location.Y ] = new CellInfo( 0, location, false );
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace OpenRa
|
||||
|
||||
public static void AddSmudge(bool isCrater, int x, int y)
|
||||
{
|
||||
var smudge = Rules.Map.MapTiles[x, y].smudge;
|
||||
var smudge = Game.world.Map.MapTiles[x, y].smudge;
|
||||
if (smudge == 0)
|
||||
Rules.Map.MapTiles[x, y].smudge = (byte) (isCrater
|
||||
Game.world.Map.MapTiles[x, y].smudge = (byte) (isCrater
|
||||
? (firstCrater + framesPerCrater * ChooseSmudge())
|
||||
: (firstScorch + ChooseSmudge()));
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace OpenRa
|
||||
/* deepen the crater */
|
||||
var amount = (smudge - firstCrater) % framesPerCrater;
|
||||
if (amount < framesPerCrater - 1)
|
||||
Rules.Map.MapTiles[x, y].smudge++;
|
||||
Game.world.Map.MapTiles[x, y].smudge++;
|
||||
}
|
||||
|
||||
public static void AddSmudge(int2 targetTile, WarheadInfo warhead)
|
||||
|
||||
@@ -36,8 +36,8 @@ namespace OpenRa.Traits.Activities
|
||||
var renderUnit = self.traits.Get<RenderUnit>(); /* better have one of these! */
|
||||
|
||||
var isGem = false;
|
||||
if (!Rules.Map.ContainsResource(self.Location) ||
|
||||
!Rules.Map.Harvest(self.Location, out isGem))
|
||||
if (!Game.world.Map.ContainsResource(self.Location) ||
|
||||
!Game.world.Map.Harvest(self.Location, out isGem))
|
||||
return false;
|
||||
|
||||
var harvestAnim = "harvest" + Util.QuantizeFacing(unit.Facing, 8);
|
||||
@@ -58,7 +58,7 @@ namespace OpenRa.Traits.Activities
|
||||
{
|
||||
var search = new PathSearch
|
||||
{
|
||||
heuristic = loc => (Rules.Map.ContainsResource(loc) ? 0 : 1),
|
||||
heuristic = loc => (Game.world.Map.ContainsResource(loc) ? 0 : 1),
|
||||
umt = UnitMovementType.Wheel,
|
||||
checkForBlocked = true
|
||||
};
|
||||
|
||||
@@ -66,9 +66,9 @@ namespace OpenRa.Traits
|
||||
|
||||
if (!crushable) return false;
|
||||
|
||||
return Rules.Map.IsInMap(a.X, a.Y) &&
|
||||
return Game.world.Map.IsInMap(a.X, a.Y) &&
|
||||
TerrainCosts.Cost(GetMovementType(),
|
||||
Rules.TileSet.GetWalkability(Rules.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||
Game.world.TileSet.GetWalkability(Game.world.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRa.Traits
|
||||
&& underCursor.traits.Contains<AcceptsOre>() && !IsEmpty)
|
||||
return new Order("Deliver", self, underCursor, int2.Zero, null);
|
||||
|
||||
if (underCursor == null && Rules.Map.ContainsResource(xy))
|
||||
if (underCursor == null && Game.world.Map.ContainsResource(xy))
|
||||
return new Order("Harvest", self, null, xy, null);
|
||||
|
||||
return null;
|
||||
|
||||
@@ -106,9 +106,9 @@ namespace OpenRa.Traits
|
||||
|
||||
if (!crushable) return false;
|
||||
|
||||
return Rules.Map.IsInMap(a.X, a.Y) &&
|
||||
return Game.world.Map.IsInMap(a.X, a.Y) &&
|
||||
TerrainCosts.Cost(GetMovementType(),
|
||||
Rules.TileSet.GetWalkability(Rules.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||
Game.world.TileSet.GetWalkability(Game.world.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
|
||||
}
|
||||
|
||||
public IEnumerable<int2> GetCurrentPath()
|
||||
|
||||
@@ -45,11 +45,11 @@ namespace OpenRa.Traits
|
||||
var p = self.Location + new int2(i % size, i / size + bibOffset);
|
||||
if (isRemove)
|
||||
{
|
||||
if (Rules.Map.MapTiles[p.X, p.Y].smudge == (byte)(i + startIndex))
|
||||
Rules.Map.MapTiles[ p.X, p.Y ].smudge = 0;
|
||||
if (Game.world.Map.MapTiles[p.X, p.Y].smudge == (byte)(i + startIndex))
|
||||
Game.world.Map.MapTiles[ p.X, p.Y ].smudge = 0;
|
||||
}
|
||||
else
|
||||
Rules.Map.MapTiles[p.X, p.Y].smudge = (byte)(i + startIndex);
|
||||
Game.world.Map.MapTiles[p.X, p.Y].smudge = (byte)(i + startIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRa.Traits
|
||||
for (var i = -1; i < 2; i++)
|
||||
if (Game.SharedRandom.NextDouble() < info.Chance)
|
||||
if (Ore.CanSpreadInto(self.Location.X + i, self.Location.Y + j))
|
||||
Rules.Map.AddOre(self.Location.X + i, self.Location.Y + j);
|
||||
Game.world.Map.AddOre(self.Location.X + i, self.Location.Y + j);
|
||||
|
||||
ticks = info.Interval;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace OpenRa
|
||||
|
||||
foreach( var t in Footprint.Tiles( name, bi, position ) )
|
||||
spriteRenderer.DrawSprite( ( isCloseEnough && Game.IsCellBuildable( t, bi.WaterBound
|
||||
? UnitMovementType.Float : UnitMovementType.Wheel ) && !Rules.Map.ContainsResource( t ) )
|
||||
? UnitMovementType.Float : UnitMovementType.Wheel ) && !Game.world.Map.ContainsResource( t ) )
|
||||
? buildOk : buildBlocked, Game.CellSize * t, 0 );
|
||||
|
||||
spriteRenderer.Flush();
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRa.Effects;
|
||||
using OpenRa.Support;
|
||||
using OpenRa.FileFormats;
|
||||
|
||||
namespace OpenRa
|
||||
{
|
||||
@@ -11,6 +12,16 @@ namespace OpenRa
|
||||
List<IEffect> effects = new List<IEffect>();
|
||||
List<Action<World>> frameEndActions = new List<Action<World>>();
|
||||
|
||||
public readonly Map Map;
|
||||
public readonly TileSet TileSet;
|
||||
|
||||
public World()
|
||||
{
|
||||
Map = new Map( Rules.AllRules );
|
||||
FileSystem.MountTemporary( new Package( Map.Theater + ".mix" ) );
|
||||
TileSet = new TileSet( Map.TileSuffix );
|
||||
}
|
||||
|
||||
public void Add(Actor a)
|
||||
{
|
||||
a.IsInWorld = true;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
# Visual C# Express 2008
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.FileFormats", "OpenRa.FileFormats\OpenRa.FileFormats.csproj", "{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.Game", "OpenRa.Game\OpenRa.Game.csproj", "{0DFB103F-2962-400F-8C6D-E2C28CCBA633}"
|
||||
@@ -17,8 +17,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RulesConverter", "RulesConv
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.Mods.RA", "OpenRa.Mods.RA\OpenRa.Mods.RA.csproj", "{4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Mods", "Mods", "{F80861C1-DD5C-40A4-94B4-02D96318AE95}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.Mods.Aftermath", "OpenRa.Mods.Aftermath\OpenRa.Mods.Aftermath.csproj", "{2E1F8D8B-AEF5-4BCE-A95C-50223A0C7331}"
|
||||
EndProject
|
||||
Global
|
||||
|
||||
Reference in New Issue
Block a user