mostly sensible init for real players and bots
This commit is contained in:
@@ -37,6 +37,7 @@ namespace OpenRA
|
||||
public readonly int Index;
|
||||
public readonly bool NonCombatant = false;
|
||||
public readonly int ClientIndex;
|
||||
public readonly PlayerReference PlayerRef;
|
||||
|
||||
public ShroudRenderer Shroud;
|
||||
public World World { get; private set; }
|
||||
@@ -59,27 +60,30 @@ namespace OpenRA
|
||||
Country = world.GetCountries()
|
||||
.FirstOrDefault(c => pr.Race == c.Race);
|
||||
|
||||
PlayerRef = pr;
|
||||
|
||||
RegisterPlayerColor(world, Palette);
|
||||
}
|
||||
|
||||
public Player( World world, Session.Client client )
|
||||
public Player( World world, Session.Client client, PlayerReference pr, int index )
|
||||
{
|
||||
World = world;
|
||||
Shroud = new ShroudRenderer(this, world.Map);
|
||||
|
||||
PlayerActor = world.CreateActor("Player", new TypeDictionary{ new OwnerInit( this ) });
|
||||
|
||||
Index = client.Index;
|
||||
Palette = "player"+client.Index;
|
||||
Index = index;
|
||||
Palette = "player"+index;
|
||||
Color = client.Color1;
|
||||
Color2 = client.Color2;
|
||||
PlayerName = client.Name;
|
||||
InternalName = "Multi{0}".F(client.Index);
|
||||
InternalName = pr.Name;
|
||||
Country = world.GetCountries()
|
||||
.FirstOrDefault(c => client != null && client.Country == c.Race)
|
||||
?? world.GetCountries().Random(world.SharedRandom);
|
||||
|
||||
ClientIndex = client.Index;
|
||||
PlayerRef = pr;
|
||||
|
||||
RegisterPlayerColor(world, Palette);
|
||||
}
|
||||
|
||||
@@ -163,6 +163,8 @@ namespace OpenRA.Traits
|
||||
public interface IGameStarted { void GameStarted(World w); }
|
||||
public interface ICreatePlayers { void CreatePlayers(World w); }
|
||||
|
||||
public interface IBot { void Activate(Player p); }
|
||||
|
||||
public interface IActivity
|
||||
{
|
||||
IActivity NextActivity { get; set; }
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Traits;
|
||||
@@ -21,11 +20,30 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
public void CreatePlayers(World w)
|
||||
{
|
||||
// Add real players
|
||||
w.SetLocalPlayer(Game.LocalClientId);
|
||||
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);
|
||||
|
||||
foreach (var c in Game.LobbyInfo.Clients)
|
||||
w.AddPlayer(new Player(w, c));
|
||||
/* 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