map.Offset is no long necessary in so many places. (removed BS where world-coords != map-coords)

This commit is contained in:
Bob
2009-10-29 22:10:54 +13:00
parent 066ce1a203
commit be39cdd054
8 changed files with 145 additions and 154 deletions

View File

@@ -14,15 +14,15 @@ namespace OpenRa.Game
class Actor class Actor
{ {
public readonly TypeDictionary traits = new TypeDictionary(); public readonly TypeDictionary traits = new TypeDictionary();
public readonly UnitInfo unitInfo; public readonly UnitInfo unitInfo;
public readonly uint ActorID; public readonly uint ActorID;
public int2 Location; public int2 Location;
public Player Owner; public Player Owner;
public int Health; public int Health;
public Actor( string name, int2 location, Player owner ) public Actor( string name, int2 location, Player owner )
{ {
ActorID = Game.world.NextAID(); ActorID = Game.world.NextAID();
unitInfo = Rules.UnitInfo[ name ]; unitInfo = Rules.UnitInfo[ name ];
Location = location; Location = location;
@@ -44,9 +44,9 @@ namespace OpenRa.Game
+ "; add Traits= to units.ini for appropriate unit" ); + "; add Traits= to units.ini for appropriate unit" );
} }
public Actor( TreeReference tree, TreeCache treeRenderer, int2 mapOffset ) public Actor( TreeReference tree, TreeCache treeRenderer )
{ {
Location = new int2( tree.Location ) - mapOffset; Location = new int2( tree.Location );
traits.Add( new Traits.Tree( treeRenderer.GetImage( tree.Image ) ) ); traits.Add( new Traits.Tree( treeRenderer.GetImage( tree.Image ) ) );
} }

View File

