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(gameengine): close every desync the second audit found

Olcay Seygan1b8279c6b82d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 481d17caf..93509386d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -229,6 +229,19 @@ found and fixed — EA's own, not port damage.**
- Somebody quitting no longer reports a desync to everyone still playing.
- A power sabotage no longer follows a player into the next match.
- Muting sound effects or speech no longer desyncs the game.
+- A replay of a match you played yourself plays back. Every recording with a human seat whose units moved went out of step at the first check, three seconds in: the playback shared those units' sight with the person watching the replay, which the match itself never did. Taking over a computer side with Shift-Ctrl-T is written into the replay as well, so a recording plays back past it.
+- A Particle Cannon beam hurts the same on every machine. How far its damage reached was read off the picture of the beam, and a machine catching up after a stutter damaged with a beam a few frames old. A cannon an enemy happened to spot while it stood idle could also go dead on that enemy's machine alone.
+- A map with its own rules no longer follows you into the next match. A custom map can change armour, upgrades, what a building leaves behind and a side's starting setup; a machine that had played one kept those values until the game was restarted, and fought the next match with them while everyone else used the stock ones. And a map sent to you over the network is played with its rules file, where the receiving machine used to skip it.
+- A building full of stealthed Jarmen Kells or Hijackers no longer shuffles them between windows on one screen only when a detector sweeps over it.
+- A unit whose firing animation has its own set of barrels fires from the same barrel on every machine, whatever each player's camera happens to be looking at.
+- A unit queued in a factory by a map script is numbered the same on every machine, so cancelling it works everywhere and not just for its owner.
+- A map script that waits on a sound, a music track or a camera move now decides on the same frame on every machine.
+- A match starts from the number the lobby agreed on, whatever the battle behind the menu was doing when the host pressed start.
+- Graphics detail no longer decides whether a piece of debris exists or how long a death takes.
+- The first building of a computer player is no longer held back a frame on a machine that already played a match that session.
+- Two allied vehicles blocking each other in a narrow pass no longer read freed memory while they make way, which could crash the game or split it.
+- A cheat every machine refused during a network game is refused in the replay of it too.
+- The price of all of the above: a replay recorded on an earlier version can go out of step on this one where it has a Particle Cannon, an EMP, a stealthed garrison or two allies making way for each other in it.
- Pausing no longer leaks a little memory for every sound that was about to start.
- A sound cancelled before it started really is cancelled. The check compared a pointer against a handle - two different things sharing one slot - so it never matched and the sound played anyway.
- Angles come from the game's own table, identical on every machine.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Player.h b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
index d9097ef34..225e644dd 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/Player.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/Player.h
@@ -80,6 +80,7 @@ enum CheatKind
CHEAT_GOD_MODE,
CHEAT_INSTANT_BUILD,
CHEAT_ONE_HIT_KILL,
+ CHEAT_TAKE_CONTROL, ///< Shift-Ctrl-T: the amount is the index of the player to take over
CHEAT_KIND_COUNT
};
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/PlayerList.h b/GeneralsMD/Code/GameEngine/Include/Common/PlayerList.h
index 93ba9a077..5aa1d7453 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/PlayerList.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/PlayerList.h
@@ -129,6 +129,15 @@ public:
*/
void setLocalPlayer(Player *player);
+ /**
+ The seat at the keyboard as the logic knows it: the local player of a single-player game when the
+ match starts, moved only by a recorded Shift-Ctrl-T, and NULL in a network game and its replay.
+ A playback puts the ReplayObserver in the local seat and this stays where the recording had it, so
+ anything the simulation does for "whoever is playing" reads this and never getLocalPlayer().
+ */
+ inline Player *getKeyboardPlayer() { return m_keyboardPlayer; }
+ inline void setKeyboardPlayer(Player *player) { m_keyboardPlayer = player; }
+
/**
Return the player matching the player mask
*/
@@ -176,6 +185,7 @@ private:
void setSlotIndex( Int playerIndex, Int slotIndex );
Player *m_local;
+ Player *m_keyboardPlayer;
Int m_playerCount;
Player *m_players[MAX_PLAYER_COUNT];
Int m_slotIndices[MAX_PLAYER_COUNT]; ///< which network slot each player index came from, -1 for none
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/PlayerTemplate.h b/GeneralsMD/Code/GameEngine/Include/Common/PlayerTemplate.h
index b23428d09..5ee056a66 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/PlayerTemplate.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/PlayerTemplate.h
@@ -229,6 +229,10 @@ private:
typedef std::vector<PlayerTemplate> PlayerTemplateVector;
PlayerTemplateVector m_playerTemplates;
+
+ /// What a map.ini overwrote, by index and in the order it did, and how many templates there were before it added any; reset() puts both back.
+ std::vector< std::pair<Int, PlayerTemplate> > m_beforeMapOverrides;
+ Int m_countBeforeMapOverrides;
};
// ----------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h b/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h
index 659f19c20..81f5831ab 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/Upgrade.h
@@ -264,6 +264,12 @@ protected:
Int m_nextTemplateMaskBit; ///< Each instantiated UpgradeTemplate will be given a Int64 bit as an identifier
Bool buttonImagesCached;
+ /// Each upgrade a map.ini changed, with a copy of what it was, in the order it changed them; reset() puts them back.
+ std::vector< std::pair<UpgradeTemplate *, UpgradeTemplate *> > m_beforeMapOverrides;
+ /// The upgrades a map.ini added, and the mask bit the first of them took; reset() removes them and hands the bits back.
+ std::vector< UpgradeTemplate * > m_addedByMap;
+ Int m_maskBitBeforeMapOverrides;
+
};
// EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
index 52810bcda..8a18a6fe0 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
@@ -573,6 +573,9 @@ public:
inline UnsignedInt getNextGroupID( void ) { return ++m_nextGroupID; }
+ /// One building placement per logic frame across every computer player: FALSE when one already went down on this frame.
+ Bool claimBuildingPlacement( UnsignedInt frame );
+
protected:
Pathfinder *m_pathfinder; ///< the pathfinding system
std::list<AIGroup *> m_groupList; ///< the list of AIGroups
@@ -582,6 +585,7 @@ protected:
UnsignedInt m_nextGroupID;
FormationID m_nextFormationID;
+ UnsignedInt m_lastBuildingPlacementFrame; ///< cleared by reset: a static here outlived the match and deferred the next match's first placement on one machine only
};
extern AI *TheAI; ///< the Artificial Intelligence singleton
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Armor.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Armor.h
index c8183eb68..a50b3fe68 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Armor.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Armor.h
@@ -105,7 +105,7 @@ public:
~ArmorStore();
void init() { }
- void reset() { }
+ void reset();
void update() { }
/**
@@ -125,6 +125,9 @@ private:
typedef std::hash_map< NameKeyType, ArmorTemplate, rts::hash<NameKeyType>, rts::equal_to<NameKeyType> > ArmorTemplateMap;
ArmorTemplateMap m_armorTemplates;
+ /// What a map.ini overwrote, in the order it did, put back by reset() so the next match starts from the stock armour.
+ std::vector< std::pair<NameKeyType, ArmorTemplate> > m_beforeMapOverrides;
+
};
// EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ContainModule.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ContainModule.h
index 06465a91d..8fd66461c 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ContainModule.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ContainModule.h
@@ -129,7 +129,10 @@ public:
virtual const Player* getApparentControllingPlayer(const Player* observingPlayer) const = 0;
virtual void recalcApparentControllingPlayer() = 0;
-
+
+ /// Redraws what the local player is shown - colour, the garrisoned look - and touches no logic. For a change of local player.
+ virtual void refreshApparentLook() = 0;
+
//
// you will want to override onContaining() and onRemoving() if you need to
// do special actions at those event times for your module
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/GarrisonContain.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/GarrisonContain.h
index 71370e5df..a2f5452af 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/GarrisonContain.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/GarrisonContain.h
@@ -140,6 +140,7 @@ public:
*/
virtual const Player* getApparentControllingPlayer( const Player* observingPlayer ) const;
virtual void recalcApparentControllingPlayer( void );
+ virtual void refreshApparentLook( void );
virtual Bool isDisplayedOnControlBar() const {return TRUE;}///< Does this container display its contents on the ControlBar?
virtual void onDamage( DamageInfo *info );
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/LaserUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/LaserUpdate.h
index cbc70f1c4..fb30f6ea5 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/LaserUpdate.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/LaserUpdate.h
@@ -94,6 +94,7 @@ protected:
void updateStartPos(); ///< figures out and sets startPos
void updateEndPos(); ///< figures out and sets endPos
+ Real computeWidthScalar( UnsignedInt frame ) const; ///< the width on that logic frame, from the frames alone
//If the master dies, so will this laser (although if it has a fade delay, it'll just skip to the fade)
Coord3D m_startPos;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/OpenContain.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/OpenContain.h
index 7ba5df487..7c741d622 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/OpenContain.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/OpenContain.h
@@ -142,6 +142,7 @@ public:
virtual const Player* getApparentControllingPlayer(const Player* observingPlayer) const { return NULL; }
virtual void recalcApparentControllingPlayer() { }
+ virtual void refreshApparentLook() { }
virtual void onContaining( Object *obj, Bool wasSelected ); ///< object now contains 'obj'
virtual void onRemoving( Object *obj ); ///< object no longer contains 'obj'
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/ObjectCreationList.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/ObjectCreationList.h
index 627fcc0a6..84ea847ff 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/ObjectCreationList.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/ObjectCreationList.h
@@ -193,7 +193,7 @@ public:
~ObjectCreationListStore();
void init() { }
- void reset() { }
+ void reset();
void update() { }
/**
@@ -211,6 +211,9 @@ private:
typedef std::map< NameKeyType, ObjectCreationList, std::less<NameKeyType> > ObjectCreationListMap;
ObjectCreationListMap m_ocls;
+ /// What a map.ini overwrote, in the order it did, put back by reset() so the next match starts from the stock lists.
+ std::vector< std::pair<NameKeyType, ObjectCreationList> > m_beforeMapOverrides;
+
// note, this list doesn't own the nuggets; all nuggets are owned by the Store.
typedef std::vector<ObjectCreationNugget*> ObjectCreationNuggetVector;
ObjectCreationNuggetVector m_nuggets;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameAudio.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameAudio.cpp
index 845907ffd..bb9739763 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameAudio.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/Audio/GameAudio.cpp
@@ -1027,9 +1027,33 @@ Real AudioManager::getAudioLengthMS( const AudioEventRTS *event )
tmpEvent.generateFilename();
tmpEvent.generatePlayInfo();
- return getFileLengthMS(tmpEvent.getAttackFilename()) +
- getFileLengthMS(tmpEvent.getFilename()) +
- getFileLengthMS(tmpEvent.getDecayFilename());
+ AsciiString attack = tmpEvent.getAttackFilename();
+ AsciiString sound = tmpEvent.getFilename();
+ AsciiString decay = tmpEvent.getDecayFilename();
+
+ /* A file in this install's language folder wins over the generic one, and a line of speech runs
+ a different length in German than in English, so two players with different languages waited
+ on the same script for a different number of frames. In a multiplayer or skirmish session the
+ length comes from the generic folder on every machine, and a line that has no generic file
+ counts as finished at once. */
+ if (TheGameEngine->isMultiplayerSession())
+ {
+ const AudioType type = tmpEvent.getAudioEventInfo()->m_soundType;
+ const AsciiString localizedPrefix = tmpEvent.generateFilenamePrefix(type, TRUE);
+ const AsciiString genericPrefix = tmpEvent.generateFilenamePrefix(type, FALSE);
+ AsciiString *names[] = { &attack, &sound, &decay };
+ for (Int i = 0; i < (Int)(sizeof(names) / sizeof(names[0])); ++i)
+ {
+ if (names[i]->startsWith(localizedPrefix))
+ {
+ AsciiString generic = genericPrefix;
+ generic.concat(names[i]->str() + localizedPrefix.getLength());
+ *names[i] = generic;
+ }
+ }
+ }
+
+ return getFileLengthMS(attack) + getFileLengthMS(sound) + getFileLengthMS(decay);
}
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
index 69287448d..3a398a211 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
@@ -694,10 +694,10 @@ void GameLODManager::applyDynamicLODLevel(DynamicGameLODLevel level)
m_numParticleGenerations=0;
m_dynamicParticleSkipMask=m_dynamicGameLODInfo[level].m_dynamicParticleSkipMask;
- m_numDebrisGenerations=0;
- m_dynamicDebrisSkipMask=m_dynamicGameLODInfo[level].m_dynamicDebrisSkipMask;
-
- m_slowDeathScale=m_dynamicGameLODInfo[level].m_slowDeathScale;
+ /* DebrisSkipMask and SlowDeathScale are still parsed and no longer applied. The dynamic level
+ follows this machine's frame rate, and logic reads both: the one decides whether a debris object
+ is created, the other how long a death takes. The stock GameLOD.ini sets them to no effect at
+ every level, and the file is outside the multiplayer checksum, so a changed one split the match. */
m_minDynamicParticlePriority=m_dynamicGameLODInfo[level].m_minDynamicParticlePriority;
m_minDynamicParticleSkipPriority=m_dynamicGameLODInfo[level].m_minDynamicParticleSkipPriority;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
index 030bcfe02..2608f0381 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp
@@ -1189,11 +1189,12 @@ void Player::becomingLocalPlayer(Bool yes)
for( Object* object = iter->first(); object; object = iter->next() )
{
// Added support for updating the perceptions of garrisoned buildings containing enemy stealth units.
- // When changing teams, it is necessary to update this information.
+ // When changing teams, it is necessary to update this information. The look only: a change of
+ // local player happens on one machine, and the full recalc also reset teams in logic.
ContainModuleInterface *contain = object->getContain();
if( contain )
{
- contain->recalcApparentControllingPlayer();
+ contain->refreshApparentLook();
TheRadar->removeObject( object );
TheRadar->addObject( object );
}
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerList.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerList.cpp
index f2e220487..0ffe72966 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerList.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerList.cpp
@@ -51,12 +51,14 @@
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "Common/PlayerTemplate.h"
+#include "Common/Recorder.h"
#include "Common/Team.h"
#include "Common/WellKnownKeys.h"
#include "Common/Xfer.h"
#ifdef _DEBUG
#include "GameLogic/Object.h"
#endif
+#include "GameLogic/GameLogic.h"
#include "GameLogic/SidesList.h"
#include "GameNetwork/GameInfo.h"
#include "GameNetwork/NetworkDefs.h"
@@ -238,6 +240,12 @@ void PlayerList::newGame()
The two numbers are not the same and never were: player 0 is the neutral player, so a human
in slot 0 is player 1. Everything in GameNetwork is indexed by the slot. */
assignSlotIndices( TheGameInfo );
+
+ /* The local player chosen above is the one the recording had, in playback too: the replay's game
+ info carries the recorded local slot, and the switch to the ReplayObserver comes later. */
+ const Int originalMode = (TheRecorder && TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK)
+ ? TheRecorder->getGameMode() : TheGameLogic->getGameMode();
+ m_keyboardPlayer = (originalMode == GAME_LAN || originalMode == GAME_INTERNET) ? NULL : m_local;
}
//-----------------------------------------------------------------------------
@@ -252,6 +260,8 @@ void PlayerList::init()
for (int j = 0; j < MAX_PLAYER_COUNT; j++)
m_slotIndices[j] = -1;
+ m_keyboardPlayer = NULL;
+
// call setLocalPlayer so that becomingLocalPlayer() gets called appropriately
setLocalPlayer(m_players[0]);
@@ -465,7 +475,9 @@ void PlayerList::xfer( Xfer *xfer )
{
// version
- XferVersion currentVersion = 1;
+ // 2: the keyboard seat, which newGame would otherwise reset to the local player and so undo a
+ // Shift-Ctrl-T for the shared-look hook
+ XferVersion currentVersion = 2;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
@@ -489,6 +501,13 @@ void PlayerList::xfer( Xfer *xfer )
for( Int i = 0; i < playerCount; ++i )
xfer->xferSnapshot( m_players[ i ] );
+ if( version >= 2 )
+ {
+ Int keyboardIndex = m_keyboardPlayer ? m_keyboardPlayer->getPlayerIndex() : -1;
+ xfer->xferInt( &keyboardIndex );
+ m_keyboardPlayer = keyboardIndex >= 0 ? getNthPlayer( keyboardIndex ) : NULL;
+ }
+
} // end xfer
// ------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerTemplate.cpp b/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerTemplate.cpp
index efc8dc729..0cf055829 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerTemplate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/RTS/PlayerTemplate.cpp
@@ -261,9 +261,9 @@ const Image *PlayerTemplate::getEnabledImage( void ) const
/*extern*/ PlayerTemplateStore *ThePlayerTemplateStore = NULL;
//-----------------------------------------------------------------------------
-PlayerTemplateStore::PlayerTemplateStore()
+PlayerTemplateStore::PlayerTemplateStore()
{
- // nothing
+ m_countBeforeMapOverrides = -1;
}
//-----------------------------------------------------------------------------
@@ -283,6 +283,16 @@ void PlayerTemplateStore::reset()
{
// don't reset this list here; we want to retain this info.
// m_playerTemplates.clear();
+
+ /* Except for what a map.ini changed, which the next match in this process would otherwise play
+ with and a machine that never loaded that map would not: starting money, the side's build
+ list and the rest, by the slot's template. */
+ for (Int i = (Int)m_beforeMapOverrides.size() - 1; i >= 0; --i)
+ m_playerTemplates[m_beforeMapOverrides[i].first] = m_beforeMapOverrides[i].second;
+ m_beforeMapOverrides.clear();
+ if (m_countBeforeMapOverrides >= 0)
+ m_playerTemplates.resize(m_countBeforeMapOverrides);
+ m_countBeforeMapOverrides = -1;
}
//-----------------------------------------------------------------------------
@@ -395,6 +405,13 @@ void PlayerTemplateStore::getAllSideStrings(AsciiStringList *outStringList)
NameKeyType namekey = NAMEKEY(c);
PlayerTemplate* pt = const_cast<PlayerTemplate*>(ThePlayerTemplateStore->findPlayerTemplate(namekey));
+ if (ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES)
+ {
+ if (ThePlayerTemplateStore->m_countBeforeMapOverrides < 0)
+ ThePlayerTemplateStore->m_countBeforeMapOverrides = (Int)ThePlayerTemplateStore->m_playerTemplates.size();
+ if (pt)
+ ThePlayerTemplateStore->m_beforeMapOverrides.push_back(std::make_pair((Int)(pt - &ThePlayerTemplateStore->m_playerTemplates[0]), *pt));
+ }
if (pt)
{
ini->initFromINI(pt, pt->getFieldParse() );
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
index 8dc12c077..c299681ee 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/ControlServer.cpp
@@ -802,6 +802,15 @@ static void handleCommand( const AsciiString &command )
return;
}
+ /* A world command changes this machine's simulation and nobody else's. A network match the
+ lobby started would split on it, and a replay would stop matching its recording; a -netgame
+ match is allowed, on the same terms -scenario is (GameLogic::startNewGame). */
+ if ((TheGameLogic->isInMultiplayerGame() && !TheGlobalData->m_netGameStarted) || TheGameLogic->isInReplayGame())
+ {
+ replyError( "world commands only run in a skirmish or a -netgame match" );
+ return;
+ }
+
if ((Int)thePendingCommands.size() >= CONTROL_MAX_COMMANDS_PER_FRAME)
{
replyError( "too many commands queued for one frame" );
@@ -904,8 +913,8 @@ void ControlServer_poll( void )
void ControlServer_runCommands( void )
{
- if (thePendingCommands.empty())
- return;
+ if (theQuitRequested && TheGameEngine)
+ TheGameEngine->setQuitting( TRUE );
for( std::vector<AsciiString>::iterator it = thePendingCommands.begin();
it != thePendingCommands.end(); ++it )
@@ -922,9 +931,6 @@ void ControlServer_runCommands( void )
}
thePendingCommands.clear();
-
- if (theQuitRequested && TheGameEngine)
- TheGameEngine->setQuitting( TRUE );
}
void ControlServer_shutdown( void )
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
index 4898a4cb4..9814bd5e5 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/FileSystem.cpp
@@ -211,6 +211,15 @@ File* FileSystem::openFile( const Char *filename, Int access )
file = TheLocalFileSystem->openFile( filename, access );
}
+ /* A file made here exists from now on, and doesFileExist may already have said it did not: a
+ map transfer asks before it writes, and the map.ini it then writes was skipped by the loader
+ on the receiving machine, which played with the stock data while the host played with the
+ map's (upstream #991). */
+ if ( file != NULL && (access & File::CREATE) )
+ {
+ m_fileExist[ TheNameKeyGenerator->nameToLowercaseKey( filename ) ] = true;
+ }
+
if ( (TheArchiveFileSystem != NULL) && (file == NULL) )
{
file = TheArchiveFileSystem->openFile( filename );
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp
index b187d2919..a2e095fa2 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/Upgrade.cpp
@@ -227,6 +227,7 @@ UpgradeCenter::UpgradeCenter( void )
m_upgradeList = NULL;
m_nextTemplateMaskBit = 0;
buttonImagesCached = FALSE;
+ m_maskBitBeforeMapOverrides = -1;
} // end UpgradeCenter
@@ -234,7 +235,9 @@ UpgradeCenter::UpgradeCenter( void )
//-------------------------------------------------------------------------------------------------
UpgradeCenter::~UpgradeCenter( void )
{
-
+ for( size_t i = 0; i < m_beforeMapOverrides.size(); ++i )
+ m_beforeMapOverrides[ i ].second->deleteInstance();
+
// delete all the upgrades loaded from the INI database
UpgradeTemplate *next;
while( m_upgradeList )
@@ -282,6 +285,35 @@ void UpgradeCenter::init( void )
//-------------------------------------------------------------------------------------------------
void UpgradeCenter::reset( void )
{
+ /* What a map.ini changed goes back, or the next match in this process researches at that price
+ and speed while a machine that never loaded the map does not. Links stay as they are now: an
+ upgrade the map.ini added may have been linked in beside one it changed. */
+ for( Int i = (Int)m_beforeMapOverrides.size() - 1; i >= 0; --i )
+ {
+ UpgradeTemplate *live = m_beforeMapOverrides[ i ].first;
+ UpgradeTemplate *before = m_beforeMapOverrides[ i ].second;
+ UpgradeTemplate *next = live->friend_getNext();
+ UpgradeTemplate *prev = live->friend_getPrev();
+ *live = *before;
+ live->friend_setNext( next );
+ live->friend_setPrev( prev );
+ before->deleteInstance();
+ }
+ m_beforeMapOverrides.clear();
+
+ /* And what it added goes, with its mask bits. Left in, the next match that loads a map.ini adding
+ upgrades hands them other bits than a machine that never played the first map; the command
+ buttons and objects that named them were overrides, and those are gone by now. */
+ for( size_t i = 0; i < m_addedByMap.size(); ++i )
+ {
+ unlinkUpgrade( m_addedByMap[ i ] );
+ m_addedByMap[ i ]->deleteInstance();
+ }
+ m_addedByMap.clear();
+ if( m_maskBitBeforeMapOverrides >= 0 )
+ m_nextTemplateMaskBit = m_maskBitBeforeMapOverrides;
+ m_maskBitBeforeMapOverrides = -1;
+
if( TheMappedImageCollection && !buttonImagesCached )
{
UpgradeTemplate *upgrade;
@@ -488,9 +520,19 @@ void UpgradeCenter::parseUpgradeDefinition( INI *ini )
{
// allocate a new item
+ if( ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES && TheUpgradeCenter->m_maskBitBeforeMapOverrides < 0 )
+ TheUpgradeCenter->m_maskBitBeforeMapOverrides = TheUpgradeCenter->m_nextTemplateMaskBit;
upgrade = TheUpgradeCenter->newUpgrade( name );
+ if( ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES )
+ TheUpgradeCenter->m_addedByMap.push_back( upgrade );
} // end if
+ else if( ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES )
+ {
+ UpgradeTemplate *before = newInstance(UpgradeTemplate);
+ *before = *upgrade;
+ TheUpgradeCenter->m_beforeMapOverrides.push_back( std::make_pair( upgrade, before ) );
+ }
// sanity
DEBUG_ASSERTCRASH( upgrade, ("parseUpgradeDefinition: Unable to allocate upgrade '%s'\n", name.str()) );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp
index b9ef4ab0b..408b8a86e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp
@@ -619,14 +619,13 @@ CBCommandStatus ControlBar::processCommandUI( GameWindow *control,
} // end if
- // get a new production id to assign to this
- ProductionID productionID = pu->requestUniqueUnitID();
-
- // create a message to build this thing
+ // create a message to build this thing. The second argument is kept for the message's
+ // shape and is unused: the logic mints the production ID, because minting it here moved
+ // the factory's counter on this machine and no other.
GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_QUEUE_UNIT_CREATE );
msg->appendIntegerArgument( whatToBuild->getTemplateID() );
- msg->appendIntegerArgument( productionID );
+ msg->appendIntegerArgument( PRODUCTIONID_INVALID );
msg->appendObjectIDArgument( factory->getID() ); // which of the selected factories builds it
//
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index 913728a5e..fb6ef142c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -2532,16 +2532,15 @@ Bool takeControlOfPlayer( Player *p )
if (!p->isPlayerActive() || !p->isPlayableSide())
return FALSE;
- p->setPlayerType(PLAYER_HUMAN, FALSE); // throws away its AIPlayer, if it had one
+ /* Throwing away the AIPlayer and moving the keyboard seat are the logic's to do, on the frame the
+ message runs, so a replay does them too. Called from here they happened on this machine only
+ and no recording of the match played back. The message goes out as the player being left. */
+ GameMessage *takeOver = TheMessageStream->appendMessage( GameMessage::MSG_CHEAT );
+ takeOver->appendIntegerArgument( CHEAT_TAKE_CONTROL );
+ takeOver->appendIntegerArgument( p->getPlayerIndex() );
+
ThePlayerList->setLocalPlayer(p);
TheInGameUI->deselectAllDrawables();
-
- /* Every driverless base feeds its sight to whoever is at the keyboard (Object::handleShroud), and
- that mask was worked out the last time each object looked - which for a building is when it was
- built. Make them all look again, or the base you just left goes dark behind you. */
- for (Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject())
- obj->handlePartitionCellMaintenance();
-
ThePartitionManager->refreshShroudForLocalPlayer();
TheControlBar->initSpecialPowershortcutBar(p);
TheControlBar->setControlBarSchemeByPlayer(p);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
index b84e05398..1df9b3ce8 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AI.cpp
@@ -316,6 +316,7 @@ AI::AI( void )
m_aiData = NEW TAiData;
m_pathfinder = NEW Pathfinder;
m_nextFormationID = NO_FORMATION_ID;
+ m_lastBuildingPlacementFrame = 0;
}
/**
@@ -352,6 +353,15 @@ void AI::reset( void )
m_nextGroupID = 0;
m_nextFormationID = NO_FORMATION_ID;
getNextFormationID(); // increment once past NO_FORMATION_ID. jba.
+ m_lastBuildingPlacementFrame = 0;
+}
+
+Bool AI::claimBuildingPlacement( UnsignedInt frame )
+{
+ if (m_lastBuildingPlacementFrame == frame && frame != 0)
+ return FALSE;
+ m_lastBuildingPlacementFrame = frame;
+ return TRUE;
}
/**
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
index 4e88c00fa..6fa82f71c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
@@ -12092,6 +12092,11 @@ if (g_UT_startTiming) return false;
if (obj->getAIUpdateInterface()) {
ignoreId = obj->getAIUpdateInterface()->getIgnoredObstacleID();
}
+ /* Collect first, move afterwards. aiMoveAwayFromUnit can recurse into moveAllies and on into
+ a move that destroys this very path, and the walk used to carry on through the freed nodes
+ (upstream #3323): a crash, or a walk that reads whatever the allocator put there next, which
+ is not the same on two machines. The allies are moved in the order the walk met them. */
+ std::vector<ObjectID> alliesToMove;
for( node = path->getLastNode(); node && node != path->getFirstNode(); node = node->getPrevious() ) {
ICoord2D curCell;
worldToCell(node->getPosition(), &curCell);
@@ -12121,27 +12126,33 @@ if (g_UT_startTiming) return false;
// If this is a general clear operation, don't let infantry push vehicles.
if (!path->getBlockedByAlly()) continue;
}
- if( otherObj && otherObj->getAI() && !otherObj->getAI()->isMoving() )
- {
- if( otherObj->getAI()->isAttacking() )
- {
- continue; // Don't move units that are attacking. [8/14/2003]
- }
-
- //Kris: Patch 1.01 November 3, 2003
- //Black Lotus exploit fix -- moving while hacking.
- if( otherObj->testStatus( OBJECT_STATUS_IS_USING_ABILITY ) || otherObj->getAI()->isBusy() )
- {
- continue; // Packing or unpacking objects for example
- }
-
- //DEBUG_LOG(("Moving ally\n"));
- otherObj->getAI()->aiMoveAwayFromUnit(obj, CMD_FROM_AI);
+ if (std::find(alliesToMove.begin(), alliesToMove.end(), otherObj->getID()) == alliesToMove.end()) {
+ alliesToMove.push_back(otherObj->getID());
}
}
}
}
}
+ for (std::vector<ObjectID>::const_iterator it = alliesToMove.begin(); it != alliesToMove.end(); ++it) {
+ Object *otherObj = TheGameLogic->findObjectByID(*it);
+ if( otherObj && otherObj->getAI() && !otherObj->getAI()->isMoving() )
+ {
+ if( otherObj->getAI()->isAttacking() )
+ {
+ continue; // Don't move units that are attacking. [8/14/2003]
+ }
+
+ //Kris: Patch 1.01 November 3, 2003
+ //Black Lotus exploit fix -- moving while hacking.
+ if( otherObj->testStatus( OBJECT_STATUS_IS_USING_ABILITY ) || otherObj->getAI()->isBusy() )
+ {
+ continue; // Packing or unpacking objects for example
+ }
+
+ //DEBUG_LOG(("Moving ally\n"));
+ otherObj->getAI()->aiMoveAwayFromUnit(obj, CMD_FROM_AI);
+ }
+ }
return true;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
index baf7a699c..dbde5853b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp
@@ -38,6 +38,7 @@
#include "Common/Team.h"
#include "Common/ThingFactory.h"
#include "Common/PlayerList.h"
+#include "Common/Recorder.h"
#include "Common/BuildAssistant.h"
#include "Common/ThingTemplate.h"
#include "Common/TunnelTracker.h"
@@ -910,13 +911,10 @@ Object *AIPlayer::buildStructureWithDozer(const ThingTemplate *bldgPlan, BuildLi
The loser waits exactly one frame - a thirtieth of a second on a building that takes half a
minute to put up. The order is the player list order, so every machine defers the same
player on the same frame and a replay still matches. */
- static UnsignedInt s_lastPlacementFrame = 0;
- const UnsignedInt nowFrame = TheGameLogic->getFrame();
- if (s_lastPlacementFrame == nowFrame && nowFrame != 0) {
+ if (!TheAI->claimBuildingPlacement(TheGameLogic->getFrame())) {
m_buildDelay = 1; // try again next frame; doBaseBuilding leaves any value >= 1 alone
return NULL;
}
- s_lastPlacementFrame = nowFrame;
// construct the building
Coord3D pos = *info->getLocation();
pos.z += TheTerrainLogic->getGroundHeight(pos.x, pos.y);
@@ -6439,7 +6437,11 @@ Bool AIPlayer::pickTacticalSpot( const Object *obj, const Coord3D *from, const C
* the retreat and the approaches included. */
Bool AIPlayer::measuringWithoutTactics( void ) const
{
- return TheGlobalData->m_noTacticsSlotParity >= 0 && TheGameLogic->isInSkirmishGame() &&
+ // A skirmish or the playback of one, so a recording made with the switch plays back with it too
+ // (given the switch again: it is a measuring aid and does not travel in the replay).
+ const Int originalMode = (TheRecorder && TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK)
+ ? TheRecorder->getGameMode() : TheGameLogic->getGameMode();
+ return TheGlobalData->m_noTacticsSlotParity >= 0 && originalMode == GAME_SKIRMISH &&
(ThePlayerList->getSlotIndex( m_player->getPlayerIndex() ) & 1) == TheGlobalData->m_noTacticsSlotParity;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp
index e038fca95..ce19d1989 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp
@@ -130,6 +130,19 @@ const ArmorTemplate* ArmorStore::findArmorTemplate(AsciiString name) const
}
}
+//-------------------------------------------------------------------------------------------------
+/** A map.ini changes armour in place and the next match in this process would play with it, where a
+ * machine that never loaded that map plays the stock values. Backwards, so an armour both map.ini and
+ * solo.ini changed goes back to what it was before either. In place, because every ArmorSet holds a
+ * pointer to its template. */
+//-------------------------------------------------------------------------------------------------
+void ArmorStore::reset()
+{
+ for (Int i = (Int)m_beforeMapOverrides.size() - 1; i >= 0; --i)
+ m_armorTemplates[m_beforeMapOverrides[i].first] = m_beforeMapOverrides[i].second;
+ m_beforeMapOverrides.clear();
+}
+
//-------------------------------------------------------------------------------------------------
/*static */ void ArmorStore::parseArmorDefinition(INI *ini)
{
@@ -140,6 +153,9 @@ const ArmorTemplate* ArmorStore::findArmorTemplate(AsciiString name) const
const char *c = ini->getNextToken();
NameKeyType key = TheNameKeyGenerator->nameToKey(c);
+ ArmorTemplateMap::const_iterator existing = TheArmorStore->m_armorTemplates.find(key);
+ if (ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES && existing != TheArmorStore->m_armorTemplates.end())
+ TheArmorStore->m_beforeMapOverrides.push_back(std::make_pair(key, existing->second));
ArmorTemplate& armorTmpl = TheArmorStore->m_armorTemplates[key];
armorTmpl.clear();
ini->initFromINI(&armorTmpl, myFieldParse);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp
index 51e985ece..f251582a8 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/GarrisonContain.cpp
@@ -1241,6 +1241,32 @@ void GarrisonContain::recalcApparentControllingPlayer( void )
m_hideGarrisonedStateFromNonallies = false;
}
+ refreshApparentLook();
+
+ // now that we have an object inside us, we need to get all the garrison point positions
+ // if we don't already have them.
+ if( getObject()->getDrawable() && getContainCount() > 0 )
+ {
+ if ( isEnclosingContainerFor( 0 ) )
+ {
+ if ( m_garrisonPointsInitialized == FALSE )
+ loadGarrisonPoints();
+ }
+ else // must need station points instead
+ {
+ if ( m_stationGarrisonPointsInitialized == FALSE )
+ loadStationGarrisonPoints();
+ }
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The half of recalcApparentControllingPlayer that is only what this machine's player is shown.
+ * A change of local player calls this alone: the whole recalc from there reset an empty building's
+ * team and the hidden-garrison flag on the machine whose player changed, and no other. */
+//-------------------------------------------------------------------------------------------------
+void GarrisonContain::refreshApparentLook( void )
+{
//Only allow the garrison state to be set if the client team knows that it is garrisoned.
Drawable *draw = getObject()->getDrawable();
if( draw )
@@ -1277,26 +1303,6 @@ void GarrisonContain::recalcApparentControllingPlayer( void )
else
draw->setIndicatorColor( controller->getPlayerColor() );
}
-
- // now that we have an object inside us, we need to get all the garrison point positions
- // if we don't already have them.
- if( getContainCount() > 0 )
- {
- if ( isEnclosingContainerFor( 0 ) )
- {
- if ( m_garrisonPointsInitialized == FALSE )
- {
- loadGarrisonPoints();
- }
- }
- else // must need station points instead
- {
- if ( m_stationGarrisonPointsInitialized == FALSE )
- {
- loadStationGarrisonPoints();
- }
- }
- }
}
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp
index 1301e8a82..348b2c750 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp
@@ -1227,6 +1227,11 @@ void OpenContain::monitorConditionChanges( void )
if( draw )
{
currCondition = draw->getModelConditionFlags();
+ /* GARRISONED is set per viewer: GarrisonContain hides it from anyone who has not detected a
+ stealth garrison, so it flips on different frames on the owner's machine and an enemy's, and
+ the redeploy it caused moved occupants on one machine only. The fire points are loaded under
+ flags of their own, so nothing needs a redeploy for this bit. */
+ currCondition.set( MODELCONDITION_GARRISONED, 0 );
if(currCondition != m_conditionState )
stateChanged = TRUE;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Damage/TransitionDamageFX.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Damage/TransitionDamageFX.cpp
index 71467fe9c..25cdcae68 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Damage/TransitionDamageFX.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Damage/TransitionDamageFX.cpp
@@ -360,7 +360,9 @@ void TransitionDamageFX::onBodyDamageStateChange( const DamageInfo* damageInfo,
getDamageTypeFlag( modData->m_damageFXTypes, lastDamageInfo->in.m_damageType ) )
{
- pos = getLocalEffectPos( &modData->m_fxList[ newState ][ i ].locInfo, draw );
+ // Client stream, as for the particle systems below: only the effect uses this spot, and
+ // how many draws the bone pick takes depends on the model art this install loaded.
+ pos = getLocalEffectPos( &modData->m_fxList[ newState ][ i ].locInfo, draw, TRUE );
getObject()->convertBonePosToWorldPos( &pos, NULL, &pos, NULL );
FXList::doFXPos( modData->m_fxList[ newState ][ i ].fx, &pos );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
index ea69cb708..c92e0e538 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
@@ -5313,12 +5313,14 @@ void Object::look()
skirmish screen, or a player taken over with Shift-Ctrl-T - shares its eyes with
whoever is at the keyboard, so you can watch it without switching to it. Both
ways round: switch to that base and your first one keeps feeding you its sight.
- Off in a network game, where the logic must not depend on who is looking. */
- if( getControllingPlayer()->getPlayerType() == PLAYER_HUMAN
- && !TheGameLogic->isInMultiplayerGame()
- && ThePlayerList->getLocalPlayer() )
+ "Whoever is at the keyboard" is the logic's keyboard player, not the local player: a
+ playback's local player is the ReplayObserver, and every human unit's looks came out
+ different from the recording's. NULL in a network game, where the logic must not
+ depend on who is looking. */
+ Player *keyboardPlayer = ThePlayerList->getKeyboardPlayer();
+ if( getControllingPlayer()->getPlayerType() == PLAYER_HUMAN && keyboardPlayer )
{
- lookingMask |= ThePlayerList->getLocalPlayer()->getPlayerMask();
+ lookingMask |= keyboardPlayer->getPlayerMask();
}
// Other players can also be looking through our eyes.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp
index 01cc3814b..8872a64b4 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/ObjectCreationList.cpp
@@ -967,7 +967,8 @@ protected:
di->setModelName(modelName, m_okToChangeModelColor ? obj->getIndicatorColor() : 0, m_shadowType);
if (m_animSets.size() > 0)
{
- Int which = GameLogicRandomValue(0, m_animSets.size()-1);
+ // the animation names only reach the draw module, so the client stream
+ Int which = GameClientRandomValue(0, m_animSets.size()-1);
di->setAnimNames(m_animSets[which].m_animInitial, m_animSets[which].m_animFlying, m_animSets[which].m_animFinal, m_fxFinal);
}
}
@@ -1623,12 +1624,27 @@ void ObjectCreationListStore::addObjectCreationNugget(ObjectCreationNugget* nugg
m_nuggets.push_back(nugget);
}
+//-------------------------------------------------------------------------------------------------
+/** Puts back what a map.ini changed, the way ArmorStore::reset does and for the same reason: the next
+ * match in this process would otherwise create objects from lists no other machine has. The nuggets
+ * a map.ini added stay in m_nuggets, which owns them, and are simply no longer listed. */
+//-------------------------------------------------------------------------------------------------
+void ObjectCreationListStore::reset()
+{
+ for (Int i = (Int)m_beforeMapOverrides.size() - 1; i >= 0; --i)
+ m_ocls[m_beforeMapOverrides[i].first] = m_beforeMapOverrides[i].second;
+ m_beforeMapOverrides.clear();
+}
+
//-------------------------------------------------------------------------------------------------
/*static */ void ObjectCreationListStore::parseObjectCreationListDefinition(INI *ini)
{
// read the ObjectCreationList name
const char *c = ini->getNextToken();
NameKeyType key = TheNameKeyGenerator->nameToKey(c);
+ ObjectCreationListMap::const_iterator existing = TheObjectCreationListStore->m_ocls.find(key);
+ if (ini->getLoadType() == INI_LOAD_CREATE_OVERRIDES && existing != TheObjectCreationListStore->m_ocls.end())
+ TheObjectCreationListStore->m_beforeMapOverrides.push_back(std::make_pair(key, existing->second));
ObjectCreationList& ocl = TheObjectCreationListStore->m_ocls[key];
ocl.clear();
ini->initFromINI(&ocl, TheObjectCreationListFieldParse);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp
index b79c408df..a00ef2834 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/DozerAIUpdate.cpp
@@ -1107,13 +1107,16 @@ void DozerPrimaryIdleState::crc( Xfer *xfer )
void DozerPrimaryIdleState::xfer( Xfer *xfer )
{
// version
- XferVersion currentVersion = 1;
+ // 2: the unfinished-structure scan's timer, or a loaded game scanned on a different frame
+ XferVersion currentVersion = 2;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
xfer->xferUnsignedInt(&m_idleTooLongTimestamp);
xfer->xferInt(&m_idlePlayerNumber);
xfer->xferBool(&m_isMarkedAsIdle);
+ if (version >= 2)
+ xfer->xferUnsignedInt(&m_nextUnfinishedScanFrame);
} // end xfer
// ------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/BoneFXUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/BoneFXUpdate.cpp
index 8092008a2..d3d21a66d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/BoneFXUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/BoneFXUpdate.cpp
@@ -298,6 +298,13 @@ UpdateSleepTime BoneFXUpdate::update( void )
m_active = TRUE;
}
+ /* Resolved here, on the first logic update in a body state, rather than by whichever timer fires
+ first: the particle timer runs on the client stream, so the frame it fired on - and the model
+ state the OCL bones were read under - differed per machine, and OCL objects are logic. */
+ if (m_bonesResolved[m_curBodyState] == FALSE) {
+ resolveBoneLocations();
+ }
+
for (Int i = 0; i < BONE_FX_MAX_BONES; ++i) {
//Check to see if its time to fire off any cool stuff.
if ((m_nextFXFrame[m_curBodyState][i] != -1) && (m_nextFXFrame[m_curBodyState][i] <= now)) {
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/EMPUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/EMPUpdate.cpp
index 6293419e0..0b11906e0 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/EMPUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/EMPUpdate.cpp
@@ -337,7 +337,8 @@ void EMPUpdate::doDisableAttack( void )
sys->attachToObject(curVictim);
sys->setPosition( &offs );
sys->setSystemLifetime(MAX(0, data->m_disabledDuration - 30));
- sys->setInitialDelay(GameLogicRandomValue(1,100));
+ // Client stream too: this line runs only where the drawable and the particle system exist.
+ sys->setInitialDelay(GameClientRandomValue(1,100));
}
}
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/LaserUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/LaserUpdate.cpp
index dd22b7c47..07b00112f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/LaserUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/LaserUpdate.cpp
@@ -202,33 +202,34 @@ void LaserUpdate::clientUpdate( void )
updateStartPos();
updateEndPos();
- if( m_decaying )
+ if( m_decaying || m_widening )
{
- UnsignedInt now = TheGameLogic->getFrame();
- m_currentWidthScalar = 1.0f - (Real)(now - m_decayStartFrame) / (Real)(m_decayFinishFrame - m_decayStartFrame);
+ m_currentWidthScalar = computeWidthScalar( TheGameLogic->getFrame() );
m_dirty = true;
- if( m_currentWidthScalar <= 0.0f )
- {
- m_currentWidthScalar = 0.0f;
+ if( !m_decaying && m_currentWidthScalar >= 1.0f )
+ m_widening = false;
+ }
+}
- //When decay is finished... delete the laser.
- //TheGameLogic->destroyObject( getObject() );
- return;
- }
+//-------------------------------------------------------------------------------------------------
+/** The width on a given logic frame, worked out from the frames alone. The Particle Cannon damages
+ * with this width, so it cannot come from m_currentWidthScalar: that one moves only when the client
+ * updates, and a network game that catches up runs several logic ticks with no client pass between
+ * them, which left the catching-up machine damaging with a width a few frames old. */
+//-------------------------------------------------------------------------------------------------
+Real LaserUpdate::computeWidthScalar( UnsignedInt frame ) const
+{
+ if( m_decaying )
+ {
+ Real scalar = 1.0f - (Real)(frame - m_decayStartFrame) / (Real)(m_decayFinishFrame - m_decayStartFrame);
+ return scalar <= 0.0f ? 0.0f : scalar;
}
- else if( m_widening )
+ if( m_widening )
{
- //We need to resize our laser width based on the growth ratio completed.
- UnsignedInt now = TheGameLogic->getFrame();
- m_currentWidthScalar = (Real)(now - m_widenStartFrame) / (Real)(m_widenFinishFrame - m_widenStartFrame);
- m_dirty = true;
- if( m_currentWidthScalar >= 1.0f )
- {
- m_currentWidthScalar = 1.0f;
- m_widening = false;
- }
+ Real scalar = (Real)(frame - m_widenStartFrame) / (Real)(m_widenFinishFrame - m_widenStartFrame);
+ return scalar >= 1.0f ? 1.0f : scalar;
}
- return;
+ return 1.0f;
}
void LaserUpdate::setDecayFrames( UnsignedInt decayFrames )
@@ -406,7 +407,7 @@ Real LaserUpdate::getCurrentLaserRadius() const
//While it appears the logic is accessing client data, it is actually accessing template module
//data from the client. This value is INI constant thus can't change. It's grouped with other
//laser defining attributes and having it there makes it easier for artists.
- return ldi->getLaserTemplateWidth() * m_currentWidthScalar;
+ return ldi->getLaserTemplateWidth() * computeWidthScalar( TheGameLogic->getFrame() );
}
}
return 0.0f;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp
index e8e0a25c7..28538baee 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ParticleUplinkCannonUpdate.cpp
@@ -776,8 +776,12 @@ UpdateSleepTime ParticleUplinkCannonUpdate::update()
{
//We can see it -- we only want to do anything if we just started seeing it, which means
//we want to add client effects again.
+ /* Not before the logic has cached the bones itself, on its first status change. Caching them
+ here happened on the frame this machine's player first saw the cannon, under whatever
+ model state it had then, and a bone count short by one sets m_invalidSettings - which
+ stops the cannon for good on this machine only. An idle cannon has nothing to show. */
Bool revealThisFrame = m_clientShroudedLastFrame != shrouded;
- if( revealThisFrame )
+ if( revealThisFrame && m_defaultInfoCached )
{
//Only if we reveal this frame, will we add client effects. The logic can take it from
//here on... unless of course we lose sight again.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp
index e9fb7de37..d6cf5d8c0 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptConditions.cpp
@@ -2687,6 +2687,10 @@ Bool ScriptConditions::evaluateSkirmishPlayerHasDiscoveredPlayer(Parameter *pSki
//-------------------------------------------------------------------------------------------------
Bool ScriptConditions::evaluateMusicHasCompleted(Parameter *pMusicParm, Parameter *pIntParm)
{
+ // The music player is this machine's: switched off, or with no device, it never finishes a track.
+ // A multiplayer or skirmish map gets a constant, the way evaluateNamedSelected does.
+ if (TheGameEngine->isMultiplayerSession())
+ return FALSE;
AsciiString str = pMusicParm->getString();
return TheAudio->hasMusicTrackCompleted(str, pIntParm->getInt());
}
@@ -2751,7 +2755,11 @@ Bool ScriptConditions::evaluateCondition( Condition *pCondition )
return evaluateNamedUnitExists(pCondition->getParameter(0));
case Condition::TEAM_HAS_UNITS:
return evaluateHasUnits(pCondition->getParameter(0));
- case Condition::CAMERA_MOVEMENT_FINISHED:
+ case Condition::CAMERA_MOVEMENT_FINISHED:
+ // A scripted camera move runs on this machine's wall clock (W3DView::updateView), so in a
+ // multiplayer or skirmish session it counts as finished at once on every machine.
+ if (TheGameEngine->isMultiplayerSession())
+ return TRUE;
return TheTacticalView->isCameraMovementFinished();
case Condition::TEAM_STATE_IS:
return evaluateTeamStateIs(pCondition->getParameter(0), pCondition->getParameter(1));
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp
index 50dbe7a45..6827a05e1 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptEngine.cpp
@@ -5957,7 +5957,9 @@ Player *ScriptEngine::getPlayerFromAsciiString(const AsciiString& playerString)
if (playerString == LOCAL_PLAYER || (playerString == THE_PLAYER && is_GeneralsChallengeContext))
// Designers have built their Generals' Challenge maps, referencing "ThePlayer" meaning the local player.
// However, they've also built many of their single player maps with this string, where "ThePlayer" is not intended as an alias.
- return ThePlayerList->getLocalPlayer();
+ // The keyboard seat, which a playback keeps where the recording had it; the local player there
+ // is the ReplayObserver. A network game has none and keeps EA's answer.
+ return ThePlayerList->getKeyboardPlayer() ? ThePlayerList->getKeyboardPlayer() : ThePlayerList->getLocalPlayer();
if (playerString == THIS_PLAYER)
return getCurrentPlayer();
else if (playerString == THIS_PLAYER_ENEMY) {
@@ -6082,7 +6084,7 @@ Team * ScriptEngine::getTeamNamed(const AsciiString& teamName)
if (teamName == TEAM_THE_PLAYER && is_GeneralsChallengeContext)
// Designers have built their Generals' Challenge maps, referencing "teamThePlayer" meaning the local player's default (parent) team.
// However, they've also built many of their single player maps with this string, where "teamThePlayer" is not intended as an alias.
- return ThePlayerList->getLocalPlayer()->getDefaultTeam();
+ return (ThePlayerList->getKeyboardPlayer() ? ThePlayerList->getKeyboardPlayer() : ThePlayerList->getLocalPlayer())->getDefaultTeam();
if (teamName == THIS_TEAM) {
if (m_callingTeam)
return m_callingTeam;
@@ -7439,6 +7441,9 @@ Bool ScriptEngine::isSpeechComplete( const AsciiString& testSpeech, Bool removeF
if (findIt == m_testingSpeech.end()) {
PairAsciiStringUINT newPair;
AudioEventRTS event(testSpeech);
+ // Logical, or a sound with several variants picks the one to measure off the audio stream,
+ // which every machine has moved differently by now.
+ event.setIsLogicalAudio(TRUE);
Real audioLength = TheAudio->getAudioLengthMS(&event);
UnsignedInt frameCount = REAL_TO_UNSIGNEDINT(audioLength / MSEC_PER_LOGICFRAME_REAL);
@@ -7474,6 +7479,7 @@ Bool ScriptEngine::isAudioComplete( const AsciiString& testAudio, Bool removeFro
if (findIt == m_testingAudio.end()) {
PairAsciiStringUINT newPair;
AudioEventRTS event(testAudio);
+ event.setIsLogicalAudio(TRUE); // see isSpeechComplete
Real audioLength = TheAudio->getAudioLengthMS(&event);
UnsignedInt frameCount = REAL_TO_UNSIGNEDINT(audioLength / MSEC_PER_LOGICFRAME_REAL);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
index 5b4e4dbbb..1753b7016 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
@@ -1184,6 +1184,14 @@ void GameLogic::startNewGame( Bool loadingSaveGame )
TheWritableGlobalData->m_peaceTime = 0; // -peacetime, and the host's options string is read below
TheWritableGlobalData->m_unitLimit = FALSE; // -unitlimit, the same
}
+ /* The playback of a network game is not a network game, but it replays one that ran the host's
+ options, so a switch given to the playback has to be dropped the same way. */
+ else if (TheRecorder && TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK
+ && (TheRecorder->getGameMode() == GAME_LAN || TheRecorder->getGameMode() == GAME_INTERNET))
+ {
+ TheWritableGlobalData->m_peaceTime = 0;
+ TheWritableGlobalData->m_unitLimit = FALSE;
+ }
m_showBehindBuildingMarkers = TRUE;
m_drawIconUI = TRUE;
@@ -4458,6 +4466,33 @@ void GameLogic::update( void )
TheScriptEngine->UPDATE();
}
+ QueryPerformanceCounter( (LARGE_INTEGER *)&tScripts );
+
+ /* A camera move that freezes time ends on this machine's wall clock, and the scripts above run
+ once per frozen pass: in a multiplayer or skirmish session a machine whose camera took longer
+ counted its script timers down further. There the camera freezes nothing, as the camera
+ condition in ScriptConditions already reports every move finished. */
+ Bool freezeTime = !TheGameEngine->isMultiplayerSession()
+ && TheTacticalView->isTimeFrozen() && !TheTacticalView->isCameraMovementFinished();
+ freezeTime = freezeTime || TheScriptEngine->isTimeFrozenDebug() || TheScriptEngine->isTimeFrozenScript();
+
+ if (freezeTime)
+ {
+ if (TheCommandList->containsMessageOfType(GameMessage::MSG_CLEAR_GAME_DATA))
+ {
+ TheScriptEngine->forceUnfreezeTime();
+ }
+ else
+ {
+ /// @todo - make sure this never happens during a network game. jba.
+ return;
+ }
+ }
+
+ /* The fork's own ticks come after the freeze return. A frozen pass does not advance the frame, so
+ ahead of it they ran once per frozen pass, and how many passes a cinematic takes is camera state
+ that differs per machine: the repair tick healed again on every one of them. */
+
// the lobby's peace time, if the host set one
peaceTimeTick();
@@ -4479,24 +4514,6 @@ void GameLogic::update( void )
happens on a render pass and making an object has to happen in here, so the two are split. */
ControlServer_runCommands();
- QueryPerformanceCounter( (LARGE_INTEGER *)&tScripts );
-
- Bool freezeTime = TheTacticalView->isTimeFrozen() && !TheTacticalView->isCameraMovementFinished();
- freezeTime = freezeTime || TheScriptEngine->isTimeFrozenDebug() || TheScriptEngine->isTimeFrozenScript();
-
- if (freezeTime)
- {
- if (TheCommandList->containsMessageOfType(GameMessage::MSG_CLEAR_GAME_DATA))
- {
- TheScriptEngine->forceUnfreezeTime();
- }
- else
- {
- /// @todo - make sure this never happens during a network game. jba.
- return;
- }
- }
-
// Note - TerrainLogic update needs to happen after ScriptEngine update, but before object updates. jba.
// This way changes in bridges are noted in the script engine before being cleared in TerrainLogic->update
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
index 8c274eac3..ee65356a8 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp
@@ -42,6 +42,7 @@
#include "Common/PlayerTemplate.h"
#include "Common/MessageStream.h"
#include "Common/MultiplayerSettings.h"
+#include "Common/RandomValue.h"
#include "Common/Recorder.h"
#include "Common/BuildAssistant.h"
#include "Common/SpecialPower.h"
@@ -573,6 +574,12 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
TheWritableGlobalData->m_useFpsLimit = true;
}
+ /* Seed again from the number the start was seeded with. Every start seeds when it appends
+ this message, and the logic acts on it a pass later, after the shell map's scripts have
+ run once more on the freshly seeded stream - a draw a copy with -noshellmap, or a replay
+ started from the command line, never made. The recorder writes this same number. */
+ InitRandom( GetGameLogicRandomSeed() );
+
// prepare for new game
prepareNewGame( gameMode, diff, rankPoints );
@@ -1659,11 +1666,12 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
{
Object *producer = NULL;
const ThingTemplate *whatToCreate;
- ProductionID productionID;
- // get data from the message
+ // get data from the message. Argument 1 was a production ID the build button minted
+ // from the factory's counter, which moved the counter on the sender's machine only, so
+ // the next ID a script or a flight deck minted there differed from everyone else's. The
+ // ID is minted below, in logic, on every machine alike.
whatToCreate = TheThingFactory->findByTemplateID( msg->getArgument( 0 )->integer );
- productionID = (ProductionID)msg->getArgument( 1 )->integer;
// an explicit producer (multi-select build) must be one of the selected objects
if( msg->getArgumentCount() > 2 && currentlySelectedGroup )
@@ -1692,7 +1700,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
} // end if
// queue the build
- pu->queueCreateUnit( whatToCreate, productionID );
+ pu->queueCreateUnit( whatToCreate, pu->requestUniqueUnitID() );
break;
@@ -2171,7 +2179,12 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
// a game that used them records them and plays back the same. A network game never takes one.
case GameMessage::MSG_CHEAT:
{
- if( isInMultiplayerGame() )
+ // Refused in a network game, and so in its playback too, or a cheat every machine
+ // ignored during the match would be applied when the replay of it plays. The recorded
+ // mode, not isMultiplayer(): the recorder counts a skirmish as multiplayer.
+ const Int originalMode = (TheRecorder && TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK)
+ ? TheRecorder->getGameMode() : getGameMode();
+ if( originalMode == GAME_LAN || originalMode == GAME_INTERNET )
break;
CheatKind kind = (CheatKind)msg->getArgument( 0 )->integer;
@@ -2209,6 +2222,23 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
case CHEAT_ONE_HIT_KILL:
thisPlayer->toggleCheat( kind );
break;
+
+ /* The logic half of takeControlOfPlayer, a message so the recording has it: the AIPlayer
+ goes, the keyboard seat moves, and every object looks again, or the base just left goes
+ dark behind you - a building's looking mask was worked out when it was built. */
+ case CHEAT_TAKE_CONTROL:
+ {
+ Player *target = ThePlayerList->getNthPlayer( amount );
+ if( target == NULL )
+ break;
+ target->setPlayerType( PLAYER_HUMAN, FALSE );
+ ThePlayerList->setKeyboardPlayer( target );
+ for( Object *obj = getFirstObject(); obj; obj = obj->getNextObject() )
+ obj->handlePartitionCellMaintenance();
+ if( target == ThePlayerList->getLocalPlayer() )
+ ThePartitionManager->refreshShroudForLocalPlayer();
+ break;
+ }
}
break;
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
index 9d2485d54..928fd813e 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DModelDraw.cpp
@@ -59,6 +59,7 @@
#include "GameLogic/WeaponSet.h"
#include "GameLogic/FPUControl.h"
#include "GameLogic/Module/AIUpdate.h"
+#include "GameLogic/Module/ContainModule.h"
#include "GameLogic/Module/PhysicsUpdate.h"
#include "W3DDevice/GameClient/Module/W3DModelDraw.h"
#include "W3DDevice/GameClient/W3DAssetManager.h"
@@ -3526,6 +3527,8 @@ Bool W3DModelDraw::clientOnly_getRenderObjInfo(Coord3D* pos, Real* boundingSpher
return true;
}
+static ModelConditionFlags logicConditionFlags(const Drawable* draw, const ModelConditionFlags& c);
+
//-------------------------------------------------------------------------------------------------
Bool W3DModelDraw::getProjectileLaunchOffset(
const ModelConditionFlags& condition,
@@ -3543,7 +3546,7 @@ Bool W3DModelDraw::getProjectileLaunchOffset(
to get the pristine bone(s) for the state that logic believes to be current,
not the one the client might currently be using...
*/
- const ModelConditionInfo* stateToUse = findBestInfo(condition);
+ const ModelConditionInfo* stateToUse = findBestInfo(logicConditionFlags(getDrawable(), condition));
if (!stateToUse)
{
CRCDEBUG_LOG(("can't find best info\n"));
@@ -3692,7 +3695,7 @@ Int W3DModelDraw::getPristineBonePositionsForConditionState(
to get the pristine bone(s) for the state that logic believes to be current,
not the one the client might currently be using...
*/
- const ModelConditionInfo* stateToUse = findBestInfo(condition);
+ const ModelConditionInfo* stateToUse = findBestInfo(logicConditionFlags(getDrawable(), condition));
if (!stateToUse)
return 0;
@@ -3964,11 +3967,36 @@ const ModelConditionInfo* W3DModelDraw::findBestInfo(const ModelConditionFlags&
return getW3DModelDrawModuleData()->findBestInfo(c);
}
+//-------------------------------------------------------------------------------------------------
+/** The flags a question from the logic is answered under. GARRISONED is set per viewer:
+ * GarrisonContain keeps it off a building full of undetected stealth units on every machine but
+ * its owner's and allies'. Bones, barrels and launch points picked under it came out different
+ * per machine, so logic asks with the owner's answer, which is whether anyone is inside. */
+//-------------------------------------------------------------------------------------------------
+static ModelConditionFlags logicConditionFlags(const Drawable* draw, const ModelConditionFlags& c)
+{
+ ModelConditionFlags flags = c;
+ const Object* obj = draw->getObject();
+ const ContainModuleInterface* contain = obj ? obj->getContain() : NULL;
+ if (contain && contain->isGarrisonable())
+ flags.set(MODELCONDITION_GARRISONED, contain->getContainCount() > 0 ? 1 : 0);
+ return flags;
+}
+
//-------------------------------------------------------------------------------------------------
Int W3DModelDraw::getBarrelCount(WeaponSlotType wslot) const
{
- return (m_curState && (m_curState->m_validStuff & ModelConditionInfo::BARRELS_VALID)) ?
- m_curState->m_weaponBarrelInfoVec[wslot].size() : 0;
+ /*
+ The weapon asks this, so it has to answer for the state logic believes to be current, the way
+ getProjectileLaunchOffset does. m_curState leaves a transition only when this drawable is drawn,
+ and whether it is drawn is this machine's camera and fog.
+ */
+ const ModelConditionInfo* stateToUse = findBestInfo(logicConditionFlags(getDrawable(), getDrawable()->getModelConditionFlags()));
+ if (!stateToUse)
+ return 0;
+ stateToUse->validateStuff(NULL, getDrawable()->getScale(), getW3DModelDrawModuleData()->m_extraPublicBones);
+ return (stateToUse->m_validStuff & ModelConditionInfo::BARRELS_VALID) ?
+ stateToUse->m_weaponBarrelInfoVec[wslot].size() : 0;
}
//-------------------------------------------------------------------------------------------------