Ore.cs is dead. Long live ResourceLayer.cs.
This commit is contained in:
@@ -120,11 +120,13 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
if (oreLayer == null)
|
if (oreLayer == null)
|
||||||
{
|
{
|
||||||
|
var res = world.WorldActor.traits.Get<ResourceLayer>();
|
||||||
var colors = terrainTypeColors[world.Map.Theater.ToLowerInvariant()];
|
var colors = terrainTypeColors[world.Map.Theater.ToLowerInvariant()];
|
||||||
|
|
||||||
oreLayer = new Bitmap(terrain);
|
oreLayer = new Bitmap(terrain);
|
||||||
for (var y = world.Map.YOffset; y < world.Map.YOffset + world.Map.Height; y++)
|
for (var y = world.Map.YOffset; y < world.Map.YOffset + world.Map.Height; y++)
|
||||||
for (var x = world.Map.XOffset; x < world.Map.XOffset + world.Map.Width; x++)
|
for (var x = world.Map.XOffset; x < world.Map.XOffset + world.Map.Width; x++)
|
||||||
if (world.Map.ContainsResource(new int2(x, y)))
|
if (res.GetResource(new int2(x,y)) != null)
|
||||||
oreLayer.SetPixel(x, y, colors[(int)TerrainMovementType.Ore]);
|
oreLayer.SetPixel(x, y, colors[(int)TerrainMovementType.Ore]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,6 @@
|
|||||||
<Compile Include="Network\OrderManager.cs" />
|
<Compile Include="Network\OrderManager.cs" />
|
||||||
<Compile Include="Orders\RepairOrderGenerator.cs" />
|
<Compile Include="Orders\RepairOrderGenerator.cs" />
|
||||||
<Compile Include="Orders\SellOrderGenerator.cs" />
|
<Compile Include="Orders\SellOrderGenerator.cs" />
|
||||||
<Compile Include="Ore.cs" />
|
|
||||||
<Compile Include="PackageDownloader.cs" />
|
<Compile Include="PackageDownloader.cs" />
|
||||||
<Compile Include="PathSearch.cs" />
|
<Compile Include="PathSearch.cs" />
|
||||||
<Compile Include="Selection.cs" />
|
<Compile Include="Selection.cs" />
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
#region Copyright & License Information
|
|
||||||
/*
|
|
||||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
|
||||||
* This file is part of OpenRA.
|
|
||||||
*
|
|
||||||
* OpenRA is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* OpenRA is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using OpenRA.FileFormats;
|
|
||||||
using OpenRA.Traits;
|
|
||||||
|
|
||||||
namespace OpenRA
|
|
||||||
{
|
|
||||||
public static class Ore
|
|
||||||
{
|
|
||||||
static bool HasOverlay(this Map map, int i, int j)
|
|
||||||
{
|
|
||||||
return map.MapTiles[i, j].overlay < overlayIsOre.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ContainsOre(this Map map, int i, int j)
|
|
||||||
{
|
|
||||||
return map.HasOverlay(i, j) && overlayIsOre[map.MapTiles[i, j].overlay];
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool ContainsGem(this Map map, int i, int j)
|
|
||||||
{
|
|
||||||
return map.HasOverlay(i, j) && overlayIsGems[map.MapTiles[i, j].overlay];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool ContainsResource(this Map map, int2 p)
|
|
||||||
{
|
|
||||||
return map.ContainsGem(p.X, p.Y) || map.ContainsOre(p.X, p.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool[] overlayIsOre =
|
|
||||||
{
|
|
||||||
false, false, false, false, false,
|
|
||||||
true, true, true, true,
|
|
||||||
false, false, false, false,
|
|
||||||
false, false, false, false, false, false, false,
|
|
||||||
false, false, false, false, false,
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool[] overlayIsGems =
|
|
||||||
{
|
|
||||||
false, false, false, false, false,
|
|
||||||
false, false, false, false,
|
|
||||||
true, true, true, true,
|
|
||||||
false, false, false, false, false, false, false,
|
|
||||||
false, false, false, false, false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -64,12 +64,14 @@ namespace OpenRA.Traits.Activities
|
|||||||
|
|
||||||
void FindMoreOre(Actor self)
|
void FindMoreOre(Actor self)
|
||||||
{
|
{
|
||||||
|
var res = self.World.WorldActor.traits.Get<ResourceLayer>();
|
||||||
|
|
||||||
self.QueueActivity(new Move(
|
self.QueueActivity(new Move(
|
||||||
() =>
|
() =>
|
||||||
{
|
{
|
||||||
var search = new PathSearch
|
var search = new PathSearch
|
||||||
{
|
{
|
||||||
heuristic = loc => (self.World.Map.ContainsResource(loc) ? 0 : 1),
|
heuristic = loc => (res.GetResource(loc) != null ? 0 : 1),
|
||||||
umt = UnitMovementType.Wheel,
|
umt = UnitMovementType.Wheel,
|
||||||
checkForBlocked = true
|
checkForBlocked = true
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ namespace OpenRA.Traits
|
|||||||
&& underCursor.traits.Contains<IAcceptOre>() && !IsEmpty)
|
&& underCursor.traits.Contains<IAcceptOre>() && !IsEmpty)
|
||||||
return new Order("Deliver", self, underCursor);
|
return new Order("Deliver", self, underCursor);
|
||||||
|
|
||||||
if (underCursor == null && self.World.Map.ContainsResource(xy))
|
if (underCursor == null && self.World.WorldActor.traits.Get<ResourceLayer>().GetResource(xy) != null)
|
||||||
return new Order("Harvest", self, xy);
|
return new Order("Harvest", self, xy);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace OpenRA.Traits
|
|||||||
World w;
|
World w;
|
||||||
|
|
||||||
public ResourceTypeInfo[] resourceTypes;
|
public ResourceTypeInfo[] resourceTypes;
|
||||||
public CellContents[,] content = new CellContents[128, 128];
|
CellContents[,] content = new CellContents[128, 128];
|
||||||
|
|
||||||
public ResourceLayer(Actor self)
|
public ResourceLayer(Actor self)
|
||||||
{
|
{
|
||||||
@@ -185,6 +185,8 @@ namespace OpenRA.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResourceTypeInfo GetResource(int2 p) { return content[p.X, p.Y].type; }
|
||||||
|
|
||||||
public struct CellContents
|
public struct CellContents
|
||||||
{
|
{
|
||||||
public ResourceTypeInfo type;
|
public ResourceTypeInfo type;
|
||||||
|
|||||||
@@ -67,10 +67,11 @@ namespace OpenRA
|
|||||||
var position = Game.controller.MousePosition.ToInt2();
|
var position = Game.controller.MousePosition.ToInt2();
|
||||||
var topLeft = position - Footprint.AdjustForBuildingSize( bi );
|
var topLeft = position - Footprint.AdjustForBuildingSize( bi );
|
||||||
var isCloseEnough = world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, topLeft);
|
var isCloseEnough = world.IsCloseEnoughToBase(world.LocalPlayer, name, bi, topLeft);
|
||||||
|
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
|
||||||
? UnitMovementType.Float : UnitMovementType.Wheel ) && !world.Map.ContainsResource( t ) )
|
? 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.
|
||||||
|
|||||||
@@ -149,8 +149,9 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore)
|
public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore)
|
||||||
{
|
{
|
||||||
|
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) || world.Map.ContainsResource(t) || !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 ? UnitMovementType.Float : UnitMovementType.Wheel,
|
||||||
toIgnore));
|
toIgnore));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user