CommandXlat.cpp 154 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615
  1. /*
  2. ** Command & Conquer Generals(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. // CommandXlat.cpp
  24. // Translate raw input events into tactical commands
  25. // Author: Michael S. Booth, February 2001
  26. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  27. #include "stdlib.h" // VC++ wants this here, or gives compile error...
  28. #include "Common/AudioAffect.h"
  29. #include "Common/ActionManager.h"
  30. #include "Common/GameAudio.h"
  31. #include "Common/GameEngine.h"
  32. #include "Common/GameType.h"
  33. #include "Common/GlobalData.h"
  34. #include "Common/MessageStream.h"
  35. #include "Common/MiscAudio.h"
  36. #include "Common/MultiplayerSettings.h"
  37. #include "Common/PerfTimer.h"
  38. #include "Common/Player.h"
  39. #include "Common/PlayerList.h"
  40. #include "Common/PlayerTemplate.h"
  41. #include "Common/Radar.h"
  42. #include "Common/Recorder.h"
  43. #include "Common/SpecialPower.h"
  44. #include "Common/StatsCollector.h"
  45. #include "Common/ThingTemplate.h"
  46. #include "Common/GameLOD.h"
  47. #include "GameClient/InGameUI.h"
  48. #include "GameClient/CommandXlat.h"
  49. #include "GameClient/DebugDisplay.h"
  50. #include "GameClient/Drawable.h"
  51. #include "GameClient/GameClient.h"
  52. #include "GameClient/GameWindowManager.h"
  53. #include "GameClient/GameText.h"
  54. #include "GameClient/ParticleSys.h"
  55. #include "GameClient/GUICallbacks.h"
  56. #include "GameClient/Shell.h"
  57. #include "GameClient/ControlBar.h"
  58. #include "GameClient/SelectionInfo.h"
  59. #include "GameClient/SelectionXlat.h"
  60. #include "GameLogic/Module/AIUpdate.h"
  61. #include "GameLogic/ExperienceTracker.h"
  62. #include "GameLogic/GameLogic.h"
  63. #include "GameLogic/Module/BodyModule.h"
  64. #include "GameLogic/Object.h"
  65. #include "GameLogic/PartitionManager.h"
  66. #include "GameLogic/ScriptEngine.h"
  67. #include "GameLogic/TerrainLogic.h"
  68. #include "GameLogic/GhostObject.h"
  69. #include "GameLogic/Weapon.h"
  70. #include "GameLogic/Module/SpawnBehavior.h"
  71. #include "GameLogic/Module/SpecialPowerModule.h"
  72. #include "Common/ThingFactory.h"
  73. #include "GameLogic/Module/ContainModule.h"
  74. #include "GameNetwork/NetworkInterface.h"
  75. #include "GameNetwork/GameInfo.h"
  76. #include "GameNetwork/GameSpyOverlay.h"
  77. #include "GameNetwork/GameSpy/BuddyThread.h"
  78. #ifdef _INTERNAL
  79. // for occasional debugging...
  80. //#pragma optimize("", off)
  81. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  82. #endif
  83. #if defined(_DEBUG) || defined(_INTERNAL)
  84. /*non-static*/ Real TheSkateDistOverride = 0.0f;
  85. void countObjects(Object *obj, void *userData)
  86. {
  87. Int *numObjects = (Int *)userData;
  88. if (!numObjects || !obj)
  89. return;
  90. DEBUG_LOG(("Looking at obj %d (%s) - isEffectivelyDead()==%d, isDestroyed==%d, numObjects==%d\n",
  91. obj->getID(), obj->getTemplate()->getName().str(), obj->isEffectivelyDead(), obj->isDestroyed(), *numObjects));
  92. if (!obj->isEffectivelyDead() && !obj->isDestroyed() && !obj->isKindOf(KINDOF_INERT))
  93. ++(*numObjects);
  94. }
  95. void printObjects(Object *obj, void *userData)
  96. {
  97. if (!obj)
  98. return;
  99. Bool isDead = obj->isEffectivelyDead() || obj->isDestroyed();
  100. Bool isInert = obj->isKindOf(KINDOF_INERT);
  101. AsciiString statusStr = (isDead)?"Dead":(isInert)?"Inert":"Living";
  102. AsciiString line;
  103. if (obj->getName().isEmpty())
  104. line.format(" Obj#%d %s - (%g,%g) %s", obj->getID(), obj->getTemplate()->getName().str(),
  105. obj->getPosition()->x, obj->getPosition()->y, statusStr.str());
  106. else
  107. line.format(" Obj#%d %s (%s) - (%g,%g) %s", obj->getID(), obj->getTemplate()->getName().str(),
  108. obj->getName().str(), obj->getPosition()->x, obj->getPosition()->y, statusStr.str());
  109. TheScriptEngine->AppendDebugMessage(line, FALSE);
  110. }
  111. #endif
  112. static Bool isSystemMessage( const GameMessage *msg );
  113. enum{ DROPPED_MAX_PARTICLE_COUNT = 1000};
  114. static Bool canSelectionSalvage( const Object *targetObj)
  115. {
  116. if (!targetObj) {
  117. return FALSE;
  118. }
  119. if (!targetObj->isSalvageCrate()) {
  120. return FALSE;
  121. }
  122. const DrawableList *drawList = TheInGameUI->getAllSelectedDrawables();
  123. for (DrawableListCIt cit = drawList->begin(); cit != drawList->end(); ++cit)
  124. {
  125. Drawable *draw = *cit;
  126. if (!draw)
  127. {
  128. continue;
  129. }
  130. Object *obj = draw->getObject();
  131. if (!obj)
  132. {
  133. continue;
  134. }
  135. if (obj->isKindOf(KINDOF_SALVAGER)) {
  136. return TRUE;
  137. }
  138. }
  139. return FALSE;
  140. }
  141. //-------------------------------------------------------------------------------------------------
  142. static CanAttackResult canObjectForceAttack( Object *obj, const Object *victim, const Coord3D *pos )
  143. {
  144. CanAttackResult result;
  145. result = obj->isAbleToAttack() ? ATTACKRESULT_POSSIBLE : ATTACKRESULT_NOT_POSSIBLE;
  146. if( result == ATTACKRESULT_NOT_POSSIBLE )
  147. {
  148. return ATTACKRESULT_NOT_POSSIBLE;
  149. }
  150. if (victim)
  151. {
  152. result = obj->getAbleToAttackSpecificObject(ATTACK_NEW_TARGET_FORCED, victim, CMD_FROM_PLAYER );
  153. //Special case -- objects with spawn weapons have to do different checks. Stinger site with stinger soldiers is
  154. //the catalyst example.
  155. if( result != ATTACKRESULT_POSSIBLE && result != ATTACKRESULT_POSSIBLE_AFTER_MOVING && obj->isKindOf( KINDOF_SPAWNS_ARE_THE_WEAPONS ) )
  156. {
  157. SpawnBehaviorInterface *spawnInterface = obj->getSpawnBehaviorInterface();
  158. if( spawnInterface )
  159. {
  160. //We found the spawn interface, now get the closest slave to the target.
  161. Object *slave = spawnInterface->getClosestSlave( victim->getPosition() );
  162. if( slave )
  163. {
  164. result = slave->getAbleToAttackSpecificObject( ATTACK_NEW_TARGET_FORCED, victim, CMD_FROM_PLAYER );
  165. }
  166. }
  167. }
  168. return result;
  169. }
  170. else
  171. {
  172. //Almost every combat unit can force attack a position. The exceptions include stationary units
  173. //that try to force attack in a location beyond their reach (range, LOS, etc).
  174. if( pos )
  175. {
  176. Object *testObj = obj;
  177. if( obj->isKindOf( KINDOF_IMMOBILE ) || obj->isKindOf( KINDOF_SPAWNS_ARE_THE_WEAPONS ) )
  178. {
  179. SpawnBehaviorInterface *spawnInterface = obj->getSpawnBehaviorInterface();
  180. if( spawnInterface )
  181. {
  182. //We found the spawn interface, now get the closest slave to the target.
  183. Object *slave = spawnInterface->getClosestSlave( pos );
  184. if( slave )
  185. {
  186. testObj = obj;
  187. }
  188. }
  189. }
  190. //Now evaluate the testObj to see if it is capable of force attacking the pos.
  191. result = testObj->getAbleToUseWeaponAgainstTarget( ATTACK_NEW_TARGET, victim, pos, CMD_FROM_PLAYER );
  192. return result;
  193. }
  194. }
  195. return ATTACKRESULT_NOT_POSSIBLE;
  196. }
  197. //-------------------------------------------------------------------------------------------------
  198. static CanAttackResult canAnyForceAttack(const DrawableList *allSelected, const Object *victim, const Coord3D *pos )
  199. {
  200. // check to make sure that allSelected can attack obj.
  201. for (DrawableListCIt cit = allSelected->begin(); cit != allSelected->end(); ++cit)
  202. {
  203. Drawable *draw = *cit;
  204. if (!draw)
  205. {
  206. continue;
  207. }
  208. Object *obj = draw->getObject();
  209. if (!obj)
  210. {
  211. continue;
  212. }
  213. return canObjectForceAttack( obj, victim, pos );
  214. }
  215. return ATTACKRESULT_NOT_POSSIBLE;
  216. }
  217. //-------------------------------------------------------------------------------------------------
  218. void pickAndPlayUnitVoiceResponse( const DrawableList *list, GameMessage::Type msgType, PickAndPlayInfo *info )
  219. {
  220. if (!list)
  221. {
  222. return;
  223. }
  224. const AudioEventRTS* soundToPlayPtr = NULL;
  225. Object *objectWithSound = NULL;
  226. Bool skip = false;
  227. Object *target = NULL;
  228. if( info && info->m_drawTarget )
  229. {
  230. target = info->m_drawTarget->getObject();
  231. }
  232. //Now, loop through all the drawables (even if you find a match on the first.
  233. //The innards are responsible for "upgrading" a sound that is played based on
  234. //priorities. For example, the voice move or voice crush. Voice move gets set
  235. //when we have a null event -- but if any of the units can crush the specified
  236. //target, then it changes to VoiceCrush.
  237. for( DrawableListCIt it = list->begin(); it != list->end(); ++it )
  238. {
  239. Object *obj = (*it)->getObject();
  240. if (obj->isKindOf( KINDOF_IGNORED_IN_GUI ))
  241. continue;
  242. // Use the object instead of the drawable to get the thing template from. This way, we get the
  243. // sounds even if the thing is disguised as something else. (Ala bomb truck.)
  244. const ThingTemplate *templ = obj->getTemplate();
  245. if (!templ)
  246. {
  247. return;
  248. }
  249. switch (msgType)
  250. {
  251. case GameMessage::MSG_DOCK:
  252. soundToPlayPtr = templ->getPerUnitSound("VoiceSupply");
  253. objectWithSound = obj;
  254. skip = true;
  255. break;
  256. case GameMessage::MSG_SELECT_TEAM0:
  257. case GameMessage::MSG_SELECT_TEAM1:
  258. case GameMessage::MSG_SELECT_TEAM2:
  259. case GameMessage::MSG_SELECT_TEAM3:
  260. case GameMessage::MSG_SELECT_TEAM4:
  261. case GameMessage::MSG_SELECT_TEAM5:
  262. case GameMessage::MSG_SELECT_TEAM6:
  263. case GameMessage::MSG_SELECT_TEAM7:
  264. case GameMessage::MSG_SELECT_TEAM8:
  265. case GameMessage::MSG_SELECT_TEAM9:
  266. case GameMessage::MSG_CREATE_SELECTED_GROUP:
  267. soundToPlayPtr = templ->getVoiceSelect();
  268. objectWithSound = obj;
  269. skip = true;
  270. break;
  271. case GameMessage::MSG_EVACUATE:
  272. soundToPlayPtr = templ->getPerUnitSound( "VoiceUnload" );
  273. objectWithSound = obj;
  274. skip = true;
  275. break;
  276. case GameMessage::MSG_DO_REPAIR:
  277. soundToPlayPtr = templ->getPerUnitSound( "VoiceRepair" );
  278. objectWithSound = obj;
  279. skip = true;
  280. break;
  281. #ifdef ALLOW_SURRENDER
  282. case GameMessage::MSG_PICK_UP_PRISONER:
  283. soundToPlayPtr = templ->getPerUnitSound( "VoicePickup" );
  284. objectWithSound = obj;
  285. skip = true;
  286. break;
  287. #endif
  288. case GameMessage::MSG_COMBATDROP_AT_LOCATION:
  289. case GameMessage::MSG_COMBATDROP_AT_OBJECT:
  290. soundToPlayPtr = templ->getPerUnitSound( "VoiceCombatDrop" );
  291. objectWithSound = obj;
  292. skip = true;
  293. break;
  294. case GameMessage::MSG_ENTER:
  295. if( target && target->isKindOf( KINDOF_HEAL_PAD ) )
  296. {
  297. soundToPlayPtr = templ->getPerUnitSound( "VoiceGetHealed" );
  298. }
  299. else if( target && target->isKindOf( KINDOF_STRUCTURE ) )
  300. {
  301. soundToPlayPtr = templ->getPerUnitSound( "VoiceGarrison" );
  302. }
  303. // order matters: we want to know if I consider it to be an ally, not vice versa
  304. else if( target && obj->getRelationship(target) != ALLIES )
  305. {
  306. soundToPlayPtr = templ->getPerUnitSound( "VoiceEnterHostile" );
  307. }
  308. else
  309. {
  310. soundToPlayPtr = templ->getPerUnitSound( "VoiceEnter" );
  311. }
  312. objectWithSound = obj;
  313. skip = true;
  314. break;
  315. case GameMessage::MSG_DO_MOVETO:
  316. case GameMessage::MSG_DO_ATTACKMOVETO:
  317. case GameMessage::MSG_GET_REPAIRED:
  318. case GameMessage::MSG_GET_HEALED:
  319. case GameMessage::MSG_DO_SALVAGE:
  320. {
  321. AIUpdateInterface *ai = obj->getAI();
  322. if( ai )
  323. {
  324. //This flag determines if the object has started moving yet... if not
  325. //it's a good initial check.
  326. Bool isEffectivelyMoving = ai->isMoving() || ai->isWaitingForPath();
  327. if( TheInGameUI->isInWaypointMode() )
  328. {
  329. if( isEffectivelyMoving )
  330. {
  331. //Don't want to play the sound unless he's not moving!
  332. continue;
  333. }
  334. }
  335. //Default to voice move (it'll be selected if we can't find a crush case as we iterate
  336. //through the rest of the drawables)
  337. if( !soundToPlayPtr )
  338. {
  339. soundToPlayPtr = templ->getVoiceMove();
  340. objectWithSound = obj;
  341. }
  342. if( TheInGameUI->isInForceMoveToMode() && target )
  343. {
  344. if( obj->canCrushOrSquish( target ) )
  345. {
  346. //Change it to voice crush because we are intentionally trying to crush this!
  347. soundToPlayPtr = templ->getPerUnitSound( "VoiceCrush" );
  348. objectWithSound = obj;
  349. skip = true;
  350. }
  351. }
  352. if (msgType == GameMessage::MSG_DO_SALVAGE)
  353. {
  354. const AudioEventRTS *tempSound = templ->getPerUnitSound( "VoiceSalvage" );
  355. if (TheAudio->isValidAudioEvent(tempSound))
  356. {
  357. soundToPlayPtr = tempSound;
  358. objectWithSound = obj;
  359. skip = true;
  360. }
  361. }
  362. }
  363. break;
  364. }
  365. case GameMessage::MSG_RESUME_CONSTRUCTION:
  366. case GameMessage::MSG_DOZER_CONSTRUCT:
  367. case GameMessage::MSG_DOZER_CONSTRUCT_LINE:
  368. {
  369. soundToPlayPtr = templ->getPerUnitSound( "VoiceBuildResponse" );
  370. objectWithSound = obj;
  371. skip = true;
  372. break;
  373. }
  374. case GameMessage::MSG_DO_FORCE_ATTACK_GROUND:
  375. {
  376. soundToPlayPtr = templ->getPerUnitSound( "VoiceBombard" );
  377. objectWithSound = obj;
  378. skip = true;
  379. if (TheAudio->isValidAudioEvent(soundToPlayPtr)) {
  380. break;
  381. } else {
  382. // clear out the sound to play, and drop into the attack object logic.
  383. soundToPlayPtr = NULL;
  384. }
  385. }
  386. case GameMessage::MSG_SWITCH_WEAPONS:
  387. {
  388. if( info && info->m_weaponSlot )
  389. {
  390. switch( *info->m_weaponSlot )
  391. {
  392. case PRIMARY_WEAPON:
  393. soundToPlayPtr = templ->getPerUnitSound( "VoicePrimaryWeaponMode" );
  394. break;
  395. case SECONDARY_WEAPON:
  396. soundToPlayPtr = templ->getPerUnitSound( "VoiceSecondaryWeaponMode" );
  397. break;
  398. case TERTIARY_WEAPON:
  399. soundToPlayPtr = templ->getPerUnitSound( "VoiceTertiaryWeaponMode" );
  400. break;
  401. }
  402. objectWithSound = obj;
  403. skip = true;
  404. }
  405. break;
  406. }
  407. case GameMessage::MSG_DO_FORCE_ATTACK_OBJECT:
  408. case GameMessage::MSG_DO_ATTACK_OBJECT:
  409. case GameMessage::MSG_DO_WEAPON_AT_OBJECT:
  410. {
  411. if( !soundToPlayPtr )
  412. {
  413. //Low priority sounds -- only do this if uninitialized.
  414. if( info && info->m_air )
  415. soundToPlayPtr = templ->getVoiceAttackAir();
  416. else
  417. soundToPlayPtr = templ->getVoiceAttack();
  418. objectWithSound = obj;
  419. }
  420. //Look for a specialty weapon fired via command button!
  421. Bool specialtyWeapon = FALSE;
  422. if( msgType == GameMessage::MSG_DO_WEAPON_AT_OBJECT )
  423. {
  424. specialtyWeapon = TRUE;
  425. }
  426. Weapon *weapon = obj->getCurrentWeapon();
  427. if( info && info->m_weaponSlot )
  428. {
  429. weapon = obj->getWeaponInWeaponSlot( *info->m_weaponSlot );
  430. }
  431. if( weapon )
  432. {
  433. switch( weapon->getDamageType() )
  434. {
  435. // this stays, even if ALLOW_SURRENDER is not defed, since flashbangs still use 'em
  436. case DAMAGE_SURRENDER:
  437. if( target && target->isKindOf( KINDOF_STRUCTURE ) )
  438. {
  439. //We are attempting to take over a building with rangers and flashbangs!
  440. soundToPlayPtr = templ->getPerUnitSound( "VoiceClearBuilding" );
  441. }
  442. else
  443. {
  444. //Special for subdue attacks.
  445. soundToPlayPtr = templ->getPerUnitSound( "VoiceSubdue" );
  446. }
  447. objectWithSound = obj;
  448. skip = true;
  449. break;
  450. case DAMAGE_DISARM:
  451. //Special for mine clearing attacks.
  452. soundToPlayPtr = templ->getPerUnitSound( "VoiceDisarm" );
  453. objectWithSound = obj;
  454. skip = true;
  455. break;
  456. case DAMAGE_KILLPILOT:
  457. if( specialtyWeapon )
  458. {
  459. //Special for sniping vehicle pilots.
  460. soundToPlayPtr = templ->getPerUnitSound( "VoiceSnipePilot" );
  461. objectWithSound = obj;
  462. skip = true;
  463. }
  464. break;
  465. case DAMAGE_MELEE:
  466. if( specialtyWeapon )
  467. {
  468. //Special for stabbing
  469. soundToPlayPtr = templ->getPerUnitSound( "VoiceMelee" );
  470. objectWithSound = obj;
  471. skip = true;
  472. }
  473. break;
  474. }
  475. }
  476. break;
  477. }
  478. case GameMessage::MSG_DO_WEAPON_AT_LOCATION:
  479. {
  480. if( !soundToPlayPtr )
  481. {
  482. //Low priority sounds -- only do this if uninitialized.
  483. if( info && info->m_air )
  484. soundToPlayPtr = templ->getVoiceAttackAir();
  485. else
  486. soundToPlayPtr = templ->getVoiceAttack();
  487. objectWithSound = obj;
  488. }
  489. //Check for possibility of a higher priority sound!
  490. Weapon *weapon = obj->getCurrentWeapon();
  491. if( info && info->m_weaponSlot )
  492. {
  493. weapon = obj->getWeaponInWeaponSlot( *info->m_weaponSlot );
  494. }
  495. if( weapon )
  496. {
  497. switch( weapon->getDamageType() )
  498. {
  499. // this stays, even if ALLOW_SURRENDER is not defed, since flashbangs still use 'em
  500. case DAMAGE_SURRENDER:
  501. break;
  502. case DAMAGE_DISARM:
  503. //Special for mine clearing attacks.
  504. soundToPlayPtr = templ->getPerUnitSound( "VoiceDisarm" );
  505. objectWithSound = obj;
  506. break;
  507. //these are specific to the guicommand based ground attacks, the toxin sprinkler and the firestorm wall thing
  508. //hence the additional check for it being a non-primary weapon
  509. case DAMAGE_FLAME:
  510. if (weapon->getWeaponSlot() != PRIMARY_WEAPON)
  511. {
  512. soundToPlayPtr = templ->getPerUnitSound( "VoiceFlameLocation" );
  513. objectWithSound = obj;
  514. }
  515. break;
  516. case DAMAGE_POISON:
  517. if (weapon->getWeaponSlot() != PRIMARY_WEAPON)
  518. {
  519. soundToPlayPtr = templ->getPerUnitSound( "VoicePoisonLocation" );
  520. objectWithSound = obj;
  521. }
  522. break;
  523. default:
  524. if( !weapon->getName().compare( "ComancheRocketPodWeapon" ) )
  525. {
  526. //Special case for comanche rocket pods.
  527. soundToPlayPtr = templ->getPerUnitSound( "VoiceFireRocketPods" );
  528. objectWithSound = obj;
  529. skip = true;
  530. }
  531. }
  532. }
  533. break;
  534. }
  535. case GameMessage::MSG_DO_GUARD_POSITION:
  536. case GameMessage::MSG_DO_GUARD_OBJECT:
  537. soundToPlayPtr = templ->getVoiceGuard();
  538. objectWithSound = obj;
  539. skip = true;
  540. break;
  541. case GameMessage::MSG_DO_SPECIAL_POWER:
  542. case GameMessage::MSG_DO_SPECIAL_POWER_AT_LOCATION:
  543. case GameMessage::MSG_DO_SPECIAL_POWER_AT_OBJECT:
  544. {
  545. if( info && info->m_specialPowerType != SPECIAL_INVALID )
  546. {
  547. SpecialPowerModuleInterface *spmInterface = obj->findSpecialPowerModuleInterface( info->m_specialPowerType );
  548. if( spmInterface )
  549. {
  550. objectWithSound = obj;
  551. soundToPlayPtr = &spmInterface->getInitiateSound();
  552. skip = TRUE;
  553. }
  554. }
  555. break;
  556. }
  557. case GameMessage::MSG_INTERNET_HACK:
  558. objectWithSound = obj;
  559. soundToPlayPtr = templ->getPerUnitSound( "VoiceHackInternet" );
  560. skip = TRUE;
  561. break;
  562. default:
  563. DEBUG_LOG(("Requested to add voice of message type %d, but don't know how - jkmcd\n", msgType));
  564. break;
  565. }
  566. if( skip )
  567. {
  568. //The unit sound doesn't have any sort of priority or special case, so simply play the first one that comes along.
  569. break;
  570. }
  571. }//next drawable in list
  572. if (!soundToPlayPtr)
  573. return;
  574. AudioEventRTS soundToPlay = *soundToPlayPtr;
  575. // to prevent voice stepping.
  576. if( objectWithSound )
  577. {
  578. soundToPlay.setObjectID( objectWithSound->getID() );
  579. TheAudio->addAudioEvent(&soundToPlay);
  580. // This seems really hacky, and MarkL admits that it is. However, we do this so that we
  581. // can "randomly" pick a different sound the next time, if we have 3 or more sounds. - jkmcd
  582. ((AudioEventRTS*)soundToPlayPtr)->setPlayingAudioIndex( soundToPlay.getPlayingAudioIndex() );
  583. if( objectWithSound->testStatus( OBJECT_STATUS_IS_CARBOMB ) )
  584. {
  585. //Additional sounds for terrorists in cars.
  586. switch (msgType)
  587. {
  588. case GameMessage::MSG_DO_FORCE_ATTACK_GROUND:
  589. case GameMessage::MSG_DO_FORCE_ATTACK_OBJECT:
  590. case GameMessage::MSG_DO_ATTACK_OBJECT:
  591. soundToPlay = TheAudio->getMiscAudio()->m_terroristInCarAttackVoice;
  592. soundToPlay.setObjectID( objectWithSound->getID() );
  593. TheAudio->addAudioEvent(&soundToPlay);
  594. break;
  595. case GameMessage::MSG_DO_MOVETO:
  596. case GameMessage::MSG_DO_ATTACKMOVETO:
  597. case GameMessage::MSG_GET_REPAIRED:
  598. case GameMessage::MSG_GET_HEALED:
  599. case GameMessage::MSG_DO_SALVAGE:
  600. soundToPlay = TheAudio->getMiscAudio()->m_terroristInCarMoveVoice;
  601. soundToPlay.setObjectID( objectWithSound->getID() );
  602. TheAudio->addAudioEvent(&soundToPlay);
  603. break;
  604. case GameMessage::MSG_SELECT_TEAM0:
  605. case GameMessage::MSG_SELECT_TEAM1:
  606. case GameMessage::MSG_SELECT_TEAM2:
  607. case GameMessage::MSG_SELECT_TEAM3:
  608. case GameMessage::MSG_SELECT_TEAM4:
  609. case GameMessage::MSG_SELECT_TEAM5:
  610. case GameMessage::MSG_SELECT_TEAM6:
  611. case GameMessage::MSG_SELECT_TEAM7:
  612. case GameMessage::MSG_SELECT_TEAM8:
  613. case GameMessage::MSG_SELECT_TEAM9:
  614. case GameMessage::MSG_CREATE_SELECTED_GROUP:
  615. soundToPlay = TheAudio->getMiscAudio()->m_terroristInCarSelectVoice;
  616. soundToPlay.setObjectID( objectWithSound->getID() );
  617. TheAudio->addAudioEvent(&soundToPlay);
  618. break;
  619. }
  620. }
  621. }
  622. }
  623. //------------------------------------------------------------------------------------
  624. /**
  625. * Find a suitable command center to view.
  626. */
  627. struct CommandCenterLocator
  628. {
  629. Bool atLeastOne;
  630. Bool isCommandCenter;
  631. Int val;
  632. Coord3D loc;
  633. CommandCenterLocator() : atLeastOne(false), isCommandCenter(false), val(-1)
  634. {
  635. loc.zero();
  636. }
  637. };
  638. void findCommandCenterOrMostExpensiveBuilding(Object* obj, void* vccl)
  639. {
  640. if (!obj) {
  641. return;
  642. }
  643. CommandCenterLocator *ccl = (CommandCenterLocator*) vccl;
  644. // here's the deal. We want to get the first Command Center in the list.
  645. // Barring that, we want the most expensive structure we currently own.
  646. if (obj->isKindOf(KINDOF_COMMANDCENTER)) {
  647. ccl->isCommandCenter = true;
  648. ccl->loc = *obj->getPosition();
  649. } else if (!ccl->isCommandCenter) {
  650. if (!obj->isKindOf(KINDOF_STRUCTURE)) {
  651. return;
  652. }
  653. Int costToBuild = obj->getTemplate()->calcCostToBuild(obj->getControllingPlayer());
  654. if (costToBuild > ccl->val) {
  655. ccl->val = costToBuild;
  656. ccl->loc = *obj->getPosition();
  657. }
  658. }
  659. ccl->atLeastOne = true;
  660. }
  661. static void viewCommandCenter( void )
  662. {
  663. Player* localPlayer = ThePlayerList->getLocalPlayer();
  664. if (!localPlayer)
  665. return;
  666. CommandCenterLocator ccl;
  667. localPlayer->iterateObjects(findCommandCenterOrMostExpensiveBuilding, &ccl);
  668. if (ccl.atLeastOne) {
  669. TheTacticalView->lookAt(&ccl.loc);
  670. } else {
  671. // @todo. Find their starting position and look at that instead?
  672. }
  673. }
  674. //----------------- Select and View Hero -----------------------------------
  675. struct HeroHolder
  676. {
  677. Object *hero;
  678. };
  679. void amIAHero(Object* obj, void* heroHolder)
  680. {
  681. if (!obj || ((HeroHolder*)heroHolder)->hero != NULL)
  682. {
  683. return;
  684. }
  685. if (obj->isKindOf( KINDOF_HERO ))
  686. {
  687. ((HeroHolder*)heroHolder)->hero = obj;
  688. }
  689. }
  690. static Object *iNeedAHero( void )
  691. {
  692. Player* localPlayer = ThePlayerList->getLocalPlayer();
  693. if (!localPlayer)
  694. return NULL;
  695. HeroHolder heroHolder;
  696. heroHolder.hero = NULL;
  697. localPlayer->iterateObjects(amIAHero, (void*)&heroHolder);
  698. return heroHolder.hero;
  699. }
  700. //------------------------------------------------------------------------------------
  701. /**
  702. * Create DO_MOVE_TO messages for each selected object, instructing it to move to the given location.
  703. */
  704. GameMessage::Type CommandTranslator::issueMoveToLocationCommand( const Coord3D *pos, Drawable *drawableInWay,
  705. CommandEvaluateType commandType )
  706. {
  707. GameMessage::Type msgType = GameMessage::MSG_INVALID;
  708. Object *obj = drawableInWay ? drawableInWay->getObject() : NULL;
  709. Bool isForceAttackable = FALSE;
  710. if (obj) {
  711. isForceAttackable = obj->isKindOf(KINDOF_FORCEATTACKABLE);
  712. }
  713. if (m_teamExists)
  714. {
  715. if( TheInGameUI->isInWaypointMode() )
  716. {
  717. msgType = GameMessage::MSG_ADD_WAYPOINT;
  718. }
  719. else if( TheInGameUI->isInAttackMoveToMode())
  720. {
  721. msgType = GameMessage::MSG_DO_ATTACKMOVETO;
  722. }
  723. else if( TheInGameUI->isInForceMoveToMode() )
  724. {
  725. msgType = GameMessage::MSG_DO_FORCEMOVETO;
  726. }
  727. else if( TheInGameUI->isInForceAttackMode() && isForceAttackable )
  728. {
  729. msgType = GameMessage::MSG_DO_ATTACK_OBJECT;
  730. }
  731. else
  732. {
  733. msgType = GameMessage::MSG_DO_MOVETO;
  734. }
  735. if( commandType == DO_COMMAND )
  736. {
  737. GameMessage *movemsg = TheMessageStream->appendMessage( msgType );
  738. if (msgType == GameMessage::MSG_DO_ATTACK_OBJECT)
  739. movemsg->appendObjectIDArgument( obj->getID() );
  740. else
  741. movemsg->appendLocationArgument( *pos );
  742. } // end if
  743. }
  744. // only make sounds if we really did the command messages
  745. if( commandType == DO_COMMAND )
  746. {
  747. PickAndPlayInfo info;
  748. info.m_drawTarget = drawableInWay;
  749. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_DO_MOVETO, &info );
  750. } // end if
  751. if(TheStatsCollector)
  752. TheStatsCollector->incrementMoveCount();
  753. // return the actual msg type used
  754. return msgType;
  755. }
  756. //------------------------------------------------------------------------------------
  757. /// @todo Play attack command response sound on client-side to hide latency
  758. GameMessage::Type CommandTranslator::createAttackMessage( Drawable *draw,
  759. Drawable *other,
  760. CommandEvaluateType commandType )
  761. {
  762. GameMessage::Type msgType = GameMessage::MSG_INVALID;
  763. // the drawable must have an object to be able to attack
  764. if( draw->getObject() == NULL )
  765. return msgType;
  766. // the target must have an object to be attacked
  767. if( other->getObject() == NULL )
  768. return msgType;
  769. // insert object attack command message into stream
  770. msgType = GameMessage::MSG_DO_ATTACK_OBJECT;
  771. // only make the message if we are really doing a command
  772. if( commandType == DO_COMMAND )
  773. {
  774. GameMessage *attackmsg = TheMessageStream->appendMessage( msgType );
  775. attackmsg->appendObjectIDArgument( other->getObject()->getID() ); // must pass object IDs to logic
  776. } // end if
  777. // return the message type created
  778. return msgType;
  779. }
  780. //------------------------------------------------------------------------------------
  781. /**
  782. * Create DO_ATTACK_GROUND_OBJECT messages for each selected object, instructing it to attack the given enemy.
  783. * Return TRUE if any attacks actually occurred.
  784. */
  785. GameMessage::Type CommandTranslator::issueAttackCommand( Drawable *target,
  786. CommandEvaluateType commandType,
  787. GUICommandType command )
  788. {
  789. GameMessage::Type msgType = GameMessage::MSG_INVALID;
  790. if (target == NULL)
  791. return msgType;
  792. // you cannot attack an enemy that has no object representation
  793. Object *targetObj = target->getObject();
  794. if( !targetObj )
  795. return msgType;
  796. if( m_teamExists )
  797. {
  798. //DEBUG_LOG(("issuing team-attack cmd against %s\n",enemy->getTemplate()->getName().str()));
  799. // insert team attack command message into stream
  800. switch( command )
  801. {
  802. #ifdef ALLOW_SURRENDER
  803. case GUICOMMANDMODE_PICK_UP_PRISONER:
  804. msgType = GameMessage::MSG_PICK_UP_PRISONER;
  805. break;
  806. #endif
  807. case GUI_COMMAND_NONE:
  808. msgType = GameMessage::MSG_DO_ATTACK_OBJECT;
  809. break;
  810. default:
  811. DEBUG_ASSERTCRASH( 0, ("issueAttackCommand was passed in a GUICommandType type that isn't supported yet...") );
  812. return msgType;
  813. }
  814. // only create the message if our command type is DO_COMMAND
  815. if( commandType == DO_COMMAND )
  816. {
  817. GameMessage *attackMsg;
  818. attackMsg = TheMessageStream->appendMessage( msgType );
  819. attackMsg->appendObjectIDArgument( targetObj->getID() ); // must pass target object ID to logic
  820. // if we have a stats collector, inrement the stats
  821. if(TheStatsCollector)
  822. TheStatsCollector->incrementAttackCount();
  823. } // end if
  824. }
  825. else
  826. {
  827. DEBUG_LOG(("issuing NON-team-attack cmd against %s\n",target->getTemplate()->getName().str()));
  828. // send single attack command for selected drawable
  829. const DrawableList *selected = TheInGameUI->getAllSelectedDrawables();
  830. // loop through all the selected drawables
  831. Drawable *draw;
  832. for( DrawableListCIt it = selected->begin(); it != selected->end(); ++it )
  833. {
  834. draw = *it;
  835. msgType = createAttackMessage(draw, target, commandType );
  836. }
  837. }
  838. // only make sounds if the command was for real
  839. if( commandType == DO_COMMAND )
  840. {
  841. PickAndPlayInfo info;
  842. info.m_air = targetObj->isUsingAirborneLocomotor();
  843. info.m_drawTarget = target;
  844. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), msgType, &info );
  845. } // end if
  846. // return the actual message type created
  847. return msgType;
  848. }
  849. //-------------------------------------------------------------------------------------------------
  850. GameMessage::Type CommandTranslator::issueSpecialPowerCommand( const CommandButton *command, CommandEvaluateType commandType, Drawable *target, const Coord3D *pos, Object* ignoreSelObj )
  851. {
  852. GameMessage::Type msgType = GameMessage::MSG_INVALID;
  853. if( !command || !command->getSpecialPowerTemplate())
  854. {
  855. return msgType;
  856. }
  857. Drawable* sourceDraw = ignoreSelObj ? ignoreSelObj->getDrawable() : TheInGameUI->getFirstSelectedDrawable();
  858. ObjectID specificSource = ignoreSelObj ? ignoreSelObj->getID() : INVALID_ID;
  859. if( BitTest( command->getOptions(), COMMAND_OPTION_NEED_OBJECT_TARGET ) )
  860. {
  861. // OBJECT BASED SPECIAL
  862. if (!command->isValidObjectTarget(sourceDraw, target))
  863. return msgType;
  864. msgType = GameMessage::MSG_DO_SPECIAL_POWER_AT_OBJECT;
  865. if( commandType == DO_COMMAND )
  866. {
  867. GameMessage *msg;
  868. msg = TheMessageStream->appendMessage( msgType );
  869. msg->appendIntegerArgument( command->getSpecialPowerTemplate()->getID() );
  870. msg->appendObjectIDArgument( target->getObject()->getID() );
  871. msg->appendIntegerArgument( command->getOptions() );
  872. msg->appendObjectIDArgument( specificSource );
  873. // say something like " I think I'll put some dynamite on that there tank."
  874. PickAndPlayInfo info;
  875. info.m_drawTarget = target;
  876. info.m_specialPowerType = command->getSpecialPowerTemplate()->getSpecialPowerType();
  877. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), msgType, &info );
  878. }
  879. }
  880. else if( BitTest( command->getOptions(), NEED_TARGET_POS ) )
  881. {
  882. //LOCATION BASED SPECIAL
  883. msgType = GameMessage::MSG_DO_SPECIAL_POWER_AT_LOCATION;
  884. if( commandType == DO_COMMAND )
  885. {
  886. GameMessage *msg;
  887. msg = TheMessageStream->appendMessage( msgType );
  888. msg->appendIntegerArgument( command->getSpecialPowerTemplate()->getID() );
  889. msg->appendLocationArgument( *pos );
  890. //Object in way.... some specials care, others don't
  891. ObjectID targetID = (target && target->getObject()) ? target->getObject()->getID() : INVALID_ID;
  892. msg->appendObjectIDArgument( targetID );
  893. msg->appendIntegerArgument( command->getOptions() );
  894. msg->appendObjectIDArgument( specificSource );
  895. // say something like " I think I'll put a timed charge on the ground, here."
  896. PickAndPlayInfo info;
  897. info.m_drawTarget = target;
  898. info.m_specialPowerType = command->getSpecialPowerTemplate()->getSpecialPowerType();
  899. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), msgType, &info );
  900. }
  901. }
  902. else
  903. {
  904. //NO TARGET SPECIAL
  905. msgType = GameMessage::MSG_DO_SPECIAL_POWER;
  906. if( commandType == DO_COMMAND )
  907. {
  908. GameMessage *msg;
  909. msg = TheMessageStream->appendMessage( msgType );
  910. msg->appendIntegerArgument( command->getSpecialPowerTemplate()->getID() );
  911. msg->appendIntegerArgument( command->getOptions() );
  912. msg->appendObjectIDArgument( specificSource );
  913. // say something like " I think I'll set down my laptop and hack some cash from a bank in the Cayman Islands."
  914. PickAndPlayInfo info;
  915. info.m_drawTarget = target;
  916. info.m_specialPowerType = command->getSpecialPowerTemplate()->getSpecialPowerType();
  917. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), msgType, &info );
  918. }
  919. }
  920. return msgType;
  921. }
  922. //-------------------------------------------------------------------------------------------------
  923. //-------------------------------------------------------------------------------------------------
  924. GameMessage::Type CommandTranslator::issueCombatDropCommand( const CommandButton *command, CommandEvaluateType commandType, Drawable *target, const Coord3D *pos )
  925. {
  926. if( !command )
  927. {
  928. return GameMessage::MSG_INVALID;
  929. }
  930. if( target != NULL && BitTest( command->getOptions(), COMMAND_OPTION_NEED_OBJECT_TARGET ) )
  931. {
  932. // OBJECT BASED SPECIAL
  933. if (!command->isValidObjectTarget(TheInGameUI->getFirstSelectedDrawable(), target))
  934. return GameMessage::MSG_INVALID;
  935. GameMessage::Type msgType = GameMessage::MSG_COMBATDROP_AT_OBJECT;
  936. if( commandType == DO_COMMAND )
  937. {
  938. GameMessage *msg = TheMessageStream->appendMessage( msgType );
  939. ObjectID targetID = (target && target->getObject()) ? target->getObject()->getID() : INVALID_ID;
  940. msg->appendObjectIDArgument( targetID );
  941. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_COMBATDROP_AT_OBJECT );
  942. }
  943. return msgType;
  944. }
  945. else if ( BitTest( command->getOptions(), NEED_TARGET_POS ) )
  946. {
  947. GameMessage::Type msgType = GameMessage::MSG_COMBATDROP_AT_LOCATION;
  948. if( commandType == DO_COMMAND )
  949. {
  950. GameMessage *msg = TheMessageStream->appendMessage( msgType );
  951. msg->appendLocationArgument( *pos );
  952. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_COMBATDROP_AT_LOCATION );
  953. }
  954. return msgType;
  955. }
  956. else
  957. {
  958. return GameMessage::MSG_INVALID;
  959. }
  960. }
  961. //-------------------------------------------------------------------------------------------------
  962. GameMessage::Type CommandTranslator::issueFireWeaponCommand( const CommandButton *command, CommandEvaluateType commandType, Drawable *target, const Coord3D *pos )
  963. {
  964. GameMessage::Type msgType = GameMessage::MSG_INVALID;
  965. if( !command )
  966. {
  967. return msgType;
  968. }
  969. if( BitTest( command->getOptions(), COMMAND_OPTION_NEED_OBJECT_TARGET ) )
  970. {
  971. //OBJECT BASED FIRE WEAPON
  972. if (!target || !target->getObject())
  973. return msgType;
  974. if (!command->isValidObjectTarget(TheInGameUI->getFirstSelectedDrawable(), target))
  975. return msgType;
  976. if( BitTest( command->getOptions(), ATTACK_OBJECTS_POSITION ) )
  977. {
  978. //Actually, you know what.... we want to attack the object's location instead.
  979. msgType = GameMessage::MSG_DO_WEAPON_AT_LOCATION;
  980. if( commandType == DO_COMMAND )
  981. {
  982. GameMessage *msg;
  983. msg = TheMessageStream->appendMessage( msgType );
  984. msg->appendIntegerArgument( command->getWeaponSlot() );
  985. msg->appendLocationArgument( *pos );
  986. msg->appendIntegerArgument( command->getMaxShotsToFire() );
  987. //Object in way.... some location weapons care, others don't
  988. ObjectID targetID = (target && target->getObject()) ? target->getObject()->getID() : INVALID_ID;
  989. msg->appendObjectIDArgument( targetID );
  990. }
  991. }
  992. else
  993. {
  994. msgType = GameMessage::MSG_DO_WEAPON_AT_OBJECT;
  995. if( commandType == DO_COMMAND )
  996. {
  997. GameMessage *msg;
  998. msg = TheMessageStream->appendMessage( msgType );
  999. msg->appendIntegerArgument( command->getWeaponSlot() );
  1000. ObjectID targetID = (target && target->getObject()) ? target->getObject()->getID() : INVALID_ID;
  1001. msg->appendObjectIDArgument( targetID );
  1002. msg->appendIntegerArgument( command->getMaxShotsToFire() );
  1003. //play a unit specific sound?
  1004. PickAndPlayInfo info;
  1005. WeaponSlotType slot = command->getWeaponSlot();
  1006. info.m_weaponSlot = &slot;
  1007. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_DO_WEAPON_AT_OBJECT, &info );
  1008. }
  1009. }
  1010. }
  1011. else if( BitTest( command->getOptions(), NEED_TARGET_POS ) )
  1012. {
  1013. //LOCATION BASED FIRE WEAPON
  1014. msgType = GameMessage::MSG_DO_WEAPON_AT_LOCATION;
  1015. if( commandType == DO_COMMAND )
  1016. {
  1017. GameMessage *msg;
  1018. msg = TheMessageStream->appendMessage( msgType );
  1019. msg->appendIntegerArgument( command->getWeaponSlot() );
  1020. msg->appendLocationArgument( *pos );
  1021. msg->appendIntegerArgument( command->getMaxShotsToFire() );
  1022. //Object in way.... some location weapons care, others don't
  1023. ObjectID targetID = (target && target->getObject()) ? target->getObject()->getID() : INVALID_ID;
  1024. msg->appendObjectIDArgument( targetID );
  1025. }
  1026. }
  1027. else
  1028. {
  1029. //NO TARGET WEAPON
  1030. msgType = GameMessage::MSG_DO_WEAPON;
  1031. if( commandType == DO_COMMAND )
  1032. {
  1033. GameMessage *msg;
  1034. msg = TheMessageStream->appendMessage( msgType );
  1035. DEBUG_ASSERTCRASH( (command->getSpecialPowerTemplate()), ("No Special Power Weapon here to 'do' with! ML"));
  1036. msg->appendIntegerArgument( command->getSpecialPowerTemplate()->getID() );
  1037. }
  1038. }
  1039. return msgType;
  1040. }
  1041. //-------------------------------------------------------------------------------------------------
  1042. GameMessage::Type CommandTranslator::createEnterMessage( Drawable *enter,
  1043. CommandEvaluateType commandType )
  1044. {
  1045. GameMessage::Type msgType = GameMessage::MSG_ENTER;
  1046. // if we're just evaluating then get out of here without actually doing the action
  1047. if( commandType == EVALUATE_ONLY )
  1048. return msgType;
  1049. if (!enter || !enter->getObject())
  1050. return msgType;
  1051. // sanity
  1052. DEBUG_ASSERTCRASH( commandType == DO_COMMAND, ("createEnterMessage - commandType is not DO_COMMAND\n") );
  1053. if( m_teamExists )
  1054. {
  1055. PickAndPlayInfo info;
  1056. info.m_drawTarget = enter;
  1057. pickAndPlayUnitVoiceResponse(TheInGameUI->getAllSelectedDrawables(), msgType, &info );
  1058. GameMessage *enterMsg = TheMessageStream->appendMessage( msgType );
  1059. enterMsg->appendObjectIDArgument( INVALID_ID ); // 0 means current "selection team" of this player
  1060. enterMsg->appendObjectIDArgument( enter->getObject()->getID() );
  1061. } // end if
  1062. else
  1063. {
  1064. DEBUG_CRASH(("Shouldn't get here. jkmcd"));
  1065. }
  1066. // return the type of the message used
  1067. return msgType;
  1068. } // end createEnterMessage
  1069. //====================================================================================
  1070. CommandTranslator::CommandTranslator() :
  1071. m_objective(0),
  1072. m_teamExists(false),
  1073. m_mouseRightDown(0),
  1074. m_mouseRightUp(0)
  1075. {
  1076. m_mouseRightDragAnchor.x = 0;
  1077. m_mouseRightDragAnchor.y = 0;
  1078. m_mouseRightDragLift.x = 0;
  1079. m_mouseRightDragLift.y = 0;
  1080. }
  1081. //====================================================================================
  1082. CommandTranslator::~CommandTranslator()
  1083. {
  1084. }
  1085. //-------------------------------------------------------------------------------------------------
  1086. GameMessage::Type CommandTranslator::evaluateForceAttack( Drawable *draw, const Coord3D *pos, CommandEvaluateType type )
  1087. {
  1088. // evaluateForceAttack is used to determine whether or not we can force attack the
  1089. // given target, and if we can, to issue the appropriate command.
  1090. GameMessage::Type retVal = GameMessage::MSG_INVALID;
  1091. if( !draw && !pos )
  1092. {
  1093. return retVal;
  1094. }
  1095. const DrawableList *allSelected = TheInGameUI->getAllSelectedDrawables();
  1096. if( draw )
  1097. {
  1098. Object *obj = draw ? draw->getObject() : NULL;
  1099. if( !obj )
  1100. {
  1101. return retVal;
  1102. }
  1103. CanAttackResult result = canAnyForceAttack( allSelected, obj, pos );
  1104. if( result == ATTACKRESULT_POSSIBLE || result == ATTACKRESULT_POSSIBLE_AFTER_MOVING )
  1105. {
  1106. retVal = GameMessage::MSG_DO_FORCE_ATTACK_OBJECT;
  1107. if( type == DO_COMMAND )
  1108. {
  1109. pickAndPlayUnitVoiceResponse( allSelected, retVal );
  1110. GameMessage *newMsg = TheMessageStream->appendMessage( retVal );
  1111. newMsg->appendObjectIDArgument( obj->getID() );
  1112. }
  1113. else if( type == DO_HINT )
  1114. {
  1115. retVal = GameMessage::MSG_DO_FORCE_ATTACK_OBJECT_HINT;
  1116. // Don't need the message back, cause there is nothing to append to it.
  1117. TheMessageStream->appendMessage( retVal );
  1118. }
  1119. }
  1120. else if( result == ATTACKRESULT_INVALID_SHOT && type == DO_HINT )
  1121. {
  1122. retVal = GameMessage::MSG_IMPOSSIBLE_ATTACK_HINT;
  1123. TheMessageStream->appendMessage( retVal );
  1124. }
  1125. }
  1126. else if( pos )
  1127. {
  1128. CanAttackResult result = canAnyForceAttack( allSelected, NULL, pos );
  1129. if( result == ATTACKRESULT_POSSIBLE || result == ATTACKRESULT_POSSIBLE_AFTER_MOVING )
  1130. {
  1131. retVal = GameMessage::MSG_DO_FORCE_ATTACK_GROUND;
  1132. if( type == DO_COMMAND )
  1133. {
  1134. pickAndPlayUnitVoiceResponse( allSelected, retVal );
  1135. GameMessage *newMsg = TheMessageStream->appendMessage( retVal );
  1136. newMsg->appendLocationArgument( *pos );
  1137. }
  1138. else if( type == DO_HINT )
  1139. {
  1140. retVal = GameMessage::MSG_DO_FORCE_ATTACK_GROUND_HINT;
  1141. // Don't need the message back, cause there is nothing to append to it.
  1142. TheMessageStream->appendMessage( retVal );
  1143. }
  1144. }
  1145. else if( result == ATTACKRESULT_INVALID_SHOT && type == DO_HINT )
  1146. {
  1147. retVal = GameMessage::MSG_IMPOSSIBLE_ATTACK_HINT;
  1148. TheMessageStream->appendMessage( retVal );
  1149. }
  1150. }
  1151. return retVal;
  1152. }
  1153. // ------------------------------------------------------------------------------------------------
  1154. /** This method and the order of operations in the check here, determine what command would
  1155. * actually happen (if type parameter == DO_COMMAND) if the user clicked on the drawable
  1156. * 'draw'. If type == DO_HINT, then the user hasn't actually clicked, but has moused over
  1157. * the drawable 'draw' and we want to generate a hint message as to what the actual
  1158. * command would be if clicked
  1159. * NOTE: draw can be NULL, in which case we give a hint for the location */
  1160. // ------------------------------------------------------------------------------------------------
  1161. GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,
  1162. const Coord3D *pos,
  1163. CommandEvaluateType type )
  1164. {
  1165. Object *obj = draw ? draw->getObject() : NULL;
  1166. Drawable *drawableInWay = draw;
  1167. //This piece of code is used to prevent interaction with unselectable objects or masked objects. When we
  1168. //call this function, we typically pass in both a position and a drawable (if applicable), so if the
  1169. //drawable is invalid... then convert it to a position to be evaluated instead.
  1170. //Added: shrubberies are the exception for interactions...
  1171. //Removed: GS Took out ObjectStatusUnselectable, since that status only prevents selection, not everything
  1172. if (obj == NULL ||
  1173. (BitTest(obj->getStatusBits(), OBJECT_STATUS_MASKED) &&
  1174. !obj->isKindOf(KINDOF_SHRUBBERY) && !obj->isKindOf(KINDOF_FORCEATTACKABLE))
  1175. )
  1176. {
  1177. //Nulling out the draw and obj pointer will force the remainder of this code to evaluate
  1178. //a position interaction.
  1179. draw = NULL;
  1180. obj = NULL;
  1181. } // end if
  1182. // If the thing is a mine, and is locally controlled, then we should issue a moveto to its location.
  1183. if (obj && obj->isLocallyControlled() && obj->isKindOf(KINDOF_MINE)) {
  1184. draw = NULL;
  1185. obj = NULL;
  1186. }
  1187. if( TheInGameUI->isInForceMoveToMode() )
  1188. {
  1189. //Nulling out the draw and obj pointer will force the remainder of this code to evaluate
  1190. //a position interaction.
  1191. draw = NULL;
  1192. obj = NULL;
  1193. } else if (TheInGameUI->isInForceAttackMode() ) {
  1194. // setting the drawableInWay to draw will allow us to force attack in the issue move command
  1195. // if there is a location to which we should attack.
  1196. drawableInWay = draw;
  1197. }
  1198. GameMessage::Type msgType = GameMessage::MSG_INVALID;
  1199. // Then we should determine if the game currently prefers selection events. If it does, then return
  1200. // the invalid message.
  1201. if (obj) {
  1202. if (obj->isLocallyControlled() && TheInGameUI->isInPreferSelectionMode()) {
  1203. return msgType;
  1204. }
  1205. }
  1206. // Kris: Now that we can select non-controllable units/structures, don't allow any actions to be performed.
  1207. const CommandButton *command = TheInGameUI->getGUICommand();
  1208. if( TheInGameUI->areSelectedObjectsControllable()
  1209. || (command && command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_COMMAND_CENTER))
  1210. {
  1211. GameMessage *hintMessage;
  1212. if( TheInGameUI->isInWaypointMode() )
  1213. {
  1214. //Override any *other* commands with waypoint commands.
  1215. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1216. {
  1217. if( TheTerrainLogic )
  1218. {
  1219. msgType = issueMoveToLocationCommand( pos, draw, type );
  1220. }
  1221. }
  1222. else
  1223. {
  1224. msgType = GameMessage::MSG_ADD_WAYPOINT_HINT;
  1225. hintMessage = TheMessageStream->appendMessage( msgType );
  1226. hintMessage->appendLocationArgument( *pos );
  1227. }
  1228. return msgType;
  1229. }
  1230. CanAttackResult result;
  1231. if(command &&
  1232. (command->isContextCommand()
  1233. || command->getCommandType() == GUI_COMMAND_SPECIAL_POWER
  1234. || command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_COMMAND_CENTER))
  1235. {
  1236. if( obj && obj->isKindOf( KINDOF_SHRUBBERY ) && !BitTest( command->getOptions(), ALLOW_SHRUBBERY_TARGET ) )
  1237. {
  1238. //If our object is a shrubbery, and we don't allow targetting it... then null it out.
  1239. //Nulling out the draw and obj pointer will force the remainder of this code to evaluate
  1240. //a position interaction.
  1241. draw = NULL;
  1242. obj = NULL;
  1243. }
  1244. if( obj && obj->isKindOf( KINDOF_MINE ) && !BitTest( command->getOptions(), ALLOW_MINE_TARGET ) )
  1245. {
  1246. //If our object is a mine, and we don't allow targetting it... then null it out.
  1247. //Nulling out the draw and obj pointer will force the remainder of this code to evaluate
  1248. //a position interaction.
  1249. draw = NULL;
  1250. obj = NULL;
  1251. }
  1252. //Kris: September 27, 2002
  1253. //Added relationship tests to make sure we're not attempting a context-command on a restricted relationship.
  1254. //This case prevents rebels from using tranq darts on allies.
  1255. if( obj && BitTest( command->getOptions(), COMMAND_OPTION_NEED_OBJECT_TARGET ) )
  1256. {
  1257. Relationship relationship = ThePlayerList->getLocalPlayer()->getRelationship( obj->getTeam() );
  1258. switch( relationship )
  1259. {
  1260. case ALLIES:
  1261. if( !BitTest( command->getOptions(), NEED_TARGET_ALLY_OBJECT ) )
  1262. {
  1263. draw = NULL;
  1264. obj = NULL;
  1265. }
  1266. break;
  1267. case ENEMIES:
  1268. if( !BitTest( command->getOptions(), NEED_TARGET_ENEMY_OBJECT ) )
  1269. {
  1270. draw = NULL;
  1271. obj = NULL;
  1272. }
  1273. break;
  1274. case NEUTRAL:
  1275. if( !BitTest( command->getOptions(), NEED_TARGET_NEUTRAL_OBJECT ) )
  1276. {
  1277. draw = NULL;
  1278. obj = NULL;
  1279. }
  1280. break;
  1281. }
  1282. }
  1283. Bool currentlyValid = FALSE;
  1284. ObjectID objectID = obj ? obj->getID() : INVALID_ID;
  1285. switch( command->getCommandType() )
  1286. {
  1287. //Kris: June 06, 2002
  1288. //This is a GUI command button that triggers a mode. In any of these modes, only one specific action
  1289. //can occur. If the mouse isn't over a valid target, then the conditions aren't met and the code will
  1290. //cause an invalid version of the cursor to be shown -- and should the user click, the action won't take place.
  1291. case GUICOMMANDMODE_CONVERT_TO_CARBOMB:
  1292. currentlyValid = TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_CONVERT_OBJECT_TO_CARBOMB, obj, InGameUI::SELECTION_ANY );
  1293. break;
  1294. case GUICOMMANDMODE_HIJACK_VEHICLE:
  1295. currentlyValid = TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_HIJACK_VEHICLE, obj, InGameUI::SELECTION_ANY );
  1296. break;
  1297. #ifdef ALLOW_SURRENDER
  1298. case GUICOMMANDMODE_PICK_UP_PRISONER:
  1299. currentlyValid = TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_PICK_UP_PRISONER, obj, InGameUI::SELECTION_ANY );
  1300. break;
  1301. #endif
  1302. case GUI_COMMAND_SPECIAL_POWER_FROM_COMMAND_CENTER:
  1303. {
  1304. Object* cmdCenter = ThePlayerList->getLocalPlayer()->findNaturalCommandCenter();
  1305. if (cmdCenter)
  1306. currentlyValid = TheInGameUI->canSelectedObjectsDoSpecialPower( command, obj, pos, InGameUI::SELECTION_ANY, command->getOptions(), cmdCenter );
  1307. else
  1308. currentlyValid = false;
  1309. break;
  1310. }
  1311. case GUI_COMMAND_SPECIAL_POWER:
  1312. currentlyValid = TheInGameUI->canSelectedObjectsDoSpecialPower( command, obj, pos, InGameUI::SELECTION_ANY, command->getOptions(), NULL );
  1313. break;
  1314. case GUI_COMMAND_FIRE_WEAPON:
  1315. currentlyValid = TheInGameUI->canSelectedObjectsEffectivelyUseWeapon( command, obj, pos, InGameUI::SELECTION_ANY );
  1316. break;
  1317. case GUI_COMMAND_COMBATDROP:
  1318. currentlyValid = !obj ? TRUE : TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_COMBATDROP_INTO, obj, InGameUI::SELECTION_ANY );
  1319. break;
  1320. }
  1321. if( currentlyValid )
  1322. {
  1323. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1324. {
  1325. switch( command->getCommandType() )
  1326. {
  1327. case GUICOMMANDMODE_CONVERT_TO_CARBOMB:
  1328. case GUICOMMANDMODE_HIJACK_VEHICLE:
  1329. msgType = createEnterMessage( draw, type );
  1330. break;
  1331. #ifdef ALLOW_SURRENDER
  1332. case GUICOMMANDMODE_PICK_UP_PRISONER:
  1333. msgType = issueAttackCommand( draw, type, command->getCommandType() );
  1334. break;
  1335. #endif
  1336. case GUI_COMMAND_SPECIAL_POWER_FROM_COMMAND_CENTER:
  1337. {
  1338. Object* cmdCenter = ThePlayerList->getLocalPlayer()->findNaturalCommandCenter();
  1339. if (cmdCenter)
  1340. msgType = issueSpecialPowerCommand( command, type, draw, pos, cmdCenter );
  1341. break;
  1342. }
  1343. case GUI_COMMAND_SPECIAL_POWER://lorenzen
  1344. msgType = issueSpecialPowerCommand( command, type, draw, pos, NULL );
  1345. break;
  1346. case GUI_COMMAND_FIRE_WEAPON:
  1347. msgType = issueFireWeaponCommand( command, type, draw, pos );
  1348. break;
  1349. case GUI_COMMAND_COMBATDROP:
  1350. msgType = issueCombatDropCommand( command, type, draw, pos );
  1351. break;
  1352. }
  1353. // NULL out the GUI command if we're actually doing something
  1354. if( type == DO_COMMAND )
  1355. {
  1356. TheInGameUI->setGUICommand( NULL );
  1357. }
  1358. }
  1359. else
  1360. {
  1361. msgType = GameMessage::MSG_VALID_GUICOMMAND_HINT;
  1362. hintMessage = TheMessageStream->appendMessage( msgType );
  1363. hintMessage->appendObjectIDArgument( objectID );
  1364. }
  1365. }
  1366. else // not currently valid
  1367. {
  1368. msgType = GameMessage::MSG_INVALID_GUICOMMAND_HINT;
  1369. hintMessage = TheMessageStream->appendMessage( msgType );
  1370. hintMessage->appendObjectIDArgument( objectID );
  1371. }
  1372. } // if a special power
  1373. // ********************************************************************************************
  1374. else if( TheInGameUI->canSelectedObjectsOverrideSpecialPowerDestination( pos, InGameUI::SELECTION_ANY, SPECIAL_INVALID ) )
  1375. {
  1376. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1377. {
  1378. // do the command
  1379. msgType = GameMessage::MSG_DO_SPECIAL_POWER_OVERRIDE_DESTINATION;
  1380. if( type == DO_COMMAND )
  1381. {
  1382. GameMessage *gameMsg = TheMessageStream->appendMessage( msgType );
  1383. gameMsg->appendLocationArgument( *pos );
  1384. gameMsg->appendIntegerArgument( SPECIAL_INVALID );
  1385. gameMsg->appendObjectIDArgument( INVALID_ID ); // no specific source
  1386. } // end if
  1387. } // end if
  1388. else
  1389. {
  1390. // generate a hint message
  1391. msgType = GameMessage::MSG_DO_SPECIAL_POWER_OVERRIDE_DESTINATION_HINT;
  1392. hintMessage = TheMessageStream->appendMessage( msgType );
  1393. } // end else
  1394. }
  1395. // ********************************************************************************************
  1396. else if( draw && !TheInGameUI->isInForceAttackMode() &&
  1397. TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_RESUME_CONSTRUCTION, obj, InGameUI::SELECTION_ANY ) )
  1398. {
  1399. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1400. {
  1401. // do the command
  1402. msgType = GameMessage::MSG_RESUME_CONSTRUCTION;
  1403. if( type == DO_COMMAND )
  1404. {
  1405. GameMessage *resumeMsg = TheMessageStream->appendMessage( msgType );
  1406. resumeMsg->appendObjectIDArgument( obj->getID() );
  1407. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_RESUME_CONSTRUCTION );
  1408. } // end if
  1409. } // end if
  1410. else
  1411. {
  1412. // generate a hint message
  1413. msgType = GameMessage::MSG_RESUME_CONSTRUCTION_HINT;
  1414. hintMessage = TheMessageStream->appendMessage( msgType );
  1415. hintMessage->appendObjectIDArgument( obj->getID() );
  1416. } // end else
  1417. } // end else if
  1418. // ********************************************************************************************
  1419. else if( draw && !TheInGameUI->isInForceAttackMode() &&
  1420. TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_DOCK_AT,
  1421. obj,
  1422. InGameUI::SELECTION_ALL ) )
  1423. {
  1424. //
  1425. // The actual logic is simply to AIUpdate::dock with the target, the hint is the
  1426. // only part that needs to be more specific.
  1427. //
  1428. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1429. {
  1430. // Give the dock command
  1431. msgType = GameMessage::MSG_DOCK;
  1432. if( type == DO_COMMAND )
  1433. {
  1434. GameMessage *dockMsg = TheMessageStream->appendMessage( msgType );
  1435. dockMsg->appendObjectIDArgument( obj->getID() );
  1436. // only make sounds if we really did the command messages
  1437. pickAndPlayUnitVoiceResponse(TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_DOCK);
  1438. } // end if
  1439. }
  1440. else
  1441. {
  1442. // make the hint
  1443. msgType = GameMessage::MSG_DOCK_HINT;
  1444. hintMessage = TheMessageStream->appendMessage( msgType );
  1445. hintMessage->appendObjectIDArgument( obj->getID() );
  1446. }
  1447. }
  1448. // ********************************************************************************************
  1449. else if( draw && !TheInGameUI->isInForceAttackMode() &&
  1450. TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_REPAIR_OBJECT, obj, InGameUI::SELECTION_ANY ) )
  1451. {
  1452. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1453. {
  1454. // do the command
  1455. msgType = GameMessage::MSG_DO_REPAIR;
  1456. if( type == DO_COMMAND )
  1457. {
  1458. GameMessage *healMsg = TheMessageStream->appendMessage( msgType );
  1459. healMsg->appendObjectIDArgument( obj->getID() );
  1460. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_DO_REPAIR );
  1461. } // end if
  1462. } // end if
  1463. else
  1464. {
  1465. // generate a hint message
  1466. msgType = GameMessage::MSG_DO_REPAIR_HINT;
  1467. hintMessage = TheMessageStream->appendMessage( msgType );
  1468. hintMessage->appendObjectIDArgument( obj->getID() );
  1469. } // end else
  1470. } // end else if
  1471. // ********************************************************************************************
  1472. else if( draw && !TheInGameUI->isInForceAttackMode() &&
  1473. TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_GET_REPAIRED_AT, obj, InGameUI::SELECTION_ANY ) )
  1474. {
  1475. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1476. {
  1477. // do the command
  1478. msgType = GameMessage::MSG_GET_REPAIRED;
  1479. if( type == DO_COMMAND )
  1480. {
  1481. GameMessage *healMsg = TheMessageStream->appendMessage( msgType );
  1482. healMsg->appendObjectIDArgument( obj->getID() );
  1483. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_GET_REPAIRED );
  1484. } // end if
  1485. } // end if
  1486. else
  1487. {
  1488. // generate a hint message
  1489. msgType = GameMessage::MSG_GET_REPAIRED_HINT;
  1490. hintMessage = TheMessageStream->appendMessage( msgType );
  1491. hintMessage->appendObjectIDArgument( obj->getID() );
  1492. } // end else
  1493. } // end else if
  1494. // ********************************************************************************************
  1495. else if( draw && !TheInGameUI->isInForceAttackMode() &&
  1496. TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_GET_HEALED_AT, obj, InGameUI::SELECTION_ANY ) )
  1497. {
  1498. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1499. {
  1500. // do the command
  1501. msgType = GameMessage::MSG_GET_HEALED;
  1502. if( type == DO_COMMAND )
  1503. {
  1504. GameMessage *healMsg = TheMessageStream->appendMessage( msgType );
  1505. healMsg->appendObjectIDArgument( obj->getID() );
  1506. pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_GET_HEALED );
  1507. } // end if
  1508. } // end if
  1509. else
  1510. {
  1511. // generate hint message
  1512. msgType = GameMessage::MSG_GET_HEALED_HINT;
  1513. hintMessage = TheMessageStream->appendMessage( msgType);
  1514. hintMessage->appendObjectIDArgument( obj->getID() );
  1515. } // end else
  1516. } // end else if
  1517. // ********************************************************************************************
  1518. else if( draw && draw->getObject() && !TheInGameUI->isInForceAttackMode() &&
  1519. TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_HIJACK_VEHICLE,
  1520. draw->getObject(),
  1521. InGameUI::SELECTION_ANY ) )
  1522. {
  1523. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1524. {
  1525. // Now, this just tricks the AI into making the hijacker run towards the target vehicle
  1526. // I must add a test to keep him from actually entering an enemy vehicle (contained)... Lorenzen
  1527. msgType = createEnterMessage( draw, type );
  1528. } // end if
  1529. else
  1530. {
  1531. msgType = GameMessage::MSG_HIJACK_HINT;
  1532. hintMessage = TheMessageStream->appendMessage( msgType );
  1533. hintMessage->appendObjectIDArgument( draw->getObject()->getID() );
  1534. } // end else
  1535. } // end else if
  1536. // ********************************************************************************************
  1537. else if( draw && !TheInGameUI->isInForceAttackMode() &&
  1538. TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_CONVERT_OBJECT_TO_CARBOMB, obj, InGameUI::SELECTION_ANY ) )
  1539. {
  1540. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1541. {
  1542. // issue the command (convert to carbomb is nearly identical to enter)
  1543. msgType = createEnterMessage( draw, type );
  1544. } // end if
  1545. else
  1546. {
  1547. msgType = GameMessage::MSG_CONVERT_TO_CARBOMB_HINT;
  1548. hintMessage = TheMessageStream->appendMessage( msgType );
  1549. hintMessage->appendObjectIDArgument( obj->getID() );
  1550. } // end else
  1551. }
  1552. // ********************************************************************************************
  1553. else if( draw && !TheInGameUI->isInForceAttackMode() && canSelectionSalvage(obj) )
  1554. {
  1555. GameMessage *msg;
  1556. if( type == DO_COMMAND || type == EVALUATE_ONLY ) {
  1557. msgType = GameMessage::MSG_DO_SALVAGE;
  1558. if (type == DO_COMMAND) {
  1559. msg = TheMessageStream->appendMessage(msgType);
  1560. msg->appendLocationArgument(*obj->getPosition());
  1561. pickAndPlayUnitVoiceResponse(TheInGameUI->getAllSelectedDrawables(), msgType);
  1562. }
  1563. } else {
  1564. msgType = GameMessage::MSG_DO_SALVAGE_HINT;
  1565. msg = TheMessageStream->appendMessage(msgType);
  1566. msg->appendLocationArgument(*obj->getPosition());
  1567. }
  1568. } // end else if
  1569. // ********************************************************************************************
  1570. else if( draw && !TheInGameUI->isInForceAttackMode() &&
  1571. TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_ENTER_OBJECT, obj, InGameUI::SELECTION_ANY, true ) )
  1572. {
  1573. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1574. {
  1575. // issue the command
  1576. msgType = createEnterMessage( draw, type );
  1577. } // end if
  1578. else
  1579. {
  1580. msgType = GameMessage::MSG_ENTER_HINT;
  1581. hintMessage = TheMessageStream->appendMessage( msgType );
  1582. hintMessage->appendObjectIDArgument( obj->getID() );
  1583. } // end else
  1584. } // end else if
  1585. // ********************************************************************************************
  1586. else if( draw && (result = TheInGameUI->getCanSelectedObjectsAttack( InGameUI::ACTIONTYPE_ATTACK_OBJECT, obj, InGameUI::SELECTION_ANY, TheInGameUI->isInForceAttackMode() )) == ATTACKRESULT_POSSIBLE )
  1587. {
  1588. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1589. {
  1590. // issue the attack order
  1591. msgType = issueAttackCommand( draw, type );
  1592. } // end if
  1593. else
  1594. {
  1595. // Generate an Attack hint
  1596. msgType = GameMessage::MSG_DO_ATTACK_OBJECT_HINT;
  1597. hintMessage = TheMessageStream->appendMessage( msgType );
  1598. hintMessage->appendObjectIDArgument( obj->getID() );
  1599. } // end else
  1600. } // end else if
  1601. // ********************************************************************************************
  1602. else if( draw && result == ATTACKRESULT_POSSIBLE_AFTER_MOVING )
  1603. {
  1604. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1605. {
  1606. // issue the attack order
  1607. msgType = issueAttackCommand( draw, type );
  1608. } // end if
  1609. else
  1610. {
  1611. // Generate an Attack hint
  1612. msgType = GameMessage::MSG_DO_ATTACK_OBJECT_AFTER_MOVING_HINT;
  1613. hintMessage = TheMessageStream->appendMessage( msgType );
  1614. hintMessage->appendObjectIDArgument( obj->getID() );
  1615. } // end else
  1616. }
  1617. // ********************************************************************************************
  1618. else if( draw && TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_CAPTURE_BUILDING, obj, InGameUI::SELECTION_ANY ) )
  1619. {
  1620. //@TODO: Kris
  1621. //PRELIMINARY CODE FOR HOOKING IN AUTO SPECIALS --- WILL BE REDONE!
  1622. Object *source = TheInGameUI->getFirstSelectedDrawable()->getObject();
  1623. const CommandSet *set = TheControlBar->findCommandSet( source->getCommandSetString() );
  1624. if( set )
  1625. {
  1626. for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
  1627. {
  1628. // get command button
  1629. const CommandButton *command = set->getCommandButton(i);
  1630. if( command && command->getCommandType() == GUI_COMMAND_SPECIAL_POWER )
  1631. {
  1632. SpecialPowerType spType = command->getSpecialPowerTemplate()->getSpecialPowerType();
  1633. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1634. {
  1635. if( spType == SPECIAL_BLACKLOTUS_CAPTURE_BUILDING ||
  1636. spType == SPECIAL_INFANTRY_CAPTURE_BUILDING )
  1637. {
  1638. //Issue the capture building command
  1639. msgType = issueSpecialPowerCommand( command, type, draw, pos, NULL );
  1640. break;
  1641. }
  1642. }
  1643. else if( spType == SPECIAL_BLACKLOTUS_CAPTURE_BUILDING )
  1644. {
  1645. //Issue the black lotus hack hint for capturing a building.
  1646. msgType = GameMessage::MSG_HACK_HINT;
  1647. hintMessage = TheMessageStream->appendMessage( msgType );
  1648. hintMessage->appendObjectIDArgument( obj->getID() );
  1649. }
  1650. else if( spType == SPECIAL_INFANTRY_CAPTURE_BUILDING )
  1651. {
  1652. //Issue the infantry hint for capturing a building
  1653. msgType = GameMessage::MSG_CAPTUREBUILDING_HINT;
  1654. hintMessage = TheMessageStream->appendMessage( msgType );
  1655. hintMessage->appendObjectIDArgument( obj->getID() );
  1656. }
  1657. }
  1658. }
  1659. }
  1660. } // end else if
  1661. // ********************************************************************************************
  1662. else if( draw && TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_DISABLE_VEHICLE_VIA_HACKING, obj, InGameUI::SELECTION_ANY ) )
  1663. {
  1664. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1665. {
  1666. //@TODO: Kris
  1667. //PRELIMINARY CODE FOR HOOKING IN AUTO SPECIALS --- WILL BE REDONE!
  1668. Object *source = TheInGameUI->getFirstSelectedDrawable()->getObject();
  1669. const CommandSet *set = TheControlBar->findCommandSet( source->getCommandSetString() );
  1670. if( set )
  1671. {
  1672. for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
  1673. {
  1674. // get command button
  1675. const CommandButton *command = set->getCommandButton(i);
  1676. if( command && command->getCommandType() == GUI_COMMAND_SPECIAL_POWER )
  1677. {
  1678. SpecialPowerType spType = command->getSpecialPowerTemplate()->getSpecialPowerType();
  1679. if( spType == SPECIAL_BLACKLOTUS_DISABLE_VEHICLE_HACK )
  1680. {
  1681. msgType = issueSpecialPowerCommand( command, type, draw, pos, NULL );
  1682. break;
  1683. }
  1684. }
  1685. }
  1686. }
  1687. }
  1688. else
  1689. {
  1690. msgType = GameMessage::MSG_HACK_HINT;
  1691. hintMessage = TheMessageStream->appendMessage( msgType );
  1692. hintMessage->appendObjectIDArgument( obj->getID() );
  1693. }
  1694. } // end else if
  1695. // ********************************************************************************************
  1696. else if( draw && TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_STEAL_CASH_VIA_HACKING, obj, InGameUI::SELECTION_ANY ) )
  1697. {
  1698. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1699. {
  1700. //@TODO: Kris
  1701. //PRELIMINARY CODE FOR HOOKING IN AUTO SPECIALS --- WILL BE REDONE!
  1702. Object *source = TheInGameUI->getFirstSelectedDrawable()->getObject();
  1703. const CommandSet *set = TheControlBar->findCommandSet( source->getCommandSetString() );
  1704. if( set )
  1705. {
  1706. for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
  1707. {
  1708. // get command button
  1709. const CommandButton *command = set->getCommandButton(i);
  1710. if( command && command->getCommandType() == GUI_COMMAND_SPECIAL_POWER )
  1711. {
  1712. SpecialPowerType spType = command->getSpecialPowerTemplate()->getSpecialPowerType();
  1713. if( spType == SPECIAL_BLACKLOTUS_STEAL_CASH_HACK )
  1714. {
  1715. msgType = issueSpecialPowerCommand( command, type, draw, pos, NULL );
  1716. break;
  1717. }
  1718. }
  1719. }
  1720. }
  1721. } // end if
  1722. else
  1723. {
  1724. msgType = GameMessage::MSG_HACK_HINT;
  1725. hintMessage = TheMessageStream->appendMessage( msgType );
  1726. hintMessage->appendObjectIDArgument( obj->getID() );
  1727. }
  1728. } // end else if
  1729. // ********************************************************************************************
  1730. else if( draw && TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_DISABLE_BUILDING_VIA_HACKING, obj, InGameUI::SELECTION_ANY ) )
  1731. {
  1732. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1733. {
  1734. //@TODO: Kris
  1735. //PRELIMINARY CODE FOR HOOKING IN AUTO SPECIALS --- WILL BE REDONE!
  1736. Object *source = TheInGameUI->getFirstSelectedDrawable()->getObject();
  1737. const CommandSet *set = TheControlBar->findCommandSet( source->getCommandSetString() );
  1738. if( set )
  1739. {
  1740. for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
  1741. {
  1742. // get command button
  1743. const CommandButton *command = set->getCommandButton(i);
  1744. if( command && command->getCommandType() == GUI_COMMAND_SPECIAL_POWER )
  1745. {
  1746. SpecialPowerType spType = command->getSpecialPowerTemplate()->getSpecialPowerType();
  1747. if( spType == SPECIAL_HACKER_DISABLE_BUILDING )
  1748. {
  1749. msgType = issueSpecialPowerCommand( command, type, draw, pos, NULL );
  1750. break;
  1751. }
  1752. }
  1753. }
  1754. }
  1755. } // end if
  1756. else
  1757. {
  1758. msgType = GameMessage::MSG_HACK_HINT;
  1759. hintMessage = TheMessageStream->appendMessage( msgType );
  1760. hintMessage->appendObjectIDArgument( obj->getID() );
  1761. }
  1762. } // end else if
  1763. #ifdef ALLOW_SURRENDER
  1764. // ********************************************************************************************
  1765. else if( draw && TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_PICK_UP_PRISONER, obj, InGameUI::SELECTION_ANY ) )
  1766. {
  1767. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1768. {
  1769. // issue the command
  1770. msgType = issueAttackCommand( draw, type, GUICOMMANDMODE_PICK_UP_PRISONER );
  1771. } // end if
  1772. else
  1773. {
  1774. msgType = GameMessage::MSG_PICK_UP_PRISONER_HINT;
  1775. hintMessage = TheMessageStream->appendMessage( msgType );
  1776. hintMessage->appendObjectIDArgument( obj->getID() );
  1777. } // end else
  1778. } // end else if
  1779. #endif
  1780. // ********************************************************************************************
  1781. else if ( pos && !draw && TheInGameUI->canSelectedObjectsDoAction( InGameUI::ACTIONTYPE_SET_RALLY_POINT, NULL, InGameUI::SELECTION_ALL, FALSE ))
  1782. {
  1783. msgType = GameMessage::MSG_SET_RALLY_POINT;
  1784. if (type == DO_COMMAND) {
  1785. const DrawableList *allSelectedDrawables = TheInGameUI->getAllSelectedDrawables();
  1786. for (DrawableList::const_iterator it = allSelectedDrawables->begin(); it != allSelectedDrawables->end(); ++it) {
  1787. Drawable *draw = (*it);
  1788. if (draw && draw->getObject()) {
  1789. GameMessage *newMsg = TheMessageStream->appendMessage(msgType);
  1790. newMsg->appendObjectIDArgument(draw->getObject()->getID());
  1791. newMsg->appendLocationArgument(*pos);
  1792. }
  1793. }
  1794. } else if (type == DO_HINT) {
  1795. msgType = GameMessage::MSG_SET_RALLY_POINT_HINT;
  1796. hintMessage = TheMessageStream->appendMessage(msgType);
  1797. hintMessage->appendLocationArgument(*pos);
  1798. }
  1799. }
  1800. // ********************************************************************************************
  1801. else if( draw && result == ATTACKRESULT_INVALID_SHOT )
  1802. {
  1803. msgType = GameMessage::MSG_IMPOSSIBLE_ATTACK_HINT;
  1804. hintMessage = TheMessageStream->appendMessage( msgType );
  1805. hintMessage->appendLocationArgument( *pos );
  1806. } // end else if
  1807. // ********************************************************************************************
  1808. else
  1809. {
  1810. //
  1811. // NOTE: If you change this command evaluation function in what it will do
  1812. // if there is nothing picked ... you might want to edit the logic of the
  1813. // selection translator in that you can only select objects if there is
  1814. // no "interesting" command to do with the picked drawable ... which is determined
  1815. // by what we return in this function by default
  1816. //
  1817. //Before we issue a move order or hint, check to see if we can even move there!
  1818. Bool validQuickPath = FALSE;
  1819. // Make sure to only to the check if the shroud is CLEARED. If it is fogged or shrouded, SKIP THE CHECK. jba [3/11/2003]
  1820. if( ThePartitionManager->getShroudStatusForPlayer( ThePlayerList->getLocalPlayer()->getPlayerIndex(), pos ) != CELLSHROUD_CLEAR )
  1821. {
  1822. //If it's in the shroud, pretend we can move there -- skip the check.
  1823. validQuickPath = TRUE;
  1824. }
  1825. else
  1826. {
  1827. //Can we path there?
  1828. const DrawableList *allSelectedDrawables = TheInGameUI->getAllSelectedDrawables();
  1829. for( DrawableList::const_iterator it = allSelectedDrawables->begin(); it != allSelectedDrawables->end(); ++it )
  1830. {
  1831. Object *obj = (*it) ? (*it)->getObject() : NULL;
  1832. AIUpdateInterface *ai = obj ? obj->getAI() : NULL;
  1833. if( ai && ai->isQuickPathAvailable( pos ) )
  1834. {
  1835. validQuickPath = TRUE;
  1836. break;
  1837. }
  1838. }
  1839. }
  1840. if( type == DO_COMMAND || type == EVALUATE_ONLY )
  1841. {
  1842. // issue command
  1843. // Note: If draw is valid, then its one of ours and we don't have something more specific
  1844. // to do. Therefore, lets not issue a move command, and instead we'll return that there
  1845. // wasn't a command for us to perform.
  1846. if ( draw == NULL )
  1847. msgType = issueMoveToLocationCommand( pos, drawableInWay, type );
  1848. } // end if
  1849. else
  1850. {
  1851. if( !validQuickPath )
  1852. {
  1853. msgType = GameMessage::MSG_DO_INVALID_HINT;
  1854. }
  1855. else if( TheInGameUI->isInWaypointMode() )
  1856. {
  1857. //Waypoint mode
  1858. msgType = GameMessage::MSG_ADD_WAYPOINT_HINT;
  1859. }
  1860. else if( TheInGameUI->isInAttackMoveToMode() )
  1861. {
  1862. //THIS CODE WILL NEVER EVER GET CALLED! -- it's a context command now (READ: rip code out)
  1863. //Attack move
  1864. msgType = GameMessage::MSG_DO_ATTACKMOVETO_HINT;
  1865. }
  1866. else
  1867. {
  1868. //Normal and forced move.
  1869. msgType = GameMessage::MSG_DO_MOVETO_HINT;
  1870. }
  1871. hintMessage = TheMessageStream->appendMessage( msgType );
  1872. hintMessage->appendLocationArgument( *pos );
  1873. } // end else
  1874. } // end else
  1875. } // end if
  1876. // return the message type
  1877. return msgType;
  1878. } // end evaluateContextCommand
  1879. // ------------------------------------------------------------------------------------------------
  1880. // ------------------------------------------------------------------------------------------------
  1881. //====================================================================================
  1882. /**
  1883. * The Command Translator translates mouse events into object command messages
  1884. * such as move_to, attack, etc.
  1885. */
  1886. GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage *msg)
  1887. {
  1888. GameMessage::Type t = msg->getType();
  1889. GameMessageDisposition disp = KEEP_MESSAGE;
  1890. // We want to always be able to get to the options menu even during no input times and a clear game data message should always go through
  1891. if (t != GameMessage::MSG_META_OPTIONS && t != GameMessage::MSG_CLEAR_GAME_DATA &&
  1892. !TheInGameUI->getInputEnabled() && !isSystemMessage(msg))
  1893. {
  1894. return DESTROY_MESSAGE;
  1895. }
  1896. #if defined(_DEBUG) || defined(_INTERNAL)
  1897. ExtentModType extentModType = EXTENTMOD_INVALID;
  1898. Real extentModAmount = 0.0f;
  1899. #endif
  1900. switch (t)
  1901. {
  1902. //-----------------------------------------------------------------------------------------
  1903. case GameMessage::MSG_META_SELECT_MATCHING_UNITS:
  1904. {
  1905. TheInGameUI->selectMatchingUnits();
  1906. disp = DESTROY_MESSAGE;
  1907. break;
  1908. }
  1909. //-----------------------------------------------------------------------------------------
  1910. case GameMessage::MSG_META_SELECT_NEXT_UNIT:
  1911. {
  1912. /* because list is prepended, iterate through backwards */
  1913. // if there is nothing on the screen, bail
  1914. if( TheGameClient->firstDrawable() == NULL )
  1915. break;
  1916. // if nothing is selected
  1917. Drawable *temp;
  1918. if( TheInGameUI->getSelectCount() == 0 )
  1919. {
  1920. // get the last drawable
  1921. for( temp = TheGameClient->firstDrawable(); temp->getNextDrawable() != NULL; temp = temp->getNextDrawable() )
  1922. {
  1923. }
  1924. // temp is the last drawable
  1925. for( temp; temp != NULL; temp = temp->getPrevDrawable() )
  1926. {
  1927. const Object *object = temp->getObject();
  1928. // if you've reached the end of the list, don't select anything
  1929. if( !object )
  1930. {
  1931. break;
  1932. }
  1933. else if( object && object->isMobile() && object->isLocallyControlled() && !object->isContained() && !object->isKindOf( KINDOF_DRONE ) )
  1934. {
  1935. // create a new group.
  1936. GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
  1937. //New group or add to group? Passed in value is true if we are creating a new group.
  1938. teamMsg->appendBooleanArgument( TRUE );
  1939. teamMsg->appendObjectIDArgument( object->getID() );
  1940. TheInGameUI->selectDrawable( temp );
  1941. // center on the unit
  1942. TheTacticalView->lookAt(temp->getPosition());
  1943. break;
  1944. }
  1945. }
  1946. }
  1947. else
  1948. {
  1949. Drawable *newDrawable = NULL;
  1950. Bool hack = FALSE;
  1951. Drawable *selectedDrawable = TheInGameUI->getFirstSelectedDrawable();
  1952. Object *selectedObject = selectedDrawable->getObject();
  1953. if( selectedObject->isLocallyControlled() )
  1954. {
  1955. // find the previous selectable drawable
  1956. temp = selectedDrawable->getPrevDrawable();
  1957. //temp = selectedDrawable;
  1958. for( ; temp != selectedDrawable; temp = temp->getPrevDrawable() )
  1959. {
  1960. if( hack == TRUE )
  1961. {
  1962. temp = temp->getNextDrawable();
  1963. hack = FALSE;
  1964. }
  1965. // if temp is null, set it to the last drawable and loop back to selected drawable
  1966. if( temp == NULL )
  1967. {
  1968. for(temp = selectedDrawable; temp->getNextDrawable() != NULL; temp = temp->getNextDrawable() )
  1969. {
  1970. }
  1971. hack = TRUE;
  1972. }
  1973. // else search for a previous selectable drawable
  1974. else
  1975. {
  1976. const Object *tempObject = temp->getObject();
  1977. if( tempObject && tempObject->isMobile() && tempObject->isLocallyControlled() && !tempObject->isContained() && !tempObject->isKindOf( KINDOF_DRONE ) )
  1978. {
  1979. newDrawable = temp;
  1980. break;
  1981. //temp = selectedDrawable; // same as break
  1982. }
  1983. }
  1984. }
  1985. //if there is another selectable unit, select it
  1986. if(newDrawable != NULL )
  1987. {
  1988. //deselect other units
  1989. TheInGameUI->deselectAllDrawables();
  1990. // create a new group.
  1991. GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
  1992. //New group or add to group? Passed in value is true if we are creating a new group.
  1993. teamMsg->appendBooleanArgument( TRUE );
  1994. teamMsg->appendObjectIDArgument( newDrawable->getObject()->getID() );
  1995. // select the unit
  1996. TheInGameUI->selectDrawable( newDrawable );
  1997. // center on the unit
  1998. TheTacticalView->lookAt(newDrawable->getPosition());
  1999. }
  2000. }
  2001. }
  2002. disp = DESTROY_MESSAGE;
  2003. break;
  2004. }
  2005. //-----------------------------------------------------------------------------------------
  2006. case GameMessage::MSG_META_SELECT_PREV_UNIT:
  2007. {
  2008. /* because list is prepended, iterate through forwards */
  2009. // if there is nothing on the screen, bail
  2010. if( TheGameClient->firstDrawable() == NULL )
  2011. break;
  2012. Drawable *temp;
  2013. // if nothing is selected
  2014. if( TheInGameUI->getSelectCount() == 0 )
  2015. {
  2016. // get the first drawable
  2017. temp = TheGameClient->firstDrawable();
  2018. for( temp; temp != NULL; temp = temp->getPrevDrawable() )
  2019. {
  2020. const Object *object = temp->getObject();
  2021. // if you've reached the end of the list, don't select anything
  2022. if( !object )
  2023. {
  2024. break;
  2025. }
  2026. else if( object && object->isMobile() && object->isLocallyControlled() && !object->isContained() && !object->isKindOf( KINDOF_DRONE ) )
  2027. {
  2028. // create a new group.
  2029. GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
  2030. //New group or add to group? Passed in value is true if we are creating a new group.
  2031. teamMsg->appendBooleanArgument( TRUE );
  2032. teamMsg->appendObjectIDArgument( object->getID() );
  2033. TheInGameUI->selectDrawable( temp );
  2034. // center on the unit
  2035. TheTacticalView->lookAt(temp->getPosition());
  2036. break;
  2037. }
  2038. }
  2039. }
  2040. else
  2041. {
  2042. Drawable *newDrawable = NULL;
  2043. TheGameClient->getDrawableList();
  2044. Bool hack = FALSE; // takes care of when for loop skips firstdrawable
  2045. Drawable *selectedDrawable = TheInGameUI->getFirstSelectedDrawable();
  2046. Object *selectedObject = selectedDrawable->getObject();
  2047. if( selectedObject->isLocallyControlled() )
  2048. {
  2049. // find the next selectable drawable
  2050. temp = selectedDrawable->getNextDrawable();
  2051. //temp = selectedDrawable;
  2052. for( temp; temp != selectedDrawable; temp = temp->getNextDrawable() )
  2053. {
  2054. if( hack == TRUE )
  2055. {
  2056. temp = TheGameClient->firstDrawable();
  2057. hack = FALSE;
  2058. if( temp == selectedDrawable )
  2059. {
  2060. break;
  2061. }
  2062. }
  2063. // if temp is null, set it to the first drawable and loop forward to selected drawable
  2064. if( temp == NULL )
  2065. {
  2066. temp = TheGameClient->firstDrawable();
  2067. hack = TRUE;
  2068. const Object *tempObject = temp->getObject();
  2069. // must take case of this case here or else the loop will break without getting newDrawable
  2070. if( tempObject && temp->getNextDrawable() == selectedDrawable && !temp->isSelected()
  2071. && tempObject->isMobile() && tempObject->isLocallyControlled() && !tempObject->isContained() && !tempObject->isKindOf( KINDOF_DRONE ) )
  2072. {
  2073. newDrawable = temp;
  2074. break;
  2075. }
  2076. }
  2077. // else search for a next selectable drawable
  2078. else
  2079. {
  2080. const Object *tempObject = temp->getObject();
  2081. if( tempObject && !temp->isSelected() && tempObject->isMobile() && tempObject->isLocallyControlled() && !tempObject->isContained() )
  2082. {
  2083. newDrawable = temp;
  2084. break;
  2085. }
  2086. }
  2087. }
  2088. //if there is another selectable unit, select it
  2089. if(newDrawable != NULL )
  2090. {
  2091. //deselect other units
  2092. TheInGameUI->deselectAllDrawables();
  2093. // select the unit
  2094. // create a new group.
  2095. GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
  2096. //New group or add to group? Passed in value is true if we are creating a new group.
  2097. teamMsg->appendBooleanArgument( TRUE );
  2098. teamMsg->appendObjectIDArgument( newDrawable->getObject()->getID() );
  2099. TheInGameUI->selectDrawable( newDrawable );
  2100. // center on the unit
  2101. TheTacticalView->lookAt(newDrawable->getPosition());
  2102. }
  2103. }
  2104. }
  2105. disp = DESTROY_MESSAGE;
  2106. break;
  2107. } // end select previous unit
  2108. //-----------------------------------------------------------------------------------------
  2109. case GameMessage::MSG_META_SELECT_NEXT_WORKER:
  2110. {
  2111. /* because list is prepended, iterate through backwards */
  2112. // if there is nothing on the screen, bail
  2113. if( TheGameClient->firstDrawable() == NULL )
  2114. break;
  2115. Drawable *temp;
  2116. // if nothing is selected
  2117. if( TheInGameUI->getSelectCount() == 0 )
  2118. {
  2119. // get the last drawable
  2120. for( temp = TheGameClient->firstDrawable(); temp->getNextDrawable() != NULL; temp = temp->getNextDrawable() )
  2121. {
  2122. }
  2123. // temp is the last drawable
  2124. for( temp; temp != NULL; temp = temp->getPrevDrawable() )
  2125. {
  2126. const Object *object = temp->getObject();
  2127. // if you've reached the end of the list, don't select anything
  2128. if( !object )
  2129. {
  2130. break;
  2131. }
  2132. // make sure you select only workers
  2133. else if( object && object->isLocallyControlled() && !object->isContained() && object->isKindOf(KINDOF_DOZER) )
  2134. {
  2135. // create a new group.
  2136. GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
  2137. //New group so pass in value true
  2138. teamMsg->appendBooleanArgument( TRUE );
  2139. teamMsg->appendObjectIDArgument( object->getID() );
  2140. TheInGameUI->selectDrawable( temp );
  2141. // play the units sound
  2142. AudioEventRTS soundEvent = *temp->getTemplate()->getVoiceSelect();
  2143. soundEvent.setObjectID(object->getID());
  2144. TheAudio->addAudioEvent( &soundEvent );
  2145. // center on the unit
  2146. TheTacticalView->lookAt(temp->getPosition());
  2147. break;
  2148. }
  2149. }
  2150. }
  2151. else
  2152. {
  2153. Drawable *newDrawable = NULL;
  2154. Bool hack = FALSE;
  2155. Drawable *selectedDrawable = TheInGameUI->getFirstSelectedDrawable();
  2156. Object *selectedObject = selectedDrawable->getObject();
  2157. if( selectedObject->isLocallyControlled() )
  2158. {
  2159. // find the previous selectable drawable
  2160. temp = selectedDrawable->getPrevDrawable();
  2161. //temp = selectedDrawable;
  2162. for( ; temp != selectedDrawable; temp = temp->getPrevDrawable() )
  2163. {
  2164. if( hack == TRUE )
  2165. {
  2166. temp = temp->getNextDrawable();
  2167. hack = FALSE;
  2168. }
  2169. // if temp is null, set it to the last drawable and loop back to selected drawable
  2170. if( temp == NULL )
  2171. {
  2172. for(temp = selectedDrawable; temp->getNextDrawable() != NULL; temp = temp->getNextDrawable() )
  2173. {
  2174. }
  2175. hack = TRUE;
  2176. }
  2177. // else search for a previous selectable drawable
  2178. else
  2179. {
  2180. const Object *tempObject = temp->getObject();
  2181. if( tempObject && tempObject->isLocallyControlled() && !tempObject->isContained() && tempObject->isKindOf( KINDOF_DOZER ) )
  2182. {
  2183. newDrawable = temp;
  2184. break;
  2185. //temp = selectedDrawable; // same as break
  2186. }
  2187. }
  2188. }
  2189. //if there is another selectable unit, select it
  2190. if(newDrawable != NULL )
  2191. {
  2192. //deselect other units
  2193. TheInGameUI->deselectAllDrawables();
  2194. // select the unit
  2195. // create a new group.
  2196. GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
  2197. //New group so pass in value true
  2198. teamMsg->appendBooleanArgument( TRUE );
  2199. teamMsg->appendObjectIDArgument( newDrawable->getObject()->getID() );
  2200. TheInGameUI->selectDrawable( newDrawable );
  2201. // center on the unit
  2202. TheTacticalView->lookAt(newDrawable->getPosition());
  2203. }
  2204. }
  2205. }
  2206. disp = DESTROY_MESSAGE;
  2207. break;
  2208. } // end select next worker
  2209. //-----------------------------------------------------------------------------------------
  2210. case GameMessage::MSG_META_SELECT_PREV_WORKER:
  2211. {
  2212. /* because list is prepended, iterate through forwards */
  2213. // if there is nothing on the screen, bail
  2214. if( TheGameClient->firstDrawable() == NULL )
  2215. break;
  2216. Drawable *temp;
  2217. // if nothing is selected
  2218. if( TheInGameUI->getSelectCount() == 0 )
  2219. {
  2220. // get the first drawable
  2221. temp = TheGameClient->firstDrawable();
  2222. for( temp; temp != NULL; temp = temp->getPrevDrawable() )
  2223. {
  2224. const Object *object = temp->getObject();
  2225. // if you've reached the end of the list, don't select anything
  2226. if( !object )
  2227. {
  2228. break;
  2229. }
  2230. else if( object && object->isMobile() && object->isLocallyControlled() && !object->isContained() && object->isKindOf( KINDOF_DOZER ))
  2231. {
  2232. // create a new group.
  2233. GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
  2234. //New group or add to group? Passed in value is true if we are creating a new group.
  2235. teamMsg->appendBooleanArgument( TRUE );
  2236. teamMsg->appendObjectIDArgument( object->getID() );
  2237. TheInGameUI->selectDrawable( temp );
  2238. // center on the unit
  2239. TheTacticalView->lookAt(temp->getPosition());
  2240. break;
  2241. }
  2242. }
  2243. }
  2244. else
  2245. {
  2246. Drawable *newDrawable = NULL;
  2247. TheGameClient->getDrawableList();
  2248. Bool hack = FALSE; // takes care of when for loop skips firstdrawable
  2249. Drawable *selectedDrawable = TheInGameUI->getFirstSelectedDrawable();
  2250. Object *selectedObject = selectedDrawable->getObject();
  2251. if( selectedObject->isLocallyControlled() )
  2252. {
  2253. // find the next selectable drawable
  2254. temp = selectedDrawable->getNextDrawable();
  2255. //temp = selectedDrawable;
  2256. for( temp; temp != selectedDrawable; temp = temp->getNextDrawable() )
  2257. {
  2258. if( hack == TRUE )
  2259. {
  2260. temp = TheGameClient->firstDrawable();
  2261. hack = FALSE;
  2262. if( temp == selectedDrawable )
  2263. {
  2264. break;
  2265. }
  2266. }
  2267. // if temp is null, set it to the first drawable and loop forward to selected drawable
  2268. if( temp == NULL )
  2269. {
  2270. temp = TheGameClient->firstDrawable();
  2271. hack = TRUE;
  2272. const Object *tempObject = temp->getObject();
  2273. // must take case of this case here or else the loop will break without getting newDrawable
  2274. if( tempObject && temp->getNextDrawable() == selectedDrawable && !temp->isSelected()
  2275. && tempObject->isMobile() && tempObject->isLocallyControlled() && !tempObject->isContained() )
  2276. {
  2277. newDrawable = temp;
  2278. break;
  2279. }
  2280. }
  2281. // else search for a next selectable drawable
  2282. else
  2283. {
  2284. const Object *tempObject = temp->getObject();
  2285. if( tempObject && !temp->isSelected() && tempObject->isMobile()
  2286. && tempObject->isLocallyControlled() && !tempObject->isContained() && tempObject->isKindOf( KINDOF_DOZER ) )
  2287. {
  2288. newDrawable = temp;
  2289. break;
  2290. }
  2291. }
  2292. }
  2293. //if there is another selectable unit, select it
  2294. if(newDrawable != NULL )
  2295. {
  2296. //deselect other units
  2297. TheInGameUI->deselectAllDrawables();
  2298. // select the unit
  2299. // create a new group.
  2300. GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
  2301. //New group so passed in value true
  2302. teamMsg->appendBooleanArgument( TRUE );
  2303. teamMsg->appendObjectIDArgument( newDrawable->getObject()->getID() );
  2304. TheInGameUI->selectDrawable( newDrawable );
  2305. // center on the unit
  2306. TheTacticalView->lookAt(newDrawable->getPosition());
  2307. }
  2308. }
  2309. }
  2310. disp = DESTROY_MESSAGE;
  2311. break;
  2312. } // end select previous worker
  2313. //-----------------------------------------------------------------------------------------
  2314. case GameMessage::MSG_META_SELECT_HERO:
  2315. {
  2316. // if there is nothing on the screen, bail
  2317. if( TheGameClient->firstDrawable() == NULL )
  2318. break;
  2319. Object *hero = iNeedAHero();
  2320. if ( hero == NULL )
  2321. break;
  2322. if ( hero->isContained() )
  2323. hero = hero->getContainedBy();
  2324. Drawable *heroDraw = hero->getDrawable();
  2325. if ( heroDraw == NULL )
  2326. break;
  2327. TheInGameUI->deselectAllDrawables();
  2328. // create a new group.
  2329. GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
  2330. //New group so pass in value true
  2331. teamMsg->appendBooleanArgument( TRUE );
  2332. teamMsg->appendObjectIDArgument( hero->getID() );
  2333. TheInGameUI->selectDrawable( heroDraw );
  2334. // center on the unit
  2335. TheTacticalView->lookAt(heroDraw->getPosition());
  2336. disp = DESTROY_MESSAGE;
  2337. break;
  2338. }
  2339. //-----------------------------------------------------------------------------------------
  2340. case GameMessage::MSG_META_VIEW_COMMAND_CENTER:
  2341. viewCommandCenter();
  2342. disp = DESTROY_MESSAGE;
  2343. break;
  2344. //-----------------------------------------------------------------------------------------
  2345. case GameMessage::MSG_META_VIEW_LAST_RADAR_EVENT:
  2346. {
  2347. // Player *player = ThePlayerList->getLocalPlayer();
  2348. // if the local player has a radar, center on last event (if any)
  2349. // Excuse me? You don't need radar for the spacebar. That's silly.
  2350. // if( TheRadar->isRadarForced() || ( TheRadar->isRadarHidden() == false && player->hasRadar() ) )
  2351. {
  2352. Coord3D lastEvent;
  2353. if( TheRadar->getLastEventLoc( &lastEvent ) )
  2354. TheTacticalView->lookAt( &lastEvent );
  2355. } // end if
  2356. disp = DESTROY_MESSAGE;
  2357. break;
  2358. } // end view last radar event
  2359. //-----------------------------------------------------------------------------------------
  2360. case GameMessage::MSG_META_SELECT_ALL:
  2361. {
  2362. TheInGameUI->deselectAllDrawables();
  2363. GameMessage *teamMsg = TheMessageStream->appendMessage( GameMessage::MSG_CREATE_SELECTED_GROUP );
  2364. // creating a new team so pass in true
  2365. teamMsg->appendBooleanArgument( TRUE );
  2366. // just loop through all the drawables in the world
  2367. Drawable *draw = TheGameClient->firstDrawable();
  2368. while( draw )
  2369. {
  2370. const Object *object = draw->getObject();
  2371. //Only select the object if it is locally controlled and not contained by anything.
  2372. KindOfMaskType disqualifyingKindofs;
  2373. disqualifyingKindofs.set(KINDOF_DOZER);
  2374. disqualifyingKindofs.set(KINDOF_HARVESTER);
  2375. disqualifyingKindofs.set(KINDOF_IGNORES_SELECT_ALL);
  2376. if( object
  2377. && object->isMobile()
  2378. && object->isLocallyControlled()
  2379. && !object->isContained()
  2380. && !object->isAnyKindOf( disqualifyingKindofs )
  2381. && !object->isEffectivelyDead()
  2382. && object->isMassSelectable()
  2383. )
  2384. {
  2385. // enforce optional unit cap
  2386. if (TheInGameUI->getMaxSelectCount() > 0 && TheInGameUI->getSelectCount() >= TheInGameUI->getMaxSelectCount())
  2387. {
  2388. if ( !TheInGameUI->getDisplayedMaxWarning() )
  2389. {
  2390. TheInGameUI->setDisplayedMaxWarning( TRUE );
  2391. UnicodeString msg;
  2392. msg.format(TheGameText->fetch("GUI:MaxSelectionSize").str(), TheInGameUI->getMaxSelectCount());
  2393. TheInGameUI->message(msg);
  2394. }
  2395. }
  2396. else
  2397. {
  2398. TheInGameUI->selectDrawable(draw);
  2399. teamMsg->appendObjectIDArgument( draw->getObject()->getID() );
  2400. TheInGameUI->setDisplayedMaxWarning( FALSE );
  2401. }
  2402. }
  2403. /*else
  2404. {
  2405. TheInGameUI->deselectDrawable(draw);
  2406. }*/
  2407. draw = draw->getNextDrawable();
  2408. }
  2409. if( TheInGameUI->getSelectCount() )
  2410. {
  2411. UnicodeString message = TheGameText->fetch( "GUI:SelectedAcrossMap" );
  2412. TheInGameUI->message( message );
  2413. }
  2414. disp = DESTROY_MESSAGE;
  2415. break;
  2416. } // end select all
  2417. //-----------------------------------------------------------------------------------------
  2418. case GameMessage::MSG_META_SCATTER:
  2419. // This message always works on the currently selected team
  2420. TheMessageStream->appendMessage(GameMessage::MSG_DO_SCATTER);
  2421. disp = DESTROY_MESSAGE;
  2422. break;
  2423. //-----------------------------------------------------------------------------------------
  2424. case GameMessage::MSG_META_STOP:
  2425. // This message always works on the currently selected team
  2426. TheMessageStream->appendMessage(GameMessage::MSG_DO_STOP);
  2427. disp = DESTROY_MESSAGE;
  2428. break;
  2429. //-----------------------------------------------------------------------------------------
  2430. case GameMessage::MSG_META_CREATE_FORMATION:
  2431. // This message always works on the currently selected team
  2432. TheMessageStream->appendMessage(GameMessage::MSG_CREATE_FORMATION);
  2433. disp = DESTROY_MESSAGE;
  2434. break;
  2435. //-----------------------------------------------------------------------------------------
  2436. case GameMessage::MSG_META_DEPLOY:
  2437. #ifdef _DEBUG
  2438. DEBUG_ASSERTCRASH(FALSE, ("unimplemented meta command MSG_META_DEPLOY !"));
  2439. #endif
  2440. /// @todo srj implement me
  2441. disp = DESTROY_MESSAGE;
  2442. break;
  2443. //-----------------------------------------------------------------------------------------
  2444. case GameMessage::MSG_META_FOLLOW:
  2445. #ifdef _DEBUG
  2446. DEBUG_ASSERTCRASH(FALSE, ("unimplemented meta command MSG_META_FOLLOW !"));
  2447. #endif
  2448. /// @todo srj implement me
  2449. disp = DESTROY_MESSAGE;
  2450. break;
  2451. //-----------------------------------------------------------------------------------------
  2452. /* MDC - no such thing as chat to players right now - not until we have a diplomacy screen
  2453. case GameMessage::MSG_META_CHAT_PLAYERS:
  2454. if (TheGameLogic->isInMultiplayerGame() && !TheGameLogic->isInReplayGame())
  2455. {
  2456. ToggleInGameChat();
  2457. SetInGameChatType( INGAME_CHAT_PLAYERS );
  2458. }
  2459. disp = DESTROY_MESSAGE;
  2460. break;
  2461. */
  2462. //-----------------------------------------------------------------------------------------
  2463. case GameMessage::MSG_META_CHAT_ALLIES:
  2464. #if !defined(_PLAYTEST)
  2465. if (TheGameLogic->isInMultiplayerGame() && !TheGameLogic->isInReplayGame())
  2466. #else
  2467. if (TheGameLogic->isInMultiplayerGame())
  2468. #endif
  2469. {
  2470. Player *localPlayer = ThePlayerList->getLocalPlayer();
  2471. if (localPlayer && localPlayer->isPlayerActive() || !TheGlobalData->m_netMinPlayers)
  2472. {
  2473. ToggleInGameChat();
  2474. SetInGameChatType( INGAME_CHAT_ALLIES );
  2475. }
  2476. }
  2477. disp = DESTROY_MESSAGE;
  2478. break;
  2479. //-----------------------------------------------------------------------------------------
  2480. case GameMessage::MSG_META_CHAT_EVERYONE:
  2481. #if !defined(_PLAYTEST)
  2482. if (TheGameLogic->isInMultiplayerGame() && !TheGameLogic->isInReplayGame())
  2483. #else
  2484. if (TheGameLogic->isInMultiplayerGame())
  2485. #endif
  2486. {
  2487. Player *localPlayer = ThePlayerList->getLocalPlayer();
  2488. if (localPlayer && localPlayer->isPlayerActive() || !TheGlobalData->m_netMinPlayers)
  2489. {
  2490. ToggleInGameChat();
  2491. SetInGameChatType( INGAME_CHAT_EVERYONE );
  2492. }
  2493. }
  2494. disp = DESTROY_MESSAGE;
  2495. break;
  2496. //-----------------------------------------------------------------------------------------
  2497. case GameMessage::MSG_META_DIPLOMACY:
  2498. if (TheGameLogic->isInGame() && !TheGameLogic->isInShellGame())
  2499. {
  2500. ToggleDiplomacy( FALSE );
  2501. }
  2502. else if( TheShell && TheShell->isShellActive() && TheGameSpyBuddyMessageQueue)
  2503. GameSpyToggleOverlay(GSOVERLAY_BUDDY);
  2504. disp = DESTROY_MESSAGE;
  2505. break;
  2506. //-----------------------------------------------------------------------------------------
  2507. case GameMessage::MSG_META_PLACE_BEACON:
  2508. #if !defined(_PLAYTEST)
  2509. if (TheGameLogic->isInMultiplayerGame() && !TheGameLogic->isInReplayGame() &&
  2510. ThePlayerList->getLocalPlayer()->isPlayerActive() &&
  2511. (TheGlobalData->m_netMinPlayers==0 || TheGameInfo->isMultiPlayer()))
  2512. #else
  2513. if (TheGameLogic->isInMultiplayerGame() && ThePlayerList->getLocalPlayer()->isPlayerActive() && TheGameInfo->isMultiPlayer())
  2514. #endif
  2515. {
  2516. Int count;
  2517. const ThingTemplate *thing = TheThingFactory->findTemplate( ThePlayerList->getLocalPlayer()->getPlayerTemplate()->getBeaconTemplate() );
  2518. ThePlayerList->getLocalPlayer()->countObjectsByThingTemplate( 1, &thing, false, &count );
  2519. DEBUG_LOG(("MSG_META_PLACE_BEACON - Player already has %d beacons active\n", count));
  2520. if (count < TheMultiplayerSettings->getMaxBeaconsPerPlayer())
  2521. {
  2522. const CommandButton *commandButton = TheControlBar->findCommandButton( "Command_PlaceBeacon" );
  2523. TheInGameUI->setGUICommand( commandButton );
  2524. }
  2525. }
  2526. disp = DESTROY_MESSAGE;
  2527. break;
  2528. //-----------------------------------------------------------------------------------------
  2529. case GameMessage::MSG_META_REMOVE_BEACON:
  2530. #if !defined(_PLAYTEST)
  2531. if (TheGameLogic->isInMultiplayerGame() && !TheGameLogic->isInReplayGame())
  2532. #else
  2533. if (TheGameLogic->isInMultiplayerGame())
  2534. #endif
  2535. {
  2536. TheMessageStream->appendMessage( GameMessage::MSG_REMOVE_BEACON );
  2537. }
  2538. disp = DESTROY_MESSAGE;
  2539. break;
  2540. //-----------------------------------------------------------------------------------------
  2541. case GameMessage::MSG_META_OPTIONS:
  2542. ToggleQuitMenu();
  2543. disp = DESTROY_MESSAGE;
  2544. break;
  2545. //-----------------------------------------------------------------------------------------
  2546. case GameMessage::MSG_META_TOGGLE_LOWER_DETAILS:
  2547. {
  2548. if (TheGlobalData)
  2549. {
  2550. static Bool isLowDetails = FALSE;
  2551. static Bool oldShadowVolumsValue = TRUE;
  2552. static Bool oldLightMapValue = TRUE;
  2553. static Bool oldCloudMap = TRUE;
  2554. static Bool oldBehindBuildingMarkers = TRUE;
  2555. static Int oldMaxParticleCount = 0;
  2556. if(isLowDetails)
  2557. {
  2558. TheWritableGlobalData->m_useShadowVolumes = oldShadowVolumsValue;
  2559. TheWritableGlobalData->m_useLightMap = oldLightMapValue;
  2560. TheWritableGlobalData->m_useCloudMap = oldCloudMap;
  2561. TheWritableGlobalData->m_maxParticleCount = oldMaxParticleCount;
  2562. TheGameLogic->setShowBehindBuildingMarkers(oldBehindBuildingMarkers);
  2563. if(TheInGameUI)
  2564. TheInGameUI->message("GUI:ReturnGraphicsToPreviousSettings");
  2565. }
  2566. else
  2567. {
  2568. oldShadowVolumsValue = TheGlobalData->m_useShadowVolumes;
  2569. TheWritableGlobalData->m_useShadowVolumes = FALSE;
  2570. oldLightMapValue = TheGlobalData->m_useLightMap;
  2571. TheWritableGlobalData->m_useLightMap = FALSE;
  2572. oldCloudMap = TheGlobalData->m_useCloudMap;
  2573. TheWritableGlobalData->m_useCloudMap = FALSE;
  2574. oldBehindBuildingMarkers = TheGameLogic->getShowBehindBuildingMarkers();
  2575. TheGameLogic->setShowBehindBuildingMarkers(FALSE);
  2576. oldMaxParticleCount = TheGlobalData->m_maxParticleCount;
  2577. TheWritableGlobalData->m_maxParticleCount = DROPPED_MAX_PARTICLE_COUNT;
  2578. if(TheInGameUI)
  2579. TheInGameUI->message("GUI:DetailsSetToLowest");
  2580. }
  2581. }
  2582. disp = DESTROY_MESSAGE;
  2583. break;
  2584. }
  2585. //-----------------------------------------------------------------------------------------
  2586. case GameMessage::MSG_META_TOGGLE_CONTROL_BAR:
  2587. {
  2588. if(TheShell->isShellActive())
  2589. {
  2590. WindowLayout *win = TheShell->top();
  2591. if(win)
  2592. {
  2593. win->hide(!win->isHidden());
  2594. }
  2595. }
  2596. else
  2597. {
  2598. if (!(TheRecorder && TheRecorder->getMode() == RECORDERMODETYPE_PLAYBACK))
  2599. {
  2600. Bool hide = false;
  2601. if (TheWindowManager)
  2602. {
  2603. Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
  2604. GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
  2605. if (window)
  2606. hide = !window->winIsHidden();
  2607. }
  2608. ToggleControlBar();
  2609. }
  2610. }
  2611. disp = DESTROY_MESSAGE;
  2612. break;
  2613. }
  2614. //-----------------------------------------------------------------------------------------
  2615. case GameMessage::MSG_META_TOGGLE_ATTACKMOVE:
  2616. TheInGameUI->toggleAttackMoveToMode( );
  2617. break;
  2618. case GameMessage::MSG_META_BEGIN_CAMERA_ROTATE_LEFT:
  2619. DEBUG_ASSERTCRASH(!TheInGameUI->isCameraRotatingLeft(), ("Setting rotate camera left, but it's already set!"));
  2620. TheInGameUI->setCameraRotateLeft( true );
  2621. break;
  2622. case GameMessage::MSG_META_END_CAMERA_ROTATE_LEFT:
  2623. DEBUG_ASSERTCRASH(TheInGameUI->isCameraRotatingLeft(), ("Clearing rotate camera left, but it's already clear!"));
  2624. TheInGameUI->setCameraRotateLeft( false );
  2625. break;
  2626. case GameMessage::MSG_META_BEGIN_CAMERA_ROTATE_RIGHT:
  2627. DEBUG_ASSERTCRASH(!TheInGameUI->isCameraRotatingRight(), ("Setting rotate camera right, but it's already set!"));
  2628. TheInGameUI->setCameraRotateRight( true );
  2629. break;
  2630. case GameMessage::MSG_META_END_CAMERA_ROTATE_RIGHT:
  2631. DEBUG_ASSERTCRASH(TheInGameUI->isCameraRotatingRight(), ("Clearing rotate camera right, but it's already clear!"));
  2632. TheInGameUI->setCameraRotateRight( false );
  2633. break;
  2634. case GameMessage::MSG_META_BEGIN_CAMERA_ZOOM_IN:
  2635. DEBUG_ASSERTCRASH(!TheInGameUI->isCameraZoomingIn(), ("Setting zoom camera in, but it's already set!"));
  2636. TheInGameUI->setCameraZoomIn( true );
  2637. break;
  2638. case GameMessage::MSG_META_END_CAMERA_ZOOM_IN:
  2639. DEBUG_ASSERTCRASH(TheInGameUI->isCameraZoomingIn(), ("Clearing zoom camera in, but it's already clear!"));
  2640. TheInGameUI->setCameraZoomIn( false );
  2641. break;
  2642. case GameMessage::MSG_META_BEGIN_CAMERA_ZOOM_OUT:
  2643. DEBUG_ASSERTCRASH(!TheInGameUI->isCameraZoomingOut(), ("Setting zoom camera out, but it's already set!"));
  2644. TheInGameUI->setCameraZoomOut( true );
  2645. break;
  2646. case GameMessage::MSG_META_END_CAMERA_ZOOM_OUT:
  2647. DEBUG_ASSERTCRASH(TheInGameUI->isCameraZoomingOut(), ("Clearing zoom camera out, but it's already clear!"));
  2648. TheInGameUI->setCameraZoomOut( false );
  2649. break;
  2650. case GameMessage::MSG_META_CAMERA_RESET:
  2651. TheInGameUI->resetCamera();
  2652. break;
  2653. //-----------------------------------------------------------------------------------------
  2654. case GameMessage::MSG_META_BEGIN_FORCEMOVE:
  2655. DEBUG_ASSERTCRASH(!TheInGameUI->isInForceMoveToMode(), ("forceMoveToMode mismatch"));
  2656. TheInGameUI->setForceMoveMode( true );
  2657. break;
  2658. //-----------------------------------------------------------------------------------------
  2659. case GameMessage::MSG_META_END_FORCEMOVE:
  2660. DEBUG_ASSERTCRASH(TheInGameUI->isInForceMoveToMode(), ("forceMoveToMode mismatch"));
  2661. TheInGameUI->setForceMoveMode( false );
  2662. break;
  2663. //-----------------------------------------------------------------------------------------
  2664. case GameMessage::MSG_META_BEGIN_WAYPOINTS:
  2665. DEBUG_ASSERTCRASH( !TheInGameUI->isInWaypointMode(), ("Setting m_waypointMode but it's already set!") );
  2666. TheInGameUI->setWaypointMode( true );
  2667. break;
  2668. //-----------------------------------------------------------------------------------------
  2669. case GameMessage::MSG_META_BEGIN_PREFER_SELECTION:
  2670. TheInGameUI->setPreferSelectionMode( true );
  2671. break;
  2672. //-----------------------------------------------------------------------------------------
  2673. case GameMessage::MSG_META_END_PREFER_SELECTION:
  2674. TheInGameUI->setPreferSelectionMode( false );
  2675. break;
  2676. //-----------------------------------------------------------------------------------------
  2677. case GameMessage::MSG_META_END_WAYPOINTS:
  2678. DEBUG_ASSERTCRASH( TheInGameUI->isInWaypointMode(), ("Clearing m_waypointMode but it's already clear!") );
  2679. TheInGameUI->setWaypointMode( false );
  2680. break;
  2681. //-----------------------------------------------------------------------------------------
  2682. case GameMessage::MSG_META_BEGIN_FORCEATTACK:
  2683. TheInGameUI->setForceAttackMode( true );
  2684. break;
  2685. //-----------------------------------------------------------------------------------------
  2686. case GameMessage::MSG_META_END_FORCEATTACK:
  2687. TheInGameUI->setForceAttackMode( false );
  2688. break;
  2689. // --------------------------------------------------------------------------------------------
  2690. case GameMessage::MSG_META_ALL_CHEER:
  2691. {
  2692. if ( TheGameLogic->isInMultiplayerGame() )
  2693. {
  2694. TheAudio->addAudioEvent(&TheAudio->getMiscAudio()->m_allCheerSound);
  2695. disp = DESTROY_MESSAGE;
  2696. TheMessageStream->appendMessage( GameMessage::MSG_DO_CHEER );
  2697. }
  2698. break;
  2699. }
  2700. // --------------------------------------------------------------------------------------------
  2701. case GameMessage::MSG_META_TAKE_SCREENSHOT:
  2702. {
  2703. if (TheDisplay)
  2704. TheDisplay->takeScreenShot();
  2705. disp = DESTROY_MESSAGE;
  2706. break;
  2707. }
  2708. // --------------------------------------------------------------------------------------------
  2709. case GameMessage::MSG_CREATE_SELECTED_GROUP:
  2710. case GameMessage::MSG_SELECT_TEAM0:
  2711. case GameMessage::MSG_SELECT_TEAM1:
  2712. case GameMessage::MSG_SELECT_TEAM2:
  2713. case GameMessage::MSG_SELECT_TEAM3:
  2714. case GameMessage::MSG_SELECT_TEAM4:
  2715. case GameMessage::MSG_SELECT_TEAM5:
  2716. case GameMessage::MSG_SELECT_TEAM6:
  2717. case GameMessage::MSG_SELECT_TEAM7:
  2718. case GameMessage::MSG_SELECT_TEAM8:
  2719. case GameMessage::MSG_SELECT_TEAM9:
  2720. {
  2721. // weed out unit responses for things we don't own.
  2722. DrawableList listOfUnits = *TheInGameUI->getAllSelectedDrawables();
  2723. for (DrawableListIt it = listOfUnits.begin(); it != listOfUnits.end(); /* empty */) {
  2724. Drawable *draw = *it;
  2725. if (draw->getObject() && draw->getObject()->isLocallyControlled()) {
  2726. // This thing can emit a unit response.
  2727. ++it;
  2728. continue;
  2729. } else {
  2730. // remove it.
  2731. it = listOfUnits.erase(it);
  2732. }
  2733. }
  2734. if (!listOfUnits.empty()) {
  2735. pickAndPlayUnitVoiceResponse( &listOfUnits, GameMessage::MSG_CREATE_SELECTED_GROUP );
  2736. }
  2737. m_teamExists = true;
  2738. break;
  2739. }
  2740. // --------------------------------------------------------------------------------------------
  2741. case GameMessage::MSG_CREATE_SELECTED_GROUP_NO_SOUND:
  2742. case GameMessage::MSG_ADD_TEAM0:
  2743. case GameMessage::MSG_ADD_TEAM1:
  2744. case GameMessage::MSG_ADD_TEAM2:
  2745. case GameMessage::MSG_ADD_TEAM3:
  2746. case GameMessage::MSG_ADD_TEAM4:
  2747. case GameMessage::MSG_ADD_TEAM5:
  2748. case GameMessage::MSG_ADD_TEAM6:
  2749. case GameMessage::MSG_ADD_TEAM7:
  2750. case GameMessage::MSG_ADD_TEAM8:
  2751. case GameMessage::MSG_ADD_TEAM9:
  2752. {
  2753. m_teamExists = true;
  2754. break;
  2755. }
  2756. // --------------------------------------------------------------------------------------------
  2757. case GameMessage::MSG_DESTROY_SELECTED_GROUP:
  2758. {
  2759. m_teamExists = false;
  2760. break;
  2761. }
  2762. // --------------------------------------------------------------------------------------------
  2763. // An object is mouseover'd. A hint of a command may be generated if something is selected
  2764. // --------------------------------------------------------------------------------------------
  2765. case GameMessage::MSG_MOUSEOVER_DRAWABLE_HINT:
  2766. {
  2767. const CommandButton *command = TheInGameUI->getGUICommand();
  2768. if( TheInGameUI->getSelectCount() > 0
  2769. || (command && command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_COMMAND_CENTER) ) // If something is selected
  2770. {
  2771. /// @todo This as well as the one in GameMessage::MSG_DRAWABLE_PICKED below should possibly have a generalized CanAttack instead of simply checking isEnemyOf
  2772. Drawable *draw = TheGameClient->findDrawableByID( msg->getArgument( 0 )->drawableID );
  2773. if( draw )
  2774. {
  2775. //
  2776. // given the drawable that we have moused over, pretend that we have actually
  2777. // "picked" that drawable, depending on what we have selected, our mode,
  2778. // and what "picked" is we would do a command ... but here we only will generate
  2779. // the hint message, *not* the actual command
  2780. //
  2781. if (TheInGameUI->isInForceAttackMode()) {
  2782. evaluateForceAttack(draw, draw->getPosition(), DO_HINT );
  2783. } else {
  2784. evaluateContextCommand( draw, draw->getPosition(), DO_HINT );
  2785. }
  2786. // Do not eat this message, as it itself has another purpose in HintSpy
  2787. }
  2788. }
  2789. }
  2790. break;
  2791. //-----------------------------------------------------------------------------
  2792. // Terrain is mouseover'd. A hint of a command may be generated if something is selected
  2793. //
  2794. case GameMessage::MSG_MOUSEOVER_LOCATION_HINT:
  2795. {
  2796. Coord3D position = msg->getArgument( 0 )->location;
  2797. //
  2798. // This message occurs whenever the mouse cursor moves off of a drawable, in which
  2799. // case we want to turn off the pick hint.
  2800. //
  2801. if (TheInGameUI->isInForceAttackMode()) {
  2802. evaluateForceAttack( NULL, &position, DO_HINT );
  2803. } else {
  2804. evaluateContextCommand( NULL, &position, DO_HINT );
  2805. }
  2806. // Do not eat this message, as it will do something itself at HintSpy
  2807. break;
  2808. } // end case GameMessage::MSG_MOUSEOVER_LOCATION_HINT
  2809. //-----------------------------------------------------------------------------
  2810. case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN:
  2811. {
  2812. // There are two ways in which we can ignore this as a deselect:
  2813. // 1) 2-D position on screen
  2814. // 2) Time has exceeded the time which we allow for this to be a click.
  2815. m_mouseRightDragAnchor = msg->getArgument( 0 )->pixel;
  2816. m_mouseRightDown = (UnsignedInt) msg->getArgument( 2 )->integer;
  2817. break;
  2818. }
  2819. //-----------------------------------------------------------------------------
  2820. case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP:
  2821. {
  2822. // register this event for determining if the click was fast or short enough not to be a drag
  2823. m_mouseRightDragLift = msg->getArgument( 0 )->pixel;
  2824. m_mouseRightUp = (UnsignedInt) msg->getArgument( 2 )->integer;
  2825. break;
  2826. }
  2827. //-----------------------------------------------------------------------------
  2828. case GameMessage::MSG_MOUSE_RIGHT_DOUBLE_CLICK:
  2829. case GameMessage::MSG_MOUSE_RIGHT_CLICK:
  2830. {
  2831. // right click is only actioned here if we're in alternate mouse mode
  2832. if (TheGlobalData->m_useAlternateMouse
  2833. && TheMouse->isClick(&m_mouseRightDragAnchor, &m_mouseRightDragLift, m_mouseRightDown, m_mouseRightUp))
  2834. {
  2835. Bool isPoint = (msg->getArgument(0)->pixelRegion.height() == 0 && msg->getArgument(0)->pixelRegion.width() == 0);
  2836. // NOTE: RIGHT_CLICK is not transmitted if AREA_SELECTION or DRAWABLE_PICKED occurs.
  2837. // If we see this msg, no object was clicked on, therefore clicked on ground.
  2838. // Issue move command to all currently selected objects.
  2839. // sanity
  2840. if( TheTacticalView == NULL )
  2841. break;
  2842. // translate from screen coordinates to terrain coords
  2843. Coord3D pos;
  2844. TheTacticalView->screenToTerrain( &msg->getArgument( 0 )->pixel, &pos );
  2845. const CommandButton *command = TheInGameUI->getGUICommand();
  2846. Bool controllable = TheInGameUI->areSelectedObjectsControllable()
  2847. || (command && command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_COMMAND_CENTER);
  2848. if (isPoint && controllable)
  2849. {
  2850. UnsignedInt pickType = getPickTypesForContext( TheInGameUI->isInForceAttackMode() );
  2851. Drawable *draw = TheTacticalView->pickDrawable(&msg->getArgument(0)->pixelRegion.lo,
  2852. TheInGameUI->isInForceAttackMode(),
  2853. (PickType) pickType);
  2854. if (TheInGameUI->isInForceAttackMode()) {
  2855. evaluateForceAttack( draw, &pos, DO_COMMAND );
  2856. } else {
  2857. evaluateContextCommand( draw, &pos, DO_COMMAND );
  2858. }
  2859. disp = DESTROY_MESSAGE;
  2860. TheInGameUI->clearAttackMoveToMode();
  2861. }
  2862. }
  2863. break;
  2864. }
  2865. //-----------------------------------------------------------------------------
  2866. case GameMessage::MSG_MOUSE_LEFT_DOUBLE_CLICK:
  2867. case GameMessage::MSG_MOUSE_LEFT_CLICK:
  2868. {
  2869. Bool isPoint = (msg->getArgument(0)->pixelRegion.height() == 0 && msg->getArgument(0)->pixelRegion.width() == 0);
  2870. // NOTE: LEFT_CLICK is not transmitted if AREA_SELECTION or DRAWABLE_PICKED occurs.
  2871. // If we see this msg, no object was clicked on, therefore clicked on ground.
  2872. // Issue move command to all currently selected objects.
  2873. // sanity
  2874. if( TheTacticalView == NULL )
  2875. break;
  2876. // translate from screen coordinates to terrain coords
  2877. Coord3D pos;
  2878. TheTacticalView->screenToTerrain( &msg->getArgument( 0 )->pixel, &pos );
  2879. const CommandButton *command = TheInGameUI->getGUICommand();
  2880. // maintain this as the set of GUI button initiated commands that require a left click action in alt mouse mode
  2881. Bool isFiringGUICommand = (command && (command->getCommandType() == GUI_COMMAND_SPECIAL_POWER
  2882. || command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_COMMAND_CENTER
  2883. || command->getCommandType() == GUI_COMMAND_FIRE_WEAPON
  2884. || command->getCommandType() == GUI_COMMAND_COMBATDROP
  2885. || command->getCommandType() == GUICOMMANDMODE_HIJACK_VEHICLE
  2886. || command->getCommandType() == GUICOMMANDMODE_CONVERT_TO_CARBOMB));
  2887. // in alternate mouse mode, this left click is only actioned here if we're firing a gui command
  2888. if ((TheGlobalData->m_useAlternateMouse) && (! isFiringGUICommand))
  2889. break;
  2890. Bool controllable = TheInGameUI->areSelectedObjectsControllable()
  2891. || (command && command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_COMMAND_CENTER);
  2892. if (isPoint && controllable)
  2893. {
  2894. UnsignedInt pickType = getPickTypesForContext( TheInGameUI->isInForceAttackMode() );
  2895. Drawable *draw = TheTacticalView->pickDrawable(&msg->getArgument(0)->pixelRegion.lo,
  2896. TheInGameUI->isInForceAttackMode(),
  2897. (PickType) pickType);
  2898. if (TheInGameUI->isInForceAttackMode()) {
  2899. evaluateForceAttack( draw, &pos, DO_COMMAND );
  2900. } else {
  2901. evaluateContextCommand( draw, &pos, DO_COMMAND );
  2902. }
  2903. disp = DESTROY_MESSAGE;
  2904. TheInGameUI->clearAttackMoveToMode();
  2905. //issueMoveToLocationCommand( &pos, draw, DO_COMMAND );
  2906. }
  2907. break;
  2908. } // end case GameMessage::MSG_MOUSE_LEFT_CLICK
  2909. #if defined(_DEBUG) || defined(_INTERNAL)
  2910. //------------------------------------------------------------------------- BEGIN DEMO MESSAGES
  2911. //------------------------------------------------------------------------- BEGIN DEMO MESSAGES
  2912. //------------------------------------------------------------------------- BEGIN DEMO MESSAGES
  2913. //------------------------------------------------------------------------------- DEMO MESSAGES
  2914. //-----------------------------------------------------------------------------------------
  2915. case GameMessage::MSG_META_DEMO_INSTANT_QUIT:
  2916. if (TheGameLogic->isInGame())
  2917. {
  2918. if (TheRecorder->getMode() == RECORDERMODETYPE_RECORD)
  2919. {
  2920. TheRecorder->stopRecording();
  2921. }
  2922. TheGameLogic->clearGameData();
  2923. }
  2924. TheGameEngine->setQuitting(TRUE);
  2925. disp = DESTROY_MESSAGE;
  2926. break;
  2927. //------------------------------------------------------------------------------- DEMO MESSAGES
  2928. //-----------------------------------------------------------------------------------------
  2929. case GameMessage::MSG_META_DEMO_SWITCH_TEAMS:
  2930. {
  2931. if (TheGameLogic->isInGame())
  2932. {
  2933. Int idx;
  2934. for (Int i = 0; i < ThePlayerList->getPlayerCount(); i++)
  2935. {
  2936. if (ThePlayerList->getNthPlayer(i) == ThePlayerList->getLocalPlayer())
  2937. {
  2938. idx = i;
  2939. break;
  2940. }
  2941. }
  2942. Int idxOrig = idx;
  2943. do
  2944. {
  2945. ++idx;
  2946. if (idx >= ThePlayerList->getPlayerCount())
  2947. idx = 0;
  2948. if (idx == idxOrig)
  2949. {
  2950. break;
  2951. }
  2952. } while (ThePlayerList->getNthPlayer(idx) == ThePlayerList->getNeutralPlayer());
  2953. ThePlayerList->setLocalPlayer(ThePlayerList->getNthPlayer(idx));
  2954. TheInGameUI->deselectAllDrawables();
  2955. #ifdef DEBUG_FOG_MEMORY
  2956. TheGhostObjectManager->setLocalPlayerIndex(idx);
  2957. #endif
  2958. ThePartitionManager->refreshShroudForLocalPlayer();
  2959. TheControlBar->initSpecialPowershortcutBar(ThePlayerList->getLocalPlayer());
  2960. TheControlBar->setControlBarSchemeByPlayer(ThePlayerList->getLocalPlayer());
  2961. }
  2962. disp = DESTROY_MESSAGE;
  2963. break;
  2964. }
  2965. //------------------------------------------------------------------------------- DEMO MESSAGES
  2966. //-----------------------------------------------------------------------------------------
  2967. case GameMessage::MSG_META_DEMO_SWITCH_TEAMS_BETWEEN_CHINA_USA:
  2968. {
  2969. Player *p = ThePlayerList->getLocalPlayer();
  2970. AsciiString side;
  2971. side.set(p->getSide());
  2972. if(side.compareNoCase("America") == 0)
  2973. {
  2974. for (Int i = 0; i < ThePlayerList->getPlayerCount(); i++)
  2975. {
  2976. Player *pt = ThePlayerList->getNthPlayer(i);
  2977. if(pt->getSide().compareNoCase("China") == 0)
  2978. {
  2979. ThePlayerList->setLocalPlayer(pt);
  2980. TheInGameUI->deselectAllDrawables();
  2981. ThePartitionManager->refreshShroudForLocalPlayer();
  2982. TheControlBar->setControlBarSchemeByPlayer(ThePlayerList->getLocalPlayer());
  2983. break;
  2984. }
  2985. }
  2986. }
  2987. if(side.compareNoCase("China") == 0)
  2988. {
  2989. for (Int i = 0; i < ThePlayerList->getPlayerCount(); i++)
  2990. {
  2991. Player *pt = ThePlayerList->getNthPlayer(i);
  2992. if(pt->getSide().compareNoCase("America") == 0)
  2993. {
  2994. ThePlayerList->setLocalPlayer(pt);
  2995. TheInGameUI->deselectAllDrawables();
  2996. ThePartitionManager->refreshShroudForLocalPlayer();
  2997. TheControlBar->setControlBarSchemeByPlayer(ThePlayerList->getLocalPlayer());
  2998. break;
  2999. }
  3000. }
  3001. }
  3002. disp = DESTROY_MESSAGE;
  3003. break;
  3004. }
  3005. //------------------------------------------------------------------------------- DEMO MESSAGES
  3006. //-----------------------------------------------------------------------------------------
  3007. case GameMessage::MSG_META_DEMO_LOD_DECREASE:
  3008. {
  3009. TheGameClient->adjustLOD(-1);
  3010. disp = DESTROY_MESSAGE;
  3011. break;
  3012. }
  3013. //------------------------------------------------------------------------------- DEMO MESSAGES
  3014. //-----------------------------------------------------------------------------------------
  3015. case GameMessage::MSG_META_DEMO_LOD_INCREASE:
  3016. {
  3017. TheGameClient->adjustLOD(1);
  3018. disp = DESTROY_MESSAGE;
  3019. break;
  3020. }
  3021. //------------------------------------------------------------------------------- DEMO MESSAGES
  3022. //-----------------------------------------------------------------------------------------
  3023. case GameMessage::MSG_META_HELP:
  3024. {
  3025. // for demo, they don't want the help menu showing up. I left this as a block comment because we
  3026. // might want to add back in the help menu at some point in time.
  3027. /*
  3028. if (TheWindowManager && TheNameKeyGenerator)
  3029. {
  3030. GameWindow *motd = TheWindowManager->winGetWindowFromId(NULL, (Int)TheNameKeyGenerator->nameToKey(AsciiString("MOTD.wnd:MOTD")));
  3031. if (motd)
  3032. motd->winHide(!motd->winIsHidden());
  3033. }*/
  3034. disp = DESTROY_MESSAGE;
  3035. break;
  3036. }
  3037. //------------------------------------------------------------------------------- DEMO MESSAGES
  3038. //-----------------------------------------------------------------------------------------
  3039. case GameMessage::MSG_META_DEMO_TOGGLE_BEHIND_BUILDINGS:
  3040. {
  3041. if (TheGlobalData)
  3042. {
  3043. if(TheGameLogic->getShowBehindBuildingMarkers())
  3044. {
  3045. TheGameLogic->setShowBehindBuildingMarkers(FALSE);
  3046. TheInGameUI->message("GUI:ShowBehindBuildings");
  3047. }
  3048. else
  3049. {
  3050. TheGameLogic->setShowBehindBuildingMarkers(TRUE);
  3051. TheInGameUI->message("GUI:HideBehindBuildings");
  3052. }
  3053. }
  3054. disp = DESTROY_MESSAGE;
  3055. break;
  3056. }
  3057. //------------------------------------------------------------------------------- DEMO MESSAGES
  3058. //-----------------------------------------------------------------------------------------
  3059. case GameMessage::MSG_META_DEMO_TOGGLE_LETTERBOX:
  3060. {
  3061. if(TheShell->isShellActive())
  3062. {
  3063. WindowLayout *win = TheShell->top();
  3064. if(win)
  3065. {
  3066. win->hide(!win->isHidden());
  3067. }
  3068. }
  3069. else
  3070. {
  3071. Bool hide = false;
  3072. if (TheWindowManager)
  3073. {
  3074. Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
  3075. GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
  3076. if (window)
  3077. hide = !window->winIsHidden();
  3078. }
  3079. if (hide)
  3080. HideControlBar();
  3081. else
  3082. ShowControlBar(FALSE);
  3083. TheDisplay->toggleLetterBox();
  3084. }
  3085. disp = DESTROY_MESSAGE;
  3086. break;
  3087. }
  3088. //------------------------------------------------------------------------------- DEMO MESSAGES
  3089. //-----------------------------------------------------------------------------------------
  3090. case GameMessage::MSG_META_DEMO_TOGGLE_MESSAGE_TEXT:
  3091. {
  3092. // toggle the message state
  3093. TheInGameUI->toggleMessages();
  3094. // when messages get turned on, display a message
  3095. if( TheInGameUI->isMessagesOn() )
  3096. TheInGameUI->message( TheGameText->fetch( "GUI:MessagesOn" ) );
  3097. disp = DESTROY_MESSAGE;
  3098. break;
  3099. } // end clear message text
  3100. //------------------------------------------------------------------------------- DEMO MESSAGES
  3101. //-----------------------------------------------------------------------------------------
  3102. case GameMessage::MSG_META_DEMO_TOGGLE_MOTION_BLUR_ZOOM:
  3103. { Int mode;
  3104. if ((mode=TheTacticalView->getViewFilterType()) == FT_VIEW_MOTION_BLUR_FILTER)
  3105. { //mode already set, turn it off
  3106. TheTacticalView->setViewFilterMode(FM_NULL_MODE);
  3107. TheTacticalView->setViewFilter(FT_NULL_FILTER);
  3108. }
  3109. else
  3110. {
  3111. static Bool saturate = false;
  3112. FilterModes mode = FM_VIEW_MB_IN_AND_OUT_ALPHA;
  3113. if (saturate) {
  3114. mode = FM_VIEW_MB_IN_AND_OUT_SATURATE;
  3115. }
  3116. if (TheTacticalView->getCameraLock()!=0) {
  3117. mode = FM_VIEW_MB_PAN_ALPHA;
  3118. }
  3119. saturate = !saturate;
  3120. Coord3D curpos;
  3121. TheTacticalView->getPosition(&curpos);
  3122. curpos.x += 200;
  3123. curpos.y += 200;
  3124. TheTacticalView->setViewFilterPos(&curpos);
  3125. TheTacticalView->setViewFilterMode(mode);
  3126. TheTacticalView->setViewFilter(FT_VIEW_MOTION_BLUR_FILTER);
  3127. }
  3128. disp = DESTROY_MESSAGE;
  3129. break;
  3130. }
  3131. //------------------------------------------------------------------------------- DEMO MESSAGES
  3132. //-----------------------------------------------------------------------------------------
  3133. case GameMessage::MSG_META_DEMO_TOGGLE_BW_VIEW:
  3134. { //We're not testing BW mode anymore, so use this message for toggling wireframe mode.
  3135. static mode=0;
  3136. if (mode == 0)
  3137. { //First turn on wireframe
  3138. TheTacticalView->set3DWireFrameMode(TRUE);
  3139. mode++;
  3140. disp = DESTROY_MESSAGE;
  3141. break;
  3142. }
  3143. if (mode == 1)
  3144. {
  3145. if ((TheTacticalView->getViewFilterType()) == FT_VIEW_CROSSFADE)
  3146. { //mode already set, turn it off
  3147. TheTacticalView->setViewFilterMode(FM_NULL_MODE);
  3148. TheTacticalView->setViewFilter(FT_NULL_FILTER);
  3149. TheTacticalView->setFadeParameters(0,-1);
  3150. }
  3151. else
  3152. {
  3153. TheScriptEngine->doFreezeTime();
  3154. //TheTacticalView->setViewFilterMode(FM_VIEW_CROSSFADE_CIRCLE);
  3155. TheTacticalView->setViewFilterMode(FM_VIEW_CROSSFADE_FB_MASK);
  3156. TheTacticalView->setViewFilter(FT_VIEW_CROSSFADE);
  3157. TheTacticalView->setFadeParameters(60,-1);
  3158. TheTacticalView->set3DWireFrameMode(FALSE);
  3159. mode++;
  3160. }
  3161. }
  3162. else
  3163. if (mode == 2)
  3164. {
  3165. TheScriptEngine->doUnfreezeTime();
  3166. mode=0; //reset everything
  3167. }
  3168. disp = DESTROY_MESSAGE;
  3169. break;
  3170. }
  3171. //------------------------------------------------------------------------------- DEMO MESSAGES
  3172. //-----------------------------------------------------------------------------------------
  3173. case GameMessage::MSG_META_DEMO_TOGGLE_RED_VIEW:
  3174. {
  3175. if ((TheTacticalView->getViewFilterType()) == FT_VIEW_BW_FILTER)
  3176. { //mode already set, turn it off
  3177. TheTacticalView->setViewFilterMode(FM_NULL_MODE);
  3178. TheTacticalView->setViewFilter(FT_NULL_FILTER);
  3179. TheTacticalView->setFadeParameters(30,-1);
  3180. }
  3181. else
  3182. {
  3183. TheTacticalView->setViewFilterMode(FM_VIEW_BW_RED_AND_WHITE);
  3184. TheTacticalView->setViewFilter(FT_VIEW_BW_FILTER);
  3185. TheTacticalView->setFadeParameters(30,1);
  3186. }
  3187. disp = DESTROY_MESSAGE;
  3188. break;
  3189. }
  3190. //------------------------------------------------------------------------------- DEMO MESSAGES
  3191. //-----------------------------------------------------------------------------------------
  3192. case GameMessage::MSG_META_DEMO_TOGGLE_GREEN_VIEW:
  3193. {
  3194. if ((TheTacticalView->getViewFilterType()) == FT_VIEW_BW_FILTER)
  3195. { //mode already set, turn it off
  3196. TheTacticalView->setViewFilterMode(FM_NULL_MODE);
  3197. TheTacticalView->setViewFilter(FT_NULL_FILTER);
  3198. TheTacticalView->setFadeParameters(30,-1);
  3199. }
  3200. else
  3201. {
  3202. TheTacticalView->setViewFilterMode(FM_VIEW_BW_GREEN_AND_WHITE);
  3203. TheTacticalView->setViewFilter(FT_VIEW_BW_FILTER);
  3204. TheTacticalView->setFadeParameters(30,1);
  3205. }
  3206. disp = DESTROY_MESSAGE;
  3207. break;
  3208. }
  3209. //------------------------------------------------------------------------------- DEMO MESSAGES
  3210. //-----------------------------------------------------------------------------------------
  3211. case GameMessage::MSG_META_DEMO_CYCLE_LOD_LEVEL:
  3212. {
  3213. static Int level=DYNAMIC_GAME_LOD_VERY_HIGH;
  3214. level--;
  3215. if (level < DYNAMIC_GAME_LOD_LOW)
  3216. level = DYNAMIC_GAME_LOD_VERY_HIGH;
  3217. TheGameLODManager->setDynamicLODLevel((DynamicGameLODLevel)level);
  3218. UnicodeString lodName;
  3219. lodName.format(L"Dynamic Game Detail %hs",TheGameLODManager->getDynamicGameLODLevelName((DynamicGameLODLevel)level));
  3220. TheInGameUI->message(lodName);
  3221. disp = DESTROY_MESSAGE;
  3222. break;
  3223. }
  3224. //------------------------------------------------------------------------------- DEMO MESSAGES
  3225. //-----------------------------------------------------------------------------------------
  3226. case GameMessage::MSG_META_DEBUG_DUMP_ASSETS:
  3227. {
  3228. TheDisplay->dumpModelAssets("UsedMapAssets.txt");
  3229. disp = DESTROY_MESSAGE;
  3230. break;
  3231. }
  3232. //------------------------------------------------------------------------------- DEMO MESSAGES
  3233. //-----------------------------------------------------------------------------------------
  3234. case GameMessage::MSG_META_DEMO_TOGGLE_SHADOW_VOLUMES:
  3235. {
  3236. TheWritableGlobalData->m_useShadowVolumes = !TheGlobalData->m_useShadowVolumes;
  3237. TheWritableGlobalData->m_useShadowDecals = !TheGlobalData->m_useShadowDecals;
  3238. disp = DESTROY_MESSAGE;
  3239. break;
  3240. }
  3241. //------------------------------------------------------------------------------- DEMO MESSAGES
  3242. //-----------------------------------------------------------------------------------------
  3243. case GameMessage::MSG_META_DEMO_TOGGLE_FOGOFWAR:
  3244. {
  3245. TheWritableGlobalData->m_fogOfWarOn = !TheGlobalData->m_fogOfWarOn;
  3246. disp = DESTROY_MESSAGE;
  3247. break;
  3248. }
  3249. //------------------------------------------------------------------------------- DEMO MESSAGES
  3250. //-----------------------------------------------------------------------------------------
  3251. case GameMessage::MSG_META_DEMO_KILL_SELECTION:
  3252. {
  3253. TheMessageStream->appendMessage( GameMessage::MSG_DEBUG_KILL_SELECTION );
  3254. disp = DESTROY_MESSAGE;
  3255. break;
  3256. }
  3257. //------------------------------------------------------------------------------- DEMO MESSAGES
  3258. //-----------------------------------------------------------------------------------------
  3259. case GameMessage::MSG_META_DEMO_KILL_ALL_ENEMIES:
  3260. {
  3261. for (Drawable *d = TheGameClient->firstDrawable(); d; d = d->getNextDrawable())
  3262. {
  3263. Object* obj = d->getObject();
  3264. if (obj && obj->getControllingPlayer() && obj->getControllingPlayer()->getRelationship(ThePlayerList->getLocalPlayer()->getDefaultTeam()) == ENEMIES)
  3265. {
  3266. obj->kill();
  3267. }
  3268. }
  3269. disp = DESTROY_MESSAGE;
  3270. break;
  3271. }
  3272. //------------------------------------------------------------------------------- DEMO MESSAGES
  3273. //-----------------------------------------------------------------------------------------
  3274. case GameMessage::MSG_META_DEBUG_GIVE_VETERANCY:
  3275. case GameMessage::MSG_META_DEBUG_TAKE_VETERANCY:
  3276. {
  3277. const DrawableList *list = TheInGameUI->getAllSelectedDrawables();
  3278. for (DrawableListCIt it = list->begin(); it != list->end(); ++it)
  3279. {
  3280. Drawable *pDraw = *it;
  3281. if (pDraw)
  3282. {
  3283. Object *pObject = pDraw->getObject();
  3284. if (pObject)
  3285. {
  3286. ExperienceTracker *et = pObject->getExperienceTracker();
  3287. if (et)
  3288. {
  3289. if (et->isTrainable())
  3290. {
  3291. VeterancyLevel oldVet = et->getVeterancyLevel();
  3292. VeterancyLevel newVet = oldVet;
  3293. if (t == GameMessage::MSG_META_DEBUG_GIVE_VETERANCY)
  3294. {
  3295. if (oldVet < LEVEL_LAST)
  3296. {
  3297. newVet = (VeterancyLevel)((Int)oldVet + 1);
  3298. }
  3299. }
  3300. else
  3301. {
  3302. if (oldVet > LEVEL_FIRST)
  3303. {
  3304. newVet = (VeterancyLevel)((Int)oldVet - 1);
  3305. }
  3306. }
  3307. et->setVeterancyLevel(newVet);
  3308. }
  3309. }
  3310. }
  3311. }
  3312. }
  3313. disp = DESTROY_MESSAGE;
  3314. break;
  3315. }
  3316. //------------------------------------------------------------------------------- DEMO MESSAGES
  3317. //-----------------------------------------------------------------------------------------
  3318. case GameMessage::MSG_META_DEBUG_INCR_ANIM_SKATE_SPEED:
  3319. {
  3320. TheSkateDistOverride += 0.25f;
  3321. TheInGameUI->message( UnicodeString( L"Skate Distance Override is now %f" ), TheSkateDistOverride );
  3322. break;
  3323. }
  3324. //------------------------------------------------------------------------------- DEMO MESSAGES
  3325. //-----------------------------------------------------------------------------------------
  3326. case GameMessage::MSG_META_DEBUG_DECR_ANIM_SKATE_SPEED:
  3327. {
  3328. TheSkateDistOverride -= 0.25f;
  3329. TheInGameUI->message( UnicodeString( L"Skate Distance Override is now %f" ), TheSkateDistOverride );
  3330. break;
  3331. }
  3332. //------------------------------------------------------------------------------- DEMO MESSAGES
  3333. //-----------------------------------------------------------------------------------------
  3334. case GameMessage::MSG_META_DEBUG_CYCLE_EXTENT_TYPE:
  3335. if (extentModType == EXTENTMOD_INVALID) extentModType = EXTENTMOD_TYPE;
  3336. if (!extentModAmount) extentModAmount = 1.0f;
  3337. case GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_MAJOR:
  3338. if (extentModType == EXTENTMOD_INVALID) extentModType = EXTENTMOD_MAJOR;
  3339. if (!extentModAmount) extentModAmount = 1.0f;
  3340. case GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_MAJOR_BIG:
  3341. if (extentModType == EXTENTMOD_INVALID) extentModType = EXTENTMOD_MAJOR;
  3342. if (!extentModAmount) extentModAmount = EXTENT_BIG_CHANGE;
  3343. case GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_MAJOR:
  3344. if (extentModType == EXTENTMOD_INVALID) extentModType = EXTENTMOD_MAJOR;
  3345. if (!extentModAmount) extentModAmount = -1.0f;
  3346. case GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_MAJOR_BIG:
  3347. if (extentModType == EXTENTMOD_INVALID) extentModType = EXTENTMOD_MAJOR;
  3348. if (!extentModAmount) extentModAmount = -EXTENT_BIG_CHANGE;
  3349. case GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_MINOR:
  3350. if (extentModType == EXTENTMOD_INVALID) extentModType = EXTENTMOD_MINOR;
  3351. if (!extentModAmount) extentModAmount = 1.0f;
  3352. case GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_MINOR_BIG:
  3353. if (extentModType == EXTENTMOD_INVALID) extentModType = EXTENTMOD_MINOR;
  3354. if (!extentModAmount) extentModAmount = EXTENT_BIG_CHANGE;
  3355. case GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_MINOR:
  3356. if (extentModType == EXTENTMOD_INVALID) extentModType = EXTENTMOD_MINOR;
  3357. if (!extentModAmount) extentModAmount = -1.0f;
  3358. case GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_MINOR_BIG:
  3359. if (extentModType == EXTENTMOD_INVALID) extentModType = EXTENTMOD_MINOR;
  3360. if (!extentModAmount) extentModAmount = -EXTENT_BIG_CHANGE;
  3361. case GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_HEIGHT:
  3362. if (extentModType == EXTENTMOD_INVALID) extentModType = EXTENTMOD_HEIGHT;
  3363. if (!extentModAmount) extentModAmount = 1.0f;
  3364. case GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_HEIGHT_BIG:
  3365. if (extentModType == EXTENTMOD_INVALID) extentModType = EXTENTMOD_HEIGHT;
  3366. if (!extentModAmount) extentModAmount = EXTENT_BIG_CHANGE;
  3367. case GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_HEIGHT:
  3368. if (extentModType == EXTENTMOD_INVALID) extentModType = EXTENTMOD_HEIGHT;
  3369. if (!extentModAmount) extentModAmount = -1.0f;
  3370. case GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_HEIGHT_BIG:
  3371. if (extentModType == EXTENTMOD_INVALID) extentModType = EXTENTMOD_HEIGHT;
  3372. if (!extentModAmount) extentModAmount = -EXTENT_BIG_CHANGE;
  3373. {
  3374. const DrawableList *list = TheInGameUI->getAllSelectedDrawables();
  3375. for (DrawableListCIt it = list->begin(); it != list->end(); ++it)
  3376. {
  3377. Drawable *pDraw = *it;
  3378. if (pDraw)
  3379. {
  3380. Object *pObject = pDraw->getObject();
  3381. if (pObject)
  3382. {
  3383. const GeometryInfo oldGeometry = pObject->getGeometryInfo();
  3384. GeometryInfo newGeometry = oldGeometry;
  3385. newGeometry.tweakExtents(extentModType, extentModAmount);
  3386. AsciiString msg;
  3387. msg.format("Extent %s --> %s %d %g",oldGeometry.getDescriptiveString().str(), newGeometry.getDescriptiveString().str(), extentModType, extentModAmount);
  3388. UnicodeString umsg;
  3389. umsg.translate(msg);
  3390. TheInGameUI->message(umsg);
  3391. DEBUG_LOG(("%ls\n", msg.str()));
  3392. pObject->setGeometryInfo( newGeometry );
  3393. }
  3394. }
  3395. }
  3396. disp = DESTROY_MESSAGE;
  3397. break;
  3398. }
  3399. //------------------------------------------------------------------------------- DEMO MESSAGES
  3400. //-----------------------------------------------------------------------------------------
  3401. case GameMessage::MSG_META_DEMO_LOCK_CAMERA_TO_SELECTION:
  3402. {
  3403. ObjectID id = INVALID_ID;
  3404. Drawable *d = NULL;
  3405. for (d = TheGameClient->firstDrawable(); d; d = d->getNextDrawable())
  3406. {
  3407. if (d->isSelected() && d->getObject())
  3408. {
  3409. id = d->getObject()->getID();
  3410. break;
  3411. }
  3412. }
  3413. if (id != 0 && TheTacticalView->getCameraLock() == id)
  3414. {
  3415. if (TheTacticalView->getCameraLockDrawable())
  3416. {
  3417. id = INVALID_ID; // toggle it
  3418. d=NULL;
  3419. TheTacticalView->forceRedraw(); //reset camera to normal
  3420. }
  3421. }
  3422. else
  3423. {
  3424. d = NULL;
  3425. }
  3426. TheTacticalView->setCameraLock(id);
  3427. TheTacticalView->setCameraLockDrawable(d);
  3428. disp = DESTROY_MESSAGE;
  3429. break;
  3430. }
  3431. //------------------------------------------------------------------------------- DEMO MESSAGES
  3432. //-----------------------------------------------------------------------------------------
  3433. case GameMessage::MSG_META_DEMO_TOGGLE_SOUND:
  3434. {
  3435. if (TheAudio->isOn(AudioAffect_Sound))
  3436. {
  3437. TheDisplay->stopMovie();
  3438. TheInGameUI->stopMovie();
  3439. TheAudio->setOn(false, AudioAffect_All);
  3440. }
  3441. else
  3442. {
  3443. TheAudio->setOn(true, AudioAffect_All);
  3444. }
  3445. disp = DESTROY_MESSAGE;
  3446. break;
  3447. }
  3448. //------------------------------------------------------------------------------- DEMO MESSAGES
  3449. //-----------------------------------------------------------------------------------------
  3450. case GameMessage::MSG_META_DEMO_TOGGLE_TRACKMARKS:
  3451. {
  3452. TheWritableGlobalData->m_makeTrackMarks = !TheGlobalData->m_makeTrackMarks;
  3453. disp = DESTROY_MESSAGE;
  3454. break;
  3455. }
  3456. //------------------------------------------------------------------------------- DEMO MESSAGES
  3457. //-----------------------------------------------------------------------------------------
  3458. case GameMessage::MSG_META_DEMO_TOGGLE_WATERPLANE:
  3459. {
  3460. TheWritableGlobalData->m_useWaterPlane = !TheGlobalData->m_useWaterPlane;
  3461. disp = DESTROY_MESSAGE;
  3462. break;
  3463. }
  3464. //------------------------------------------------------------------------------- DEMO MESSAGES
  3465. //-----------------------------------------------------------------------------------------
  3466. case GameMessage::MSG_META_DEMO_TIME_OF_DAY:
  3467. {
  3468. TimeOfDay tod = TimeOfDay((Int) TheGlobalData->m_timeOfDay + 1);
  3469. if (tod >= TIME_OF_DAY_COUNT)
  3470. tod = TIME_OF_DAY_FIRST;
  3471. if (TheWritableGlobalData->setTimeOfDay(tod))
  3472. {
  3473. TheGameClient->setTimeOfDay(TheGlobalData->m_timeOfDay);
  3474. if (TheGlobalData->m_forceModelsToFollowTimeOfDay)
  3475. {
  3476. for (Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject())
  3477. {
  3478. Drawable* d = obj->getDrawable();
  3479. if (d)
  3480. {
  3481. // this just forces a refresh.
  3482. ModelConditionFlags empty;
  3483. d->clearAndSetModelConditionFlags(empty, empty);
  3484. }
  3485. }
  3486. }
  3487. }
  3488. disp = DESTROY_MESSAGE;
  3489. break;
  3490. }
  3491. //------------------------------------------------------------------------------- DEMO MESSAGES
  3492. //-----------------------------------------------------------------------------------------
  3493. case GameMessage::MSG_META_DEMO_REMOVE_PREREQ:
  3494. {
  3495. // Doesn't make a valid network message
  3496. Player *localPlayer = ThePlayerList->getLocalPlayer();
  3497. localPlayer->toggleIgnorePrereqs();
  3498. disp = DESTROY_MESSAGE;
  3499. break;
  3500. }
  3501. //------------------------------------------------------------------------------- DEMO MESSAGES
  3502. //-----------------------------------------------------------------------------------------
  3503. case GameMessage::MSG_META_DEMO_INSTANT_BUILD:
  3504. {
  3505. // Doesn't make a valid network message
  3506. Player *localPlayer = ThePlayerList->getLocalPlayer();
  3507. localPlayer->toggleInstantBuild();
  3508. disp = DESTROY_MESSAGE;
  3509. break;
  3510. }
  3511. //------------------------------------------------------------------------------- DEMO MESSAGES
  3512. //-----------------------------------------------------------------------------------------
  3513. case GameMessage::MSG_META_DEMO_FREE_BUILD:
  3514. {
  3515. // Doesn't make a valid network message
  3516. Player *localPlayer = ThePlayerList->getLocalPlayer();
  3517. localPlayer->toggleFreeBuild();
  3518. disp = DESTROY_MESSAGE;
  3519. break;
  3520. }
  3521. //------------------------------------------------------------------------------- DEMO MESSAGES
  3522. //-----------------------------------------------------------------------------------------
  3523. case GameMessage::MSG_META_DEMO_TOGGLE_RENDER:
  3524. {
  3525. TheWritableGlobalData->m_disableRender = !TheGlobalData->m_disableRender;
  3526. break;
  3527. }
  3528. //------------------------------------------------------------------------------- DEMO MESSAGES
  3529. //-----------------------------------------------------------------------------------------
  3530. case GameMessage::MSG_META_DEMO_ADD_CASH:
  3531. {
  3532. Player *localPlayer = ThePlayerList->getLocalPlayer();
  3533. Money *money = localPlayer->getMoney();
  3534. money->deposit( 10000 );
  3535. break;
  3536. }
  3537. //------------------------------------------------------------------------------- DEMO MESSAGES
  3538. //-----------------------------------------------------------------------------------------
  3539. case GameMessage::MSG_META_DEMO_RUNSCRIPT1:
  3540. case GameMessage::MSG_META_DEMO_RUNSCRIPT2:
  3541. case GameMessage::MSG_META_DEMO_RUNSCRIPT3:
  3542. case GameMessage::MSG_META_DEMO_RUNSCRIPT4:
  3543. case GameMessage::MSG_META_DEMO_RUNSCRIPT5:
  3544. case GameMessage::MSG_META_DEMO_RUNSCRIPT6:
  3545. case GameMessage::MSG_META_DEMO_RUNSCRIPT7:
  3546. case GameMessage::MSG_META_DEMO_RUNSCRIPT8:
  3547. case GameMessage::MSG_META_DEMO_RUNSCRIPT9:
  3548. {
  3549. if( TheScriptEngine )
  3550. {
  3551. Int script = t - GameMessage::MSG_META_DEMO_RUNSCRIPT1 + 1;
  3552. AsciiString scriptName;
  3553. scriptName.format("KEY_F%d", script);
  3554. TheScriptEngine->runScript(scriptName);
  3555. }
  3556. disp = DESTROY_MESSAGE;
  3557. break;
  3558. }
  3559. //------------------------------------------------------------------------------- DEMO MESSAGES
  3560. //-----------------------------------------------------------------------------------------
  3561. case GameMessage::MSG_META_DEMO_KILL_AREA_SELECTION:
  3562. {
  3563. for( int i=1; i<msg->getArgumentCount(); i++ )
  3564. {
  3565. Object *obj = TheGameLogic->findObjectByID( msg->getArgument( i )->objectID );
  3566. if( obj )
  3567. {
  3568. obj->kill();
  3569. }
  3570. }
  3571. }
  3572. break;
  3573. //------------------------------------------------------------------------------- DEMO MESSAGES
  3574. //-----------------------------------------------------------------------------------------
  3575. case GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE1:
  3576. case GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE2:
  3577. case GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE3:
  3578. case GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE4:
  3579. case GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE5:
  3580. case GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE6:
  3581. case GameMessage::MSG_META_DEMO_NEXT_OBJECTIVE_MOVIE:
  3582. {
  3583. if (TheGameLogic->isInGame())
  3584. {
  3585. if (t == GameMessage::MSG_META_DEMO_NEXT_OBJECTIVE_MOVIE)
  3586. {
  3587. m_objective++;
  3588. if (m_objective > 6)
  3589. m_objective = 1;
  3590. }
  3591. else
  3592. {
  3593. m_objective = t - GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE1 + 1;
  3594. }
  3595. AsciiString name;
  3596. name.format("DemoObjective%02d", m_objective);
  3597. TheInGameUI->playMovie(name);
  3598. }
  3599. disp = DESTROY_MESSAGE;
  3600. break;
  3601. }
  3602. //------------------------------------------------------------------------------- DEMO MESSAGES
  3603. //-----------------------------------------------------------------------------------------
  3604. case GameMessage::MSG_META_DEMO_TOGGLE_MILITARY_SUBTITLES:
  3605. {
  3606. TheInGameUI->militarySubtitle("MSG:Testing", 10000); // use some innocuous string
  3607. disp = DESTROY_MESSAGE;
  3608. break;
  3609. }
  3610. //------------------------------------------------------------------------------- DEMO MESSAGES
  3611. //-----------------------------------------------------------------------------------------
  3612. case GameMessage::MSG_META_DEMO_TOGGLE_MUSIC:
  3613. {
  3614. if (TheAudio->isMusicPlaying()) {
  3615. TheAudio->stopAudio(AudioAffect_Music);
  3616. TheInGameUI->message( UnicodeString( L"Stopping Music" ));
  3617. } else {
  3618. TheAudio->resumeAudio(AudioAffect_Music);
  3619. TheInGameUI->message( UnicodeString( L"Resuming Music" ));
  3620. }
  3621. disp = DESTROY_MESSAGE;
  3622. break;
  3623. }
  3624. //------------------------------------------------------------------------------- DEMO MESSAGES
  3625. //-----------------------------------------------------------------------------------------
  3626. case GameMessage::MSG_META_DEMO_MUSIC_NEXT_TRACK:
  3627. {
  3628. TheAudio->nextMusicTrack();
  3629. UnicodeString ustr;
  3630. ustr.format(L"Playing Track: %hs", TheAudio->getMusicTrackName().str());
  3631. TheInGameUI->message( ustr );
  3632. disp = DESTROY_MESSAGE;
  3633. break;
  3634. }
  3635. //------------------------------------------------------------------------------- DEMO MESSAGES
  3636. //-----------------------------------------------------------------------------------------
  3637. case GameMessage::MSG_META_DEMO_MUSIC_PREV_TRACK:
  3638. {
  3639. TheAudio->prevMusicTrack();
  3640. UnicodeString ustr;
  3641. ustr.format(L"Playing Track: %hs", TheAudio->getMusicTrackName().str());
  3642. TheInGameUI->message( ustr );
  3643. disp = DESTROY_MESSAGE;
  3644. break;
  3645. }
  3646. //------------------------------------------------------------------------------- DEMO MESSAGES
  3647. //-----------------------------------------------------------------------------------------
  3648. #ifdef PERF_TIMERS
  3649. case GameMessage::MSG_META_DEMO_TOGGLE_METRICS:
  3650. {
  3651. TheWritableGlobalData->m_showMetrics = !TheGlobalData->m_showMetrics;
  3652. if (TheGlobalData->m_showMetrics) {
  3653. TheDisplay->setDebugDisplayCallback(StatMetricsDisplay);
  3654. } else {
  3655. TheDisplay->setDebugDisplayCallback(NULL);
  3656. }
  3657. break;
  3658. }
  3659. #endif // #ifdef PERF_TIMERS
  3660. //------------------------------------------------------------------------------- DEMO MESSAGES
  3661. //-----------------------------------------------------------------------------------------
  3662. case GameMessage::MSG_META_DEMO_TOGGLE_AI_DEBUG:
  3663. {
  3664. TheWritableGlobalData->m_debugAI = (AIDebugOptions)((Int)TheGlobalData->m_debugAI + 1);
  3665. if (TheGlobalData->m_debugAI >= AI_DEBUG_END)
  3666. TheWritableGlobalData->m_debugAI=AI_DEBUG_NONE;
  3667. UnicodeString line;
  3668. line.format(L"Level %d", TheGlobalData->m_debugAI);
  3669. TheInGameUI->message( UnicodeString( L"Debug AI Mode is %s" ), TheGlobalData->m_debugAI ? line.str() : L"OFF" );
  3670. disp = DESTROY_MESSAGE;
  3671. break;
  3672. }
  3673. //------------------------------------------------------------------------------- DEMO MESSAGES
  3674. //-----------------------------------------------------------------------------------------
  3675. case GameMessage::MSG_META_DEMO_GIVE_SCIENCEPURCHASEPOINTS:
  3676. {
  3677. Player *player = ThePlayerList->getLocalPlayer();
  3678. if (player)
  3679. player->addSciencePurchasePoints(1);
  3680. TheInGameUI->message( UnicodeString( L"Adding a SciencePurchasePoint" ));
  3681. disp = DESTROY_MESSAGE;
  3682. break;
  3683. }
  3684. //------------------------------------------------------------------------------- DEMO MESSAGES
  3685. //-----------------------------------------------------------------------------------------
  3686. case GameMessage::MSG_META_DEMO_GIVE_ALL_SCIENCES:
  3687. {
  3688. Player *player = ThePlayerList->getLocalPlayer();
  3689. if (player)
  3690. {
  3691. // cheese festival: do NOT imitate this code. it is for debug purposes only.
  3692. std::vector<AsciiString> v = TheScienceStore->friend_getScienceNames();
  3693. for (int i = 0; i < v.size(); ++i)
  3694. {
  3695. ScienceType st = TheScienceStore->getScienceFromInternalName(v[i]);
  3696. if (st != SCIENCE_INVALID && TheScienceStore->isScienceGrantable(st))
  3697. {
  3698. player->grantScience(st);
  3699. }
  3700. }
  3701. }
  3702. TheInGameUI->message( UnicodeString( L"Granting all sciences!" ));
  3703. disp = DESTROY_MESSAGE;
  3704. break;
  3705. }
  3706. //------------------------------------------------------------------------------- DEMO MESSAGES
  3707. //-----------------------------------------------------------------------------------------
  3708. case GameMessage::MSG_META_DEMO_GIVE_RANKLEVEL:
  3709. {
  3710. Player *player = ThePlayerList->getLocalPlayer();
  3711. if (player)
  3712. player->setRankLevel(player->getRankLevel() + 1);
  3713. TheInGameUI->message( UnicodeString( L"Adding a RankLevel" ));
  3714. disp = DESTROY_MESSAGE;
  3715. break;
  3716. }
  3717. //------------------------------------------------------------------------------- DEMO MESSAGES
  3718. //-----------------------------------------------------------------------------------------
  3719. case GameMessage::MSG_META_DEMO_TAKE_RANKLEVEL:
  3720. {
  3721. Player *player = ThePlayerList->getLocalPlayer();
  3722. if (player)
  3723. player->setRankLevel(player->getRankLevel() - 1);
  3724. TheInGameUI->message( UnicodeString( L"Subtracting a RankLevel" ));
  3725. disp = DESTROY_MESSAGE;
  3726. break;
  3727. }
  3728. //------------------------------------------------------------------------------- DEMO MESSAGES
  3729. //-----------------------------------------------------------------------------------------
  3730. case GameMessage::MSG_META_DEMO_TOGGLE_CAMERA_DEBUG:
  3731. {
  3732. TheWritableGlobalData->m_debugCamera = !TheGlobalData->m_debugCamera;
  3733. TheInGameUI->message( UnicodeString( L"Debug Camera Mode is %s" ), TheGlobalData->m_debugCamera ? L"On" : L"OFF" );
  3734. disp = DESTROY_MESSAGE;
  3735. break;
  3736. }
  3737. //------------------------------------------------------------------------------- DEMO MESSAGES
  3738. //-----------------------------------------------------------------------------------------
  3739. case GameMessage::MSG_NO_DRAW:
  3740. {
  3741. TheWritableGlobalData->m_noDraw = REAL_TO_INT(pow(2, 32) - 1);
  3742. disp = DESTROY_MESSAGE;
  3743. break;
  3744. }
  3745. //------------------------------------------------------------------------------- DEMO MESSAGES
  3746. //-----------------------------------------------------------------------------------------
  3747. case GameMessage::MSG_META_DEBUG_DUMP_PLAYER_OBJECTS:
  3748. case GameMessage::MSG_META_DEBUG_DUMP_ALL_PLAYER_OBJECTS:
  3749. {
  3750. AsciiString line;
  3751. line.format("*******************************");
  3752. TheScriptEngine->AppendDebugMessage(line, FALSE);
  3753. line.format("Dumping player object counts");
  3754. TheScriptEngine->AppendDebugMessage(line, FALSE);
  3755. for (Int i=0; i<MAX_PLAYER_COUNT; ++i)
  3756. {
  3757. Player *pPlayer = ThePlayerList->getNthPlayer(i);
  3758. if (!pPlayer || !pPlayer->getPlayerTemplate() || !pPlayer->getPlayerTemplate()->isPlayableSide())
  3759. continue;
  3760. Int numObjects = 0;
  3761. pPlayer->iterateObjects( countObjects, &numObjects );
  3762. line.format("Player %d (%ls) has %d non-dead objects", i, pPlayer->getPlayerDisplayName().str(), numObjects);
  3763. TheScriptEngine->AppendDebugMessage(line, FALSE);
  3764. if (numObjects && (numObjects <= 5 || t == GameMessage::MSG_META_DEBUG_DUMP_ALL_PLAYER_OBJECTS))
  3765. {
  3766. line = "Objects are:";
  3767. TheScriptEngine->AppendDebugMessage(line, FALSE);
  3768. pPlayer->iterateObjects( printObjects, NULL );
  3769. }
  3770. }
  3771. disp = DESTROY_MESSAGE;
  3772. break;
  3773. }
  3774. //------------------------------------------------------------------------------- DEMO MESSAGES
  3775. //-----------------------------------------------------------------------------------------
  3776. case GameMessage::MSG_META_DEBUG_TOGGLE_NETWORK:
  3777. {
  3778. if (TheNetwork != NULL) {
  3779. TheNetwork->toggleNetworkOn();
  3780. }
  3781. disp = DESTROY_MESSAGE;
  3782. break;
  3783. }
  3784. //------------------------------------------------------------------------------- DEMO MESSAGES
  3785. //-----------------------------------------------------------------------------------------
  3786. case GameMessage::MSG_META_DEMO_TOGGLE_PARTICLEDEBUG:
  3787. {
  3788. if (TheDisplay->getDebugDisplayCallback() == ParticleSystemDebugDisplay)
  3789. TheDisplay->setDebugDisplayCallback(NULL);
  3790. else
  3791. TheDisplay->setDebugDisplayCallback(ParticleSystemDebugDisplay);
  3792. disp = DESTROY_MESSAGE;
  3793. break;
  3794. }
  3795. //------------------------------------------------------------------------------- DEMO MESSAGES
  3796. //-----------------------------------------------------------------------------------------
  3797. case GameMessage::MSG_META_DEMO_TOGGLE_VISIONDEBUG:
  3798. {
  3799. TheWritableGlobalData->m_debugVisibility = !TheGlobalData->m_debugVisibility;
  3800. TheInGameUI->message( UnicodeString( L"Debug Vision Mode is %s" ), TheGlobalData->m_debugVisibility? L"On" : L"OFF" );
  3801. disp = DESTROY_MESSAGE;
  3802. break;
  3803. }
  3804. //------------------------------------------------------------------------------- DEMO MESSAGES
  3805. //-----------------------------------------------------------------------------------------
  3806. case GameMessage::MSG_META_DEMO_TOGGLE_PROJECTILEDEBUG:
  3807. {
  3808. TheWritableGlobalData->m_debugProjectilePath = !TheGlobalData->m_debugProjectilePath;
  3809. TheInGameUI->message( UnicodeString( L"Debug Projectile Path Mode is %s" ), TheGlobalData->m_debugProjectilePath? L"On" : L"OFF" );
  3810. disp = DESTROY_MESSAGE;
  3811. break;
  3812. }
  3813. //------------------------------------------------------------------------------- DEMO MESSAGES
  3814. //-----------------------------------------------------------------------------------------
  3815. case GameMessage::MSG_META_DEMO_TOGGLE_THREATDEBUG:
  3816. {
  3817. TheWritableGlobalData->m_debugThreatMap = !TheGlobalData->m_debugThreatMap;
  3818. if (TheGlobalData->m_debugThreatMap) {
  3819. TheWritableGlobalData->m_debugCashValueMap = false;
  3820. }
  3821. TheInGameUI->message( UnicodeString( L"Debug Threat Map is %s" ), TheGlobalData->m_debugThreatMap? L"On" : L"OFF" );
  3822. disp = DESTROY_MESSAGE;
  3823. break;
  3824. }
  3825. //------------------------------------------------------------------------------- DEMO MESSAGES
  3826. //-----------------------------------------------------------------------------------------
  3827. case GameMessage::MSG_META_DEMO_TOGGLE_CASHMAPDEBUG:
  3828. {
  3829. TheWritableGlobalData->m_debugCashValueMap = !TheGlobalData->m_debugCashValueMap ;
  3830. if (TheGlobalData->m_debugCashValueMap) {
  3831. TheWritableGlobalData->m_debugThreatMap = false;
  3832. }
  3833. TheInGameUI->message( UnicodeString( L"Debug Cash Value Map is %s" ), TheGlobalData->m_debugCashValueMap? L"On" : L"OFF" );
  3834. disp = DESTROY_MESSAGE;
  3835. break;
  3836. }
  3837. //------------------------------------------------------------------------------- DEMO MESSAGES
  3838. //-----------------------------------------------------------------------------------------
  3839. case GameMessage::MSG_META_DEMO_TOGGLE_GRAPHICALFRAMERATEBAR:
  3840. {
  3841. TheWritableGlobalData->m_debugShowGraphicalFramerate = !TheGlobalData->m_debugShowGraphicalFramerate;
  3842. disp = DESTROY_MESSAGE;
  3843. break;
  3844. }
  3845. //------------------------------------------------------------------------------- DEMO MESSAGES
  3846. //-----------------------------------------------------------------------------------------
  3847. case GameMessage::MSG_META_DEBUG_SHOW_EXTENTS:
  3848. TheWritableGlobalData->m_showCollisionExtents = 1 - TheGlobalData->m_showCollisionExtents;
  3849. TheInGameUI->message( UnicodeString( L"Show Object Extents %s" ),
  3850. TheGlobalData->m_showCollisionExtents ? L"ON" : L"OFF" );
  3851. break;
  3852. //------------------------------------------------------------------------------- DEMO MESSAGES
  3853. //-----------------------------------------------------------------------------------------
  3854. case GameMessage::MSG_META_DEBUG_SHOW_HEALTH:
  3855. {
  3856. TheWritableGlobalData->m_showObjectHealth = 1 - TheGlobalData->m_showObjectHealth;
  3857. TheInGameUI->message( UnicodeString( L"Object Health %s" ),
  3858. TheGlobalData->m_showObjectHealth ? L"ON" : L"OFF" );
  3859. break;
  3860. }
  3861. //------------------------------------------------------------------------------- DEMO MESSAGES
  3862. //-----------------------------------------------------------------------------------------
  3863. case GameMessage::MSG_META_DEMO_PLAY_CAMEO_MOVIE:
  3864. {
  3865. if (TheGameLogic->isInGame())
  3866. {
  3867. if(TheInGameUI->cameoVideoBuffer() == NULL)
  3868. TheInGameUI->playCameoMovie("CameoMovie");
  3869. else
  3870. TheInGameUI->stopCameoMovie();
  3871. }
  3872. disp = DESTROY_MESSAGE;
  3873. break;
  3874. }
  3875. //------------------------------------------------------------------------------- DEMO MESSAGES
  3876. //-----------------------------------------------------------------------------------------
  3877. case GameMessage::MSG_META_DEMO_TOGGLE_ZOOM_LOCK:
  3878. {
  3879. if( TheTacticalView )
  3880. {
  3881. TheTacticalView->setZoomLimited( !TheTacticalView->isZoomLimited() );
  3882. TheInGameUI->message( UnicodeString( L"Camera Zoom Limit: %s" ),
  3883. TheTacticalView->isZoomLimited() ? L"ON" : L"OFF" );
  3884. } // end if
  3885. disp = DESTROY_MESSAGE;
  3886. break;
  3887. }
  3888. //------------------------------------------------------------------------------- DEMO MESSAGES
  3889. //---------------------------------------------------------------------------------------------
  3890. case GameMessage::MSG_META_DEMO_TOGGLE_SPECIAL_POWER_DELAYS:
  3891. {
  3892. if( TheGlobalData )
  3893. {
  3894. TheWritableGlobalData->m_specialPowerUsesDelay = 1 - TheGlobalData->m_specialPowerUsesDelay;
  3895. TheInGameUI->message( UnicodeString( L"Special Power (Superweapon) Delay: %s" ),
  3896. TheGlobalData->m_specialPowerUsesDelay ? L"ON" : L"OFF" );
  3897. } // end if
  3898. disp = DESTROY_MESSAGE;
  3899. break;
  3900. } // end toggle special power delays
  3901. #ifdef ALLOW_SURRENDER
  3902. //------------------------------------------------------------------------------- DEMO MESSAGES
  3903. //---------------------------------------------------------------------------------------------
  3904. case GameMessage::MSG_META_DEMO_TEST_SURRENDER:
  3905. {
  3906. GameMessage* msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_SURRENDER );
  3907. msg->appendObjectIDArgument(INVALID_ID); // zero means "surrender to anyone"
  3908. msg->appendBooleanArgument(true);
  3909. disp = DESTROY_MESSAGE;
  3910. break;
  3911. }
  3912. #endif
  3913. //------------------------------------------------------------------------------- DEMO MESSAGES
  3914. // --------------------------------------------------------------------------------------------
  3915. case GameMessage::MSG_META_DEMO_BATTLE_CRY:
  3916. {
  3917. TheAudio->addAudioEvent(&TheAudio->getMiscAudio()->m_battleCrySound);
  3918. disp = DESTROY_MESSAGE;
  3919. break;
  3920. }
  3921. //------------------------------------------------------------------------------- DEMO MESSAGES
  3922. // --------------------------------------------------------------------------------------------
  3923. case GameMessage::MSG_META_DEMO_TOGGLE_AVI:
  3924. {
  3925. if (TheDisplay)
  3926. TheDisplay->toggleMovieCapture();
  3927. disp = DESTROY_MESSAGE;
  3928. break;
  3929. }
  3930. //------------------------------------------------------------------------------- DEMO MESSAGES
  3931. //-----------------------------------------------------------------------------
  3932. case GameMessage::MSG_META_DEBUG_VTUNE_ON:
  3933. {
  3934. TheScriptEngine->setEnableVTune(true);
  3935. TheInGameUI->message( UnicodeString( L"VTune Gathering is ON" ));
  3936. disp = DESTROY_MESSAGE;
  3937. break;
  3938. }
  3939. //------------------------------------------------------------------------------- DEMO MESSAGES
  3940. // --------------------------------------------------------------------------------------------
  3941. case GameMessage::MSG_META_DEBUG_VTUNE_OFF:
  3942. {
  3943. TheScriptEngine->setEnableVTune(false);
  3944. TheInGameUI->message( UnicodeString( L"VTune Gathering is OFF" ));
  3945. disp = DESTROY_MESSAGE;
  3946. break;
  3947. }
  3948. //------------------------------------------------------------------------------- DEMO MESSAGES
  3949. // --------------------------------------------------------------------------------------------
  3950. case GameMessage::MSG_META_DEBUG_TOGGLE_FEATHER_WATER:
  3951. {
  3952. //TheScriptEngine->setEnableVTune(false);
  3953. //TheInGameUI->message( UnicodeString( L"VTune Gathering is OFF" ));
  3954. --TheWritableGlobalData->m_featherWater;
  3955. if (TheGlobalData->m_featherWater < 0)
  3956. TheWritableGlobalData->m_featherWater = 5;
  3957. disp = DESTROY_MESSAGE;
  3958. break;
  3959. }
  3960. //------------------------------------------------------------------------------- DEMO MESSAGES
  3961. //-----------------------------------------------------------------------------
  3962. case GameMessage::MSG_META_DEBUG_WIN:
  3963. {
  3964. TheScriptEngine->debugVictory();
  3965. TheInGameUI->message( UnicodeString( L"Instant Win" ));
  3966. disp = DESTROY_MESSAGE;
  3967. break;
  3968. }
  3969. //------------------------------------------------------------------------PLAYTEST DEMO MESSAGES
  3970. //-----------------------------------------------------------------------------------------
  3971. case GameMessage::MSG_META_DEMO_TOGGLE_DEBUG_STATS:
  3972. {
  3973. if (TheDisplay->getDebugDisplayCallback() == StatDebugDisplay)
  3974. TheDisplay->setDebugDisplayCallback(NULL);
  3975. else
  3976. TheDisplay->setDebugDisplayCallback(StatDebugDisplay);
  3977. disp = DESTROY_MESSAGE;
  3978. break;
  3979. }
  3980. //--------------------------------------------------------------------------- END DEMO MESSAGES
  3981. //--------------------------------------------------------------------------- END DEMO MESSAGES
  3982. //--------------------------------------------------------------------------- END DEMO MESSAGES
  3983. #endif // #if defined(_DEBUG) || defined(_INTERNAL)
  3984. //------------------------------------------------------------------------PLAYTEST DEMO MESSAGES
  3985. //-----------------------------------------------------------------------------------------
  3986. #if defined(_INTERNAL) || defined(_DEBUG) || defined(_PLAYTEST)
  3987. case GameMessage::MSG_META_DEMO_TOGGLE_AUDIODEBUG:
  3988. {
  3989. if (TheDisplay->getDebugDisplayCallback() == AudioDebugDisplay)
  3990. TheDisplay->setDebugDisplayCallback(NULL);
  3991. else
  3992. TheDisplay->setDebugDisplayCallback(AudioDebugDisplay);
  3993. disp = DESTROY_MESSAGE;
  3994. break;
  3995. }
  3996. #endif//defined(_INTERNAL) || defined(_DEBUG) || defined(_PLAYTEST)
  3997. #ifdef DUMP_PERF_STATS
  3998. //------------------------------------------------------------------------PLAYTEST DEMO MESSAGES
  3999. //-----------------------------------------------------------------------------------------
  4000. case GameMessage::MSG_META_DEMO_PERFORM_STATISTICAL_DUMP:
  4001. //Dump performance statistics for this frame.
  4002. TheWritableGlobalData->m_dumpPerformanceStatistics = TRUE;
  4003. TheInGameUI->message( UnicodeString( L"Statistics dump made on frame: %d" ), TheGameLogic->getFrame() );
  4004. break;
  4005. #endif // DUMP_PERF_STATS
  4006. } // end switch( msg->type )
  4007. return disp;
  4008. } // end CommandTranslator
  4009. static Bool isSystemMessage( const GameMessage *msg )
  4010. {
  4011. if (!msg) {
  4012. return false;
  4013. }
  4014. GameMessage::Type msgType = msg->getType();
  4015. switch (msgType)
  4016. {
  4017. case GameMessage::MSG_DESTROY_SELECTED_GROUP:
  4018. case GameMessage::MSG_LOGIC_CRC:
  4019. case GameMessage::MSG_SET_REPLAY_CAMERA:
  4020. case GameMessage::MSG_FRAME_TICK:
  4021. return TRUE;
  4022. }
  4023. return FALSE;
  4024. }