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(gameclient): retail health bars, info strip for all, peace in it
Olcay Seygan8b859d61a2e1
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 6be97d369..dda880980 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -1384,17 +1384,8 @@ protected:SuperweaponMap m_superweapons[MAX_PLAYER_COUNT];enum { HUD_OVERLAY_POINT_SIZE = 9 }; ///< small: this sits over the battlefield, not in a panelenum { HUD_CLOCK_POINT_SIZE = 7 }; ///< smaller still, and bold: the clock/rate plate is a glance, not a read- enum { PEACE_TIMER_POINT_SIZE = 24 }; ///< the peace time clock is the one number you watch, so it is read from across the room- enum { PEACE_TIMER_LABEL_POINT_SIZE = 12 }; ///< the word over it, which is read once and then only glanced at- enum { PEACE_TIMER_TOP_PAD = 16 }; ///< how far its plate hangs below the top edge, an 800x600 number like the strip's- enum { PEACE_COUNTDOWN_POINT_SIZE = 96 }; ///< the last ten seconds, written across the middle of the battlefield- enum { PEACE_COUNTDOWN_SECONDS = 10 }; ///< how much of the peace time is counted out in the middle of the screen- enum { PEACE_COUNTDOWN_SIZE_STEP = 12 }; ///< the popping digit's point sizes are rounded to this, so the font library caches four of them rather than one per frame- enum { PEACE_COUNTDOWN_LABEL_SHARE = 4 }; ///< the word over that digit is this fraction of it-- void drawPeaceTimer( void ); ///< the lobby's peace time, counting down at the top of the screen- void drawPeaceCountdown( UnsignedInt framesLeft ); ///< the last seconds of it, one big digit in the middle of the screen- void drawHudOverlay( void ); ///< the small elapsed-time / fps plate (ShowHudOverlay)++ void drawHudOverlay( void ); ///< the top right info strip (ShowNetBox), peace time at its endvoid drawProductionList( void ); ///< the production list, lines on the left above the control barSignalKind m_armedSignal; ///< the signal the next click drops; SIGNAL_KIND_COUNT for none@@ -1430,8 +1421,8 @@ protected:UnsignedInt m_dozerCheckFrame; ///< the logic frame watchDozers last looked onBool m_hadDozer[ MAX_PLAYER_COUNT ]; ///< that player had a dozer or worker then- DisplayString * m_hudDisplayString; ///< the ShowHudOverlay line (fps / clock)- DisplayString * m_peaceTimeDisplayString; ///< the peace time clock at the top of the screen+ DisplayString * m_hudDisplayString; ///< the info strip's readout (clock / rates)+ DisplayString * m_peaceTimeDisplayString; ///< the info strip's red peace time segment/// the broadcast's string for what key names, in font at points, holding text: one string per/// thing written, so a text is laid out again only when it changesDisplayString *broadcastText( const std::string &key, const UnicodeString &text, const char *font, Int points, Bool bold );@@ -1442,8 +1433,6 @@ protected:/// the score bar laid out for players, under the clock's tab, team letters taken from namedvoid layOutBroadcast( const std::vector< SpectatorStats > &players, const std::vector< SpectatorStats > &named,const std::string &tag, Int clockBox, Int clockBoxHeight, BroadcastLayout &layout );- DisplayString * m_peaceTimeLabelDisplayString; ///< the word written over that clock- DisplayString * m_peaceCountdownDisplayString; ///< the big digit of its last ten secondsInt m_lastMoneyDisplayed; ///< so the money gadget is only written when the amount changesUnsignedInt m_hudDrawCount; ///< rendered frames counted by drawHudOverlay itselfUnsignedInt m_hudLastSampleFrame; ///< m_hudDrawCount the fps sample was last refreshed ondiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cppindex c783f803b..e52866b0a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp@@ -4649,29 +4649,7 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)outlineColor = GameMakeColor( 0, healthRatio * 128.0f, 128, 255 );//dark blue to dark cyan}- else if( obj->getControllingPlayer() != NULL &&- obj->getControllingPlayer()->getPlayerColor() != 0 )- {- //- // The bar wears its owner's colour. Red-to-green said how hurt a thing was, which the- // length of the bar was already saying, and said nothing at all about whose it was -- // the one question a glance across a busy fight actually needs answered. Player colour- // is what the minimap, the selection rings and the unit tint all use, so a green bar- // means the same thing everywhere on screen.- //- // The outline stays a darkened version of the same colour, so a light player colour- // still reads against light terrain. A building going up fills its bar in the same- // colour as it builds - whose site it is answers a glance across the map, and the- // seconds written over it (drawConstructPercent) already say it is not finished. The- // disabled blue above keeps its own colour: that is a state nothing else signals.- //- UnsignedByte r, g, b, a;- GameGetColorComponents( clientPlayerColor( obj->getControllingPlayer() ), &r, &g, &b, &a );-- color = GameMakeColor( r, g, b, 255 ); // the stored colour's alpha is not ours to trust- outlineColor = GameDarkenColor( color, 60 );- }- else //red to green: civilians, crates, anything with no owning player to borrow a colour from+ else //retail's ramp for every owner: green at full health, through yellow, to red{RGBColor inColor, outColor;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cppindex 903cba455..2c9b898c5 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameConsole.cpp@@ -557,7 +557,7 @@ void GameConsole::runCommand( AsciiString commandLine )printLine( AsciiString( "speed [n] game speed in percent, 100 is normal, 'reset' goes back" ) );printLine( AsciiString( "get [key] a setting by its Options.ini key; no key lists them all" ) );printLine( AsciiString( "set <key> <v> change a setting and save it, e.g. 'set ShowNetBox no' hides the" ) );- printLine( AsciiString( " top right info box, 'set ShowSuperweaponStrip no' the superweapon timers" ) );+ printLine( AsciiString( " top right info strip" ) );printLine( AsciiString( "freecam photo mode: fly the camera anywhere, the whole map drawn, no interface." ) );printLine( AsciiString( " W/S forward and back, A/D left and right, R up, F down, mouse turns," ) );printLine( AsciiString( " Shift faster; Esc or 'freecam' again lands. 'freecam x y z heading tilt'" ) );diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 5103d89eb..8356472ed 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -1150,8 +1150,6 @@ InGameUI::InGameUI()forgetPendingPlacements();m_hudDisplayString = NULL;m_peaceTimeDisplayString = NULL;- m_peaceTimeLabelDisplayString = NULL;- m_peaceCountdownDisplayString = NULL;m_lastMoneyDisplayed = -1;m_hudDrawCount = 0;m_hudLastSampleFrame = 0;@@ -7882,21 +7880,6 @@ void InGameUI::updateFloatingText( void )//-------------------------------------------------------------------------------------------------/** Itterates through and draws each floating text *///--------------------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------------------/** A one-line heads-up overlay: render rate and elapsed game time.- * GlobalData's m_showHudOverlay: on by default in the developer builds (Debug, _INTERNAL) and off in- * Release, a project rule. A player turns it on with ShowHudOverlay = Yes in GameData.ini; the harnesses- * whose screenshots are evidence pass -showHudOverlay. Nothing shipped forces it on: the staged overlay- * and the packages refuse a ShowHudOverlay = Yes. Retail only ever showed the frame rate, and only behind- * -displayDebug together with a screenful of engine internals. */-//--------------------------------------------------------------------------------------------------//--------------------------------------------------------------------------------------------------/** How the last ten seconds of peace time animate, as fractions of one second. */-//--------------------------------------------------------------------------------------------------static const Real PEACE_COUNTDOWN_POP_SCALE = 1.35f; ///< the size the digit lands at when the second turns-static const Real PEACE_COUNTDOWN_POP_TIME = 0.35f; ///< how long it takes to settle back to its own size-static const Real PEACE_COUNTDOWN_FADE_TIME = 0.30f; ///< how long it fades out for at the end of the second-//-------------------------------------------------------------------------------------------------/** The one red the truce is written in, wherever it is written. *///-------------------------------------------------------------------------------------------------@@ -7905,155 +7888,6 @@ static Color peaceTimeColor( Int alpha )return GameMakeColor( 255, 48, 48, alpha );}-//--------------------------------------------------------------------------------------------------/** The lobby's peace time at the top of the screen, in the middle of it: the word PEACE in small- * letters over the time left, both red and bold on one plate. The top centre is where a player- * already looks for the state of the match, and it keeps the corner free for the clock and the- * superweapon timers. It is not behind ShowHudOverlay - that switch is for a readout, and this- * is a rule of the match.- *- * The plate goes away for the last ten seconds. Those are counted out across the middle of the- * screen instead, and two copies of the same number in two places is one of them asking to be- * read and neither getting it. Nothing draws once the truce runs out. */-//--------------------------------------------------------------------------------------------------void InGameUI::drawPeaceTimer( void )-{- if( TheGameLogic == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )- return;-- if( !TheGameLogic->isPeaceTime() )- return;-- const UnsignedInt left = TheGameLogic->getPeaceTimeEndFrame() - TheGameLogic->getFrame();- if( left <= PEACE_COUNTDOWN_SECONDS * LOGICFRAMES_PER_SECOND )- {- drawPeaceCountdown( left );- return;- }-- const UnsignedInt secs = ControlBar_secondsFromFrames( (Real)left );-- UnicodeString text;- text.format( TheGameText->fetch( "GUI:PeaceTimeHud" ), secs / 60, secs % 60 );-- if( m_peaceTimeDisplayString == NULL )- {- m_peaceTimeDisplayString = TheDisplayStringManager->newDisplayString();- m_peaceTimeDisplayString->setFont( TheFontLibrary->getFont( m_superweaponNormalFont,- TheGlobalLanguageData->adjustFontSize( PEACE_TIMER_POINT_SIZE ),- TRUE ) );- }- m_peaceTimeDisplayString->setText( text );-- // the label is a second string rather than a line of the first: the text renderer has no- // concept of a newline and would draw one as a character- if( m_peaceTimeLabelDisplayString == NULL )- {- m_peaceTimeLabelDisplayString = TheDisplayStringManager->newDisplayString();- m_peaceTimeLabelDisplayString->setFont( TheFontLibrary->getFont( m_superweaponNormalFont,- TheGlobalLanguageData->adjustFontSize( PEACE_TIMER_LABEL_POINT_SIZE ),- TRUE ) );- }- m_peaceTimeLabelDisplayString->setText( TheGameText->fetch( "GUI:PeaceTimeHudLabel" ) );-- Int textWidth = 0, textHeight = 0;- m_peaceTimeDisplayString->getSize( &textWidth, &textHeight );-- Int labelWidth = 0, labelHeight = 0;- m_peaceTimeLabelDisplayString->getSize( &labelWidth, &labelHeight );-- // clear of the top edge, the gap growing with the screen the same way the command bar does- const Int pad = 4;- const Int plateWidth = (labelWidth > textWidth ? labelWidth : textWidth) + pad*2;- const Int plateLeft = (TheDisplay->getWidth() - plateWidth) / 2;- const Int top = stripPixels( PEACE_TIMER_TOP_PAD );-- TheDisplay->drawFillRect( plateLeft, top - 1, plateWidth, labelHeight + textHeight + 2,- GameMakeColor( 0, 0, 0, 160 ) );-- m_peaceTimeLabelDisplayString->draw( (TheDisplay->getWidth() - labelWidth) / 2, top,- peaceTimeColor( 255 ), GameMakeColor( 0, 0, 0, 255 ) );-- m_peaceTimeDisplayString->draw( (TheDisplay->getWidth() - textWidth) / 2, top + labelHeight,- peaceTimeColor( 255 ), GameMakeColor( 0, 0, 0, 255 ) );-}--//--------------------------------------------------------------------------------------------------/** The last ten seconds of that peace time, one digit at a time, with the plate at the top of the- * screen taken down for them. The word PEACE goes over the digit at a quarter of its size, on- * the same line the plate's own word was on, so what happens at ten seconds is the time being- * replaced by a number you cannot miss rather than the whole thing moving somewhere else. The- * middle of the screen is where the fighting you are about to do is, and a countdown sitting on- * your own units is in the way of the thing it counts down to.- *- * Each second the digit lands at PEACE_COUNTDOWN_POP_SCALE of its size, settles to it over the- * first third of the second, then fades out through the last third, so the movement is what- * catches the eye rather than the number changing. The word holds still and keeps its colour- * through all of it, and the digit grows downwards from under it, so nothing but the number- * moves.- *- * The animation is driven by the logic frame, not the wall clock, because the number it counts- * is a logic frame: a paused or slowed game shows a paused countdown instead of one that has- * run ahead of the truce it belongs to. */-//--------------------------------------------------------------------------------------------------void InGameUI::drawPeaceCountdown( UnsignedInt framesLeft )-{- const UnsignedInt secondsLeft = (framesLeft + LOGICFRAMES_PER_SECOND - 1) / LOGICFRAMES_PER_SECOND;- const UnsignedInt framesLeftOfSecond = framesLeft - (secondsLeft - 1) * LOGICFRAMES_PER_SECOND;- const Real secondElapsed = 1.0f - INT_TO_REAL( framesLeftOfSecond ) / INT_TO_REAL( LOGICFRAMES_PER_SECOND );-- Real scale = 1.0f;- if( secondElapsed < PEACE_COUNTDOWN_POP_TIME )- scale = PEACE_COUNTDOWN_POP_SCALE- - (PEACE_COUNTDOWN_POP_SCALE - 1.0f) * (secondElapsed / PEACE_COUNTDOWN_POP_TIME);-- Real opacity = 1.0f;- if( secondElapsed > 1.0f - PEACE_COUNTDOWN_FADE_TIME )- opacity = (1.0f - secondElapsed) / PEACE_COUNTDOWN_FADE_TIME;-- // rounded to a step so a second's worth of scaling asks the font library for a few sizes, not thirty- const Int wantedPointSize = REAL_TO_INT_CEIL( PEACE_COUNTDOWN_POINT_SIZE * scale );- const Int pointSize = ((wantedPointSize + PEACE_COUNTDOWN_SIZE_STEP - 1) / PEACE_COUNTDOWN_SIZE_STEP)- * PEACE_COUNTDOWN_SIZE_STEP;-- if( m_peaceCountdownDisplayString == NULL )- m_peaceCountdownDisplayString = TheDisplayStringManager->newDisplayString();-- m_peaceCountdownDisplayString->setFont( TheFontLibrary->getFont( m_superweaponNormalFont,- TheGlobalLanguageData->adjustFontSize( pointSize ),- TRUE ) );-- UnicodeString text;- text.format( u"%d", (Int)secondsLeft );- m_peaceCountdownDisplayString->setText( text );-- // the same string the plate at the top uses, in its own size: the two are never up together- if( m_peaceTimeLabelDisplayString == NULL )- m_peaceTimeLabelDisplayString = TheDisplayStringManager->newDisplayString();-- m_peaceTimeLabelDisplayString->setFont( TheFontLibrary->getFont( m_superweaponNormalFont,- TheGlobalLanguageData->adjustFontSize( PEACE_COUNTDOWN_POINT_SIZE- / PEACE_COUNTDOWN_LABEL_SHARE ),- TRUE ) );- m_peaceTimeLabelDisplayString->setText( TheGameText->fetch( "GUI:PeaceTimeHudLabel" ) );-- Int textWidth = 0, textHeight = 0;- m_peaceCountdownDisplayString->getSize( &textWidth, &textHeight );-- Int labelWidth = 0, labelHeight = 0;- m_peaceTimeLabelDisplayString->getSize( &labelWidth, &labelHeight );-- const Int alpha = REAL_TO_INT_CEIL( opacity * 255.0f );-- // the word and the digit stand on the line the plate's word was on- const Int top = stripPixels( PEACE_TIMER_TOP_PAD );- m_peaceTimeLabelDisplayString->draw( (TheDisplay->getWidth() - labelWidth) / 2, top,- peaceTimeColor( 255 ), GameMakeColor( 0, 0, 0, 255 ) );-- m_peaceCountdownDisplayString->draw( (TheDisplay->getWidth() - textWidth) / 2, top + labelHeight,- peaceTimeColor( alpha ), GameMakeColor( 0, 0, 0, alpha ) );-}-// -directorrecord's broadcast is drawn in zerohour.gg's colours: the ground, its panel, ink, muted// text, the line and the gold the pane lines are drawn in. The ground is opaque: at the site's veil// the gold of the pane lines under it showed through the score bar's corners. The site sets words in@@ -9209,9 +9043,6 @@ void InGameUI::drawDirectorIntroPlate( void )//-------------------------------------------------------------------------------------------------void InGameUI::drawHudOverlay( void ){- if( !TheGlobalData->m_showHudOverlay || !TheGlobalData->m_showNetBox )- return;-// only once a real game is under way - not in the shell, and not on the menu's background mapif( !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )return;@@ -9219,6 +9050,13 @@ void InGameUI::drawHudOverlay( void )if( TheGameLogic->getFrame() == 0 )return;+ // ShowNetBox is the player's switch for the readout. Peace time is a rule of the match rather+ // than a readout, so while it runs the strip stays up with only that segment in it.+ const Bool showInfo = TheGlobalData->m_showNetBox;+ const Bool peace = TheGameLogic->isPeaceTime();+ if( !showInfo && !peace )+ return;+//// Two rates, both sampled over half a second of wall clock so the numbers are readable, and// they are not the same thing. Client frames are the render rate. Logic frames are the@@ -9315,13 +9153,45 @@ void InGameUI::drawHudOverlay( void )TheGlobalLanguageData->adjustFontSize( HUD_CLOCK_POINT_SIZE ),TRUE ) );}- m_hudDisplayString->setText( text );-Int textWidth = 0, textHeight = 0;- m_hudDisplayString->getSize( &textWidth, &textHeight );+ if( showInfo )+ {+ m_hudDisplayString->setText( text );+ m_hudDisplayString->getSize( &textWidth, &textHeight );+ }- // top right, clear of the radar and the superweapon timers, and first in that corner: the peace- // time clock is drawn across the top middle of the screen and takes no room here.+ // the truce goes last on the line, in red, so it sits in the same spot whether the readout to+ // its left is there or not+ Int peaceWidth = 0;+ if( peace )+ {+ const UnsignedInt secs = ControlBar_secondsFromFrames(+ (Real)(TheGameLogic->getPeaceTimeEndFrame() - logicFrame) );+ UnicodeString clock;+ clock.format( TheGameText->fetch( "GUI:PeaceTimeHud" ), secs / 60, secs % 60 );+ UnicodeString peaceText = TheGameText->fetch( "GUI:PeaceTimeHudLabel" );+ peaceText.concat( u' ' );+ peaceText.concat( clock );++ if( m_peaceTimeDisplayString == NULL )+ {+ m_peaceTimeDisplayString = TheDisplayStringManager->newDisplayString();+ m_peaceTimeDisplayString->setFont( TheFontLibrary->getFont( m_superweaponNormalFont,+ TheGlobalLanguageData->adjustFontSize( HUD_CLOCK_POINT_SIZE ),+ TRUE ) );+ }+ m_peaceTimeDisplayString->setText( peaceText );++ Int peaceHeight = 0;+ m_peaceTimeDisplayString->getSize( &peaceWidth, &peaceHeight );+ if( peaceHeight > textHeight )+ textHeight = peaceHeight;+ }++ const Int gap = (showInfo && peace) ? stripPixels( 6 ) : 0;+ const Int stripWidth = textWidth + gap + peaceWidth;++ // top right, clear of the radar and the superweapon timers, and first in that corner.//// The three gaps are 800x600 numbers put through the command bar's own scale, like everything// else on this overlay. Held at a flat pixel count the plate crept into the corner as the@@ -9329,14 +9199,18 @@ void InGameUI::drawHudOverlay( void )// shot and a 1080-tall one did not overlay however the text was sized.const Int pad = stripPixels( 2 );const UIRect box = TheUIRect();- Int x = box.x + box.w - textWidth - pad - stripPixels( 4 );+ Int x = box.x + box.w - stripWidth - pad - stripPixels( 4 );Int y = box.y + stripPixels( 2 );// a plate behind it, so it stays legible over bright terrain- TheDisplay->drawFillRect( x - pad, y - 1, textWidth + pad*2, textHeight + 2,+ TheDisplay->drawFillRect( x - pad, y - 1, stripWidth + pad*2, textHeight + 2,GameMakeColor( 0, 0, 0, 140 ) );- m_hudDisplayString->draw( x, y, GameMakeColor( 235, 235, 235, 255 ), GameMakeColor( 0, 0, 0, 255 ) );+ if( showInfo )+ m_hudDisplayString->draw( x, y, GameMakeColor( 235, 235, 235, 255 ), GameMakeColor( 0, 0, 0, 255 ) );++ if( peace )+ m_peaceTimeDisplayString->draw( x + textWidth + gap, y, peaceTimeColor( 255 ), GameMakeColor( 0, 0, 0, 255 ) );}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cppindex 56231d770..0ad5fca4f 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp@@ -675,15 +675,12 @@ void W3DInGameUI::draw( void )#endif//- // The peace time clock across the top middle and the clock plate in the corner go on last, after- // every window has painted: drawn before the window manager, a dialog, the menu or the control- // bar's own art covered them.+ // The info strip in the corner, peace time included, goes on last, after every window has+ // painted: drawn before the window manager, a dialog, the menu or the control bar's own art+ // covered it.//if( matchOnScreen )- {- drawPeaceTimer();drawHudOverlay();- }#ifdef EXTENDED_STATS}