Smarter unit spawn logic. Fixes #3496.
This commit is contained in:
@@ -22,6 +22,7 @@ namespace OpenRA.FileFormats
|
|||||||
public bool Playable = false;
|
public bool Playable = false;
|
||||||
public string Bot = null;
|
public string Bot = null;
|
||||||
public bool DefaultStartingUnits = false;
|
public bool DefaultStartingUnits = false;
|
||||||
|
public string StartingUnitsClass;
|
||||||
public bool AllowBots = true;
|
public bool AllowBots = true;
|
||||||
public bool Required = false;
|
public bool Required = false;
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ namespace OpenRA.Network
|
|||||||
public bool Dedicated;
|
public bool Dedicated;
|
||||||
public string Difficulty;
|
public string Difficulty;
|
||||||
public bool Crates = true;
|
public bool Crates = true;
|
||||||
|
public string StartingUnitsClass = "default";
|
||||||
public bool AllowVersionMismatch;
|
public bool AllowVersionMismatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
32
OpenRA.Mods.RA/MPStartUnits.cs
Normal file
32
OpenRA.Mods.RA/MPStartUnits.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2011 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.FileFormats;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA
|
||||||
|
{
|
||||||
|
public class MPStartUnitsInfo : TraitInfo<MPStartUnits>
|
||||||
|
{
|
||||||
|
public readonly string Class = "default";
|
||||||
|
public readonly string[] Races = { };
|
||||||
|
|
||||||
|
public readonly string BaseActor = null;
|
||||||
|
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 { }
|
||||||
|
}
|
||||||
@@ -458,6 +458,7 @@
|
|||||||
<Compile Include="Widgets\ResourceBarWidget.cs" />
|
<Compile Include="Widgets\ResourceBarWidget.cs" />
|
||||||
<Compile Include="Widgets\Logic\SimpleTooltipLogic.cs" />
|
<Compile Include="Widgets\Logic\SimpleTooltipLogic.cs" />
|
||||||
<Compile Include="World\DomainIndex.cs" />
|
<Compile Include="World\DomainIndex.cs" />
|
||||||
|
<Compile Include="MPStartUnits.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
* 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
|
* available to you under the terms of the GNU General Public License
|
||||||
* as published by the Free Software Foundation. For more information,
|
* as published by the Free Software Foundation. For more information,
|
||||||
@@ -8,45 +8,74 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Mods.RA.Move;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
class SpawnMPUnitsInfo : ITraitInfo, Requires<MPStartLocationsInfo>
|
public class SpawnMPUnitsInfo : TraitInfo<SpawnMPUnits>, Requires<MPStartLocationsInfo>, Requires<MPStartUnitsInfo> { }
|
||||||
|
|
||||||
|
public class SpawnMPUnits : IWorldLoaded
|
||||||
{
|
{
|
||||||
public readonly string InitialUnit = "mcv";
|
|
||||||
public readonly string Faction = null;
|
|
||||||
|
|
||||||
public object Create (ActorInitializer init) { return new SpawnMPUnits(this); }
|
|
||||||
}
|
|
||||||
|
|
||||||
class SpawnMPUnits : IWorldLoaded
|
|
||||||
{
|
|
||||||
SpawnMPUnitsInfo info;
|
|
||||||
|
|
||||||
public SpawnMPUnits(SpawnMPUnitsInfo info) { this.info = info; }
|
|
||||||
|
|
||||||
public void WorldLoaded(World world)
|
public void WorldLoaded(World world)
|
||||||
{
|
{
|
||||||
foreach (var s in world.WorldActor.Trait<MPStartLocations>().Start)
|
foreach (var s in world.WorldActor.Trait<MPStartLocations>().Start)
|
||||||
SpawnUnitsForPlayer(s.Key, s.Value);
|
SpawnUnitsForPlayer(world, s.Key, s.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpawnUnitsForPlayer(Player p, CPos sp)
|
void SpawnUnitsForPlayer(World w, Player p, CPos sp)
|
||||||
{
|
{
|
||||||
|
// They don't want a MCV - the map provides something else for them
|
||||||
if (!p.PlayerReference.DefaultStartingUnits)
|
if (!p.PlayerReference.DefaultStartingUnits)
|
||||||
return; /* they don't want an mcv, the map provides something else for them */
|
|
||||||
|
|
||||||
/* support different starting units for each faction */
|
|
||||||
if (info.Faction != null && p.Country.Race != info.Faction)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p.World.CreateActor(info.InitialUnit, new TypeDictionary
|
var spawnClass = p.PlayerReference.StartingUnitsClass ?? w.LobbyInfo.GlobalSettings.StartingUnitsClass;
|
||||||
|
var unitGroup = Rules.Info["world"].Traits.WithInterface<MPStartUnitsInfo>()
|
||||||
|
.Where(g => g.Class == spawnClass && g.Races != null && g.Races.Contains(p.Country.Race))
|
||||||
|
.RandomOrDefault(w.SharedRandom);
|
||||||
|
|
||||||
|
if (unitGroup == null)
|
||||||
|
throw new InvalidOperationException("No starting units defined for country {0} with class {1}".F(p.Country.Race, spawnClass));
|
||||||
|
|
||||||
|
// Spawn base actor at the spawnpoint
|
||||||
|
if (unitGroup.BaseActor != null)
|
||||||
{
|
{
|
||||||
new LocationInit( sp ),
|
w.CreateActor(unitGroup.BaseActor.ToLowerInvariant(), new TypeDictionary
|
||||||
new OwnerInit( p ),
|
{
|
||||||
});
|
new LocationInit(sp),
|
||||||
|
new OwnerInit(p),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!unitGroup.SupportActors.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Spawn support units in an annulus around the base actor
|
||||||
|
var supportSpawnCells = w.FindTilesInCircle(sp, unitGroup.OuterSupportRadius)
|
||||||
|
.Except(w.FindTilesInCircle(sp, unitGroup.InnerSupportRadius));
|
||||||
|
|
||||||
|
foreach (var s in unitGroup.SupportActors)
|
||||||
|
{
|
||||||
|
var mi = Rules.Info[s.ToLowerInvariant()].Traits.Get<MobileInfo>();
|
||||||
|
var validCells = supportSpawnCells.Where(c => mi.CanEnterCell(w, c));
|
||||||
|
if (!validCells.Any())
|
||||||
|
throw new InvalidOperationException("No cells available to spawn starting unit {0}".F(s));
|
||||||
|
|
||||||
|
var cell = validCells.Random(w.SharedRandom);
|
||||||
|
var subCell = w.ActorMap.FreeSubCell(cell).Value;
|
||||||
|
|
||||||
|
w.CreateActor(s.ToLowerInvariant(), new TypeDictionary
|
||||||
|
{
|
||||||
|
new OwnerInit(p),
|
||||||
|
new LocationInit(cell),
|
||||||
|
new SubCellInit(subCell),
|
||||||
|
new FacingInit(w.SharedRandom.Next(256))
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -307,9 +307,12 @@ World:
|
|||||||
Depths:5,5,5,5,5,5
|
Depths:5,5,5,5,5,5
|
||||||
DebugOverlay:
|
DebugOverlay:
|
||||||
SpawnMapActors:
|
SpawnMapActors:
|
||||||
CreateMPPlayers:
|
|
||||||
SpawnMPUnits:
|
|
||||||
MPStartLocations:
|
MPStartLocations:
|
||||||
|
CreateMPPlayers:
|
||||||
|
MPStartUnits:
|
||||||
|
Races: gdi, nod
|
||||||
|
BaseActor: mcv
|
||||||
|
SpawnMPUnits:
|
||||||
SpatialBins:
|
SpatialBins:
|
||||||
BinSize: 4
|
BinSize: 4
|
||||||
CrateSpawner:
|
CrateSpawner:
|
||||||
|
|||||||
@@ -380,15 +380,16 @@ World:
|
|||||||
SpawnMapActors:
|
SpawnMapActors:
|
||||||
CreateMPPlayers:
|
CreateMPPlayers:
|
||||||
MPStartLocations:
|
MPStartLocations:
|
||||||
SpawnMPUnits@atreides:
|
MPStartUnits@atreides:
|
||||||
InitialUnit: mcva
|
Races: atreides
|
||||||
Faction: atreides
|
BaseActor: mcva
|
||||||
SpawnMPUnits@harkonnen:
|
MPStartUnits@harkonnen:
|
||||||
InitialUnit: mcvh
|
Races: harkonnen
|
||||||
Faction: harkonnen
|
BaseActor: mcvh
|
||||||
SpawnMPUnits@ordos:
|
MPStartUnits@ordos:
|
||||||
InitialUnit: mcvo
|
Races: ordos
|
||||||
Faction: ordos
|
BaseActor: mcvo
|
||||||
|
SpawnMPUnits:
|
||||||
SpatialBins:
|
SpatialBins:
|
||||||
BinSize: 4
|
BinSize: 4
|
||||||
PathFinder:
|
PathFinder:
|
||||||
|
|||||||
@@ -639,6 +639,9 @@ World:
|
|||||||
DebugOverlay:
|
DebugOverlay:
|
||||||
SpawnMapActors:
|
SpawnMapActors:
|
||||||
CreateMPPlayers:
|
CreateMPPlayers:
|
||||||
|
MPStartUnits:
|
||||||
|
Races: soviet, allies
|
||||||
|
BaseActor: mcv
|
||||||
MPStartLocations:
|
MPStartLocations:
|
||||||
SpawnMPUnits:
|
SpawnMPUnits:
|
||||||
SpatialBins:
|
SpatialBins:
|
||||||
|
|||||||
Reference in New Issue
Block a user