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;
NonCombatant = pr.NonCombatant;
Country = world.GetCountries()
.FirstOrDefault(c => pr.Race == c.Race);
.FirstOrDefault(c => pr.Race == c.Race)
?? world.GetCountries().Random(world.SharedRandom);
PlayerRef = pr;

View File

@@ -11,7 +11,8 @@
using System.Collections.Generic;
using System.Linq;
using System;
using OpenRA.FileFormats;
using OpenRA.FileFormats;
using OpenRA.Network;
namespace OpenRA.Traits
{
@@ -29,11 +30,20 @@ namespace OpenRA.Traits
.Select(c => world.Map.SpawnPoints.ElementAt(c.SpawnPoint - 1)).ToList();
var available = world.Map.SpawnPoints.Except(taken).ToList();
// Set spawn
foreach (var client in Game.LobbyInfo.Clients)
Start.Add(world.players[client.Index],(client.SpawnPoint == 0)
? ChooseSpawnPoint(world, available, taken)
: world.Map.SpawnPoints.ElementAt(client.SpawnPoint - 1));
// Set spawn
foreach (var slot in Game.LobbyInfo.Slots)
{
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)
: world.Map.SpawnPoints.ElementAt(client.SpawnPoint - 1);
Start.Add(player, spid);
}
// Explore allied shroud
foreach (var p in Start)
@@ -44,6 +54,11 @@ namespace OpenRA.Traits
// Set viewport
if (world.LocalPlayer != null && Start.ContainsKey(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)

View File

@@ -200,10 +200,8 @@ namespace OpenRA.Mods.RA
// which is a leading cause of blocking the spawn points :(
int2 attackTarget = spawnPoints[random.Next(0, spawnPoints.Length)];
foreach (var a in unitsHangingAroundTheBase)
{
attackForce.Add(a);
tryToMove(a, attackTarget);
}
if (TryToMove(a, attackTarget))
attackForce.Add(a);
unitsHangingAroundTheBase.Clear();
}
}
@@ -235,8 +233,11 @@ namespace OpenRA.Mods.RA
//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? )
private bool tryToMove(Actor a, int2 desiredMoveTarget)
private bool TryToMove(Actor a, int2 desiredMoveTarget)
{
if (!a.HasTrait<IMove>())
return false;
int2 xy;
int loopCount = 0; //avoid infinite loops.
int range = 2;