Skip to content

Commit

Permalink
Testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
dnqbob committed Nov 1, 2023
1 parent 64f8ef5 commit 9c01db0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
47 changes: 47 additions & 0 deletions OpenRA.Mods.Common/Scripting/Global/WorldActorConditionGlobal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Linq;
using Eluant;
using OpenRA.Mods.Common.Traits;
using OpenRA.Scripting;

namespace OpenRA.Mods.Common.Scripting
{
[ScriptGlobal("WorldActor")]
public class WorldActorConditionGlobal : ScriptGlobal
{
public WorldActorConditionGlobal(ScriptContext context)
: base(context)
{
externalConditions = context.World.WorldActor.TraitsImplementing<ExternalCondition>().ToArray();
}

readonly ExternalCondition[] externalConditions;

[Desc("Grant an external condition on world actor and return the revocation token.",
"Conditions must be defined on an ExternalConditions trait on the actor.",
"If duration > 0 the condition will be automatically revoked after the defined number of ticks.")]
public int GrantCondition(string condition, int duration = 0)
{
var external = Array.Find(externalConditions, t => t.Info.Condition == condition && t.CanGrantCondition(this));

if (external == null)
throw new LuaException($"Condition `{condition}` has not been listed on an enabled ExternalCondition trait");

return external.GrantCondition(Context.World.WorldActor, this, duration);
}

[Desc("Revoke a condition on world actor using the token returned by GrantCondition.")]
public void RevokeCondition(int token)
{
foreach (var external in externalConditions)
if (external.TryRevokeCondition(Context.World.WorldActor, this, token))
break;
}

[Desc("Check whether world actor accepts a specific external condition.")]
public bool AcceptsCondition(string condition)
{
return Array.Exists(externalConditions, t => t.Info.Condition == condition && t.CanGrantCondition(this));
}
}
}
8 changes: 8 additions & 0 deletions mods/ra/maps/desert-shellmap/desert-shellmap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ ChronoshiftAlliedUnits = function()
Trigger.AfterDelay(DateTime.Seconds(60), ChronoshiftAlliedUnits)
end

DesertSandStormLoop = function()
WorldActor.GrantCondition("sandstorm", 1000)
Trigger.AfterDelay(2500, function()
DesertSandStormLoop()
end)
end

Ticks = 0
Speed = 5

Expand All @@ -188,6 +195,7 @@ WorldLoaded = function()
SetupAlliedUnits()
SetupFactories()
ShipAlliedUnits()
DesertSandStormLoop()
InsertAlliedChinookReinforcements(Chinook1Entry, HeliPad1)
InsertAlliedChinookReinforcements(Chinook2Entry, HeliPad2)
PowerProxy = Actor.Create(ProxyType, false, { Owner = Soviets })
Expand Down
21 changes: 21 additions & 0 deletions mods/ra/maps/desert-shellmap/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ World:
LuaScript:
Scripts: desert-shellmap.lua
-StartGameNotification:
ExternalCondition@sandstorm:
Condition: sandstorm
WeatherOverlay:
ChangingWindLevel: false
WindLevels: 12, 7, 11, 8, 10, 9
WindTick: 150, 550
InstantWindChanges: false
UseSquares: false
ParticleSize: 1, 1
ParticleDensityFactor: 32
ScatterDirection: 0, 0
Gravity: -2.00, 2.00
SwingOffset: 0, 0
SwingSpeed: 0.001, 0.008
SwingAmplitude: 0.2, 0.3
ParticleColors: 686064, 986854, B48854, BD8D7E, CAA264, CB9367
LineTailAlphaValue: 150
InitialParticlePercentage: 0
FadeInTicks: 500
FadeOutTicks: 750
RequiresCondition: sandstorm

^ExistsInWorld:
GivesExperience:
Expand Down

0 comments on commit 9c01db0

Please sign in to comment.