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): judge fogged orders on what the player last saw
Olcay Seygan4adde6dda400
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9d2d081ee..c0dd8c63a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -177,7 +177,7 @@ found and fixed — EA's own, not port damage.**- A guarding unit no longer fights itself between returning to post and shooting back.- Engineers can clear mines and booby traps they cannot see.- A helicopter no longer boards a transport from the air.-- A building in the fog takes orders. Send infantry into a fogged garrison, a Ranger at a fogged oil derrick or a hacker at a fogged supply center and they go, where the click used to turn into a plain move to the spot. What decides whether the job still works is what they find when they get there: if the building was taken or filled up while you were not looking, they stop at the door. Ground you have never seen stays out of reach.+- A building in the fog takes orders. Send infantry into a fogged garrison, a Ranger at a fogged oil derrick or a hacker at a fogged supply center and they go, where the click used to turn into a plain move to the spot. The cursor and the walk over go by what you last saw there, so if the building was taken, filled or emptied while you were not looking, nothing on your screen says so until your men get close enough to see it, and then they stop. Ground you have never seen stays out of reach.- A computer player's reinforcement catches up with the team it joined. A unit sent to a team already walking a waypoint path took the team's orders without the path itself, which crashed the match; the crash was stopped by leaving the newcomer standing where it spawned, and now it picks up the route from wherever the team has got to. Found and fixed by T0T0W.- Select a big army, right click once, and all of it goes. In a crowd, units step aside to let a neighbour past, and a unit that stepped aside at the moment it was working out its route forgot the order and stood where it was. Out of 120 units sent across a small map, 7 were left behind, and the bigger the selection the more of them stayed. Now 200 out of 200 get there. Clicking on a building did the same thing to the whole group: there was no open ground right under the cursor, so nobody was given a place to stand. The group now stands around the building.- The whole unit limit moves on one click. The lobby allows 840 units in a match, and the game could only keep 512 of them waiting for a route at once: sent across the map together, 329 of 841 never took a step, then or ever. All 840 go now, whether one player owns them or two armies of 420 are crossing through each other, and the game never falls behind: the click itself costs 13 milliseconds, and no moment of the march took longer than 33, the time the game has for each step of the battle. With all 840 on screen the picture averages 30 frames a second on the new renderer and 37 on the old one, 2.7 milliseconds quicker than before because a crowd of infantry now redraws its shadows' poses in turns instead of every soldier every frame.diff --git a/GeneralsMD/Code/GameEngine/Include/Common/ActionManager.h b/GeneralsMD/Code/GameEngine/Include/Common/ActionManager.hindex 7b5d72503..7d0786490 100644--- a/GeneralsMD/Code/GameEngine/Include/Common/ActionManager.h+++ b/GeneralsMD/Code/GameEngine/Include/Common/ActionManager.h@@ -64,6 +64,13 @@ enum CanEnterTypeextern Bool ActionManager_shroudHidesTarget( Bool humanSource, Bool fromScript, Bool targetShrouded,Bool ownPlacementSilhouette );+//-------------------------------------------------------------------------------------------------+/** Is this order judged on the asker's memory of a structure out of their sight, rather than on+ * the structure as it is? Only a human's own clicks are; the AI and scripts always saw the truth,+ * and changing what they see would change every AI game and replay. */+//-------------------------------------------------------------------------------------------------+extern Bool ActionManager_orderReadsMemory( CommandSourceType commandSource, Bool humanAsker );+class ActionManager : public SubsystemInterface{@@ -78,7 +85,7 @@ public://Single unit to unit checkBool canGetRepairedAt( const Object *obj, const Object *repairDest, CommandSourceType commandSource );- Bool canTransferSuppliesAt( const Object *obj, const Object *transferDest );+ Bool canTransferSuppliesAt( const Object *obj, const Object *transferDest, CommandSourceType commandSource );Bool canDockAt( const Object *obj, const Object *dockDest, CommandSourceType commandSource );Bool canGetHealedAt( const Object *obj, const Object *healDest, CommandSourceType commandSource );Bool canRepairObject( const Object *obj, const Object *objectToRepair, CommandSourceType commandSource );diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.hindex 0bd83b016..2e6f75d53 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h@@ -188,6 +188,21 @@ extern Bool Object_keepsOwnerAlive( Bool underConstruction, Real constructionPer///< is this a plan a viewer on that footing with its owner must not see, live or remembered in the fog?extern Bool Object_isPlanHiddenFrom( Bool underConstruction, Real constructionPercent, Relationship viewerToOwner );+//-------------------------------------------------------------------------------------------------+/** What one player saw of a structure the moment the last of it went out of their sight. An order+ * that player gives against it in the fog is judged on this, not on what has happened there since. */+//-------------------------------------------------------------------------------------------------+struct ObjectSeenState+{+ UnsignedInt teamID; ///< the TeamID it belonged to, TEAM_ID_INVALID while nothing is remembered+ Int apparentPlayerIndex; ///< the owner its contain showed, or NO_APPARENT_PLAYER when it showed none+ Int nonStealthOccupants; ///< occupants anyone could see+ Bool suppliesExhausted; ///< a supply warehouse with no boxes left+ Bool atFullHealth;++ enum { NO_APPARENT_PLAYER = -1 };+};+class Object : public Thing, public Snapshot{@@ -619,6 +634,11 @@ public:ObjectShroudStatus getShroudedStatus(Int playerIndex) const;+ const ObjectSeenState *getSeenStateFor( Int playerIndex ) const; ///< NULL while that player can see it+ void rememberAsSeenBy( Int playerIndex ); ///< it just went out of that player's sight+ void forgetAsSeenBy( Int playerIndex ); ///< it is back in that player's sight+ Bool isUnknownTo( Int playerIndex ) const; ///< neither in that player's sight nor remembered; the logic's own answer, unlike getShroudedStatus+DisabledMaskType getDisabledFlags() const { return m_disabledMask; }Bool isDisabled() const { return m_disabledMask.any(); }Bool clearDisabled( DisabledType type );@@ -752,6 +772,7 @@ private:SightingInfo *m_partitionRevealAllLastLook; ///< And a seperate look to reveal at a different range if so markedInt m_visionSpiedBy[MAX_PLAYER_COUNT]; ///< Reference count of having units spied on by players.PlayerMaskType m_visionSpiedMask; ///< For quick lookup and edge triggered maintenance+ ObjectSeenState m_seenState[MAX_PLAYER_COUNT]; ///< each player's memory of this structure while it is out of their sightSightingInfo *m_partitionLastShroud; ///< Where and for whom I last shrouded, so I can undo its effects when I stopSightingInfo *m_partitionLastThreat; ///< Where and for whom I last delt with threat, so I can undo its effects when I stopdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.hindex 54dc50d43..ea3883931 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h@@ -356,6 +356,7 @@ public:void removeCashValue( Int playerIndex, UnsignedInt cashValue );void invalidateShroudedStatusForAllCois(Int playerIndex);+ void updateSeenStructures(Int playerIndex); ///< this cell just changed for that player: who kept or lost sight of which structure#ifdef PM_CACHE_TERRAIN_HEIGHTinline Real getLoTerrain() const { return m_loTerrainZ; }@@ -531,6 +532,8 @@ public:void invalidateShroudedStatusForPlayer(Int playerIndex);void invalidateShroudedStatusForAllPlayers();+ Bool isInSightOf(Int playerIndex); ///< is any cell it touches clear for that player, read straight from the cells+ObjectShroudStatus getShroudedStatus(Int playerIndex);inline Int wasSeenByAnyPlayers() const ///<check if a player in the game has seen the object but is now looking at fogged version.diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cppindex 18d542568..8db656569 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/ActionManager.cpp@@ -77,9 +77,89 @@ ActionManager *TheActionManager = NULL;// LOCAL //////////////////////////////////////////////////////////////////////////////////////////// ------------------------------------------------------------------------------------------------+/** A player's own order against a structure out of their sight is judged on what they last saw of+ * it, so neither the cursor nor the unit on its way gives away what has changed there. The unit+ * finds out once it can see the place, and the memory is gone by then. The AI and scripts see+ * the real thing, as they always have. */// -------------------------------------------------------------------------------------------------static Bool appearsToContainFriendlies(const Object* obj, const Object* otherObject)+static const ObjectSeenState *seenStateForOrder( const Object *source, const Object *target, CommandSourceType commandSource ){+ const Player *asker = source->getControllingPlayer();+ if( !ActionManager_orderReadsMemory( commandSource, asker->getPlayerType() == PLAYER_HUMAN ) )+ return NULL;++ return target->getSeenStateFor( asker->getPlayerIndex() );+}++// ------------------------------------------------------------------------------------------------+Bool ActionManager_orderReadsMemory( CommandSourceType commandSource, Bool humanAsker )+{+ return commandSource == CMD_FROM_PLAYER && humanAsker;+}++// ------------------------------------------------------------------------------------------------+/** NULL when there is no memory, or its team has since been disbanded and there is nothing left to+ * compare against but the live one. */+// ------------------------------------------------------------------------------------------------+static const Team *teamAsSeen( const Object *source, const Object *target, CommandSourceType commandSource )+{+ const ObjectSeenState *seen = seenStateForOrder( source, target, commandSource );+ return seen ? TheTeamFactory->findTeamByID( seen->teamID ) : NULL;+}++// ------------------------------------------------------------------------------------------------+static Relationship relationshipAsSeen( const Object *source, const Object *target, CommandSourceType commandSource )+{+ const Team *seenTeam = teamAsSeen( source, target, commandSource );+ if( seenTeam == NULL || source->getIsUndetectedDefector() )+ return source->getRelationship( target );++ return source->getTeam()->getRelationship( seenTeam );+}++// ------------------------------------------------------------------------------------------------+static const Player *ownerAsSeen( const Object *source, const Object *target, CommandSourceType commandSource )+{+ const Team *seenTeam = teamAsSeen( source, target, commandSource );+ return seenTeam ? seenTeam->getControllingPlayer() : target->getControllingPlayer();+}++// ------------------------------------------------------------------------------------------------+static Int nonStealthOccupantsAsSeen( const Object *source, const Object *target, CommandSourceType commandSource,+ const ContainModuleInterface *contain )+{+ const ObjectSeenState *seen = seenStateForOrder( source, target, commandSource );+ if( seen )+ return seen->nonStealthOccupants;++ return contain->getContainCount() - contain->getStealthUnitsContained();+}++// ------------------------------------------------------------------------------------------------+static Bool atFullHealthAsSeen( const Object *source, const Object *target, CommandSourceType commandSource )+{+ const ObjectSeenState *seen = seenStateForOrder( source, target, commandSource );+ if( seen )+ return seen->atFullHealth;++ const BodyModuleInterface *body = target->getBodyModule();+ return body->getHealth() == body->getMaxHealth();+}++// ------------------------------------------------------------------------------------------------+// ------------------------------------------------------------------------------------------------+static Bool appearsToContainFriendlies(const Object* obj, const Object* otherObject, CommandSourceType commandSource)+{+ const ObjectSeenState *seen = seenStateForOrder( obj, otherObject, commandSource );+ if( seen )+ {+ if( seen->apparentPlayerIndex == ObjectSeenState::NO_APPARENT_PLAYER )+ return FALSE;++ const Player *seenPlayer = ThePlayerList->getNthPlayer( seen->apparentPlayerIndex );+ return obj->getTeam()->getRelationship( seenPlayer->getDefaultTeam() ) != ENEMIES;+ }+// check if the object is a container containing stealth units tricking// the player into thinking it isn't actually an enemy.const ContainModuleInterface *otherContain = otherObject->getContain();@@ -110,9 +190,9 @@ static Bool isObjectShroudedForAction ( const Object *source, const Object *targ// the asking player is human// the asking impetus is not from a script- // and the target object is Shrouded. Fog alone does not stop the order: what the player last saw- // there is what they click on, and whether the enter, capture or hack still works is decided when- // the unit arrives and can see it.+ // and the player neither sees the target nor remembers it. Fog alone does not stop the order: what+ // the player last saw there is what they click on, and whether the enter, capture or hack still+ // works is decided when the unit can see it.if( source && target && source->getControllingPlayer() ){@@ -128,7 +208,7 @@ static Bool isObjectShroudedForAction ( const Object *source, const Object *targreturn ActionManager_shroudHidesTarget( source->getControllingPlayer()->getPlayerType() == PLAYER_HUMAN,commandSource == CMD_FROM_SCRIPT,- target->getShroudedStatus( source->getControllingPlayer()->getPlayerIndex() ) == OBJECTSHROUD_SHROUDED,+ target->isUnknownTo( source->getControllingPlayer()->getPlayerIndex() ),ownPlacementSilhouette );}@@ -171,7 +251,7 @@ Bool ActionManager::canGetRepairedAt( const Object *obj, const Object *repairDesif( obj == NULL || repairDest == NULL )return FALSE;- Relationship r = obj->getRelationship(repairDest);+ Relationship r = relationshipAsSeen(obj, repairDest, commandSource);// only available by our alliesif( r != ALLIES )@@ -229,7 +309,7 @@ Bool ActionManager::canGetRepairedAt( const Object *obj, const Object *repairDes// ------------------------------------------------------------------------------------------------// ------------------------------------------------------------------------------------------------// note that "dest" is typically a building...-Bool ActionManager::canTransferSuppliesAt( const Object *obj, const Object *transferDest )+Bool ActionManager::canTransferSuppliesAt( const Object *obj, const Object *transferDest, CommandSourceType commandSource ){// sanity@@ -262,16 +342,22 @@ Bool ActionManager::canTransferSuppliesAt( const Object *obj, const Object *tran// If it is a warehouse, it must have boxes left and not be an enemystatic const NameKeyType key_warehouseUpdate = NAMEKEY("SupplyWarehouseDockUpdate");SupplyWarehouseDockUpdate *warehouseModule = (SupplyWarehouseDockUpdate*)transferDest->findUpdateModule( key_warehouseUpdate );+ const ObjectSeenState *seen = seenStateForOrder( obj, transferDest, commandSource );if( warehouseModule )- if( warehouseModule->getBoxesStored() == 0 || transferDest->getRelationship( obj ) == ENEMIES )+ {+ Bool exhausted = seen ? seen->suppliesExhausted : warehouseModule->getBoxesStored() == 0;+ const Team *seenTeam = teamAsSeen( obj, transferDest, commandSource );+ Relationship warehouseToTruck = seenTeam ? seenTeam->getRelationship( obj->getTeam() ) : transferDest->getRelationship( obj );+ if( exhausted || warehouseToTruck == ENEMIES )return FALSE;+ }// if it is a supply center, I must have boxes, and must be controlled by the same player// (not merely an ally... otherwise you may find yourself funding your allies. ick.)static const NameKeyType key_centerUpdate = NAMEKEY("SupplyCenterDockUpdate");SupplyCenterDockUpdate *centerModule = (SupplyCenterDockUpdate*)transferDest->findUpdateModule( key_centerUpdate );if( centerModule )- if( supplyTruck->getNumberBoxes() == 0 || transferDest->getControllingPlayer() != obj->getControllingPlayer() )+ if( supplyTruck->getNumberBoxes() == 0 || ownerAsSeen( obj, transferDest, commandSource ) != obj->getControllingPlayer() )return FALSE;// if he is not a warehouse or a center, then shut the hell up@@ -294,7 +380,7 @@ Bool ActionManager::canTransferSuppliesAt( const Object *obj, const Object *tranif( objPlayer ){if( objPlayer->getPlayerType() == PLAYER_HUMAN &&- transferDest->getShroudedStatus( objPlayer->getPlayerIndex() ) == OBJECTSHROUD_SHROUDED )+ transferDest->isUnknownTo( objPlayer->getPlayerIndex() ) ){return FALSE;}@@ -328,7 +414,7 @@ Bool ActionManager::canDockAt( const Object *obj, const Object *dockDest, Comman*/// transferring supplies is a valid docking action- if( canTransferSuppliesAt( obj, dockDest ) == TRUE )+ if( canTransferSuppliesAt( obj, dockDest, commandSource ) == TRUE )return TRUE;// units and infantry can dock with a railed transport@@ -356,7 +442,7 @@ Bool ActionManager::canGetHealedAt( const Object *obj, const Object *healDest, Cif( obj == NULL || healDest == NULL )return FALSE;- Relationship r = obj->getRelationship(healDest);+ Relationship r = relationshipAsSeen(obj, healDest, commandSource);// only available by our alliesif( r != ALLIES )@@ -408,7 +494,7 @@ Bool ActionManager::canRepairObject( const Object *obj, const Object *objectToReif( obj == NULL || objectToRepair == NULL )return FALSE;- Relationship r = obj->getRelationship(objectToRepair);+ Relationship r = relationshipAsSeen(obj, objectToRepair, commandSource);// you can only repair allies, we ignore this restriction for bridges// srj sez: nope, allow neutral too, so civ bldgs can be repaired@@ -447,11 +533,8 @@ Bool ActionManager::canRepairObject( const Object *obj, const Object *objectToReif( objectToRepair->isKindOf( KINDOF_STRUCTURE ) == FALSE )return FALSE;- // get the body module from the object to repair- BodyModuleInterface *body = objectToRepair->getBodyModule();-// buildings that are at full health cannot be repaired- if( body->getHealth() == body->getMaxHealth() )+ if( atFullHealthAsSeen( obj, objectToRepair, commandSource ) )return FALSE;// if the target is in the shroud, we can't do anything@@ -710,13 +793,14 @@ Bool ActionManager::canEnterObject( const Object *obj, const Object *objectToEnt}else{- Bool checkCapacity = (mode == CHECK_CAPACITY);- Int containCount = contain->getContainCount();+ // in the fog capacity is not checked: a house that filled up while nobody was watching would+ // turn the cursor away and give it up. The unit finds out at the door.+ Bool checkCapacity = (mode == CHECK_CAPACITY) && seenStateForOrder(obj, objectToEnter, commandSource) == NULL;Int stealthContainCount = contain->getStealthUnitsContained();- Int nonStealthContainCount = containCount - stealthContainCount;+ Int nonStealthContainCount = nonStealthOccupantsAsSeen(obj, objectToEnter, commandSource, contain);// not ours... must do special checks.- if (objectToEnter->getControllingPlayer() != obj->getControllingPlayer())+ if (ownerAsSeen(obj, objectToEnter, commandSource) != obj->getControllingPlayer()){// not empty... can't do it.if (nonStealthContainCount > 0)@@ -993,7 +1077,7 @@ Bool ActionManager::canSabotageBuilding( const Object *obj, const Object *objectreturn FALSE;}- Relationship r = obj->getRelationship(objectToSabotage);+ Relationship r = relationshipAsSeen(obj, objectToSabotage, commandSource);//Only sabotage enemy objectsif( r != ENEMIES ){@@ -1121,7 +1205,7 @@ Bool ActionManager::canCaptureBuilding( const Object *obj, const Object *objectTif (isObjectShroudedForAction(obj, objectToCapture, commandSource))return FALSE;- Relationship r = obj->getRelationship(objectToCapture);+ Relationship r = relationshipAsSeen(obj, objectToCapture, commandSource);// ensure that it's capturable, and not allied// exception: we can always capture enemy bldgs, regardless of kindof@@ -1141,16 +1225,13 @@ Bool ActionManager::canCaptureBuilding( const Object *obj, const Object *objectTContainModuleInterface *contain = objectToCapture->getContain();if (contain != NULL && contain->isGarrisonable()){- Int containCount = contain->getContainCount();- Int stealthContainCount = contain->getStealthUnitsContained();- Int nonStealthContainCount = containCount - stealthContainCount;- if (nonStealthContainCount > 0)+ if (nonStealthOccupantsAsSeen(obj, objectToCapture, commandSource, contain) > 0)return FALSE;}// Also check if the object is a container containing stealth units, tricking// the player into thinking it isn't actually an enemy.- if (appearsToContainFriendlies(obj, objectToCapture))+ if (appearsToContainFriendlies(obj, objectToCapture, commandSource))return FALSE;return TRUE;@@ -1206,7 +1287,7 @@ Bool ActionManager::canDisableVehicleViaHacking( const Object *obj, const Objectif (isObjectShroudedForAction(obj, objectToHack, commandSource))return FALSE;- Relationship r = obj->getRelationship(objectToHack);+ Relationship r = relationshipAsSeen(obj, objectToHack, commandSource);// Make sure object is an enemyif( r == ENEMIES )@@ -1228,7 +1309,7 @@ Bool ActionManager::canDisableVehicleViaHacking( const Object *obj, const Object//Also check if the object is a container containing stealth units tricking//the player into thinking it isn't actually an enemy.- if (appearsToContainFriendlies(obj, objectToHack))+ if (appearsToContainFriendlies(obj, objectToHack, commandSource))return FALSE;return TRUE;@@ -1324,7 +1405,7 @@ Bool ActionManager::canStealCashViaHacking( const Object *obj, const Object *objif (isObjectShroudedForAction(obj, objectToHack, commandSource))return FALSE;- Relationship r = obj->getRelationship(objectToHack);+ Relationship r = relationshipAsSeen(obj, objectToHack, commandSource);// Make sure object is an enemyif( r == ENEMIES )@@ -1358,7 +1439,7 @@ Bool ActionManager::canStealCashViaHacking( const Object *obj, const Object *obj//Also check if the object is a container containing stealth units tricking//the player into thinking it isn't actually an enemy.- if (appearsToContainFriendlies(obj, objectToHack))+ if (appearsToContainFriendlies(obj, objectToHack, commandSource))return FALSE;return TRUE;@@ -1396,7 +1477,7 @@ Bool ActionManager::canDisableBuildingViaHacking( const Object *obj, const Objecif (isObjectShroudedForAction(obj, objectToHack, commandSource))return FALSE;- Relationship r = obj->getRelationship(objectToHack);+ Relationship r = relationshipAsSeen(obj, objectToHack, commandSource);// Make sure object is an enemyif( r != ENEMIES )@@ -1431,7 +1512,7 @@ Bool ActionManager::canDisableBuildingViaHacking( const Object *obj, const Objec//Also check if the object is a container containing stealth units tricking//the player into thinking it isn't actually an enemy.- if (appearsToContainFriendlies(obj, objectToHack))+ if (appearsToContainFriendlies(obj, objectToHack, commandSource))return FALSE;return TRUE;@@ -1684,7 +1765,7 @@ Bool ActionManager::canDoSpecialPowerAtObject( const Object *obj, const Object *return FALSE;}- Relationship r = obj->getRelationship(target);+ Relationship r = relationshipAsSeen(obj, target, commandSource);SpecialPowerModuleInterface *mod = obj->getSpecialPowerModule( spTemplate );if( mod )@@ -1708,7 +1789,7 @@ Bool ActionManager::canDoSpecialPowerAtObject( const Object *obj, const Object *return false;case SPECIAL_BATTLESHIP_BOMBARDMENT:- if( obj->getRelationship( target ) != ALLIES )+ if( r != ALLIES ){return TRUE;}diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/ResourceGatheringManager.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/ResourceGatheringManager.cppindex 97db65d9f..b4dbed76c 100644--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/ResourceGatheringManager.cpp+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/ResourceGatheringManager.cpp@@ -126,7 +126,7 @@ static Real computeRelativeCost( Object *queryObject, Object *destObject, Real *if( queryObject == NULL || destObject == NULL )return FLT_MAX;- if( !TheActionManager->canTransferSuppliesAt(queryObject, destObject) )+ if( !TheActionManager->canTransferSuppliesAt(queryObject, destObject, CMD_FROM_AI) )return FLT_MAX;// Handles emptyness and alliancesDockUpdateInterface *dockInterface = destObject->getDockUpdateInterface();diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex 8ba01308c..0fd60a808 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -47,6 +47,7 @@#include "Common/Recorder.h"#include "Common/SpecialPower.h"#include "Common/StatsCollector.h"+#include "Common/Team.h"#include "Common/ThingTemplate.h"#include "Common/GameLOD.h"@@ -1707,7 +1708,12 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,//This case prevents rebels from using tranq darts on allies.if( obj && BitTest( command->getOptions(), COMMAND_OPTION_NEED_OBJECT_TARGET ) ){- Relationship relationship = ThePlayerList->getLocalPlayer()->getRelationship( obj->getTeam() );+ // a building out of sight is judged on who held it when it was last seen, the way+ // the ActionManager judges the order itself+ const Player *localPlayer = ThePlayerList->getLocalPlayer();+ const ObjectSeenState *seen = obj->getSeenStateFor( localPlayer->getPlayerIndex() );+ const Team *seenTeam = seen ? TheTeamFactory->findTeamByID( seen->teamID ) : NULL;+ Relationship relationship = localPlayer->getRelationship( seenTeam ? seenTeam : obj->getTeam() );switch( relationship ){case ALLIES:diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cppindex c40852abe..7c62cccaa 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp@@ -92,6 +92,7 @@#include "GameLogic/Module/StatusDamageHelper.h"#include "GameLogic/Module/StickyBombUpdate.h"#include "GameLogic/Module/SubdualDamageHelper.h"+#include "GameLogic/Module/SupplyWarehouseDockUpdate.h"#include "GameLogic/Module/TempWeaponBonusHelper.h"#include "GameLogic/Module/ToppleUpdate.h"#include "GameLogic/Module/UpdateModule.h"@@ -243,9 +244,10 @@ Object::Object( const ThingTemplate *tt, const ObjectStatusMaskType &objectStatum_formationOffset.x = m_formationOffset.y = 0.0f;m_iPos.zero();//- for (i = 0; i < MAX_PLAYER_COUNT; ++i)+ for (i = 0; i < MAX_PLAYER_COUNT; ++i){m_visionSpiedBy[i] = 0;+ m_seenState[i].teamID = TEAM_ID_INVALID;}for( i = 0; i < DISABLED_COUNT; i++ )@@ -1888,10 +1890,79 @@ ObjectShroudStatus Object::getShroudedStatus(Int playerIndex) constreturn m_partitionData->getShroudedStatus(playerIndex);// This can happen for objects removed from the partition system (e.g.,- // for soldiers that are garrisoned inside a building).+ // for soldiers that are garrisoned inside a building).return OBJECTSHROUD_CLEAR;}+//-------------------------------------------------------------------------------------------------+const ObjectSeenState *Object::getSeenStateFor( Int playerIndex ) const+{+ const ObjectSeenState &seen = m_seenState[ playerIndex ];+ return seen.teamID == TEAM_ID_INVALID ? NULL : &seen;+}++//-------------------------------------------------------------------------------------------------+/** Kept once, when the last of it goes out of sight: whatever happens to it after that, the player+ * did not see happen. */+//-------------------------------------------------------------------------------------------------+void Object::rememberAsSeenBy( Int playerIndex )+{+ ObjectSeenState &seen = m_seenState[ playerIndex ];+ // no team only while the game is being torn down and its sight taken away+ if( seen.teamID != TEAM_ID_INVALID || getTeam() == NULL )+ return;++ seen.teamID = getTeam()->getID();+ seen.apparentPlayerIndex = ObjectSeenState::NO_APPARENT_PLAYER;+ seen.nonStealthOccupants = 0;+ seen.suppliesExhausted = FALSE;++ const BodyModuleInterface *body = getBodyModule();+ seen.atFullHealth = body->getHealth() == body->getMaxHealth();++ const ContainModuleInterface *contain = getContain();+ if( contain )+ {+ const Player *apparent = contain->getApparentControllingPlayer( ThePlayerList->getNthPlayer( playerIndex ) );+ if( apparent )+ seen.apparentPlayerIndex = apparent->getPlayerIndex();+ seen.nonStealthOccupants = contain->getContainCount() - contain->getStealthUnitsContained();+ }++ static const NameKeyType key_warehouseUpdate = NAMEKEY( "SupplyWarehouseDockUpdate" );+ const SupplyWarehouseDockUpdate *warehouse = (const SupplyWarehouseDockUpdate *)findUpdateModule( key_warehouseUpdate );+ if( warehouse )+ seen.suppliesExhausted = warehouse->getBoxesStored() == 0;+}++//-------------------------------------------------------------------------------------------------+void Object::forgetAsSeenBy( Int playerIndex )+{+ m_seenState[ playerIndex ].teamID = TEAM_ID_INVALID;+}++//-------------------------------------------------------------------------------------------------+/** getShroudedStatus tells fogged from shrouded by whether the player "has ever seen" it, and that+ * is only noted when something happens to ask while it is in sight - the drawing loop, on each+ * machine for its own player. Two machines disagree about it, so an order must not hang on it.+ * This asks the cells and the memory, which every machine keeps on the same logic frame. */+//-------------------------------------------------------------------------------------------------+Bool Object::isUnknownTo( Int playerIndex ) const+{+ if( getTemplate()->isKindOf( KINDOF_ALWAYS_VISIBLE ) )+ return FALSE;++ if( Object_isPlanHiddenFrom( testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ), getConstructionPercent(),+ ThePlayerList->getNthPlayer( playerIndex )->getRelationship( getTeam() ) ) )+ return TRUE;++ // carried inside something, the same as getShroudedStatus answers+ if( m_partitionData == NULL )+ return FALSE;++ return !m_partitionData->isInSightOf( playerIndex ) && getSeenStateFor( playerIndex ) == NULL;+}+//-------------------------------------------------------------------------------------------------/** Something is attempting to damage this object *///-------------------------------------------------------------------------------------------------@@ -4224,13 +4295,14 @@ void Object::crc( Xfer *xfer )* 7: save full mtx, not pos+orient.* 8: Kris: Conversion of object status bits from UnsignedInt to BitFlags<>* 9: Extra sighting for reveal to all with different range units+ * 10: each player's memory of it while it is out of their sight*///-------------------------------------------------------------------------------------------------void Object::xfer( Xfer *xfer ){-+// version- const XferVersion currentVersion = 9;+ const XferVersion currentVersion = 10;XferVersion version = currentVersion;xfer->xferVersion( &version, currentVersion );@@ -4339,6 +4411,19 @@ void Object::xfer( Xfer *xfer )// vision spied by maskxfer->xferUser( &m_visionSpiedMask, sizeof( PlayerMaskType ) );+ if( version >= 10 )+ {+ for( Int playerIndex = 0; playerIndex < MAX_PLAYER_COUNT; ++playerIndex )+ {+ ObjectSeenState &seen = m_seenState[ playerIndex ];+ xfer->xferUnsignedInt( &seen.teamID );+ xfer->xferInt( &seen.apparentPlayerIndex );+ xfer->xferInt( &seen.nonStealthOccupants );+ xfer->xferBool( &seen.suppliesExhausted );+ xfer->xferBool( &seen.atFullHealth );+ }+ }+// sighting info, last threat// John M says we don't need to save this (CBD)// xfer->xferSnapshot( &m_partitionLastThreat );diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cppindex c8fae254b..75bfbb95d 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp@@ -1285,6 +1285,28 @@ void PartitionCell::invalidateShroudedStatusForAllCois(Int playerIndex)}}+//-----------------------------------------------------------------------------+/** Called only from the logic's own look and shroud edges, never from the local player's display+ * refresh, so every machine keeps the same memories on the same frame. */+//-----------------------------------------------------------------------------+void PartitionCell::updateSeenStructures(Int playerIndex)+{+ for (CellAndObjectIntersection* coi = m_firstCoiInCell; coi; coi = coi->getNextCoi())+ {+ PartitionData *module = coi->getModule();+ Object *object = module->getObject();++ // a module holding only a ghost has no object left to remember+ if (object == NULL || !object->isKindOf(KINDOF_STRUCTURE) || object->isKindOf(KINDOF_ALWAYS_VISIBLE))+ continue;++ if (module->isInSightOf(playerIndex))+ object->forgetAsSeenBy(playerIndex);+ else+ object->rememberAsSeenBy(playerIndex);+ }+}+//-----------------------------------------------------------------------------void PartitionCell::addLooker(Int playerIndex){@@ -1294,9 +1316,9 @@ void PartitionCell::addLooker(Int playerIndex)CellShroudStatus newShroud = getShroudStatusForPlayer( playerIndex );-// DEBUG_LOG(( "ADD %d, %d. CS = %d, AS = %d for player %d.\n",-// m_cellX,-// m_cellY,+// DEBUG_LOG(( "ADD %d, %d. CS = %d, AS = %d for player %d.\n",+// m_cellX,+// m_cellY,// m_shroudLevel[playerIndex].m_currentShroud,// m_shroudLevel[playerIndex].m_activeShroudLevel,// playerIndex@@ -1306,6 +1328,7 @@ void PartitionCell::addLooker(Int playerIndex){// On an edge trigger, tell all objects to think about their shroudednessinvalidateShroudedStatusForAllCois( playerIndex );+ updateSeenStructures( playerIndex );if( playerIndex == ThePlayerList->getLocalPlayer()->getPlayerIndex() ){@@ -1330,9 +1353,9 @@ void PartitionCell::removeLooker(Int playerIndex)}CellShroudStatus newShroud = getShroudStatusForPlayer( playerIndex );-// DEBUG_LOG(( "REMOVE %d, %d. CS = %d, AS = %d for player %d.\n",-// m_cellX,-// m_cellY,+// DEBUG_LOG(( "REMOVE %d, %d. CS = %d, AS = %d for player %d.\n",+// m_cellX,+// m_cellY,// m_shroudLevel[playerIndex].m_currentShroud,// m_shroudLevel[playerIndex].m_activeShroudLevel,// playerIndex@@ -1342,6 +1365,7 @@ void PartitionCell::removeLooker(Int playerIndex){// On an edge trigger, tell all objects to think about their shroudednessinvalidateShroudedStatusForAllCois( playerIndex );+ updateSeenStructures( playerIndex );if( playerIndex == ThePlayerList->getLocalPlayer()->getPlayerIndex() ){@@ -1369,6 +1393,7 @@ void PartitionCell::addShrouder( Int playerIndex ){// On an edge trigger, tell all objects to think about their shroudednessinvalidateShroudedStatusForAllCois( playerIndex );+ updateSeenStructures( playerIndex );// and update the client if we are on the local playerif( playerIndex == ThePlayerList->getLocalPlayer()->getPlayerIndex() )@@ -1611,6 +1636,18 @@ Int PartitionData::getControllingPlayerIndex() constreturn 0;}+//-----------------------------------------------------------------------------+Bool PartitionData::isInSightOf(Int playerIndex)+{+ CellAndObjectIntersection* coi = m_coiArray;+ for (Int i = m_coiInUseCount; i; --i, ++coi)+ {+ if (coi->getCell()->getShroudStatusForPlayer(playerIndex) == CELLSHROUD_CLEAR)+ return TRUE;+ }+ return FALSE;+}+//-----------------------------------------------------------------------------// only used to restore state after map border resizing and/or xfer!void PartitionData::friend_setShroudednessPrevious(Int playerIndex, ObjectShroudStatus status)diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 614c9d80a..9c95ccd19 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -6666,6 +6666,18 @@ TEST(the_shroud_never_hides_your_own_plan_from_your_own_builder)CHECK( ActionManager_shroudHidesTarget( TRUE, FALSE, FALSE, FALSE ) == FALSE ); // in plain sight}+/** A player clicking a building in the fog is judged on what they last saw there, so the cursor and+ the walk over give nothing away. The AI and scripts keep seeing the real building: were they+ judged on memory too, every computer game would play differently and every replay recorded+ before would stop matching. */+TEST(only_a_players_own_click_is_judged_on_what_they_last_saw)+{+ CHECK( ActionManager_orderReadsMemory( CMD_FROM_PLAYER, TRUE ) == TRUE );+ CHECK( ActionManager_orderReadsMemory( CMD_FROM_PLAYER, FALSE ) == FALSE ); // a computer player's group order+ CHECK( ActionManager_orderReadsMemory( CMD_FROM_AI, TRUE ) == FALSE ); // a human's unit acting on its own+ CHECK( ActionManager_orderReadsMemory( CMD_FROM_SCRIPT, TRUE ) == FALSE );+}+//-------------------------------------------------------------------------------------------------/** A plan is a silhouette, not a building: cancelling it - or an enemy shooting it - must not setoff the explosion, collapse and rubble of a structure that never stood. Object::onDie skips