CommandXlat.cpp 174 KB

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