Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameclient): number queued build plans in their builder's order

Olcay Seygan055cbf87bf5b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9b3a18525..8ffb47539 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -602,7 +602,7 @@ A third pass went through the generals' powers, promotions and unit abilities.
- The production strip dims fresh orders the same way.
- A second worker can take over a half-built building.
- The nearest idle worker takes a new job, without yanking a busy one off.
-- Hand one worker a string of jobs and it does them in the order you gave them. Hold shift and put down three buildings while it is busy; each waits on the ground as a plan, and the worker goes from the first to the second to the third. It used to take whichever was nearest when it finished, so the barracks you placed first could be the last one up.
+- Hand one worker a string of jobs and it does them in the order you gave them. Hold shift and put down three buildings while it is busy; each waits on the ground as a plan, and the worker goes from the first to the second to the third. It used to take whichever was nearest when it finished, so the barracks you placed first could be the last one up. Each waiting plan now carries its turn as a number over the outline, 1 for the one going up next, counted separately for every worker that has more than one, so two dozers laying out one base never read as a single list. Only you see them.
- A worker that is building something still offers you the whole build list.
- The GLA's decoy build list toggles both ways now.
- Workers go back to collecting supplies when they finish.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index 3f3c236a0..2e80e0a20 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -374,6 +374,21 @@ Int InGameUI_moneyPlateWidth( MoneyPlateWidth &plate, Int needed, UnsignedInt no
* player earning `perSecond` dollars a second. See IncomeRateModeType for what automatic picks. */
Bool InGameUI_incomePerMinute( Int incomeRateMode, Int perSecond );
+/** A plan waiting for its builder, as the number over its silhouette is worked out. */
+struct BuildPlanNumber
+{
+ ObjectID plan;
+ ObjectID builder; ///< the dozer or worker the plan was given to
+ Bool current; ///< the builder is already on its way to this one
+ Coord3D spot; ///< where the number goes, in the world
+ Int step; ///< 1 for the next one built, 0 when its builder has only the one
+};
+
+/** Number each builder's plans in the order it will take them: the one it is walking to first, then
+ * lowest id first, which is the order findUnfinishedStructureToContinue picks them in. The list
+ * comes back sorted by builder and step. */
+void InGameUI_numberBuildPlans( std::vector<BuildPlanNumber>& plans );
+
// ------------------------------------------------------------------------------------------------
/** Basic functionality common to all in-game user interfaces */
// ------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index e6f0bdc72..d480bfd4f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -10679,6 +10679,33 @@ Bool InGameUI_incomePerMinute( Int incomeRateMode, Int perSecond )
return incomeRateMode == INCOME_RATE_PER_MINUTE;
}
+static bool buildPlanComesFirst( const BuildPlanNumber& a, const BuildPlanNumber& b )
+{
+ if( a.builder != b.builder )
+ return a.builder < b.builder;
+ if( a.current != b.current )
+ return a.current != FALSE;
+ return a.plan < b.plan;
+}
+
+void InGameUI_numberBuildPlans( std::vector<BuildPlanNumber>& plans )
+{
+ std::sort( plans.begin(), plans.end(), buildPlanComesFirst );
+
+ size_t first = 0;
+ while( first < plans.size() )
+ {
+ size_t end = first + 1;
+ while( end < plans.size() && plans[ end ].builder == plans[ first ].builder )
+ ++end;
+
+ // a lone "1" says nothing, as on a unit's order markers
+ for( size_t i = first; i < end; ++i )
+ plans[ i ].step = end - first > 1 ? (Int)( i - first ) + 1 : 0;
+ first = end;
+ }
+}
+
/** One seat on the scoreboard page. `full` is whether the local player may see the numbers: his
* own side, or everybody when watching. An enemy is a name, a colour and a team. `perSecond` is
* what the seat has earned a second lately, beside {{income}}, its average over the match. */
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
index 20e7977db..23c010803 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
@@ -85,6 +85,7 @@ protected:
virtual void drawAllyCursorLights( void ); ///< the patch of an ally's colour lying under their cursor
void drawAllyCursors( void ); ///< each ally's pointer and name, over the world
void drawOrderStep( const OrderHint& hint, const ICoord2D& tip, UnsignedInt color ); ///< a shift list step's number and what it is
+ void drawBuildPlanNumbers( void ); ///< each waiting plan's turn in its builder's queue
RenderObjClass *m_buildingPlacementAnchor;
RenderObjClass *m_buildingPlacementArrow;
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
index d8babbba2..c867e3dc8 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
@@ -39,6 +39,8 @@
#include "GameLogic/TerrainLogic.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/Object.h"
+#include "GameLogic/Module/AIUpdate.h"
+#include "GameLogic/Module/DozerAIUpdate.h"
#include "GameClient/CinemaDirector.h"
#include "GameClient/DisplayStringManager.h"
#include "GameClient/Drawable.h"
@@ -426,6 +428,9 @@ void W3DInGameUI::draw( void )
// and where everything selected is headed, drag or no drag
drawOrderHints();
+ // and which of the plans each builder puts up next
+ drawBuildPlanNumbers();
+
// where the allies are pointing, which is the one thing on this screen somebody else is doing
drawAllyCursors();
@@ -1276,6 +1281,54 @@ void W3DInGameUI::drawOrderHints( void )
} // end drawOrderHints
+//-------------------------------------------------------------------------------------------------
+/** The local player's plans still waiting for a builder carry the number of their turn, so a
+ * string of shift-placed buildings reads in the order its dozer will put them up. Read off the
+ * objects every frame; nothing here goes back to the logic. */
+//-------------------------------------------------------------------------------------------------
+void W3DInGameUI::drawBuildPlanNumbers( void )
+{
+ // ponytail: walks every object each frame; keep a list of plans if a big map shows it in a profile
+ std::vector<BuildPlanNumber> plans;
+ for( Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() )
+ {
+ if( !obj->isLocallyControlled() || obj->testStatus( OBJECT_STATUS_SOLD ) || obj->isEffectivelyDead() ||
+ !Object_isAwaitingBuilder( obj->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ), obj->getConstructionPercent() ) )
+ continue;
+
+ // a plan whose builder is gone is nobody's queue
+ Object *builder = TheGameLogic->findObjectByID( obj->getBuilderID() );
+ if( builder == NULL || builder->isEffectivelyDead() || builder->getAIUpdateInterface() == NULL )
+ continue;
+ DozerAIInterface *dozerAI = builder->getAIUpdateInterface()->getDozerAIInterface();
+ if( dozerAI == NULL )
+ continue;
+
+ BuildPlanNumber plan;
+ plan.plan = obj->getID();
+ plan.builder = builder->getID();
+ plan.current = dozerAI->isTaskPending( DOZER_TASK_BUILD ) && dozerAI->getTaskTarget( DOZER_TASK_BUILD ) == obj->getID();
+ plan.spot = *obj->getPosition();
+ plan.spot.z += obj->getGeometryInfo().getMaxHeightAbovePosition();
+ plan.step = 0;
+ plans.push_back( plan );
+ }
+
+ InGameUI_numberBuildPlans( plans );
+
+ for( std::vector<BuildPlanNumber>::const_iterator it = plans.begin(); it != plans.end(); ++it )
+ {
+ ICoord2D tip;
+ if( it->step == 0 || !TheTacticalView->worldToScreen( &it->spot, &tip ) )
+ continue;
+
+ OrderHint hint;
+ hint.step = it->step;
+ drawOrderStep( hint, tip, orderHintMarkerColor( ORDER_HINT_MOVE ) );
+ }
+
+} // end drawBuildPlanNumbers
+
//-------------------------------------------------------------------------------------------------
/** A patch of the ally's own colour on the ground under their cursor. It is a fan of rings whose
* alpha falls to nothing at the rim, drawn in the terrain pass like the attack circle's wash, so
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 7bb4be28c..597556db3 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -12486,6 +12486,35 @@ TEST(income_rate_stays_per_second_until_picked_and_automatic_turns_at_ten_a_seco
CHECK( !InGameUI_incomePerMinute( INCOME_RATE_AUTOMATIC, 40 ) );
}
+TEST(build_plans_are_numbered_in_the_order_their_builder_takes_them)
+{
+ // dozer 7 holds plans 40, 12 and 25 and is walking to 40; dozer 3 holds 30 alone
+ const Int ids[] = { 40, 12, 30, 25 };
+ const Int builders[] = { 7, 7, 3, 7 };
+ const Bool current[] = { TRUE, FALSE, FALSE, FALSE };
+ std::vector<BuildPlanNumber> plans;
+ for( Int i = 0; i < 4; ++i )
+ {
+ BuildPlanNumber plan;
+ plan.plan = (ObjectID)ids[ i ];
+ plan.builder = (ObjectID)builders[ i ];
+ plan.current = current[ i ];
+ plan.step = -1;
+ plans.push_back( plan );
+ }
+
+ InGameUI_numberBuildPlans( plans );
+
+ CHECK_EQ( (Int)plans[ 0 ].plan, 30 );
+ CHECK_EQ( plans[ 0 ].step, 0 );
+ CHECK_EQ( (Int)plans[ 1 ].plan, 40 );
+ CHECK_EQ( plans[ 1 ].step, 1 );
+ CHECK_EQ( (Int)plans[ 2 ].plan, 12 );
+ CHECK_EQ( plans[ 2 ].step, 2 );
+ CHECK_EQ( (Int)plans[ 3 ].plan, 25 );
+ CHECK_EQ( plans[ 3 ].step, 3 );
+}
+
TEST(empty_building_slots_are_a_check_box_that_starts_on)
{
const OptionDef *def = findOptionDef( "EmptyBuildingPips" );