@@ -24,8 +24,8 @@ namespace OpenRa.Game
public static Viewport viewport; public static Viewport viewport;
public static PathFinder PathFinder; public static PathFinder PathFinder;
public static WorldRenderer worldRenderer; public static WorldRenderer worldRenderer;
public static Controller controller; public static Controller controller;
public static OrderManager orderManager; public static OrderManager orderManager;
static int localPlayerIndex; static int localPlayerIndex;
@@ -36,8 +36,8 @@ namespace OpenRa.Game
public static BuildingInfluenceMap BuildingInfluence; public static BuildingInfluenceMap BuildingInfluence;
public static UnitInfluenceMap UnitInfluence; public static UnitInfluenceMap UnitInfluence;
static ISoundEngine soundEngine; static ISoundEngine soundEngine;
public static string Replay; public static string Replay;
public static void Initialize(string mapName, Renderer renderer, int2 clientSize, int localPlayer) public static void Initialize(string mapName, Renderer renderer, int2 clientSize, int localPlayer)
@@ -51,16 +51,16 @@ namespace OpenRa.Game
var mapFile = new IniFile(FileSystem.Open(mapName)); var mapFile = new IniFile(FileSystem.Open(mapName));
map = new Map(mapFile); map = new Map(mapFile);
FileSystem.Mount(new Package(map.Theater + ".mix")); FileSystem.Mount(new Package(map.Theater + ".mix"));
viewport = new Viewport(clientSize, map.Size, renderer); viewport = new Viewport( clientSize, map.Offset, map.Offset + map.Size, renderer );
terrain = new TerrainRenderer(renderer, map, viewport); terrain = new TerrainRenderer(renderer, map, viewport);
world = new World(); world = new World();
treeCache = new TreeCache(map); treeCache = new TreeCache(map);
foreach (TreeReference treeReference in map.Trees) foreach (TreeReference treeReference in map.Trees)
world.Add(new Actor(treeReference, treeCache, map.Offset)); world.Add(new Actor(treeReference, treeCache));
BuildingInfluence = new BuildingInfluenceMap(8); BuildingInfluence = new BuildingInfluenceMap(8);
UnitInfluence = new UnitInfluenceMap(); UnitInfluence = new UnitInfluenceMap();
@@ -74,10 +74,10 @@ namespace OpenRa.Game
worldRenderer = new WorldRenderer(renderer); worldRenderer = new WorldRenderer(renderer);
soundEngine = new ISoundEngine(); soundEngine = new ISoundEngine();
sounds = new Cache<string, ISoundSource>(LoadSound); sounds = new Cache<string, ISoundSource>(LoadSound);
orderManager = (Replay == "") orderManager = (Replay == "")
? new OrderManager(new[] { new LocalOrderSource() }, "replay.rep") ? new OrderManager(new[] { new LocalOrderSource() }, "replay.rep")
: new OrderManager(new[] { new ReplayOrderSource(Replay) }); : new OrderManager(new[] { new ReplayOrderSource(Replay) });
PlaySound("intro.aud", false); PlaySound("intro.aud", false);
@@ -90,7 +90,7 @@ namespace OpenRa.Game
//num=owner,type,health,location,facing,trigger,unknown,shouldRepair //num=owner,type,health,location,facing,trigger,unknown,shouldRepair
var parts = s.Value.ToLowerInvariant().Split( ',' ); var parts = s.Value.ToLowerInvariant().Split( ',' );
var loc = int.Parse( parts[ 3 ] ); var loc = int.Parse( parts[ 3 ] );
world.Add( new Actor( parts[ 1 ], new int2( loc % 128 - map.Offset.X, loc / 128-map.Offset.Y ), players[ 0 ] ) ); world.Add( new Actor( parts[ 1 ], new int2( loc % 128, loc / 128 ), players[ 0 ] ) );
} }
} }
@@ -101,7 +101,7 @@ namespace OpenRa.Game
//num=owner,type,health,location,facing,action,trigger //num=owner,type,health,location,facing,action,trigger
var parts = s.Value.ToLowerInvariant().Split( ',' ); var parts = s.Value.ToLowerInvariant().Split( ',' );
var loc = int.Parse( parts[ 3 ] ); var loc = int.Parse( parts[ 3 ] );
world.Add( new Actor( parts[ 1 ], new int2( loc % 128 - map.Offset.X, loc / 128 - map.Offset.Y ), players[ 0 ] ) ); world.Add( new Actor( parts[ 1 ], new int2( loc % 128, loc / 128 ), players[ 0 ] ) );
} }
} }
@@ -132,8 +132,8 @@ namespace OpenRa.Game
world.Update(); world.Update();
UnitInfluence.Tick(); UnitInfluence.Tick();
viewport.DrawRegions(); viewport.DrawRegions();
orderManager.Tick(); orderManager.Tick();
} }
@@ -142,8 +142,6 @@ namespace OpenRa.Game
if (BuildingInfluence.GetBuildingAt(a) != null) return false; if (BuildingInfluence.GetBuildingAt(a) != null) return false;
if (UnitInfluence.GetUnitAt(a) != null) return false; if (UnitInfluence.GetUnitAt(a) != null) return false;
a += map.Offset;
return map.IsInMap(a.X, a.Y) && return map.IsInMap(a.X, a.Y) &&
TerrainCosts.Cost(umt, TerrainCosts.Cost(umt,
terrain.tileSet.GetWalkability(map.MapTiles[a.X, a.Y])) < double.PositiveInfinity; terrain.tileSet.GetWalkability(map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
@@ -253,8 +251,8 @@ namespace OpenRa.Game
var mobile = unit.traits.Get<Mobile>(); var mobile = unit.traits.Get<Mobile>();
mobile.facing = 128; mobile.facing = 128;
mobile.QueueActivity(new Mobile.MoveTo(unit.Location + new int2(0, 3))); mobile.QueueActivity(new Mobile.MoveTo(unit.Location + new int2(0, 3)));
} }
world.Add(unit); world.Add(unit);
if (producer.traits.Contains<RenderWarFactory>()) if (producer.traits.Contains<RenderWarFactory>())

View File

