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
feat(gameengine): production repeat on the ctrl+alt build key
Olcay Seygan52523a98516b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 746d50461..d52128a4f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -793,6 +793,7 @@ A third pass went through the generals' powers, promotions and unit abilities.- One right click cancels one thing, counted the moment you press.- A build button takes a batch: Shift queues five, Ctrl twenty, both together as many as the queue will hold and the bank will pay for. Right-click with the same keys and the same number comes back out. Ten tanks used to be ten clicks. How many are still coming is written in the corner of the button, half again bigger than the price and the countdown beside it and on a plate you can actually read it against: at the size the other markings wear, the one number you check in the middle of a fight was a smudge you had to look for.- Right-click a picture on the strip and that one order is cancelled and paid back, without walking the camera over to the building first. A build button greyed out because the bank is empty or the queue is full still takes the right click, so what is already queued on it can come back out.+- A factory builds a unit on repeat. Hold Ctrl and Alt and press the unit's key, or click its button, and a green pair of arrows starts turning in the button's corner: whenever the factory has nothing queued it orders another and pays for it, waiting for the money like a click would. Do it again to stop. Several units on repeat take turns in the order you put them on, each factory keeps its own, and with several factories selected one press sets them all. Losing the building that unlocks the unit takes it off the repeat; selling or losing the factory ends it. Right-click still takes queued units back out. A button whose unit is on repeat stays clickable when the bank is empty, so the repeat can always be stopped.- Buying an upgrade for a group starts it in all of them.- The progress clock over a picture is steady at any frame rate.- A group's upgrade shows its progress, whichever building is paying for it.diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifestindex 831db2433..88d303328 100644--- a/GeneralsMD/Code/BuildFingerprint.manifest+++ b/GeneralsMD/Code/BuildFingerprint.manifest@@ -252,6 +252,7 @@ Data/Scenarios/mobclose.txtData/Scenarios/mobopen.txtData/Scenarios/mobstress.txtData/Scenarios/mobwin.txt+Data/Scenarios/netrepeat.txtData/Scenarios/netstance.txtData/Scenarios/nukefade.txtData/Scenarios/obeyorders.txt@@ -261,6 +262,7 @@ Data/Scenarios/overlordrush.txtData/Scenarios/parade.txtData/Scenarios/particles100k.txtData/Scenarios/reachshot.txt+Data/Scenarios/repeatbuild.txtData/Scenarios/rf_mass840.txtData/Scenarios/rf_night.txtData/Scenarios/rf_nightday.txtdiff --git a/GeneralsMD/Code/Data/Scenarios/netrepeat.txt b/GeneralsMD/Code/Data/Scenarios/netrepeat.txtnew file mode 100644index 000000000..1eb65681b--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/netrepeat.txt@@ -0,0 +1,22 @@+# Production repeat across a network match. A -netgame seat gets a random general, so there is a+# line for each of the twelve command centers; the eleven that slot 0 does not own are refused.+# Every copy plays the file and only the copy whose local seat is slot 0 sends the message, so the+# other copy learns of the repeat from the network alone. Each copy's log carries the dispatcher's+# REPEAT line and one REPEAT line per builder queued; the CRC covers the builders that come out.+#+# python net_check.py --each "-scenario netrepeat" --tag netrepeat+#+# repeatbuild.txt is the same on one machine, for the replay.++60 repeat 0 AmericaCommandCenter AmericaVehicleDozer on+60 repeat 0 AirF_AmericaCommandCenter AirF_AmericaVehicleDozer on+60 repeat 0 Lazr_AmericaCommandCenter Lazr_AmericaVehicleDozer on+60 repeat 0 SupW_AmericaCommandCenter SupW_AmericaVehicleDozer on+60 repeat 0 ChinaCommandCenter ChinaVehicleDozer on+60 repeat 0 Tank_ChinaCommandCenter Tank_ChinaVehicleDozer on+60 repeat 0 Infa_ChinaCommandCenter Infa_ChinaVehicleDozer on+60 repeat 0 Nuke_ChinaCommandCenter Nuke_ChinaVehicleDozer on+60 repeat 0 GLACommandCenter GLAInfantryWorker on+60 repeat 0 Demo_GLACommandCenter Demo_GLAInfantryWorker on+60 repeat 0 Slth_GLACommandCenter Slth_GLAInfantryWorker on+60 repeat 0 Chem_GLACommandCenter Chem_GLAInfantryWorker ondiff --git a/GeneralsMD/Code/Data/Scenarios/repeatbuild.txt b/GeneralsMD/Code/Data/Scenarios/repeatbuild.txtnew file mode 100644index 000000000..0c4e958bf--- /dev/null+++ b/GeneralsMD/Code/Data/Scenarios/repeatbuild.txt@@ -0,0 +1,19 @@+# Production repeat: the Ctrl+Alt build key, sent as MSG_SET_REPEAT_UNIT onto the message stream, so+# the replay records it and a network match sends it to every copy. The command center builds+# dozers on repeat from frame 60 and stops at frame 1200; each one queued writes a REPEAT line. On+# 2026-10-15 it queued four, one every 601 logic frames, and the tally read 5 alive and $6000 left;+# the replay played back to the same 0xCEBBE5D2 at frame 3000.+#+# Nothing here bypasses the replay (no spawn), so the replay this run leaves plays back to the same+# HEADLESS CRC with -replay and no -scenario. Slot 0 is the local seat, so no -observer.+#+# generals.exe -headless -quickstart -noshellmap -multiInstance -noFPSLimit+# -randommap 1 2 small -autoskirmish 2 -takeover+# -side 0 FactionAmerica -side 1 FactionGLA -seed 1 -maxframes 3000+# -scenario repeatbuild -logPrefix repeat_+#+# netrepeat.txt is the same over a network match.++60 repeat 0 AmericaCommandCenter AmericaVehicleDozer on+1200 repeat 0 AmericaCommandCenter AmericaVehicleDozer off+1450 tally 0 AmericaVehicleDozerdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.hindex 763d61bdb..271dd6ec6 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h@@ -661,6 +661,7 @@ public:MSG_CLEAR_RALLY_POINT, ///< (objectID) the building forgets its rally point (fork)MSG_SET_STANCE, ///< (Int 0 defensive, 1 aggressive) how far the selected units go after what they see (fork)MSG_VOTE_KICK, ///< (Int player index, Bool yes) a vote kick: opens one, or answers the open one (fork)+ MSG_SET_REPEAT_UNIT, ///< (Int template ID, objectID producer, Bool on) the factory builds that unit on repeat, or stops (fork)MSG_BEGIN_DEBUG_NETWORK_MESSAGES = 1900, ///< network messages that exist only in debug/internal builds. all grouped separately.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex a6ea9fd0d..87e3a983e 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -804,6 +804,8 @@ public:/// mark the UI as dirty so the context of everything is re-evaluatedvoid markUIDirty( void );+ Bool selectionRepeatsUnit( const ThingTemplate *thing ); ///< a selected factory of ours builds it on repeat+ void toggleRepeatUnit( const ThingTemplate *thing ); ///< Ctrl+Alt on a build button: repeat on or off/// a drawable has just become selectedvoid onDrawableSelected( Drawable *draw );diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.hindex dd32271e9..1d985fc11 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h@@ -438,6 +438,7 @@ typedef struct _PushButtonDataBool drawBorder; ///< We only want to draw the border if we want toColor colorBorder; ///< The color for the border around the buttonInt drawCount; ///< when > 0, a small number badge drawn in the bottom right corner+ Bool drawRepeat; ///< a spinning repeat mark in the top right corner: the unit is built on repeatvoid *userData; ///< random additional data we can setconst Image *overlayImage; ///< An overlay image (like a veterancy symbol)AsciiString altSound; ///< use an alternitive sound if one is setdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.hindex 75bacb70b..f16d8d879 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h@@ -84,6 +84,7 @@ void GadgetButtonDrawInverseClock( GameWindow *g, Int percent, Color color ); //void GadgetButtonDrawOverlayImage( GameWindow *g, const Image *image );void GadgetButtonSetBorder( GameWindow *g, Color color, Bool drawBorder = TRUE );void GadgetButtonSetCount( GameWindow *g, Int count );+void GadgetButtonSetRepeat( GameWindow *g, Bool repeat );void GadgetButtonSetData(GameWindow *g, void *data);void *GadgetButtonGetData(GameWindow *g);void GadgetButtonSetAltSound( GameWindow *g, AsciiString altSound );diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.hindex 3addc7a7b..d31881b6b 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.h@@ -144,9 +144,66 @@ public:static void parseAppendQuantityModifier( INI* ini, void *instance, void *store, const void *userData );};+//-------------------------------------------------------------------------------------------------+/** The units a factory builds on repeat (fork). The player turns one on and off with Ctrl+Alt and+ * the button's key, or a Ctrl+Alt click on it. Whenever the factory's queue is empty it queues+ * the unit whose turn it is, and the turn passes to the next in the order they were turned on.+ * Logic state, set only by MSG_SET_REPEAT_UNIT; kept apart from the module so the test binary can+ * drive it with no object behind it. */+//-------------------------------------------------------------------------------------------------+struct ProductionRepeat+{+ std::vector<const ThingTemplate *> m_units; ///< in the order they were turned on+ UnsignedInt m_next; ///< index into m_units of the one whose turn it is++ ProductionRepeat() : m_next( 0 ) {}++ Bool has( const ThingTemplate *unit ) const+ {+ for( size_t i = 0; i < m_units.size(); ++i )+ if( m_units[ i ] == unit )+ return TRUE;+ return FALSE;+ }++ /// on appends it at the end of the turn order, off takes it out; either is a no-op when it already is+ void set( const ThingTemplate *unit, Bool on )+ {+ for( size_t i = 0; i < m_units.size(); ++i )+ {+ if( m_units[ i ] != unit )+ continue;+ if( on )+ return;+ m_units.erase( m_units.begin() + i );+ // the turn stays with the unit it was on, or wraps to the first when that was the last+ if( i < m_next )+ --m_next;+ if( m_next >= m_units.size() )+ m_next = 0;+ return;+ }+ if( on )+ m_units.push_back( unit );+ }++ const ThingTemplate *turn() const { return m_units.empty() ? NULL : m_units[ m_next ]; }+ void advance() { if( !m_units.empty() ) m_next = ( m_next + 1 ) % m_units.size(); }+ void clear() { m_units.clear(); m_next = 0; }+};+//-------------------------------------------------------------------------------------------------enum CanMakeType : Int;+enum ProductionRepeatAction : Int+{+ REPEAT_QUEUE, ///< queue it now+ REPEAT_WAIT, ///< not now (money, queue, cap, power): try again next frame+ REPEAT_DROP ///< the factory can no longer make it: off the repeat+};++ProductionRepeatAction Production_repeatAction( CanMakeType canMake );+/** A building still going up or being sold researches nothing. Its own command bar never offers an* upgrade then, but a multi-selection that mixes it with finished ones did, and the logic took it. */inline Bool canResearchWithStatus( const ObjectStatusMaskType &status )@@ -178,6 +235,9 @@ public:virtual void cancelAndRefundAllProduction( void ) = 0;+ virtual void setRepeatUnit( const ThingTemplate *unitType, Bool on ) = 0; ///< see ProductionRepeat+ virtual Bool isRepeatUnit( const ThingTemplate *unitType ) const = 0;+virtual UnsignedInt getProductionCount( void ) const = 0;virtual UnsignedInt getMaxQueueEntries( void ) const = 0;@@ -236,6 +296,9 @@ public:virtual void cancelAndRefundAllProduction( void ); ///< cancel and refund anything in the production queue+ virtual void setRepeatUnit( const ThingTemplate *unitType, Bool on ) { m_repeat.set( unitType, on ); }+ virtual Bool isRepeatUnit( const ThingTemplate *unitType ) const { return m_repeat.has( unitType ); }+virtual UnsignedInt getProductionCount( void ) const { return m_productionCount; } ///< return # of things in the production queuevirtual UnsignedInt getMaxQueueEntries( void ) const { return getProductionUpdateModuleData()->m_maxQueueEntries; } ///< how deep the queue may go (INI MaxQueueEntries)@@ -255,8 +318,12 @@ public:// DieModuleInterfacevirtual void onDie( const DamageInfo *damageInfo );+ virtual void onCapture( Player *oldOwner, Player *newOwner );+protected:+ void queueRepeatUnit( void ); ///< an empty queue takes the repeated unit whose turn it is+void addToProductionQueue( ProductionEntry *production ); ///< add to *END* of production queue listvoid removeFromProductionQueue( ProductionEntry *production ); ///< remove production from the queue list@@ -282,6 +349,7 @@ protected:ModelConditionFlags m_clearFlags; ///< flags to clear from modelModelConditionFlags m_setFlags; ///< flags to set in modelBool m_flagsDirty; ///< clearFlags/setFlags needs to be set into the model+ ProductionRepeat m_repeat; ///< the units built on repeat};diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.hindex 397d522ef..cf370ce4d 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ScenarioDrill.h@@ -90,7 +90,8 @@ enum ScenarioActionTypeSCENARIO_ACTION_FORCEGROUND, ///< forceground <slot> <selector> <position>; the attack key's click on the ground, as MSG_DO_FORCE_ATTACK_GROUNDSCENARIO_ACTION_REAIM, ///< reaim <slot> <selector> <position>; a right click that moves a running power's aim (the Spectre Gunship's), as MSG_DO_SPECIAL_POWER_OVERRIDE_DESTINATIONSCENARIO_ACTION_RESPOND, ///< respond <slot> <selector> <position>; from now, how long each unit takes to point its gun at the position, fire with it pointed there, and get closer to it- SCENARIO_ACTION_GUARD ///< guard <slot> <selector> <targetSlot> <targetSelector>; a guard order on one object, as a script gives it+ SCENARIO_ACTION_GUARD, ///< guard <slot> <selector> <targetSlot> <targetSelector>; a guard order on one object, as a script gives it+ SCENARIO_ACTION_REPEAT ///< repeat <slot> <building> <template> on|off; the Ctrl+Alt build key, as MSG_SET_REPEAT_UNIT onto the message stream};/// ScenarioAction::atStart when the position is plain numbersdiff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cppindex f4cdf4aa2..78d2204dc 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp@@ -666,6 +666,7 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)CHECK_IF(MSG_CLEAR_RALLY_POINT)CHECK_IF(MSG_SET_STANCE)CHECK_IF(MSG_VOTE_KICK)+ CHECK_IF(MSG_SET_REPEAT_UNIT)CHECK_IF(MSG_DO_GUARD_OBJECT)CHECK_IF(MSG_DO_STOP)CHECK_IF(MSG_DO_SCATTER)diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cppindex 0634dcadd..8d2542ee1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp@@ -894,6 +894,11 @@ void ControlBar::updateContextCommand( void )GadgetButtonClearClock( win );win->winClearStatus( WIN_STATUS_CANCEL_WHEN_DISABLED );+ // the spinning repeat mark: some selected factory builds this unit on repeat+ const Bool repeating = command->getCommandType() == GUI_COMMAND_UNIT_BUILD &&+ selectionRepeatsUnit( command->getThingTemplate() );+ GadgetButtonSetRepeat( win, repeating );+//// a unit build button wears a radial fill over the cameo while its unit is the one being// built, and right-click cancels the last one queued@@ -1003,6 +1008,11 @@ void ControlBar::updateContextCommand( void )win->winSetStatus( WIN_STATUS_ALWAYS_COLOR );}+ // the same for a unit on repeat the bank cannot pay for right now: Ctrl+Alt click has to+ // reach the button to stop it, and a plain click only says there is not enough money+ if( repeating && availability == COMMAND_CANT_AFFORD )+ win->winEnable( TRUE );+//Determine by the production type of this button, whether or not the created object//will have a veterancy rankif( command->getCommandType() != GUI_COMMAND_EXIT_CONTAINER )diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cppindex f61064fd2..4e3eefa25 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp@@ -524,6 +524,14 @@ CBCommandStatus ControlBar::processCommandUI( GameWindow *control,DEBUG_ASSERTCRASH( whatToBuild, ("Undefined BUILD command for object '%s'\n",commandButton->getThingTemplate()->getName().str()) );+ // Ctrl+Alt, on the button's key or a click, puts the unit on repeat or takes it off.+ // The right button already takes units back out of the queue, so it stays that+ if( TheKeyboard->isCtrl() && TheKeyboard->isAlt() )+ {+ toggleRepeatUnit( whatToBuild );+ break;+ }+// shift, control or both queue a whole batch with one clickInt wanted = getBuildBatchCount();@@ -1163,3 +1171,48 @@ CBCommandStatus ControlBar::processCommandUI( GameWindow *control,} // end processCommandUI+//-------------------------------------------------------------------------------------------------+/** The button's repeat mark: some selected factory of ours builds 'thing' on repeat. */+//-------------------------------------------------------------------------------------------------+Bool ControlBar::selectionRepeatsUnit( const ThingTemplate *thing )+{+ const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();+ for( DrawableListCIt it = selected->begin(); it != selected->end(); ++it )+ {+ Object *candidate = (*it)->getObject();+ if( candidate == NULL || candidate->getControllingPlayer() != ThePlayerList->getLocalPlayer() )+ continue;+ ProductionUpdateInterface *pu = candidate->getProductionUpdateInterface();+ if( pu && pu->isRepeatUnit( thing ) )+ return TRUE;+ }+ return FALSE;+}++//-------------------------------------------------------------------------------------------------+/** Ctrl+Alt on a build button: every selected factory of ours that can make the unit builds it on+ * repeat, or, when any of them already does, every one of them stops. One message per factory+ * with the state named outright, so a mixed selection comes out all on or all off. */+//-------------------------------------------------------------------------------------------------+void ControlBar::toggleRepeatUnit( const ThingTemplate *thing )+{+ const Bool on = !selectionRepeatsUnit( thing );+ const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();+ for( DrawableListCIt it = selected->begin(); it != selected->end(); ++it )+ {+ Object *candidate = (*it)->getObject();+ if( candidate == NULL || candidate->getControllingPlayer() != ThePlayerList->getLocalPlayer() )+ continue;+ if( candidate->getProductionUpdateInterface() == NULL )+ continue;+ if( on && !TheBuildAssistant->isPossibleToMakeUnit( candidate, thing ) )+ continue;++ GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_SET_REPEAT_UNIT );+ msg->appendIntegerArgument( thing->getTemplateID() );+ msg->appendObjectIDArgument( candidate->getID() );+ msg->appendBooleanArgument( on );+ }+ markUIDirty();+}+diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cppindex e1132f2c4..09b4cc420 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp@@ -605,6 +605,7 @@ PushButtonData * getNewPushButtonData( void )p->drawBorder = FALSE;p->drawClock = NO_CLOCK;p->drawCount = 0;+ p->drawRepeat = FALSE;p->overlayImage = NULL;return p;}@@ -626,6 +627,20 @@ void GadgetButtonSetCount( GameWindow *g, Int count )g->winSetUserData(pData);}+// GadgetButtonSetRepeat ======================================================+/** Show or take off the spinning repeat mark in the button's top right corner */+//=============================================================================+void GadgetButtonSetRepeat( GameWindow *g, Bool repeat )+{+ PushButtonData *pData = (PushButtonData *)g->winGetUserData();+ if(!pData)+ {+ pData = getNewPushButtonData();+ }+ pData->drawRepeat = repeat;+ g->winSetUserData(pData);+}+// GadgetButtonSetBorder ======================================================/** Set to draw the special borders in the game *///=============================================================================diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cppindex 7c6a08981..79eef7fb0 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp@@ -105,12 +105,14 @@ GameMessageDisposition HotKeyTranslator::translateGameMessage(const GameMessage{newModState |= ALT;}+ // Ctrl+Alt and a build button's key puts its unit on repeat or takes it off+ const Bool repeatChord = newModState == ( CTRL | ALT );// shift is allowed through: a shift-click on a build button queues a batch of units, and// the label hotkey is meant to be that click's equal. Ctrl and alt still block the hotkey.- if( ( newModState & ~SHIFT ) != 0 )+ if( !repeatChord && ( newModState & ~SHIFT ) != 0 )return disp;// Ctrl+F let go of Ctrl first ends on a bare F release; it is still Ctrl+F- if( keyState & KEY_STATE_PRESSED_WITH_CTRL_ALT )+ if( !repeatChord && ( keyState & KEY_STATE_PRESSED_WITH_CTRL_ALT ) )return disp;const UnsignedByte scanCode = (UnsignedByte)msg->getArgument(0)->integer;WideChar typed = TheKeyboard->getPrintableKey(scanCode, 0);@@ -127,6 +129,24 @@ GameMessageDisposition HotKeyTranslator::translateGameMessage(const GameMessagetyped = (WideChar)out[0];}#endif+ if( repeatChord )+ {+ // straight to the bar rather than as a click: a repeated unit the bank cannot pay for+ // right now has a greyed button, and that is when the repeat most wants stopping+ Bool pressable = FALSE;+ GameWindow *win = TheHotKeyManager ? TheHotKeyManager->findHotKey( HotKeyManager::nameOf( typed ), &pressable ) : NULL;+ const CommandButton *command = win ? (const CommandButton *)GadgetButtonGetData( win ) : NULL;+ if( command && command->getCommandType() == GUI_COMMAND_UNIT_BUILD &&+ !BitTest( win->winGetStatus(), WIN_STATUS_HIDDEN ) )+ {+ TheControlBar->toggleRepeatUnit( command->getThingTemplate() );+ AudioEventRTS buttonClick( "GUIClick" );+ if( TheAudio )+ TheAudio->addAudioEvent( &buttonClick );+ disp = DESTROY_MESSAGE;+ }+ return disp;+ }if(TheHotKeyManager && TheHotKeyManager->executeHotKey(HotKeyManager::nameOf(typed)))disp = DESTROY_MESSAGE;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cppindex a8528b24c..ad103074f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp@@ -765,9 +765,12 @@ UpdateSleepTime ProductionUpdate::update( void )} // end if- // if nothing in the queue get outta here- if( production == NULL )+ // if nothing in the queue, a unit on repeat takes the empty queue; it starts next frame+ if( production == NULL )+ {+ queueRepeatUnit();return UPDATE_SLEEP_NONE;+ }//// if we've become OBJECT_STATUS_SOLD, halt all production ... leave things in the@@ -1265,12 +1268,71 @@ void ProductionUpdate::onDie( const DamageInfo *damageInfo )cancelAndRefundAllProduction();}+// ------------------------------------------------------------------------------------------------+/** A captured factory does not go on building for its old owner's orders, nor for its new owner's+ * money on orders he never gave. */+// ------------------------------------------------------------------------------------------------+void ProductionUpdate::onCapture( Player *oldOwner, Player *newOwner )+{+ if( oldOwner != newOwner )+ m_repeat.clear();+}++// ------------------------------------------------------------------------------------------------+/** What a factory on repeat does with the unit whose turn it is, from what canMakeUnit says of it.+ * Money, a full queue or parking, the unit cap and a factory out of action (unpowered, disabled,+ * still going up) all pass, so it waits for them like a player at the button would. A unit the+ * factory can no longer make at all (its prerequisite gone, a script taking it away) leaves the+ * repeat. */+// ------------------------------------------------------------------------------------------------+ProductionRepeatAction Production_repeatAction( CanMakeType canMake )+{+ if( canMake == CANMAKE_OK )+ return REPEAT_QUEUE;+ if( canMake == CANMAKE_NO_PREREQ )+ return REPEAT_DROP;+ return REPEAT_WAIT;+}++// ------------------------------------------------------------------------------------------------+// ------------------------------------------------------------------------------------------------+void ProductionUpdate::queueRepeatUnit( void )+{+ const ThingTemplate *unit = m_repeat.turn();+ if( unit == NULL )+ return;++ switch( Production_repeatAction( TheBuildAssistant->canMakeUnit( getObject(), unit ) ) )+ {+ case REPEAT_QUEUE:+ if( queueCreateUnit( unit, requestUniqueUnitID() ) )+ {+ DEBUG_LOG(( "REPEAT: frame %d %s (%d) queues %s\n", TheGameLogic->getFrame(),+ getObject()->getTemplate()->getName().str(), getObject()->getID(), unit->getName().str() ));+ m_repeat.advance();+ }+ break;++ case REPEAT_DROP:+ DEBUG_LOG(( "REPEAT: frame %d %s (%d) drops %s, no longer buildable\n", TheGameLogic->getFrame(),+ getObject()->getTemplate()->getName().str(), getObject()->getID(), unit->getName().str() ));+ m_repeat.set( unit, FALSE );+ break;++ case REPEAT_WAIT:+ break;+ }+}+// ------------------------------------------------------------------------------------------------/** Cancel each of the production items in the queue. By going through the actual cancel* methods, the cost of each of those items will be refunded to the player */// ------------------------------------------------------------------------------------------------void ProductionUpdate::cancelAndRefundAllProduction( void ){+ // death, sale and defection all come through here, and none of them leaves a factory to repeat+ m_repeat.clear();+//// The old loop ran a fixed 100 passes whether or not the queue was empty, because// cancelUpgrade could return without removing its entry (fixed above) and the head would@@ -1374,7 +1436,8 @@ void ProductionUpdate::xfer( Xfer *xfer )// version// 2: each entry carries what was paid for it// 3: each entry carries the build time its frame count was measured against- XferVersion currentVersion = 3;+ // 4: the units on repeat and whose turn it is+ XferVersion currentVersion = 4;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -1557,6 +1620,38 @@ void ProductionUpdate::xfer( Xfer *xfer )// flags dirtyxfer->xferBool( &m_flagsDirty );+ // units on repeat, by template name, and whose turn it is+ if( version >= 4 )+ {+ UnsignedShort repeatCount = (UnsignedShort)m_repeat.m_units.size();+ xfer->xferUnsignedShort( &repeatCount );+ AsciiString name;+ if( xfer->getXferMode() == XFER_SAVE )+ {+ for( UnsignedShort i = 0; i < repeatCount; ++i )+ {+ name = m_repeat.m_units[ i ]->getName();+ xfer->xferAsciiString( &name );+ }+ }+ else+ {+ m_repeat.m_units.clear();+ for( UnsignedShort i = 0; i < repeatCount; ++i )+ {+ xfer->xferAsciiString( &name );+ const ThingTemplate *unit = TheThingFactory->findTemplate( name );+ if( unit == NULL )+ {+ DEBUG_CRASH(( "ProductionUpdate::xfer - Cannot find repeat template '%s'\n", name.str() ));+ throw SC_INVALID_DATA;+ }+ m_repeat.m_units.push_back( unit );+ }+ }+ xfer->xferUnsignedInt( &m_repeat.m_next );+ }+} // end xfer// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cppindex 0209d4336..e897b1347 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp@@ -1919,6 +1919,37 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, AIGroup *orderedGroup} // end GameMessage::MSG_CANCEL_UNIT_CREATE+ //-------------------------------------------------------------------------------------------------+ // Production repeat (fork): (Int template ID, objectID producer, Bool on). The arguments came+ // over the network, so their shape is checked, the producer must be the sender's, and a unit+ // goes on repeat only where the factory could build it. Turning one off is always allowed.+ case GameMessage::MSG_SET_REPEAT_UNIT:+ {+ if( msg->getArgumentCount() < 3 || msg->getArgumentDataType( 0 ) != ARGUMENTDATATYPE_INTEGER+ || msg->getArgumentDataType( 1 ) != ARGUMENTDATATYPE_OBJECTID+ || msg->getArgumentDataType( 2 ) != ARGUMENTDATATYPE_BOOLEAN )+ break;++ const ThingTemplate *unit = TheThingFactory->findByTemplateID( msg->getArgument( 0 )->integer );+ Object *producer = TheGameLogic->findObjectByID( msg->getArgument( 1 )->objectID );+ const Bool on = msg->getArgument( 2 )->boolean;+ if( unit == NULL || producer == NULL || producer->getControllingPlayer() != thisPlayer )+ break;++ ProductionUpdateInterface *pu = producer->getProductionUpdateInterface();+ if( pu == NULL )+ break;+ if( on && !TheBuildAssistant->isPossibleToMakeUnit( producer, unit ) )+ break;++ pu->setRepeatUnit( unit, on );+ DEBUG_LOG(( "REPEAT: frame %d player %d %s %s on %s (%d)\n", TheGameLogic->getFrame(), msg->getPlayerIndex(),+ on ? "repeats" : "stops repeating", unit->getName().str(),+ producer->getTemplate()->getName().str(), producer->getID() ));+ break;++ } // end GameMessage::MSG_SET_REPEAT_UNIT+//---------------------------------------------------------------------------------------------case GameMessage::MSG_DOZER_CONSTRUCT:case GameMessage::MSG_DOZER_CONSTRUCT_LINE:diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cppindex d2c7811ef..bf1c8a793 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/ScenarioDrill.cpp@@ -239,6 +239,8 @@ static Bool parseActionType( const AsciiString &token, ScenarioActionType *actio*action = SCENARIO_ACTION_RESPOND;else if (token == "guard")*action = SCENARIO_ACTION_GUARD;+ else if (token == "repeat")+ *action = SCENARIO_ACTION_REPEAT;elsereturn FALSE;@@ -336,6 +338,7 @@ static Int tokensNeededFor( ScenarioActionType action )case SCENARIO_ACTION_DOCK: return SCENARIO_TOKENS_ATTACK;case SCENARIO_ACTION_GUARD: return SCENARIO_TOKENS_ATTACK;case SCENARIO_ACTION_PRODUCE: return SCENARIO_TOKENS_ATTACK;+ case SCENARIO_ACTION_REPEAT: return SCENARIO_TOKENS_ATTACK;case SCENARIO_ACTION_STOP: return SCENARIO_TOKENS_STOP;case SCENARIO_ACTION_TALLY: return SCENARIO_TOKENS_STOP;case SCENARIO_ACTION_ARRIVE: return SCENARIO_TOKENS_ARRIVE;@@ -470,6 +473,13 @@ ScenarioParseResult ScenarioDrill_parseLine( const char *line, ScenarioAction *abreak;}+ case SCENARIO_ACTION_REPEAT:+ action->targetSelector = tokens[ 4 ]; // the unit+ action->name = tokens[ 5 ];+ if (action->name != "on" && action->name != "off")+ return SCENARIO_PARSE_BAD_ACTION;+ break;+case SCENARIO_ACTION_STOP:case SCENARIO_ACTION_TALLY:break;@@ -1796,6 +1806,7 @@ static Bool executeOrder( const ScenarioAction &action, Player *player, const Cocase SCENARIO_ACTION_PARTICLES:case SCENARIO_ACTION_POWER:case SCENARIO_ACTION_PRODUCE:+ case SCENARIO_ACTION_REPEAT:case SCENARIO_ACTION_TALLY:case SCENARIO_ACTION_RESPOND:ordered = FALSE; // handled before the group is built@@ -1830,6 +1841,29 @@ static Bool executeConstruct( const ScenarioAction &action, Player *player, consreturn TRUE;}+/** The Ctrl+Alt build key on a factory: one MSG_SET_REPEAT_UNIT onto the message stream, recorded and+ sent to every machine like construct, so only the local player can press it. */+static Bool executeRepeat( const ScenarioAction &action, Player *player )+{+ Object *building = findFirstMatching( player, action.selector );+ const ThingTemplate *made = TheThingFactory->findTemplate( action.targetSelector );+ if (player != ThePlayerList->getLocalPlayer() || building == NULL || made == NULL)+ {+ DEBUG_LOG(("SCENARIO: frame %d repeat: slot %d is not the local player, has no '%s', or '%s' is no template\n",+ action.frame, action.slot, action.selector.str(), action.targetSelector.str()));+ return FALSE;+ }++ GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_SET_REPEAT_UNIT );+ msg->appendIntegerArgument( made->getTemplateID() );+ msg->appendObjectIDArgument( building->getID() );+ msg->appendBooleanArgument( action.name == "on" );++ DEBUG_LOG(("SCENARIO: frame %d repeat slot %d '%s' %d '%s' %s\n", action.frame, action.slot,+ action.selector.str(), building->getID(), action.targetSelector.str(), action.name.str()));+ return TRUE;+}+Bool ScenarioDrill_execute( const ScenarioAction &action ){Player *player = findPlayerForSlot( action.slot );@@ -1861,6 +1895,9 @@ Bool ScenarioDrill_execute( const ScenarioAction &action )if (action.action == SCENARIO_ACTION_PRODUCE)return executeProduce( action, player );+ if (action.action == SCENARIO_ACTION_REPEAT)+ return executeRepeat( action, player );+if (action.action == SCENARIO_ACTION_TALLY)return executeTally( action, player );diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cppindex b6d93e956..2eb9f253f 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp@@ -60,6 +60,7 @@#include "GameClient/DisplayStringManager.h"#include "GameClient/InGameUI.h" // HudReadout_draw, the plate every corner marking stands on#include "Common/GlobalData.h"+#include "Lib/Clock.h"#include "W3DDevice/GameClient/W3DGameWindow.h"#include "W3DDevice/GameClient/W3DDisplay.h"#include "W3DDevice/GameClient/W3DGadget.h"@@ -325,6 +326,60 @@ static void drawClassicKeyBadge( GameWindow *window, const UnicodeString &text,} // end drawClassicKeyBadge+// drawRepeatMark =============================================================+/** The unit on this button is built on repeat: two arrows chasing each other round a ring, on the+ * key letter's square plate in the top right corner, turning once every REPEAT_TURN_MS. Drawn in+ * lines rather than from art so it stays sharp at every HUD size, and turned by the wall clock,+ * which only the picture reads. */+//=============================================================================+static const UnsignedInt REPEAT_TURN_MS = 1200;++static void drawRepeatMark( GameWindow *window )+{+ ICoord2D origin, size;+ window->winGetScreenPosition( &origin.x, &origin.y );+ window->winGetSize( &size.x, &size.y );++ const Int side = max( 11, REAL_TO_INT( min( size.x, size.y ) * 0.4f ) );+ const Int left = origin.x + size.x - 1 - side;+ const Int top = origin.y + 1;+ TheDisplay->drawFillRect( left, top, side, side, GameMakeColor( 2, 4, 5, 230 ) );+ TheDisplay->drawOpenRect( left, top, side, side, 1, GameMakeColor( 90, 90, 90, 255 ) );++ const Color green = GameMakeColor( 110, 235, 90, 255 );+ const Real cx = left + side * 0.5f;+ const Real cy = top + side * 0.5f;+ const Real radius = side * 0.3f;+ const Real width = max( 1.5f, side * 0.1f );+ const Real head = side * 0.16f;+ const Real spin = ( Clock_Milliseconds() % REPEAT_TURN_MS ) * ( 2.0f * PI / REPEAT_TURN_MS );++ // two arcs of 130 degrees, half a turn apart, each with its head on the leading end+ const Int SEGMENTS = 6;+ const Real ARC = 130.0f * PI / 180.0f;+ for( Int arrow = 0; arrow < 2; ++arrow )+ {+ const Real start = spin + arrow * PI;+ for( Int s = 0; s < SEGMENTS; ++s )+ {+ const Real a0 = start + ARC * s / SEGMENTS;+ const Real a1 = start + ARC * ( s + 1 ) / SEGMENTS;+ TheDisplay->drawLine( REAL_TO_INT( cx + radius * cosf( a0 ) ), REAL_TO_INT( cy + radius * sinf( a0 ) ),+ REAL_TO_INT( cx + radius * cosf( a1 ) ), REAL_TO_INT( cy + radius * sinf( a1 ) ), width, green );+ }++ // the head: a point a little ahead along the ring, its barbs either side of the arc's end+ const Real end = start + ARC;+ const Real ex = cx + radius * cosf( end ), ey = cy + radius * sinf( end );+ const Real tx = -sinf( end ), ty = cosf( end ); // the way the ring turns+ const Real nx = cosf( end ), ny = sinf( end ); // out from the centre+ const Int px = REAL_TO_INT( ex + tx * head ), py = REAL_TO_INT( ey + ty * head );+ TheDisplay->drawLine( px, py, REAL_TO_INT( ex + nx * head ), REAL_TO_INT( ey + ny * head ), width, green );+ TheDisplay->drawLine( px, py, REAL_TO_INT( ex - nx * head ), REAL_TO_INT( ey - ny * head ), width, green );+ }++} // end drawRepeatMark+///////////////////////////////////////////////////////////////////////////////// PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////@@ -457,6 +512,9 @@ void W3DGadgetPushButtonDraw( GameWindow *window, WinInstanceData *instData )if( pData->drawCount > 0 )drawCountBadge( window, pData->drawCount );++ if( pData->drawRepeat )+ drawRepeatMark( window );}// the text goes on last: the cooldown clock sweeps across the whole button and used to@@ -633,6 +691,9 @@ void W3DGadgetPushButtonImageDrawOne( GameWindow *window,if( pData->drawCount > 0 )drawCountBadge( window, pData->drawCount );++ if( pData->drawRepeat )+ drawRepeatMark( window );}//Now render overlays that pertain to the correct state.@@ -896,6 +957,9 @@ void W3DGadgetPushButtonImageDrawThree(GameWindow *window, WinInstanceData *instif( pData->drawCount > 0 )drawCountBadge( window, pData->drawCount );++ if( pData->drawRepeat )+ drawRepeatMark( window );}// the text goes on last: the cooldown clock sweeps across the whole button and used todiff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 843542754..7535648b4 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -12927,6 +12927,65 @@ TEST(a_door_stays_open_while_another_unit_is_still_coming)CHECK( !Production_shouldCloseDoorNow( 31, 30, true, true ) );}+/* ProductionUpdate.h: production repeat. A factory keeps a list of units on repeat in the order+ they were turned on, and every time its queue runs empty it queues the one whose turn it is and+ passes the turn on. Turning one off must leave the turn with the unit it was on. */+TEST(production_repeat_turns_round_the_units_in_the_order_they_were_turned_on)+{+ static const char a = 0, b = 0, c = 0;+ const ThingTemplate *tank = (const ThingTemplate *)&a;+ const ThingTemplate *apc = (const ThingTemplate *)&b;+ const ThingTemplate *jeep = (const ThingTemplate *)&c;++ ProductionRepeat repeat;+ CHECK( repeat.turn() == NULL );+ repeat.advance(); // nothing on repeat: no turn to pass, and no division by zero+ CHECK( repeat.turn() == NULL );++ repeat.set( tank, TRUE );+ repeat.set( apc, TRUE );+ repeat.set( tank, TRUE ); // already on: not a second entry+ CHECK_EQ( 2, (Int)repeat.m_units.size() );+ CHECK( repeat.has( tank ) && repeat.has( apc ) && !repeat.has( jeep ) );++ CHECK( repeat.turn() == tank );+ repeat.advance();+ CHECK( repeat.turn() == apc );+ repeat.advance();+ CHECK( repeat.turn() == tank );++ /* the turn is on the third of three; taking the first off keeps it on the third */+ repeat.set( jeep, TRUE );+ repeat.advance();+ repeat.advance();+ CHECK( repeat.turn() == jeep );+ repeat.set( tank, FALSE );+ CHECK( repeat.turn() == jeep );++ /* taking off the one whose turn it is, when it is the last, wraps to the first */+ repeat.set( jeep, FALSE );+ CHECK( repeat.turn() == apc );+ repeat.set( jeep, FALSE ); // already off: nothing happens+ CHECK_EQ( 1, (Int)repeat.m_units.size() );++ repeat.clear();+ CHECK( repeat.turn() == NULL );+ CHECK( !repeat.has( apc ) );+}++/* What a factory on repeat does when canMakeUnit answers: money, a full queue or parking, the unit+ cap and a factory out of action wait, a unit the factory can no longer make leaves the repeat. */+TEST(production_repeat_waits_for_money_and_drops_a_unit_it_can_no_longer_make)+{+ CHECK_EQ( (Int)REPEAT_QUEUE, (Int)Production_repeatAction( CANMAKE_OK ) );+ CHECK_EQ( (Int)REPEAT_WAIT, (Int)Production_repeatAction( CANMAKE_NO_MONEY ) );+ CHECK_EQ( (Int)REPEAT_WAIT, (Int)Production_repeatAction( CANMAKE_QUEUE_FULL ) );+ CHECK_EQ( (Int)REPEAT_WAIT, (Int)Production_repeatAction( CANMAKE_PARKING_PLACES_FULL ) );+ CHECK_EQ( (Int)REPEAT_WAIT, (Int)Production_repeatAction( CANMAKE_MAXED_OUT_FOR_PLAYER ) );+ CHECK_EQ( (Int)REPEAT_WAIT, (Int)Production_repeatAction( CANMAKE_FACTORY_IS_DISABLED ) );+ CHECK_EQ( (Int)REPEAT_DROP, (Int)Production_repeatAction( CANMAKE_NO_PREREQ ) );+}+TEST(borderless_asks_for_a_windowed_device_the_size_of_the_desktop){/* -borderless is borderless fullscreen. Half of it is the window itself, which WinMain creates