ControlBarCommandProcessing.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  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: ControlBarCommandProcessing.cpp //////////////////////////////////////////////////////////
  24. // Author: Colin Day, March 2002
  25. // Desc: This file contain just the method responsible for processing the actual command
  26. // clicks from the window controls in the UI
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////
  28. // USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
  29. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  30. #include "Common/BuildAssistant.h"
  31. #include "Common/Money.h"
  32. #include "Common/Player.h"
  33. #include "Common/PlayerList.h"
  34. #include "Common/Science.h"
  35. #include "Common/SpecialPower.h"
  36. #include "Common/ThingTemplate.h"
  37. #include "Common/Upgrade.h"
  38. #include "Common/PlayerTemplate.h"
  39. #include "GameClient/CommandXlat.h"
  40. #include "GameClient/ControlBar.h"
  41. #include "GameClient/Drawable.h"
  42. #include "GameClient/Eva.h"
  43. #include "GameClient/GameClient.h"
  44. #include "GameClient/GadgetPushButton.h"
  45. #include "GameClient/GameWindow.h"
  46. #include "GameClient/GameWindowManager.h"
  47. #include "GameClient/InGameUI.h"
  48. #include "GameClient/AnimateWindowManager.h"
  49. #include "GameLogic/GameLogic.h"
  50. #include "GameLogic/Object.h"
  51. #include "GameLogic/Module/ProductionUpdate.h"
  52. #ifdef _INTERNAL
  53. // for occasional debugging...
  54. //#pragma optimize("", off)
  55. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  56. #endif
  57. //-------------------------------------------------------------------------------------------------
  58. //-------------------------------------------------------------------------------------------------
  59. struct SelectObjectsInfo
  60. {
  61. const ThingTemplate *thingTemplate;
  62. GameMessage *msg;
  63. };
  64. //-------------------------------------------------------------------------------------------------
  65. void selectObjectOfType( Object* obj, void* selectObjectsInfo )
  66. {
  67. SelectObjectsInfo *soInfo = (SelectObjectsInfo*)selectObjectsInfo;
  68. if( !obj || !soInfo )
  69. {
  70. return;
  71. }
  72. //Do the templates match?
  73. if( obj->getTemplate()->isEquivalentTo( soInfo->thingTemplate ) )
  74. {
  75. //Okay, then add it to the selected group.
  76. soInfo->msg->appendObjectIDArgument( obj->getID() );
  77. Drawable *draw = obj->getDrawable();
  78. if( draw )
  79. {
  80. TheInGameUI->selectDrawable( draw );
  81. }
  82. }
  83. }
  84. //-------------------------------------------------------------------------------------------------
  85. //-------------------------------------------------------------------------------------------------
  86. //-------------------------------------------------------------------------------------------------
  87. /** Process a button transition message from the window system that should be for one of
  88. * our GUI commands */
  89. //-------------------------------------------------------------------------------------------------
  90. CBCommandStatus ControlBar::processCommandTransitionUI( GameWindow *control, GadgetGameMessage gadgetMessage )
  91. {
  92. // sanity, we won't process messages if we have no source object
  93. if( m_currContext != CB_CONTEXT_MULTI_SELECT &&
  94. (m_currentSelectedDrawable == NULL ||
  95. m_currentSelectedDrawable->getObject() == NULL) )
  96. {
  97. if( m_currContext != CB_CONTEXT_NONE &&
  98. m_currContext != CB_CONTEXT_OBSERVER_INFO &&
  99. m_currContext != CB_CONTEXT_OBSERVER_LIST)
  100. switchToContext( CB_CONTEXT_NONE, NULL );
  101. return CBC_COMMAND_NOT_USED;
  102. } // end if
  103. return CBC_COMMAND_USED;
  104. }
  105. //-------------------------------------------------------------------------------------------------
  106. /** Process a button selected message from the window system that should be for one of
  107. * our GUI commands */
  108. //-------------------------------------------------------------------------------------------------
  109. CBCommandStatus ControlBar::processCommandUI( GameWindow *control,
  110. GadgetGameMessage gadgetMessage )
  111. {
  112. // get the command pointer from the control user data we put in the button
  113. const CommandButton *commandButton = (const CommandButton *)GadgetButtonGetData(control);
  114. if( !commandButton )
  115. {
  116. DEBUG_CRASH( ("ControlBar::processCommandUI() -- Button activated has no data. Ignoring...") );
  117. return CBC_COMMAND_NOT_USED;
  118. }
  119. // sanity, we won't process messages if we have no source object,
  120. // unless we're CB_CONTEXT_PURCHASE_SCIENCE or GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT
  121. if( m_currContext != CB_CONTEXT_MULTI_SELECT &&
  122. commandButton->getCommandType() != GUI_COMMAND_PURCHASE_SCIENCE &&
  123. commandButton->getCommandType() != GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT &&
  124. commandButton->getCommandType() != GUI_COMMAND_SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT &&
  125. commandButton->getCommandType() != GUI_COMMAND_SELECT_ALL_UNITS_OF_TYPE &&
  126. (m_currentSelectedDrawable == NULL || m_currentSelectedDrawable->getObject() == NULL) )
  127. {
  128. if( m_currContext != CB_CONTEXT_NONE )
  129. switchToContext( CB_CONTEXT_NONE, NULL );
  130. return CBC_COMMAND_NOT_USED;
  131. } // end if
  132. // sanity
  133. if( control == NULL )
  134. return CBC_COMMAND_NOT_USED;
  135. // the context sensitive gui only is only made of buttons ... sanity
  136. if( control->winGetInputFunc() != GadgetPushButtonInput )
  137. return CBC_COMMAND_NOT_USED;
  138. if( commandButton == NULL )
  139. return CBC_COMMAND_NOT_USED;
  140. // if the button is flashing, tell it to stop flashing
  141. commandButton->setFlashCount(0);
  142. TheControlBar->setFlash( FALSE );
  143. if( commandButton->getCommandType() != GUI_COMMAND_EXIT_CONTAINER )
  144. {
  145. GadgetButtonSetEnabledImage( control, commandButton->getButtonImage() );
  146. }
  147. //
  148. // get the object that is driving the context sensitive UI if we're not in a multi
  149. // select context
  150. //
  151. Object *obj = NULL;
  152. if( m_currContext != CB_CONTEXT_MULTI_SELECT &&
  153. commandButton->getCommandType() != GUI_COMMAND_PURCHASE_SCIENCE &&
  154. commandButton->getCommandType() != GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT &&
  155. commandButton->getCommandType() != GUI_COMMAND_SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT &&
  156. commandButton->getCommandType() != GUI_COMMAND_SELECT_ALL_UNITS_OF_TYPE )
  157. obj = m_currentSelectedDrawable->getObject();
  158. //@todo Kris -- Special case code so convoy trucks can detonate nuke trucks -- if other things need this,
  159. //rethink it.
  160. if( obj && BitTest( commandButton->getOptions(), SINGLE_USE_COMMAND ) )
  161. {
  162. /** @todo Added obj check because Single Use and Multi Select crash when used together, but with this check
  163. * they just won't work. When the "rethinking" occurs, this can get fixed. Right now it is unused.
  164. * Convoy Truck needs Multi Select so Single Use is turned off, and noone else has it.
  165. */
  166. //Make sure the command button is marked as used if it's a single use command. That way
  167. //we can never press the button again. This was added specifically for nuke convoy trucks.
  168. //When you click to detonate the nuke, it takes a few seconds to detonate in order to play
  169. //a sound. But we want to disable the button after the first click.
  170. obj->markSingleUseCommandUsed(); //Yeah, an object can only use one single use command...
  171. }
  172. TheInGameUI->placeBuildAvailable( NULL, NULL );
  173. //Play any available unit specific sound for button
  174. Player *player = ThePlayerList->getLocalPlayer();
  175. if( player )
  176. {
  177. AudioEventRTS sound = *commandButton->getUnitSpecificSound();
  178. sound.setPlayerIndex( player->getPlayerIndex() );
  179. TheAudio->addAudioEvent( &sound );
  180. }
  181. if( BitTest( commandButton->getOptions(), COMMAND_OPTION_NEED_TARGET ) )
  182. {
  183. if (commandButton->getOptions() & USES_MINE_CLEARING_WEAPONSET)
  184. {
  185. TheMessageStream->appendMessage( GameMessage::MSG_SET_MINE_CLEARING_DETAIL );
  186. }
  187. //June 06, 2002 -- Major change
  188. //I've added support for specific context sensitive commands which need targets just like
  189. //other options may need. When we need a target, the user must move the cursor to a position
  190. //where he wants the GUI command to take place. Older commands such as napalm strikes or daisy
  191. //cutter drops simply needed the user to click anywhere he desired.
  192. //
  193. //Now, we have new commands that will only work when the user clicks on valid targets to interact
  194. //with. For example, the terrorist can jack a car and convert it into a carbomb, but he has to
  195. //click on a valid car. In this case the doCommandOrHint code will determine if the mode is valid
  196. //or not and the cursor modes will be set appropriately.
  197. TheInGameUI->setGUICommand( commandButton );
  198. }
  199. else switch( commandButton->getCommandType() )
  200. {
  201. //---------------------------------------------------------------------------------------------
  202. case GUI_COMMAND_DOZER_CONSTRUCT:
  203. {
  204. // sanity
  205. if( m_currentSelectedDrawable == NULL )
  206. break;
  207. //Kris: September 27, 2002
  208. //Make sure we have enough CASH to build it WHEN we click the button to build it,
  209. //before actually previewing the purchase, otherwise, cancel altogether.
  210. const ThingTemplate *whatToBuild = commandButton->getThingTemplate();
  211. CanMakeType cmt = TheBuildAssistant->canMakeUnit( obj, whatToBuild );
  212. if (cmt == CANMAKE_NO_MONEY)
  213. {
  214. TheEva->setShouldPlay(EVA_InsufficientFunds);
  215. TheInGameUI->message( "GUI:NotEnoughMoneyToBuild" );
  216. break;
  217. }
  218. else if (cmt == CANMAKE_QUEUE_FULL)
  219. {
  220. TheInGameUI->message( "GUI:ProductionQueueFull" );
  221. break;
  222. }
  223. else if (cmt == CANMAKE_PARKING_PLACES_FULL)
  224. {
  225. TheInGameUI->message( "GUI:ParkingPlacesFull" );
  226. break;
  227. }
  228. else if( cmt == CANMAKE_MAXED_OUT_FOR_PLAYER )
  229. {
  230. TheInGameUI->message( "GUI:UnitMaxedOut" );
  231. break;
  232. }
  233. // tell the UI that we want to build something so we get a building at the cursor
  234. TheInGameUI->placeBuildAvailable( commandButton->getThingTemplate(), m_currentSelectedDrawable );
  235. break;
  236. } // end dozer construct
  237. case GUI_COMMAND_SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT:
  238. {
  239. //Determine the object that would construct it.
  240. const SpecialPowerTemplate *spTemplate = commandButton->getSpecialPowerTemplate();
  241. SpecialPowerType spType = spTemplate->getSpecialPowerType();
  242. Object* obj = ThePlayerList->getLocalPlayer()->findMostReadyShortcutSpecialPowerOfType( spType );
  243. if( !obj )
  244. break;
  245. Drawable *draw = obj->getDrawable();
  246. const ThingTemplate *whatToBuild = commandButton->getThingTemplate();
  247. CanMakeType cmt = TheBuildAssistant->canMakeUnit( obj, whatToBuild );
  248. if (cmt == CANMAKE_NO_MONEY)
  249. {
  250. TheEva->setShouldPlay(EVA_InsufficientFunds);
  251. TheInGameUI->message( "GUI:NotEnoughMoneyToBuild" );
  252. break;
  253. }
  254. else if (cmt == CANMAKE_QUEUE_FULL)
  255. {
  256. TheInGameUI->message( "GUI:ProductionQueueFull" );
  257. break;
  258. }
  259. else if (cmt == CANMAKE_PARKING_PLACES_FULL)
  260. {
  261. TheInGameUI->message( "GUI:ParkingPlacesFull" );
  262. break;
  263. }
  264. else if( cmt == CANMAKE_MAXED_OUT_FOR_PLAYER )
  265. {
  266. TheInGameUI->message( "GUI:UnitMaxedOut" );
  267. break;
  268. }
  269. // tell the UI that we want to build something so we get a building at the cursor
  270. TheInGameUI->placeBuildAvailable( commandButton->getThingTemplate(), draw );
  271. ProductionUpdateInterface* pu = obj->getProductionUpdateInterface();
  272. if( pu )
  273. {
  274. pu->setSpecialPowerConstructionCommandButton( commandButton );
  275. }
  276. break;
  277. }
  278. case GUI_COMMAND_SPECIAL_POWER_CONSTRUCT:
  279. {
  280. // sanity
  281. if( m_currentSelectedDrawable == NULL )
  282. break;
  283. const ThingTemplate *whatToBuild = commandButton->getThingTemplate();
  284. CanMakeType cmt = TheBuildAssistant->canMakeUnit( obj, whatToBuild );
  285. if (cmt == CANMAKE_NO_MONEY)
  286. {
  287. TheEva->setShouldPlay(EVA_InsufficientFunds);
  288. TheInGameUI->message( "GUI:NotEnoughMoneyToBuild" );
  289. break;
  290. }
  291. else if (cmt == CANMAKE_QUEUE_FULL)
  292. {
  293. TheInGameUI->message( "GUI:ProductionQueueFull" );
  294. break;
  295. }
  296. else if (cmt == CANMAKE_PARKING_PLACES_FULL)
  297. {
  298. TheInGameUI->message( "GUI:ParkingPlacesFull" );
  299. break;
  300. }
  301. else if( cmt == CANMAKE_MAXED_OUT_FOR_PLAYER )
  302. {
  303. TheInGameUI->message( "GUI:UnitMaxedOut" );
  304. break;
  305. }
  306. // tell the UI that we want to build something so we get a building at the cursor
  307. TheInGameUI->placeBuildAvailable( commandButton->getThingTemplate(), m_currentSelectedDrawable );
  308. ProductionUpdateInterface* pu = obj->getProductionUpdateInterface();
  309. if( pu )
  310. {
  311. pu->setSpecialPowerConstructionCommandButton( commandButton );
  312. }
  313. break;
  314. } // end dozer construct
  315. //---------------------------------------------------------------------------------------------
  316. case GUI_COMMAND_DOZER_CONSTRUCT_CANCEL:
  317. {
  318. // get the object we have selected
  319. Object *building = obj;
  320. if( building == NULL )
  321. break;
  322. // sanity check, the building must be under our control to cancel construction
  323. if( building->getControllingPlayer() != ThePlayerList->getLocalPlayer() )
  324. break;
  325. // do the message
  326. TheMessageStream->appendMessage( GameMessage::MSG_DOZER_CANCEL_CONSTRUCT );
  327. break;
  328. } // end cancel dozer construction
  329. //---------------------------------------------------------------------------------------------
  330. case GUI_COMMAND_UNIT_BUILD:
  331. {
  332. //
  333. const ThingTemplate *whatToBuild = commandButton->getThingTemplate();
  334. // get the "factory" object that is going to make the thing
  335. Object *factory = obj;
  336. if( factory == NULL )
  337. break;
  338. // sanity, we must have something to build
  339. DEBUG_ASSERTCRASH( whatToBuild, ("Undefined BUILD command for object '%s'\n",
  340. commandButton->getThingTemplate()->getName().str()) );
  341. CanMakeType cmt = TheBuildAssistant->canMakeUnit(factory, whatToBuild);
  342. if (cmt == CANMAKE_NO_MONEY)
  343. {
  344. TheEva->setShouldPlay(EVA_InsufficientFunds);
  345. TheInGameUI->message( "GUI:NotEnoughMoneyToBuild" );
  346. break;
  347. }
  348. else if (cmt == CANMAKE_QUEUE_FULL)
  349. {
  350. TheInGameUI->message( "GUI:ProductionQueueFull" );
  351. break;
  352. }
  353. else if (cmt == CANMAKE_PARKING_PLACES_FULL)
  354. {
  355. TheInGameUI->message( "GUI:ParkingPlacesFull" );
  356. break;
  357. }
  358. else if( cmt == CANMAKE_MAXED_OUT_FOR_PLAYER )
  359. {
  360. TheInGameUI->message( "GUI:UnitMaxedOut" );
  361. break;
  362. }
  363. else if (cmt != CANMAKE_OK)
  364. {
  365. DEBUG_ASSERTCRASH( 0, ("Cannot create '%s' because the factory object '%s' returns false for canMakeUnit\n",
  366. whatToBuild->getName().str(),
  367. factory->getTemplate()->getName().str()) );
  368. break;
  369. }
  370. // get the production interface from the factory object
  371. ProductionUpdateInterface *pu = factory->getProductionUpdateInterface();
  372. // sanity, we can't build things if we can't produce units
  373. if( pu == NULL )
  374. {
  375. DEBUG_ASSERTCRASH( 0, ("Cannot create '%s' because the factory object '%s' is not capable of producting units\n",
  376. whatToBuild->getName().str(),
  377. factory->getTemplate()->getName().str()) );
  378. break;
  379. } // end if
  380. // get a new production id to assign to this
  381. ProductionID productionID = pu->requestUniqueUnitID();
  382. // create a message to build this thing
  383. GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_QUEUE_UNIT_CREATE );
  384. msg->appendIntegerArgument( whatToBuild->getTemplateID() );
  385. msg->appendIntegerArgument( productionID );
  386. break;
  387. } // end build unit
  388. //---------------------------------------------------------------------------------------------
  389. case GUI_COMMAND_CANCEL_UNIT_BUILD:
  390. {
  391. Int i;
  392. // find out which index (i) in the queue represents the button clicked
  393. for( i = 0; i < MAX_BUILD_QUEUE_BUTTONS; i++ )
  394. if( m_queueData[ i ].control == control )
  395. break;
  396. // sanity, control not found
  397. if( i == MAX_BUILD_QUEUE_BUTTONS )
  398. {
  399. DEBUG_ASSERTCRASH( 0, ("Control not found in build queue data\n") );
  400. break;
  401. } // end if
  402. // sanity
  403. if( m_queueData[ i ].type != PRODUCTION_UNIT )
  404. break;
  405. // the the production ID to cancel
  406. ProductionID productionIDToCancel = m_queueData[ i ].productionID;
  407. // get the object that is the producer
  408. Object *producer = obj;
  409. if( producer == NULL )
  410. break;
  411. // sanity, we must control the producer ... if this isn't true they might be hacking the game
  412. if( producer->getControllingPlayer() != ThePlayerList->getLocalPlayer() )
  413. break;
  414. // send a message to cancel that particular production entry
  415. GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_CANCEL_UNIT_CREATE );
  416. msg->appendIntegerArgument( productionIDToCancel );
  417. break;
  418. } // end cancel unit build
  419. //---------------------------------------------------------------------------------------------
  420. case GUI_COMMAND_PLAYER_UPGRADE:
  421. {
  422. const UpgradeTemplate *upgradeT = commandButton->getUpgradeTemplate();
  423. DEBUG_ASSERTCRASH( upgradeT, ("Undefined upgrade '%s' in player upgrade command\n", "UNKNOWN") );
  424. // sanity
  425. if( obj == NULL || upgradeT == NULL )
  426. break;
  427. // make sure the player can really make this
  428. if( TheUpgradeCenter->canAffordUpgrade( ThePlayerList->getLocalPlayer(), upgradeT, TRUE ) == FALSE )
  429. {
  430. break;
  431. }
  432. ProductionUpdateInterface* pu = obj ? obj->getProductionUpdateInterface() : NULL;
  433. if (pu != NULL)
  434. {
  435. CanMakeType cmt = pu->canQueueUpgrade(upgradeT);
  436. if (cmt == CANMAKE_QUEUE_FULL)
  437. {
  438. TheInGameUI->message( "GUI:ProductionQueueFull" );
  439. break;
  440. }
  441. }
  442. // send the message
  443. GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_QUEUE_UPGRADE );
  444. msg->appendObjectIDArgument( obj->getID() );
  445. msg->appendIntegerArgument( upgradeT->getUpgradeNameKey() );
  446. break;
  447. } // command player upgrade
  448. //---------------------------------------------------------------------------------------------
  449. case GUI_COMMAND_OBJECT_UPGRADE:
  450. {
  451. const UpgradeTemplate *upgradeT = commandButton->getUpgradeTemplate();
  452. DEBUG_ASSERTCRASH( upgradeT, ("Undefined upgrade '%s' in object upgrade command\n", "UNKNOWN") );
  453. // sanity
  454. if( upgradeT == NULL )
  455. break;
  456. //Make sure the player can really make this
  457. if( TheUpgradeCenter->canAffordUpgrade( ThePlayerList->getLocalPlayer(), upgradeT, TRUE ) == FALSE )
  458. {
  459. //Kris: Disabled because we can get a valid reason for not being able to afford the upgrade!
  460. //TheInGameUI->message( "upgrade unsupported in commandprocessing." );
  461. break;
  462. }
  463. ProductionUpdateInterface* pu = obj ? obj->getProductionUpdateInterface() : NULL;
  464. if (pu != NULL)
  465. {
  466. CanMakeType cmt = pu->canQueueUpgrade(upgradeT);
  467. if (cmt == CANMAKE_QUEUE_FULL)
  468. {
  469. TheInGameUI->message( "GUI:ProductionQueueFull" );
  470. break;
  471. }
  472. }
  473. ObjectID objID = INVALID_ID;
  474. if (obj)
  475. objID = obj->getID();
  476. // make sure that the this object can actually build the upgrade
  477. if( obj && (obj->hasUpgrade( upgradeT ) == TRUE || obj->affectedByUpgrade( upgradeT ) == FALSE) )
  478. break;
  479. // send the message
  480. GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_QUEUE_UPGRADE );
  481. msg->appendObjectIDArgument( objID );
  482. msg->appendIntegerArgument( upgradeT->getUpgradeNameKey() );
  483. break;
  484. } // end object upgrade
  485. //---------------------------------------------------------------------------------------------
  486. case GUI_COMMAND_CANCEL_UPGRADE:
  487. {
  488. Int i;
  489. // find out which index (i) in the queue represents the button clicked
  490. for( i = 0; i < MAX_BUILD_QUEUE_BUTTONS; i++ )
  491. if( m_queueData[ i ].control == control )
  492. break;
  493. // sanity, control not found
  494. if( i == MAX_BUILD_QUEUE_BUTTONS )
  495. {
  496. DEBUG_ASSERTCRASH( 0, ("Control not found in build queue data\n") );
  497. break;
  498. } // end if
  499. // sanity
  500. if( m_queueData[ i ].type != PRODUCTION_UPGRADE )
  501. break;
  502. // get the upgrade to cancel
  503. const UpgradeTemplate *upgradeT = m_queueData[ i ].upgradeToResearch;
  504. // get producer object (the thing driving our UI)
  505. Object *producer = obj;
  506. // sanity
  507. if( upgradeT == NULL || producer == NULL )
  508. break;
  509. // send the message
  510. GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_CANCEL_UPGRADE );
  511. msg->appendIntegerArgument( upgradeT->getUpgradeNameKey() );
  512. break;
  513. } // end cancel upgrade
  514. //---------------------------------------------------------------------------------------------
  515. case GUI_COMMAND_ATTACK_MOVE:
  516. TheMessageStream->appendMessage(GameMessage::MSG_META_TOGGLE_ATTACKMOVE);
  517. break;
  518. //---------------------------------------------------------------------------------------------
  519. case GUI_COMMAND_STOP:
  520. {
  521. // This message always works on the currently selected team
  522. TheMessageStream->appendMessage(GameMessage::MSG_DO_STOP);
  523. break;
  524. }
  525. case GUI_COMMAND_SELECT_ALL_UNITS_OF_TYPE:
  526. {
  527. Player* localPlayer = ThePlayerList->getLocalPlayer();
  528. if( !localPlayer )
  529. {
  530. break;
  531. }
  532. const ThingTemplate *thing = commandButton->getThingTemplate();
  533. if( !thing )
  534. {
  535. break;
  536. }
  537. //deselect other units
  538. TheInGameUI->deselectAllDrawables();
  539. // create a new group.
  540. GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
  541. //New group or add to group? Passed in value is true if we are creating a new group.
  542. teamMsg->appendBooleanArgument( TRUE );
  543. //Iterate through the player's entire team and select each member that matches the template.
  544. SelectObjectsInfo info;
  545. info.thingTemplate = thing;
  546. info.msg = teamMsg;
  547. localPlayer->iterateObjects( selectObjectOfType, (void*)&info );
  548. break;
  549. }
  550. //---------------------------------------------------------------------------------------------
  551. case GUI_COMMAND_WAYPOINTS:
  552. break;
  553. //-------------------------------------------------------------------------------------------------
  554. case GUI_COMMAND_EXIT_CONTAINER:
  555. {
  556. Int i;
  557. ObjectID objID;
  558. //
  559. // find the object ID that wants to exit by scanning through the transport data and looking
  560. // for the matching control button
  561. //
  562. for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
  563. if( m_containData[ i ].control == control )
  564. objID = m_containData[ i ].objectID;
  565. // get the actual object
  566. Object *objWantingExit = TheGameLogic->findObjectByID( objID );
  567. // if object is not found remove inventory entry and exit
  568. if( objWantingExit == NULL )
  569. {
  570. //
  571. // remove from inventory data to avoid future matches ... the inventory update
  572. // cycle of the UI will repopulate any buttons as the contents of objects
  573. // change so this is only an edge case that will be visually corrected next frame
  574. //
  575. m_containData[ i ].control = NULL;
  576. m_containData[ i ].objectID = INVALID_ID;
  577. break; // exit case
  578. } // end if
  579. //what if container is subdued... assert a logic failure, perhaps?
  580. // send message to exit
  581. GameMessage *exitMsg = TheMessageStream->appendMessage( GameMessage::MSG_EXIT );
  582. exitMsg->appendObjectIDArgument( objWantingExit->getID() ); // 0 is the thing inside coming out
  583. break;
  584. } // end transport exit
  585. //---------------------------------------------------------------------------------------------
  586. case GUI_COMMAND_EVACUATE:
  587. {
  588. // Cancel GUI command mode.
  589. TheInGameUI->setGUICommand( NULL );
  590. if (BitTest(commandButton->getOptions(), NEED_TARGET_POS) == FALSE) {
  591. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_EVACUATE );
  592. TheMessageStream->appendMessage( GameMessage::MSG_EVACUATE );
  593. }
  594. break;
  595. } // end evacuate
  596. // --------------------------------------------------------------------------------------------
  597. case GUI_COMMAND_EXECUTE_RAILED_TRANSPORT:
  598. {
  599. TheMessageStream->appendMessage( GameMessage::MSG_EXECUTE_RAILED_TRANSPORT );
  600. break;
  601. } // end execute railed transport
  602. // --------------------------------------------------------------------------------------------
  603. case GUI_COMMAND_HACK_INTERNET:
  604. {
  605. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_INTERNET_HACK );
  606. TheMessageStream->appendMessage( GameMessage::MSG_INTERNET_HACK );
  607. break;
  608. }
  609. //---------------------------------------------------------------------------------------------
  610. case GUI_COMMAND_SET_RALLY_POINT:
  611. {
  612. break;
  613. } // end set rally point
  614. //---------------------------------------------------------------------------------------------
  615. case GUI_COMMAND_SELL:
  616. {
  617. // command needs no additional data, send the message
  618. TheMessageStream->appendMessage( GameMessage::MSG_SELL );
  619. break;
  620. } // end sell
  621. // --------------------------------------------------------------------------------------------
  622. case GUI_COMMAND_TOGGLE_OVERCHARGE:
  623. {
  624. TheMessageStream->appendMessage( GameMessage::MSG_TOGGLE_OVERCHARGE );
  625. break;
  626. } // end overcharge
  627. #ifdef ALLOW_SURRENDER
  628. // ------------------------------------------------------------------------------------------------
  629. case GUI_COMMAND_POW_RETURN_TO_PRISON:
  630. {
  631. TheMessageStream->appendMessage( GameMessage::MSG_RETURN_TO_PRISON );
  632. break;
  633. } // end return to prison
  634. #endif
  635. //---------------------------------------------------------------------------------------------
  636. case GUI_COMMAND_BEACON_DELETE:
  637. {
  638. break;
  639. } // end delete beacon
  640. //---------------------------------------------------------------------------------------------
  641. case GUI_COMMAND_GUARD:
  642. case GUI_COMMAND_GUARD_WITHOUT_PURSUIT:
  643. case GUI_COMMAND_GUARD_FLYING_UNITS_ONLY:
  644. case GUI_COMMAND_COMBATDROP:
  645. {
  646. DEBUG_CRASH(("hmm, should never occur"));
  647. }
  648. break;
  649. //---------------------------------------------------------------------------------------------
  650. case GUI_COMMAND_SWITCH_WEAPON:
  651. {
  652. // command needs no additional data, send the message
  653. GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_SWITCH_WEAPONS );
  654. //Play mode change acknowledgement
  655. PickAndPlayInfo info;
  656. WeaponSlotType slot = commandButton->getWeaponSlot();
  657. info.m_weaponSlot = &slot;
  658. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_SWITCH_WEAPONS, &info );
  659. msg->appendIntegerArgument( commandButton->getWeaponSlot() );
  660. break;
  661. }
  662. //---------------------------------------------------------------------------------------------
  663. case GUI_COMMAND_FIRE_WEAPON:
  664. {
  665. // command needs no additional data, send the message
  666. GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_WEAPON );
  667. msg->appendIntegerArgument( commandButton->getWeaponSlot() );
  668. msg->appendIntegerArgument( commandButton->getMaxShotsToFire() );
  669. break;
  670. } // end fire weapon
  671. //---------------------------------------------------------------------------------------------
  672. case GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT:
  673. {
  674. const SpecialPowerTemplate *spTemplate = commandButton->getSpecialPowerTemplate();
  675. SpecialPowerType spType = spTemplate->getSpecialPowerType();
  676. Object* obj = ThePlayerList->getLocalPlayer()->findMostReadyShortcutSpecialPowerOfType( spType );
  677. if( !obj )
  678. break;
  679. // command needs no additional data, send the message
  680. GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_SPECIAL_POWER );
  681. msg->appendIntegerArgument( spTemplate->getID() );
  682. msg->appendIntegerArgument( commandButton->getOptions() );
  683. msg->appendObjectIDArgument( obj->getID() );
  684. break;
  685. } // end special weapon
  686. case GUI_COMMAND_SPECIAL_POWER:
  687. {
  688. // command needs no additional data, send the message
  689. GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_SPECIAL_POWER );
  690. msg->appendIntegerArgument( commandButton->getSpecialPowerTemplate()->getID() );
  691. msg->appendIntegerArgument( commandButton->getOptions() );
  692. msg->appendObjectIDArgument( INVALID_ID ); // no specific source
  693. break;
  694. } // end special weapon
  695. //---------------------------------------------------------------------------------------------
  696. case GUI_COMMAND_PURCHASE_SCIENCE:
  697. {
  698. // loop through all the sciences on the button and select the one we don't have
  699. ScienceType st = SCIENCE_INVALID;
  700. Player *player = ThePlayerList->getLocalPlayer();
  701. for(Int i = 0; i < commandButton->getScienceVec().size(); ++i)
  702. {
  703. st = commandButton->getScienceVec()[ i ];
  704. if(!player->hasScience(st) && TheScienceStore->playerHasPrereqsForScience(player, st) && TheScienceStore->getSciencePurchaseCost(st) <= player->getSciencePurchasePoints())
  705. {
  706. break;
  707. }
  708. }
  709. if( st == SCIENCE_INVALID)
  710. {
  711. switchToContext( CB_CONTEXT_NONE, NULL );
  712. break;
  713. }
  714. GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_PURCHASE_SCIENCE );
  715. msg->appendIntegerArgument( st );
  716. markUIDirty();
  717. break;
  718. } // end pick specialized science
  719. //---------------------------------------------------------------------------------------------
  720. default:
  721. DEBUG_ASSERTCRASH( 0, ("Unknown command '%d'\n", commandButton->getCommandType()) );
  722. return CBC_COMMAND_NOT_USED;
  723. } // end switch
  724. return CBC_COMMAND_USED;
  725. } // end processCommandUI