mostly sensible init for real players and bots
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Traits;
|
||||
@@ -20,12 +19,31 @@ namespace OpenRA.Mods.RA
|
||||
public class CreateMPPlayers : ICreatePlayers
|
||||
{
|
||||
public void CreatePlayers(World w)
|
||||
{
|
||||
// Add real players
|
||||
w.SetLocalPlayer(Game.LocalClientId);
|
||||
|
||||
foreach (var c in Game.LobbyInfo.Clients)
|
||||
w.AddPlayer(new Player(w, c));
|
||||
{
|
||||
var playerIndex = 0;
|
||||
foreach (var slot in Game.LobbyInfo.Slots)
|
||||
{
|
||||
var client = Game.LobbyInfo.Clients.FirstOrDefault(c => c.Slot == slot.Index);
|
||||
if (client != null)
|
||||
{
|
||||
/* spawn a real player in this slot. */
|
||||
var player = new Player(w, client, w.Map.Players[slot.MapPlayer], playerIndex++);
|
||||
w.AddPlayer(player);
|
||||
if (client.Index == Game.LocalClientId)
|
||||
w.SetLocalPlayer(player.Index); // bind this one to the local player.
|
||||
}
|
||||
else if (slot.Bot != null)
|
||||
{
|
||||
/* spawn a bot in this slot, "owned" by the host */
|
||||
var player = new Player(w, w.Map.Players[slot.MapPlayer], playerIndex++);
|
||||
w.AddPlayer(player);
|
||||
|
||||
/* todo: init its bot -- but only on the host! */
|
||||
if (Game.IsHost)
|
||||
foreach (var bot in player.PlayerActor.TraitsImplementing<IBot>())
|
||||
bot.Activate(player);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var p in w.players.Values)
|
||||
foreach (var q in w.players.Values)
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
/* a pile of hacks, which control a local player on the host. */
|
||||
|
||||
class HackyAI : IGameStarted, ITick
|
||||
class HackyAI : ITick, IBot
|
||||
{
|
||||
bool enabled;
|
||||
int ticks;
|
||||
@@ -62,23 +62,14 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
BuildState state = BuildState.WaitForFeedback;
|
||||
|
||||
public void GameStarted(World w)
|
||||
/* called by the host's player creation code */
|
||||
public void Activate(Player p)
|
||||
{
|
||||
try
|
||||
{
|
||||
p = Game.world.players.First(c => c.Value.PlayerName.Equals("bot")).Value;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//Could not find a bot.
|
||||
}
|
||||
//p = Game.world.LocalPlayer;
|
||||
enabled = Game.IsHost && p != null;
|
||||
if (enabled)
|
||||
{
|
||||
productionQueue = p.PlayerActor.Trait<ProductionQueue>();
|
||||
playerResources = p.PlayerActor.Trait<PlayerResources>();
|
||||
}
|
||||
this.p = p;
|
||||
enabled = true;
|
||||
|
||||
productionQueue = p.PlayerActor.Trait<ProductionQueue>();
|
||||
playerResources = p.PlayerActor.Trait<PlayerResources>();
|
||||
}
|
||||
|
||||
int GetPowerProvidedBy(string building)
|
||||
@@ -341,6 +332,5 @@ namespace OpenRA.Mods.RA
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -238,7 +238,7 @@
|
||||
<Compile Include="CreateMapPlayers.cs" />
|
||||
<Compile Include="CreateMPPlayers.cs" />
|
||||
<Compile Include="LocalPlayerFromMap.cs" />
|
||||
<Compile Include="World\HackyAI.cs" />
|
||||
<Compile Include="HackyAI.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Traits;
|
||||
|
||||
@@ -28,6 +25,9 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
void SpawnUnitsForPlayer(Player p, int2 sp)
|
||||
{
|
||||
if (!p.PlayerRef.DefaultStartingUnits)
|
||||
return; /* they don't want an mcv, the map provides something else for them. */
|
||||
|
||||
p.World.CreateActor("mcv", new TypeDictionary
|
||||
{
|
||||
new LocationInit( sp ),
|
||||
|
||||
Reference in New Issue
Block a user