Core: Added basic support for Spectators
TODO: Someone modify the files for cnc (chrome / rules)
This commit is contained in:
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA
|
||||
// create the players which are bound through slots.
|
||||
foreach (var slot in w.LobbyInfo.Slots)
|
||||
{
|
||||
var client = w.LobbyInfo.Clients.FirstOrDefault(c => c.Slot == slot.Index);
|
||||
var client = w.LobbyInfo.Clients.FirstOrDefault(c => c.Slot == slot.Index && slot.MapPlayer != null);
|
||||
if (client != null)
|
||||
{
|
||||
/* spawn a real player in this slot. */
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA
|
||||
if (client.Index == Game.LocalClientId)
|
||||
w.SetLocalPlayer(player.Index); // bind this one to the local player.
|
||||
}
|
||||
else if (slot.Bot != null)
|
||||
else if (slot.Bot != null && slot.MapPlayer != null)
|
||||
{
|
||||
/* spawn a bot in this slot, "owned" by the host */
|
||||
|
||||
@@ -80,6 +80,14 @@ namespace OpenRA.Mods.RA
|
||||
static Stance ChooseInitialStance(Player p, Player q)
|
||||
{
|
||||
if (p == q) return Stance.Ally;
|
||||
var pc = GetClientForPlayer(p);
|
||||
var qc = GetClientForPlayer(q);
|
||||
|
||||
if (p.World.LobbyInfo.Slots.Count > 0)
|
||||
{
|
||||
if (p.World.LobbyInfo.Slots[pc.Slot].Spectator) return Stance.Ally;
|
||||
if (p.World.LobbyInfo.Slots[qc.Slot].Spectator) return Stance.Ally;
|
||||
}
|
||||
|
||||
if (p.PlayerRef.Allies.Contains(q.InternalName))
|
||||
return Stance.Ally;
|
||||
@@ -92,8 +100,6 @@ namespace OpenRA.Mods.RA
|
||||
if (p.IsBot ^ q.IsBot)
|
||||
return Stance.Enemy; // bots and humans hate each other
|
||||
|
||||
var pc = GetClientForPlayer(p);
|
||||
var qc = GetClientForPlayer(q);
|
||||
|
||||
return pc.Team != 0 && pc.Team == qc.Team
|
||||
? Stance.Ally : Stance.Enemy;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Traits;
|
||||
using XRandom = OpenRA.Thirdparty.Random;
|
||||
using OpenRA.FileFormats;
|
||||
@@ -232,6 +233,10 @@ namespace OpenRA.Mods.RA
|
||||
return !hackyAI.enabled;
|
||||
}
|
||||
|
||||
bool HasHumanPlayers()
|
||||
{
|
||||
return p.World.players.Any(a => !a.Value.IsBot && !a.Value.NonCombatant);
|
||||
}
|
||||
int2? ChooseEnemyTarget()
|
||||
{
|
||||
// Criteria for picking an enemy:
|
||||
@@ -240,7 +245,7 @@ namespace OpenRA.Mods.RA
|
||||
// 3. not dead.
|
||||
|
||||
var possibleTargets = world.WorldActor.Trait<MPStartLocations>().Start
|
||||
.Where(kv => kv.Key != p && IsHumanPlayer(kv.Key)
|
||||
.Where(kv => kv.Key != p && (!HasHumanPlayers()|| IsHumanPlayer(kv.Key))
|
||||
&& p.WinState == WinState.Undefined)
|
||||
.Select(kv => kv.Value);
|
||||
|
||||
|
||||
@@ -28,13 +28,15 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public void WorldLoaded(World world)
|
||||
{
|
||||
var taken = world.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0)
|
||||
var taken = world.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0 && c.Slot != -1)
|
||||
.Select(c => world.Map.SpawnPoints.ElementAt(c.SpawnPoint - 1)).ToList();
|
||||
var available = world.Map.SpawnPoints.Except(taken).ToList();
|
||||
|
||||
// Set spawn
|
||||
foreach (var slot in world.LobbyInfo.Slots)
|
||||
{
|
||||
if (slot.Spectator)
|
||||
continue; // Skip spectator slots
|
||||
var client = world.LobbyInfo.Clients.FirstOrDefault(c => c.Slot == slot.Index);
|
||||
var player = FindPlayerInSlot(world, slot);
|
||||
|
||||
@@ -49,7 +51,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
// Explore allied shroud
|
||||
foreach (var p in Start)
|
||||
if (p.Key == world.LocalPlayer || p.Key.Stances[world.LocalPlayer] == Stance.Ally)
|
||||
if ((world.LocalPlayer != null ) &&(p.Key == world.LocalPlayer || p.Key.Stances[world.LocalPlayer] == Stance.Ally))
|
||||
world.WorldActor.Trait<Shroud>().Explore(world, p.Value,
|
||||
world.WorldActor.Info.Traits.Get<MPStartLocationsInfo>().InitialExploreRange);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
@@ -230,6 +230,7 @@
|
||||
<Compile Include="WaterPaletteRotation.cs" />
|
||||
<Compile Include="Weapon.cs" />
|
||||
<Compile Include="Widgets\BuildPaletteWidget.cs" />
|
||||
<Compile Include="Widgets\Delegates\IngameObserverChromeDelegate.cs" />
|
||||
<Compile Include="Widgets\Delegates\IngameChromeDelegate.cs" />
|
||||
<Compile Include="Widgets\MoneyBinWidget.cs" />
|
||||
<Compile Include="Widgets\OrderButtonWidget.cs" />
|
||||
|
||||
@@ -14,8 +14,9 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
public class OpenWidgetAtGameStartInfo : ITraitInfo
|
||||
{
|
||||
public readonly string Widget = "INGAME_ROOT";
|
||||
|
||||
public readonly string Widget = "INGAME_ROOT";
|
||||
public readonly string ObserverWidget = "";
|
||||
|
||||
public object Create(ActorInitializer init) { return new OpenWidgetAtGameStart(this); }
|
||||
}
|
||||
|
||||
@@ -29,9 +30,10 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public void WorldLoaded(World world)
|
||||
{
|
||||
// Todo: custom observer ui?
|
||||
if (world.LocalPlayer != null)
|
||||
world.OpenWindow(Info.Widget);
|
||||
world.OpenWindow(Info.Widget);
|
||||
else if (Info.ObserverWidget != null)
|
||||
world.OpenWindow(Info.ObserverWidget);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ 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. */
|
||||
return; /* they don't want an mcv, the map provides something else for them OR it is a spectator. */
|
||||
|
||||
p.World.CreateActor("mcv", new TypeDictionary
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user