Give EngineerRepair(able) more generic names

This commit is contained in:
Matthias Mailänder
2023-01-22 23:24:00 +01:00
committed by abcdefg30
parent 9b2e291a46
commit f67b6f6cad
14 changed files with 83 additions and 51 deletions

View File

@@ -14,15 +14,15 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities
{
class RepairBuilding : Enter
class InstantRepair : Enter
{
readonly EngineerRepairInfo info;
readonly InstantlyRepairsInfo info;
Actor enterActor;
IHealth enterHealth;
EngineerRepairable enterEngineerRepariable;
InstantlyRepairable enterInstantlyRepariable;
public RepairBuilding(Actor self, in Target target, EngineerRepairInfo info)
public InstantRepair(Actor self, in Target target, InstantlyRepairsInfo info)
: base(self, target, info.TargetLineColor)
{
this.info = info;
@@ -32,12 +32,12 @@ namespace OpenRA.Mods.Common.Activities
{
enterActor = targetActor;
enterHealth = targetActor.TraitOrDefault<IHealth>();
enterEngineerRepariable = targetActor.TraitOrDefault<EngineerRepairable>();
enterInstantlyRepariable = targetActor.TraitOrDefault<InstantlyRepairable>();
// Make sure we can still repair the target before entering
// (but not before, because this may stop the actor in the middle of nowhere)
var stance = self.Owner.RelationshipWith(enterActor.Owner);
if (enterHealth == null || enterHealth.DamageState == DamageState.Undamaged || enterEngineerRepariable == null || enterEngineerRepariable.IsTraitDisabled || !info.ValidRelationships.HasRelationship(stance))
if (enterHealth == null || enterHealth.DamageState == DamageState.Undamaged || enterInstantlyRepariable == null || enterInstantlyRepariable.IsTraitDisabled || !info.ValidRelationships.HasRelationship(stance))
{
Cancel(self, true);
return false;
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Activities
if (targetActor != enterActor)
return;
if (enterEngineerRepariable.IsTraitDisabled)
if (enterInstantlyRepariable.IsTraitDisabled)
return;
if (enterHealth.DamageState == DamageState.Undamaged)

View File

@@ -13,20 +13,20 @@ using OpenRA.Primitives;
namespace OpenRA.Mods.Common.Traits
{
public class EngineerRepairType { }
public class InstantlyRepairType { }
[Desc("Eligible for instant repair.")]
public class EngineerRepairableInfo : ConditionalTraitInfo
public class InstantlyRepairableInfo : ConditionalTraitInfo
{
[Desc("Actors with these Types under EngineerRepair trait can repair me.")]
public readonly BitSet<EngineerRepairType> Types = default;
public readonly BitSet<InstantlyRepairType> Types = default;
public override object Create(ActorInitializer init) { return new EngineerRepairable(this); }
public override object Create(ActorInitializer init) { return new InstantlyRepairable(this); }
}
public class EngineerRepairable : ConditionalTrait<EngineerRepairableInfo>
public class InstantlyRepairable : ConditionalTrait<InstantlyRepairableInfo>
{
public EngineerRepairable(EngineerRepairableInfo info)
public InstantlyRepairable(InstantlyRepairableInfo info)
: base(info) { }
}
}

View File

@@ -18,10 +18,10 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Can instantly repair other actors, but gets consumed afterwards.")]
public class EngineerRepairInfo : ConditionalTraitInfo
public class InstantlyRepairsInfo : ConditionalTraitInfo
{
[Desc("Uses the \"EngineerRepairable\" trait to determine repairability.")]
public readonly BitSet<EngineerRepairType> Types = default;
[Desc("Uses the " + nameof(InstantlyRepairable) + " trait to determine repairability.")]
public readonly BitSet<InstantlyRepairType> Types = default;
[VoiceReference]
public readonly string Voice = "Action";
@@ -47,12 +47,12 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Cursor to display when target actor has full health so it can't be repaired.")]
public readonly string RepairBlockedCursor = "goldwrench-blocked";
public override object Create(ActorInitializer init) { return new EngineerRepair(this); }
public override object Create(ActorInitializer init) { return new InstantlyRepairs(this); }
}
public class EngineerRepair : ConditionalTrait<EngineerRepairInfo>, IIssueOrder, IResolveOrder, IOrderVoice
public class InstantlyRepairs : ConditionalTrait<InstantlyRepairsInfo>, IIssueOrder, IResolveOrder, IOrderVoice
{
public EngineerRepair(EngineerRepairInfo info)
public InstantlyRepairs(InstantlyRepairsInfo info)
: base(info) { }
public IEnumerable<IOrderTargeter> Orders
@@ -62,13 +62,13 @@ namespace OpenRA.Mods.Common.Traits
if (IsTraitDisabled)
yield break;
yield return new EngineerRepairOrderTargeter(Info);
yield return new InstantRepairOrderTargeter(Info);
}
}
public Order IssueOrder(Actor self, IOrderTargeter order, in Target target, bool queued)
{
if (order.OrderID != "EngineerRepair")
if (order.OrderID != "InstantRepair")
return null;
return new Order(order.OrderID, self, target, queued);
@@ -87,36 +87,36 @@ namespace OpenRA.Mods.Common.Traits
public string VoicePhraseForOrder(Actor self, Order order)
{
return order.OrderString == "EngineerRepair" && IsValidOrder(order)
return order.OrderString == "InstantRepair" && IsValidOrder(order)
? Info.Voice : null;
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString != "EngineerRepair" || !IsValidOrder(order))
if (order.OrderString != "InstantRepair" || !IsValidOrder(order))
return;
self.QueueActivity(order.Queued, new RepairBuilding(self, order.Target, Info));
self.QueueActivity(order.Queued, new InstantRepair(self, order.Target, Info));
self.ShowTargetLines();
}
class EngineerRepairOrderTargeter : UnitOrderTargeter
class InstantRepairOrderTargeter : UnitOrderTargeter
{
readonly EngineerRepairInfo info;
readonly InstantlyRepairsInfo info;
public EngineerRepairOrderTargeter(EngineerRepairInfo info)
: base("EngineerRepair", 6, info.Cursor, true, true)
public InstantRepairOrderTargeter(InstantlyRepairsInfo info)
: base("InstantRepair", 6, info.Cursor, true, true)
{
this.info = info;
}
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
{
var engineerRepairable = target.TraitOrDefault<EngineerRepairable>();
if (engineerRepairable == null || engineerRepairable.IsTraitDisabled)
var instantlyRepairable = target.TraitOrDefault<InstantlyRepairable>();
if (instantlyRepairable == null || instantlyRepairable.IsTraitDisabled)
return false;
if (!engineerRepairable.Info.Types.IsEmpty && !engineerRepairable.Info.Types.Overlaps(info.Types))
if (!instantlyRepairable.Info.Types.IsEmpty && !instantlyRepairable.Info.Types.Overlaps(info.Types))
return false;
if (!info.ValidRelationships.HasRelationship(target.Owner.RelationshipWith(self.Owner)))
@@ -131,14 +131,14 @@ namespace OpenRA.Mods.Common.Traits
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
// TODO: FrozenActors don't yet have a way of caching conditions, so we can't filter disabled traits
// This therefore assumes that all EngineerRepairable traits are enabled, which is probably wrong.
// Actors with FrozenUnderFog should therefore not disable the EngineerRepairable trait if
// This therefore assumes that all InstantlyRepairable traits are enabled, which is probably wrong.
// Actors with FrozenUnderFog should therefore not disable the InstantlyRepairable trait if
// ValidStances includes Enemy actors.
var engineerRepairable = target.Info.TraitInfoOrDefault<EngineerRepairableInfo>();
if (engineerRepairable == null)
var instantlyRepairable = target.Info.TraitInfoOrDefault<InstantlyRepairableInfo>();
if (instantlyRepairable == null)
return false;
if (!engineerRepairable.Types.IsEmpty && !engineerRepairable.Types.Overlaps(info.Types))
if (!instantlyRepairable.Types.IsEmpty && !instantlyRepairable.Types.Overlaps(info.Types))
return false;
if (!info.ValidRelationships.HasRelationship(target.Owner.RelationshipWith(self.Owner)))

View File

@@ -0,0 +1,31 @@
#region Copyright & License Information
/*
* Copyright (c) The OpenRA Developers and Contributors
* 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
namespace OpenRA.Mods.Common.UpdateRules.Rules
{
public class RenameEngineerRepair : UpdateRule
{
public override string Name => "Traits revolving around instant (building) repairs were renamed.";
public override string Description =>
"'EngineerRepair' was renamed to 'InstantlyRepairs' " +
"and 'EngineerRepairable' to 'InstantlyRepairable'.";
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
{
actorNode.RenameChildrenMatching("EngineerRepair", "InstantlyRepairs");
actorNode.RenameChildrenMatching("EngineerRepairable", "InstantlyRepairable");
yield break;
}
}
}

View File

@@ -104,6 +104,7 @@ namespace OpenRA.Mods.Common.UpdateRules
{
new TextNotificationsDisplayWidgetRemoveTime(),
new ExplicitSequenceFilenames(),
new RenameEngineerRepair(),
})
};