Remove IExplodeModifier interface.

This commit is contained in:
Paul Chote
2018-11-17 09:13:28 +00:00
committed by Oliver Brakmann
parent 80842fd4b8
commit 807a40c209
12 changed files with 72 additions and 11 deletions

View File

@@ -596,6 +596,7 @@
<Compile Include="Traits\ActorSpawner.cs" />
<Compile Include="UpdateRules\Rules\20180923\RemovedDemolishLocking.cs" />
<Compile Include="UpdateRules\Rules\20180923\RemoveNegativeDamageFullHealthCheck.cs" />
<Compile Include="UpdateRules\Rules\20180923\RemoveResourceExplodeModifier.cs" />
<Compile Include="UpdateRules\Rules\20180923\RenameCrateActionNotification.cs" />
<Compile Include="UpdateRules\Rules\20180923\CloakRequiresConditionToPause.cs" />
<Compile Include="UpdateRules\Rules\20180923\MergeCaptureTraits.cs" />

View File

@@ -101,7 +101,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
public class Armament : PausableConditionalTrait<ArmamentInfo>, ITick, IExplodeModifier
public class Armament : PausableConditionalTrait<ArmamentInfo>, ITick
{
public readonly WeaponInfo Weapon;
public readonly Barrel[] Barrels;
@@ -369,8 +369,6 @@ namespace OpenRA.Mods.Common.Traits
}
public virtual bool IsReloading { get { return FireDelay > 0 || IsTraitDisabled; } }
public virtual bool AllowExplode { get { return !IsReloading; } }
bool IExplodeModifier.ShouldExplode(Actor self) { return AllowExplode; }
public WVec MuzzleOffset(Actor self, Barrel b)
{

View File

@@ -127,7 +127,12 @@ namespace OpenRA.Mods.Common.Traits
WeaponInfo ChooseWeaponForExplosion(Actor self)
{
var shouldExplode = self.TraitsImplementing<IExplodeModifier>().All(a => a.ShouldExplode(self));
var armaments = self.TraitsImplementing<Armament>();
if (!armaments.Any())
return Info.WeaponInfo;
// TODO: EmptyWeapon should be removed in favour of conditions
var shouldExplode = !armaments.All(a => a.IsReloading);
var useFullExplosion = self.World.SharedRandom.Next(100) <= Info.LoadedChance;
return (shouldExplode && useFullExplosion) ? Info.WeaponInfo : Info.EmptyWeaponInfo;
}

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new Harvester(init.Self, this); }
}
public class Harvester : IIssueOrder, IResolveOrder, IPips, IExplodeModifier, IOrderVoice,
public class Harvester : IIssueOrder, IResolveOrder, IPips, IOrderVoice,
ISpeedModifier, ISync, INotifyCreated, INotifyIdle, INotifyBlockingMove
{
public readonly HarvesterInfo Info;
@@ -470,8 +470,6 @@ namespace OpenRA.Mods.Common.Traits
yield return GetPipAt(i);
}
bool IExplodeModifier.ShouldExplode(Actor self) { return !IsEmpty; }
int ISpeedModifier.GetSpeedModifier()
{
return 100 - (100 - Info.FullyLoadedSpeed) * contents.Values.Sum() / Info.Capacity;

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
public object Create(ActorInitializer init) { return new StoresResources(init.Self, this); }
}
class StoresResources : IPips, INotifyOwnerChanged, INotifyCapture, IExplodeModifier, IStoreResources, ISync, INotifyKilled
class StoresResources : IPips, INotifyOwnerChanged, INotifyCapture, IStoreResources, ISync, INotifyKilled
{
readonly StoresResourcesInfo info;
PlayerResources player;
@@ -70,7 +70,5 @@ namespace OpenRA.Mods.Common.Traits
player.Resources * info.PipCount > i * player.ResourceCapacity
? info.PipColor : PipType.Transparent);
}
bool IExplodeModifier.ShouldExplode(Actor self) { return Stored > 0; }
}
}

View File