@@ -73,7 +73,7 @@ namespace OpenRa.Game.Graphics
{ {
var location = new int2(x, y); var location = new int2(x, y);
spriteRenderer.DrawSprite(smudgeSprites[tr.smudge - 1], spriteRenderer.DrawSprite(smudgeSprites[tr.smudge - 1],
Game.CellSize * (float2)(location - map.Offset), 0); Game.CellSize * (float2)location, 0);
} }
var o = tr.overlay; var o = tr.overlay;
@@ -86,7 +86,7 @@ namespace OpenRa.Game.Graphics
else if (overlayIsOre[o]) spriteIndex = 11; else if (overlayIsOre[o]) spriteIndex = 11;
else if (overlayIsGems[o]) spriteIndex = 2; else if (overlayIsGems[o]) spriteIndex = 2;
spriteRenderer.DrawSprite(sprites[spriteIndex], spriteRenderer.DrawSprite(sprites[spriteIndex],
Game.CellSize * (float2)(location - map.Offset), 0); Game.CellSize * (float2)location, 0);
} }
} }

View File

@@ -1,89 +1,89 @@
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using Ijw.DirectX; using Ijw.DirectX;
using IjwFramework.Collections; using IjwFramework.Collections;
using OpenRa.FileFormats; using OpenRa.FileFormats;
namespace OpenRa.Game.Graphics namespace OpenRa.Game.Graphics
{ {
class TerrainRenderer class TerrainRenderer
{ {
FvfVertexBuffer<Vertex> vertexBuffer; FvfVertexBuffer<Vertex> vertexBuffer;
IndexBuffer indexBuffer; IndexBuffer indexBuffer;
Sheet terrainSheet; Sheet terrainSheet;
public TileSet tileSet; public TileSet tileSet;
Region region; Region region;
Renderer renderer; Renderer renderer;
Map map; Map map;
Viewport viewport; Viewport viewport;
OverlayRenderer overlayRenderer; OverlayRenderer overlayRenderer;
public TerrainRenderer(Renderer renderer, Map map, Viewport viewport) public TerrainRenderer(Renderer renderer, Map map, Viewport viewport)
{ {
this.renderer = renderer; this.renderer = renderer;
this.viewport = viewport; this.viewport = viewport;
region = Region.Create(viewport, DockStyle.Left, viewport.Width - 128, Draw, null ); region = Region.Create(viewport, DockStyle.Left, viewport.Width - 128, Draw, null );
viewport.AddRegion(region); viewport.AddRegion(region);
this.map = map; this.map = map;
overlayRenderer = new OverlayRenderer( renderer, map ); overlayRenderer = new OverlayRenderer( renderer, map );
tileSet = new TileSet( map.TileSuffix ); tileSet = new TileSet( map.TileSuffix );
Size tileSize = new Size( Game.CellSize, Game.CellSize ); Size tileSize = new Size( Game.CellSize, Game.CellSize );
SheetBuilder.ForceNewSheet(); SheetBuilder.ForceNewSheet();
var tileMapping = new Cache<TileReference, Sprite>( var tileMapping = new Cache<TileReference, Sprite>(
x => SheetBuilder.Add(tileSet.GetBytes(x), tileSize)); x => SheetBuilder.Add(tileSet.GetBytes(x), tileSize));
Vertex[] vertices = new Vertex[4 * map.Height * map.Width]; Vertex[] vertices = new Vertex[4 * map.Height * map.Width];
ushort[] indices = new ushort[6 * map.Height * map.Width]; ushort[] indices = new ushort[6 * map.Height * map.Width];
int nv = 0; int nv = 0;
int ni = 0; int ni = 0;
for( int j = 0 ; j < map.Height ; j++ ) for( int j = map.YOffset ; j < map.YOffset + map.Height ; j++ )
for (int i = 0; i < map.Width; i++) for( int i = map.XOffset ; i < map.XOffset + map.Width; i++ )
{ {
Sprite tile = tileMapping[map.MapTiles[i + map.XOffset, j + map.YOffset]]; Sprite tile = tileMapping[map.MapTiles[i, j]];
Util.FastCreateQuad(vertices, indices, Game.CellSize * new float2(i, j), tile, 0, nv, ni); Util.FastCreateQuad(vertices, indices, Game.CellSize * new float2(i, j), tile, 0, nv, ni);
nv += 4; nv += 4;
ni += 6; ni += 6;
} }
terrainSheet = tileMapping[map.MapTiles[map.XOffset, map.YOffset]].sheet; terrainSheet = tileMapping[map.MapTiles[map.XOffset, map.YOffset]].sheet;
vertexBuffer = new FvfVertexBuffer<Vertex>( renderer.Device, vertices.Length, Vertex.Format ); vertexBuffer = new FvfVertexBuffer<Vertex>( renderer.Device, vertices.Length, Vertex.Format );
vertexBuffer.SetData( vertices ); vertexBuffer.SetData( vertices );
indexBuffer = new IndexBuffer( renderer.Device, indices.Length ); indexBuffer = new IndexBuffer( renderer.Device, indices.Length );
indexBuffer.SetData( indices ); indexBuffer.SetData( indices );
} }
void Draw() void Draw()
{ {
int indicesPerRow = map.Width * 6; int indicesPerRow = map.Width * 6;
int verticesPerRow = map.Width * 4; int verticesPerRow = map.Width * 4;
int visibleRows = (int)(region.Size.Y / 24.0f + 2); int visibleRows = (int)(region.Size.Y / 24.0f + 2);
int firstRow = (int)((region.Position.Y + viewport.Location.Y) / 24.0f); int firstRow = 0;// (int)( ( region.Position.Y + viewport.Location.Y ) / 24.0f );
int lastRow = firstRow + visibleRows; int lastRow = 128;// firstRow + visibleRows;
if (lastRow < 0 || firstRow > map.Height) if (lastRow < 0 || firstRow > map.Height)
return; return;
if (firstRow < 0) firstRow = 0; if (firstRow < 0) firstRow = 0;
if (lastRow > map.Height) lastRow = map.Height; if (lastRow > map.Height) lastRow = map.Height;
renderer.SpriteShader.Quality = ShaderQuality.Low; renderer.SpriteShader.Quality = ShaderQuality.Low;
renderer.SpriteShader.Render(() => renderer.SpriteShader.Render(() =>
renderer.DrawBatch(vertexBuffer, indexBuffer, renderer.DrawBatch(vertexBuffer, indexBuffer,
new Range<int>(verticesPerRow * firstRow, verticesPerRow * lastRow), new Range<int>(verticesPerRow * firstRow, verticesPerRow * lastRow),
new Range<int>(indicesPerRow * firstRow, indicesPerRow * lastRow), new Range<int>(indicesPerRow * firstRow, indicesPerRow * lastRow),
terrainSheet.Texture, PrimitiveType.TriangleList)); terrainSheet.Texture, PrimitiveType.TriangleList));
overlayRenderer.Draw(); overlayRenderer.Draw();
} }
} }
} }

