working game with bots; stop bots from trying to order husks around

This commit is contained in:
Chris Forbes
2010-08-25 20:05:02 +12:00
parent 701ef05562
commit f2dd0de1ea
3 changed files with 29 additions and 12 deletions

View File

@@ -58,7 +58,8 @@ namespace OpenRA
PlayerName = InternalName = pr.Name; PlayerName = InternalName = pr.Name;
NonCombatant = pr.NonCombatant; NonCombatant = pr.NonCombatant;
Country = world.GetCountries() Country = world.GetCountries()
.FirstOrDefault(c => pr.Race == c.Race); .FirstOrDefault(c => pr.Race == c.Race)
?? world.GetCountries().Random(world.SharedRandom);
PlayerRef = pr; PlayerRef = pr;

View File

@@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System; using System;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Network;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
@@ -30,10 +31,19 @@ namespace OpenRA.Traits
var available = world.Map.SpawnPoints.Except(taken).ToList(); var available = world.Map.SpawnPoints.Except(taken).ToList();
// Set spawn // Set spawn
foreach (var client in Game.LobbyInfo.Clients) foreach (var slot in Game.LobbyInfo.Slots)
Start.Add(world.players[client.Index],(client.SpawnPoint == 0) {
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Slot == slot.Index);
var player = FindPlayerInSlot(world, slot);
if (player == null) continue;
var spid = (client == null || client.SpawnPoint == 0)
? ChooseSpawnPoint(world, available, taken) ? ChooseSpawnPoint(world, available, taken)
: world.Map.SpawnPoints.ElementAt(client.SpawnPoint - 1)); : world.Map.SpawnPoints.ElementAt(client.SpawnPoint - 1);
Start.Add(player, spid);
}
// Explore allied shroud // Explore allied shroud
foreach (var p in Start) foreach (var p in Start)
@@ -46,6 +56,11 @@ namespace OpenRA.Traits
Game.viewport.Center(Start[world.LocalPlayer]); Game.viewport.Center(Start[world.LocalPlayer]);
} }
static Player FindPlayerInSlot(World world, Session.Slot slot)
{
return world.players.Values.FirstOrDefault(p => p.PlayerRef.Name == slot.MapPlayer);
}
static int2 ChooseSpawnPoint(World world, List<int2> available, List<int2> taken) static int2 ChooseSpawnPoint(World world, List<int2> available, List<int2> taken)
{ {
if (available.Count == 0) if (available.Count == 0)

View File

@@ -200,10 +200,8 @@ namespace OpenRA.Mods.RA
// which is a leading cause of blocking the spawn points :( // which is a leading cause of blocking the spawn points :(
int2 attackTarget = spawnPoints[random.Next(0, spawnPoints.Length)]; int2 attackTarget = spawnPoints[random.Next(0, spawnPoints.Length)];
foreach (var a in unitsHangingAroundTheBase) foreach (var a in unitsHangingAroundTheBase)
{ if (TryToMove(a, attackTarget))
attackForce.Add(a); attackForce.Add(a);
tryToMove(a, attackTarget);
}
unitsHangingAroundTheBase.Clear(); unitsHangingAroundTheBase.Clear();
} }
} }
@@ -235,8 +233,11 @@ namespace OpenRA.Mods.RA
//try very hard to find a valid move destination near the target. //try very hard to find a valid move destination near the target.
//(Don't accept a move onto the subject's current position. maybe this is already not allowed? ) //(Don't accept a move onto the subject's current position. maybe this is already not allowed? )
private bool tryToMove(Actor a, int2 desiredMoveTarget) private bool TryToMove(Actor a, int2 desiredMoveTarget)
{ {
if (!a.HasTrait<IMove>())
return false;
int2 xy; int2 xy;
int loopCount = 0; //avoid infinite loops. int loopCount = 0; //avoid infinite loops.
int range = 2; int range = 2;