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(ai): drive straight into an empty dock

Olcay Seygan627f58dd60cd
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DockUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DockUpdate.h
index 163dd59db..77924d408 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DockUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DockUpdate.h
@@ -121,6 +121,9 @@ public:
virtual void cancelDock( Object* docker ); ///< Clear me from any reserved points, and if I was the reason you were Busy, you aren't anymore.
virtual Bool isDockOpen( void ) { return m_dockOpen; } ///< Is the dock open to accepting dockers
+
+ /// Who is inside right now, INVALID_ID for nobody - an empty dock is not one to queue outside of
+ virtual ObjectID getActiveDocker( void ) const { return m_activeDocker; }
virtual void setDockOpen( Bool open ) { m_dockOpen = open; } ///< Open/Close the dock
virtual Bool isAllowPassthroughType(); ///< Not all docks allow you to path through them in your AIDock machine
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpdateModule.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpdateModule.h
index 59c219feb..9219b4b68 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpdateModule.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/UpdateModule.h
@@ -300,6 +300,9 @@ public:
*/
virtual Bool isClearToEnter( Object const* docker ) const = 0;
+ /// Who is inside right now, INVALID_ID for nobody - an empty dock is not one to queue outside of
+ virtual ObjectID getActiveDocker( void ) const = 0;
+
/** Return true when it is OK for docker to request a new Approach position. The dock is in
charge of keeping track of holes in the line, but the docker will remind us of their spot.
*/
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp
index fa5a6fa8e..50dcca1e5 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIDock.cpp
@@ -198,6 +198,25 @@ StateReturnType AIDockApproachState::onEnter( void )
if (ai) {
ai->ignoreObstacle( NULL );
}
+
+ //
+ // Nobody ahead of us and nobody inside: drive straight in.
+ //
+ // The approach position is a queue slot, and the machine treats it as a destination - a move
+ // order that ends by stopping there, then a wait, then a second move to the entry, then a third
+ // to the pad. With a queue that is the whole point. With an empty dock, which is what a worker
+ // meets on nearly every trip it makes, it is a full stop in open ground outside the building
+ // followed by a standing start, twice a load: the hesitation at the supply pile and again at the
+ // centre. Taking the slot and reporting it reached without driving to it hands the dock to the
+ // next state a frame later; the queue behind is unaffected, because there is nobody in it.
+ //
+ if( dock->getActiveDocker() == INVALID_ID
+ && ( (AIDockMachine*)getMachine() )->m_approachPosition == 0 )
+ {
+ dock->onApproachReached( getMachineOwner() );
+ return STATE_SUCCESS;
+ }
+
// this behavior is an extention of basic MoveTo
return AIInternalMoveToState::onEnter();
}