View File

@@ -6,35 +6,36 @@ namespace OpenRa.Game.Graphics
{ {
class Viewport class Viewport
{ {
readonly float2 size; readonly float2 screenSize;
readonly float2 mapSize;
float2 scrollPosition; float2 scrollPosition;
readonly Renderer renderer; readonly Renderer renderer;
public float2 Location { get { return scrollPosition; } } public float2 Location { get { return scrollPosition; } }
public float2 Size { get { return size; } }
public int Width { get { return (int)size.X; } } public int Width { get { return (int)screenSize.X; } }
public int Height { get { return (int)size.Y; } } public int Height { get { return (int)screenSize.Y; } }
public Cursor cursor = Cursor.Move; public Cursor cursor = Cursor.Move;
SpriteRenderer cursorRenderer; SpriteRenderer cursorRenderer;
int2 mousePos; int2 mousePos;
float cursorFrame = 0f; float cursorFrame = 0f;
readonly float2 scrollLowBounds, scrollHighBounds;
public void Scroll(float2 delta) public void Scroll(float2 delta)
{ {
scrollPosition = ( scrollPosition + delta ).Constrain( float2.Zero, mapSize ); scrollPosition = ( scrollPosition + delta ).Constrain( scrollLowBounds, scrollHighBounds );
} }
public Viewport(float2 size, float2 mapSize, Renderer renderer) public Viewport(float2 screenSize, int2 mapStart, int2 mapEnd, Renderer renderer)
{ {
this.size = size; this.screenSize = screenSize;
this.mapSize = Game.CellSize * mapSize - size + new float2(128, 0); this.scrollLowBounds = Game.CellSize * mapStart;
if( this.mapSize.X < 0 ) this.mapSize.X = 0; this.scrollHighBounds = float2.Max( scrollLowBounds, Game.CellSize * mapEnd - ( screenSize - new float2( 128, 0 ) ) );
if( this.mapSize.Y < 0 ) this.mapSize.Y = 0;
this.renderer = renderer; this.renderer = renderer;
cursorRenderer = new SpriteRenderer(renderer, true); cursorRenderer = new SpriteRenderer(renderer, true);
this.scrollPosition = scrollLowBounds;
} }
List<Region> regions = new List<Region>(); List<Region> regions = new List<Region>();
@@ -43,7 +44,7 @@ namespace OpenRa.Game.Graphics
public void DrawRegions() public void DrawRegions()
{ {
float2 r1 = new float2(2, -2) / Size; float2 r1 = new float2(2, -2) / screenSize;
float2 r2 = new float2(-1, 1); float2 r2 = new float2(-1, 1);
renderer.BeginFrame(r1, r2, scrollPosition); renderer.BeginFrame(r1, r2, scrollPosition);

View File

@@ -51,7 +51,7 @@ namespace OpenRa.Game
SheetBuilder.Initialize(renderer); SheetBuilder.Initialize(renderer);
UiOverlay.ShowUnitDebug = settings.GetValue("udebug", false); UiOverlay.ShowUnitDebug = settings.GetValue("udebug", false);
WorldRenderer.ShowUnitPaths = settings.GetValue("pathdebug", false); WorldRenderer.ShowUnitPaths = settings.GetValue("pathdebug", false);
Game.Replay = settings.GetValue("replay", ""); Game.Replay = settings.GetValue("replay", "");
Game.Initialize(settings.GetValue("map", "scg11eb.ini"), renderer, new int2(ClientSize), Game.Initialize(settings.GetValue("map", "scg11eb.ini"), renderer, new int2(ClientSize),
@@ -59,14 +59,11 @@ namespace OpenRa.Game
SequenceProvider.ForcePrecache(); SequenceProvider.ForcePrecache();
Game.world.Add( new Actor( "mcv", new int2( 5, 5 ), Game.players[ 1 ]) ); Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 5, 5 ), Game.players[ 1 ]) );
Game.world.Add( new Actor( "mcv", new int2( 7, 5 ), Game.players[ 2 ] ) ); Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 7, 5 ), Game.players[ 2 ] ) );
Game.world.Add( new Actor( "mcv", new int2( 9, 5 ), Game.players[ 0 ] ) ); Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 9, 5 ), Game.players[ 0 ] ) );
var jeep = new Actor( "jeep", new int2( 9, 15 ), Game.players[ 1 ] ); Game.world.Add( new Actor( "jeep", Game.map.Offset + new int2( 9, 15 ), Game.players[ 1 ] ) );
Game.world.Add( jeep ); Game.world.Add( new Actor( "3tnk", Game.map.Offset + new int2( 12, 7 ), Game.players[ 1 ] ) );
var tank = new Actor( "3tnk", new int2( 12, 7 ), Game.players[ 1 ] );
Game.world.Add( tank );
tank.traits.Get<Traits.AttackTurreted>().target = jeep;
sidebar = new Sidebar(renderer); sidebar = new Sidebar(renderer);

