Merge branch 'master' of git@github.com:beedee/OpenRA

This commit is contained in:
Bob
2009-11-04 21:22:09 +13:00
7 changed files with 35 additions and 11 deletions

View File

@@ -11,6 +11,7 @@ namespace OpenRa.Game
{
class BuildingInfluenceMap
{
bool[,] blocked = new bool[128, 128];
Pair<Actor, float>[,] influence = new Pair<Actor, float>[128, 128];
readonly int maxDistance; /* clip limit for voronoi cells */
static readonly Pair<Actor, float> NoClaim = Pair.New((Actor)null, float.MaxValue);
@@ -31,7 +32,7 @@ namespace OpenRa.Game
void AddInfluence(Actor a)
{
var tiles = Footprint.UnpathableTiles(a.unitInfo, a.Location).ToArray();
var tiles = Footprint.Tiles(a).ToArray();
var min = int2.Max(new int2(0, 0),
tiles.Aggregate(int2.Min) - new int2(maxDistance, maxDistance));
var max = int2.Min(new int2(128, 128),
@@ -41,6 +42,10 @@ namespace OpenRa.Game
var initialTileCount = 0;
foreach (var u in Footprint.UnpathableTiles(a.unitInfo, a.Location))
if (IsValid(u))
blocked[u.X, u.Y] = true;
foreach (var t in tiles)
if (IsValid(t))
{
@@ -98,11 +103,15 @@ namespace OpenRa.Game
void RemoveInfluence(Actor a)
{
var tiles = Footprint.UnpathableTiles(a.unitInfo, a.Location).ToArray();
var tiles = Footprint.Tiles(a).ToArray();
var min = int2.Max(new int2(0, 0),
tiles.Aggregate(int2.Min) - new int2(maxDistance, maxDistance));
var max = int2.Min(new int2(128, 128),
tiles.Aggregate(int2.Max) + new int2(maxDistance, maxDistance));
foreach (var u in Footprint.UnpathableTiles(a.unitInfo, a.Location))
if (IsValid(u))
blocked[u.X, u.Y] = false;
for (var j = min.Y; j <= max.Y; j++)
for (var i = min.X; i <= max.X; i++)
@@ -149,6 +158,11 @@ namespace OpenRa.Game
return (int)influence[cell.X, cell.Y].Second;
}
public bool CanMoveHere(int2 cell)
{
return IsValid(cell) && !blocked[cell.X, cell.Y];
}
struct Cell : IComparable<Cell>
{
public int2 location;

View File

@@ -143,6 +143,7 @@ namespace OpenRa.Game
public static int RenderFrame = 0;
public static double RenderTime = 0.0;
public static double TickTime = 0.0;
public static double OreTime = 0.0;
public static Stopwatch sw;
@@ -162,7 +163,9 @@ namespace OpenRa.Game
if (--oreTicks == 0)
{
map.GrowOre(p => IsCellBuildable(p, UnitMovementType.Wheel), SharedRandom);
var oresw = new Stopwatch();
map.GrowOre(p => IsCellBuildable(p, UnitMovementType.Wheel), SharedRandom);
OreTime = oresw.ElapsedTime();
oreTicks = oreFrequency;
}
world.Tick();

View File

@@ -99,10 +99,11 @@ namespace OpenRa.Game.Graphics
lineRenderer.Flush();
renderer.DrawText(string.Format("RenderFrame {0} ({2:F1} ms) Tick {1} ({3:F1} ms)",
renderer.DrawText(string.Format("RenderFrame {0} ({2:F1} ms) Tick {1} ({3:F1} ms) Ore ({4:F1} ms)",
Game.RenderFrame, Game.orderManager.FrameNumber,
Game.RenderTime * 1000,
Game.TickTime * 1000), new int2(5, 5), Color.White);
Game.TickTime * 1000,
Game.OreTime * 1000), new int2(5, 5), Color.White);
}
const float conditionYellow = 0.5f; /* todo: get these from gamerules */

View File

@@ -52,7 +52,7 @@ namespace OpenRa.Game
for( int i = 0 ; i < path.Count ; i++ )
{
var sl = path[ i ];
if( i == 0 || Game.BuildingInfluence.GetBuildingAt( path[ i ] ) == null & Game.UnitInfluence.GetUnitAt( path[ i ] ) == null )
if( i == 0 || (Game.BuildingInfluence.CanMoveHere(path[i]) && Game.UnitInfluence.GetUnitAt( path[ i ] ) == null) )
{
queue.Add( new PathDistance( estimator( sl ), sl ) );
cellInfo[ sl.X, sl.Y ] = new CellInfo( cost, prev, false );
@@ -105,7 +105,7 @@ namespace OpenRa.Game
continue;
if( passableCost[(int)umt][ newHere.X, newHere.Y ] == double.PositiveInfinity )
continue;
if (Game.BuildingInfluence.GetBuildingAt(newHere) != null)
if (!Game.BuildingInfluence.CanMoveHere(newHere))
continue;
if( checkForBlock && Game.UnitInfluence.GetUnitAt( newHere ) != null )
continue;

View File

@@ -15,6 +15,12 @@ namespace OpenRa.Game.Traits.Activities
{
if (isDone)
{
var harv = self.traits.Get<Harvester>();
/* todo: give cash */
harv.gemsCarried = 0;
harv.oreCarried = 0;
mobile.InternalSetActivity(NextActivity);
/* todo: return to the ore patch */
return;

View File

@@ -33,9 +33,9 @@ namespace OpenRa.Game.Traits.Activities
static bool CanEnterCell( int2 c, Actor self )
{
if (!Game.BuildingInfluence.CanMoveHere(c)) return false;
var u = Game.UnitInfluence.GetUnitAt( c );
var b = Game.BuildingInfluence.GetBuildingAt( c );
return ( u == null || u == self ) && b == null;
return (u == null || u == self);
}
public void Tick( Actor self, Mobile mobile )

View File

@@ -8,8 +8,8 @@ namespace OpenRa.Game.Traits
class Harvester : IOrder
{
const int capacity = 28;
int oreCarried = 0; /* sum of these must not exceed capacity */
int gemsCarried = 0;
public int oreCarried = 0; /* sum of these must not exceed capacity */
public int gemsCarried = 0;
public bool IsFull { get { return oreCarried + gemsCarried == capacity; } }
public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } }