Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameengine): fire special powers from a scenario file

Olcay Seygan196918f85554
diff --git a/GeneralsMD/Code/Data/Cinema/tr_chaos.txt b/GeneralsMD/Code/Data/Cinema/tr_chaos.txt
new file mode 100644
index 000000000..78b1358ad
--- /dev/null
+++ b/GeneralsMD/Code/Data/Cinema/tr_chaos.txt
@@ -0,0 +1,17 @@
+# Trailer: the trailer_chaos fight, ten seconds, frames 930 to 1229. Filmed twice for a morph, once
+# with ClassicGraphics = yes in Options.ini and once without; everything else identical.
+#
+# generals.exe -borderless -msaa 0 -quickstart -noshellmap -observer -multiInstance
+# -particlecap 5000 -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 3 -takeover
+# -side 0 FactionAmerica -side 1 FactionChina -side 2 FactionGLA -seed 7
+# -scenario trailer_chaos -cinema tr_chaos -video 930 1229 tr_chaos -maxframes 1250
+#
+# Aimed at 1075,3775, between the particle beam (1080,3740) and the nuke (1060,3790), because the
+# fight sits there and not on the midpoint the armies were sent to. Pitch 0: at +8 the top sixth of
+# the frame was black past the map edge. A slow push-in and a 20 degree turn over the whole ten
+# seconds, so the first and last frames are the same place seen slightly apart.
+
+30 cut 1075 3775 0.85 -45 0
+31 zoom 0.7 10
+31 orbit 20 10
+42 end
diff --git a/GeneralsMD/Code/Data/Scenarios/trailer_chaos.txt b/GeneralsMD/Code/Data/Scenarios/trailer_chaos.txt
new file mode 100644
index 000000000..6c978eb13
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/trailer_chaos.txt
@@ -0,0 +1,78 @@
+# Trailer: three armies, the air over them and three superweapons, all inside one ten-second shot.
+# America, China and the GLA each attack-move on 1135,3696, the midpoint of the two 2-player starts
+# on Twilight Flame (see docs/reference/UI-MAP.md). Every seat is an enemy of every other.
+# The superweapons and the command centers whose general's powers bring the aircraft in sit back at
+# the start positions, powered, and are fired with the power verb so they need no charge time.
+#
+# generals.exe -borderless -msaa 0 -quickstart -noshellmap -observer -multiInstance
+# -particlecap 5000 -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 3 -takeover
+# -side 0 FactionAmerica -side 1 FactionChina -side 2 FactionGLA -seed 7
+# -scenario trailer_chaos -cinema tr_chaos -video 930 1229 tr_chaos -maxframes 1250
+#
+# The shot is frames 930 to 1229, ten seconds at 30 a second.
+
+# --- the buildings, far out of frame -------------------------------------------------------
+10 spawn 0 AmericaParticleCannonUplink 1 start0:0:-200
+10 spawn 0 AmericaPowerPlant 3 start0:-260:40 90
+10 spawn 0 AmericaCommandCenter 1 start0:240:60
+10 spawn 1 ChinaNuclearMissileLauncher 1 start1:0:200
+10 spawn 1 ChinaPowerPlant 3 start1:260:-40 90
+10 spawn 1 ChinaCommandCenter 1 start1:-260:60
+10 spawn 2 GLAScudStorm 1 start2:0:200
+10 spawn 2 GLACommandCenter 1 start2:-260:0
+
+# --- the armies ----------------------------------------------------------------------------
+30 spawn 0 AmericaTankCrusader 12 790 3420 36
+30 spawn 0 AmericaTankPaladin 6 700 3520 40
+30 spawn 0 AmericaVehicleTomahawk 4 690 3380 40
+30 spawn 0 AmericaTankMicrowave 3 860 3330 40
+30 spawn 0 AmericaInfantryRanger 16 880 3480 18
+30 spawn 0 AmericaVehicleComanche 6 700 3300 60
+30 spawn 0 AmericaJetRaptor 4 640 3250 70
+
+30 spawn 1 ChinaTankOverlord 5 1480 3980 50
+30 spawn 1 ChinaTankBattleMaster 10 1400 4040 40
+30 spawn 1 ChinaTankGattling 5 1560 3900 36
+30 spawn 1 ChinaTankDragon 4 1380 3920 36
+30 spawn 1 ChinaVehicleInfernoCannon 4 1540 4060 40
+30 spawn 1 ChinaInfantryRedguard 16 1330 4010 18
+30 spawn 1 ChinaVehicleHelix 3 1600 4050 60
+30 spawn 1 ChinaJetMIG 4 1650 4120 70
+
+30 spawn 2 GLATankScorpion 10 1460 3400 36
+30 spawn 2 GLATankMarauder 5 1540 3440 40
+30 spawn 2 GLAVehicleRocketBuggy 6 1400 3330 32
+30 spawn 2 GLAVehicleQuadCannon 4 1520 3330 36
+30 spawn 2 GLAVehicleToxinTruck 3 1600 3380 36
+30 spawn 2 GLAVehicleTechnical 6 1380 3460 30
+30 spawn 2 GLAInfantryRebel 16 1450 3500 18
+
+60 attackmove 0 * 1135 3696
+60 attackmove 1 * 1135 3696
+60 attackmove 2 * 1135 3696
+
+# --- the second wave, so the fight is still being fed while the camera rolls --------------
+600 spawn 0 AmericaTankCrusader 8 790 3420 36
+600 spawn 0 AmericaTankPaladin 4 700 3520 40
+600 spawn 1 ChinaTankBattleMaster 8 1400 4040 40
+600 spawn 1 ChinaTankOverlord 3 1480 3980 50
+600 spawn 2 GLATankScorpion 8 1460 3400 36
+600 spawn 2 GLATankMarauder 3 1540 3440 40
+630 attackmove 0 * 1135 3696
+630 attackmove 1 * 1135 3696
+630 attackmove 2 * 1135 3696
+
+# --- the sky -------------------------------------------------------------------------------
+# A general's power reaches the target about 400 frames after it is called, flying in from the map
+# edge, so these are called well before the shot.
+450 power 0 AmericaCommandCenter 1135 3696 SuperweaponSpectreGunship
+560 power 0 AmericaCommandCenter 980 3600 SuperweaponA10ThunderboltMissileStrike
+640 power 1 ChinaCommandCenter 1300 3700 Early_SuperweaponChinaCarpetBomb
+700 power 2 GLACommandCenter 1150 3560 SuperweaponAnthraxBomb
+
+# --- the superweapons ----------------------------------------------------------------------
+# The beam touches down 75 frames after the call and stays 300: frames 930 to 1230, the whole shot.
+# The nuke took 170 frames from this silo in the first probe, the SCUDs about 130.
+855 power 0 AmericaParticleCannonUplink 1080 3740
+830 power 1 ChinaNuclearMissileLauncher 1060 3790
+930 power 2 GLAScudStorm 1200 3640
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
index 02fcfe0f6..885df4e2b 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
@@ -66,7 +66,8 @@ enum ScenarioActionType
SCENARIO_ACTION_ARRIVE, ///< arrive <slot> <selector> <position> [radius]
SCENARIO_ACTION_PARTICLES, ///< particles <slot> <systemTemplate> <count> <position> [spacing]; slot is read and ignored
SCENARIO_ACTION_ENTER, ///< enter <slot> <selector> <targetSlot> <targetSelector>
- SCENARIO_ACTION_PLAYERMOVE ///< playermove <slot> <selector> <position>; a right click, not a script order
+ SCENARIO_ACTION_PLAYERMOVE, ///< playermove <slot> <selector> <position>; a right click, not a script order
+ SCENARIO_ACTION_POWER ///< power <slot> <building> <position> [powerName]; fire its special powers (or the one named) there now, charged or not
};
/// ScenarioAction::atStart when the position is plain numbers
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
index 8c4cebeb3..1ac1a9f8e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
@@ -39,9 +39,11 @@
#include "GameLogic/Module/AIUpdate.h"
#include "GameLogic/Module/BehaviorModule.h"
#include "GameLogic/Module/CreateModule.h"
+#include "GameLogic/Module/SpecialPowerModule.h"
#include "GameLogic/Object.h"
#include "GameLogic/ScenarioDrill.h"
#include "GameLogic/TerrainLogic.h"
+#include "GameClient/ControlBar.h" // COMMAND_FIRED_BY_SCRIPT, the flag every script-fired power carries
#include "GameClient/ParticleSys.h"
#include <algorithm>
@@ -169,6 +171,8 @@ static Bool parseActionType( const AsciiString &token, ScenarioActionType *actio
*action = SCENARIO_ACTION_ARRIVE;
else if (token == "particles")
*action = SCENARIO_ACTION_PARTICLES;
+ else if (token == "power")
+ *action = SCENARIO_ACTION_POWER;
else
return FALSE;
@@ -244,6 +248,7 @@ static Int tokensNeededFor( ScenarioActionType action )
case SCENARIO_ACTION_PARTICLES: return SCENARIO_TOKENS_SPAWN;
case SCENARIO_ACTION_MOVE: return SCENARIO_TOKENS_MOVE;
case SCENARIO_ACTION_PLAYERMOVE: return SCENARIO_TOKENS_MOVE;
+ case SCENARIO_ACTION_POWER: return SCENARIO_TOKENS_MOVE;
case SCENARIO_ACTION_ATTACKMOVE: return SCENARIO_TOKENS_MOVE;
case SCENARIO_ACTION_ATTACK: return SCENARIO_TOKENS_ATTACK;
case SCENARIO_ACTION_ENTER: return SCENARIO_TOKENS_ATTACK;
@@ -312,6 +317,7 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *a
case SCENARIO_ACTION_PLAYERMOVE:
case SCENARIO_ACTION_ATTACKMOVE:
case SCENARIO_ACTION_ARRIVE:
+ case SCENARIO_ACTION_POWER:
{
Int next = SCENARIO_ORDER_POSITION_TOKEN;
const ScenarioParseResult position = parseScenarioPosition( tokens, count, &next, action );
@@ -319,6 +325,8 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *a
return position;
if (actionType == SCENARIO_ACTION_ARRIVE && count > next)
action->radius = (Real)atof( tokens[ next ].str() );
+ if (actionType == SCENARIO_ACTION_POWER && count > next)
+ action->targetSelector = tokens[ next ]; // fire only the power of this name
break;
}
@@ -864,6 +872,44 @@ void ScenarioDrill_logArrivals( void )
}
}
+/** Fire every special power the first matching building of this seat carries, at the position, the
+ way a map script's "fire special power at waypoint" does. A script fire does not wait for the
+ countdown, so a superweapon spawned a second ago goes off; it still needs power and must not be
+ disabled, which is what the refusal line reports. */
+static Bool executePower( const ScenarioAction &action, Player *player, const Coord3D &target )
+{
+ Object *obj = findFirstMatching( player, action.selector );
+ if (obj == NULL)
+ {
+ DEBUG_LOG(("SCENARIO: frame %d power: slot %d owns nothing matching '%s'\n",
+ action.frame, action.slot, action.selector.str()));
+ return FALSE;
+ }
+
+ if (obj->isDisabled())
+ {
+ DEBUG_LOG(("SCENARIO: frame %d power: '%s' is disabled (no power?)\n",
+ action.frame, action.selector.str()));
+ return FALSE;
+ }
+
+ Int fired = 0;
+ for( BehaviorModule **m = obj->getBehaviorModules(); *m; ++m )
+ {
+ SpecialPowerModuleInterface *power = (*m)->getSpecialPower();
+ if (power == NULL)
+ continue;
+ if (!action.targetSelector.isEmpty() && power->getPowerName() != action.targetSelector)
+ continue;
+ power->doSpecialPowerAtLocation( &target, INVALID_ANGLE, COMMAND_FIRED_BY_SCRIPT );
+ ++fired;
+ }
+
+ DEBUG_LOG(("SCENARIO: frame %d power slot %d '%s' fired %d at (%.0f,%.0f)\n",
+ action.frame, action.slot, action.selector.str(), fired, target.x, target.y));
+ return fired > 0;
+}
+
static Bool executeOrder( const ScenarioAction &action, Player *player, const Coord3D &dest )
{
AIGroup *group = TheAI->createGroup();
@@ -937,6 +983,7 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Co
case SCENARIO_ACTION_SPAWN:
case SCENARIO_ACTION_ARRIVE:
case SCENARIO_ACTION_PARTICLES:
+ case SCENARIO_ACTION_POWER:
ordered = FALSE; // handled before the group is built
break;
}
@@ -967,6 +1014,9 @@ Bool ScenarioDrill_execute( const ScenarioAction &action )
if (action.action == SCENARIO_ACTION_ARRIVE)
return executeArrive( action, player, position );
+ if (action.action == SCENARIO_ACTION_POWER)
+ return executePower( action, player, position );
+
return executeOrder( action, player, position );
}
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index ac23b622d..0b61984de 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -12908,6 +12908,18 @@ TEST(scenario_parses_the_order_lines)
CHECK_EQ( (Int)ScenarioDrill_parseLine( "900 stop 2 *", &action ), (Int)SCENARIO_PARSE_OK );
CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_STOP );
+
+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "700 power 1 GLAScudStorm start0:0:300", &action ),
+ (Int)SCENARIO_PARSE_OK );
+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_POWER );
+ CHECK_STR( action.selector.str(), "GLAScudStorm" );
+ CHECK_EQ( action.atStart, 0 );
+ CHECK_NEAR( action.at.y, 300.0f, 0.01f );
+ CHECK_EQ( (Int)action.targetSelector.isEmpty(), 1 );
+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "700 power 0 AmericaCommandCenter 900 900 SuperweaponA10ThunderboltMissileStrike", &action ),
+ (Int)SCENARIO_PARSE_OK );
+ CHECK_STR( action.targetSelector.str(), "SuperweaponA10ThunderboltMissileStrike" );
+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "700 power 1 GLAScudStorm", &action ), (Int)SCENARIO_PARSE_MISSING_ARGS );
}
TEST(scenario_ignores_comments_and_blank_lines)