diff --git a/AUTHORS b/AUTHORS index a54e89c1cc..c73bee95c7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -60,6 +60,7 @@ Also thanks to: * Kyrre Soerensen (zypres) * Lawrence Wang * Lesueur Benjamin (Valkirie) + * Lukas Franke (abcdefg30) * Maarten Meuris (Nyerguds) * Mark Olson (markolson) * Matija Hustic (matija-hustic) diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index bb977977c5..9076035e4e 100644 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -239,7 +239,7 @@ namespace OpenRA.Network var targetPlayer = order.Player.World.Players.FirstOrDefault(p => p.InternalName == order.TargetString); var newStance = (Stance)order.ExtraData; - SetPlayerStance(world, order.Player, targetPlayer, newStance); + order.Player.SetStance(targetPlayer, newStance); Game.Debug("{0} has set diplomatic stance vs {1} to {2}", order.Player.PlayerName, targetPlayer.PlayerName, newStance); @@ -247,7 +247,7 @@ namespace OpenRA.Network // automatically declare war reciprocally if (newStance == Stance.Enemy && targetPlayer.Stances[order.Player] == Stance.Ally) { - SetPlayerStance(world, targetPlayer, order.Player, newStance); + targetPlayer.SetStance(order.Player, newStance); Game.Debug("{0} has reciprocated",targetPlayer.PlayerName); } @@ -275,17 +275,6 @@ namespace OpenRA.Network } } - static void SetPlayerStance(World w, Player p, Player target, Stance s) - { - var oldStance = p.Stances[target]; - p.Stances[target] = s; - target.Shroud.UpdatePlayerStance(w, p, oldStance, s); - p.Shroud.UpdatePlayerStance(w, target, oldStance, s); - - foreach (var nsc in w.ActorsWithTrait()) - nsc.Trait.StanceChanged(nsc.Actor, p, target, oldStance, s); - } - static void SetOrderLag(OrderManager o) { if (o.FramesAhead != o.LobbyInfo.GlobalSettings.OrderLatency && !o.GameStarted) diff --git a/OpenRA.Game/Player.cs b/OpenRA.Game/Player.cs index 96f9f91453..bb97e2b9fe 100644 --- a/OpenRA.Game/Player.cs +++ b/OpenRA.Game/Player.cs @@ -111,6 +111,17 @@ namespace OpenRA return p == null || Stances[p] == Stance.Ally; } + public void SetStance(Player target, Stance s) + { + var oldStance = Stances[target]; + Stances[target] = s; + target.Shroud.UpdatePlayerStance(World, this, oldStance, s); + Shroud.UpdatePlayerStance(World, target, oldStance, s); + + foreach (var nsc in World.ActorsWithTrait()) + nsc.Trait.StanceChanged(nsc.Actor, this, target, oldStance, s); + } + #region Scripting interface Lazy luaInterface; diff --git a/OpenRA.Mods.RA/Scripting/Properties/DiplomacyProperties.cs b/OpenRA.Mods.RA/Scripting/Properties/DiplomacyProperties.cs new file mode 100644 index 0000000000..51ee35f965 --- /dev/null +++ b/OpenRA.Mods.RA/Scripting/Properties/DiplomacyProperties.cs @@ -0,0 +1,39 @@ +#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 Eluant; +using OpenRA.Network; +using OpenRA.Scripting; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA.Scripting +{ + [ScriptPropertyGroup("Diplomacy")] + public class DiplomacyProperties : ScriptPlayerProperties + { + public DiplomacyProperties(ScriptContext context, Player player) + : base(context, player) { } + + [Desc("Returns true if the player is allied with the other player.")] + public bool IsAlliedWith(Player targetPlayer) + { + return player.IsAlliedWith(targetPlayer); + } + + [Desc("Changes the current stance of the player against the target player. " + + "Allowed keywords for new stance: Ally, Neutral, Enemy.")] + public void SetStance(Player targetPlayer, string newStance) + { + var emergingStance = Enum.Parse(newStance); + player.SetStance(targetPlayer, emergingStance); + } + } +} \ No newline at end of file