Less carp
This commit is contained in:
@@ -32,7 +32,7 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
public ProductionSurround(Actor self) : base(self) { }
|
public ProductionSurround(Actor self) : base(self) { }
|
||||||
|
|
||||||
static int2? FindAdjacentTile(Actor self, UnitMovementType umt)
|
static int2? FindAdjacentTile(Actor self, bool waterBound)
|
||||||
{
|
{
|
||||||
var tiles = Footprint.Tiles(self, self.traits.Get<Traits.Building>());
|
var tiles = Footprint.Tiles(self, self.traits.Get<Traits.Building>());
|
||||||
var min = tiles.Aggregate(int2.Min) - new int2(1, 1);
|
var min = tiles.Aggregate(int2.Min) - new int2(1, 1);
|
||||||
@@ -40,7 +40,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
for (var j = min.Y; j <= max.Y; j++)
|
for (var j = min.Y; j <= max.Y; j++)
|
||||||
for (var i = min.X; i <= max.X; i++)
|
for (var i = min.X; i <= max.X; i++)
|
||||||
if (self.World.IsCellBuildable(new int2(i, j), umt))
|
if (self.World.IsCellBuildable(new int2(i, j), waterBound))
|
||||||
return new int2(i, j);
|
return new int2(i, j);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -48,8 +48,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public override int2? CreationLocation(Actor self, ActorInfo producee)
|
public override int2? CreationLocation(Actor self, ActorInfo producee)
|
||||||
{
|
{
|
||||||
return FindAdjacentTile(self, producee.Traits.Get<OwnedActorInfo>().WaterBound ?
|
return FindAdjacentTile(self, producee.Traits.Get<OwnedActorInfo>().WaterBound);
|
||||||
UnitMovementType.Float : UnitMovementType.Wheel); /* hackety hack */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int CreationFacing(Actor self, Actor newUnit)
|
public override int CreationFacing(Actor self, Actor newUnit)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
* This file is part of OpenRA.
|
* This file is part of OpenRA.
|
||||||
@@ -53,7 +53,7 @@ namespace OpenRA.Traits
|
|||||||
for (var j = -1; j < 2; j++)
|
for (var j = -1; j < 2; j++)
|
||||||
for (var i = -1; i < 2; i++)
|
for (var i = -1; i < 2; i++)
|
||||||
if (self.World.SharedRandom.NextDouble() < info.Chance)
|
if (self.World.SharedRandom.NextDouble() < info.Chance)
|
||||||
if (self.World.IsCellBuildable(self.Location + new int2(i, j), UnitMovementType.Wheel))
|
if (self.World.IsCellBuildable(self.Location + new int2(i, j), false))
|
||||||
resLayer.AddResource(resourceType, self.Location.X + i, self.Location.Y + j, 1);
|
resLayer.AddResource(resourceType, self.Location.X + i, self.Location.Y + j, 1);
|
||||||
|
|
||||||
ticks = info.Interval;
|
ticks = info.Interval;
|
||||||
|
|||||||
@@ -62,13 +62,12 @@ namespace OpenRA.Traits
|
|||||||
void SpawnCrate(Actor self, CrateSpawnerInfo info)
|
void SpawnCrate(Actor self, CrateSpawnerInfo info)
|
||||||
{
|
{
|
||||||
var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance;
|
var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance;
|
||||||
var umt = inWater ? UnitMovementType.Float : UnitMovementType.Wheel;
|
|
||||||
|
|
||||||
for (var n = 0; n < ChooseCrateLocationAttempts; n++)
|
for (var n = 0; n < ChooseCrateLocationAttempts; n++)
|
||||||
{
|
{
|
||||||
var p = self.World.ChooseRandomCell(self.World.SharedRandom);
|
var p = self.World.ChooseRandomCell(self.World.SharedRandom);
|
||||||
|
|
||||||
if (self.World.IsCellBuildable(p, umt))
|
if (self.World.IsCellBuildable(p, inWater))
|
||||||
{
|
{
|
||||||
self.World.AddFrameEndTask(
|
self.World.AddFrameEndTask(
|
||||||
w => crates.Add(w.CreateActor("crate", p, self.World.NeutralPlayer)));
|
w => crates.Add(w.CreateActor("crate", p, self.World.NeutralPlayer)));
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ namespace OpenRA.Traits
|
|||||||
for (int i = mini; i < maxi; i++)
|
for (int i = mini; i < maxi; i++)
|
||||||
if (content[i,j].type == null
|
if (content[i,j].type == null
|
||||||
&& GetAdjacentCellsWith(info, i,j ) > 0
|
&& GetAdjacentCellsWith(info, i,j ) > 0
|
||||||
&& w.IsCellBuildable(new int2(i, j), UnitMovementType.Wheel))
|
&& w.IsCellBuildable(new int2(i, j), false))
|
||||||
growMask[i, j] = true;
|
growMask[i, j] = true;
|
||||||
|
|
||||||
for (int j = minj; j < maxj; j++)
|
for (int j = minj; j < maxj; j++)
|
||||||
|
|||||||
@@ -71,8 +71,7 @@ namespace OpenRA
|
|||||||
var res = world.WorldActor.traits.Get<ResourceLayer>();
|
var res = world.WorldActor.traits.Get<ResourceLayer>();
|
||||||
|
|
||||||
foreach( var t in Footprint.Tiles( name, bi, topLeft ) )
|
foreach( var t in Footprint.Tiles( name, bi, topLeft ) )
|
||||||
spriteRenderer.DrawSprite( ( isCloseEnough && world.IsCellBuildable( t, bi.WaterBound
|
spriteRenderer.DrawSprite( ( isCloseEnough && world.IsCellBuildable( t, bi.WaterBound) && res.GetResource(t) == null )
|
||||||
? UnitMovementType.Float : UnitMovementType.Wheel ) && res.GetResource(t) == null )
|
|
||||||
? buildOk : buildBlocked, Game.CellSize * t, "terrain" );
|
? buildOk : buildBlocked, Game.CellSize * t, "terrain" );
|
||||||
|
|
||||||
// Linebuild for walls.
|
// Linebuild for walls.
|
||||||
@@ -105,7 +104,7 @@ namespace OpenRA
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
int2 cell = topLeft + i * vecs[d];
|
int2 cell = topLeft + i * vecs[d];
|
||||||
if (world.IsCellBuildable(cell, bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel, null))
|
if (world.IsCellBuildable(cell, bi.WaterBound))
|
||||||
continue; // Cell is empty; continue search
|
continue; // Cell is empty; continue search
|
||||||
|
|
||||||
// Cell contains an actor. Is it the type we want?
|
// Cell contains an actor. Is it the type we want?
|
||||||
|
|||||||
@@ -38,16 +38,19 @@ namespace OpenRA
|
|||||||
return world.Map.IsInMap(a.X, a.Y) && TerrainCosts.Cost(umt, world.TileSet.GetTerrainType(world.Map.MapTiles[a.X,a.Y])) < double.PositiveInfinity;
|
return world.Map.IsInMap(a.X, a.Y) && TerrainCosts.Cost(umt, world.TileSet.GetTerrainType(world.Map.MapTiles[a.X,a.Y])) < double.PositiveInfinity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsCellBuildable(this World world, int2 a, UnitMovementType umt)
|
public static bool IsCellBuildable(this World world, int2 a, bool waterBound)
|
||||||
{
|
{
|
||||||
return world.IsCellBuildable(a, umt, null);
|
return world.IsCellBuildable(a, waterBound, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsCellBuildable(this World world, int2 a, UnitMovementType umt, Actor toIgnore)
|
public static bool IsCellBuildable(this World world, int2 a, bool waterBound, Actor toIgnore)
|
||||||
{
|
{
|
||||||
if (world.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(a) != null) return false;
|
if (world.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(a) != null) return false;
|
||||||
if (world.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(a).Any(b => b != toIgnore)) return false;
|
if (world.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(a).Any(b => b != toIgnore)) return false;
|
||||||
|
|
||||||
|
if (waterBound)
|
||||||
|
return world.Map.IsInMap(a.X,a.Y) && GetTerrainType(world,a) == TerrainMovementType.Water;
|
||||||
|
|
||||||
return world.Map.IsInMap(a.X, a.Y) && TerrainCosts.Buildable(world.TileSet.GetTerrainType(world.Map.MapTiles[a.X, a.Y]));
|
return world.Map.IsInMap(a.X, a.Y) && TerrainCosts.Buildable(world.TileSet.GetTerrainType(world.Map.MapTiles[a.X, a.Y]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,8 +139,7 @@ namespace OpenRA
|
|||||||
var res = world.WorldActor.traits.Get<ResourceLayer>();
|
var res = world.WorldActor.traits.Get<ResourceLayer>();
|
||||||
return !Footprint.Tiles(name, building, topLeft).Any(
|
return !Footprint.Tiles(name, building, topLeft).Any(
|
||||||
t => !world.Map.IsInMap(t.X, t.Y) || res.GetResource(t) != null || !world.IsCellBuildable(t,
|
t => !world.Map.IsInMap(t.X, t.Y) || res.GetResource(t) != null || !world.IsCellBuildable(t,
|
||||||
building.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel,
|
building.WaterBound, toIgnore));
|
||||||
toIgnore));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsCloseEnoughToBase(this World world, Player p, string buildingName, BuildingInfo bi, int2 topLeft)
|
public static bool IsCloseEnoughToBase(this World world, Player p, string buildingName, BuildingInfo bi, int2 topLeft)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||||
* This file is part of OpenRA.
|
* This file is part of OpenRA.
|
||||||
@@ -64,13 +64,12 @@ namespace OpenRA.Mods.RA_NG
|
|||||||
void SpawnCrate(Actor self, CrateDropInfo info)
|
void SpawnCrate(Actor self, CrateDropInfo info)
|
||||||
{
|
{
|
||||||
var threshold = 100;
|
var threshold = 100;
|
||||||
|
|
||||||
var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance;
|
var inWater = self.World.SharedRandom.NextDouble() < info.WaterChance;
|
||||||
var umt = inWater ? UnitMovementType.Float : UnitMovementType.Wheel;
|
|
||||||
for (var n = 0; n < threshold; n++ )
|
for (var n = 0; n < threshold; n++ )
|
||||||
{
|
{
|
||||||
var p = self.World.ChooseRandomCell(self.World.SharedRandom);
|
var p = self.World.ChooseRandomCell(self.World.SharedRandom);
|
||||||
if (self.World.IsCellBuildable(p, umt))
|
if (self.World.IsCellBuildable(p, inWater))
|
||||||
{
|
{
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user