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): let a scenario board a transport with enter

Olcay Seygand1ff5a43cc5b
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
index 1e6f26bcb..3c3d4de64 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h
@@ -64,7 +64,8 @@ enum ScenarioActionType
SCENARIO_ACTION_ATTACK, ///< attack <slot> <selector> <targetSlot> <targetSelector>
SCENARIO_ACTION_STOP, ///< stop <slot> <selector>
SCENARIO_ACTION_ARRIVE, ///< arrive <slot> <selector> <position> [radius]
- SCENARIO_ACTION_PARTICLES ///< particles <slot> <systemTemplate> <count> <position> [spacing]; slot is read and ignored
+ SCENARIO_ACTION_PARTICLES, ///< particles <slot> <systemTemplate> <count> <position> [spacing]; slot is read and ignored
+ SCENARIO_ACTION_ENTER ///< enter <slot> <selector> <targetSlot> <targetSelector>
};
/// 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 8c8b7bebd..708d665d6 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp
@@ -159,6 +159,8 @@ static Bool parseActionType( const AsciiString &token, ScenarioActionType *actio
*action = SCENARIO_ACTION_ATTACKMOVE;
else if (token == "attack")
*action = SCENARIO_ACTION_ATTACK;
+ else if (token == "enter")
+ *action = SCENARIO_ACTION_ENTER;
else if (token == "stop")
*action = SCENARIO_ACTION_STOP;
else if (token == "arrive")
@@ -241,6 +243,7 @@ static Int tokensNeededFor( ScenarioActionType action )
case SCENARIO_ACTION_MOVE: 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;
case SCENARIO_ACTION_STOP: return SCENARIO_TOKENS_STOP;
case SCENARIO_ACTION_ARRIVE: return SCENARIO_TOKENS_ARRIVE;
}
@@ -316,6 +319,7 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *a
}
case SCENARIO_ACTION_ATTACK:
+ case SCENARIO_ACTION_ENTER:
{
if (!parseWholeNumber( tokens[ 4 ], &action->targetSlot ))
return SCENARIO_PARSE_BAD_SLOT;
@@ -787,22 +791,28 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Co
}
case SCENARIO_ACTION_ATTACK:
+ case SCENARIO_ACTION_ENTER:
{
+ const char *verb = (action.action == SCENARIO_ACTION_ATTACK) ? "attack" : "enter";
Player *targetPlayer = findPlayerForSlot( action.targetSlot );
- Object *victim = (targetPlayer != NULL)
+ Object *target = (targetPlayer != NULL)
? findFirstMatching( targetPlayer, action.targetSelector )
: NULL;
- if (victim == NULL)
+ if (target == NULL)
{
- DEBUG_LOG(("SCENARIO: frame %d attack: slot %d owns nothing matching '%s'\n",
- action.frame, action.targetSlot, action.targetSelector.str()));
+ DEBUG_LOG(("SCENARIO: frame %d %s: slot %d owns nothing matching '%s'\n",
+ action.frame, verb, action.targetSlot, action.targetSelector.str()));
ordered = FALSE;
break;
}
- group->groupAttackObject( victim, SCENARIO_ATTACK_SHOTS, CMD_FROM_SCRIPT );
- DEBUG_LOG(("SCENARIO: frame %d attack slot %d '%s' x%d -> slot %d '%s'\n",
- action.frame, action.slot, action.selector.str(), taken,
+ if (action.action == SCENARIO_ACTION_ATTACK)
+ group->groupAttackObject( target, SCENARIO_ATTACK_SHOTS, CMD_FROM_SCRIPT );
+ else
+ group->groupEnter( target, CMD_FROM_SCRIPT );
+
+ DEBUG_LOG(("SCENARIO: frame %d %s slot %d '%s' x%d -> slot %d '%s'\n",
+ action.frame, verb, action.slot, action.selector.str(), taken,
action.targetSlot, action.targetSelector.str()));
break;
}
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 9b44094d4..d6dc1b0e4 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -11744,6 +11744,13 @@ TEST(scenario_parses_the_order_lines)
CHECK_EQ( action.targetSlot, 1 );
CHECK_STR( action.targetSelector.str(), "AmericaCommandCenter" );
+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "40 enter 0 AmericaInfantryMissileDefender 0 AmericaVehicleHumvee", &action ),
+ (Int)SCENARIO_PARSE_OK );
+ CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_ENTER );
+ CHECK_EQ( action.targetSlot, 0 );
+ CHECK_STR( action.targetSelector.str(), "AmericaVehicleHumvee" );
+ CHECK_EQ( (Int)ScenarioDrill_parseLine( "40 enter 0 * 0", &action ), (Int)SCENARIO_PARSE_MISSING_ARGS );
+
CHECK_EQ( (Int)ScenarioDrill_parseLine( "900 stop 2 *", &action ), (Int)SCENARIO_PARSE_OK );
CHECK_EQ( (Int)action.action, (Int)SCENARIO_ACTION_STOP );
}