Moves a few start location/spawn traits to Mods.Common.
This commit is contained in:
@@ -123,11 +123,15 @@
|
||||
<Compile Include="Widgets\MenuButtonWidget.cs" />
|
||||
<Compile Include="Widgets\RadarWidget.cs" />
|
||||
<Compile Include="Widgets\ResourceBarWidget.cs" />
|
||||
<Compile Include="World\CreateMPPlayers.cs" />
|
||||
<Compile Include="World\MPStartLocations.cs" />
|
||||
<Compile Include="World\MPStartUnits.cs" />
|
||||
<Compile Include="World\PlayMusicOnMapLoad.cs" />
|
||||
<Compile Include="World\RadarPings.cs" />
|
||||
<Compile Include="World\ResourceClaim.cs" />
|
||||
<Compile Include="World\ResourceClaimLayer.cs" />
|
||||
<Compile Include="World\SmudgeLayer.cs" />
|
||||
<Compile Include="World\SpawnMapActors.cs" />
|
||||
<Compile Include="SpriteLoaders\ShpTDLoader.cs" />
|
||||
<Compile Include="SpriteLoaders\ShpTSLoader.cs" />
|
||||
<Compile Include="SpriteLoaders\TmpRALoader.cs" />
|
||||
|
||||
97
OpenRA.Mods.Common/World/CreateMPPlayers.cs
Normal file
97
OpenRA.Mods.Common/World/CreateMPPlayers.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common
|
||||
{
|
||||
[Desc("Attach this to the world actor.")]
|
||||
public class CreateMPPlayersInfo : TraitInfo<CreateMPPlayers> { }
|
||||
|
||||
public class CreateMPPlayers : ICreatePlayers
|
||||
{
|
||||
public void CreatePlayers(World w)
|
||||
{
|
||||
// create the unplayable map players -- neutral, shellmap, scripted, etc.
|
||||
foreach (var kv in w.Map.Players.Where(p => !p.Value.Playable))
|
||||
{
|
||||
var player = new Player(w, null, null, kv.Value);
|
||||
w.AddPlayer(player);
|
||||
if (kv.Value.OwnsWorld)
|
||||
w.WorldActor.Owner = player;
|
||||
}
|
||||
|
||||
// create the players which are bound through slots.
|
||||
foreach (var kv in w.LobbyInfo.Slots)
|
||||
{
|
||||
var client = w.LobbyInfo.ClientInSlot(kv.Key);
|
||||
if (client == null)
|
||||
continue;
|
||||
|
||||
var player = new Player(w, client, kv.Value, w.Map.Players[kv.Value.PlayerReference]);
|
||||
w.AddPlayer(player);
|
||||
|
||||
if (client.Index == Game.LocalClientId)
|
||||
w.SetLocalPlayer(player.InternalName);
|
||||
}
|
||||
|
||||
// create a player that is allied with everyone for shared observer shroud
|
||||
w.AddPlayer(new Player(w, null, null, new PlayerReference
|
||||
{
|
||||
Name = "Everyone",
|
||||
NonCombatant = true,
|
||||
Spectating = true,
|
||||
Allies = w.Players.Where(p => !p.NonCombatant && p.Playable).Select(p => p.InternalName).ToArray()
|
||||
}));
|
||||
|
||||
foreach (var p in w.Players)
|
||||
foreach (var q in w.Players)
|
||||
if (!p.Stances.ContainsKey(q))
|
||||
p.Stances[q] = ChooseInitialStance(p, q);
|
||||
}
|
||||
|
||||
static Stance ChooseInitialStance(Player p, Player q)
|
||||
{
|
||||
if (p == q)
|
||||
return Stance.Ally;
|
||||
|
||||
if (q.Spectating && !p.NonCombatant && p.Playable)
|
||||
return Stance.Ally;
|
||||
|
||||
// Stances set via PlayerReference
|
||||
if (p.PlayerReference.Allies.Contains(q.InternalName))
|
||||
return Stance.Ally;
|
||||
if (p.PlayerReference.Enemies.Contains(q.InternalName))
|
||||
return Stance.Enemy;
|
||||
|
||||
// HACK: Map players share a ClientID with the host, so would
|
||||
// otherwise take the host's team stance instead of being neutral
|
||||
if (p.PlayerReference.Playable && q.PlayerReference.Playable)
|
||||
{
|
||||
// Stances set via lobby teams
|
||||
var pc = GetClientForPlayer(p);
|
||||
var qc = GetClientForPlayer(q);
|
||||
if (pc != null && qc != null)
|
||||
return pc.Team != 0 && pc.Team == qc.Team
|
||||
? Stance.Ally : Stance.Enemy;
|
||||
}
|
||||
|
||||
// Otherwise, default to neutral
|
||||
return Stance.Neutral;
|
||||
}
|
||||
|
||||
static Session.Client GetClientForPlayer(Player p)
|
||||
{
|
||||
return p.World.LobbyInfo.ClientWithIndex(p.ClientIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
89
OpenRA.Mods.Common/World/MPStartLocations.cs
Normal file
89
OpenRA.Mods.Common/World/MPStartLocations.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common
|
||||
{
|
||||
public class MPStartLocationsInfo : TraitInfo<MPStartLocations>
|
||||
{
|
||||
public readonly WRange InitialExploreRange = WRange.FromCells(5);
|
||||
}
|
||||
|
||||
public class MPStartLocations : IWorldLoaded
|
||||
{
|
||||
public Dictionary<Player, CPos> Start = new Dictionary<Player, CPos>();
|
||||
|
||||
public void WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
var spawns = world.Map.GetSpawnPoints().ToList();
|
||||
var taken = world.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0 && c.Slot != null)
|
||||
.Select(c => spawns[c.SpawnPoint-1]).ToList();
|
||||
var available = spawns.Except(taken).ToList();
|
||||
|
||||
// Set spawn
|
||||
foreach (var kv in world.LobbyInfo.Slots)
|
||||
{
|
||||
var player = FindPlayerInSlot(world, kv.Key);
|
||||
if (player == null) continue;
|
||||
|
||||
var client = world.LobbyInfo.ClientInSlot(kv.Key);
|
||||
var spid = (client == null || client.SpawnPoint == 0)
|
||||
? ChooseSpawnPoint(world, available, taken)
|
||||
: spawns[client.SpawnPoint-1];
|
||||
|
||||
Start.Add(player, spid);
|
||||
|
||||
player.SpawnPoint = (client == null || client.SpawnPoint == 0)
|
||||
? spawns.IndexOf(spid) + 1
|
||||
: client.SpawnPoint;
|
||||
}
|
||||
|
||||
// Explore allied shroud
|
||||
var explore = world.WorldActor.Info.Traits.Get<MPStartLocationsInfo>().InitialExploreRange;
|
||||
foreach (var p in Start.Keys)
|
||||
foreach (var q in world.Players)
|
||||
if (p.IsAlliedWith(q))
|
||||
q.Shroud.Explore(world, Start[p], explore);
|
||||
|
||||
// Set viewport
|
||||
if (world.LocalPlayer != null && Start.ContainsKey(world.LocalPlayer))
|
||||
wr.Viewport.Center(world.Map.CenterOfCell(Start[world.LocalPlayer]));
|
||||
}
|
||||
|
||||
static Player FindPlayerInSlot(World world, string pr)
|
||||
{
|
||||
return world.Players.FirstOrDefault(p => p.PlayerReference.Name == pr);
|
||||
}
|
||||
|
||||
static CPos ChooseSpawnPoint(World world, List<CPos> available, List<CPos> taken)
|
||||
{
|
||||
if (available.Count == 0)
|
||||
throw new InvalidOperationException("No free spawnpoint.");
|
||||
|
||||
var n = taken.Count == 0
|
||||
? world.SharedRandom.Next(available.Count)
|
||||
: available // pick the most distant spawnpoint from everyone else
|
||||
.Select((k, i) => Pair.New(k, i))
|
||||
.MaxBy(a => taken.Sum(t => (t - a.First).LengthSquared)).Second;
|
||||
|
||||
var sp = available[n];
|
||||
available.RemoveAt(n);
|
||||
taken.Add(sp);
|
||||
return sp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
41
OpenRA.Mods.Common/World/MPStartUnits.cs
Normal file
41
OpenRA.Mods.Common/World/MPStartUnits.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common
|
||||
{
|
||||
[Desc("Used by SpawnMPUnits. Attach these to the world actor. You can have multiple variants by adding @suffixes.")]
|
||||
public class MPStartUnitsInfo : TraitInfo<MPStartUnits>
|
||||
{
|
||||
[Desc("Internal class ID.")]
|
||||
public readonly string Class = "none";
|
||||
|
||||
[Desc("Exposed via the UI to the player.")]
|
||||
public readonly string ClassName = "Unlabeled";
|
||||
|
||||
[Desc("Only available when selecting this faction.", "Leave empty for no restrictions.")]
|
||||
public readonly string[] Races = { };
|
||||
|
||||
[Desc("The mobile construction vehicle.")]
|
||||
public readonly string BaseActor = null;
|
||||
|
||||
[Desc("A group of units ready to defend or scout.")]
|
||||
public readonly string[] SupportActors = { };
|
||||
|
||||
[Desc("Inner radius for spawning support actors")]
|
||||
public readonly int InnerSupportRadius = 2;
|
||||
|
||||
[Desc("Outer radius for spawning support actors")]
|
||||
public readonly int OuterSupportRadius = 4;
|
||||
}
|
||||
|
||||
public class MPStartUnits { }
|
||||
}
|
||||
44
OpenRA.Mods.Common/World/SpawnMapActors.cs
Normal file
44
OpenRA.Mods.Common/World/SpawnMapActors.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common
|
||||
{
|
||||
public class SpawnMapActorsInfo : TraitInfo<SpawnMapActors> { }
|
||||
|
||||
public class SpawnMapActors : IWorldLoaded
|
||||
{
|
||||
public Dictionary<string, Actor> Actors = new Dictionary<string, Actor>();
|
||||
public uint LastMapActorID { get; private set; }
|
||||
|
||||
public void WorldLoaded(World world, WorldRenderer wr)
|
||||
{
|
||||
foreach (var actorReference in world.Map.Actors.Value)
|
||||
{
|
||||
// if there is no real player associated, dont spawn it.
|
||||
var ownerName = actorReference.Value.InitDict.Get<OwnerInit>().PlayerName;
|
||||
if (!world.Players.Any(p => p.InternalName == ownerName))
|
||||
continue;
|
||||
|
||||
var initDict = actorReference.Value.InitDict;
|
||||
initDict.Add(new SkipMakeAnimsInit());
|
||||
var actor = world.CreateActor(actorReference.Value.Type, initDict);
|
||||
Actors[actorReference.Key] = actor;
|
||||
LastMapActorID = actor.ActorID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SkipMakeAnimsInit : IActorInit {}
|
||||
}
|
||||
Reference in New Issue
Block a user