@@ -142,7 +142,6 @@ namespace OpenRA.Mods.Common.Traits
public interface IRenderActorPreviewInfo : ITraitInfo { IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init); }
public interface ICruiseAltitudeInfo : ITraitInfo { WDist GetCruiseAltitude(); }
public interface IExplodeModifier { bool ShouldExplode(Actor self); }
public interface IHuskModifier { string HuskActor(Actor self); }
public interface ISeedableResource { void Seed(Actor self); }

View File

@@ -0,0 +1,49 @@
#region Copyright & License Information
/*
* Copyright 2007-2018 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
namespace OpenRA.Mods.Common.UpdateRules.Rules
{
public class RemoveResourceExplodeModifier : UpdateRule
{
public override string Name { get { return "Harvester and StoresResources traits no longer force Explodes.EmptyWeapon"; } }
public override string Description
{
get
{
return "The hardcoded behaviour forcing Explodes to use EmptyWeapon when the harvester/player has no\n" +
"resources has been removed. Affected actors are listed so that conditions may be manually defined.";
}
}
readonly List<string> locations = new List<string>();
public override IEnumerable<string> AfterUpdate(ModData modData)
{
if (locations.Any())
yield return "Review the following definitions and, if the actor uses Harvester or StoresResources,\n" +
"define a new Explodes trait with the previous EmptyWeapon, enabled by Harvester.EmptyCondition or\n" +
"GrantConditionOnPlayerResources.Condition (negated):\n" + UpdateUtils.FormatMessageList(locations);
locations.Clear();
}
public override IEnumerable<string> UpdateActorNode(ModData modData, MiniYamlNode actorNode)
{
if (actorNode.LastChildMatching("Explodes") != null)
locations.Add("{0} ({1})".F(actorNode.Key, actorNode.Location.Filename));
yield break;
}
}
}

View File

@@ -108,6 +108,7 @@ namespace OpenRA.Mods.Common.UpdateRules
new AddBotOrderManager(),
new AddHarvesterBotModule(),
new RemoveNegativeDamageFullHealthCheck(),
new RemoveResourceExplodeModifier(),
})
};

View File

@@ -66,6 +66,7 @@ HARV:
BaleUnloadDelay: 6
SearchFromProcRadius: 25
SearchFromOrderRadius: 15
EmptyCondition: no-tiberium
Mobile:
Speed: 85
Health:
@@ -83,6 +84,7 @@ HARV:
WithHarvestAnimation:
WithDockingAnimation:
Explodes:
RequiresCondition: !no-tiberium
Weapon: TiberiumExplosion
SelectionDecorations:

View File

@@ -301,6 +301,7 @@ HARV:
BaleUnloadDelay: 1
SearchFromProcRadius: 30
SearchFromOrderRadius: 11
EmptyCondition: no-ore
Health:
HP: 60000
Armor:
@@ -328,6 +329,7 @@ HARV:
HealIfBelow: 50
DamageCooldown: 500
Explodes:
RequiresCondition: !no-ore
Weapon: OreExplosion
MCV:

View File

@@ -123,7 +123,10 @@ PROC:
FactionImages:
gdi: proc.gdi
nod: proc.nod
GrantConditionOnPlayerResources:
Condition: contains-tiberium
Explodes:
RequiresCondition: contains-tiberium
Weapon: TiberiumExplosion
GASILO:
@@ -172,7 +175,10 @@ GASILO:
Power:
Amount: -10
SelectionDecorations:
GrantConditionOnPlayerResources:
Condition: contains-tiberium
Explodes:
RequiresCondition: contains-tiberium
Weapon: TiberiumExplosion
ANYPOWER:

View File

@@ -67,6 +67,7 @@ HARV:
SearchFromOrderRadius: 18
HarvestVoice: Attack
DeliverVoice: Move
EmptyCondition: no-tiberium
Mobile:
Speed: 71
Health:
@@ -85,6 +86,7 @@ HARV:
-WithVoxelBody:
WithVoxelUnloadBody:
Explodes:
RequiresCondition: !no-tiberium
Weapon: TiberiumExplosion
WithHarvestOverlay:
LocalOffset: 543,0,0