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(gameclient): charge bar for superweapons and payouts, batch queue cancel

Olcay Seygan56cb5e5279e0
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index 182b227d9..3d876dcc9 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -407,6 +407,9 @@ private:
/** Command sets are collections of configurable command buttons. They are used in the
* command context sensitive window in the battle user interface */
//-------------------------------------------------------------------------------------------------
+// how many units a shift-click on a build button queues at once, and a shift-right-click cancels
+enum { SHIFT_BUILD_QUEUE_COUNT = 5 };
+
enum { MAX_COMMANDS_PER_SET = 18 }; // user interface max is 14 (but internally it's 18 for script only buttons!)
enum { MAX_RIGHT_HUD_UPGRADE_CAMEOS = 5};
enum { MAX_MULTI_SELECT_GROUPS = 36 }; ///< unit types a multi-selection tells apart (6x6 grid, Tab focus)
@@ -872,7 +875,7 @@ protected:
void setMultiSelectFocus( Int index );
void updateMultiSelectStrip( void );
void layoutMultiSelectTiles( Int count ); ///< make sure count cells exist, laid out n x n over the right HUD
- void cancelLastQueuedUnit( const ThingTemplate *thing ); ///< right-click on a build button
+ Bool cancelLastQueuedUnit( const ThingTemplate *thing ); ///< returns FALSE when there was nothing left to cancel ///< right-click on a build button
void populateStructureInventory( Object *building );
void populateBeacon( Object *beacon );
void populateUnderConstruction( Object *objectUnderConstruction );
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
index 08847fe5c..444f1ad29 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
@@ -702,8 +702,6 @@ private:
ModelConditionFlags m_conditionState; ///< The Drawables current behavior state
Real m_lastConstructDisplayed; ///< last construct percent used to make the string
DisplayString* m_constructDisplayString; ///< string to display construction % complete
- Int m_lastChargeDisplayed; ///< last countdown second drawn, so the string is not rebuilt every frame
- DisplayString* m_chargeDisplayString; ///< seconds left on a special power or an OCL payout
DisplayString* m_captionDisplayString; ///< string to display caption
DisplayString* m_groupNumber; ///< string to display the group number of this drawable
@@ -744,7 +742,6 @@ public:
private:
// "icon" drawing methods **************
void drawConstructPercent( const IRegion2D *healthBarRegion ); ///< display % construction complete
- void drawChargeCountdown( const IRegion2D *healthBarRegion ); ///< seconds left on a special power or an OCL payout
void drawCaption( const IRegion2D *healthBarRegion ); ///< draw caption
void drawAmmo( const IRegion2D *healthBarRegion ); ///< draw icons
void drawContained( const IRegion2D *healthBarRegion ); ///< draw icons
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index bc9d2a49b..e5896e64c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -54,6 +54,7 @@
#include "GameLogic/Object.h"
#include "GameLogic/Module/OCLUpdate.h"
#include "GameLogic/Module/SpecialPowerModule.h"
+#include "Common/SpecialPower.h"
// countdown text over a building
#include "GameLogic/Locomotor.h"
#include "GameLogic/Module/AIUpdate.h"
@@ -383,8 +384,6 @@ Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBit
m_expirationDate = 0; // 0 == never expires
m_lastConstructDisplayed = -1.0f;
- m_lastChargeDisplayed = -1;
- m_chargeDisplayString = NULL;
//Added By Sadullah Nader
//Fix for the building percent
@@ -545,10 +544,6 @@ Drawable::~Drawable()
TheDisplayStringManager->freeDisplayString( m_constructDisplayString );
m_constructDisplayString = NULL;
- if( m_chargeDisplayString )
- TheDisplayStringManager->freeDisplayString( m_chargeDisplayString );
- m_chargeDisplayString = NULL;
-
if ( m_captionDisplayString )
TheDisplayStringManager->freeDisplayString( m_captionDisplayString );
m_captionDisplayString = NULL;
@@ -2789,7 +2784,6 @@ void Drawable::drawIconUI( void )
drawCaption( healthBarRegion );
drawConstructPercent( healthBarRegion );
- drawChargeCountdown( healthBarRegion );
//All Icons Below only draw on ALIVE things, so bail here -------------------------
if( obj->isEffectivelyDead() || obj->isKindOf( KINDOF_IGNORED_IN_GUI )) // object explicitly wants nothing to do with these icons, so...
@@ -3773,91 +3767,6 @@ void Drawable::drawConstructPercent( const IRegion2D *healthBarRegion )
} // end drawConstructPercent
-//-------------------------------------------------------------------------------------------------
-/** Seconds left until this building's next payout, or until its special power comes up, written
- * over the building itself. The control bar counts these down too, but only for whatever is
- * selected, and the superweapon list in the corner never says which building on the map it
- * belongs to. */
-//-------------------------------------------------------------------------------------------------
-void Drawable::drawChargeCountdown( const IRegion2D *healthBarRegion )
-{
- Object *obj = getObject();
-
- Int secondsLeft = -1;
-
- if( obj != NULL &&
- obj->isLocallyControlled() &&
- !obj->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) &&
- !obj->getStatusBits().test( OBJECT_STATUS_SOLD ) )
- {
- const UnsignedInt now = TheGameLogic->getFrame();
-
- // a charging special power - the superweapons, and the powers a building holds
- for( BehaviorModule** m = obj->getBehaviorModules(); *m; ++m )
- {
- SpecialPowerModuleInterface* sp = (*m)->getSpecialPower();
- if( sp == NULL || sp->isReady() )
- continue;
-
- UnsignedInt ready = sp->getReadyFrame();
- if( ready > now )
- {
- Int secs = (ready - now) / LOGICFRAMES_PER_SECOND;
- if( secondsLeft < 0 || secs < secondsLeft )
- secondsLeft = secs;
- }
- }
-
- // ...and a timed payout, which is what the supply drop zone runs on
- if( secondsLeft < 0 )
- {
- static const NameKeyType key_OCLUpdate = NAMEKEY( "OCLUpdate" );
- OCLUpdate *ocl = (OCLUpdate*)obj->findUpdateModule( key_OCLUpdate );
- if( ocl != NULL )
- secondsLeft = ocl->getRemainingFrames() / LOGICFRAMES_PER_SECOND;
- }
- }
-
- if( secondsLeft < 0 )
- {
- if( m_chargeDisplayString )
- {
- TheDisplayStringManager->freeDisplayString( m_chargeDisplayString );
- m_chargeDisplayString = NULL;
- m_lastChargeDisplayed = -1;
- }
- return;
- }
-
- if( m_chargeDisplayString == NULL )
- {
- m_chargeDisplayString = TheDisplayStringManager->newDisplayString();
- m_chargeDisplayString->setFont(TheFontLibrary->getFont(TheInGameUI->getDrawableCaptionFontName(),
- TheGlobalLanguageData->adjustFontSize(TheInGameUI->getDrawableCaptionPointSize()),
- TheInGameUI->isDrawableCaptionBold() ));
- }
-
- if( m_lastChargeDisplayed != secondsLeft )
- {
- UnicodeString buffer;
- buffer.format( L"%ds", secondsLeft );
- m_chargeDisplayString->setText( buffer );
- m_lastChargeDisplayed = secondsLeft;
- }
-
- ICoord2D screen;
- Coord3D pos;
- getDrawableGeometryInfo().getCenterPosition( *getPosition(), pos );
- TheTacticalView->worldToScreen( &pos, &screen );
- if( screen.x < 1 )
- return;
-
- Color color = GameMakeColor( 255, 220, 120, 255 );
- Color dropColor = GameMakeColor( 0, 0, 0, 255 );
- screen.x -= (m_chargeDisplayString->getWidth() / 2);
- m_chargeDisplayString->draw( screen.x, screen.y, color, dropColor );
-
-} // end drawChargeCountdown
//-------------------------------------------------------------------------------------------------
/** Draw caption */
@@ -4080,6 +3989,64 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)
TheDisplay->drawFillRect( healthBarRegion->lo.x, healthBarRegion->lo.y - 2, healthBoxWidth + 1, 1,
GameMakeColor( 255, 255, 255, 255 ) );
+ //
+ // A superweapon charging, or a building on a timed payout (the supply drop zone), gets the
+ // same yellow bar the production queue uses. Only powers that carry a public timer count -
+ // that is the flag the superweapon list in the corner goes by - so the command centre's
+ // general's powers do not put a permanent bar on the main base.
+ //
+ if( obj->isLocallyControlled() &&
+ !obj->getStatusBits().test( OBJECT_STATUS_UNDER_CONSTRUCTION ) &&
+ !obj->getStatusBits().test( OBJECT_STATUS_SOLD ) )
+ {
+ const UnsignedInt now = TheGameLogic->getFrame();
+ Real chargePct = -1.0f;
+
+ for( BehaviorModule** m = obj->getBehaviorModules(); *m; ++m )
+ {
+ SpecialPowerModuleInterface* sp = (*m)->getSpecialPower();
+ if( sp == NULL )
+ continue;
+ const SpecialPowerTemplate *tmpl = sp->getSpecialPowerTemplate();
+ if( tmpl == NULL || !tmpl->hasPublicTimer() )
+ continue;
+
+ Real full = INT_TO_REAL( tmpl->getReloadTime() );
+ if( full <= 0.0f )
+ continue;
+
+ UnsignedInt ready = sp->getReadyFrame();
+ Real left = (ready > now) ? INT_TO_REAL( ready - now ) : 0.0f;
+ Real pct = 100.0f * (1.0f - left / full);
+ if( pct < 0.0f ) pct = 0.0f;
+ if( pct > 100.0f ) pct = 100.0f;
+ if( chargePct < 0.0f || pct < chargePct )
+ chargePct = pct;
+ }
+
+ if( chargePct < 0.0f )
+ {
+ static const NameKeyType key_OCLUpdate = NAMEKEY( "OCLUpdate" );
+ OCLUpdate *ocl = (OCLUpdate*)obj->findUpdateModule( key_OCLUpdate );
+ if( ocl != NULL )
+ {
+ chargePct = ocl->getCountdownPercent() * 100.0f;
+ if( chargePct < 0.0f ) chargePct = 0.0f;
+ if( chargePct > 100.0f ) chargePct = 100.0f;
+ }
+ }
+
+ if( chargePct >= 0.0f )
+ {
+ Int chargeY = healthBarRegion->lo.y - 3 - healthBoxHeight;
+ TheDisplay->drawOpenRect( healthBarRegion->lo.x, chargeY, healthBoxWidth, healthBoxHeight,
+ healthBoxOutlineSize, GameMakeColor( 128, 128, 0, 255 ) );
+ TheDisplay->drawFillRect( healthBarRegion->lo.x + 1, chargeY + 1,
+ (healthBoxWidth - 2) * chargePct * 0.01f, healthBoxHeight - 2,
+ GameMakeColor( 255, 255, 0, 255 ) );
+ }
+ }
+
// own producers show a yellow production-progress bar above the (selection) line, with seconds left at its top-left
ProductionUpdateInterface *pu = obj->isLocallyControlled() ? obj->getProductionUpdateInterface() : NULL;
const ProductionEntry *pe = pu ? pu->firstProduction() : NULL;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index f89bc1581..68a5c2dc2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -2335,7 +2335,10 @@ CBCommandStatus ControlBar::processContextSensitiveButtonClick( GameWindow *butt
const CommandButton *command = (const CommandButton *)GadgetButtonGetData( button );
if( command && command->getCommandType() == GUI_COMMAND_UNIT_BUILD )
{
- cancelLastQueuedUnit( command->getThingTemplate() );
+ // holding shift takes a whole batch back out, mirroring the shift-click that queued one
+ Int wanted = (TheKeyboard && TheKeyboard->isShift()) ? SHIFT_BUILD_QUEUE_COUNT : 1;
+ while( wanted-- > 0 && cancelLastQueuedUnit( command->getThingTemplate() ) )
+ ;
return CBC_COMMAND_USED;
}
}
@@ -2348,27 +2351,56 @@ CBCommandStatus ControlBar::processContextSensitiveButtonClick( GameWindow *butt
//-------------------------------------------------------------------------------------------------
/** Cancel the last queued production of 'thing' on the representative producer */
//-------------------------------------------------------------------------------------------------
-void ControlBar::cancelLastQueuedUnit( const ThingTemplate *thing )
+Bool ControlBar::cancelLastQueuedUnit( const ThingTemplate *thing )
{
- Object *producer = m_currentSelectedDrawable ? m_currentSelectedDrawable->getObject() : NULL;
- ProductionUpdateInterface *pu = producer ? producer->getProductionUpdateInterface() : NULL;
- if( pu == NULL || thing == NULL )
- return;
- if( producer->getControllingPlayer() != ThePlayerList->getLocalPlayer() )
- return;
+ if( thing == NULL )
+ return FALSE;
+ //
+ // Look across every selected producer, not just the representative one. A shift-click spreads
+ // a batch over all the selected factories, so cancelling only ever on the representative left
+ // the units queued on the others unreachable from the bar.
+ //
+ Object *producer = NULL;
+ ProductionUpdateInterface *pu = NULL;
ProductionID last = PRODUCTIONID_INVALID;
- for( const ProductionEntry *p = pu->firstProduction(); p; p = pu->nextProduction( p ) )
- if( p->getProductionType() == PRODUCTION_UNIT && p->getProductionObject() == thing )
- last = p->getProductionID();
- if( last == PRODUCTIONID_INVALID )
- return;
+
+ 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 *cpu = candidate->getProductionUpdateInterface();
+ if( cpu == NULL )
+ continue;
+
+ ProductionID candidateLast = PRODUCTIONID_INVALID;
+ for( const ProductionEntry *p = cpu->firstProduction(); p; p = cpu->nextProduction( p ) )
+ if( p->getProductionType() == PRODUCTION_UNIT && p->getProductionObject() == thing )
+ candidateLast = p->getProductionID();
+
+ if( candidateLast == PRODUCTIONID_INVALID )
+ continue;
+
+ // prefer the one the bar is actually showing, otherwise take the first that has any
+ producer = candidate;
+ pu = cpu;
+ last = candidateLast;
+ if( m_currentSelectedDrawable && candidate == m_currentSelectedDrawable->getObject() )
+ break;
+ }
+
+ if( pu == NULL || last == PRODUCTIONID_INVALID )
+ return FALSE;
// the producer travels with the message: in a multi-selection the logic cannot tell
// which selected object the queue belongs to otherwise
GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_CANCEL_UNIT_CREATE );
msg->appendIntegerArgument( last );
msg->appendObjectIDArgument( producer->getID() );
+ return TRUE;
} // end cancelLastQueuedUnit
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp
index 5408c3d45..42301acf9 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp
@@ -57,8 +57,6 @@
#include "GameLogic/Object.h"
#include "GameLogic/Module/ProductionUpdate.h"
-// how many units a shift-click on a build button queues at once
-static const Int SHIFT_BUILD_QUEUE_COUNT = 5;
#ifdef _INTERNAL
// for occasional debugging...