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(gameengine): gate orders during the exit path, draw it while placing
Olcay Seygan82c0390e052f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 505830c22..b65e71ea7 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -440,6 +440,12 @@ Right-clicking to cancel a building you were about to place used to also deselecputting down something else meant finding and clicking the dozer again. The cancel now cancels theplacement and nothing else.+A building on the cursor now shows you where its units will come out. The see-through ghost carries a+line from its door to the spot units step to before they take their first order, and that line swings+around with the building as you wheel it. Siting a war factory is a decision about which way the+tanks face when they roll off the line, and until now you could not see that decision until the+building was finished and selected.+## Bonuses that come and go when they shouldA squad of infantry standing over its own dead used to keep the horde bonus the dead were paying@@ -511,6 +517,12 @@ the ones on the command bar below, so the same unit is the same picture in bothAround it, the whole production loop got tightened:+- **A unit finishes walking out of the building that built it before it takes an order.** Clicking+ a tank the instant it appeared used to turn it around inside its own factory. Nothing blocks a unit+ while it is still stepping out of the door, so it could be pushed back through the wall, and the+ next one off the line came out into an occupied doorway. A click during that one step out does+ nothing now; the unit is yours the moment it is clear. Aircraft leaving a pad or a runway are+ untouched — redirecting those is the point of them.- **An upgrade you can buy is offered even if one of the selected buildings already has it.** Selectevery barracks you own and the upgrade button used to grey out the moment the first one in thegroup had bought it, leaving you to hunt the rest down one at a time. The button now lights ifdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/Module.h b/GeneralsMD/Code/GameEngine/Include/Common/Module.hindex 93b6f5af5..b50da8840 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/Module.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/Module.h@@ -117,6 +117,11 @@ public:virtual const W3DTreeDrawModuleData* getAsW3DTreeDrawModuleData() const { return NULL; }virtual StaticGameLODLevel getMinimumRequiredGameLOD() const { return (StaticGameLODLevel)0;}+ /** Where units this module produces come out, in model space. Answered by the production exit+ * modules only, so the build placement preview can draw the exit before there is an Object to+ * ask through ExitInterface. Both points are relative to the model origin. */+ virtual Bool getProductionExitPointsInModelSpace( Coord3D& unitCreatePoint, Coord3D& naturalRallyPoint ) const { return FALSE; }+static void buildFieldParse(MultiIniFieldParse& p){// nothingdiff --git a/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.hindex b7f613980..1390c72fc 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h@@ -445,6 +445,21 @@ public:UnsignedInt getOcclusionDelay(void) const { return m_occlusionDelay;}const ModuleInfo& getBehaviorModuleInfo() const { return m_behaviorModuleInfo; }++ /** Ask the production exit module, if this template has one, where its units come out. Both+ * points come back in model space. This is the only way to get at them before the structure+ * exists - the build placement preview has a Drawable and a template, no Object, so there is+ * no ExitInterface to ask. */+ Bool getProductionExitPointsInModelSpace( Coord3D& unitCreatePoint, Coord3D& naturalRallyPoint ) const+ {+ for( Int i = 0; i < m_behaviorModuleInfo.getCount(); ++i )+ {+ const ModuleData* data = m_behaviorModuleInfo.getNthData( i );+ if( data && data->getProductionExitPointsInModelSpace( unitCreatePoint, naturalRallyPoint ) )+ return TRUE;+ }+ return FALSE;+ }const ModuleInfo& getDrawModuleInfo() const { return m_drawModuleInfo; }const ModuleInfo& getClientUpdateModuleInfo() const { return m_clientUpdateModuleInfo; }diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex b48142caf..6cdac8eb8 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -432,6 +432,7 @@ public: // ********************************************************************// build interfacevirtual void placeBuildAvailable( const ThingTemplate *build, Drawable *buildDrawable ); ///< built thing being placedvirtual const ThingTemplate *getPendingPlaceType( void ); ///< get item we're trying to place+ virtual const Drawable *getPendingPlaceDrawable( void ) const; ///< the ghost riding the cursor, NULL when not placingvirtual const ObjectID getPendingPlaceSourceObjectID( void ); ///< get producing objectvirtual Bool getPreventLeftClickDeselectionInAlternateMouseModeForOneClick() const { return m_preventLeftClickDeselectionInAlternateMouseModeForOneClick; }virtual void setPreventLeftClickDeselectionInAlternateMouseModeForOneClick( Bool set ) { m_preventLeftClickDeselectionInAlternateMouseModeForOneClick = set; }diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DefaultProductionExitUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DefaultProductionExitUpdate.hindex 6f7b5a3f7..ec8c61b09 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DefaultProductionExitUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DefaultProductionExitUpdate.h@@ -54,6 +54,13 @@ public:m_useSpawnRallyPoint = false;}+ virtual Bool getProductionExitPointsInModelSpace( Coord3D& unitCreatePoint, Coord3D& naturalRallyPoint ) const+ {+ unitCreatePoint = m_unitCreatePoint;+ naturalRallyPoint = m_naturalRallyPoint;+ return TRUE;+ }+static void buildFieldParse(MultiIniFieldParse& p){UpdateModuleData::buildFieldParse(p);diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/QueueProductionExitUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/QueueProductionExitUpdate.hindex 9a3025e43..bcdc80942 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/QueueProductionExitUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/QueueProductionExitUpdate.h@@ -58,6 +58,13 @@ public:m_initialBurst = 0;}+ virtual Bool getProductionExitPointsInModelSpace( Coord3D& unitCreatePoint, Coord3D& naturalRallyPoint ) const+ {+ unitCreatePoint = m_unitCreatePoint;+ naturalRallyPoint = m_naturalRallyPoint;+ return TRUE;+ }+static void buildFieldParse(MultiIniFieldParse& p){UpdateModuleData::buildFieldParse(p);diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyCenterProductionExitUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyCenterProductionExitUpdate.hindex 7c9e6bc4d..b31270056 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyCenterProductionExitUpdate.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/SupplyCenterProductionExitUpdate.h@@ -51,6 +51,13 @@ public:m_naturalRallyPoint.zero();}+ virtual Bool getProductionExitPointsInModelSpace( Coord3D& unitCreatePoint, Coord3D& naturalRallyPoint ) const+ {+ unitCreatePoint = m_unitCreatePoint;+ naturalRallyPoint = m_naturalRallyPoint;+ return TRUE;+ }+static void buildFieldParse(MultiIniFieldParse& p){UpdateModuleData::buildFieldParse(p);diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex ea80735be..a90d02d5e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -3399,6 +3399,18 @@ const ThingTemplate *InGameUI::getPendingPlaceType( void )return m_pendingPlaceType;}+//-------------------------------------------------------------------------------------------------+/** The see-thru structure the cursor is carrying, so the renderer can hang decoration off it -+ * the exit line, for one. NULL whenever we are not in placement mode. */+//-------------------------------------------------------------------------------------------------+const Drawable *InGameUI::getPendingPlaceDrawable( void ) const+{+ if( m_pendingPlaceType == NULL )+ return NULL;++ return m_placeIcon[ 0 ];+}+//-------------------------------------------------------------------------------------------------//-------------------------------------------------------------------------------------------------const ObjectID InGameUI::getPendingPlaceSourceObjectID( void )diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cppindex 7988e3218..1eb3c3696 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp@@ -2637,6 +2637,18 @@ Bool AIUpdateInterface::isAllowedToRespondToAiCommands(const AICommandParms* par// ALLOWING ONLY THE SPECTREUPDATE TO COMMAND IT VIA CMD_FROM_AI// AUTHOR, LORENZEN... 5/15/03+ //+ // A unit that is still walking the exit path out of the thing that produced it finishes that+ // step before it will listen to anyone. Taking an order mid-doorway leaves it turning around+ // inside the building's footprint, which blocks the next unit off the line and, with+ // setCanPathThroughUnits on for the exit path, lets it be shoved back through the wall.+ // Aircraft are left alone: their "exit path" is the taxi and takeoff run off a helipad or+ // airfield, which the player is expected to be able to redirect.+ //+ if ( parms->m_cmdSource == CMD_FROM_PLAYER+ && getStateMachine()->getCurrentStateID() == AI_FOLLOW_EXITPRODUCTION_PATH+ && isDoingGroundMovement() )+ return FALSE;return TRUE;}diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cppindex 88b5ce02d..470316f66 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3dWaypointBuffer.cpp@@ -564,6 +564,49 @@ void W3DWaypointBuffer::drawWaypoints(RenderInfoClass &rinfo)renderQueuedLines( localRinfo );}++ //+ // While a structure rides the cursor waiting to be placed, show where its units will come out.+ // Siting a war factory is a decision about which way the tanks face when they roll off the+ // line, and until now that was invisible until the building was finished and selected. The two+ // points come off the template's production exit module - there is no Object yet, so there is no+ // ExitInterface to ask - and the ghost's own transform carries them into world space, so the+ // line swings around with the building as the player wheels it.+ //+ const Drawable *placeIcon = TheInGameUI->getPendingPlaceDrawable();+ if( placeIcon )+ {+ Coord3D createPoint, naturalRallyPoint;+ if( TheInGameUI->getPendingPlaceType()->getProductionExitPointsInModelSpace( createPoint, naturalRallyPoint ) )+ {+ const Matrix3D *transform = placeIcon->getTransformMatrix();++ Vector3 exitLoc( createPoint.x, createPoint.y, createPoint.z );+ transform->Transform_Vector( *transform, exitLoc, &exitLoc );++ Vector3 rallyLoc( naturalRallyPoint.x, naturalRallyPoint.y, naturalRallyPoint.z );+ transform->Transform_Vector( *transform, rallyLoc, &rallyLoc );++ // a helipad puts both points in the same place; one puck, no line+ if( !(exitLoc == rallyLoc) )+ {+ LightEnvironmentClass lightEnv;+ lightEnv.Reset(Vector3(0,0,0), Vector3(1.0f,1.0f,1.0f));+ lightEnv.Pre_Render_Update(rinfo.Camera.Get_Transform());+ RenderInfoClass localRinfo(rinfo.Camera);+ localRinfo.light_environment=&lightEnv;++ m_waypointNodeRobj->Set_Position( rallyLoc );+ WW3D::Render(*m_waypointNodeRobj,localRinfo); //The little hockey puck++ Vector3 points[ 2 ];+ points[ 0 ] = exitLoc;+ points[ 1 ] = rallyLoc;+ queueLine( 2, points );+ renderQueuedLines( localRinfo );+ }+ }+ }}diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex d4e7836ff..93f14c393 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -70,6 +70,10 @@#include "Common/XferCRC.h"#include "Common/ObjectStatusTypes.h"#include "Common/Player.h"+#include "GameLogic/Module/DefaultProductionExitUpdate.h"+#include "GameLogic/Module/QueueProductionExitUpdate.h"+#include "GameLogic/Module/SupplyCenterProductionExitUpdate.h"+#include "WWMath/matrix3d.h"#include <stdio.h>#include <string.h>@@ -4564,3 +4568,79 @@ TEST(simulation_uses_no_runtime_trig)printf(" %d runtime math call(s) in the simulation; use Lib/Trig.h\n", hits);CHECK_EQ(hits, 0);}++/* The build placement preview draws the door of the structure it is carrying before that structure+ exists, so it cannot go through ExitInterface - it asks the production exit module's *data* for+ the two points instead. A module that produces nothing must keep answering no, or every wall+ segment would sprout a rally line out of (0,0,0). */+TEST(production_exit_points_come_off_the_module_data_before_there_is_an_object)+{+ Coord3D create, natural;++ DefaultProductionExitUpdateModuleData def;+ def.m_unitCreatePoint.x = 10.0f; def.m_unitCreatePoint.y = -3.0f; def.m_unitCreatePoint.z = 1.0f;+ def.m_naturalRallyPoint.x = 40.0f; def.m_naturalRallyPoint.y = 5.0f; def.m_naturalRallyPoint.z = 0.0f;++ CHECK( def.getProductionExitPointsInModelSpace( create, natural ) );+ CHECK_NEAR( create.x, 10.0f, 0.0001f );+ CHECK_NEAR( create.y, -3.0f, 0.0001f );+ CHECK_NEAR( create.z, 1.0f, 0.0001f );+ CHECK_NEAR( natural.x, 40.0f, 0.0001f );+ CHECK_NEAR( natural.y, 5.0f, 0.0001f );++ // the war factory / barracks style queue module and the supply center answer the same way+ QueueProductionExitUpdateModuleData queue;+ queue.m_unitCreatePoint.x = 7.0f;+ queue.m_naturalRallyPoint.x = 70.0f;+ CHECK( queue.getProductionExitPointsInModelSpace( create, natural ) );+ CHECK_NEAR( create.x, 7.0f, 0.0001f );+ CHECK_NEAR( natural.x, 70.0f, 0.0001f );++ SupplyCenterProductionExitUpdateModuleData supply;+ supply.m_unitCreatePoint.x = -8.0f;+ supply.m_naturalRallyPoint.x = -80.0f;+ CHECK( supply.getProductionExitPointsInModelSpace( create, natural ) );+ CHECK_NEAR( create.x, -8.0f, 0.0001f );+ CHECK_NEAR( natural.x, -80.0f, 0.0001f );++ // and anything that is not a production exit module says no and touches nothing+ UpdateModuleData notAnExit;+ create.x = 1234.0f;+ natural.x = 5678.0f;+ CHECK( notAnExit.getProductionExitPointsInModelSpace( create, natural ) == FALSE );+ CHECK_NEAR( create.x, 1234.0f, 0.0001f );+ CHECK_NEAR( natural.x, 5678.0f, 0.0001f );+}++/* Those points are in model space, and the preview line is only useful if it swings around with+ the building as the player wheels it. This is the transform the renderer applies: a structure+ dropped at (100,200) facing a quarter turn left puts a door that is 10 units "ahead" of the+ model origin 10 units to the north of the building, not 10 units east of it. */+TEST(a_placed_structures_exit_point_turns_with_the_structure)+{+ Coord3D create, natural;++ DefaultProductionExitUpdateModuleData def;+ def.m_unitCreatePoint.x = 10.0f; def.m_unitCreatePoint.y = 0.0f; def.m_unitCreatePoint.z = 0.0f;+ def.m_naturalRallyPoint.x = 30.0f; def.m_naturalRallyPoint.y = 0.0f; def.m_naturalRallyPoint.z = 0.0f;+ CHECK( def.getProductionExitPointsInModelSpace( create, natural ) );++ Matrix3D transform;+ transform.Make_Identity();+ transform.Rotate_Z( PI / 2.0f );+ transform.Set_Translation( Vector3( 100.0f, 200.0f, 5.0f ) );++ Vector3 exitLoc( create.x, create.y, create.z );+ transform.Transform_Vector( transform, exitLoc, &exitLoc );+ CHECK_NEAR( exitLoc.X, 100.0f, 0.001f );+ CHECK_NEAR( exitLoc.Y, 210.0f, 0.001f );+ CHECK_NEAR( exitLoc.Z, 5.0f, 0.001f );++ Vector3 rallyLoc( natural.x, natural.y, natural.z );+ transform.Transform_Vector( transform, rallyLoc, &rallyLoc );+ CHECK_NEAR( rallyLoc.X, 100.0f, 0.001f );+ CHECK_NEAR( rallyLoc.Y, 230.0f, 0.001f );++ // the two points are distinct, which is what tells the renderer to draw a line and not just a puck+ CHECK( !(exitLoc == rallyLoc) );+}