remove more uses of Game.world

This commit is contained in:
Bob
2010-10-02 09:33:36 +12:00
committed by Paul Chote
parent 0002e80a19
commit f41aa474aa
4 changed files with 28 additions and 26 deletions

View File

@@ -21,10 +21,10 @@ namespace OpenRA.Network
return Game.LobbyInfo.Clients.FirstOrDefault(c => c.Index == id);
}
static Player FindPlayerByClientId(int id)
static Player FindPlayerByClientId( this World world, int id)
{
/* todo: find the interactive player. */
return Game.world.players.Values.FirstOrDefault(p => p.ClientIndex == id);
return world.players.Values.FirstOrDefault(p => p.ClientIndex == id);
}
public static void ProcessOrder( World world, int clientId, Order order )
@@ -43,7 +43,7 @@ namespace OpenRA.Network
var client = FindClientById(clientId);
if (client != null)
{
var player = FindPlayerByClientId(clientId);
var player = world.FindPlayerByClientId(clientId);
if (player != null && player.WinState == WinState.Lost)
Game.AddChatLine(client.Color1, client.Name + " (Dead)", order.TargetString);
else
@@ -56,7 +56,7 @@ namespace OpenRA.Network
var client = FindClientById(clientId);
if (client != null)
{
var player = FindPlayerByClientId(clientId);
var player = world.FindPlayerByClientId(clientId);
var display = (world.GameHasStarted) ?
player != null && (world.LocalPlayer != null && player.Stances[world.LocalPlayer] == Stance.Ally
|| player.WinState == WinState.Lost) :

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Traits
{
DisableShroud ^= true;
if (self.World.LocalPlayer == self.Owner)
Game.world.LocalPlayer.Shroud.Disabled = DisableShroud;
self.World.LocalPlayer.Shroud.Disabled = DisableShroud;
break;
}
case "DevPathDebug":

View File

@@ -158,7 +158,7 @@ namespace OpenRA.Traits
void DrawUnitPath(Actor self)
{
if (!Game.world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().PathDebug) return;
if (!self.World.LocalPlayer.PlayerActor.Trait<DeveloperMode>().PathDebug) return;
var activity = self.GetCurrentActivity();
var mobile = self.TraitOrDefault<IMove>();

View File

@@ -45,6 +45,8 @@ namespace OpenRA.Mods.RA
int2 baseCenter;
XRandom random = new XRandom(); //we do not use the synced random number generator.
World world { get { return p.PlayerActor.World; } }
Dictionary<string, float> unitsToBuild = new Dictionary<string, float>
{
{"e1", .0f},
@@ -171,9 +173,9 @@ namespace OpenRA.Mods.RA
var bi = Rules.Info[item.Item].Traits.Get<BuildingInfo>();
for (var k = 0; k < MaxBaseDistance; k++)
foreach (var t in Game.world.FindTilesInCircle(baseCenter, k))
if (Game.world.CanPlaceBuilding(item.Item, bi, t, null))
if (Game.world.IsCloseEnoughToBase(p, item.Item, bi, t))
foreach (var t in world.FindTilesInCircle(baseCenter, k))
if (world.CanPlaceBuilding(item.Item, bi, t, null))
if (world.IsCloseEnoughToBase(p, item.Item, bi, t))
return t;
return null; // i don't know where to put it.
@@ -237,7 +239,7 @@ namespace OpenRA.Mods.RA
// 2. human.
// 3. not dead.
var possibleTargets = Game.world.WorldActor.Trait<MPStartLocations>().Start
var possibleTargets = world.WorldActor.Trait<MPStartLocations>().Start
.Where(kv => kv.Key != p && IsHumanPlayer(kv.Key)
&& p.WinState == WinState.Undefined)
.Select(kv => kv.Value);
@@ -305,8 +307,8 @@ namespace OpenRA.Mods.RA
private int2 ChooseRallyLocationNear(int2 startPos)
{
Random r = new Random();
foreach (var t in Game.world.FindTilesInCircle(startPos, 8))
if (Game.world.IsCellBuildable(t, false) && t != startPos && r.Next(64) == 0)
foreach (var t in world.FindTilesInCircle(startPos, 8))
if (world.IsCellBuildable(t, false) && t != startPos && r.Next(64) == 0)
return t;
return startPos; // i don't know where to put it.
@@ -353,7 +355,7 @@ namespace OpenRA.Mods.RA
private void BuildRandom(string category)
{
// Pick a free queue
var queue = Game.world.Queries.WithTraitMultiple<ProductionQueue>()
var queue = world.Queries.WithTraitMultiple<ProductionQueue>()
.Where(a => a.Actor.Owner == p &&
a.Trait.Info.Type == category &&
a.Trait.CurrentItem() == null)
@@ -386,7 +388,7 @@ namespace OpenRA.Mods.RA
private void BuildBuildings()
{
// Pick a free queue
var queue = Game.world.Queries.WithTraitMultiple<ProductionQueue>()
var queue = world.Queries.WithTraitMultiple<ProductionQueue>()
.Where(a => a.Actor.Owner == p && a.Trait.Info.Type == "Building")
.Select(a => a.Trait)
.FirstOrDefault();
@@ -448,7 +450,7 @@ namespace OpenRA.Mods.RA
private void BuildDefense()
{
// Pick a free queue
var queue = Game.world.Queries.WithTraitMultiple<ProductionQueue>()
var queue = world.Queries.WithTraitMultiple<ProductionQueue>()
.Where(a => a.Actor.Owner == p && a.Trait.Info.Type == "Defense")
.Select(a => a.Trait)
.FirstOrDefault();