Move ChooseRandomCell from WorldUtils to Map
This commit is contained in:
@@ -19,6 +19,7 @@ using OpenRA.FileSystem;
|
|||||||
using OpenRA.Network;
|
using OpenRA.Network;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Support;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
@@ -556,5 +557,12 @@ namespace OpenRA
|
|||||||
var r = Bounds;
|
var r = Bounds;
|
||||||
return xy.Clamp(new Rectangle(r.X, r.Y, r.Width - 1, r.Height - 1));
|
return xy.Clamp(new Rectangle(r.X, r.Y, r.Width - 1, r.Height - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CPos ChooseRandomCell(MersenneTwister r)
|
||||||
|
{
|
||||||
|
return new CPos(
|
||||||
|
r.Next(Bounds.Left, Bounds.Right),
|
||||||
|
r.Next(Bounds.Top, Bounds.Bottom));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,13 +100,6 @@ namespace OpenRA
|
|||||||
: (edge ? w.Map.Bounds.Top : w.Map.Bounds.Bottom));
|
: (edge ? w.Map.Bounds.Top : w.Map.Bounds.Bottom));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CPos ChooseRandomCell(this World w, MersenneTwister r)
|
|
||||||
{
|
|
||||||
return new CPos(
|
|
||||||
r.Next(w.Map.Bounds.Left, w.Map.Bounds.Right),
|
|
||||||
r.Next(w.Map.Bounds.Top, w.Map.Bounds.Bottom));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static WRange DistanceToMapEdge(this World w, WPos pos, WVec dir)
|
public static WRange DistanceToMapEdge(this World w, WPos pos, WVec dir)
|
||||||
{
|
{
|
||||||
var tl = w.Map.Bounds.TopLeftAsCPos().TopLeft;
|
var tl = w.Map.Bounds.TopLeftAsCPos().TopLeft;
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
for (var n = 0; n < maxTries; n++)
|
for (var n = 0; n < maxTries; n++)
|
||||||
{
|
{
|
||||||
var p = self.World.ChooseRandomCell(self.World.SharedRandom);
|
var p = self.World.Map.ChooseRandomCell(self.World.SharedRandom);
|
||||||
|
|
||||||
// Is this valid terrain?
|
// Is this valid terrain?
|
||||||
var terrainType = self.World.Map.GetTerrainInfo(p).Type;
|
var terrainType = self.World.Map.GetTerrainInfo(p).Type;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
[Desc("Returns a random cell inside the visible region of the map.")]
|
[Desc("Returns a random cell inside the visible region of the map.")]
|
||||||
public CPos RandomCell()
|
public CPos RandomCell()
|
||||||
{
|
{
|
||||||
return context.World.ChooseRandomCell(context.World.SharedRandom);
|
return context.World.Map.ChooseRandomCell(context.World.SharedRandom);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Desc("Returns a random cell on the visible border of the map.")]
|
[Desc("Returns a random cell on the visible border of the map.")]
|
||||||
|
|||||||
@@ -339,7 +339,7 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
[LuaGlobal]
|
[LuaGlobal]
|
||||||
public CPos GetRandomCell()
|
public CPos GetRandomCell()
|
||||||
{
|
{
|
||||||
return world.ChooseRandomCell(world.SharedRandom);
|
return world.Map.ChooseRandomCell(world.SharedRandom);
|
||||||
}
|
}
|
||||||
|
|
||||||
[LuaGlobal]
|
[LuaGlobal]
|
||||||
|
|||||||
Reference in New Issue
Block a user