Fix MP gamestart
This commit is contained in:
@@ -390,7 +390,7 @@ namespace OpenRA
|
|||||||
orderManager.StartGame();
|
orderManager.StartGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static event Action OnGameStart = () => {};
|
public static event Action AfterGameStart = () => {};
|
||||||
public static event Action BeforeGameStart = () => {};
|
public static event Action BeforeGameStart = () => {};
|
||||||
internal static void StartGame()
|
internal static void StartGame()
|
||||||
{
|
{
|
||||||
@@ -404,9 +404,8 @@ namespace OpenRA
|
|||||||
foreach (var gs in world.WorldActor.TraitsImplementing<IGameStarted>())
|
foreach (var gs in world.WorldActor.TraitsImplementing<IGameStarted>())
|
||||||
gs.GameStarted(world);
|
gs.GameStarted(world);
|
||||||
|
|
||||||
viewport.GoToStartLocation(world.LocalPlayer);
|
|
||||||
orderManager.StartGame();
|
orderManager.StartGame();
|
||||||
OnGameStart();
|
AfterGameStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Stance ChooseInitialStance(Player p, Player q)
|
public static Stance ChooseInitialStance(Player p, Player q)
|
||||||
|
|||||||
@@ -110,11 +110,6 @@ namespace OpenRA.Graphics
|
|||||||
scrollPosition = (avgPos - .5f * new float2(Width, Height)).ToInt2();
|
scrollPosition = (avgPos - .5f * new float2(Width, Height)).ToInt2();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GoToStartLocation( Player player )
|
|
||||||
{
|
|
||||||
Center( player.World.Queries.OwnedBy[ player ].WithTrait<Selectable>().Select( a => a.Actor ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public Rectangle? ShroudBounds()
|
public Rectangle? ShroudBounds()
|
||||||
{
|
{
|
||||||
var localPlayer = Game.world.LocalPlayer;
|
var localPlayer = Game.world.LocalPlayer;
|
||||||
|
|||||||
@@ -223,6 +223,7 @@
|
|||||||
<Compile Include="Traits\Activities\Drag.cs" />
|
<Compile Include="Traits\Activities\Drag.cs" />
|
||||||
<Compile Include="Widgets\VqaPlayerWidget.cs" />
|
<Compile Include="Widgets\VqaPlayerWidget.cs" />
|
||||||
<Compile Include="Widgets\Delegates\VideoPlayerDelegate.cs" />
|
<Compile Include="Widgets\Delegates\VideoPlayerDelegate.cs" />
|
||||||
|
<Compile Include="Traits\MPStartLocations.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
69
OpenRA.Game/Traits/MPStartLocations.cs
Normal file
69
OpenRA.Game/Traits/MPStartLocations.cs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2010 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 LICENSE.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
|
namespace OpenRA.Traits
|
||||||
|
{
|
||||||
|
public class MPStartLocationsInfo : TraitInfo<MPStartLocations>
|
||||||
|
{
|
||||||
|
public readonly int InitialExploreRange = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MPStartLocations : IGameStarted
|
||||||
|
{
|
||||||
|
public Dictionary<Player, int2> Start = new Dictionary<Player, int2>();
|
||||||
|
public void GameStarted(World world)
|
||||||
|
{
|
||||||
|
var taken = Game.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0)
|
||||||
|
.Select(c => world.Map.SpawnPoints.ElementAt(c.SpawnPoint - 1)).ToList();
|
||||||
|
var available = world.Map.SpawnPoints.Except(taken).ToList();
|
||||||
|
|
||||||
|
// Set spawn
|
||||||
|
foreach (var client in Game.LobbyInfo.Clients)
|
||||||
|
Start.Add(world.players[client.Index],(client.SpawnPoint == 0)
|
||||||
|
? ChooseSpawnPoint(world, available, taken)
|
||||||
|
: world.Map.SpawnPoints.ElementAt(client.SpawnPoint - 1));
|
||||||
|
|
||||||
|
// Explore allied shroud
|
||||||
|
foreach (var p in Start)
|
||||||
|
if (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);
|
||||||
|
|
||||||
|
// Set viewport
|
||||||
|
if (world.LocalPlayer != null && Start.ContainsKey(world.LocalPlayer))
|
||||||
|
Game.viewport.Center(Start[world.LocalPlayer]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int2 ChooseSpawnPoint(World world, List<int2> available, List<int2> 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))
|
||||||
|
.OrderByDescending(a => taken.Sum(t => (t - a.First).LengthSquared))
|
||||||
|
.Select(a => a.Second)
|
||||||
|
.First();
|
||||||
|
|
||||||
|
var sp = available[n];
|
||||||
|
available.RemoveAt(n);
|
||||||
|
taken.Add(sp);
|
||||||
|
return sp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
Game.OnGameStart += () => validPlayers = Game.world.players.Values.Where(a => a != Game.world.LocalPlayer && !a.NonCombatant).Count();
|
Game.AfterGameStart += () => validPlayers = Game.world.players.Values.Where(a => a != Game.world.LocalPlayer && !a.NonCombatant).Count();
|
||||||
diplomacy.IsVisible = () => (validPlayers > 0);
|
diplomacy.IsVisible = () => (validPlayers > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,27 +16,14 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
class SpawnMPUnitsInfo : TraitInfo<SpawnMPUnits>
|
class SpawnMPUnitsInfo : TraitInfo<SpawnMPUnits>, ITraitPrerequisite<MPStartLocationsInfo> {}
|
||||||
{
|
|
||||||
public readonly int InitialExploreRange = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
class SpawnMPUnits : IGameStarted
|
class SpawnMPUnits : IGameStarted
|
||||||
{
|
{
|
||||||
public void GameStarted(World world)
|
public void GameStarted(World world)
|
||||||
{
|
{
|
||||||
var taken = Game.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0)
|
foreach (var s in world.WorldActor.Trait<MPStartLocations>().Start)
|
||||||
.Select(c => world.Map.SpawnPoints.ElementAt(c.SpawnPoint - 1)).ToList();
|
SpawnUnitsForPlayer(s.Key, s.Value);
|
||||||
|
|
||||||
var available = world.Map.SpawnPoints.Except(taken).ToList();
|
|
||||||
|
|
||||||
foreach (var client in Game.LobbyInfo.Clients)
|
|
||||||
{
|
|
||||||
SpawnUnitsForPlayer(world.players[client.Index],
|
|
||||||
(client.SpawnPoint == 0)
|
|
||||||
? ChooseSpawnPoint(world, available, taken)
|
|
||||||
: world.Map.SpawnPoints.ElementAt(client.SpawnPoint - 1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpawnUnitsForPlayer(Player p, int2 sp)
|
void SpawnUnitsForPlayer(Player p, int2 sp)
|
||||||
@@ -46,29 +33,6 @@ namespace OpenRA.Mods.RA
|
|||||||
new LocationInit( sp ),
|
new LocationInit( sp ),
|
||||||
new OwnerInit( p ),
|
new OwnerInit( p ),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (p == p.World.LocalPlayer || p.Stances[p.World.LocalPlayer] == Stance.Ally)
|
|
||||||
p.World.WorldActor.Trait<Shroud>().Explore(p.World, sp,
|
|
||||||
p.World.WorldActor.Info.Traits.Get<SpawnMPUnitsInfo>().InitialExploreRange);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int2 ChooseSpawnPoint(World world, List<int2> available, List<int2> 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))
|
|
||||||
.OrderByDescending(a => taken.Sum(t => (t - a.First).LengthSquared))
|
|
||||||
.Select(a => a.Second)
|
|
||||||
.First();
|
|
||||||
|
|
||||||
var sp = available[n];
|
|
||||||
available.RemoveAt(n);
|
|
||||||
taken.Add(sp);
|
|
||||||
return sp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
var optionsBG = gameRoot.GetWidget("INGAME_OPTIONS_BG");
|
var optionsBG = gameRoot.GetWidget("INGAME_OPTIONS_BG");
|
||||||
|
|
||||||
Game.BeforeGameStart += () => r.OpenWindow("INGAME_ROOT");
|
Game.BeforeGameStart += () => r.OpenWindow("INGAME_ROOT");
|
||||||
Game.OnGameStart += () => gameRoot.GetWidget<RadarBinWidget>("INGAME_RADAR_BIN").SetWorld(Game.world);
|
Game.AfterGameStart += () => gameRoot.GetWidget<RadarBinWidget>("INGAME_RADAR_BIN").SetWorld(Game.world);
|
||||||
|
|
||||||
r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => {
|
r.GetWidget("INGAME_OPTIONS_BUTTON").OnMouseUp = mi => {
|
||||||
optionsBG.Visible = !optionsBG.Visible;
|
optionsBG.Visible = !optionsBG.Visible;
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ World:
|
|||||||
SpawnMapActors:
|
SpawnMapActors:
|
||||||
CreateMPPlayers:
|
CreateMPPlayers:
|
||||||
SpawnMPUnits:
|
SpawnMPUnits:
|
||||||
|
MPStartLocations:
|
||||||
EvaAlerts:
|
EvaAlerts:
|
||||||
RadarUp: comcntr1.aud
|
RadarUp: comcntr1.aud
|
||||||
RadarDown: powrdn1.aud
|
RadarDown: powrdn1.aud
|
||||||
|
|||||||
@@ -1237,3 +1237,4 @@ Rules:
|
|||||||
DefaultShellmapScript:
|
DefaultShellmapScript:
|
||||||
-CreateMPPlayers:
|
-CreateMPPlayers:
|
||||||
-SpawnMPUnits:
|
-SpawnMPUnits:
|
||||||
|
-MPStartLocations:
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ World:
|
|||||||
CreateMapPlayers:
|
CreateMapPlayers:
|
||||||
SpawnMapActors:
|
SpawnMapActors:
|
||||||
CreateMPPlayers:
|
CreateMPPlayers:
|
||||||
|
MPStartLocations:
|
||||||
SpawnMPUnits:
|
SpawnMPUnits:
|
||||||
EvaAlerts:
|
EvaAlerts:
|
||||||
SpatialBins:
|
SpatialBins:
|
||||||
|
|||||||
Reference in New Issue
Block a user