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(gamelogic): a sneak attack tunnel has to fit where you put it

Olcay Seygan3e18fee761b6
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h b/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h
index 0a7d7e777..35a0eb0a7 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h
@@ -159,14 +159,14 @@ public:
const ThingTemplate *build,
Real angle, // angle to construct 'build' at
UnsignedInt options, // use LocationLegalToBuildOptions
- Object *builderObject,
+ const Object *builderObject,
Player *player);
/// query if we can build at this location
virtual LegalBuildCode isLocationClearOfObjects( const Coord3D *worldPos,
const ThingTemplate *build,
Real angle, // angle to construct 'build' a
- Object *builderObject,
+ const Object *builderObject,
UnsignedInt options,
Player *thePlayer);
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp
index 4875d752f..2cef29b57 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp
@@ -36,6 +36,7 @@
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
#include "Common/ActionManager.h"
+#include "Common/BuildAssistant.h"
#include "Common/GlobalData.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
@@ -1579,11 +1580,29 @@ Bool ActionManager::canDoSpecialPowerAtLocation( const Object *obj, const Coord3
case SUPW_SPECIAL_PARTICLE_UPLINK_CANNON:
case LAZR_SPECIAL_PARTICLE_UPLINK_CANNON:
case SPECIAL_CLEANUP_AREA:
- case SPECIAL_SNEAK_ATTACK:
case SPECIAL_BATTLESHIP_BOMBARDMENT:
//Don't allow "damaging" special powers in shrouded areas, but Fogged are okay.
return ThePartitionManager->getShroudStatusForPlayer( obj->getControllingPlayer()->getPlayerIndex(), loc ) != CELLSHROUD_SHROUDED;
+ case SPECIAL_SNEAK_ATTACK:
+ {
+ // The Sneak Attack puts a building on the ground, and the only thing checked here was
+ // the shroud, so it could be dropped on water, on a cliff or inside another building.
+ const ThingTemplate *referenceThing = mod->getReferenceThingTemplate();
+ if( referenceThing == NULL )
+ return FALSE;
+
+ return TheBuildAssistant->isLocationLegalToBuild(
+ loc, referenceThing, referenceThing->getPlacementViewAngle(),
+ BuildAssistant::USE_QUICK_PATHFIND |
+ BuildAssistant::TERRAIN_RESTRICTIONS |
+ BuildAssistant::CLEAR_PATH |
+ BuildAssistant::NO_OBJECT_OVERLAP |
+ BuildAssistant::SHROUD_REVEALED |
+ BuildAssistant::IGNORE_STEALTHED,
+ obj, NULL ) == LBC_OK;
+ }
+
case SPECIAL_SPY_SATELLITE:
case SPECIAL_RADAR_VAN_SCAN:
case SPECIAL_SPY_DRONE:
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
index 24d33961b..5b5cd3741 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
@@ -677,7 +677,7 @@ void BuildAssistant::iterateFootprint( const ThingTemplate *build,
LegalBuildCode BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos,
const ThingTemplate *build,
Real angle,
- Object *builderObject,
+ const Object *builderObject,
UnsignedInt options,
Player *thePlayer)
{
@@ -930,7 +930,7 @@ LegalBuildCode BuildAssistant::isLocationLegalToBuild( const Coord3D *worldPos,
const ThingTemplate *build,
Real angle,
UnsignedInt options,
- Object *builderObject,
+ const Object *builderObject,
Player *player)
{
@@ -1017,7 +1017,7 @@ LegalBuildCode BuildAssistant::isLocationLegalToBuild( const Coord3D *worldPos,
// if clear path is requested check to see if the builder object can get there (unless it's a structure)
if( BitTest( options, CLEAR_PATH ) && builderObject && !builderObject->isKindOf( KINDOF_IMMOBILE ) )
{
- AIUpdateInterface *ai = builderObject->getAIUpdateInterface();
+ const AIUpdateInterface *ai = builderObject->getAIUpdateInterface();
//
// if there is no AI interface for this object, it cannot possible pass a clear path