Merge pull request #9438 from atlimit8/UpgradableMobile
Upgradable Mobile and replace IDisableMove
This commit is contained in:
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
readonly IPositionable positionable;
|
||||
readonly IMove movement;
|
||||
readonly IDisableMove[] moveDisablers;
|
||||
readonly IDisabledTrait disableable;
|
||||
WPos start, end;
|
||||
int length;
|
||||
int ticks = 0;
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
positionable = self.Trait<IPositionable>();
|
||||
movement = self.TraitOrDefault<IMove>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
disableable = movement as IDisabledTrait;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.length = length;
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
{
|
||||
if (moveDisablers.Any(d => d.MoveDisabled(self)))
|
||||
if (disableable != null && disableable.IsTraitDisabled)
|
||||
return this;
|
||||
|
||||
var pos = length > 1
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
static readonly List<CPos> NoPath = new List<CPos>();
|
||||
|
||||
readonly Mobile mobile;
|
||||
readonly IDisableMove[] moveDisablers;
|
||||
readonly WDist nearEnough;
|
||||
readonly Func<List<CPos>> getPath;
|
||||
readonly Actor ignoredActor;
|
||||
@@ -43,7 +42,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, CPos destination)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () =>
|
||||
{
|
||||
@@ -65,7 +63,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, CPos destination, WDist nearEnough)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () => self.World.WorldActor.Trait<IPathFinder>()
|
||||
.FindUnitPath(mobile.ToCell, destination, self);
|
||||
@@ -76,7 +73,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, CPos destination, SubCell subCell, WDist nearEnough)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () => self.World.WorldActor.Trait<IPathFinder>()
|
||||
.FindUnitPathToRange(mobile.FromCell, subCell, self.World.Map.CenterOfSubCell(destination, subCell), nearEnough, self);
|
||||
@@ -87,7 +83,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, CPos destination, Actor ignoredActor)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () =>
|
||||
{
|
||||
@@ -107,7 +102,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, Target target, WDist range)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
getPath = () =>
|
||||
{
|
||||
@@ -125,7 +119,6 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Move(Actor self, Func<List<CPos>> getPath)
|
||||
{
|
||||
mobile = self.Trait<Mobile>();
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
|
||||
this.getPath = getPath;
|
||||
|
||||
@@ -155,7 +148,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
if (IsCanceled)
|
||||
return NextActivity;
|
||||
|
||||
if (moveDisablers.Any(d => d.MoveDisabled(self)))
|
||||
if (mobile.IsTraitDisabled)
|
||||
return this;
|
||||
|
||||
if (destination == mobile.ToCell)
|
||||
|
||||
@@ -11,18 +11,19 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Activities;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
public class Turn : Activity
|
||||
{
|
||||
readonly IDisableMove[] moveDisablers;
|
||||
readonly IDisabledTrait disablable;
|
||||
readonly int desiredFacing;
|
||||
|
||||
public Turn(Actor self, int desiredFacing)
|
||||
{
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
disablable = self.TraitOrDefault<IMove>() as IDisabledTrait;
|
||||
this.desiredFacing = desiredFacing;
|
||||
}
|
||||
|
||||
@@ -30,7 +31,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
if (IsCanceled)
|
||||
return NextActivity;
|
||||
if (moveDisablers.Any(d => d.MoveDisabled(self)))
|
||||
if (disablable != null && disablable.IsTraitDisabled)
|
||||
return this;
|
||||
|
||||
var facing = self.Trait<IFacing>();
|
||||
|
||||
@@ -484,7 +484,6 @@
|
||||
<Compile Include="Traits\ProducibleWithLevel.cs" />
|
||||
<Compile Include="Traits\Upgrades\DeployToUpgrade.cs" />
|
||||
<Compile Include="Traits\Upgrades\DisableOnUpgrade.cs" />
|
||||
<Compile Include="Traits\Upgrades\DisableMovementOnUpgrade.cs" />
|
||||
<Compile Include="Traits\Upgrades\UpgradableTrait.cs" />
|
||||
<Compile Include="Traits\Upgrades\UpgradeActorsNear.cs" />
|
||||
<Compile Include="Traits\Upgrades\UpgradeManager.cs" />
|
||||
|
||||
@@ -61,5 +61,8 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
{
|
||||
Self.QueueActivity(new EnterTransport(Self, transport, 1, true));
|
||||
}
|
||||
|
||||
[Desc("Whether the actor can move (false if immobilized).")]
|
||||
public bool IsMobile { get { return !mobile.IsTraitDisabled; } }
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("This actor can transport Passenger actors.")]
|
||||
public class CargoInfo : ITraitInfo, Requires<IOccupySpaceInfo>
|
||||
public class CargoInfo : ITraitInfo, Requires<IOccupySpaceInfo>, Requires<UpgradeManagerInfo>
|
||||
{
|
||||
[Desc("The maximum sum of Passenger.Weight that this actor can support.")]
|
||||
public readonly int MaxWeight = 0;
|
||||
@@ -51,14 +51,19 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Cursor to display when unable to unload the passengers.")]
|
||||
public readonly string UnloadBlockedCursor = "deploy-blocked";
|
||||
|
||||
[UpgradeGrantedReference]
|
||||
[Desc("The upgrades to grant to self while loading cargo.")]
|
||||
public readonly string[] LoadingUpgrades = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new Cargo(init, this); }
|
||||
}
|
||||
|
||||
public class Cargo : IPips, IIssueOrder, IResolveOrder, IOrderVoice, INotifyCreated, INotifyKilled,
|
||||
INotifyOwnerChanged, INotifyAddedToWorld, ITick, INotifySold, IDisableMove, INotifyActorDisposing
|
||||
INotifyOwnerChanged, INotifyAddedToWorld, ITick, INotifySold, INotifyActorDisposing
|
||||
{
|
||||
public readonly CargoInfo Info;
|
||||
readonly Actor self;
|
||||
readonly UpgradeManager upgradeManager;
|
||||
readonly Stack<Actor> cargo = new Stack<Actor>();
|
||||
readonly HashSet<Actor> reserves = new HashSet<Actor>();
|
||||
readonly Lazy<IFacing> facing;
|
||||
@@ -80,6 +85,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Info = info;
|
||||
Unloading = false;
|
||||
checkTerrainType = info.UnloadTerrainTypes.Count > 0;
|
||||
upgradeManager = self.Trait<UpgradeManager>();
|
||||
|
||||
if (init.Contains<RuntimeCargoInit>())
|
||||
{
|
||||
@@ -183,6 +189,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!HasSpace(w))
|
||||
return false;
|
||||
|
||||
if (reserves.Count == 0)
|
||||
foreach (var u in Info.LoadingUpgrades)
|
||||
upgradeManager.GrantUpgrade(self, u, this);
|
||||
|
||||
reserves.Add(a);
|
||||
reservedWeight += w;
|
||||
|
||||
@@ -196,6 +206,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
reservedWeight -= GetWeight(a);
|
||||
reserves.Remove(a);
|
||||
|
||||
if (reserves.Count == 0)
|
||||
foreach (var u in Info.LoadingUpgrades)
|
||||
upgradeManager.RevokeUpgrade(self, u, this);
|
||||
}
|
||||
|
||||
public string CursorForOrder(Actor self, Order order)
|
||||
@@ -214,7 +228,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return Info.UnloadVoice;
|
||||
}
|
||||
|
||||
public bool MoveDisabled(Actor self) { return reserves.Any(); }
|
||||
public bool HasSpace(int weight) { return totalWeight + reservedWeight + weight <= Info.MaxWeight; }
|
||||
public bool IsEmpty(Actor self) { return cargo.Count == 0; }
|
||||
|
||||
@@ -235,7 +248,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
p.Transport = null;
|
||||
|
||||
foreach (var u in p.Info.GrantUpgrades)
|
||||
self.Trait<UpgradeManager>().RevokeUpgrade(self, u, p);
|
||||
upgradeManager.RevokeUpgrade(self, u, p);
|
||||
|
||||
return a;
|
||||
}
|
||||
@@ -287,6 +300,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
reservedWeight -= w;
|
||||
reserves.Remove(a);
|
||||
|
||||
if (reserves.Count == 0)
|
||||
foreach (var u in Info.LoadingUpgrades)
|
||||
upgradeManager.RevokeUpgrade(self, u, this);
|
||||
}
|
||||
|
||||
foreach (var npe in self.TraitsImplementing<INotifyPassengerEntered>())
|
||||
@@ -295,7 +312,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var p = a.Trait<Passenger>();
|
||||
p.Transport = self;
|
||||
foreach (var u in p.Info.GrantUpgrades)
|
||||
self.Trait<UpgradeManager>().GrantUpgrade(self, u, p);
|
||||
upgradeManager.GrantUpgrade(self, u, p);
|
||||
}
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
[Desc("Unit is able to move.")]
|
||||
public class MobileInfo : IMoveInfo, IPositionableInfo, IOccupySpaceInfo, IFacingInfo,
|
||||
public class MobileInfo : UpgradableTraitInfo, IMoveInfo, IPositionableInfo, IOccupySpaceInfo, IFacingInfo,
|
||||
UsesInit<FacingInit>, UsesInit<LocationInit>, UsesInit<SubCellInit>
|
||||
{
|
||||
[FieldLoader.LoadUsing("LoadSpeeds", true)]
|
||||
@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
[VoiceReference] public readonly string Voice = "Action";
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new Mobile(init, this); }
|
||||
public override object Create(ActorInitializer init) { return new Mobile(init, this); }
|
||||
|
||||
static object LoadSpeeds(MiniYaml y)
|
||||
{
|
||||
@@ -304,8 +304,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
bool IOccupySpaceInfo.SharesCell { get { return SharesCell; } }
|
||||
}
|
||||
|
||||
public class Mobile : IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove, IFacing, ISync, IDeathActorInitModifier,
|
||||
INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove
|
||||
public class Mobile : UpgradableTrait<MobileInfo>, IIssueOrder, IResolveOrder, IOrderVoice, IPositionable, IMove, IFacing, ISync,
|
||||
IDeathActorInitModifier, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyBlockingMove
|
||||
{
|
||||
const int AverageTicksBeforePathing = 5;
|
||||
const int SpreadTicksBeforePathing = 5;
|
||||
@@ -313,7 +313,6 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
readonly Actor self;
|
||||
readonly Lazy<IEnumerable<int>> speedModifiers;
|
||||
public readonly MobileInfo Info;
|
||||
public bool IsMoving { get; set; }
|
||||
|
||||
int facing;
|
||||
@@ -349,9 +348,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
public Mobile(ActorInitializer init, MobileInfo info)
|
||||
: base(info)
|
||||
{
|
||||
self = init.Self;
|
||||
Info = info;
|
||||
|
||||
speedModifiers = Exts.Lazy(() => self.TraitsImplementing<ISpeedModifier>().ToArray().Select(x => x.GetSpeedModifier()));
|
||||
|
||||
@@ -438,7 +437,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
self.World.ScreenMap.Remove(self);
|
||||
}
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders { get { yield return new MoveOrderTargeter(self, Info); } }
|
||||
public IEnumerable<IOrderTargeter> Orders { get { yield return new MoveOrderTargeter(self, this); } }
|
||||
|
||||
// Note: Returns a valid order even if the unit can't move to the target
|
||||
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
|
||||
@@ -629,6 +628,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void Nudge(Actor self, Actor nudger, bool force)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
return;
|
||||
|
||||
/* initial fairly braindead implementation. */
|
||||
if (!force && self.Owner.Stances[nudger.Owner] != Stance.Ally)
|
||||
return; /* don't allow ourselves to be pushed around
|
||||
@@ -691,16 +693,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
class MoveOrderTargeter : IOrderTargeter
|
||||
{
|
||||
readonly MobileInfo unitType;
|
||||
readonly Mobile mobile;
|
||||
readonly bool rejectMove;
|
||||
readonly IDisableMove[] moveDisablers;
|
||||
public bool OverrideSelection { get { return false; } }
|
||||
|
||||
public MoveOrderTargeter(Actor self, MobileInfo unitType)
|
||||
public MoveOrderTargeter(Actor self, Mobile unit)
|
||||
{
|
||||
this.unitType = unitType;
|
||||
this.mobile = unit;
|
||||
rejectMove = !self.AcceptsOrder("Move");
|
||||
moveDisablers = self.TraitsImplementing<IDisableMove>().ToArray();
|
||||
}
|
||||
|
||||
public string OrderID { get { return "Move"; } }
|
||||
@@ -717,12 +717,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var explored = self.Owner.Shroud.IsExplored(location);
|
||||
cursor = self.World.Map.Contains(location) ?
|
||||
(self.World.Map.GetTerrainInfo(location).CustomCursor ?? unitType.Cursor) : unitType.BlockedCursor;
|
||||
(self.World.Map.GetTerrainInfo(location).CustomCursor ?? mobile.Info.Cursor) : mobile.Info.BlockedCursor;
|
||||
|
||||
if ((!explored && !unitType.MoveIntoShroud)
|
||||
|| (explored && unitType.MovementCostForCell(self.World, location) == int.MaxValue)
|
||||
|| moveDisablers.Any(d => d.MoveDisabled(self)))
|
||||
cursor = unitType.BlockedCursor;
|
||||
if (mobile.IsTraitDisabled
|
||||
|| (!explored && !mobile.Info.MoveIntoShroud)
|
||||
|| (explored && mobile.Info.MovementCostForCell(self.World, location) == int.MaxValue))
|
||||
cursor = mobile.Info.BlockedCursor;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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.Traits
|
||||
{
|
||||
[Desc("Disable the ability to move and turn of the actor when this trait is enabled by an upgrade.")]
|
||||
public class DisableMovementInfo : UpgradableTraitInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new DisableMovementOnUpgrade(this); }
|
||||
}
|
||||
|
||||
public class DisableMovementOnUpgrade : UpgradableTrait<DisableMovementInfo>, IDisableMove
|
||||
{
|
||||
public DisableMovementOnUpgrade(DisableMovementInfo info)
|
||||
: base(info) { }
|
||||
|
||||
public bool MoveDisabled(Actor self) { return !IsTraitDisabled; }
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public override object Create(ActorInitializer init) { return new DisableOnUpgrade(this); }
|
||||
}
|
||||
|
||||
public class DisableOnUpgrade : UpgradableTrait<DisableOnUpgradeInfo>, IDisable, IDisableMove
|
||||
public class DisableOnUpgrade : UpgradableTrait<DisableOnUpgradeInfo>, IDisable
|
||||
{
|
||||
public DisableOnUpgrade(DisableOnUpgradeInfo info)
|
||||
: base(info) { }
|
||||
|
||||
public bool Disabled { get { return !IsTraitDisabled; } }
|
||||
public bool MoveDisabled(Actor self) { return !IsTraitDisabled; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2510,6 +2510,179 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
}
|
||||
}
|
||||
|
||||
// Mobile actors immobilized by Carryable, Cargo, DeployToUpgrade, and/or others using upgrade(s)
|
||||
if (engineVersion < 20151204 && depth == 0)
|
||||
{
|
||||
var notMobile = "notmobile";
|
||||
|
||||
var mobileNode = node.Value.Nodes.Find(n => n.Key == "Mobile");
|
||||
var carryableNode = node.Value.Nodes.Find(n => n.Key == "Carryable");
|
||||
var cargoNode = node.Value.Nodes.Find(n => n.Key == "Cargo");
|
||||
var deployToUpgradeNode = node.Value.Nodes.Find(n => n.Key == "DeployToUpgrade");
|
||||
var disableUpgradeNode = node.Value.Nodes.Find(n => n.Key == "DisableUpgrade");
|
||||
var disableMovementOnUpgradeNode = node.Value.Nodes.Find(n => n.Key == "DisableMovementOnUpgrade");
|
||||
|
||||
Action<MiniYamlNode, string> addNotMobileToTraitUpgrades = (trait, upgradesKey) =>
|
||||
{
|
||||
if (trait != null)
|
||||
{
|
||||
var upgrades = trait.Value.Nodes.Find(u => u.Key == upgradesKey);
|
||||
if (upgrades == null)
|
||||
trait.Value.Nodes.Add(new MiniYamlNode(upgradesKey, notMobile));
|
||||
else if (string.IsNullOrEmpty(upgrades.Value.Value))
|
||||
upgrades.Value.Value = notMobile;
|
||||
else if (!upgrades.Value.Value.Contains(notMobile))
|
||||
upgrades.Value.Value += ", " + notMobile;
|
||||
}
|
||||
};
|
||||
|
||||
if (mobileNode != null)
|
||||
{
|
||||
var mobileUpgrades = mobileNode.Value.Nodes.Find(n => n.Key == "UpgradeTypes");
|
||||
var mobileUpgradeMaxEnabledLevel = mobileNode.Value.Nodes.Find(n => n.Key == "UpgradeMaxEnabledLevel");
|
||||
var comma = new char[] { ',' };
|
||||
|
||||
Func<bool> addUpgradeMaxEnabledLevelNode = () =>
|
||||
{
|
||||
if (mobileUpgradeMaxEnabledLevel == null)
|
||||
{
|
||||
mobileUpgradeMaxEnabledLevel = new MiniYamlNode("UpgradeMaxEnabledLevel", "0");
|
||||
mobileNode.Value.Nodes.Add(mobileUpgradeMaxEnabledLevel);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return mobileUpgradeMaxEnabledLevel.Value.Value == "0";
|
||||
};
|
||||
|
||||
// If exactly one upgrade type is in UpgradeTypes and UpgradeMaxEnabledLevel is/can be 0 , then use it as notmobile
|
||||
if (mobileUpgrades != null && !string.IsNullOrEmpty(mobileUpgrades.Value.Value)
|
||||
&& !mobileUpgrades.Value.Value.Contains(",") && addUpgradeMaxEnabledLevelNode())
|
||||
notMobile = mobileUpgrades.Value.Value;
|
||||
|
||||
if (mobileUpgradeMaxEnabledLevel != null && mobileUpgradeMaxEnabledLevel.Value.Value != "0")
|
||||
Console.WriteLine("\t\t" + node.Key + " actor rules may require manual upgrading for immobilization upgrade logic.");
|
||||
else
|
||||
{
|
||||
Action<string> addImmobilizeUpgradeType = upgradeType =>
|
||||
{
|
||||
if (mobileUpgrades == null)
|
||||
{
|
||||
mobileUpgrades = new MiniYamlNode("UpgradeTypes", upgradeType);
|
||||
mobileNode.Value.Nodes.Add(mobileUpgrades);
|
||||
}
|
||||
else if (string.IsNullOrEmpty(mobileUpgrades.Value.Value))
|
||||
mobileUpgrades.Value.Value = upgradeType;
|
||||
else if (!mobileUpgrades.Value.Value.Split(comma).Contains(upgradeType))
|
||||
mobileUpgrades.Value.Value += ", " + upgradeType;
|
||||
};
|
||||
|
||||
Predicate<string> addImmobilizeUpgradeTypes = upgradeTypes =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(upgradeTypes))
|
||||
return false;
|
||||
|
||||
foreach (var upgradeType in upgradeTypes.Split(comma))
|
||||
addImmobilizeUpgradeType(upgradeType);
|
||||
return true;
|
||||
};
|
||||
|
||||
Predicate<MiniYamlNode> addUpgradeTypeFromTrait = trait =>
|
||||
{
|
||||
var upgradeTypesNode = trait.Value.Nodes.Find(n => n.Key == "UpgradeTypes");
|
||||
if (upgradeTypesNode == null)
|
||||
return false;
|
||||
|
||||
addUpgradeMaxEnabledLevelNode();
|
||||
return addImmobilizeUpgradeTypes(upgradeTypesNode.Value.Value);
|
||||
};
|
||||
|
||||
var noticeWritten = false;
|
||||
|
||||
Action writeNotice = () =>
|
||||
{
|
||||
if (noticeWritten)
|
||||
return;
|
||||
Console.WriteLine("\t\t" + node.Key + " actor rules may require manual upgrading for immobilization upgrade logic.");
|
||||
noticeWritten = true;
|
||||
};
|
||||
|
||||
if (disableUpgradeNode != null && !addUpgradeTypeFromTrait(disableUpgradeNode))
|
||||
{
|
||||
writeNotice();
|
||||
Console.WriteLine("\t\t\tOne or more upgrades may need to be copied from the DisableUpgrade trait to the Mobile trait.");
|
||||
}
|
||||
|
||||
if (disableMovementOnUpgradeNode != null)
|
||||
{
|
||||
if (addUpgradeTypeFromTrait(disableMovementOnUpgradeNode))
|
||||
parent.Value.Nodes.Remove(disableMovementOnUpgradeNode);
|
||||
else
|
||||
{
|
||||
writeNotice();
|
||||
Console.WriteLine("\t\t\tOne or more upgrades may need to be moved from the DisableMovementOnUpgrade trait to the Mobile trait.");
|
||||
Console.WriteLine("\t\t\t\tRemember to remove the DisableMovementOnUpgrade trait.");
|
||||
}
|
||||
}
|
||||
|
||||
if (carryableNode != null || cargoNode != null || deployToUpgradeNode != null)
|
||||
{
|
||||
addUpgradeMaxEnabledLevelNode();
|
||||
addImmobilizeUpgradeTypes(notMobile);
|
||||
|
||||
addNotMobileToTraitUpgrades(carryableNode, "CarryableUpgrades");
|
||||
addNotMobileToTraitUpgrades(cargoNode, "LoadingUpgrades");
|
||||
addNotMobileToTraitUpgrades(deployToUpgradeNode, "DeployedUpgrades");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!node.Value.Nodes.Exists(n => n.Key == "Husk" || n.Key == "Building" || n.Key == "Aircraft" || n.Key == "Immobile"))
|
||||
{
|
||||
if (carryableNode != null || cargoNode != null || deployToUpgradeNode != null)
|
||||
{
|
||||
Console.WriteLine("\t\tIf " + node.Key
|
||||
+ " has a Mobile trait then adding the following with <upgrade> substituted by an immobilization upgrade for "
|
||||
+ node.Key + " may be neeeded:");
|
||||
|
||||
if (carryableNode != null)
|
||||
{
|
||||
Console.WriteLine("\t\t\tCarryable:");
|
||||
Console.WriteLine("\t\t\t\tCarryableUpgrades: <upgrade>");
|
||||
}
|
||||
|
||||
if (cargoNode != null)
|
||||
{
|
||||
Console.WriteLine("\t\t\tCargo:");
|
||||
Console.WriteLine("\t\t\t\tLoadingUpgrades: <upgrade>");
|
||||
}
|
||||
|
||||
if (deployToUpgradeNode != null)
|
||||
{
|
||||
Console.WriteLine("\t\t\tDeployToUpgrade:");
|
||||
Console.WriteLine("\t\t\t\tDeployedUpgrades: <upgrade>");
|
||||
}
|
||||
}
|
||||
|
||||
var disableUpgradeUpgradeTypesNode = disableUpgradeNode != null
|
||||
? disableUpgradeNode.Value.Nodes.Find(n => n.Key == "UpgradeTypes")
|
||||
: null;
|
||||
var disableMovementOnUpgradeUpgradeTypesNode = disableMovementOnUpgradeNode != null
|
||||
? disableMovementOnUpgradeNode.Value.Nodes.Find(n => n.Key == "UpgradeTypes")
|
||||
: null;
|
||||
|
||||
if (disableUpgradeUpgradeTypesNode != null || disableMovementOnUpgradeUpgradeTypesNode != null)
|
||||
Console.WriteLine("\t\t" + node.Key + " actor rules may require manual upgrading for immobilization upgrade logic.");
|
||||
|
||||
if (disableUpgradeUpgradeTypesNode != null)
|
||||
Console.WriteLine("\t\t\tDisableUpgrade UpgradeTypes: " + disableUpgradeUpgradeTypesNode.Value.Value);
|
||||
|
||||
if (disableMovementOnUpgradeUpgradeTypesNode != null)
|
||||
Console.WriteLine("\t\t\tDisableMovementOnUpgrade UpgradeTypes: " + disableMovementOnUpgradeUpgradeTypesNode.Value.Value);
|
||||
|
||||
if (disableMovementOnUpgradeNode != null)
|
||||
node.Value.Nodes.Remove(disableMovementOnUpgradeNode);
|
||||
}
|
||||
}
|
||||
|
||||
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user