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.

fix(gameclient): price on the build button, and the new AI levels in the lobby

Olcay Seygan83b2d412d434
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 081f406b1..997483809 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -79,7 +79,8 @@ found and fixed — EA's own, not port damage.**
- Easy, Steady, Medium, Hard, Brutal, Merciless. Medium to Brutal used to be a cliff; the steps in between are where a player actually needs them.
- Every level plays by your rules. No level gets extra money, cheaper units, faster building, longer vision or tougher units - in either direction. What changes is what the computer is allowed to decide: how often it looks at the map, how long it takes to react, whether it counters what you field, whether it masses before attacking, whether it pulls damaged units out.
- Each step up switches on exactly one new thing, so you can say in a sentence what you get for climbing.
-- Measured, not asserted: Merciless beats Easy 15-0 over 32 headless matches with the seats swapped both ways, on twice the army and twice the spending. Easy is slow and brave. Steady saves its damaged units. Medium expands on its own. Hard counters your build. Brutal masses and commits. Merciless is the ceiling - everything on, no hesitation.
+- Measured, not asserted: Merciless beats Easy 15-0 over 32 headless matches with the seats swapped both ways, on twice the army and twice the spending.
+- The three new levels showed up in the lobby as "Closed" and lost their start position on the map every time the list refreshed. Both fixed. Easy is slow and brave. Steady saves its damaged units. Medium expands on its own. Hard counters your build. Brutal masses and commits. Merciless is the ceiling - everything on, no hesitation.
- Making Easy easier means giving it worse decisions, never less money. That is the whole promise.
- The computer also picks a personality each match and keeps it: one plays for the attack, the other for the base. Same resources, spent differently.
@@ -266,7 +267,7 @@ found and fixed — EA's own, not port damage.**
## Where the money is, and where it is coming from
- Supply piles and docks say what is left in them, in cash, over the pile. No more guessing which expansion is worth taking from the art on the model.
-- Everything on the field prices itself off its top right corner, at its owner's price. What that push cost, and what he just lost.
+- Every build button carries its price in the top right corner, opposite the build time already in the other one. It was only ever in the tooltip, which means hovering one button at a time to compare two of them.
- A worker fetching or handing over a box shows a bar while it works.
- Hackers show how far off the next payout is. So do the black market and the oil derricks.
- Factories take a hundred units in the queue, not nine. The build queue only ever had nine buttons and that had become the limit.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
index 3458f9eac..97cf55452 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h
@@ -714,8 +714,6 @@ private:
DisplayString* m_constructDisplayString; ///< string to display construction % complete
DisplayString* m_supplyCashDisplayString; ///< string to display the cash left in a supply pile
Int m_lastSupplyCashDisplayed; ///< so the string is only rebuilt when the pile shrinks
- DisplayString* m_costDisplayString; ///< string to display what this thing cost to build
- Int m_lastCostDisplayed; ///< so the string is built once and not every frame
DisplayString* m_captionDisplayString; ///< string to display caption
DisplayString* m_groupNumber; ///< string to display the group number of this drawable
@@ -757,7 +755,6 @@ private:
// "icon" drawing methods **************
void drawConstructPercent( const IRegion2D *healthBarRegion ); ///< display % construction complete
void drawSupplyCash( const IRegion2D *healthBarRegion ); ///< display the cash left in a supply pile
- void drawUnitCost( const IRegion2D *healthBarRegion ); ///< display what this thing cost to build
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/Include/GameClient/Gadget.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h
index 66e741573..e6e234c79 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h
@@ -437,6 +437,7 @@ typedef struct _PushButtonData
Color colorBorder; ///< The color for the border around the button
Int drawCount; ///< when > 0, a small number badge drawn in the bottom right corner
Int drawSeconds; ///< when > 0, a seconds label drawn in the bottom left corner
+ Int drawCost; ///< when > 0, a price drawn in the top right corner
Int barPercent; ///< when >= 0, a thin bar drawn along the bottom edge (experience)
Color barColor; ///< colour of that bar
void *userData; ///< random additional data we can set
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h
index fa121deaf..5b0902a3a 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h
@@ -84,6 +84,7 @@ void GadgetButtonDrawOverlayImage( GameWindow *g, const Image *image );
void GadgetButtonSetBorder( GameWindow *g, Color color, Bool drawBorder = TRUE );
void GadgetButtonSetCount( GameWindow *g, Int count );
void GadgetButtonSetSeconds( GameWindow *g, Int seconds );
+void GadgetButtonSetCost( GameWindow *g, Int cost );
void GadgetButtonSetBar( GameWindow *g, Int percent, Color color );
void GadgetButtonSetData(GameWindow *g, void *data);
void *GadgetButtonGetData(GameWindow *g);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index 6e82753fd..dd356a188 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -420,8 +420,6 @@ Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBit
m_lastConstructDisplayed = -1.0f;
m_supplyCashDisplayString = NULL;
m_lastSupplyCashDisplayed = -1;
- m_costDisplayString = NULL;
- m_lastCostDisplayed = -1;
//Added By Sadullah Nader
//Fix for the building percent
@@ -586,10 +584,6 @@ Drawable::~Drawable()
TheDisplayStringManager->freeDisplayString( m_supplyCashDisplayString );
m_supplyCashDisplayString = NULL;
- if( m_costDisplayString )
- TheDisplayStringManager->freeDisplayString( m_costDisplayString );
- m_costDisplayString = NULL;
-
if ( m_captionDisplayString )
TheDisplayStringManager->freeDisplayString( m_captionDisplayString );
m_captionDisplayString = NULL;
@@ -2877,7 +2871,6 @@ void Drawable::drawIconUI( void )
drawCaption( healthBarRegion );
drawConstructPercent( healthBarRegion );
drawSupplyCash( healthBarRegion );
- drawUnitCost( 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...
@@ -3936,60 +3929,6 @@ void Drawable::drawSupplyCash( const IRegion2D *healthBarRegion )
} // end drawSupplyCash
-//-------------------------------------------------------------------------------------------------
-/** What this thing cost to build, written off its top right corner. The price of everything on
- * the field is otherwise only visible in the command bar, and only for what you can build right
- * now - so "is that push worth trading for" and "what did he just lose" were questions you
- * answered from memory. It is the owner's price, so a faction discount shows.
- *
- * Anything the player never bought - scenery, wreckage, projectiles, civilians - prices at zero
- * and says nothing, which is the whole filter this needs. */
-//-------------------------------------------------------------------------------------------------
-void Drawable::drawUnitCost( const IRegion2D *healthBarRegion )
-{
- if( healthBarRegion == NULL )
- return;
-
- Object *obj = getObject();
- if( obj == NULL || obj->isEffectivelyDead() || obj->isKindOf( KINDOF_IGNORED_IN_GUI ) )
- return;
-
- // shrouded ground keeps its secrets: what was there when you last looked is not news
- if( obj->getShroudedStatus( ThePlayerList->getLocalPlayer()->getPlayerIndex() ) != OBJECTSHROUD_CLEAR )
- return;
-
- Int cost = getTemplate() ? getTemplate()->calcCostToBuild( obj->getControllingPlayer() ) : 0;
- if( cost <= 0 )
- return;
-
- if( m_costDisplayString == NULL )
- {
- m_costDisplayString = TheDisplayStringManager->newDisplayString();
- m_costDisplayString->setFont( TheFontLibrary->getFont( TheInGameUI->getDrawableCaptionFontName(),
- TheGlobalLanguageData->adjustFontSize( TheInGameUI->getDrawableCaptionPointSize() - 2 ),
- FALSE ) );
- }
-
- if( m_lastCostDisplayed != cost )
- {
- UnicodeString buffer;
- buffer.format( L"$%d", cost );
- m_costDisplayString->setText( buffer );
- m_lastCostDisplayed = cost;
- }
-
- Int width, height;
- m_costDisplayString->getSize( &width, &height );
-
- // hangs off the right end of the health bar, above it - clear of the veterancy chevron on the
- // bar's own right end and of the queue count that is right-aligned onto it
- m_costDisplayString->draw( healthBarRegion->hi.x + 2, healthBarRegion->lo.y - height,
- GameMakeColor( 235, 210, 120, 255 ),
- GameMakeColor( 0, 0, 0, 255 ) );
-
-} // end drawUnitCost
-
-
//-------------------------------------------------------------------------------------------------
/** Draw caption */
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 9668e38e4..1331fd286 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -3082,6 +3082,7 @@ void ControlBar::setControlCommand( GameWindow *button, const CommandButton *com
// time of whatever used to live in that window.
GadgetButtonSetCount( button, 0 );
GadgetButtonSetSeconds( button, 0 );
+ GadgetButtonSetCost( button, 0 );
setCommandBarBorder(button, commandButton->getCommandButtonMappedBorderType());
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
index db7bd3a99..d9a284bfc 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
@@ -829,7 +829,16 @@ void ControlBar::updateContextCommand( void )
const ThingTemplate *tmpl = command->getThingTemplate();
Player *localPlayer = ThePlayerList ? ThePlayerList->getLocalPlayer() : NULL;
if( tmpl && localPlayer )
+ {
GadgetButtonSetSeconds( win, ControlBar_secondsFromFrames( (Real)tmpl->calcTimeToBuild( localPlayer ) ) );
+ //
+ // ... and what it costs, in the opposite corner. The price was only ever in the
+ // tooltip, which means hovering one button at a time to compare two of them - and
+ // it is the other half of the question the seconds answer. It is this player's
+ // price, so a faction discount or a general's promotion shows in it.
+ //
+ GadgetButtonSetCost( win, tmpl->calcCostToBuild( localPlayer ) );
+ }
}
//
@@ -849,7 +858,10 @@ void ControlBar::updateContextCommand( void )
const UpgradeTemplate *ut = command->getUpgradeTemplate();
Player *localPlayer = ThePlayerList ? ThePlayerList->getLocalPlayer() : NULL;
if( ut && localPlayer )
+ {
GadgetButtonSetSeconds( win, ControlBar_secondsFromFrames( (Real)ut->calcTimeToBuild( localPlayer ) ) );
+ GadgetButtonSetCost( win, ut->calcCostToBuild( localPlayer ) );
+ }
if( queuedHere )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
index 3742c3322..5f023bb3f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
@@ -1160,7 +1160,7 @@ void InitSkirmishGameGadgets( void )
GadgetComboBoxSetItemData(comboBoxPlayer[i], 4, (void *)SLOT_STEADY_AI);
GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:MediumAI"),white);
GadgetComboBoxSetItemData(comboBoxPlayer[i], 5, (void *)SLOT_MED_AI);
- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:HardAI"),white);
+ GadgetComboBoxAddEntry(comboBoxPlayer[i],UnicodeString(L"Hard AI"),white);
GadgetComboBoxSetItemData(comboBoxPlayer[i], 6, (void *)SLOT_HARD_AI);
GadgetComboBoxAddEntry(comboBoxPlayer[i],UnicodeString(L"Brutal AI"),white);
GadgetComboBoxSetItemData(comboBoxPlayer[i], 7, (void *)SLOT_BRUTAL_AI);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp
index 551068612..87a368276 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->drawClock = NO_CLOCK;
p->drawCount = 0;
p->drawSeconds = 0;
+ p->drawCost = 0;
p->barPercent = -1;
p->barColor = GAME_COLOR_UNDEFINED;
p->overlayImage = NULL;
@@ -735,6 +736,28 @@ void GadgetButtonSetSeconds( GameWindow *g, Int seconds )
g->winSetUserData(pData);
}
+// GadgetButtonSetCost ========================================================
+/** Set the price drawn in the button's top right corner, 0 for none. What one
+ * of these costs is the other half of what a build decision needs, next to
+ * the seconds already in the opposite corner. Unlike the seconds it is not
+ * cleared by GadgetButtonClearClock - a price does not change per frame. */
+//=============================================================================
+void GadgetButtonSetCost( GameWindow *g, Int cost )
+{
+ if( g == NULL )
+ return;
+
+ PushButtonData *pData = (PushButtonData *)g->winGetUserData();
+ if(!pData)
+ {
+ pData = getNewPushButtonData();
+ if(!pData)
+ return;
+ }
+ pData->drawCost = cost;
+ g->winSetUserData(pData);
+}
+
// GadgetButtonSetBar =========================================================
/** Set a thin progress bar along the button's bottom edge, percent < 0 for none */
//=============================================================================
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp
index adbdc94ed..88260d27e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp
@@ -200,12 +200,39 @@ void GameSlot::setMapAvailability( Bool hasMap )
}
}
+/** Which slot states are an opponent seat.
+ *
+ * This used to be written out as a list in three places, and appending the ladder's three rungs to
+ * the enum broke two of them: the seat came back named "Closed" because setState's name switch
+ * had no case for it, and its start position was wiped on every menu refresh because the guard
+ * below did not recognise it as still being the same kind of seat. One function, three callers.
+ *
+ * SLOT_TAKEOVER counts here on purpose: to the lobby it is an ordinary opponent seat that the
+ * host owns and that no network peer is expected to check in from. It differs in one place only
+ * - the player it creates is human (GameLogic::startNewGame), so no AI is ever attached. */
+static Bool slotStateIsAI( SlotState state )
+{
+ switch( state )
+ {
+ case SLOT_EASY_AI:
+ case SLOT_STEADY_AI:
+ case SLOT_MED_AI:
+ case SLOT_HARD_AI:
+ case SLOT_BRUTAL_AI:
+ case SLOT_MERCILESS_AI:
+ case SLOT_TAKEOVER:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
void GameSlot::setState( SlotState state, UnicodeString name, UnsignedInt IP )
{
// An opponent seat keeps its colour, faction, team and start spot while it stays an opponent
// seat - SLOT_TAKEOVER included, or the menu's own refresh (which re-sends the state to the
// slot) would wipe the faction and team the moment you picked them.
- if (!(isAI() && (state == SLOT_EASY_AI || state == SLOT_MED_AI || state == SLOT_BRUTAL_AI || state == SLOT_TAKEOVER)))
+ if (!(isAI() && slotStateIsAI( state )))
{
m_color = -1;
m_startPos = -1;
@@ -245,6 +272,20 @@ void GameSlot::setState( SlotState state, UnicodeString name, UnsignedInt IP )
case SLOT_TAKEOVER:
m_name = TheGameText->fetch("GUI:HumanSlot");
break;
+ //
+ // The three rungs the ladder added. No shipped string for them, so plain English rather
+ // than a MISSING: - and, before these cases existed, they fell through to the default and
+ // every one of them appeared in the lobby as "Closed".
+ //
+ case SLOT_STEADY_AI:
+ m_name = UnicodeString(L"Steady AI");
+ break;
+ case SLOT_HARD_AI:
+ m_name = UnicodeString(L"Hard AI");
+ break;
+ case SLOT_MERCILESS_AI:
+ m_name = UnicodeString(L"Merciless AI");
+ break;
case SLOT_CLOSED:
default:
m_name = TheGameText->fetch("GUI:Closed");
@@ -268,12 +309,7 @@ Bool GameSlot::isOccupied( void ) const
Bool GameSlot::isAI( void ) const
{
- // SLOT_TAKEOVER counts here on purpose: to the lobby it is an ordinary opponent seat that the
- // host owns and that no network peer is expected to check in from. It differs in one place
- // only - the player it creates is human (GameLogic::startNewGame), so no AI is ever attached.
- return m_state == SLOT_EASY_AI || m_state == SLOT_MED_AI || m_state == SLOT_BRUTAL_AI ||
- m_state == SLOT_STEADY_AI || m_state == SLOT_HARD_AI || m_state == SLOT_MERCILESS_AI ||
- m_state == SLOT_TAKEOVER;
+ return slotStateIsAI( m_state );
}
Bool GameSlot::isPlayer( AsciiString userName ) const
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp
index 4a2a3ef67..648996ea4 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp
@@ -231,6 +231,46 @@ static void drawSecondsBadge( GameWindow *window, Int seconds )
} // end drawSecondsBadge
+// drawCostBadge ==============================================================
+/** Draw a "$1200" price in the button's top right corner - what one of these
+ * costs. The opposite corner from the seconds, and the two together are the
+ * whole of what a build decision asks: how much, and how long. */
+//=============================================================================
+static void drawCostBadge( GameWindow *window, Int cost )
+{
+ static DisplayString *label = NULL;
+ ICoord2D origin, size, textPos;
+ Int width, height;
+
+ if( label == NULL )
+ {
+ label = TheDisplayStringManager->newDisplayString();
+ if( label == NULL )
+ return;
+ }
+
+ UnicodeString text;
+ text.format( L"$%d", cost );
+ label->setText( text );
+
+ if( label->getFont() != window->winGetFont() )
+ label->setFont( window->winGetFont() );
+
+ window->winGetScreenPosition( &origin.x, &origin.y );
+ window->winGetSize( &size.x, &size.y );
+ label->getSize( &width, &height );
+
+ textPos.x = origin.x + size.x - width - 3;
+ textPos.y = origin.y + 1;
+
+ // same translucent plate the other two badges wear - button art can be any colour
+ TheDisplay->drawFillRect( textPos.x - 2, textPos.y, width + 4, height,
+ GameMakeColor( 0, 0, 0, 160 ) );
+ label->draw( textPos.x, textPos.y, GameMakeColor( 235, 210, 120, 255 ),
+ GameMakeColor( 0, 0, 0, 255 ) );
+
+} // end drawCostBadge
+
// drawButtonBar ==============================================================
/** Draw a thin progress bar along the button's bottom edge (experience) */
//=============================================================================
@@ -395,6 +435,9 @@ void W3DGadgetPushButtonDraw( GameWindow *window, WinInstanceData *instData )
if( pData->drawSeconds > 0 )
drawSecondsBadge( window, pData->drawSeconds );
+ if( pData->drawCost > 0 )
+ drawCostBadge( window, pData->drawCost );
+
if( pData->barPercent >= 0 )
drawButtonBar( window, pData->barPercent, pData->barColor );
}
@@ -574,6 +617,9 @@ void W3DGadgetPushButtonImageDrawOne( GameWindow *window,
if( pData->drawSeconds > 0 )
drawSecondsBadge( window, pData->drawSeconds );
+ if( pData->drawCost > 0 )
+ drawCostBadge( window, pData->drawCost );
+
if( pData->barPercent >= 0 )
drawButtonBar( window, pData->barPercent, pData->barColor );
}
@@ -839,6 +885,9 @@ void W3DGadgetPushButtonImageDrawThree(GameWindow *window, WinInstanceData *inst
if( pData->drawSeconds > 0 )
drawSecondsBadge( window, pData->drawSeconds );
+ if( pData->drawCost > 0 )
+ drawCostBadge( window, pData->drawCost );
+
if( pData->barPercent >= 0 )
drawButtonBar( window, pData->barPercent, pData->barColor );
}