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): price the field, show the money clocks, and fix every countdown
Olcay Seygane89488b15a78
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b87d431fc..450dcc04d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -37,6 +37,7 @@ found and fixed — EA's own, not port damage.**- A unit turns onto whatever is actually shooting it, then resumes the advance.- Otherwise it picks the worst thing in range: anything armed before anything that is not, then the more dangerous of the two, and worth fades with distance so it is never the far one it walks the field for. A group ordered through a base no longer stops for the first dozer it passes while the artillery beside it keeps firing.- Ctrl on the attack-move click no longer shells the ground instead.+- A big selection arrives as a crowd. Two hundred units told to attack-move used to spread along a line and three hundred told to move mostly stood still: the group tried to hold its shape all the way in. Now everyone heads for the spot you clicked and takes the nearest free ground to it.- Troop Crawlers wait for their squad to climb back in, up to ten seconds.- One man who cannot get back aboard no longer parks the Crawler for the rest of the attack move.- Their squad stays out until the area is clear, instead of piling back in after every kill.@@ -192,10 +193,12 @@ found and fixed — EA's own, not port damage.**## Placing buildings-- The placement grid is drawn on the ground and follows the slope.+- The placement grid is drawn on the ground and follows the slope, and reaches twice as far as it used to.- Unbuildable ground is a soft red wash, crossed out square by square.- Running out of money no longer strands the ghost on the map.- Holding shift and clicking out a row of buildings no longer stops halfway and selects one.+- That row keeps going with no worker selected, too, instead of ending after the first building.+- Turning a building no longer turns everything you build afterwards. A wheeled heading still carries from one wall to the next, but the next supply centre comes out facing the way it was designed to.- A building you point at blocked ground slides to the nearest spot it fits, and lands there.- The pointer keeps its build cursor while you place, even passing over your own buildings.- GLA defences get a range ring while you site them.@@ -203,6 +206,14 @@ found and fixed — EA's own, not port damage.**- The two-key building shortcut survives the command bar's redraw now.- Escape cancels what you were doing before it opens the menu.+## 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.+- 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.+## Health bars- Health bars are in the owner's colour instead of green to red.@@ -213,6 +224,8 @@ found and fixed — EA's own, not port damage.**## Twenty-two-year-old bugs, found by testing+- Every countdown on screen was a second too long. Rounding up a whole number of seconds gave a whole number plus one, so a ten second build said eleven - production queues, buildings going up, superweapons, all of it.+- A Chinese silo researching an upgrade while its missile charged drew both bars and both countdowns in the same row of pixels. They stack now.- Units moving diagonally ran up to 40% faster than their own stat sheet.- Garrisoned infantry and base defences only ever range-checked one of their weapons.- Killing something with poison or toxin credited nobody with experience or score.diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex 501f6926a..85639ef6e 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -953,6 +953,8 @@ public:// get method for list of commandbuttonsconst CommandButton *getCommandButtons( void ) { return m_commandButtons; }+ Drawable *findStandInBuilder( Bool freeOnly ); ///< the local player's free builder (or, unless freeOnly, any builder) to stand in for an empty selection+protected:ICoord2D m_defaultControlBarPosition; ///< Stored the original position of the control bar on the screen@@ -1006,7 +1008,6 @@ protected:UnsignedInt m_chordStartMs; ///< millisecond the chord was armed on, for CHORD_TIMEOUT_MSDrawableID m_chordDrawableID; ///< builder the armed chord addresses; the chord dies if the bar moves to another oneDrawableID m_standInBuilderID; ///< with nothing selected, the builder whose command bar is shown (INVALID_DRAWABLE_ID otherwise)- Drawable *findStandInBuilder( Bool freeOnly ); ///< the local player's free builder (or, unless freeOnly, any builder) to stand in for an empty selection/** A player upgrade is researched once, so it goes to exactly one of the selected buildings -* and the bar cannot see the queue an earlier click in this same frame just filled, becausediff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.hindex 364c5c54f..3458f9eac 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Drawable.h@@ -712,6 +712,10 @@ private:ModelConditionFlags m_conditionState; ///< The Drawables current behavior stateReal m_lastConstructDisplayed; ///< last construct percent used to make the stringDisplayString* 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 frameDisplayString* m_captionDisplayString; ///< string to display captionDisplayString* m_groupNumber; ///< string to display the group number of this drawable@@ -752,6 +756,8 @@ public: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 buildvoid drawCaption( const IRegion2D *healthBarRegion ); ///< draw captionvoid drawAmmo( const IRegion2D *healthBarRegion ); ///< draw iconsvoid drawContained( const IRegion2D *healthBarRegion ); ///< draw iconsdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 0b908b1c8..d4c0267d5 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -868,6 +868,7 @@ protected:ICoord2D m_placeAnchorStart; ///< place angle anchor startICoord2D m_placeAnchorEnd; ///< place angle anchor endReal m_placeAngleOffset; ///< wheel-chosen heading, added to every structure's own view angle+ const ThingTemplate * m_placeAngleType; ///< the structure that heading was chosen for; another type starts square againBool m_placementLegal; ///< last legality verdict for the spot under the structure being placedCoord3D m_placementNudge; ///< how far the last legality check had to slide the structure to make it fitInt m_selectCount; ///< Number of objects currently "selected"diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AutoDepositUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AutoDepositUpdate.hindex e285907a9..a8ed99118 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AutoDepositUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AutoDepositUpdate.h@@ -122,6 +122,13 @@ public:void awardInitialCaptureBonus( Player *player ); // Test and award the initial capture bonusvirtual UpdateSleepTime update( void );+ /** How far along the wait for the next payout is, 0..1, or negative when this thing is not+ * actually paying anyone (neutral, still under construction, or set to deposit nothing).+ * Only so a bar can be drawn over it - the black market and the oil derricks pay on a clock+ * the player otherwise cannot see. */+ Real getDepositProgress( void ) const;+ UnsignedInt getDepositFramesLeft( void ) const;+protected:Int getUpgradedSupplyBoost() const;diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/HackInternetAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/HackInternetAIUpdate.hindex a9c100b5c..bd5806e4b 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/HackInternetAIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/HackInternetAIUpdate.h@@ -184,6 +184,11 @@ class HackInternetAIInterfacepublic:virtual Bool isHacking() const = 0;virtual Bool isHackingPackingOrUnpacking() const = 0;++ /** How far along the wait for the next payout is, 0..1, or negative when not hacking.+ * HackInternetState keeps the countdown; this is only so a bar can be drawn over it. */+ virtual Real getHackProgress() const = 0;+ virtual void setHackProgress( Real progress ) = 0;};//-------------------------------------------------------------------------------------------------@@ -221,12 +226,16 @@ public:virtual Bool isHacking() const;virtual Bool isHackingPackingOrUnpacking() const;+ virtual Real getHackProgress() const { return m_hackProgress; }+ virtual void setHackProgress( Real progress ) { m_hackProgress = progress; }+protected:virtual AIStateMachine* makeStateMachine();AICommandParmsStorage m_pendingCommand;Bool m_hasPendingCommand;+ Real m_hackProgress; ///< 0..1 towards the next payout, negative while not hacking};#endifdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.hindex 34ead4176..0bb6c3770 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ProductionUpdate.h@@ -167,6 +167,7 @@ public:virtual void cancelAndRefundAllProduction( void ) = 0;virtual UnsignedInt getProductionCount( void ) const = 0;+ virtual UnsignedInt getMaxQueueEntries( void ) const = 0;virtual const ProductionEntry *firstProduction( void ) const = 0;virtual const ProductionEntry *nextProduction( const ProductionEntry *p ) const = 0;@@ -223,6 +224,7 @@ public:virtual void cancelAndRefundAllProduction( void ); ///< cancel and refund anything in the production queuevirtual UnsignedInt getProductionCount( void ) const { return m_productionCount; } ///< return # of things in the production queue+ virtual UnsignedInt getMaxQueueEntries( void ) const { return getProductionUpdateModuleData()->m_maxQueueEntries; } ///< how deep the queue may go (INI MaxQueueEntries)// walking the production list from outsidevirtual const ProductionEntry *firstProduction( void ) const { return m_productionQueue; }diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.hindex 7e088a049..045eb61ac 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyTruckAIUpdate.h@@ -34,6 +34,20 @@#include "Common/StateMachine.h"#include "GameLogic/Module/AIUpdate.h"+//-------------------------------------------------------------------------------------------------+/** How far through a dock action (fetching or handing over one box) frame 'now' is, given the+ * window the dock state announced. Negative outside the window - which is also what a docker+ * that is not docked reads, since nothing but the dock state ever moves the window. Shared by+ * SupplyTruckAIUpdate and WorkerAIUpdate, which implement the same interface side by side. */+//-------------------------------------------------------------------------------------------------+inline Real dockActionProgress( UnsignedInt now, UnsignedInt start, UnsignedInt end )+{+ if( end <= start || now >= end || now < start )+ return -1.0f;++ return INT_TO_REAL( now - start ) / INT_TO_REAL( end - start );+}+//-------------------------------------------------------------------------------------------------class SupplyTruckStateMachine : public StateMachine{@@ -180,6 +194,11 @@ public:virtual ObjectID getPreferredDockID() const = 0;virtual UnsignedInt getActionDelayForDock( Object *dock ) = 0;virtual Int getUpgradedSupplyBoost() const = 0;++ /** The dock state announces how long the box it is working on takes; that window is what the+ * progress bar over the worker's head fills across. (See AIDockProcessDockState.) */+ virtual void noteDockActionWindow( UnsignedInt frames ) = 0;+ virtual Real getDockActionProgress() const = 0; ///< 0..1 while loading or unloading, negative otherwise};//-------------------------------------------------------------------------------------------------@@ -218,6 +237,9 @@ public:virtual ObjectID getPreferredDockID() const { return m_preferredDock; }virtual UnsignedInt getActionDelayForDock( Object *dock );virtual Int getUpgradedSupplyBoost() const { return 0; }++ virtual void noteDockActionWindow( UnsignedInt frames );+ virtual Real getDockActionProgress() const;virtual UpdateSleepTime update();@@ -228,6 +250,8 @@ protected:virtual void privateIdle(CommandSourceType cmdSource); ///< Enter idle state.private:+ UnsignedInt m_dockActionStartFrame; ///< when the box currently being moved started+ UnsignedInt m_dockActionEndFrame; ///< and when it lands; equal means "not docking"SupplyTruckStateMachine* m_supplyTruckStateMachine;ObjectID m_preferredDock; ///< Instead of searching, try this one firstInt m_numberBoxes;diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyWarehouseDockUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyWarehouseDockUpdate.hindex ad8143aa7..3968fe159 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyWarehouseDockUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyWarehouseDockUpdate.h@@ -68,6 +68,7 @@ public:virtual Bool action( Object* docker, Object *drone = NULL ); ///<For me, this means identifying who is docking and either taking Boxes away or giving themInt getBoxesStored() const { return m_boxesStored; }+ virtual Int getSupplyCashValue( void ) const;void setCashValue( Int cashValue );diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpdateModule.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpdateModule.hindex 21b6e2085..59c219feb 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpdateModule.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpdateModule.h@@ -275,6 +275,11 @@ public:class DockUpdateInterface{public:+ /** What this dock is still holding, in cash, or -1 when it is not a supply source at all.+ * Supply piles and docks keep boxes; everything else that can be docked with (refineries,+ * repair pads, prisons) has nothing to report. */+ virtual Int getSupplyCashValue( void ) const { return -1; }+/** Returns true if it is okay for the docker to approach and prepare to dock.False could mean the queue is full, for example.*/diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.hindex 1297daa29..6544ab2b2 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/WorkerAIUpdate.h@@ -215,6 +215,9 @@ public:virtual Int getUpgradedSupplyBoost() const;+ virtual void noteDockActionWindow( UnsignedInt frames );+ virtual Real getDockActionProgress() const;+protected:// Dozer data@@ -241,6 +244,9 @@ protected:// Supply Truck dataInt m_numberBoxes;+ UnsignedInt m_dockActionStartFrame; ///< when the box currently being moved started+ UnsignedInt m_dockActionEndFrame; ///< and when it lands; equal means "not docking"+ObjectID m_preferredDock; ///< Instead of searching, try this one firstObjectID m_dockBeforeBuilding; ///< the dock we left to go build, so we can go back (WorkersReturnToSupply)Bool m_forcePending; // To prevent a function from doing a setState, forceWanting will latch into here until serviced.diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cppindex 116baacc1..6e82753fd 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp@@ -62,6 +62,9 @@#include "GameLogic/Module/ContainModule.h"#include "GameLogic/Module/PhysicsUpdate.h"#include "GameLogic/Module/ProductionUpdate.h"+#include "GameLogic/Module/AutoDepositUpdate.h"+#include "GameLogic/Module/HackInternetAIUpdate.h"+#include "GameLogic/Module/SupplyTruckAIUpdate.h"#include "Common/Upgrade.h"#include "GameLogic/Module/StealthUpdate.h"#include "GameLogic/Module/StickyBombUpdate.h"@@ -415,6 +418,10 @@ Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatus statusBitm_expirationDate = 0; // 0 == never expiresm_lastConstructDisplayed = -1.0f;+ m_supplyCashDisplayString = NULL;+ m_lastSupplyCashDisplayed = -1;+ m_costDisplayString = NULL;+ m_lastCostDisplayed = -1;//Added By Sadullah Nader//Fix for the building percent@@ -575,6 +582,14 @@ Drawable::~Drawable()TheDisplayStringManager->freeDisplayString( m_constructDisplayString );m_constructDisplayString = NULL;+ if( m_supplyCashDisplayString )+ 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;@@ -2861,6 +2876,8 @@ 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...@@ -3858,6 +3875,120 @@ void Drawable::drawConstructPercent( const IRegion2D *healthBarRegion )} // end drawConstructPercent+//-------------------------------------------------------------------------------------------------+/** How much money is still in a supply pile, written over it. The piles were readable only as+ * art - a full one and a nearly-empty one differ by a few boxes on the model - so deciding which+ * one to send workers to, or whether an expansion is worth taking, meant guessing. Written as+ * cash rather than as boxes because cash is the number the decision is actually about. */+//-------------------------------------------------------------------------------------------------+void Drawable::drawSupplyCash( const IRegion2D *healthBarRegion )+{+ Object *obj = getObject();+ DockUpdateInterface *dock = obj ? obj->getDockUpdateInterface() : NULL;+ Int cash = dock ? dock->getSupplyCashValue() : -1;++ if( cash <= 0 )+ {+ // not a supply source, or picked clean - drop the string rather than leave "$0" behind+ if( m_supplyCashDisplayString )+ {+ TheDisplayStringManager->freeDisplayString( m_supplyCashDisplayString );+ m_supplyCashDisplayString = NULL;+ m_lastSupplyCashDisplayed = -1;+ }+ 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;++ if( m_supplyCashDisplayString == NULL )+ {+ m_supplyCashDisplayString = TheDisplayStringManager->newDisplayString();+ m_supplyCashDisplayString->setFont( TheFontLibrary->getFont( TheInGameUI->getDrawableCaptionFontName(),+ TheGlobalLanguageData->adjustFontSize( TheInGameUI->getDrawableCaptionPointSize() ),+ TheInGameUI->isDrawableCaptionBold() ) );+ }++ if( m_lastSupplyCashDisplayed != cash )+ {+ UnicodeString buffer;+ buffer.format( L"$%d", cash );+ m_supplyCashDisplayString->setText( buffer );+ m_lastSupplyCashDisplayed = cash;+ }++ Coord3D pos;+ obj->getHealthBoxPosition( pos );+ ICoord2D screen;+ if( !TheTacticalView->worldToScreen( &pos, &screen ) )+ return;++ Int width, height;+ m_supplyCashDisplayString->getSize( &width, &height );+ screen.x -= width / 2;+ screen.y -= height;++ m_supplyCashDisplayString->draw( screen.x, screen.y,+ GameMakeColor( 90, 220, 90, 255 ),+ GameMakeColor( 0, 0, 0, 255 ) );++} // 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 */@@ -4114,9 +4245,97 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)TheDisplay->drawFillRect( healthBarRegion->lo.x, healthBarRegion->lo.y - 2, healthBoxWidth + 1, 1,GameMakeColor( 255, 255, 255, 255 ) );+ // bars stack upwards from just above the health bar, each clearing the seconds written over+ // the one below it+ Int stackY = healthBarRegion->lo.y - 3;++ // 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;+ if( pe )+ {+ Int prodY = stackY - healthBoxHeight;+ // the entry keeps counting past 100% while the finished unit waits for a free exit door, so clamp+ Real pct = pe->getPercentComplete();+ if( pct > 100.0f )+ pct = 100.0f;+ else if( pct < 0.0f )+ pct = 0.0f;+ TheDisplay->drawOpenRect( healthBarRegion->lo.x, prodY, healthBoxWidth, healthBoxHeight,+ healthBoxOutlineSize, GameMakeColor( 128, 128, 0, 255 ) );+ TheDisplay->drawFillRect( healthBarRegion->lo.x + 1, prodY + 1,+ (healthBoxWidth - 2) * pct * 0.01f, healthBoxHeight - 2,+ GameMakeColor( 255, 255, 0, 255 ) );++ Player *player = obj->getControllingPlayer();+ Int totalFrames = pe->getProductionType() == PRODUCTION_UNIT+ ? pe->getProductionObject()->calcTimeToBuild( player )+ : pe->getProductionUpgrade()->calcTimeToBuild( player );+ // real seconds: the logic runs at the game-speed rate, not at a fixed 30 frames a second+ Int logicFps = TheGameEngine ? TheGameEngine->getFramesPerSecondLimit() : 0;+ if( logicFps <= 0 )+ logicFps = LOGICFRAMES_PER_SECOND;+ Int secondsLeft = REAL_TO_INT_CEIL( totalFrames * (1.0f - pct * 0.01f) / logicFps );++ // everything behind the head of the queue has not started yet, so each costs its full+ // build time (an entry builds its whole quantity at once, so quantity does not scale it)+ Int queuedFrames = 0;+ for( const ProductionEntry *q = pu->nextProduction( pe ); q != NULL; q = pu->nextProduction( q ) )+ queuedFrames += q->getProductionType() == PRODUCTION_UNIT+ ? q->getProductionObject()->calcTimeToBuild( player )+ : q->getProductionUpgrade()->calcTimeToBuild( player );++ // one shared string: draw() renders immediately, and the manager lives for the whole app+ static DisplayString *prodTimeString = NULL;+ if( prodTimeString == NULL )+ {+ prodTimeString = TheDisplayStringManager->newDisplayString();+ prodTimeString->setFont( TheFontLibrary->getFont( TheInGameUI->getDrawableCaptionFontName(),+ TheGlobalLanguageData->adjustFontSize( TheInGameUI->getDrawableCaptionPointSize() - 2 ),+ FALSE ) );+ }+ // "52s (70s)": this one, then the whole queue. Nothing behind it, no parentheses.+ UnicodeString text;+ if( queuedFrames > 0 )+ text.format( L"%ds (%ds)", secondsLeft,+ secondsLeft + REAL_TO_INT_CEIL( INT_TO_REAL( queuedFrames ) / logicFps ) );+ else+ text.format( L"%ds", secondsLeft );+ if( prodTimeString->getText().compare( text ) != 0 )+ prodTimeString->setText( text );+ Int textW, textH;+ prodTimeString->getSize( &textW, &textH );+ prodTimeString->draw( healthBarRegion->lo.x, prodY - textH,+ GameMakeColor( 255, 255, 255, 255 ), GameMakeColor( 0, 0, 0, 255 ) );++ // whatever comes next goes above the seconds, not through them+ stackY = prodY - textH - 1;++ // how many entries the queue holds, right-aligned on the bar (one is not worth saying)+ if( pu->getProductionCount() > 1 )+ {+ static DisplayString *prodCountString = NULL;+ if( prodCountString == NULL )+ {+ prodCountString = TheDisplayStringManager->newDisplayString();+ prodCountString->setFont( prodTimeString->getFont() );+ }+ UnicodeString countText;+ countText.format( L"x%d", pu->getProductionCount() );+ if( prodCountString->getText().compare( countText ) != 0 )+ prodCountString->setText( countText );+ Int countW, countH;+ prodCountString->getSize( &countW, &countH );+ prodCountString->draw( healthBarRegion->hi.x - countW, prodY - countH,+ GameMakeColor( 255, 255, 255, 255 ), GameMakeColor( 0, 0, 0, 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 -+ // same yellow bar the production queue uses - stacked above it rather than on top of it,+ // which is what a Chinese nuclear silo researching an upgrade while its missile charges used+ // to draw: two bars and two countdowns in the same row of pixels. Only powers that carry a public timer count -// that is the flag the superweapon list in the corner goes by.//// A power only counts while it is really counting down towards something the player can@@ -4190,9 +4409,52 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)}}+ //+ // Nothing charging? Then show what the thing is doing for a living instead: a worker+ // fetching or handing over a box of supplies, a hacker waiting out the delay before the+ // next payout, a black market or oil derrick on its deposit clock. All three of those+ // are money arriving on a timer that the player had no way at all to see - the cash just+ // appeared - and the worker one doubles as "yes, it really is working".+ //+ // No seconds are written over these: chargeFramesLeft is left at zero on purpose, the+ // bar is the whole message.+ //+ if( chargePct < 0.0f )+ {+ Real workPct = -1.0f;++ AIUpdateInterface *ai = obj->getAIUpdateInterface();+ if( ai != NULL )+ {+ SupplyTruckAIInterface *supply = ai->getSupplyTruckAIInterface();+ if( supply != NULL )+ workPct = supply->getDockActionProgress();++ if( workPct < 0.0f )+ {+ HackInternetAIInterface *hack = ai->getHackInternetAIInterface();+ if( hack != NULL )+ workPct = hack->getHackProgress();+ }+ }++ if( workPct < 0.0f )+ {+ static const NameKeyType key_autoDeposit = NAMEKEY( "AutoDepositUpdate" );+ AutoDepositUpdate *deposit = (AutoDepositUpdate*)obj->findUpdateModule( key_autoDeposit );+ if( deposit != NULL )+ workPct = deposit->getDepositProgress();+ }++ if( workPct > 1.0f )+ workPct = 1.0f;+ if( workPct >= 0.0f )+ chargePct = workPct * 100.0f;+ }+if( chargePct >= 0.0f ){- Int chargeY = healthBarRegion->lo.y - 3 - healthBoxHeight;+ Int chargeY = stackY - healthBoxHeight;TheDisplay->drawOpenRect( healthBarRegion->lo.x, chargeY, healthBoxWidth, healthBoxHeight,healthBoxOutlineSize, GameMakeColor( 128, 128, 0, 255 ) );TheDisplay->drawFillRect( healthBarRegion->lo.x + 1, chargeY + 1,@@ -4235,84 +4497,6 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)}}- // 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;- if( pe )- {- Int prodY = healthBarRegion->lo.y - 3 - healthBoxHeight;- // the entry keeps counting past 100% while the finished unit waits for a free exit door, so clamp- Real pct = pe->getPercentComplete();- if( pct > 100.0f )- pct = 100.0f;- else if( pct < 0.0f )- pct = 0.0f;- TheDisplay->drawOpenRect( healthBarRegion->lo.x, prodY, healthBoxWidth, healthBoxHeight,- healthBoxOutlineSize, GameMakeColor( 128, 128, 0, 255 ) );- TheDisplay->drawFillRect( healthBarRegion->lo.x + 1, prodY + 1,- (healthBoxWidth - 2) * pct * 0.01f, healthBoxHeight - 2,- GameMakeColor( 255, 255, 0, 255 ) );-- Player *player = obj->getControllingPlayer();- Int totalFrames = pe->getProductionType() == PRODUCTION_UNIT- ? pe->getProductionObject()->calcTimeToBuild( player )- : pe->getProductionUpgrade()->calcTimeToBuild( player );- // real seconds: the logic runs at the game-speed rate, not at a fixed 30 frames a second- Int logicFps = TheGameEngine ? TheGameEngine->getFramesPerSecondLimit() : 0;- if( logicFps <= 0 )- logicFps = LOGICFRAMES_PER_SECOND;- Int secondsLeft = REAL_TO_INT_CEIL( totalFrames * (1.0f - pct * 0.01f) / logicFps );-- // everything behind the head of the queue has not started yet, so each costs its full- // build time (an entry builds its whole quantity at once, so quantity does not scale it)- Int queuedFrames = 0;- for( const ProductionEntry *q = pu->nextProduction( pe ); q != NULL; q = pu->nextProduction( q ) )- queuedFrames += q->getProductionType() == PRODUCTION_UNIT- ? q->getProductionObject()->calcTimeToBuild( player )- : q->getProductionUpgrade()->calcTimeToBuild( player );-- // one shared string: draw() renders immediately, and the manager lives for the whole app- static DisplayString *prodTimeString = NULL;- if( prodTimeString == NULL )- {- prodTimeString = TheDisplayStringManager->newDisplayString();- prodTimeString->setFont( TheFontLibrary->getFont( TheInGameUI->getDrawableCaptionFontName(),- TheGlobalLanguageData->adjustFontSize( TheInGameUI->getDrawableCaptionPointSize() - 2 ),- FALSE ) );- }- // "52s (70s)": this one, then the whole queue. Nothing behind it, no parentheses.- UnicodeString text;- if( queuedFrames > 0 )- text.format( L"%ds (%ds)", secondsLeft,- secondsLeft + REAL_TO_INT_CEIL( INT_TO_REAL( queuedFrames ) / logicFps ) );- else- text.format( L"%ds", secondsLeft );- if( prodTimeString->getText().compare( text ) != 0 )- prodTimeString->setText( text );- Int textW, textH;- prodTimeString->getSize( &textW, &textH );- prodTimeString->draw( healthBarRegion->lo.x, prodY - textH,- GameMakeColor( 255, 255, 255, 255 ), GameMakeColor( 0, 0, 0, 255 ) );-- // how many entries the queue holds, right-aligned on the bar (one is not worth saying)- if( pu->getProductionCount() > 1 )- {- static DisplayString *prodCountString = NULL;- if( prodCountString == NULL )- {- prodCountString = TheDisplayStringManager->newDisplayString();- prodCountString->setFont( prodTimeString->getFont() );- }- UnicodeString countText;- countText.format( L"x%d", pu->getProductionCount() );- if( prodCountString->getText().compare( countText ) != 0 )- prodCountString->setText( countText );- Int countW, countH;- prodCountString->getSize( &countW, &countH );- prodCountString->draw( healthBarRegion->hi.x - countW, prodY - countH,- GameMakeColor( 255, 255, 255, 255 ), GameMakeColor( 0, 0, 0, 255 ) );- }- }} // end if} // end drawHealthBardiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cppindex d3613540b..db7bd3a99 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp@@ -1258,10 +1258,15 @@ CommandAvailability ControlBar::getCommandAvailability( const CommandButton *comreturn COMMAND_RESTRICTED;}- // >=, not ==: the production queue is far deeper than the number of buttons and a shift-click- // queues several at once, so an exact-equality test greyed the button out at exactly- // MAX_BUILD_QUEUE_BUTTONS and then stopped firing once the count stepped past it.- Bool queueMaxed = pu ? ( pu->getProductionCount() >= MAX_BUILD_QUEUE_BUTTONS ) : FALSE;+ //+ // The cap is the queue's own depth (INI MaxQueueEntries, 100 by default here), not the number+ // of buttons the build-queue strip happens to have room for - those nine buttons are a display+ // limit and were greying every build button out at nine units.+ //+ // >=, not ==: a shift-click queues several at once, so an exact-equality test stopped firing+ // once the count stepped past the cap.+ //+ Bool queueMaxed = pu ? ( pu->getProductionCount() >= pu->getMaxQueueEntries() ) : FALSE;switch( command->getCommandType() ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cppindex cbc723792..d87438856 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarPopupDescription.cpp@@ -383,7 +383,7 @@ void ControlBar::populateBuildTooltipLayout( const CommandButton *commandButton,commandButton->getCommandType() == GUI_COMMAND_OBJECT_UPGRADE ){ProductionUpdateInterface *pui = selectedObject->getProductionUpdateInterface();- if( pui && pui->getProductionCount() == MAX_BUILD_QUEUE_BUTTONS )+ if( pui && pui->getProductionCount() >= pui->getMaxQueueEntries() ){descrip.concat( L"\n\n" );descrip.concat( TheGameText->fetch( "TOOLTIP:TooltipCannotPurchaseBecauseQueueFull" ) );diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex cf89a71cf..f2a37b07e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -1036,6 +1036,7 @@ InGameUI::InGameUI()m_placeAnchorEnd.x = m_placeAnchorEnd.y = 0;m_placeAnchorInProgress = FALSE;m_placeAngleOffset = 0.0f;+ m_placeAngleType = NULL;m_placementLegal = TRUE;m_placementNudge.zero();@@ -2251,6 +2252,7 @@ void InGameUI::reset( void )// remove any build available statusplaceBuildAvailable( NULL, NULL );m_placeAngleOffset = 0.0f;+ m_placeAngleType = NULL;// free any message resources allocatedfreeMessageResources();@@ -3345,6 +3347,19 @@ void InGameUI::placeBuildAvailable( const ThingTemplate *build, Drawable *buildDif( m_pendingPlaceType != NULL && build != NULL )placeBuildAvailable( NULL, NULL );+ //+ // The wheeled/dragged heading is carried from one placement to the next so a row of walls or+ // bunkers goes down facing the same way. It belongs to that one structure though: turning a+ // bunker used to leave every later building - a supply centre, a war factory - wearing the same+ // offset off its own designed view angle, which reads as the building coming out backwards. A+ // different type starts square again.+ //+ if( build != NULL && build != m_placeAngleType )+ {+ m_placeAngleOffset = 0.0f;+ m_placeAngleType = build;+ }+//// keep a record of what we are trying to place, if we are already trying to// place something, it is overwrittendiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cppindex b93e98a30..fe0153a3d 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp@@ -88,6 +88,24 @@ static Bool getPlacementDrag( ICoord2D *start, ICoord2D *end )} // end getPlacementDrag+//-------------------------------------------------------------------------------------------------+/** The object that is to do the building. Normally the one the placement was started from, but+ * with nothing selected the command bar is being driven by a stand-in builder that is not part of+ * any selection - and that one is free to die, finish its job or be replaced between two clicks of+ * a shift-held run of structures. When it is gone, ask the command bar for the current stand-in+ * rather than dropping out of placement mode: the logic picks the idle builder nearest the site+ * anyway (MSG_DOZER_CONSTRUCT), so any builder will do to keep the ghost on the cursor. */+//-------------------------------------------------------------------------------------------------+static Object *resolvePlacementBuilder( void )+{+ Object *builder = TheGameLogic->findObjectByID( TheInGameUI->getPendingPlaceSourceObjectID() );+ if( builder != NULL && !builder->isEffectivelyDead() )+ return builder;++ Drawable *standIn = TheControlBar ? TheControlBar->findStandInBuilder( FALSE ) : NULL;+ return standIn ? standIn->getObject() : NULL;+}+//-------------------------------------------------------------------------------------------------PlaceEventTranslator::PlaceEventTranslator() : m_frameOfUpButton(-1), m_stripClickTaken(FALSE){@@ -154,9 +172,9 @@ GameMessageDisposition PlaceEventTranslator::translateGameMessage(const GameMess// placing things causes a dozer to go over and build it ... get the dozer in question// from the in game UI//- Object *builderObject = TheGameLogic->findObjectByID( TheInGameUI->getPendingPlaceSourceObjectID() );+ Object *builderObject = resolvePlacementBuilder();- // if our source object is gone cancel this whole placement process+ // if there is no builder left at all, cancel this whole placement processif( builderObject == NULL ){@@ -266,7 +284,7 @@ GameMessageDisposition PlaceEventTranslator::translateGameMessage(const GameMess// get the source object ID of the thing that is "building" the objectObjectID builderID = INVALID_ID;- Object *builderObj = TheGameLogic->findObjectByID( TheInGameUI->getPendingPlaceSourceObjectID() );+ Object *builderObj = resolvePlacementBuilder();if( builderObj )builderID = builderObj->getID();@@ -392,10 +410,18 @@ GameMessageDisposition PlaceEventTranslator::translateGameMessage(const GameMesspickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), placeMsg->getType() );+ //// get out of pending placement mode, this will also clear the arrow anchor status -- // unless shift is held, which keeps placing the same structure until released- if( TheKeyboard && TheKeyboard->isShift() && builderObj && builderObj->getDrawable() )- TheInGameUI->placeBuildAvailable( build, builderObj->getDrawable() );+ // unless shift is held, which keeps placing the same structure until released.+ // The builder it re-arms on is whatever resolvePlacementBuilder found, so a run of+ // structures placed with nothing selected carries on across the stand-in builder+ // going off to build the one just ordered.+ //+ Drawable *nextBuilder = builderObj ? builderObj->getDrawable() : NULL;+ if( TheKeyboard && TheKeyboard->isShift() && nextBuilder == NULL && TheControlBar )+ nextBuilder = TheControlBar->findStandInBuilder( FALSE );+ if( TheKeyboard && TheKeyboard->isShift() && nextBuilder )+ TheInGameUI->placeBuildAvailable( build, nextBuilder );elseTheInGameUI->placeBuildAvailable( NULL, NULL );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cppindex 9806b88eb..3f1a37b10 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp@@ -578,7 +578,10 @@ void AIDockProcessDockState::setNextDockActionFrame()SupplyTruckAIInterface *supplyTruck = getMachineOwner()->getAI()->getSupplyTruckAIInterface();if( supplyTruck ){- m_nextDockActionFrame = TheGameLogic->getFrame() + supplyTruck->getActionDelayForDock( getMachineGoalObject() );+ UnsignedInt delay = supplyTruck->getActionDelayForDock( getMachineGoalObject() );+ m_nextDockActionFrame = TheGameLogic->getFrame() + delay;+ // ... and let the docker publish that window, so a bar can fill over it while it works+ supplyTruck->noteDockActionWindow( delay );return;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cppindex 1d255d15f..46ab63934 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp@@ -1578,8 +1578,23 @@ void AIGroup::groupMoveToPosition( const Coord3D *p_posIn, Bool addWaypoint, ComisFormation = false;}+ //+ // A player's move order means "everybody go there", and with a big selection the group+ // machinery was answering a different question. friend_moveInfantryToPos walks the group down+ // one shared path in three or five columns, and computeIndividualDestination keeps each+ // member's offset from the group centroid (normalized to a fixed radius, so a wide selection+ // lands strung out on an arc): two hundred units asked to attack-move drew a line instead of+ // arriving, and with three hundred most of them never got a workable goal cell at all.+ //+ // So the point itself is the goal for every member, and each unit's own move state takes the+ // nearest free cell to it (Pathfinder::adjustDestination spirals out from there, reserving as+ // it goes, and the orders are issued nearest-first). They pile onto the spot instead of+ // holding a shape. Explicit formations - the ones the player asked for by name - still keep+ // theirs, and the AI still moves its teams the old way.+ //+ const Bool gatherOnPoint = ( cmdSource == CMD_FROM_PLAYER && !isFormation );- if (!addWaypoint && !isFormation) {+ if (!addWaypoint && !isFormation && !gatherOnPoint) {friend_computeGroundPath(pos, cmdSource);didInfantry = friend_moveInfantryToPos(pos, cmdSource);didVehicles = friend_moveVehicleToPos(pos, cmdSource);@@ -1588,7 +1603,7 @@ void AIGroup::groupMoveToPosition( const Coord3D *p_posIn, Bool addWaypoint, Comrecompute();std::list<Object *>::iterator i;- if( !isFormation && cmdSource == CMD_FROM_PLAYER && TheGlobalData->m_groupMoveClickToGatherFactor > 0.0f )+ if( !isFormation && !gatherOnPoint && cmdSource == CMD_FROM_PLAYER && TheGlobalData->m_groupMoveClickToGatherFactor > 0.0f ){ScaleRect2D( &min, &max, TheGlobalData->m_groupMoveClickToGatherFactor );@@ -1723,7 +1738,10 @@ void AIGroup::groupMoveToPosition( const Coord3D *p_posIn, Bool addWaypoint, Com}firstUnit = false;}- computeIndividualDestination( &dest, &goalPos, theUnit, ¢er, isFormation );+ if (gatherOnPoint)+ dest = goalPos; // the clicked spot; the move state finds the nearest free cell to it+ else+ computeIndividualDestination( &dest, &goalPos, theUnit, ¢er, isFormation );if( cmdSource == CMD_FROM_PLAYER && theUnit->getStatusBits().test( OBJECT_STATUS_CAN_STEALTH ) && ai->canAutoAcquire() ){@@ -2348,8 +2366,17 @@ void AIGroup::groupAttackMoveToPosition( const Coord3D *pos, Int maxShotsToFire,firstUnit = false;}+ //+ // As with a plain move (see groupMoveToPosition): a player's attack move sends everyone to+ // the point and lets each unit take the nearest free cell to it, rather than holding the+ // selection's shape on the way in - which a large group could only do by spreading along+ // an arc.+ //Coord3D dest;- computeIndividualDestination( &dest, &goalPos, theUnit, ¢er, FALSE );+ if (cmdSource == CMD_FROM_PLAYER)+ dest = goalPos;+ else+ computeIndividualDestination( &dest, &goalPos, theUnit, ¢er, FALSE );// the speed of the slowest member is picked up by AIAttackMoveToState::onEnter, which runs// inside this order - the move state resets the desired speed, so it cannot be set here.diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cppindex f98c48292..3bbef3106 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp@@ -62,6 +62,7 @@ AIStateMachine* HackInternetAIUpdate::makeStateMachine()HackInternetAIUpdate::HackInternetAIUpdate( Thing *thing, const ModuleData* moduleData ) : AIUpdateInterface( thing, moduleData ){m_hasPendingCommand = false;+ m_hackProgress = -1.0f;}//-------------------------------------------------------------------------------------------------@@ -461,6 +462,7 @@ StateReturnType HackInternetState::onEnter()MAKE_MODELCONDITION_MASK( MODELCONDITION_FIRING_A ) );m_framesRemaining = ai->getCashUpdateDelay();+ ai->setHackProgress( 0.0f );return STATE_CONTINUE;}@@ -481,6 +483,17 @@ StateReturnType HackInternetState::update()return STATE_CONTINUE;}+ //+ // Where the next payout has got to, so a bar can fill over the hacker's head (see+ // Drawable::drawHealthBar). The delay is the only clock the player has on this and it was+ // entirely invisible - a hacker either dropped cash or looked idle.+ //+ {+ UnsignedInt full = ai->getCashUpdateDelay();+ ai->setHackProgress( full > 0 ? 1.0f - INT_TO_REAL( m_framesRemaining ) / INT_TO_REAL( full )+ : -1.0f );+ }+if( m_framesRemaining > 0 ){//Decrement frame counter.@@ -602,4 +615,9 @@ void HackInternetState::onExit( StateExitType status ){Object *owner = getMachineOwner();owner->clearModelConditionState( MODELCONDITION_FIRING_A );++ // packed up: no payout is on the way, so take the bar down with the animation+ HackInternetAIUpdate *ai = (HackInternetAIUpdate*)owner->getAIUpdateInterface();+ if( ai )+ ai->setHackProgress( -1.0f );}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cppindex 1657deb13..f8fe4ed0c 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/SupplyTruckAIUpdate.cpp@@ -31,6 +31,7 @@#include "Common/Player.h"#include "Common/ResourceGatheringManager.h"#include "Common/ThingTemplate.h"+#include "GameLogic/GameLogic.h"#include "GameLogic/Object.h"#include "GameLogic/PartitionManager.h"#include "GameLogic/Module/SupplyTruckAIUpdate.h"@@ -84,6 +85,8 @@ SupplyTruckAIUpdate::SupplyTruckAIUpdate( Thing *thing, const ModuleData* modulem_numberBoxes = 0;m_forcePending = FALSE;m_forcedBusyPending = FALSE;+ m_dockActionStartFrame = 0;+ m_dockActionEndFrame = 0;m_supplyTruckStateMachine = newInstance(SupplyTruckStateMachine)( getObject() );m_supplyTruckStateMachine->initDefaultState();@@ -238,6 +241,23 @@ UnsignedInt SupplyTruckAIUpdate::getActionDelayForDock( Object *dock )return 0;}+//----------------------------------------------------------------------------------------+void SupplyTruckAIUpdate::noteDockActionWindow( UnsignedInt frames )+{+ m_dockActionStartFrame = TheGameLogic->getFrame();+ m_dockActionEndFrame = m_dockActionStartFrame + frames;+}++//----------------------------------------------------------------------------------------+/** How far through fetching or handing over the current box we are, for the bar drawn over the+ * worker's head. Negative once the window has run out, which is also what a worker that is not+ * docked reads: nothing refreshes the window but the dock state. */+//----------------------------------------------------------------------------------------+Real SupplyTruckAIUpdate::getDockActionProgress() const+{+ return dockActionProgress( TheGameLogic->getFrame(), m_dockActionStartFrame, m_dockActionEndFrame );+}+//-------------------------------------------------------------------------------------------------//-------------------------------------------------------------------------------------------------Real SupplyTruckAIUpdate::getWarehouseScanDistance() constdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cppindex 3601512aa..52d9b01ba 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/WorkerAIUpdate.cpp@@ -119,6 +119,8 @@ WorkerAIUpdate::WorkerAIUpdate( Thing *thing, const ModuleData* moduleData ) :m_dockBeforeBuilding = INVALID_ID;m_forcePending = FALSE;m_forcedBusyPending = FALSE;+ m_dockActionStartFrame = 0;+ m_dockActionEndFrame = 0;m_workerMachine = NULL;@@ -237,6 +239,23 @@ UnsignedInt WorkerAIUpdate::getActionDelayForDock( Object *dock )return 0;}+//----------------------------------------------------------------------------------------+void WorkerAIUpdate::noteDockActionWindow( UnsignedInt frames )+{+ m_dockActionStartFrame = TheGameLogic->getFrame();+ m_dockActionEndFrame = m_dockActionStartFrame + frames;+}++//----------------------------------------------------------------------------------------+/** How far through fetching or handing over the current box we are, for the bar drawn over the+ * worker's head. Negative once the window has run out, which is also what a worker that is not+ * docked reads: nothing refreshes the window but the dock state. */+//----------------------------------------------------------------------------------------+Real WorkerAIUpdate::getDockActionProgress() const+{+ return dockActionProgress( TheGameLogic->getFrame(), m_dockActionStartFrame, m_dockActionEndFrame );+}+//-------------------------------------------------------------------------------------------------//-------------------------------------------------------------------------------------------------Real WorkerAIUpdate::getWarehouseScanDistance() constdiff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cppindex d6896ce2f..883a6873b 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp@@ -141,6 +141,40 @@ void AutoDepositUpdate::awardInitialCaptureBonus( Player *player )m_awardInitialCaptureBonus = FALSE;}+//-------------------------------------------------------------------------------------------------+//-------------------------------------------------------------------------------------------------+UnsignedInt AutoDepositUpdate::getDepositFramesLeft( void ) const+{+ const AutoDepositUpdateModuleData *modData = getAutoDepositUpdateModuleData();+ UnsignedInt now = TheGameLogic->getFrame();++ if( modData->m_depositFrame == 0 || modData->m_depositAmount <= 0 )+ return 0;+ if( getObject()->isNeutralControlled() )+ return 0;+ if( getObject()->getConstructionPercent() != CONSTRUCTION_COMPLETE )+ return 0;+ if( m_depositOnFrame <= now )+ return 0;++ return m_depositOnFrame - now;+}++//-------------------------------------------------------------------------------------------------+//-------------------------------------------------------------------------------------------------+Real AutoDepositUpdate::getDepositProgress( void ) const+{+ UnsignedInt left = getDepositFramesLeft();+ if( left == 0 )+ return -1.0f;++ const UnsignedInt full = getAutoDepositUpdateModuleData()->m_depositFrame;+ if( left > full )+ return -1.0f;++ return 1.0f - INT_TO_REAL( left ) / INT_TO_REAL( full );+}+//-------------------------------------------------------------------------------------------------//-------------------------------------------------------------------------------------------------UpdateSleepTime AutoDepositUpdate::update( void )diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cppindex 40989f29d..ccfcd5b8c 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyWarehouseDockUpdate.cpp@@ -175,6 +175,11 @@ void SupplyWarehouseDockUpdate::setDockCrippled( Bool setting )DockUpdate::setDockCrippled( setting );}+Int SupplyWarehouseDockUpdate::getSupplyCashValue( void ) const+{+ return m_boxesStored * TheGlobalData->m_baseValuePerSupplyBox;+}+void SupplyWarehouseDockUpdate::setCashValue( Int cashValue ){// A script can tell us our set value, and we need to figure out the boxes needed to provide that.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cppindex 4a65f711e..defd0dff7 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp@@ -608,7 +608,7 @@ void W3DInGameUI::drawBuildGrid( void )return;// how many cells each way around the cursor we light up- enum { GRID_RADIUS = 14 };+ enum { GRID_RADIUS = 28 };enum { GRID_CELLS = GRID_RADIUS * 2 + 1, GRID_POINTS = GRID_CELLS + 1 };// half the width of a painted line, in world units - a cell is PLACEMENT_CELL (10) across@@ -621,10 +621,13 @@ void W3DInGameUI::drawBuildGrid( void )const Int cellX = REAL_TO_INT_FLOOR( (center->x + 0.5f) / PATHFIND_CELL_SIZE_F ) - GRID_RADIUS;const Int cellY = REAL_TO_INT_FLOOR( (center->y + 0.5f) / PATHFIND_CELL_SIZE_F ) - GRID_RADIUS;- // sample the terrain once per grid corner, rather than once per quad corner+ // sample the terrain once per grid corner, rather than once per quad corner. Static, not+ // automatic: at this radius the two square tables are ~27k together, which is more than a+ // render-path stack frame should be carrying (the quad batch below is static for the same+ // reason).Real gx[ GRID_POINTS ], gy[ GRID_POINTS ];- Real gz[ GRID_POINTS ][ GRID_POINTS ];- Real fade[ GRID_POINTS ][ GRID_POINTS ];+ static Real gz[ GRID_POINTS ][ GRID_POINTS ];+ static Real fade[ GRID_POINTS ][ GRID_POINTS ];Int ix, iy;for( ix = 0; ix < GRID_POINTS; ++ix )diff --git a/GeneralsMD/Code/Libraries/Include/Lib/BaseType.h b/GeneralsMD/Code/Libraries/Include/Lib/BaseType.hindex 49174220b..1df598fec 100644--- a/GeneralsMD/Code/Libraries/Include/Lib/BaseType.h+++ b/GeneralsMD/Code/Libraries/Include/Lib/BaseType.h@@ -224,22 +224,34 @@ __forceinline float fast_float_trunc(float f)return f;}+/* floor and ceil, off the truncation above.+ *+ * EA's versions nudged the value by 0.99999994 (the largest float below one) in the direction they+ * wanted and then truncated. That is exact only while the nudge survives the addition, and it does+ * not: for any f of 2 or more the sum f + 0.99999994 has no representable neighbour that close, so+ * it rounds to f + 1 and the "ceil" of an exact integer came back one too high. ceil(10.0f) was 11.+ *+ * Nobody noticed in the simulation, where the arguments are cell arithmetic on positions that are+ * almost never whole - but every countdown on screen is a whole number of seconds by construction,+ * so the build time over a war factory and the seconds over a structure going up were both a second+ * long.+ *+ * Truncation already rounds toward zero, so the correction is one comparison and no magic constant.+ *+ * Pinned by ceil_and_floor_are_exact_on_whole_numbers in test_gameengine.cpp. */+// same here, fast floor function__forceinline float fast_float_floor(float f){- static unsigned almost1=(126<<23)|0x7fffff;- if (*(unsigned *)&f &0x80000000)- f-=*(float *)&almost1;- return fast_float_trunc(f);+ float t = fast_float_trunc(f);+ return (t > f) ? t - 1.0f : t;}// same here, fast ceil function__forceinline float fast_float_ceil(float f){- static unsigned almost1=(126<<23)|0x7fffff;- if ( (*(unsigned *)&f &0x80000000)==0)- f+=*(float *)&almost1;- return fast_float_trunc(f);+ float t = fast_float_trunc(f);+ return (t < f) ? t + 1.0f : t;}//-------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 607110313..380337908 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -66,6 +66,8 @@#include "GameClient/ParticleSys.h"#include "GameClient/FXList.h"#include "GameClient/ControlBar.h"+#include "GameLogic/Module/ProductionUpdate.h"+#include "GameLogic/Module/SupplyTruckAIUpdate.h"#include "GameClient/InGameUI.h"#include "GameClient/View.h"#include "GameLogic/IncomingDamage.h"@@ -1315,39 +1317,6 @@ TEST(income_is_zero_not_negative_when_nothing_comes_in)CHECK_EQ(computeIncomePerMinute(samples, 4, 4, 2), 0);}-/*- * BaseType.h's fast_float_ceil does not ceil an integer. It adds 0.99999994 and- * truncates, but 0.99999994 is only a sixteenth of a float ULP once the value is past- * 1.0, so the sum rounds up to the next whole float before the truncate ever runs:- * ceil(600) is 601, ceil(1080) is 1081, and so on for every positive whole number.- * Fractions - what it is normally handed - come out right, which is why this has- * survived. Every REAL_TO_INT_CEIL in the codebase inherits it.- *- * Pinned rather than fixed: the sum is in a header every translation unit includes and- * a correcting compare would cost the branch the whole routine exists to avoid, so the- * blast radius of changing it is the entire game. Callers that need an exact edge floor- * and pin it instead - a screen height that ceils to one past the bottom of the screen is- * where this turned up.- */-TEST(realtointceil_DEFECT_overshoots_every_whole_number)-{- CHECK_EQ(REAL_TO_INT_CEIL(1.0f), 2);- CHECK_EQ(REAL_TO_INT_CEIL(600.0f), 601);- CHECK_EQ(REAL_TO_INT_CEIL(768.0f), 769);- CHECK_EQ(REAL_TO_INT_CEIL(1080.0f), 1081);- CHECK_EQ(REAL_TO_INT_CEIL(1920.0f), 1921);-- // zero is the one whole number it gets right - 0.99999994 truncates back to it- CHECK_EQ(REAL_TO_INT_CEIL(0.0f), 0);-- // genuine fractions round up correctly, which is what callers normally feed it- CHECK_EQ(REAL_TO_INT_CEIL(600.5f), 601);- CHECK_EQ(REAL_TO_INT_CEIL(1080.25f), 1081);-- // negatives skip the addition entirely and truncate, which really is ceil- CHECK_EQ(REAL_TO_INT_CEIL(-600.0f), -600);- CHECK_EQ(REAL_TO_INT_CEIL(-600.5f), -600);-}//////////////////////////////////////////////////////////////////////////////// The in-flight damage ledger@@ -5738,3 +5707,79 @@ TEST(replay_crc_queue_drops_the_frame_the_network_never_recorded)CHECK_EQ( 0x33333333, net.readCRC() );CHECK_EQ( 0, net.readCRC() );}+++/** The build queue strip has nine buttons, and that number had become the production cap: every+ build button greyed out at nine units even though the queue itself is a hundred deep. The two+ numbers are unrelated - one is how many entries fit on screen, the other is how many the factory+ will take (INI MaxQueueEntries). */+TEST(a_factorys_queue_is_as_deep_as_its_ini_says_not_as_wide_as_the_button_strip)+{+ ProductionUpdateModuleData data;++ CHECK_EQ( 100, data.m_maxQueueEntries );+ CHECK( data.m_maxQueueEntries > MAX_BUILD_QUEUE_BUTTONS );+}++/** The bar over a worker's head while it loads or unloads a box fills across the window the dock+ state announced. Outside that window there is no bar at all - which is how a worker walking+ between the pile and the refinery reads, since nothing but the dock state ever moves the+ window - and the ends of the window are exclusive so a stale one cannot leave a full bar+ hanging over an idle worker. */+TEST(a_dock_action_bar_fills_across_its_window_and_shows_nothing_outside_it)+{+ // half way through a thirty frame box+ CHECK_NEAR( 0.5f, dockActionProgress( 115, 100, 130 ), 0.0001f );+ CHECK_NEAR( 0.0f, dockActionProgress( 100, 100, 130 ), 0.0001f );++ // the frame it lands on, and every frame after, is over: no bar+ CHECK( dockActionProgress( 130, 100, 130 ) < 0.0f );+ CHECK( dockActionProgress( 400, 100, 130 ) < 0.0f );++ // before it starts, and a window that was never set, are both no bar+ CHECK( dockActionProgress( 99, 100, 130 ) < 0.0f );+ CHECK( dockActionProgress( 0, 0, 0 ) < 0.0f );++ // a zero-length window is not a divide by zero+ CHECK( dockActionProgress( 100, 100, 100 ) < 0.0f );+}+++/** EA's floor and ceil nudged the value by the largest float below one and truncated. The nudge+ does not survive the addition: for anything from 2 upwards, f + 0.99999994 rounds to f + 1, so+ the "ceil" of a whole number came back one too high - and every countdown drawn over a building+ is a whole number of seconds, which is why a ten second build said eleven. */+TEST(ceil_and_floor_are_exact_on_whole_numbers)+{+ // the case that was wrong: a whole number is already its own ceiling. This used to be pinned+ // the other way round, as realtointceil_DEFECT_overshoots_every_whole_number - the screen+ // heights are the values that first turned it up, the seconds over a building are what+ // finally made it worth the compare.+ CHECK_EQ( 10, REAL_TO_INT_CEIL( 10.0f ) );+ CHECK_EQ( 2, REAL_TO_INT_CEIL( 2.0f ) );+ CHECK_EQ( 1, REAL_TO_INT_CEIL( 1.0f ) );+ CHECK_EQ( 0, REAL_TO_INT_CEIL( 0.0f ) );+ CHECK_EQ( 600, REAL_TO_INT_CEIL( 600.0f ) );+ CHECK_EQ( 768, REAL_TO_INT_CEIL( 768.0f ) );+ CHECK_EQ( 1080, REAL_TO_INT_CEIL( 1080.0f ) );+ CHECK_EQ( 1920, REAL_TO_INT_CEIL( 1920.0f ) );+ CHECK_EQ( -3, REAL_TO_INT_CEIL( -3.0f ) );+ CHECK_EQ( -600, REAL_TO_INT_CEIL( -600.0f ) );++ // ... and a fraction still rounds away from zero the way ceil must+ CHECK_EQ( 11, REAL_TO_INT_CEIL( 10.0001f ) );+ CHECK_EQ( 11, REAL_TO_INT_CEIL( 10.9f ) );+ CHECK_EQ( 1, REAL_TO_INT_CEIL( 0.001f ) );+ CHECK_EQ( 601, REAL_TO_INT_CEIL( 600.5f ) );+ CHECK_EQ( 1081, REAL_TO_INT_CEIL( 1080.25f ) );+ CHECK_EQ( -10, REAL_TO_INT_CEIL( -10.9f ) );+ CHECK_EQ( -600, REAL_TO_INT_CEIL( -600.5f ) );++ // floor had the same flaw on the negative side+ CHECK_EQ( -3, REAL_TO_INT_FLOOR( -3.0f ) );+ CHECK_EQ( 10, REAL_TO_INT_FLOOR( 10.0f ) );+ CHECK_EQ( 10, REAL_TO_INT_FLOOR( 10.9f ) );+ CHECK_EQ( -4, REAL_TO_INT_FLOOR( -3.1f ) );+ CHECK_EQ( 0, REAL_TO_INT_FLOOR( 0.9f ) );+ CHECK_EQ( -1, REAL_TO_INT_FLOOR( -0.1f ) );+}