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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
test(gameengine): scenario purchase and resume verbs
Olcay Seygan050816fbee39
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.hindex f13491a61..f493851c6 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h@@ -75,6 +75,8 @@ enum ScenarioActionTypeSCENARIO_ACTION_PLAYERATTACKMOVE, ///< playerattackmove <slot> <selector> <position>; the player's attack move, not a script'sSCENARIO_ACTION_PRODUCE, ///< produce <slot> <building> <template> <count>; queue that many in its first matching buildingSCENARIO_ACTION_TALLY, ///< tally <slot> <selector>; log how many are alive, their health and what they cost+ SCENARIO_ACTION_RESUME, ///< resume <slot> <selector> <targetSlot> <targetSelector>; a player's right click of builders on a half-built structure+ SCENARIO_ACTION_PURCHASE, ///< purchase <slot> <science>; the rank needed and the points, then MSG_PURCHASE_SCIENCE as the science button sends itSCENARIO_ACTION_SHIFTMOVE, ///< shiftmove <slot> <selector> <position>; a shift right click, onto the units' order queueSCENARIO_ACTION_SHIFTATTACKMOVE, ///< shiftattackmove <slot> <selector> <position>; the same with attack moveSCENARIO_ACTION_SHIFTATTACK, ///< shiftattack <slot> <selector> <targetSlot> <targetSelector>; the same with an attack on one unitdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cppindex a941cef1b..7d2bc77f7 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp@@ -33,6 +33,7 @@#include "Common/Player.h"#include "Common/MessageStream.h"#include "Common/PlayerList.h"+#include "Common/Science.h"#include "Common/SpecialPower.h"#include "Common/Team.h"#include "Common/ThingFactory.h"@@ -201,6 +202,10 @@ static Bool parseActionType( const AsciiString &token, ScenarioActionType *actio*action = SCENARIO_ACTION_PRODUCE;else if (token == "tally")*action = SCENARIO_ACTION_TALLY;+ else if (token == "purchase")+ *action = SCENARIO_ACTION_PURCHASE;+ else if (token == "resume")+ *action = SCENARIO_ACTION_RESUME;else if (token == "shiftmove")*action = SCENARIO_ACTION_SHIFTMOVE;else if (token == "shiftattackmove")@@ -320,10 +325,12 @@ static Int tokensNeededFor( ScenarioActionType action )case SCENARIO_ACTION_SHIFTUPGRADE: return SCENARIO_TOKENS_SHIFTUPGRADE;case SCENARIO_ACTION_ATTACK: return SCENARIO_TOKENS_ATTACK;case SCENARIO_ACTION_ENTER: return SCENARIO_TOKENS_ATTACK;+ case SCENARIO_ACTION_RESUME: return SCENARIO_TOKENS_ATTACK;case SCENARIO_ACTION_DOCK: return SCENARIO_TOKENS_ATTACK;case SCENARIO_ACTION_PRODUCE: return SCENARIO_TOKENS_ATTACK;case SCENARIO_ACTION_STOP: return SCENARIO_TOKENS_STOP;case SCENARIO_ACTION_TALLY: return SCENARIO_TOKENS_STOP;+ case SCENARIO_ACTION_PURCHASE: return SCENARIO_TOKENS_STOP;case SCENARIO_ACTION_ARRIVE: return SCENARIO_TOKENS_ARRIVE;}return SCENARIO_TOKENS_STOP;@@ -423,6 +430,7 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *acase SCENARIO_ACTION_ATTACK:case SCENARIO_ACTION_ENTER:+ case SCENARIO_ACTION_RESUME:case SCENARIO_ACTION_DOCK:case SCENARIO_ACTION_SHIFTATTACK:case SCENARIO_ACTION_FORCEATTACK:@@ -456,6 +464,7 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *acase SCENARIO_ACTION_STOP:case SCENARIO_ACTION_TALLY:+ case SCENARIO_ACTION_PURCHASE:break;}@@ -1568,6 +1577,37 @@ static Bool executeSweep( const ScenarioAction &action, Player *player, const Coreturn TRUE;}+/** The rank tree's button: the player is raised to the rank the science asks for and given the points+ it costs, and then MSG_PURCHASE_SCIENCE goes to the dispatcher as the control bar sends it, so the+ purchase itself is the one a click makes. */+static const Int SCENARIO_HIGHEST_RANK = 5;++static Bool executePurchase( const ScenarioAction &action, Player *player )+{+ const ScienceType science = TheScienceStore->getScienceFromInternalName( action.selector );+ if (science == SCIENCE_INVALID)+ {+ DEBUG_LOG(("SCENARIO: frame %d purchase: there is no science '%s'\n", action.frame, action.selector.str()));+ return FALSE;+ }++ while (!TheScienceStore->playerHasPrereqsForScience( player, science ) && player->getRankLevel() < SCENARIO_HIGHEST_RANK)+ player->setRankLevel( player->getRankLevel() + 1 );+ const Int cost = TheScienceStore->getSciencePurchaseCost( science );+ if (player->getSciencePurchasePoints() < cost)+ player->addSciencePurchasePoints( cost - player->getSciencePurchasePoints() );++ GameMessage *msg = newInstance( GameMessage )( GameMessage::MSG_PURCHASE_SCIENCE );+ msg->friend_setPlayerIndex( player->getPlayerIndex() );+ msg->appendIntegerArgument( science );+ TheGameLogic->logicMessageDispatcher( msg, NULL );+ msg->deleteInstance();++ DEBUG_LOG(("SCENARIO: frame %d purchase slot %d '%s' rank %d: %s\n", action.frame, action.slot,+ action.selector.str(), player->getRankLevel(), player->hasScience( science ) ? "bought" : "refused"));+ return player->hasScience( science );+}+static Bool executeOrder( const ScenarioAction &action, Player *player, const Coord3D &dest ){if (action.action == SCENARIO_ACTION_SHIFTUPGRADE)@@ -1613,10 +1653,12 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Cocase SCENARIO_ACTION_ATTACK:case SCENARIO_ACTION_ENTER:+ case SCENARIO_ACTION_RESUME:case SCENARIO_ACTION_DOCK:{const char *verb = (action.action == SCENARIO_ACTION_ATTACK) ? "attack"- : (action.action == SCENARIO_ACTION_DOCK) ? "dock" : "enter";+ : (action.action == SCENARIO_ACTION_DOCK) ? "dock"+ : (action.action == SCENARIO_ACTION_RESUME) ? "resume" : "enter";Player *targetPlayer = findPlayerForSlot( action.targetSlot );Object *target = (targetPlayer != NULL)? findFirstMatching( targetPlayer, action.targetSelector )@@ -1633,6 +1675,8 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Cogroup->groupAttackObject( target, SCENARIO_ATTACK_SHOTS, CMD_FROM_SCRIPT );else if (action.action == SCENARIO_ACTION_DOCK)group->groupDock( target, CMD_FROM_SCRIPT );+ else if (action.action == SCENARIO_ACTION_RESUME)+ group->groupResumeConstruction( target, CMD_FROM_PLAYER );elsegroup->groupEnter( target, CMD_FROM_SCRIPT );@@ -1755,6 +1799,9 @@ Bool ScenarioDrill_execute( const ScenarioAction &action )if (action.action == SCENARIO_ACTION_TALLY)return executeTally( action, player );+ if (action.action == SCENARIO_ACTION_PURCHASE)+ return executePurchase( action, player );+if (action.action == SCENARIO_ACTION_CONSTRUCT)return executeConstruct( action, player, position );