View File

@@ -34,8 +34,7 @@ namespace OpenRa.Game
public List<int2> FindUnitPathToRange(int2 src, int2 dest, UnitMovementType umt, int range) public List<int2> FindUnitPathToRange(int2 src, int2 dest, UnitMovementType umt, int range)
{ {
var tilesInRange = Game.FindTilesInCircle(dest, range) var tilesInRange = Game.FindTilesInCircle(dest, range)
.Where(t => Game.IsCellBuildable(t, umt)) .Where(t => Game.IsCellBuildable(t, umt));
.Select(t => t + map.Offset);
var path = FindUnitPath(tilesInRange, DefaultEstimator(src), umt); var path = FindUnitPath(tilesInRange, DefaultEstimator(src), umt);
path.Reverse(); path.Reverse();
@@ -44,19 +43,18 @@ namespace OpenRa.Game
public List<int2> FindPathToPath( int2 from, List<int2> path, UnitMovementType umt ) public List<int2> FindPathToPath( int2 from, List<int2> path, UnitMovementType umt )
{ {
var offset = map.Offset;
var cellInfo = InitCellInfo(); var cellInfo = InitCellInfo();
var queue = new PriorityQueue<PathDistance>(); var queue = new PriorityQueue<PathDistance>();
var estimator = DefaultEstimator( from ); var estimator = DefaultEstimator( from );
var cost = 0.0; var cost = 0.0;
var prev = path[ 0 ] + offset; var prev = path[ 0 ];
for( int i = 0 ; i < path.Count ; i++ ) for( int i = 0 ; i < path.Count ; i++ )
{ {
var sl = path[ i ] + offset; var sl = path[ i ];
if( i == 0 || Game.BuildingInfluence.GetBuildingAt( path[ i ] ) == null & Game.UnitInfluence.GetUnitAt( path[ i ] ) == null ) if( i == 0 || Game.BuildingInfluence.GetBuildingAt( path[ i ] ) == null & Game.UnitInfluence.GetUnitAt( path[ i ] ) == null )
{ {
queue.Add( new PathDistance( estimator( sl - offset ), sl ) ); queue.Add( new PathDistance( estimator( sl ), sl ) );
cellInfo[ sl.X, sl.Y ] = new CellInfo( cost, prev, false ); cellInfo[ sl.X, sl.Y ] = new CellInfo( cost, prev, false );
} }
var d = sl - prev; var d = sl - prev;
@@ -70,19 +68,17 @@ namespace OpenRa.Game
List<int2> FindUnitPath( int2 unitLocation, Func<int2,double> estimator, UnitMovementType umt ) List<int2> FindUnitPath( int2 unitLocation, Func<int2,double> estimator, UnitMovementType umt )
{ {
var startLocation = unitLocation + map.Offset; return FindUnitPath( new[] { unitLocation }, estimator, umt );
return FindUnitPath( new[] {startLocation}, estimator, umt );
} }
List<int2> FindUnitPath(IEnumerable<int2> startLocations, Func<int2, double> estimator, UnitMovementType umt) List<int2> FindUnitPath(IEnumerable<int2> startLocations, Func<int2, double> estimator, UnitMovementType umt)
{ {
var offset = map.Offset;
var cellInfo = InitCellInfo(); var cellInfo = InitCellInfo();
var queue = new PriorityQueue<PathDistance>(); var queue = new PriorityQueue<PathDistance>();
foreach (var sl in startLocations) foreach (var sl in startLocations)
{ {
queue.Add(new PathDistance(estimator(sl - offset), sl)); queue.Add(new PathDistance(estimator(sl), sl));
cellInfo[sl.X, sl.Y].MinCost = 0; cellInfo[sl.X, sl.Y].MinCost = 0;
} }
@@ -91,7 +87,6 @@ namespace OpenRa.Game
List<int2> FindPath( CellInfo[ , ] cellInfo, PriorityQueue<PathDistance> queue, Func<int2, double> estimator, UnitMovementType umt, bool checkForBlock ) List<int2> FindPath( CellInfo[ , ] cellInfo, PriorityQueue<PathDistance> queue, Func<int2, double> estimator, UnitMovementType umt, bool checkForBlock )
{ {
var offset = map.Offset;
while( !queue.Empty ) while( !queue.Empty )
{ {
@@ -99,8 +94,8 @@ namespace OpenRa.Game
int2 here = p.Location; int2 here = p.Location;
cellInfo[ here.X, here.Y ].Seen = true; cellInfo[ here.X, here.Y ].Seen = true;
if( estimator( here - offset ) == 0.0 ) if( estimator( here ) == 0.0 )
return MakePath( cellInfo, here, offset ); return MakePath( cellInfo, here );
foreach( int2 d in Util.directions ) foreach( int2 d in Util.directions )
{ {
@@ -110,9 +105,9 @@ namespace OpenRa.Game
continue; continue;
if( passableCost[(int)umt][ newHere.X, newHere.Y ] == double.PositiveInfinity ) if( passableCost[(int)umt][ newHere.X, newHere.Y ] == double.PositiveInfinity )
continue; continue;
if (Game.BuildingInfluence.GetBuildingAt(newHere - offset) != null) if (Game.BuildingInfluence.GetBuildingAt(newHere) != null)
continue; continue;
if( checkForBlock && Game.UnitInfluence.GetUnitAt( newHere - offset ) != null ) if( checkForBlock && Game.UnitInfluence.GetUnitAt( newHere ) != null )
continue; continue;
double cellCost = ( ( d.X * d.Y != 0 ) ? 1.414213563 : 1.0 ) * passableCost[(int)umt][ newHere.X, newHere.Y ]; double cellCost = ( ( d.X * d.Y != 0 ) ? 1.414213563 : 1.0 ) * passableCost[(int)umt][ newHere.X, newHere.Y ];
@@ -124,7 +119,7 @@ namespace OpenRa.Game
cellInfo[ newHere.X, newHere.Y ].Path = here; cellInfo[ newHere.X, newHere.Y ].Path = here;
cellInfo[ newHere.X, newHere.Y ].MinCost = newCost; cellInfo[ newHere.X, newHere.Y ].MinCost = newCost;
queue.Add( new PathDistance( newCost + estimator( newHere - offset ), newHere ) ); queue.Add( new PathDistance( newCost + estimator( newHere ), newHere ) );
} }
} }
@@ -141,18 +136,18 @@ namespace OpenRa.Game
return cellInfo; return cellInfo;
} }
List<int2> MakePath( CellInfo[ , ] cellInfo, int2 destination, int2 offset ) List<int2> MakePath( CellInfo[ , ] cellInfo, int2 destination )
{ {
List<int2> ret = new List<int2>(); List<int2> ret = new List<int2>();
int2 pathNode = destination; int2 pathNode = destination;
while( cellInfo[ pathNode.X, pathNode.Y ].Path != pathNode ) while( cellInfo[ pathNode.X, pathNode.Y ].Path != pathNode )
{ {
ret.Add( pathNode - offset ); ret.Add( pathNode );
pathNode = cellInfo[ pathNode.X, pathNode.Y ].Path; pathNode = cellInfo[ pathNode.X, pathNode.Y ].Path;
} }
ret.Add(pathNode - offset); ret.Add(pathNode);
return ret; return ret;
} }

View File

@@ -30,7 +30,7 @@ namespace OpenRa.Game.Traits
for (int i = 0; i < 2 * size; i++) for (int i = 0; i < 2 * size; i++)
{ {
var p = self.Location + Game.map.Offset + new int2(i % size, i / size + bibOffset); var p = self.Location + new int2(i % size, i / size + bibOffset);
Game.map.MapTiles[p.X, p.Y].smudge = (byte)(i + startIndex); Game.map.MapTiles[p.X, p.Y].smudge = (byte)(i + startIndex);
} }
} }