GameLogicDispatch.cpp 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: GameLogicDispatch.cpp ////////////////////////////////////////////////////////////////////
  24. // Author: Mike Booth, Colin Day
  25. // Description: Message logic to drive the game play
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/CRCDebug.h"
  30. #include "Common/GameAudio.h"
  31. #include "Common/GameEngine.h"
  32. #include "Common/GlobalData.h"
  33. #include "Common/NameKeyGenerator.h"
  34. #include "Common/ThingFactory.h"
  35. #include "Common/Player.h"
  36. #include "Common/PlayerList.h"
  37. #include "Common/PlayerTemplate.h"
  38. #include "Common/MessageStream.h"
  39. #include "Common/MultiplayerSettings.h"
  40. #include "Common/Recorder.h"
  41. #include "Common/BuildAssistant.h"
  42. #include "Common/SpecialPower.h"
  43. #include "Common/ThingTemplate.h"
  44. #include "Common/Upgrade.h"
  45. #include "Common/StatsCollector.h"
  46. #include "Common/Radar.h"
  47. #include "GameLogic/AIPathfind.h"
  48. #include "GameLogic/GameLogic.h"
  49. #include "GameLogic/Locomotor.h"
  50. #include "GameLogic/Object.h"
  51. #include "GameLogic/ObjectCreationList.h"
  52. #include "GameLogic/ObjectIter.h"
  53. //#include "GameLogic/PartitionManager.h"
  54. #include "GameLogic/AI.h"
  55. #include "GameLogic/Module/AIUpdate.h"
  56. #include "GameLogic/Module/BodyModule.h"
  57. #include "GameLogic/Module/OpenContain.h"
  58. #include "GameLogic/Module/ProductionUpdate.h"
  59. #include "GameLogic/Module/SpecialPowerModule.h"
  60. #include "GameLogic/ScriptActions.h"
  61. #include "GameLogic/ScriptEngine.h"
  62. #include "GameLogic/VictoryConditions.h"
  63. #include "GameLogic/Weapon.h"
  64. #include "GameClient/CommandXlat.h"
  65. #include "GameClient/ControlBar.h"
  66. #include "GameClient/Drawable.h"
  67. #include "GameClient/Eva.h"
  68. #include "GameClient/GameText.h"
  69. #include "GameClient/GameWindowTransitions.h"
  70. #include "GameClient/GameWindowManager.h"
  71. #include "GameClient/GuiCallbacks.h"
  72. #include "GameClient/InGameUI.h"
  73. #include "GameClient/KeyDefs.h"
  74. #include "GameClient/Mouse.h"
  75. #include "GameClient/ParticleSys.h"
  76. #include "GameClient/Shell.h"
  77. #include "GameClient/Module/BeaconClientUpdate.h"
  78. #include "GameClient/LookAtXlat.h"
  79. #include "GameNetwork/NetworkInterface.h"
  80. #ifdef _INTERNAL
  81. // for occasional debugging...
  82. //#pragma optimize("", off)
  83. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  84. #endif
  85. #define MAX_PATH_SUBJECTS 64
  86. static Bool theBuildPlan = false;
  87. static Object *thePlanSubject[ MAX_PATH_SUBJECTS ];
  88. static int thePlanSubjectCount = 0;
  89. //static WindowLayout *background = NULL;
  90. // ------------------------------------------------------------------------------------------------
  91. /** Issue the movement command to the object */
  92. // ------------------------------------------------------------------------------------------------
  93. static void doMoveTo( Object *obj, const Coord3D *pos )
  94. {
  95. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  96. DEBUG_ASSERTCRASH(ai, ("Attemped doMoveTo() on an Object with no AI\n"));
  97. if (ai)
  98. {
  99. if (theBuildPlan)
  100. {
  101. int i;
  102. // if this object isn't in the buildPlan set, add it
  103. for( i=0; i<thePlanSubjectCount; i++ )
  104. if (thePlanSubject[i] == obj)
  105. break;
  106. if (i == thePlanSubjectCount)
  107. thePlanSubject[ thePlanSubjectCount++ ] = obj;
  108. ai->queueWaypoint( pos );
  109. }
  110. else
  111. {
  112. ai->clearWaypointQueue();
  113. obj->leaveGroup();
  114. obj->releaseWeaponLock(LOCKED_TEMPORARILY); // release any temporary locks.
  115. ai->aiMoveToPosition( pos, CMD_FROM_PLAYER );
  116. }
  117. }
  118. }
  119. // ------------------------------------------------------------------------------------------------
  120. // ------------------------------------------------------------------------------------------------
  121. static void doSetRallyPoint( Object *obj, const Coord3D& pos )
  122. {
  123. Bool isLocalPlayer = obj->isLocallyControlled();
  124. //
  125. // we must be able to find a path from the object to the point they have chosen, cause setting
  126. // a rally point at a invalid location would suck. To be super nice, we have to make sure
  127. // that every type of object that can be created from the thing setting the rally point
  128. // can actually find a path from the thing to the point
  129. //
  130. // to see the never-finished code to check all locomotor sets, see past revs of GUICommandTranslator.cpp -MDC
  131. //
  132. // for now, just use the basic human locomotor ... and enable the above code when Steven
  133. // tells me how to get the locomotor sets based on a thing template (CBD)
  134. //
  135. NameKeyType key = NAMEKEY( "BasicHumanLocomotor" );
  136. LocomotorSet locomotorSet;
  137. locomotorSet.addLocomotor( TheLocomotorStore->findLocomotorTemplate( key ) );
  138. if( TheAI->pathfinder()->clientSafeQuickDoesPathExist( locomotorSet, obj->getPosition(), &pos ) == FALSE )
  139. {
  140. // user feedback
  141. if( isLocalPlayer )
  142. {
  143. // display error message to user
  144. TheInGameUI->message( TheGameText->fetch( "GUI:RallyPointNoPath" ) );
  145. // play the no can do sound
  146. static AudioEventRTS rallyNotSet("UnableToSetRallyPoint");
  147. rallyNotSet.setPosition(&pos);
  148. TheAudio->addAudioEvent(&rallyNotSet);
  149. } // end if
  150. return;
  151. } // end if
  152. // feedback to the player
  153. if( isLocalPlayer )
  154. {
  155. // print a message to the user
  156. UnicodeString info;
  157. info.format( TheGameText->fetch( "GUI:RallyPointSet" ),
  158. obj->getTemplate()->getDisplayName().str() );
  159. TheInGameUI->message( info );
  160. // play a sound for setting the rally point
  161. static AudioEventRTS rallyPointSet("RallyPointSet");
  162. rallyPointSet.setPosition(&pos);
  163. rallyPointSet.setPlayerIndex(obj->getControllingPlayer()->getPlayerIndex());
  164. TheAudio->addAudioEvent(&rallyPointSet);
  165. // mark the UI as dirty so that we re-evaluate the selection and show the rally point
  166. Drawable *draw = obj->getDrawable();
  167. if( draw && draw->isSelected() )
  168. TheControlBar->markUIDirty();
  169. } // end if
  170. // if this object has a ProductionExitUpdate interface, we are setting a rally point
  171. ExitInterface *exitInterface = obj->getObjectExitInterface();
  172. if( exitInterface )
  173. {
  174. // set the rally point
  175. exitInterface->setRallyPoint( &pos );
  176. }
  177. }
  178. static Object * getSingleObjectFromSelection(const AIGroup *currentlySelectedGroup)
  179. {
  180. if( currentlySelectedGroup )
  181. {
  182. const VecObjectID& selectedObjects = currentlySelectedGroup->getAllIDs();
  183. DEBUG_ASSERTCRASH(selectedObjects.size() == 1, ("Trying to get single object from multiple selection!"));
  184. VecObjectID::const_iterator it = selectedObjects.begin();
  185. return TheGameLogic->findObjectByID(*it);
  186. }
  187. return NULL;
  188. }
  189. // ------------------------------------------------------------------------------------------------
  190. // ------------------------------------------------------------------------------------------------
  191. void GameLogic::closeWindows( void )
  192. {
  193. HideDiplomacy();
  194. ResetDiplomacy();
  195. HideInGameChat();
  196. ResetInGameChat();
  197. TheControlBar->hidePurchaseScience();
  198. TheControlBar->hideSpecialPowerShortcut();
  199. HideQuitMenu();
  200. // hide the options menu
  201. NameKeyType buttonID = TheNameKeyGenerator->nameToKey( "OptionsMenu.wnd:ButtonBack" );
  202. GameWindow *button = TheWindowManager->winGetWindowFromId( NULL, buttonID );
  203. GameWindow *window = TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey("OptionsMenu.wnd:OptionsMenuParent") );
  204. if(window)
  205. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  206. (WindowMsgData)button, buttonID );
  207. }
  208. // ------------------------------------------------------------------------------------------------
  209. // ------------------------------------------------------------------------------------------------
  210. void GameLogic::clearGameData( Bool showScoreScreen )
  211. {
  212. if( !isInGame() )
  213. {
  214. DEBUG_CRASH(("We tried to clear the game data when we weren't in a game"));
  215. return;
  216. }
  217. setClearingGameData( TRUE );
  218. // m_background = TheWindowManager->winCreateLayout("Menus/BlankWindow.wnd");
  219. // DEBUG_ASSERTCRASH(m_background,("We Couldn't Load Menus/BlankWindow.wnd"));
  220. // m_background->hide(FALSE);
  221. // m_background->bringForward();
  222. // reset the game engine to accept data for a new game
  223. if(TheStatsCollector)
  224. TheStatsCollector->writeFileEnd();
  225. TheScriptActions->closeWindows(FALSE); // Close victory or defeat windows.
  226. Bool shellGame = FALSE;
  227. if ((!isInShellGame() || !isInGame()) && showScoreScreen)
  228. {
  229. shellGame = TRUE;
  230. TheTransitionHandler->setGroup("FadeWholeScreen");
  231. TheShell->push("Menus/ScoreScreen.wnd");
  232. TheShell->showShell(FALSE); // by passing in false, we don't want to run the Init on the shell screen we just pushed on
  233. TheTransitionHandler->reverse("FadeWholeScreen");
  234. void FixupScoreScreenMovieWindow( void );
  235. FixupScoreScreenMovieWindow();
  236. }
  237. TheGameEngine->reset();
  238. setGameMode(GAME_NONE);
  239. // m_background->bringForward();
  240. // if(shellGame)
  241. if (TheGlobalData->m_initialFile.isEmpty() == FALSE)
  242. {
  243. TheGameEngine->setQuitting(TRUE);
  244. }
  245. HideControlBar();
  246. closeWindows();
  247. TheMouse->setVisibility(TRUE);
  248. if(m_background)
  249. {
  250. m_background->destroyWindows();
  251. m_background->deleteInstance();
  252. m_background = NULL;
  253. }
  254. setClearingGameData( FALSE );
  255. }
  256. // ------------------------------------------------------------------------------------------------
  257. /** Prepare for a new game */
  258. // ------------------------------------------------------------------------------------------------
  259. void GameLogic::prepareNewGame( Int gameMode, GameDifficulty diff, Int rankPoints )
  260. {
  261. //Added By Sadullah Nader
  262. //Fix for loading game scene
  263. //Kris: Commented this out, but leaving it around incase it bites us later. I cleaned up the
  264. // nomenclature. Look for setLoadingMap() and setLoadingSave()
  265. //setGameLoading(TRUE);
  266. TheScriptEngine->setGlobalDifficulty(diff);
  267. if(!m_background)
  268. {
  269. m_background = TheWindowManager->winCreateLayout("Menus/BlankWindow.wnd");
  270. DEBUG_ASSERTCRASH(m_background,("We Couldn't Load Menus/BlankWindow.wnd"));
  271. m_background->hide(FALSE);
  272. m_background->bringForward();
  273. }
  274. m_background->getFirstWindow()->winClearStatus(WIN_STATUS_IMAGE);
  275. TheGameLogic->setGameMode( gameMode );
  276. if (!TheGlobalData->m_pendingFile.isEmpty())
  277. {
  278. TheWritableGlobalData->m_mapName = TheGlobalData->m_pendingFile;
  279. TheWritableGlobalData->m_pendingFile.clear();
  280. }
  281. m_rankPointsToAddAtGameStart = rankPoints;
  282. DEBUG_LOG(("GameLogic::prepareNewGame() - m_rankPointsToAddAtGameStart = %d\n", m_rankPointsToAddAtGameStart));
  283. // If we're about to start a game, hide the shell.
  284. if(!TheGameLogic->isInShellGame())
  285. TheShell->hideShell();
  286. m_startNewGame = FALSE;
  287. } // end prepareNewGame
  288. //-------------------------------------------------------------------------------------------------
  289. /** This message handles dispatches object command messages to the
  290. * appropriate objects.
  291. * @todo Rename this to "CommandProcessor", or similiar. */
  292. //-------------------------------------------------------------------------------------------------
  293. void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
  294. {
  295. #ifdef _DEBUG
  296. DEBUG_ASSERTCRASH(msg != NULL && msg != (GameMessage*)0xdeadbeef, ("bad msg"));
  297. #endif
  298. Player *thisPlayer = ThePlayerList->getNthPlayer( msg->getPlayerIndex() );
  299. DEBUG_ASSERTCRASH( thisPlayer, ("logicMessageDispatcher: Processing message from unknown player (player index '%d')\n",
  300. msg->getPlayerIndex()) );
  301. AIGroup *currentlySelectedGroup = NULL;
  302. if (isInGame())
  303. {
  304. if (msg->getType() >= GameMessage::MSG_BEGIN_NETWORK_MESSAGES && msg->getType() <= GameMessage::MSG_END_NETWORK_MESSAGES)
  305. {
  306. if (msg->getType() != GameMessage::MSG_LOGIC_CRC && msg->getType() != GameMessage::MSG_SET_REPLAY_CAMERA)
  307. {
  308. currentlySelectedGroup = TheAI->createGroup(); // can't do this outside a game - it'll cause sync errors galore.
  309. CRCGEN_LOG(( "Creating AIGroup %d in GameLogic::logicMessageDispatcher()\n", (currentlySelectedGroup)?currentlySelectedGroup->getID():0 ));
  310. thisPlayer->getCurrentSelectionAsAIGroup(currentlySelectedGroup);
  311. // We can't issue commands to groups that contain units that don't belong the issuing player, so pretend like
  312. // there's nothing selected. Also, if currentlySelectedGroup is empty, go ahead and delete it, so that we can skip
  313. // any processing on it.
  314. if (currentlySelectedGroup->isEmpty())
  315. {
  316. TheAI->destroyGroup(currentlySelectedGroup);
  317. currentlySelectedGroup = NULL;
  318. }
  319. // If there are any units that the player doesn't own, then remove them from the "currentlySelectedGroup"
  320. if (currentlySelectedGroup)
  321. if (currentlySelectedGroup->removeAnyObjectsNotOwnedByPlayer(thisPlayer))
  322. currentlySelectedGroup = NULL;
  323. if(TheStatsCollector)
  324. TheStatsCollector->collectMsgStats(msg);
  325. }
  326. }
  327. }
  328. #ifdef DEBUG_LOGGING
  329. AsciiString commandName;
  330. commandName = msg->getCommandAsAsciiString();
  331. if (msg->getType() < GameMessage::MSG_BEGIN_NETWORK_MESSAGES || msg->getType() > GameMessage::MSG_END_NETWORK_MESSAGES)
  332. {
  333. commandName.concat(" (NON-LOGIC-MESSAGE!!!)");
  334. }
  335. else if (msg->getType() == GameMessage::MSG_BEGIN_NETWORK_MESSAGES)
  336. {
  337. commandName = " (CRC message!)";
  338. }
  339. #if 0
  340. if (commandName.isNotEmpty() /*&& msg->getType() != GameMessage::MSG_FRAME_TICK*/)
  341. {
  342. DEBUG_LOG(("Frame %d: GameLogic::logicMessageDispatcher() saw a %s from player %d (%ls)\n", getFrame(), commandName.str(),
  343. msg->getPlayerIndex(), thisPlayer->getPlayerDisplayName().str()));
  344. }
  345. #endif
  346. #endif // DEBUG_LOGGING
  347. // process the message
  348. GameMessage::Type msgType = msg->getType();
  349. switch( msgType )
  350. {
  351. //---------------------------------------------------------------------------------------------
  352. case GameMessage::MSG_NEW_GAME:
  353. {
  354. //DEBUG_ASSERTCRASH(msg->getArgumentCount() == 1 || msg->getArgumentCount() == 2, ("%d arguments to MSG_NEW_GAME", msg->getArgumentCount()));
  355. Int gameMode = msg->getArgument( 0 )->integer;
  356. Int rankPoints = 0;
  357. GameDifficulty diff = DIFFICULTY_NORMAL;
  358. if ( msg->getArgumentCount() >= 2 )
  359. diff = (GameDifficulty)msg->getArgument( 1 )->integer;
  360. if ( msg->getArgumentCount() >= 3 )
  361. rankPoints = msg->getArgument( 2 )->integer;
  362. if ( msg->getArgumentCount() >= 4 )
  363. {
  364. Int maxFPS = msg->getArgument( 3 )->integer;
  365. if (maxFPS < 1 || maxFPS > 1000)
  366. maxFPS = TheGlobalData->m_framesPerSecondLimit;
  367. DEBUG_LOG(("Setting max FPS limit to %d FPS\n", maxFPS));
  368. TheGameEngine->setFramesPerSecondLimit(maxFPS);
  369. TheWritableGlobalData->m_useFpsLimit = true;
  370. }
  371. // prepare for new game
  372. prepareNewGame( gameMode, diff, rankPoints );
  373. // start new game
  374. startNewGame( FALSE );
  375. break;
  376. } // end new game
  377. //---------------------------------------------------------------------------------------------
  378. case GameMessage::MSG_CLEAR_GAME_DATA:
  379. {
  380. #if defined(_DEBUG) || defined(_INTERNAL)
  381. if (TheDisplay && TheGlobalData->m_dumpAssetUsage)
  382. TheDisplay->dumpAssetUsage(TheGlobalData->m_mapName.str());
  383. #endif
  384. if (currentlySelectedGroup)
  385. TheAI->destroyGroup(currentlySelectedGroup);
  386. currentlySelectedGroup = NULL;
  387. TheGameLogic->clearGameData();
  388. break;
  389. } // end clear game data
  390. //---------------------------------------------------------------------------------------------
  391. case GameMessage::MSG_META_BEGIN_PATH_BUILD:
  392. {
  393. DEBUG_LOG(("META: begin path build\n"));
  394. DEBUG_ASSERTCRASH(!theBuildPlan, ("mismatched theBuildPlan"));
  395. if (theBuildPlan == false)
  396. {
  397. theBuildPlan = true;
  398. thePlanSubjectCount = 0;
  399. }
  400. break;
  401. }
  402. //---------------------------------------------------------------------------------------------
  403. case GameMessage::MSG_META_END_PATH_BUILD:
  404. {
  405. DEBUG_LOG(("META: end path build\n"));
  406. DEBUG_ASSERTCRASH(theBuildPlan, ("mismatched theBuildPlan"));
  407. // tell everyone who participated in the plan to move
  408. for( int i=0; i<thePlanSubjectCount; i++ )
  409. {
  410. AIUpdateInterface *ai = thePlanSubject[i]->getAIUpdateInterface();
  411. if (ai)
  412. ai->executeWaypointQueue();
  413. }
  414. theBuildPlan = false;
  415. thePlanSubjectCount = 0;
  416. break;
  417. }
  418. //---------------------------------------------------------------------------------------------
  419. case GameMessage::MSG_SET_RALLY_POINT:
  420. {
  421. Object *obj = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  422. Coord3D dest = msg->getArgument( 1 )->location;
  423. if (obj)
  424. {
  425. doSetRallyPoint( obj, dest );
  426. }
  427. break;
  428. }
  429. //---------------------------------------------------------------------------------------------
  430. case GameMessage::MSG_DO_WEAPON:
  431. {
  432. WeaponSlotType weaponSlot = (WeaponSlotType)msg->getArgument( 0 )->integer;
  433. Int maxShotsToFire = msg->getArgument( 1 )->integer;
  434. // lock it just till the weapon is empty or the attack is "done"
  435. if( currentlySelectedGroup && currentlySelectedGroup->setWeaponLockForGroup( weaponSlot, LOCKED_TEMPORARILY ))
  436. {
  437. currentlySelectedGroup->groupAttackPosition( NULL, maxShotsToFire, CMD_FROM_PLAYER );
  438. }
  439. break;
  440. }
  441. //---------------------------------------------------------------------------------------------
  442. case GameMessage::MSG_COMBATDROP_AT_OBJECT:
  443. {
  444. Object *targetObject = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  445. // issue command for either single object or for selected group
  446. if( currentlySelectedGroup )
  447. currentlySelectedGroup->groupCombatDrop( targetObject,
  448. *targetObject->getPosition(),
  449. CMD_FROM_PLAYER );
  450. /*
  451. if( sourceObject && targetObject )
  452. {
  453. AIUpdateInterface* sourceAI = sourceObject->getAIUpdateInterface();
  454. if (sourceAI)
  455. {
  456. sourceAI->aiCombatDrop( targetObject, *targetObject->getPosition(), CMD_FROM_PLAYER );
  457. }
  458. }
  459. */
  460. break;
  461. } // end GameMessage::MSG_COMBATDROP_AT_OBJECT
  462. //---------------------------------------------------------------------------------------------
  463. case GameMessage::MSG_COMBATDROP_AT_LOCATION:
  464. {
  465. Coord3D targetLoc = msg->getArgument( 0 )->location;
  466. if( currentlySelectedGroup )
  467. currentlySelectedGroup->groupCombatDrop( NULL, targetLoc, CMD_FROM_PLAYER );
  468. /*
  469. if( sourceObject )
  470. {
  471. AIUpdateInterface* sourceAI = sourceObject->getAIUpdateInterface();
  472. if (sourceAI)
  473. {
  474. sourceAI->aiCombatDrop( NULL, targetLoc, CMD_FROM_PLAYER );
  475. }
  476. }
  477. */
  478. break;
  479. } // end GameMessage::MSG_COMBATDROP_AT_LOCATION
  480. //---------------------------------------------------------------------------------------------
  481. case GameMessage::MSG_DO_WEAPON_AT_OBJECT:
  482. {
  483. // Lock the weapon choice to the right weapon, then give an attack command
  484. WeaponSlotType weaponSlot = (WeaponSlotType)msg->getArgument( 0 )->integer;
  485. Object *targetObject = TheGameLogic->findObjectByID( msg->getArgument( 1 )->objectID );
  486. Int maxShotsToFire = msg->getArgument( 2 )->integer;
  487. // sanity
  488. if( targetObject == NULL )
  489. break;
  490. // issue command for either single object or for selected group
  491. if( currentlySelectedGroup )
  492. {
  493. // lock it just till the weapon is empty or the attack is "done"
  494. if (currentlySelectedGroup->setWeaponLockForGroup( weaponSlot, LOCKED_TEMPORARILY ))
  495. currentlySelectedGroup->groupAttackObject( targetObject, maxShotsToFire, CMD_FROM_PLAYER );
  496. } // end if, command for group
  497. break;
  498. } // end do weapon at object
  499. //---------------------------------------------------------------------------------------------
  500. case GameMessage::MSG_SWITCH_WEAPONS:
  501. {
  502. // use the selected group
  503. WeaponSlotType weaponSlot = (WeaponSlotType)msg->getArgument( 0 )->integer;
  504. // lock until un-switched, or switched to something else.
  505. if( currentlySelectedGroup )
  506. currentlySelectedGroup->setWeaponLockForGroup( weaponSlot, LOCKED_PERMANENTLY );
  507. break;
  508. }
  509. //---------------------------------------------------------------------------------------------
  510. case GameMessage::MSG_SET_MINE_CLEARING_DETAIL:
  511. {
  512. if( currentlySelectedGroup )
  513. {
  514. currentlySelectedGroup->setMineClearingDetail(true);
  515. }
  516. break;
  517. }
  518. case GameMessage::MSG_ENABLE_RETALIATION_MODE:
  519. {
  520. //Logically turns on or off retaliation mode for a specified player.
  521. Int playerIndex = msg->getArgument( 0 )->integer;
  522. Bool enableRetaliation = msg->getArgument( 1 )->boolean;
  523. Player *player = ThePlayerList->getNthPlayer( playerIndex );
  524. if( player )
  525. {
  526. player->setLogicalRetaliationModeEnabled( enableRetaliation );
  527. }
  528. break;
  529. }
  530. //---------------------------------------------------------------------------------------------
  531. case GameMessage::MSG_DO_WEAPON_AT_LOCATION:
  532. {
  533. WeaponSlotType weaponSlot = (WeaponSlotType)msg->getArgument( 0 )->integer;
  534. Coord3D targetLoc = msg->getArgument( 1 )->location;
  535. Int maxShotsToFire = msg->getArgument( 2 )->integer;
  536. // issue command for either single object or for selected group
  537. if( currentlySelectedGroup )
  538. {
  539. // lock it just till the weapon is empty or the attack is "done"
  540. if (currentlySelectedGroup->setWeaponLockForGroup( weaponSlot, LOCKED_TEMPORARILY ))
  541. currentlySelectedGroup->groupAttackPosition( &targetLoc, maxShotsToFire, CMD_FROM_PLAYER );
  542. } // end if, command for group
  543. break;
  544. } //end do weapon at location
  545. //---------------------------------------------------------------------------------------------
  546. case GameMessage::MSG_DO_SPECIAL_POWER:
  547. {
  548. // first argument is the special power ID
  549. UnsignedInt specialPowerID = msg->getArgument( 0 )->integer;
  550. // Command button options -- special power may care about variance options
  551. UnsignedInt options = msg->getArgument( 1 )->integer;
  552. // check for possible specific source, ignoring selection.
  553. ObjectID sourceID = msg->getArgument(2)->objectID;
  554. Object* source = TheGameLogic->findObjectByID(sourceID);
  555. if (source != NULL)
  556. {
  557. AIGroup* theGroup = TheAI->createGroup();
  558. theGroup->add(source);
  559. theGroup->groupDoSpecialPower( specialPowerID, options );
  560. TheAI->destroyGroup(theGroup);
  561. }
  562. else
  563. {
  564. //Use the selected group!
  565. if( currentlySelectedGroup )
  566. {
  567. currentlySelectedGroup->groupDoSpecialPower( specialPowerID, options );
  568. }
  569. }
  570. break;
  571. } // end do special
  572. //---------------------------------------------------------------------------------------------
  573. case GameMessage::MSG_DO_SPECIAL_POWER_AT_LOCATION:
  574. {
  575. // first argument is the special power ID
  576. UnsignedInt specialPowerID = msg->getArgument( 0 )->integer;
  577. // Location argument 2 is destination
  578. Coord3D targetCoord = msg->getArgument(1)->location;
  579. // Angle argument 3 is the orientation of the special power (if applicable)
  580. Real angle = msg->getArgument(2)->real;
  581. // Object in way -- if applicable (some specials care, others don't)
  582. ObjectID objectID = msg->getArgument( 3 )->objectID;
  583. Object *objectInWay = TheGameLogic->findObjectByID( objectID );
  584. // Command button options -- special power may care about variance options
  585. UnsignedInt options = msg->getArgument( 4 )->integer;
  586. // check for possible specific source, ignoring selection.
  587. ObjectID sourceID = msg->getArgument(5)->objectID;
  588. Object* source = TheGameLogic->findObjectByID(sourceID);
  589. if (source != NULL)
  590. {
  591. AIGroup* theGroup = TheAI->createGroup();
  592. theGroup->add(source);
  593. theGroup->groupDoSpecialPowerAtLocation( specialPowerID, &targetCoord, angle, objectInWay, options );
  594. TheAI->destroyGroup(theGroup);
  595. }
  596. else
  597. {
  598. //Use the selected group!
  599. if( currentlySelectedGroup )
  600. {
  601. currentlySelectedGroup->groupDoSpecialPowerAtLocation( specialPowerID, &targetCoord, angle, objectInWay, options );
  602. }
  603. }
  604. break;
  605. } // end do special at location
  606. //---------------------------------------------------------------------------------------------
  607. case GameMessage::MSG_DO_SPECIAL_POWER_AT_OBJECT:
  608. {
  609. // first argument is the special power ID
  610. UnsignedInt specialPowerID = msg->getArgument( 0 )->integer;
  611. // argument 2 is target object
  612. ObjectID targetID = msg->getArgument(1)->objectID;
  613. Object *target = TheGameLogic->findObjectByID( targetID );
  614. if( !target )
  615. {
  616. break;
  617. }
  618. // Command button options -- special power may care about variance options
  619. UnsignedInt options = msg->getArgument( 2 )->integer;
  620. // check for possible specific source, ignoring selection.
  621. ObjectID sourceID = msg->getArgument(3)->objectID;
  622. Object* source = TheGameLogic->findObjectByID(sourceID);
  623. if (source != NULL)
  624. {
  625. AIGroup* theGroup = TheAI->createGroup();
  626. theGroup->add(source);
  627. theGroup->groupDoSpecialPowerAtObject( specialPowerID, target, options );
  628. TheAI->destroyGroup(theGroup);
  629. }
  630. else
  631. {
  632. if( currentlySelectedGroup )
  633. {
  634. currentlySelectedGroup->groupDoSpecialPowerAtObject( specialPowerID, target, options );
  635. }
  636. }
  637. break;
  638. } // end do special at object
  639. //---------------------------------------------------------------------------------------------
  640. case GameMessage::MSG_DO_ATTACKMOVETO:
  641. {
  642. Coord3D dest = msg->getArgument( 0 )->location;
  643. if (currentlySelectedGroup)
  644. {
  645. currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
  646. currentlySelectedGroup->groupAttackMoveToPosition( &dest, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );
  647. }
  648. break;
  649. }
  650. //---------------------------------------------------------------------------------------------
  651. case GameMessage::MSG_DO_FORCEMOVETO:
  652. {
  653. Coord3D dest = msg->getArgument( 0 )->location;
  654. if (currentlySelectedGroup)
  655. {
  656. currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
  657. currentlySelectedGroup->groupMoveToPosition( &dest, false, CMD_FROM_PLAYER );
  658. }
  659. break;
  660. }
  661. //---------------------------------------------------------------------------------------------
  662. // MSG_DO_SALVAGE is intentionally set up to mimic the moveto.
  663. case GameMessage::MSG_DO_SALVAGE:
  664. case GameMessage::MSG_DO_MOVETO:
  665. {
  666. Coord3D dest = msg->getArgument( 0 )->location;
  667. if( currentlySelectedGroup )
  668. {
  669. //DEBUG_LOG(("GameLogicDispatch - got a MSG_DO_MOVETO command\n"));
  670. currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
  671. currentlySelectedGroup->groupMoveToPosition( &dest, false, CMD_FROM_PLAYER );
  672. }
  673. break;
  674. }
  675. //---------------------------------------------------------------------------------------------
  676. case GameMessage::MSG_ADD_WAYPOINT:
  677. {
  678. Coord3D dest = msg->getArgument( 0 )->location;
  679. if( currentlySelectedGroup )
  680. {
  681. //DEBUG_LOG(("GameLogicDispatch - got a MSG_DO_MOVETO command\n"));
  682. currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
  683. currentlySelectedGroup->groupMoveToPosition( &dest, true, CMD_FROM_PLAYER );
  684. }
  685. break;
  686. }
  687. //---------------------------------------------------------------------------------------------
  688. case GameMessage::MSG_DO_GUARD_POSITION:
  689. {
  690. Coord3D loc = msg->getArgument( 0 )->location;
  691. GuardMode gm = (GuardMode)msg->getArgument( 1 )->integer;
  692. if (currentlySelectedGroup)
  693. {
  694. currentlySelectedGroup->groupGuardPosition(&loc, gm, CMD_FROM_PLAYER);
  695. }
  696. break;
  697. }
  698. //---------------------------------------------------------------------------------------------
  699. case GameMessage::MSG_DO_GUARD_OBJECT:
  700. {
  701. Object* obj = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  702. if (!obj)
  703. break;
  704. GuardMode gm = (GuardMode)msg->getArgument( 1 )->integer;
  705. if (currentlySelectedGroup)
  706. {
  707. currentlySelectedGroup->groupGuardObject(obj, gm, CMD_FROM_PLAYER);
  708. }
  709. break;
  710. }
  711. //---------------------------------------------------------------------------------------------
  712. case GameMessage::MSG_DO_STOP:
  713. {
  714. if (currentlySelectedGroup)
  715. {
  716. currentlySelectedGroup->groupIdle(CMD_FROM_PLAYER);
  717. }
  718. break;
  719. }
  720. //---------------------------------------------------------------------------------------------
  721. case GameMessage::MSG_DO_SCATTER:
  722. {
  723. if (currentlySelectedGroup)
  724. {
  725. currentlySelectedGroup->groupScatter(CMD_FROM_PLAYER);
  726. }
  727. break;
  728. }
  729. //---------------------------------------------------------------------------------------------
  730. case GameMessage::MSG_CREATE_FORMATION:
  731. {
  732. if (currentlySelectedGroup)
  733. {
  734. currentlySelectedGroup->groupCreateFormation(CMD_FROM_PLAYER);
  735. }
  736. break;
  737. }
  738. //---------------------------------------------------------------------------------------------
  739. case GameMessage::MSG_CLEAR_INGAME_POPUP_MESSAGE:
  740. {
  741. if( TheInGameUI )
  742. {
  743. TheInGameUI->clearPopupMessageData();
  744. }
  745. break;
  746. }
  747. //---------------------------------------------------------------------------------------------
  748. case GameMessage::MSG_DO_CHEER:
  749. {
  750. //All selected units play cheer animation.
  751. if( currentlySelectedGroup )
  752. {
  753. currentlySelectedGroup->groupCheer( CMD_FROM_PLAYER );
  754. }
  755. break;
  756. }
  757. #if defined(_DEBUG) || defined(_INTERNAL) || defined (_ALLOW_DEBUG_CHEATS_IN_RELEASE)
  758. //---------------------------------------------------------------------------------------------
  759. case GameMessage::MSG_DEBUG_KILL_SELECTION:
  760. {
  761. //All selected units die
  762. if( currentlySelectedGroup )
  763. {
  764. const VecObjectID& selectedObjects = currentlySelectedGroup->getAllIDs();
  765. for (VecObjectID::const_iterator it = selectedObjects.begin(); it != selectedObjects.end(); ++it)
  766. {
  767. Object *obj = findObjectByID(*it);
  768. if (obj)
  769. {
  770. obj->kill();
  771. }
  772. }
  773. }
  774. break;
  775. }
  776. //---------------------------------------------------------------------------------------------
  777. case GameMessage::MSG_DEBUG_HURT_OBJECT:
  778. {
  779. Object* objToHurt = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  780. if (objToHurt)
  781. {
  782. DamageInfo damageInfo;
  783. damageInfo.in.m_damageType = DAMAGE_UNRESISTABLE;
  784. damageInfo.in.m_deathType = DEATH_NORMAL;
  785. damageInfo.in.m_sourceID = INVALID_ID;
  786. damageInfo.in.m_amount = objToHurt->getBodyModule()->getMaxHealth() / 10.0f;
  787. objToHurt->attemptDamage( &damageInfo );
  788. }
  789. break;
  790. }
  791. //---------------------------------------------------------------------------------------------
  792. case GameMessage::MSG_DEBUG_KILL_OBJECT:
  793. {
  794. Object* objToHurt = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  795. if (objToHurt)
  796. {
  797. objToHurt->kill();
  798. }
  799. break;
  800. }
  801. #endif
  802. #ifdef ALLOW_SURRENDER
  803. //---------------------------------------------------------------------------------------------
  804. case GameMessage::MSG_DO_SURRENDER:
  805. {
  806. //All selected units surrender
  807. if( currentlySelectedGroup )
  808. {
  809. Object* objWeSurrenderedTo = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  810. Bool surrender = msg->getArgument( 1 )->boolean;
  811. currentlySelectedGroup->groupSurrender( objWeSurrenderedTo, surrender, CMD_FROM_PLAYER );
  812. }
  813. break;
  814. }
  815. #endif
  816. //---------------------------------------------------------------------------------------------
  817. case GameMessage::MSG_ENTER:
  818. {
  819. Object *enter = TheGameLogic->findObjectByID( msg->getArgument( 1 )->objectID );
  820. // sanity
  821. if( enter == NULL )
  822. break;
  823. if( currentlySelectedGroup )
  824. {
  825. currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
  826. currentlySelectedGroup->groupEnter( enter, CMD_FROM_PLAYER );
  827. }
  828. break;
  829. } // end GameMessage::MSG_ENTER
  830. //---------------------------------------------------------------------------------------------
  831. case GameMessage::MSG_EXIT:
  832. {
  833. Object *objectWantingToExit = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  834. Object *objectContainingExiter = getSingleObjectFromSelection(currentlySelectedGroup);
  835. // sanity
  836. if( objectWantingToExit == NULL )
  837. break;
  838. if( objectContainingExiter == NULL )
  839. break;
  840. // sanity, the player must actually control this object
  841. if( objectWantingToExit->getControllingPlayer() != thisPlayer )
  842. break;
  843. objectWantingToExit->releaseWeaponLock(LOCKED_TEMPORARILY); // release any temporary locks.
  844. // exit whatever objectWantingToExit is INSIDE of
  845. AIUpdateInterface *ai = objectWantingToExit->getAIUpdateInterface();
  846. if( ai )
  847. ai->aiExit( objectContainingExiter, CMD_FROM_PLAYER );
  848. // Just like Enter, Exit needs to know the thing to exit. This can no longer be assumed because of the Tunnel system.
  849. // If you do not specify the thing to Exit, it will Exit the thing it thinks it is in. For a tunnel network,
  850. // that will be the specific Tunnel it entered. (Scripts can talk directly to the guy to say Get Out Regardless)
  851. break;
  852. } // end GameMessage::MSG_EXIT
  853. //---------------------------------------------------------------------------------------------
  854. case GameMessage::MSG_EVACUATE:
  855. {
  856. // issue command for either single object or for selected group
  857. // AIGroup *group = TheAI->findGroup( *selectedGroupID );
  858. if( currentlySelectedGroup )
  859. {
  860. //Coord3D pos;
  861. //Bool hasArgs = FALSE;
  862. //hasArgs = (msg->getArgumentCount() > 0);
  863. //if (hasArgs)
  864. // pos = msg->getArgument(0)->location;
  865. currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
  866. // evacuate message is for the selected group
  867. //if (hasArgs)
  868. // currentlySelectedGroup->groupMoveToAndEvacuate( &pos, CMD_FROM_PLAYER );
  869. //else
  870. currentlySelectedGroup->groupEvacuate( CMD_FROM_PLAYER );
  871. // no, this is bad, don't do here, do when POSTING message
  872. // pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_EVACUATE );
  873. } // end if, command for group
  874. break;
  875. } // end GameMessage::MSG_EVACUATE
  876. // --------------------------------------------------------------------------------------------
  877. case GameMessage::MSG_EXECUTE_RAILED_TRANSPORT:
  878. {
  879. // issue command to currently selected objects
  880. if( currentlySelectedGroup )
  881. currentlySelectedGroup->groupExecuteRailedTransport( CMD_FROM_PLAYER );
  882. break;
  883. } // end GameMessage::MSG_EXECUTE_RAILED_TRANSPORT
  884. //---------------------------------------------------------------------------------------------
  885. case GameMessage::MSG_INTERNET_HACK:
  886. {
  887. // ObjectID sourceID = msg->getArgument( 0 )->objectID;
  888. if( currentlySelectedGroup )
  889. {
  890. currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
  891. currentlySelectedGroup->groupHackInternet( CMD_FROM_PLAYER );
  892. }
  893. break;
  894. }
  895. // --------------------------------------------------------------------------------------------
  896. case GameMessage::MSG_GET_REPAIRED:
  897. {
  898. Object *repairDepot = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  899. // sanity
  900. if( repairDepot == NULL )
  901. break;
  902. // tell the currently selected group to go get repaired
  903. if( currentlySelectedGroup )
  904. currentlySelectedGroup->groupGetRepaired( repairDepot, CMD_FROM_PLAYER );
  905. break;
  906. } // end get repaired
  907. // --------------------------------------------------------------------------------------------
  908. case GameMessage::MSG_DOCK:
  909. {
  910. Object *dockBuilding = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  911. // sanity
  912. if( dockBuilding == NULL )
  913. break;
  914. // tell the currently selected group to go get repaired
  915. if( currentlySelectedGroup )
  916. currentlySelectedGroup->groupDock( dockBuilding, CMD_FROM_PLAYER );
  917. break;
  918. } // end get repaired
  919. // --------------------------------------------------------------------------------------------
  920. case GameMessage::MSG_GET_HEALED:
  921. {
  922. Object *healDest = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  923. // sanity
  924. if( healDest == NULL )
  925. break;
  926. // tell the currently selected group to enter the building for healing
  927. if( currentlySelectedGroup )
  928. currentlySelectedGroup->groupGetHealed( healDest, CMD_FROM_PLAYER );
  929. break;
  930. } // end get repaired
  931. // --------------------------------------------------------------------------------------------
  932. case GameMessage::MSG_DO_REPAIR:
  933. {
  934. Object *repairTarget = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  935. // sanity
  936. if( repairTarget == NULL )
  937. break;
  938. //
  939. // tell the currently selected group of objects to go repair the target object, note
  940. // that only one of them will actually go ahead and do the repair
  941. //
  942. if( currentlySelectedGroup )
  943. currentlySelectedGroup->groupRepair( repairTarget, CMD_FROM_PLAYER );
  944. break;
  945. } // end get repaired
  946. // --------------------------------------------------------------------------------------------
  947. case GameMessage::MSG_RESUME_CONSTRUCTION:
  948. {
  949. Object *constructTarget = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  950. // sanity
  951. if( constructTarget == NULL )
  952. break;
  953. //
  954. // tell the currently selected group of objects to resume construction on
  955. // the target object, note that only one of them will go off and resume construction
  956. // on the target
  957. //
  958. if( currentlySelectedGroup )
  959. currentlySelectedGroup->groupResumeConstruction( constructTarget, CMD_FROM_PLAYER );
  960. // no, this is bad, don't do here, do when POSTING message
  961. // pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), msg->getType() );
  962. break;
  963. } // end resume construction
  964. // --------------------------------------------------------------------------------------------
  965. case GameMessage::MSG_DO_SPECIAL_POWER_OVERRIDE_DESTINATION:
  966. {
  967. const Coord3D *loc = &msg->getArgument( 0 )->location;
  968. SpecialPowerType spType = (SpecialPowerType)msg->getArgument( 1 )->integer;
  969. ObjectID sourceID = msg->getArgument(2)->objectID;
  970. Object* source = TheGameLogic->findObjectByID(sourceID);
  971. if (source != NULL)
  972. {
  973. AIGroup* theGroup = TheAI->createGroup();
  974. theGroup->add(source);
  975. theGroup->groupOverrideSpecialPowerDestination( spType, loc, CMD_FROM_PLAYER );
  976. TheAI->destroyGroup(theGroup);
  977. }
  978. else
  979. {
  980. if( currentlySelectedGroup )
  981. {
  982. currentlySelectedGroup->groupOverrideSpecialPowerDestination( spType, loc, CMD_FROM_PLAYER );
  983. }
  984. }
  985. }
  986. //---------------------------------------------------------------------------------------------
  987. case GameMessage::MSG_DO_ATTACK_OBJECT:
  988. {
  989. Object *enemy = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  990. // Check enemy, as it is possible that he died this frame.
  991. if (enemy)
  992. {
  993. if (currentlySelectedGroup)
  994. {
  995. currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
  996. currentlySelectedGroup->groupAttackObject( enemy, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );
  997. }
  998. }
  999. break;
  1000. } // end GameMessage::MSG_DO_ATTACK_GROUND_OBJECT
  1001. //---------------------------------------------------------------------------------------------
  1002. case GameMessage::MSG_DO_FORCE_ATTACK_OBJECT:
  1003. {
  1004. Object *enemy = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  1005. // Check enemy, as it is possible that he died this frame.
  1006. if (enemy)
  1007. {
  1008. if (currentlySelectedGroup)
  1009. {
  1010. currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY); // release any temporary locks.
  1011. currentlySelectedGroup->groupForceAttackObject( enemy, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );
  1012. }
  1013. }
  1014. break;
  1015. } // end GameMessage::MSG_DO_ATTACK_GROUND_OBJECT
  1016. //---------------------------------------------------------------------------------------------
  1017. case GameMessage::MSG_DO_FORCE_ATTACK_GROUND:
  1018. {
  1019. const Coord3D *pos = &msg->getArgument( 0 )->location;
  1020. if (currentlySelectedGroup)
  1021. {
  1022. /////////////////////////////////////////////////////////////////////
  1023. //Lorenzen sez: unclear, yet how to solve this for all cases
  1024. //Kris: This code was added to allow the toxin tractor to force attack
  1025. // while contaminating. When this change was made, it was causing
  1026. // rangers and scud launchers to reset to primary weapon mode whenever
  1027. // force attacking while not idle. I fixed this by enforcing the
  1028. // temporary and permanent modes that are already set when attempting
  1029. // the new lock. In this case, the temp lock attempt will fail whenever
  1030. // a permanent lock is in effect, thus fixing the ranger and scud and
  1031. // allowing the tox tractor to work as well.
  1032. Bool forceAttackRequiresPrimaryWeapon = !currentlySelectedGroup->isIdle();
  1033. if ( forceAttackRequiresPrimaryWeapon )
  1034. {
  1035. currentlySelectedGroup->setWeaponLockForGroup( PRIMARY_WEAPON, LOCKED_TEMPORARILY );
  1036. currentlySelectedGroup->groupAttackPosition( pos, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );
  1037. currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY);
  1038. }
  1039. else
  1040. ///////////////////////////////////////////////////////////////////
  1041. {
  1042. currentlySelectedGroup->releaseWeaponLockForGroup(LOCKED_TEMPORARILY);
  1043. currentlySelectedGroup->groupAttackPosition( pos, NO_MAX_SHOTS_LIMIT, CMD_FROM_PLAYER );
  1044. }
  1045. }
  1046. break;
  1047. } // end GameMessage::MSG_DO_ATTACK_GROUND_OBJECT
  1048. //---------------------------------------------------------------------------------------------
  1049. case GameMessage::MSG_QUEUE_UPGRADE:
  1050. {
  1051. const UpgradeTemplate *upgradeT = TheUpgradeCenter->findUpgradeByKey( (NameKeyType)(msg->getArgument( 1 )->integer) );
  1052. if (!upgradeT) // sanity
  1053. break;
  1054. if (currentlySelectedGroup)
  1055. currentlySelectedGroup->queueUpgrade( upgradeT );
  1056. break;
  1057. } // end queue upgrade
  1058. //---------------------------------------------------------------------------------------------
  1059. case GameMessage::MSG_CANCEL_UPGRADE:
  1060. {
  1061. Object *producer = getSingleObjectFromSelection(currentlySelectedGroup);
  1062. const UpgradeTemplate *upgradeT = TheUpgradeCenter->findUpgradeByKey( (NameKeyType)(msg->getArgument( 0 )->integer) );
  1063. // sanity
  1064. if( producer == NULL || upgradeT == NULL )
  1065. break;
  1066. // the player must actually control the producer object
  1067. if( producer->getControllingPlayer() != thisPlayer )
  1068. break;
  1069. // producer must have a production update
  1070. ProductionUpdateInterface *pu = producer->getProductionUpdateInterface();
  1071. if( pu == NULL )
  1072. break;
  1073. // cancel the upgrade
  1074. pu->cancelUpgrade( upgradeT );
  1075. break;
  1076. } // end cancel upgrade
  1077. //---------------------------------------------------------------------------------------------
  1078. case GameMessage::MSG_QUEUE_UNIT_CREATE:
  1079. {
  1080. Object *producer = getSingleObjectFromSelection(currentlySelectedGroup);
  1081. const ThingTemplate *whatToCreate;
  1082. ProductionID productionID;
  1083. // get data from the message
  1084. whatToCreate = TheThingFactory->findByTemplateID( msg->getArgument( 0 )->integer );
  1085. productionID = (ProductionID)msg->getArgument( 1 )->integer;
  1086. // sanity
  1087. if ( producer == NULL || whatToCreate == NULL )
  1088. break;
  1089. // get the production interface for the producer
  1090. ProductionUpdateInterface *pu = producer->getProductionUpdateInterface();
  1091. if( pu == NULL )
  1092. {
  1093. DEBUG_ASSERTCRASH( 0, ("MSG_QUEUE_UNIT_CREATE: Producer '%s' doesn't have a unit production interface\n",
  1094. producer->getTemplate()->getName().str()) );
  1095. break;
  1096. } // end if
  1097. // queue the build
  1098. pu->queueCreateUnit( whatToCreate, productionID );
  1099. break;
  1100. } // end GameMessage::MSG_QUEUE_UNIT_CREATE
  1101. //-------------------------------------------------------------------------------------------------
  1102. case GameMessage::MSG_CANCEL_UNIT_CREATE:
  1103. {
  1104. Object *producer = getSingleObjectFromSelection(currentlySelectedGroup);
  1105. ProductionID productionID = (ProductionID)msg->getArgument( 0 )->integer;
  1106. // sanity
  1107. if( producer == NULL )
  1108. break;
  1109. // sanity, the player must control the producer
  1110. if( producer->getControllingPlayer() != thisPlayer )
  1111. break;
  1112. // get the unit production interface
  1113. ProductionUpdateInterface *pu = producer->getProductionUpdateInterface();
  1114. if( pu == NULL )
  1115. return;
  1116. // cancel the production
  1117. pu->cancelUnitCreate( productionID );
  1118. break;
  1119. } // end GameMessage::MSG_CANCEL_UNIT_CREATE
  1120. //---------------------------------------------------------------------------------------------
  1121. case GameMessage::MSG_DOZER_CONSTRUCT:
  1122. case GameMessage::MSG_DOZER_CONSTRUCT_LINE:
  1123. {
  1124. const ThingTemplate *place;
  1125. Coord3D loc;
  1126. Real angle;
  1127. // get player, what to place, and location
  1128. Object *constructorObject = getSingleObjectFromSelection(currentlySelectedGroup);
  1129. place = TheThingFactory->findByTemplateID( msg->getArgument( 0 )->integer );
  1130. loc = msg->getArgument( 1 )->location;
  1131. angle = msg->getArgument( 2 )->real;
  1132. if( place == NULL || constructorObject == NULL )
  1133. break; //These are not crashes, as the object may have died before this message came in
  1134. if( msg->getType() == GameMessage::MSG_DOZER_CONSTRUCT )
  1135. {
  1136. TheBuildAssistant->buildObjectNow( constructorObject, place, &loc, angle,
  1137. constructorObject->getControllingPlayer() );
  1138. } // end if
  1139. else
  1140. {
  1141. Coord3D locEnd;
  1142. // get the end of the line location in the world
  1143. locEnd = msg->getArgument( 3 )->location;
  1144. // place the line of structures, the end location being present will make it happen
  1145. TheBuildAssistant->buildObjectLineNow( constructorObject, place, &loc, &locEnd, angle,
  1146. constructorObject->getControllingPlayer() );
  1147. } // end else
  1148. // place the sound for putting a building down
  1149. static AudioEventRTS placeBuilding(AsciiString("PlaceBuilding"));
  1150. placeBuilding.setObjectID(constructorObject->getID());
  1151. TheAudio->addAudioEvent( &placeBuilding );
  1152. // no, this is bad, don't do here, do when POSTING message
  1153. // pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), msg->getType() );
  1154. break;
  1155. } // end build start
  1156. //---------------------------------------------------------------------------------------------
  1157. case GameMessage::MSG_DOZER_CANCEL_CONSTRUCT:
  1158. {
  1159. // get the building to cancel construction on
  1160. Object *building = getSingleObjectFromSelection(currentlySelectedGroup);
  1161. if( building == NULL )
  1162. break;
  1163. // the player sending this message must actually control this building
  1164. if( building->getControllingPlayer() != thisPlayer )
  1165. break;
  1166. // Check to make sure it is actually under construction
  1167. if( !building->testStatus(OBJECT_STATUS_UNDER_CONSTRUCTION) )
  1168. break;
  1169. // OK, refund the money to the player, unless it is a rebuilding Hole.
  1170. if( !building->testStatus(OBJECT_STATUS_RECONSTRUCTING))
  1171. {
  1172. Money *money = thisPlayer->getMoney();
  1173. UnsignedInt amount = building->getTemplate()->calcCostToBuild( thisPlayer );
  1174. money->deposit( amount );
  1175. }
  1176. //
  1177. // Destroy the building ... killing the
  1178. // building will automatically cause the dozer also cancel its own building
  1179. // behavior and it will go on its merry way doing other assigned tasks
  1180. //
  1181. building->kill();
  1182. break;
  1183. } // end cancel dozer construction
  1184. // --------------------------------------------------------------------------------------------
  1185. case GameMessage::MSG_SELL:
  1186. {
  1187. // use the selected group
  1188. if( currentlySelectedGroup )
  1189. currentlySelectedGroup->groupSell( CMD_FROM_PLAYER );
  1190. break;
  1191. } // end sell
  1192. // --------------------------------------------------------------------------------------------
  1193. case GameMessage::MSG_TOGGLE_OVERCHARGE:
  1194. {
  1195. // use the selected group
  1196. if( currentlySelectedGroup )
  1197. currentlySelectedGroup->groupToggleOvercharge( CMD_FROM_PLAYER );
  1198. break;
  1199. } // end toggle overcharge
  1200. #ifdef ALLOW_SURRENDER
  1201. // --------------------------------------------------------------------------------------------
  1202. case GameMessage::MSG_PICK_UP_PRISONER:
  1203. {
  1204. Object *prisoner = TheGameLogic->findObjectByID( msg->getArgument( 0 )->objectID );
  1205. if( prisoner )
  1206. {
  1207. // use selected group
  1208. if( currentlySelectedGroup )
  1209. currentlySelectedGroup->groupPickUpPrisoner( prisoner, CMD_FROM_PLAYER );
  1210. } // end if
  1211. break;
  1212. } // end pick up prisoner
  1213. #endif
  1214. #ifdef ALLOW_SURRENDER
  1215. // --------------------------------------------------------------------------------------------
  1216. case GameMessage::MSG_RETURN_TO_PRISON:
  1217. {
  1218. // use selected group
  1219. if( currentlySelectedGroup )
  1220. currentlySelectedGroup->groupReturnToPrison( NULL, CMD_FROM_PLAYER );
  1221. break;
  1222. } // end return to prison
  1223. #endif
  1224. //---------------------------------------------------------------------------------------------
  1225. // No sound does exactly the same logical processing as the usual message. Just double them up.
  1226. case GameMessage::MSG_CREATE_SELECTED_GROUP_NO_SOUND:
  1227. case GameMessage::MSG_CREATE_SELECTED_GROUP:
  1228. {
  1229. Bool createNewGroup = msg->getArgument( 0 )->boolean;
  1230. Player *player = ThePlayerList->getNthPlayer(msg->getPlayerIndex());
  1231. if (player == NULL) {
  1232. DEBUG_CRASH(("GameLogicDispatch - MSG_CREATE_SELECTED_GROUP had an invalid player nubmer"));
  1233. break;
  1234. }
  1235. Bool firstObject = TRUE;
  1236. for (Int i = 1; i < msg->getArgumentCount(); ++i) {
  1237. Object *obj = TheGameLogic->findObjectByID( msg->getArgument( i )->objectID );
  1238. if (!obj) {
  1239. continue;
  1240. }
  1241. TheGameLogic->selectObject(obj, createNewGroup && firstObject, player->getPlayerMask());
  1242. firstObject = FALSE;
  1243. }
  1244. break;
  1245. } // end build start
  1246. //---------------------------------------------------------------------------------------------
  1247. case GameMessage::MSG_REMOVE_FROM_SELECTED_GROUP:
  1248. {
  1249. Player *player = ThePlayerList->getNthPlayer(msg->getPlayerIndex());
  1250. if (player == NULL) {
  1251. DEBUG_CRASH(("GameLogicDispatch - MSG_CREATE_SELECTED_GROUP had an invalid player nubmer"));
  1252. break;
  1253. }
  1254. for (Int i = 0; i < msg->getArgumentCount(); ++i) {
  1255. ObjectID objID = msg->getArgument(i)->objectID;
  1256. Object *objToRemove = TheGameLogic->findObjectByID(objID);
  1257. if (!objToRemove) {
  1258. continue;
  1259. }
  1260. TheGameLogic->deselectObject(objToRemove, player->getPlayerMask());
  1261. }
  1262. break;
  1263. } // end MSG_REMOVE_FROM_SELECTED_GROUP
  1264. //---------------------------------------------------------------------------------------------
  1265. case GameMessage::MSG_DESTROY_SELECTED_GROUP:
  1266. {
  1267. Player *player = ThePlayerList->getNthPlayer(msg->getPlayerIndex());
  1268. if (player != NULL)
  1269. {
  1270. player->setCurrentlySelectedAIGroup(NULL);
  1271. }
  1272. break;
  1273. } // end build start
  1274. // --------------------------------------------------------------------------------------------
  1275. case GameMessage::MSG_SELECTED_GROUP_COMMAND:
  1276. {
  1277. break;
  1278. } // end selected group command
  1279. // --------------------------------------------------------------------------------------------
  1280. case GameMessage::MSG_PLACE_BEACON:
  1281. {
  1282. // how many does this player have active?
  1283. Coord3D pos = msg->getArgument( 0 )->location;
  1284. Region3D r;
  1285. TheTerrainLogic->getExtent(&r);
  1286. if (!r.isInRegionNoZ(&pos))
  1287. pos = TheTerrainLogic->findClosestEdgePoint(&pos);
  1288. const ThingTemplate *thing = TheThingFactory->findTemplate( thisPlayer->getPlayerTemplate()->getBeaconTemplate() );
  1289. if (thing && !TheVictoryConditions->hasSinglePlayerBeenDefeated(thisPlayer))
  1290. {
  1291. Int count;
  1292. thisPlayer->countObjectsByThingTemplate( 1, &thing, false, &count );
  1293. DEBUG_LOG(("Player already has %d beacons active\n", count));
  1294. if (count >= TheMultiplayerSettings->getMaxBeaconsPerPlayer())
  1295. {
  1296. if (thisPlayer == ThePlayerList->getLocalPlayer())
  1297. {
  1298. // tell the user
  1299. TheInGameUI->message( TheGameText->fetch("GUI:TooManyBeacons") );
  1300. // play a sound
  1301. static AudioEventRTS aSound("BeaconPlacementFailed");
  1302. aSound.setPosition(&pos);
  1303. aSound.setPlayerIndex(thisPlayer->getPlayerIndex());
  1304. TheAudio->addAudioEvent(&aSound);
  1305. }
  1306. break;
  1307. }
  1308. Object *object = TheThingFactory->newObject( thing, thisPlayer->getDefaultTeam() );
  1309. object->setPosition( &pos );
  1310. object->setProducer(NULL);
  1311. if (thisPlayer->getRelationship( ThePlayerList->getLocalPlayer()->getDefaultTeam() ) == ALLIES || ThePlayerList->getLocalPlayer()->isPlayerObserver())
  1312. {
  1313. // tell the user
  1314. UnicodeString s;
  1315. s.format(TheGameText->fetch("GUI:BeaconPlaced"), thisPlayer->getPlayerDisplayName().str());
  1316. TheInGameUI->message( s );
  1317. // play a sound
  1318. static AudioEventRTS aSound("BeaconPlaced");
  1319. aSound.setPlayerIndex(thisPlayer->getPlayerIndex());
  1320. aSound.setPosition(&pos);
  1321. TheAudio->addAudioEvent(&aSound);
  1322. // beacons are a rare event; play a nifty radar event thingie
  1323. TheRadar->createEvent( object->getPosition(), RADAR_EVENT_INFORMATION );
  1324. if (ThePlayerList->getLocalPlayer()->getRelationship(thisPlayer->getDefaultTeam()) == ALLIES)
  1325. TheEva->setShouldPlay(EVA_BeaconDetected);
  1326. TheControlBar->markUIDirty(); // check if we should grey out the button
  1327. }
  1328. else
  1329. {
  1330. Int updateCount = 0;
  1331. static NameKeyType nameKeyClientUpdate = NAMEKEY("BeaconClientUpdate");
  1332. ClientUpdateModule ** clientModules = object->getDrawable()->getClientUpdateModules();
  1333. if (clientModules)
  1334. {
  1335. while (*clientModules)
  1336. {
  1337. if ((*clientModules)->getModuleNameKey() == nameKeyClientUpdate)
  1338. {
  1339. (*(BeaconClientUpdate **)clientModules)->hideBeacon();
  1340. ++updateCount;
  1341. }
  1342. ++clientModules;
  1343. }
  1344. }
  1345. DEBUG_ASSERTCRASH(updateCount == 1, ("Saw %d update modules for the beacon!", updateCount));
  1346. }
  1347. }
  1348. else
  1349. {
  1350. // tell the user
  1351. TheInGameUI->message( TheGameText->fetch("GUI:BeaconPlacementFailed") );
  1352. // play a sound
  1353. static AudioEventRTS aSound("BeaconPlacementFailed");
  1354. aSound.setPosition(&pos);
  1355. aSound.setPlayerIndex(thisPlayer->getPlayerIndex());
  1356. TheAudio->addAudioEvent(&aSound);
  1357. }
  1358. break;
  1359. } // end beacon placement
  1360. // --------------------------------------------------------------------------------------------
  1361. case GameMessage::MSG_REMOVE_BEACON:
  1362. {
  1363. AIGroup *allSelectedObjects = NULL;
  1364. allSelectedObjects = TheAI->createGroup();
  1365. thisPlayer->getCurrentSelectionAsAIGroup(allSelectedObjects); // need to act on all objects, so we can hide teammates' beacons.
  1366. if( allSelectedObjects )
  1367. {
  1368. const VecObjectID& selectedObjects = allSelectedObjects->getAllIDs();
  1369. for (VecObjectID::const_iterator it = selectedObjects.begin(); it != selectedObjects.end(); ++it)
  1370. {
  1371. Object *beacon = findObjectByID(*it);
  1372. if (beacon)
  1373. {
  1374. const ThingTemplate *thing = TheThingFactory->findTemplate( beacon->getControllingPlayer()->getPlayerTemplate()->getBeaconTemplate() );
  1375. if (thing->isEquivalentTo(beacon->getTemplate()))
  1376. {
  1377. if (beacon->getControllingPlayer() == thisPlayer)
  1378. {
  1379. TheGameLogic->destroyObject(beacon); // the owner is telling it to go away. such is life.
  1380. TheControlBar->markUIDirty(); // check if we should un-grey out the button
  1381. }
  1382. else if (thisPlayer == ThePlayerList->getLocalPlayer())
  1383. {
  1384. Drawable *beaconDrawable = beacon->getDrawable();
  1385. if (beaconDrawable)
  1386. {
  1387. static NameKeyType nameKeyClientUpdate = NAMEKEY("BeaconClientUpdate");
  1388. ClientUpdateModule ** clientModules = beaconDrawable->getClientUpdateModules();
  1389. if (clientModules)
  1390. {
  1391. while (*clientModules)
  1392. {
  1393. if ((*clientModules)->getModuleNameKey() == nameKeyClientUpdate)
  1394. (*(BeaconClientUpdate **)clientModules)->hideBeacon();
  1395. ++clientModules;
  1396. }
  1397. }
  1398. }
  1399. }
  1400. }
  1401. }
  1402. }
  1403. if (allSelectedObjects->isEmpty())
  1404. {
  1405. TheAI->destroyGroup(allSelectedObjects);
  1406. allSelectedObjects = NULL;
  1407. }
  1408. }
  1409. break;
  1410. } // end beacon removal
  1411. // --------------------------------------------------------------------------------------------
  1412. case GameMessage::MSG_SET_BEACON_TEXT:
  1413. {
  1414. if( currentlySelectedGroup )
  1415. {
  1416. const VecObjectID& selectedObjects = currentlySelectedGroup->getAllIDs();
  1417. for (VecObjectID::const_iterator it = selectedObjects.begin(); it != selectedObjects.end(); ++it)
  1418. {
  1419. Object *beacon = findObjectByID(*it);
  1420. if (beacon)
  1421. {
  1422. Drawable *beaconDrawable = beacon->getDrawable();
  1423. if (beaconDrawable)
  1424. {
  1425. UnicodeString s;
  1426. for( int i=0; i<msg->getArgumentCount(); i++ )
  1427. {
  1428. s.concat( msg->getArgument(i)->wChar );
  1429. }
  1430. if (s.isEmpty())
  1431. beaconDrawable->clearCaptionText();
  1432. else
  1433. beaconDrawable->setCaptionText(s);
  1434. }
  1435. }
  1436. }
  1437. }
  1438. break;
  1439. } // end beacon text
  1440. // --------------------------------------------------------------------------------------------
  1441. case GameMessage::MSG_SELF_DESTRUCT:
  1442. {
  1443. if (msg->getArgument(0)->boolean)
  1444. {
  1445. // transfer control to any living ally
  1446. for (Int i=0; i<ThePlayerList->getPlayerCount(); ++i)
  1447. {
  1448. if (i != msg->getPlayerIndex())
  1449. {
  1450. Player *otherPlayer = ThePlayerList->getNthPlayer(i);
  1451. if (thisPlayer->getRelationship(otherPlayer->getDefaultTeam()) == ALLIES &&
  1452. otherPlayer->getRelationship(thisPlayer->getDefaultTeam()) == ALLIES)
  1453. {
  1454. if (TheVictoryConditions->hasSinglePlayerBeenDefeated(otherPlayer))
  1455. continue;
  1456. // a living ally! hooray!
  1457. otherPlayer->transferAssetsFromThat(thisPlayer);
  1458. thisPlayer->killPlayer(); // just to be safe (and to kill beacons etc that don't transfer)
  1459. break;
  1460. }
  1461. }
  1462. }
  1463. if (i == ThePlayerList->getPlayerCount())
  1464. {
  1465. // didn't find any allies. die, loner!
  1466. thisPlayer->killPlayer();
  1467. }
  1468. }
  1469. else
  1470. {
  1471. thisPlayer->killPlayer();
  1472. }
  1473. // There is no reason to do any notification here, it now takes place in the victory conditions.
  1474. // bonehead.
  1475. break;
  1476. }
  1477. // --------------------------------------------------------------------------------------------
  1478. case GameMessage::MSG_SET_REPLAY_CAMERA:
  1479. {
  1480. if (TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK && TheGlobalData->m_useCameraInReplay && TheControlBar->getObserverLookAtPlayer() == thisPlayer)
  1481. {
  1482. if (TheTacticalView->isCameraMovementFinished())
  1483. {
  1484. ViewLocation loc;
  1485. Coord3D pos;
  1486. Real pitch, angle, zoom;
  1487. pos = msg->getArgument( 0 )->location;
  1488. angle = msg->getArgument( 1 )->real;
  1489. pitch = msg->getArgument( 2 )->real;
  1490. zoom = msg->getArgument( 3 )->real;
  1491. loc.init(pos.x, pos.y, pos.z, angle, pitch, zoom);
  1492. TheTacticalView->setLocation( &loc );
  1493. if (!TheLookAtTranslator->hasMouseMovedRecently())
  1494. {
  1495. TheMouse->setCursor( (Mouse::MouseCursor)(msg->getArgument( 4 )->integer) );
  1496. ICoord2D mousePos = msg->getArgument( 5 )->pixel;
  1497. TheMouse->setPosition( mousePos.x, mousePos.y );
  1498. TheLookAtTranslator->setCurrentPos( mousePos );
  1499. }
  1500. }
  1501. }
  1502. break;
  1503. } // end beacon text
  1504. //---------------------------------------------------------------------------------------------
  1505. case GameMessage::MSG_CREATE_TEAM0:
  1506. case GameMessage::MSG_CREATE_TEAM1:
  1507. case GameMessage::MSG_CREATE_TEAM2:
  1508. case GameMessage::MSG_CREATE_TEAM3:
  1509. case GameMessage::MSG_CREATE_TEAM4:
  1510. case GameMessage::MSG_CREATE_TEAM5:
  1511. case GameMessage::MSG_CREATE_TEAM6:
  1512. case GameMessage::MSG_CREATE_TEAM7:
  1513. case GameMessage::MSG_CREATE_TEAM8:
  1514. case GameMessage::MSG_CREATE_TEAM9:
  1515. {
  1516. Int playerIndex = msg->getPlayerIndex();
  1517. Player *player = ThePlayerList->getNthPlayer(playerIndex);
  1518. DEBUG_ASSERTCRASH(player != NULL, ("Could not find player for create team message"));
  1519. if (player == NULL)
  1520. {
  1521. break;
  1522. }
  1523. player->processCreateTeamGameMessage(msg->getType() - GameMessage::MSG_CREATE_TEAM0, msg);
  1524. break;
  1525. } // end create team command
  1526. case GameMessage::MSG_SELECT_TEAM0:
  1527. case GameMessage::MSG_SELECT_TEAM1:
  1528. case GameMessage::MSG_SELECT_TEAM2:
  1529. case GameMessage::MSG_SELECT_TEAM3:
  1530. case GameMessage::MSG_SELECT_TEAM4:
  1531. case GameMessage::MSG_SELECT_TEAM5:
  1532. case GameMessage::MSG_SELECT_TEAM6:
  1533. case GameMessage::MSG_SELECT_TEAM7:
  1534. case GameMessage::MSG_SELECT_TEAM8:
  1535. case GameMessage::MSG_SELECT_TEAM9:
  1536. {
  1537. Int playerIndex = msg->getPlayerIndex();
  1538. Player *player = ThePlayerList->getNthPlayer(playerIndex);
  1539. DEBUG_ASSERTCRASH(player != NULL, ("Could not find player for select team message"));
  1540. if (player == NULL)
  1541. {
  1542. break;
  1543. }
  1544. player->processSelectTeamGameMessage(msg->getType() - GameMessage::MSG_SELECT_TEAM0, msg);
  1545. break;
  1546. }
  1547. case GameMessage::MSG_ADD_TEAM0:
  1548. case GameMessage::MSG_ADD_TEAM1:
  1549. case GameMessage::MSG_ADD_TEAM2:
  1550. case GameMessage::MSG_ADD_TEAM3:
  1551. case GameMessage::MSG_ADD_TEAM4:
  1552. case GameMessage::MSG_ADD_TEAM5:
  1553. case GameMessage::MSG_ADD_TEAM6:
  1554. case GameMessage::MSG_ADD_TEAM7:
  1555. case GameMessage::MSG_ADD_TEAM8:
  1556. case GameMessage::MSG_ADD_TEAM9:
  1557. {
  1558. Int playerIndex = msg->getPlayerIndex();
  1559. Player *player = ThePlayerList->getNthPlayer(playerIndex);
  1560. DEBUG_ASSERTCRASH(player != NULL, ("Could not find player for add team message"));
  1561. if (player == NULL)
  1562. {
  1563. break;
  1564. }
  1565. player->processAddTeamGameMessage(msg->getType() - GameMessage::MSG_ADD_TEAM0, msg);
  1566. break;
  1567. }
  1568. //---------------------------------------------------------------------------------------------
  1569. case GameMessage::MSG_LOGIC_CRC:
  1570. {
  1571. if (TheNetwork)
  1572. {
  1573. Int slotIndex = -1;
  1574. for (Int i=0; i<MAX_SLOTS; ++i)
  1575. {
  1576. if (thisPlayer->getPlayerType() == PLAYER_HUMAN && TheNetwork->getPlayerName(i) == thisPlayer->getPlayerDisplayName())
  1577. {
  1578. slotIndex = i;
  1579. break;
  1580. }
  1581. }
  1582. if (slotIndex < 0 || !TheNetwork->isPlayerConnected(slotIndex))
  1583. break;
  1584. if (thisPlayer->isLocalPlayer())
  1585. {
  1586. #if defined(_DEBUG) || defined(_INTERNAL)
  1587. // don't even put this in release, cause someone might hack it.
  1588. if (!TheDebugIgnoreSyncErrors)
  1589. {
  1590. #endif
  1591. m_shouldValidateCRCs = TRUE;
  1592. #if defined(_DEBUG) || defined(_INTERNAL)
  1593. }
  1594. #endif
  1595. }
  1596. //UnsignedInt oldCRC = m_cachedCRCs[msg->getPlayerIndex()];
  1597. UnsignedInt newCRC = msg->getArgument(0)->integer;
  1598. //DEBUG_LOG(("Recieved CRC of %8.8X from %ls on frame %d\n", newCRC,
  1599. //thisPlayer->getPlayerDisplayName().str(), m_frame));
  1600. m_cachedCRCs[msg->getPlayerIndex()] = newCRC; // to mask problem: = (oldCRC < newCRC)?newCRC:oldCRC;
  1601. }
  1602. else if (TheRecorder && TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK)
  1603. {
  1604. UnsignedInt newCRC = msg->getArgument(0)->integer;
  1605. //DEBUG_LOG(("Saw CRC of %X from player %d. Our CRC is %X. Arg count is %d\n",
  1606. //newCRC, thisPlayer->getPlayerIndex(), getCRC(), msg->getArgumentCount()));
  1607. TheRecorder->handleCRCMessage(newCRC, thisPlayer->getPlayerIndex(), (msg->getArgument(1)->boolean));
  1608. }
  1609. break;
  1610. } // end CRC message
  1611. //---------------------------------------------------------------------------------------------
  1612. case GameMessage::MSG_PURCHASE_SCIENCE:
  1613. {
  1614. ScienceType science = (ScienceType)msg->getArgument( 0 )->integer;
  1615. // sanity
  1616. if( science == SCIENCE_INVALID || thisPlayer == NULL )
  1617. break;
  1618. thisPlayer->attemptToPurchaseScience(science);
  1619. break;
  1620. } // end pick specialized science
  1621. } // end switch
  1622. /**/ /// @todo: multiplayer semantics
  1623. if (currentlySelectedGroup && TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK && TheGlobalData->m_useCameraInReplay && TheControlBar->getObserverLookAtPlayer() == thisPlayer /*&& !TheRecorder->isMultiplayer()*/)
  1624. {
  1625. const VecObjectID& selectedObjects = currentlySelectedGroup->getAllIDs();
  1626. TheInGameUI->deselectAllDrawables();
  1627. for (VecObjectID::const_iterator it = selectedObjects.begin(); it != selectedObjects.end(); ++it)
  1628. {
  1629. const Object *obj = findObjectByID(*it);
  1630. if (obj)
  1631. {
  1632. Drawable *draw = obj->getDrawable();
  1633. if (draw)
  1634. TheInGameUI->selectDrawable(draw);
  1635. }
  1636. }
  1637. }
  1638. /**/
  1639. if( currentlySelectedGroup != NULL )
  1640. {
  1641. TheAI->destroyGroup(currentlySelectedGroup);
  1642. }
  1643. } // end logicMessageDispatches