ScriptActions.cpp 241 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: ScriptActions.cpp /////////////////////////////////////////////////////////////////////////
  24. // The game scripting engine. Interprets scripts.
  25. // Author: John Ahlquist, Nov. 2001
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  28. #include "Common/AudioAffect.h"
  29. #include "Common/AudioHandleSpecialValues.h"
  30. #include "Common/GameAudio.h"
  31. #include "Common/GameEngine.h"
  32. #include "Common/MapObject.h" // For MAP_XY_FACTOR
  33. #include "Common/PartitionSolver.h"
  34. #include "Common/Player.h"
  35. #include "Common/PlayerList.h"
  36. #include "Common/PlayerTemplate.h"
  37. #include "Common/Radar.h" // For TheRadar
  38. #include "Common/SpecialPower.h"
  39. #include "Common/ThingFactory.h"
  40. #include "Common/ThingTemplate.h"
  41. #include "Common/Team.h"
  42. #include "Common/Upgrade.h"
  43. #include "GameClient/Anim2D.h"
  44. #include "GameClient/CampaignManager.h"
  45. #include "GameClient/CommandXlat.h"
  46. #include "GameClient/ControlBar.h"
  47. #include "GameClient/Drawable.h"
  48. #include "GameClient/Eva.h"
  49. #include "GameClient/GadgetStaticText.h"
  50. #include "GameClient/GameClient.h"
  51. #include "GameClient/GameText.h"
  52. #include "GameClient/GUICallbacks.h"
  53. #include "GameClient/InGameUI.h"
  54. #include "GameClient/LookAtXlat.h"
  55. #include "GameClient/MessageBox.h"
  56. #include "GameClient/Mouse.h"
  57. #include "GameClient/View.h"
  58. #include "GameClient/GlobalLanguage.h"
  59. #include "GameLogic/AI.h"
  60. #include "GameLogic/AISkirmishPlayer.h"
  61. #include "GameLogic/Locomotor.h"
  62. #include "GameLogic/Module/AIUpdate.h"
  63. #include "GameLogic/Module/CaveContain.h"
  64. #include "GameLogic/Module/CommandButtonHuntUpdate.h"
  65. #include "GameLogic/Module/ContainModule.h"
  66. #include "GameLogic/Module/DeliverPayloadAIUpdate.h"
  67. #include "GameLogic/Module/SpecialPowerModule.h"
  68. #include "GameLogic/Module/SupplyWarehouseDockUpdate.h"
  69. #include "GameLogic/Module/TransportContain.h"
  70. #include "GameLogic/Module/MobNexusContain.h"
  71. #include "GameLogic/PartitionManager.h"
  72. #include "GameLogic/PolygonTrigger.h"
  73. #include "GameLogic/ScriptActions.h"
  74. #include "GameLogic/ScriptEngine.h"
  75. #include "GameLogic/Weapon.h"
  76. #include "GameLogic/VictoryConditions.h"
  77. #ifdef _INTERNAL
  78. // for occasional debugging...
  79. //#pragma optimize("", off)
  80. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  81. #endif
  82. // Kind of hacky, but we need to dance on the guts of the terrain.
  83. extern void oversizeTheTerrain(Int amount);
  84. //-------------------------------------------------------------------------------------------------
  85. //-------------------------------------------------------------------------------------------------
  86. // when you set controlling player or merge teams, we don't always update all the upgrade stuff
  87. // or the indicator color. this allows us to force the situation. (srj)
  88. static void updateTeamAndPlayerStuff( Object *obj, void *userData )
  89. {
  90. if (obj)
  91. {
  92. obj->updateUpgradeModules();
  93. // srj sez: apparently we have to do this too, since Team::setControllingPlayer
  94. // does not. Might make more sense to do it there, but am scared to at this point.
  95. Drawable* draw = obj->getDrawable();
  96. if (draw)
  97. {
  98. if (TheGlobalData->m_timeOfDay == TIME_OF_DAY_NIGHT)
  99. draw->setIndicatorColor(obj->getNightIndicatorColor());
  100. else
  101. draw->setIndicatorColor(obj->getIndicatorColor());
  102. }
  103. }
  104. }
  105. //-------------------------------------------------------------------------------------------------
  106. //-------------------------------------------------------------------------------------------------
  107. // STATICS ////////////////////////////////////////////////////////////////////////////////////////
  108. // DEFINES ////////////////////////////////////////////////////////////////////////////////////////
  109. #define REALLY_FAR (100000 * MAP_XY_FACTOR)
  110. // GLOBALS ////////////////////////////////////////////////////////////////////////////////////////
  111. ScriptActionsInterface *TheScriptActions = NULL;
  112. GameWindow *ScriptActions::m_messageWindow = NULL;
  113. //-------------------------------------------------------------------------------------------------
  114. //-------------------------------------------------------------------------------------------------
  115. ScriptActions::ScriptActions()
  116. {
  117. m_suppressNewWindows = FALSE;
  118. m_unnamedUnit = AsciiString::TheEmptyString;
  119. } // end ScriptActions
  120. //-------------------------------------------------------------------------------------------------
  121. //-------------------------------------------------------------------------------------------------
  122. ScriptActions::~ScriptActions()
  123. {
  124. reset(); // just in case.
  125. } // end ~ScriptActions
  126. //-------------------------------------------------------------------------------------------------
  127. /** Init */
  128. //-------------------------------------------------------------------------------------------------
  129. void ScriptActions::init( void )
  130. {
  131. reset();
  132. } // end init
  133. //-------------------------------------------------------------------------------------------------
  134. /** Reset */
  135. //-------------------------------------------------------------------------------------------------
  136. void ScriptActions::reset( void )
  137. {
  138. m_suppressNewWindows = FALSE;
  139. closeWindows(FALSE); // Close victory or defeat windows.
  140. } // end reset
  141. //-------------------------------------------------------------------------------------------------
  142. /** Update */
  143. //-------------------------------------------------------------------------------------------------
  144. void ScriptActions::update( void )
  145. {
  146. // Empty for now. jba.
  147. } // end update
  148. //-------------------------------------------------------------------------------------------------
  149. /** closeWindows */
  150. //-------------------------------------------------------------------------------------------------
  151. void ScriptActions::closeWindows( Bool suppressNewWindows )
  152. {
  153. m_suppressNewWindows = suppressNewWindows;
  154. if (m_messageWindow) {
  155. TheWindowManager->winDestroy(m_messageWindow);
  156. m_messageWindow = NULL;
  157. }
  158. }
  159. //-------------------------------------------------------------------------------------------------
  160. /** doQuickVictory */
  161. //-------------------------------------------------------------------------------------------------
  162. void ScriptActions::doQuickVictory( void )
  163. {
  164. closeWindows(FALSE);
  165. TheGameLogic->closeWindows();
  166. doDisableInput();
  167. if(TheCampaignManager)
  168. TheCampaignManager->SetVictorious(TRUE);
  169. TheScriptEngine->startQuickEndGameTimer();
  170. }
  171. //-------------------------------------------------------------------------------------------------
  172. /** doSetInfantryLightingOverride */
  173. //-------------------------------------------------------------------------------------------------
  174. void ScriptActions::doSetInfantryLightingOverride(Real setting)
  175. {
  176. DEBUG_ASSERTCRASH( (setting == -1.0f) || (setting > 0.0f), ("Invalid setting (%d) in Infantry Lighting Override script.", setting) );
  177. TheWritableGlobalData->m_scriptOverrideInfantryLightScale = setting;
  178. }
  179. //-------------------------------------------------------------------------------------------------
  180. /** doVictory */
  181. //-------------------------------------------------------------------------------------------------
  182. void ScriptActions::doVictory( void )
  183. {
  184. closeWindows(FALSE);
  185. TheGameLogic->closeWindows();
  186. doDisableInput();
  187. if (!m_suppressNewWindows)
  188. {
  189. const Player *localPlayer = ThePlayerList->getLocalPlayer();
  190. Bool showObserverWindow = localPlayer->isPlayerObserver() || TheScriptEngine->hasShownMPLocalDefeatWindow();
  191. if(showObserverWindow)
  192. m_messageWindow = TheWindowManager->winCreateFromScript("Menus/ObserverQuit.wnd");
  193. else
  194. {
  195. m_messageWindow = TheWindowManager->winCreateFromScript("Menus/Victorious.wnd");
  196. }
  197. }
  198. if(TheCampaignManager)
  199. TheCampaignManager->SetVictorious(TRUE);
  200. TheScriptEngine->startEndGameTimer();
  201. }
  202. //-------------------------------------------------------------------------------------------------
  203. /** doDefeat */
  204. //-------------------------------------------------------------------------------------------------
  205. void ScriptActions::doDefeat( void )
  206. {
  207. closeWindows(FALSE);
  208. TheGameLogic->closeWindows();
  209. doDisableInput();
  210. if (!m_suppressNewWindows)
  211. {
  212. const Player *localPlayer = ThePlayerList->getLocalPlayer();
  213. Bool showObserverWindow = localPlayer->isPlayerObserver() || TheScriptEngine->hasShownMPLocalDefeatWindow();
  214. if(showObserverWindow)
  215. m_messageWindow = TheWindowManager->winCreateFromScript("Menus/ObserverQuit.wnd");
  216. else
  217. {
  218. m_messageWindow = TheWindowManager->winCreateFromScript("Menus/Defeat.wnd");
  219. }
  220. }
  221. if(TheCampaignManager)
  222. TheCampaignManager->SetVictorious(FALSE);
  223. TheScriptEngine->startEndGameTimer();
  224. }
  225. //-------------------------------------------------------------------------------------------------
  226. /** doLocalDefeat */
  227. //-------------------------------------------------------------------------------------------------
  228. void ScriptActions::doLocalDefeat( void )
  229. {
  230. TheScriptEngine->markMPLocalDefeatWindowShown();
  231. closeWindows(FALSE);
  232. TheGameLogic->closeWindows();
  233. if (!m_suppressNewWindows)
  234. {
  235. if(!TheVictoryConditions->amIObserver())
  236. m_messageWindow = TheWindowManager->winCreateFromScript("Menus/LocalDefeat.wnd");
  237. }
  238. if(TheCampaignManager)
  239. TheCampaignManager->SetVictorious(FALSE);
  240. TheScriptEngine->startCloseWindowTimer();
  241. }
  242. //-------------------------------------------------------------------------------------------------
  243. /** changeObjectPanelFlagForSingleObject */
  244. //-------------------------------------------------------------------------------------------------
  245. void ScriptActions::changeObjectPanelFlagForSingleObject(Object *obj, const AsciiString& flagToChange, Bool newVal )
  246. {
  247. // Enabled flag
  248. if (flagToChange == TheObjectFlagsNames[0])
  249. {
  250. obj->setScriptStatus(OBJECT_STATUS_SCRIPT_DISABLED, !newVal);
  251. return;
  252. }
  253. // Powered flag
  254. if (flagToChange == TheObjectFlagsNames[1])
  255. {
  256. obj->setScriptStatus(OBJECT_STATUS_SCRIPT_UNPOWERED, !newVal);
  257. return;
  258. }
  259. // Indestructible flag
  260. if (flagToChange == TheObjectFlagsNames[2])
  261. {
  262. BodyModuleInterface* body = obj->getBodyModule();
  263. if (body) {
  264. body->setIndestructible(newVal);
  265. }
  266. return;
  267. }
  268. // Unsellable flag
  269. if (flagToChange == TheObjectFlagsNames[3])
  270. {
  271. obj->setScriptStatus(OBJECT_STATUS_SCRIPT_UNSELLABLE, newVal);
  272. return;
  273. }
  274. // Selectable flag
  275. if (flagToChange == TheObjectFlagsNames[4])
  276. {
  277. if (obj->isSelectable() != newVal) {
  278. obj->setSelectable(newVal);
  279. }
  280. return;
  281. }
  282. // AI Recruitable flag
  283. if (flagToChange == TheObjectFlagsNames[5])
  284. {
  285. if (obj->getAIUpdateInterface()) {
  286. obj->getAIUpdateInterface()->setIsRecruitable(newVal);
  287. }
  288. return;
  289. }
  290. // Player targetable flag
  291. if( flagToChange == TheObjectFlagsNames[6] )
  292. {
  293. obj->setScriptStatus( OBJECT_STATUS_SCRIPT_TARGETABLE, newVal );
  294. return;
  295. }
  296. }
  297. //-------------------------------------------------------------------------------------------------
  298. /** doDebugMessage */
  299. //-------------------------------------------------------------------------------------------------
  300. void ScriptActions::doDebugMessage(const AsciiString& msg, Bool pause )
  301. {
  302. TheScriptEngine->AppendDebugMessage(msg, pause);
  303. }
  304. //-------------------------------------------------------------------------------------------------
  305. /** doPlaySoundEffect */
  306. //-------------------------------------------------------------------------------------------------
  307. void ScriptActions::doPlaySoundEffect(const AsciiString& sound)
  308. {
  309. AudioEventRTS audioEvent(sound);
  310. audioEvent.setIsLogicalAudio(true);
  311. audioEvent.setPlayerIndex(ThePlayerList->getLocalPlayer()->getPlayerIndex());
  312. TheAudio->addAudioEvent( &audioEvent );
  313. }
  314. //-------------------------------------------------------------------------------------------------
  315. /** doPlaySoundEffectAt */
  316. //-------------------------------------------------------------------------------------------------
  317. void ScriptActions::doPlaySoundEffectAt(const AsciiString& sound, const AsciiString& waypoint)
  318. {
  319. Waypoint *way = TheTerrainLogic->getWaypointByName(waypoint);
  320. if (!way) {
  321. return;
  322. }
  323. AudioEventRTS audioEvent(sound, way->getLocation());
  324. audioEvent.setIsLogicalAudio(true);
  325. audioEvent.setPlayerIndex(ThePlayerList->getLocalPlayer()->getPlayerIndex());
  326. TheAudio->addAudioEvent( &audioEvent );
  327. }
  328. //-------------------------------------------------------------------------------------------------
  329. /** doDamageTeamMembers */
  330. //-------------------------------------------------------------------------------------------------
  331. void ScriptActions::doDamageTeamMembers(const AsciiString& team, Real amount)
  332. {
  333. Team *theTeam = TheScriptEngine->getTeamNamed( team );
  334. // The team is the team based on the name, and the calling team (if any) and the team that
  335. // triggered the condition. jba. :)
  336. if (theTeam) {
  337. theTeam->damageTeamMembers(amount);
  338. }
  339. }
  340. //-------------------------------------------------------------------------------------------------
  341. /** doMoveToWaypoint */
  342. //-------------------------------------------------------------------------------------------------
  343. void ScriptActions::doMoveToWaypoint(const AsciiString& team, const AsciiString& waypoint)
  344. {
  345. Team *theTeam = TheScriptEngine->getTeamNamed( team );
  346. // The team is the team based on the name, and the calling team (if any) and the team that
  347. // triggered the condition. jba. :)
  348. if (theTeam) {
  349. AIGroup* theGroup = TheAI->createGroup();
  350. if (!theGroup) {
  351. return;
  352. }
  353. theTeam->getTeamAsAIGroup(theGroup);
  354. Waypoint *way = TheTerrainLogic->getWaypointByName(waypoint);
  355. if (way) {
  356. Coord3D destination = *way->getLocation();
  357. //DEBUG_LOG(("Moving team to waypoint %f, %f, %f\n", destination.x, destination.y, destination.z));
  358. theGroup->groupMoveToPosition( &destination, false, CMD_FROM_SCRIPT );
  359. }
  360. }
  361. }
  362. //-------------------------------------------------------------------------------------------------
  363. /** doNamedMoveToWaypoint */
  364. //-------------------------------------------------------------------------------------------------
  365. void ScriptActions::doNamedMoveToWaypoint(const AsciiString& unit, const AsciiString& waypoint)
  366. {
  367. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  368. if (theObj)
  369. {
  370. Waypoint *way = TheTerrainLogic->getWaypointByName(waypoint);
  371. if (!way) {
  372. return;
  373. }
  374. Coord3D destination = *way->getLocation();
  375. AIUpdateInterface *aiUpdate = theObj->getAIUpdateInterface();
  376. if (!aiUpdate) {
  377. return;
  378. }
  379. aiUpdate->clearWaypointQueue();
  380. theObj->leaveGroup();
  381. aiUpdate->chooseLocomotorSet( LOCOMOTORSET_NORMAL );
  382. aiUpdate->aiMoveToPosition( &destination, CMD_FROM_SCRIPT );
  383. }
  384. }
  385. //-------------------------------------------------------------------------------------------------
  386. /** doCameraFollowNamed */
  387. //-------------------------------------------------------------------------------------------------
  388. void ScriptActions::doCameraFollowNamed(const AsciiString& unit, Bool snapToUnit)
  389. {
  390. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  391. if (theObj)
  392. {
  393. TheTacticalView->setCameraLock(theObj->getID());
  394. if (snapToUnit)
  395. TheTacticalView->snapToCameraLock();
  396. TheTacticalView->setSnapMode( View::LOCK_FOLLOW, 0.0f );
  397. }
  398. }
  399. //-------------------------------------------------------------------------------------------------
  400. /** doStopCameraFollowUnit */
  401. //-------------------------------------------------------------------------------------------------
  402. void ScriptActions::doStopCameraFollowUnit(void)
  403. {
  404. TheTacticalView->setCameraLock(INVALID_ID);
  405. }
  406. //-------------------------------------------------------------------------------------------------
  407. /** doSetTeamState */
  408. //-------------------------------------------------------------------------------------------------
  409. void ScriptActions::doSetTeamState(const AsciiString& team, const AsciiString& state)
  410. {
  411. Team *theTeam = TheScriptEngine->getTeamNamed( team );
  412. // The team is the team based on the name, and the calling team (if any) and the team that
  413. // triggered the condition. jba. :)
  414. if (theTeam) {
  415. theTeam->setState(state);
  416. }
  417. }
  418. /** doCreateReinforcements */
  419. //-------------------------------------------------------------------------------------------------
  420. void ScriptActions::doCreateReinforcements(const AsciiString& team, const AsciiString& waypoint)
  421. {
  422. TeamPrototype *theTeamProto = TheTeamFactory->findTeamPrototype( team );
  423. Coord3D destination;
  424. Bool needToMoveToDestination = false;
  425. //Validate the waypoint
  426. Waypoint *way = TheTerrainLogic->getWaypointByName(waypoint);
  427. if (way==NULL)
  428. {
  429. return;
  430. }
  431. destination = *way->getLocation();
  432. if (!theTeamProto) {
  433. DEBUG_LOG(("***WARNING - Team %s not found.\n", team));
  434. return;
  435. }
  436. const TeamTemplateInfo *pInfo = theTeamProto->getTemplateInfo();
  437. Coord3D origin = destination;
  438. way = TheTerrainLogic->getWaypointByName(pInfo->m_startReinforceWaypoint);
  439. if (way) {
  440. origin = *way->getLocation();
  441. if (origin.x != destination.x || origin.y != destination.y) {
  442. needToMoveToDestination = true;
  443. }
  444. }
  445. //Create the team (not the units inside team).
  446. Team *theTeam = TheTeamFactory->createInactiveTeam( team );
  447. if (theTeam==NULL) {
  448. return;
  449. }
  450. const ThingTemplate *transportTemplate;
  451. const ThingTemplate *unitTemplate;
  452. //Create the transport first (if applicable), so we can determine if it has paradrop capabilities.
  453. //If so, we'll be doing a lot of things differently!
  454. Object *transport=NULL;
  455. ContainModuleInterface *contain = NULL;
  456. transportTemplate = TheThingFactory->findTemplate( pInfo->m_transportUnitType );
  457. if( transportTemplate )
  458. {
  459. transport = TheThingFactory->newObject( transportTemplate, theTeam );
  460. transport->setPosition( &origin );
  461. transport->setOrientation( 0.0f );
  462. if( transport )
  463. {
  464. contain = transport->getContain();
  465. }
  466. }
  467. Int transportCount = 1;
  468. //Check to see if we have a transport, and if our transport has paradrop capabilities. If this is the
  469. //case, we'll need to create each unit inside "parachute containers".
  470. static NameKeyType key_DeliverPayloadAIUpdate = NAMEKEY("DeliverPayloadAIUpdate");
  471. DeliverPayloadAIUpdate *dp = NULL;
  472. if( transport )
  473. {
  474. dp = (DeliverPayloadAIUpdate*)transport->findUpdateModule(key_DeliverPayloadAIUpdate);
  475. }
  476. //Our tranport has a deliverPayload update module. This means it'll do airborned drops.
  477. const ThingTemplate* putInContainerTemplate = NULL;
  478. if( dp )
  479. {
  480. //Check to see if we are packaging our units
  481. putInContainerTemplate = dp->getPutInContainerTemplateViaModuleData();
  482. }
  483. //Now create the units that make up the team.
  484. Int i, j;
  485. for (i=0; i<pInfo->m_numUnitsInfo; i++)
  486. {
  487. // get thing template based from map object name
  488. unitTemplate = TheThingFactory->findTemplate(pInfo->m_unitsInfo[i].unitThingName);
  489. Coord3D pos = origin;
  490. if (unitTemplate && theTeam)
  491. {
  492. Object *obj = NULL;
  493. for (j=0; j<pInfo->m_unitsInfo[i].maxUnits; j++)
  494. {
  495. // create new object in the world
  496. obj = TheThingFactory->newObject( unitTemplate, theTeam );
  497. if( obj )
  498. {
  499. /// @todo - have better positioning for reinforcement units.
  500. pos.x = origin.x + 2.25*(j)*obj->getGeometryInfo().getMajorRadius();
  501. pos.z = TheTerrainLogic->getGroundHeight(pos.x, pos.y);
  502. obj->setPosition( &pos );
  503. obj->setOrientation(0.0f);
  504. } // end if
  505. }
  506. if (obj) pos.y += 2*obj->getGeometryInfo().getMajorRadius();
  507. }
  508. origin.y = pos.y;
  509. }
  510. origin = destination;
  511. if (pInfo->m_teamStartsFull)
  512. {
  513. // Have them load into transports in the team.
  514. EntriesVec vecOfUnits;
  515. SpacesVec vecOfTransports;
  516. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance())
  517. {
  518. Object *obj = iter.cur();
  519. if (!obj) {
  520. continue;
  521. }
  522. if (obj==transport) {
  523. continue; // Skip the one we created. The team loads into the transports on the team for team starts full. jba
  524. }
  525. if (obj->isKindOf(KINDOF_TRANSPORT))
  526. {
  527. ContainModuleInterface *contain = obj->getContain();
  528. if( contain )
  529. {
  530. vecOfTransports.push_back(std::make_pair(obj->getID(), ((TransportContain*)contain)->getContainMax()));
  531. }
  532. else
  533. {
  534. DEBUG_CRASH( ("doCreateReinforcement script -- transport doesn't have contain to hold guys.") );
  535. }
  536. }
  537. else
  538. {
  539. Int slots = obj->getTransportSlotCount();
  540. if (slots==0) slots = 0x7fffff; // 0 means lots.
  541. vecOfUnits.push_back(std::make_pair(obj->getID(), slots));
  542. }
  543. }
  544. // we've now built the necessary stuff. Partition the units.
  545. PartitionSolver partition(vecOfUnits, vecOfTransports, PREFER_FAST_SOLUTION);
  546. partition.solve();
  547. SolutionVec solution = partition.getSolution();
  548. for (int i = 0; i < solution.size(); ++i) {
  549. Object *unit = TheGameLogic->findObjectByID(solution[i].first);
  550. Object *trans = TheGameLogic->findObjectByID(solution[i].second);
  551. if (!unit || !trans) {
  552. continue;
  553. }
  554. ContainModuleInterface *contain = trans->getContain();
  555. if (contain)
  556. {
  557. contain->addToContain(unit);
  558. }
  559. }
  560. }
  561. contain = NULL;
  562. if( transport )
  563. {
  564. contain = transport->getContain();
  565. }
  566. if (contain)
  567. {
  568. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance())
  569. {
  570. Object *obj = iter.cur();
  571. if (!obj)
  572. {
  573. continue;
  574. }
  575. if (obj->getTemplate()->isEquivalentTo(transport->getTemplate()) )
  576. {
  577. // it's our transport.
  578. continue;
  579. }
  580. if (obj->getContainedBy() != NULL)
  581. {
  582. continue;
  583. }
  584. //Check to see if it's a valid transport for this unit, even if it's full.
  585. Coord3D pos = origin;
  586. pos.x += transportCount*transport->getGeometryInfo().getMajorRadius();
  587. pos.z = TheTerrainLogic->getGroundHeight(pos.x, pos.y);
  588. if (contain && contain->isValidContainerFor(obj, false))
  589. {
  590. //Now that we know it fits in the transport, check to see if it's full. If it is,
  591. //then we'll create a new transport.
  592. if (!contain->isValidContainerFor(obj, true))
  593. {
  594. // full, try building another.
  595. transport = TheThingFactory->newObject( transportTemplate, theTeam );
  596. transport->setPosition( &pos );
  597. transportCount++;
  598. transport->setOrientation(0.0f);
  599. if (transport)
  600. {
  601. contain = transport->getContain();
  602. }
  603. }
  604. //If our unit is going to be put in another container (such as infantry being contained by a parachute)
  605. //do so now.
  606. if( putInContainerTemplate )
  607. {
  608. Object* container = TheThingFactory->newObject( putInContainerTemplate, theTeam );
  609. container->setPosition( &pos );
  610. //Make sure this is valid.
  611. if( container->getContain() && container->getContain()->isValidContainerFor( obj, true ) )
  612. {
  613. container->getContain()->addToContain( obj );
  614. obj = container;
  615. }
  616. else
  617. {
  618. DEBUG_CRASH( ("doCreateReinforcements: PutInContainer %s is full, or not valid for the payload %s!", putInContainerTemplate->getName().str(), obj->getTemplate()->getName().str() ) );
  619. }
  620. }
  621. //Add our unit to the transport.
  622. contain->addToContain( obj );
  623. }
  624. }
  625. }
  626. if (theTeam)
  627. {
  628. if (transport)
  629. {
  630. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance())
  631. {
  632. Object *obj = iter.cur();
  633. if (!obj)
  634. {
  635. continue;
  636. }
  637. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  638. if (obj->getTemplate()->isEquivalentTo(transport->getTemplate()) )
  639. {
  640. if( dp )
  641. {
  642. dp->deliverPayloadViaModuleData( &destination );
  643. }
  644. // it's our transport.
  645. else if( pInfo->m_transportsExit )
  646. {
  647. if( ai )
  648. {
  649. ai->chooseLocomotorSet( LOCOMOTORSET_NORMAL );
  650. ai->aiMoveToAndEvacuateAndExit(&destination, CMD_FROM_SCRIPT);
  651. }
  652. }
  653. else
  654. {
  655. if( ai )
  656. {
  657. ai->chooseLocomotorSet( LOCOMOTORSET_NORMAL );
  658. ai->aiMoveToAndEvacuate( &destination, CMD_FROM_SCRIPT );
  659. }
  660. }
  661. }
  662. else
  663. {
  664. // If there are any units that aren't transportable, move them to the goal.
  665. if( !obj->isDisabledByType( DISABLED_HELD ) )
  666. {
  667. if( ai )
  668. {
  669. ai->chooseLocomotorSet( LOCOMOTORSET_NORMAL );
  670. ai->aiMoveToPosition(&destination, CMD_FROM_SCRIPT);
  671. }
  672. }
  673. }
  674. }
  675. }
  676. else
  677. {
  678. theTeam->setActive();
  679. if (needToMoveToDestination)
  680. {
  681. AIGroup* theGroup = TheAI->createGroup();
  682. if (!theGroup)
  683. {
  684. return;
  685. }
  686. theTeam->getTeamAsAIGroup(theGroup);
  687. theGroup->groupMoveToPosition( &destination, false, CMD_FROM_SCRIPT );
  688. }
  689. }
  690. }
  691. }
  692. //-------------------------------------------------------------------------------------------------
  693. /** doMoveCameraTo */
  694. //-------------------------------------------------------------------------------------------------
  695. void ScriptActions::doMoveCameraTo(const AsciiString& waypoint, Real sec, Real cameraStutterSec)
  696. {
  697. for (Waypoint *way = TheTerrainLogic->getFirstWaypoint(); way; way = way->getNext()) {
  698. if (way->getName() == waypoint) {
  699. Coord3D destination = *way->getLocation();
  700. TheTacticalView->moveCameraTo(&destination, sec*1000, cameraStutterSec*1000, true);
  701. break;
  702. }
  703. }
  704. }
  705. //-------------------------------------------------------------------------------------------------
  706. /** doZoomCamera */
  707. //-------------------------------------------------------------------------------------------------
  708. void ScriptActions::doZoomCamera( Real zoom, Real sec)
  709. {
  710. TheTacticalView->zoomCamera(zoom, sec * 1000);
  711. }
  712. //-------------------------------------------------------------------------------------------------
  713. /** doPitchCamera */
  714. //-------------------------------------------------------------------------------------------------
  715. void ScriptActions::doPitchCamera(Real pitch, Real sec)
  716. {
  717. TheTacticalView->pitchCamera(pitch, sec * 1000);
  718. }
  719. //-------------------------------------------------------------------------------------------------
  720. /** doOversizeTheTerrain */
  721. //-------------------------------------------------------------------------------------------------
  722. void ScriptActions::doOversizeTheTerrain(Int amount)
  723. {
  724. oversizeTheTerrain(amount);
  725. Coord2D offset;
  726. offset.x = 0.0001f;
  727. offset.y = 0.0001f;
  728. TheTacticalView->scrollBy(&offset);
  729. offset.x = -0.0001f;
  730. offset.y = -0.0001f;
  731. TheTacticalView->scrollBy(&offset);
  732. }
  733. //-------------------------------------------------------------------------------------------------
  734. /** doSetupCamera */
  735. //-------------------------------------------------------------------------------------------------
  736. void ScriptActions::doSetupCamera(const AsciiString& waypoint, Real zoom, Real pitch, const AsciiString& lookAtWaypoint)
  737. {
  738. Waypoint *way = TheTerrainLogic->getWaypointByName(waypoint);
  739. if (way==NULL) return;
  740. Coord3D pos = *way->getLocation();
  741. Waypoint *lookat = TheTerrainLogic->getWaypointByName(lookAtWaypoint);
  742. if (lookat==NULL) return;
  743. Coord3D destination = *lookat->getLocation();
  744. TheTacticalView->moveCameraTo(&pos, 0, 0, true);
  745. TheTacticalView->cameraModLookToward(&destination);
  746. TheTacticalView->cameraModFinalPitch(pitch);
  747. TheTacticalView->cameraModFinalZoom(zoom);
  748. }
  749. //-------------------------------------------------------------------------------------------------
  750. /** doModCameraLookToward */
  751. //-------------------------------------------------------------------------------------------------
  752. void ScriptActions::doModCameraLookToward(const AsciiString& waypoint)
  753. {
  754. for (Waypoint *way = TheTerrainLogic->getFirstWaypoint(); way; way = way->getNext()) {
  755. if (way->getName() == waypoint) {
  756. Coord3D destination = *way->getLocation();
  757. TheTacticalView->cameraModLookToward(&destination);
  758. break;
  759. }
  760. }
  761. }
  762. //-------------------------------------------------------------------------------------------------
  763. /** doModCameraFinalLookToward */
  764. //-------------------------------------------------------------------------------------------------
  765. void ScriptActions::doModCameraFinalLookToward(const AsciiString& waypoint)
  766. {
  767. for (Waypoint *way = TheTerrainLogic->getFirstWaypoint(); way; way = way->getNext()) {
  768. if (way->getName() == waypoint) {
  769. Coord3D destination = *way->getLocation();
  770. TheTacticalView->cameraModFinalLookToward(&destination);
  771. break;
  772. }
  773. }
  774. }
  775. //-------------------------------------------------------------------------------------------------
  776. /** doModCameraMoveToSelection */
  777. //-------------------------------------------------------------------------------------------------
  778. void ScriptActions::doModCameraMoveToSelection(void)
  779. {
  780. Int count=0;
  781. Coord3D destination;
  782. destination.x=destination.y=destination.z = 0;
  783. for (Drawable *d = TheGameClient->firstDrawable(); d; d = d->getNextDrawable())
  784. {
  785. if (d->isSelected())
  786. {
  787. Coord3D pos = *d->getPosition();
  788. destination.x += pos.x;
  789. destination.y += pos.y;
  790. destination.z += pos.z;
  791. count++;
  792. }
  793. }
  794. if (count) {
  795. destination.z /= count;
  796. destination.x /= count;
  797. destination.y /= count;
  798. TheTacticalView->cameraModFinalMoveTo(&destination);
  799. }
  800. }
  801. //-------------------------------------------------------------------------------------------------
  802. /** doResetCamera */
  803. //-------------------------------------------------------------------------------------------------
  804. void ScriptActions::doResetCamera(const AsciiString& waypoint, Real sec)
  805. {
  806. for (Waypoint *way = TheTerrainLogic->getFirstWaypoint(); way; way = way->getNext()) {
  807. if (way->getName() == waypoint) {
  808. Coord3D destination = *way->getLocation();
  809. TheTacticalView->resetCamera(&destination, sec*1000);
  810. break;
  811. }
  812. }
  813. }
  814. //-------------------------------------------------------------------------------------------------
  815. /** doRotateCamera */
  816. //-------------------------------------------------------------------------------------------------
  817. void ScriptActions::doRotateCamera(Real rotations, Real sec)
  818. {
  819. TheTacticalView->rotateCamera(rotations, sec*1000);
  820. }
  821. //-------------------------------------------------------------------------------------------------
  822. /** doRotateCameraTowardObject */
  823. //-------------------------------------------------------------------------------------------------
  824. void ScriptActions::doRotateCameraTowardObject(const AsciiString& unitName, Real sec, Real holdSec)
  825. {
  826. const Object *unit = TheScriptEngine->getUnitNamed(unitName);
  827. if (!unit)
  828. return;
  829. TheTacticalView->rotateCameraTowardObject(unit->getID(), sec*1000, holdSec*1000);
  830. }
  831. //-------------------------------------------------------------------------------------------------
  832. /** doRotateCameraTowardWaypoint */
  833. //-------------------------------------------------------------------------------------------------
  834. void ScriptActions::doRotateCameraTowardWaypoint(const AsciiString& waypointName, Real sec)
  835. {
  836. Waypoint *way = TheTerrainLogic->getWaypointByName(waypointName);
  837. if (way==NULL) return;
  838. TheTacticalView->rotateCameraTowardPosition(way->getLocation(), sec*1000);
  839. }
  840. //-------------------------------------------------------------------------------------------------
  841. /** doMoveAlongWaypointPath */
  842. //-------------------------------------------------------------------------------------------------
  843. void ScriptActions::doMoveCameraAlongWaypointPath(const AsciiString& waypoint, Real sec, Real cameraStutterSec)
  844. {
  845. for (Waypoint *way = TheTerrainLogic->getFirstWaypoint(); way; way = way->getNext()) {
  846. if (way->getName() == waypoint) {
  847. TheTacticalView->moveCameraAlongWaypointPath(way, sec*1000, cameraStutterSec*1000, true);
  848. break;
  849. }
  850. }
  851. }
  852. //-------------------------------------------------------------------------------------------------
  853. /** doCreateObject */
  854. //-------------------------------------------------------------------------------------------------
  855. void ScriptActions::doCreateObject(const AsciiString& objectName, const AsciiString& thingName, const AsciiString& teamName, Coord3D *pos, Real angle )
  856. {
  857. Object* pOldObj = NULL;
  858. if (objectName != m_unnamedUnit) {
  859. pOldObj = TheScriptEngine->getUnitNamed(objectName);
  860. if (pOldObj && !pOldObj->isEffectivelyDead()) {
  861. AsciiString str = "WARNING - Object with name ";
  862. str.concat(objectName);
  863. str.concat(" already exists. Failed Create.");
  864. TheScriptEngine->AppendDebugMessage(str, false);
  865. // Unit by that name already exists
  866. return;
  867. }
  868. }
  869. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  870. // The team is the team based on the name, and the calling team (if any) and the team that
  871. // triggered the condition. jba. :)
  872. if (theTeam==NULL) {
  873. // We may need to create the team.
  874. theTeam = TheTeamFactory->createTeam( teamName );
  875. }
  876. if (!theTeam) {
  877. TheScriptEngine->AppendDebugMessage("***WARNING - Team not found:***", false);
  878. TheScriptEngine->AppendDebugMessage(teamName, true);
  879. DEBUG_LOG(("WARNING - Team %s not found.\n", teamName.str()));
  880. return;
  881. }
  882. const ThingTemplate *thingTemplate;
  883. // get thing template based from map object name
  884. thingTemplate = TheThingFactory->findTemplate(thingName);
  885. if (thingTemplate) {
  886. // create new object in the world
  887. Object *obj = TheThingFactory->newObject( thingTemplate, theTeam );
  888. if( obj )
  889. {
  890. if (objectName != m_unnamedUnit) {
  891. obj->setName(objectName);
  892. if (pOldObj || TheScriptEngine->didUnitExist(objectName)) {
  893. TheScriptEngine->transferObjectName(objectName, obj);
  894. } else {
  895. TheScriptEngine->addObjectToCache(obj);
  896. }
  897. }
  898. obj->setOrientation(angle);
  899. obj->setPosition( pos );
  900. } // end if
  901. } else {
  902. DEBUG_LOG(("WARNING - ThingTemplate '%s' not found.\n", thingName.str()));
  903. }
  904. }
  905. //-------------------------------------------------------------------------------------------------
  906. /** doAttack */
  907. //-------------------------------------------------------------------------------------------------
  908. void ScriptActions::doAttack(const AsciiString& attackerName, const AsciiString& victimName)
  909. {
  910. Team *attackingTeam = TheScriptEngine->getTeamNamed( attackerName );
  911. // The team is the team based on the name, and the calling team (if any) and the team that
  912. // triggered the condition. jba. :)
  913. const Team *victimTeam = TheScriptEngine->getTeamNamed( victimName );
  914. // sanity
  915. if( attackingTeam == NULL || victimTeam == NULL )
  916. return;
  917. AIGroup *aiGroup = TheAI->createGroup();
  918. if (!aiGroup) {
  919. return;
  920. }
  921. attackingTeam->getTeamAsAIGroup(aiGroup);
  922. aiGroup->groupAttackTeam(victimTeam, NO_MAX_SHOTS_LIMIT, CMD_FROM_SCRIPT);
  923. }
  924. //-------------------------------------------------------------------------------------------------
  925. /** doNamedAttack */
  926. //-------------------------------------------------------------------------------------------------
  927. void ScriptActions::doNamedAttack(const AsciiString& attackerName, const AsciiString& victimName)
  928. {
  929. /// @todo Implement me (MSB)
  930. Object *attackingObj = TheScriptEngine->getUnitNamed( attackerName );
  931. Object *victimObj = TheScriptEngine->getUnitNamed( victimName );
  932. if (!attackingObj || !victimObj) {
  933. return;
  934. }
  935. // tell every member of attacking team to attack a random member of victim team
  936. {
  937. AIUpdateInterface *aiUpdate = attackingObj->getAIUpdateInterface();
  938. if (aiUpdate)
  939. {
  940. /// @todo Teams should have a method that returns the number of members in the team (MSB)
  941. attackingObj->leaveGroup();
  942. aiUpdate->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  943. aiUpdate->aiForceAttackObject( victimObj, NO_MAX_SHOTS_LIMIT, CMD_FROM_SCRIPT );
  944. }
  945. }
  946. }
  947. //-------------------------------------------------------------------------------------------------
  948. /** doBuildBuilding */
  949. //-------------------------------------------------------------------------------------------------
  950. void ScriptActions::doBuildBuilding(const AsciiString& buildingType)
  951. {
  952. // This action ALWAYS occur on the current player.
  953. Player *thePlayer = TheScriptEngine->getCurrentPlayer();
  954. if (thePlayer) {
  955. thePlayer->buildSpecificBuilding(buildingType);
  956. }
  957. }
  958. //-------------------------------------------------------------------------------------------------
  959. /** doBuildSupplyCenter */
  960. //-------------------------------------------------------------------------------------------------
  961. void ScriptActions::doBuildSupplyCenter(const AsciiString& player, const AsciiString& buildingType, Int cash)
  962. {
  963. Player* thePlayer = TheScriptEngine->getPlayerFromAsciiString(player);
  964. if (thePlayer) {
  965. thePlayer->buildBySupplies(cash, buildingType);
  966. }
  967. }
  968. //-------------------------------------------------------------------------------------------------
  969. /** doBuildUpgrade */
  970. //-------------------------------------------------------------------------------------------------
  971. void ScriptActions::doBuildUpgrade(const AsciiString& player, const AsciiString& upgrade)
  972. {
  973. Player* thePlayer = TheScriptEngine->getPlayerFromAsciiString(player);
  974. if (thePlayer) {
  975. thePlayer->buildUpgrade(upgrade);
  976. }
  977. }
  978. //-------------------------------------------------------------------------------------------------
  979. /** doBuildBaseDefense */
  980. //-------------------------------------------------------------------------------------------------
  981. void ScriptActions::doBuildBaseDefense(Bool flank)
  982. {
  983. // This action ALWAYS occur on the current player.
  984. Player *thePlayer = TheScriptEngine->getCurrentPlayer();
  985. if (thePlayer) {
  986. thePlayer->buildBaseDefense(flank);
  987. }
  988. }
  989. //-------------------------------------------------------------------------------------------------
  990. /** doBuildBuilding */
  991. //-------------------------------------------------------------------------------------------------
  992. void ScriptActions::doBuildBaseStructure(const AsciiString& buildingType, Bool flank)
  993. {
  994. // This action ALWAYS occur on the current player.
  995. Player *thePlayer = TheScriptEngine->getCurrentPlayer();
  996. if (thePlayer) {
  997. thePlayer->buildBaseDefenseStructure(buildingType, flank);
  998. }
  999. }
  1000. //-------------------------------------------------------------------------------------------------
  1001. /** createUnitOnTeamAt */
  1002. //-------------------------------------------------------------------------------------------------
  1003. void ScriptActions::createUnitOnTeamAt(const AsciiString& unitName, const AsciiString& objType, const AsciiString& teamName, const AsciiString& waypoint)
  1004. {
  1005. Object* pOldObj = TheScriptEngine->getUnitNamed(unitName);
  1006. if (pOldObj && !pOldObj->isEffectivelyDead()) {
  1007. AsciiString str = "WARNING - Object with name ";
  1008. str.concat(unitName);
  1009. str.concat(" already exists. Failed Create.");
  1010. TheScriptEngine->AppendDebugMessage(str, false);
  1011. // Unit by that name already exists
  1012. return;
  1013. }
  1014. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1015. // The team is the team based on the name, and the calling team (if any) and the team that
  1016. // triggered the condition. jba. :)
  1017. if (theTeam==NULL) {
  1018. // We may need to create the team.
  1019. theTeam = TheTeamFactory->createTeam( teamName );
  1020. }
  1021. if (!theTeam) {
  1022. TheScriptEngine->AppendDebugMessage("***WARNING - Team not found:***", false);
  1023. TheScriptEngine->AppendDebugMessage(teamName, true);
  1024. DEBUG_LOG(("WARNING - Team %s not found.\n", teamName.str()));
  1025. return;
  1026. }
  1027. const ThingTemplate *thingTemplate;
  1028. // get thing template based from map object name
  1029. thingTemplate = TheThingFactory->findTemplate(objType);
  1030. if (thingTemplate) {
  1031. // create new object in the world
  1032. Object *obj = TheThingFactory->newObject( thingTemplate, theTeam );
  1033. if( obj )
  1034. {
  1035. if (unitName != m_unnamedUnit) {
  1036. obj->setName(unitName);
  1037. if (pOldObj || TheScriptEngine->didUnitExist(unitName)) {
  1038. TheScriptEngine->transferObjectName(unitName, obj);
  1039. } else {
  1040. TheScriptEngine->addObjectToCache(obj);
  1041. }
  1042. }
  1043. Waypoint *way = TheTerrainLogic->getWaypointByName( waypoint );
  1044. if (way)
  1045. {
  1046. Coord3D destination = *way->getLocation();
  1047. obj->setPosition(&destination);
  1048. }
  1049. } // end if
  1050. } else {
  1051. DEBUG_LOG(("WARNING - ThingTemplate '%s' not found.\n", objType.str()));
  1052. }
  1053. }
  1054. //-------------------------------------------------------------------------------------------------
  1055. /** updateNamedAttackPrioritySet */
  1056. //-------------------------------------------------------------------------------------------------
  1057. void ScriptActions::updateNamedAttackPrioritySet(const AsciiString& unitName, const AsciiString& attackPrioritySet)
  1058. {
  1059. Object *theSrcUnit = TheScriptEngine->getUnitNamed(unitName);
  1060. if (!theSrcUnit) {
  1061. return;
  1062. }
  1063. AIUpdateInterface *pInterface = theSrcUnit->getAIUpdateInterface();
  1064. if (!pInterface) {
  1065. return;
  1066. }
  1067. const AttackPriorityInfo *info = TheScriptEngine->getAttackInfo(attackPrioritySet);
  1068. pInterface->setAttackInfo(info);
  1069. }
  1070. //-------------------------------------------------------------------------------------------------
  1071. /** updateTeamAttackPrioritySet */
  1072. //-------------------------------------------------------------------------------------------------
  1073. void ScriptActions::updateTeamAttackPrioritySet(const AsciiString& teamName, const AsciiString& attackPrioritySet)
  1074. {
  1075. Team *team = TheScriptEngine->getTeamNamed(teamName);
  1076. if (!team) {
  1077. return;
  1078. }
  1079. const AttackPriorityInfo *info = TheScriptEngine->getAttackInfo(attackPrioritySet);
  1080. if (info->getName().isNotEmpty()) {
  1081. team->setAttackPriorityName(info->getName());
  1082. }
  1083. // Set team member's attack priority.
  1084. for (DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance())
  1085. {
  1086. Object *obj = iter.cur();
  1087. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  1088. if (!ai) {
  1089. continue;
  1090. }
  1091. ai->setAttackInfo(info);
  1092. }
  1093. }
  1094. //-------------------------------------------------------------------------------------------------
  1095. /** updateBaseConstructionSpeed */
  1096. //-------------------------------------------------------------------------------------------------
  1097. void ScriptActions::updateBaseConstructionSpeed(const AsciiString& playerName, Int delayInSeconds)
  1098. {
  1099. Player* thePlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  1100. if (thePlayer) {
  1101. thePlayer->setTeamDelaySeconds(delayInSeconds);
  1102. }
  1103. }
  1104. //-------------------------------------------------------------------------------------------------
  1105. /** updateNamedSetAttitude */
  1106. //-------------------------------------------------------------------------------------------------
  1107. void ScriptActions::updateNamedSetAttitude(const AsciiString& unitName, Int attitude)
  1108. {
  1109. Object *theSrcUnit = TheScriptEngine->getUnitNamed(unitName);
  1110. if (!theSrcUnit) {
  1111. return;
  1112. }
  1113. AIUpdateInterface *pInterface = theSrcUnit->getAIUpdateInterface();
  1114. if (!pInterface) {
  1115. return;
  1116. }
  1117. pInterface->setAttitude((AttitudeType) attitude);
  1118. }
  1119. //-------------------------------------------------------------------------------------------------
  1120. /** updateTeamSetAttitude */
  1121. //-------------------------------------------------------------------------------------------------
  1122. void ScriptActions::updateTeamSetAttitude(const AsciiString& teamName, Int attitude)
  1123. {
  1124. Team *theSrcTeam = TheScriptEngine->getTeamNamed(teamName);
  1125. if (!theSrcTeam) {
  1126. return;
  1127. }
  1128. AIGroup *pAIGroup = TheAI->createGroup();
  1129. if (!pAIGroup) {
  1130. return;
  1131. }
  1132. theSrcTeam->getTeamAsAIGroup(pAIGroup);
  1133. pAIGroup->setAttitude((AttitudeType) attitude);
  1134. }
  1135. //-------------------------------------------------------------------------------------------------
  1136. /** doNamedSetRepulsor */
  1137. //-------------------------------------------------------------------------------------------------
  1138. void ScriptActions::doNamedSetRepulsor(const AsciiString& unitName, Bool repulsor)
  1139. {
  1140. Object *theSrcUnit = TheScriptEngine->getUnitNamed(unitName);
  1141. if (!theSrcUnit) {
  1142. return;
  1143. }
  1144. theSrcUnit->setStatus(OBJECT_STATUS_REPULSOR, repulsor);
  1145. }
  1146. //-------------------------------------------------------------------------------------------------
  1147. /** doTeamSetRepulsor */
  1148. //-------------------------------------------------------------------------------------------------
  1149. void ScriptActions::doTeamSetRepulsor(const AsciiString& teamName, Bool repulsor)
  1150. {
  1151. Team *theSrcTeam = TheScriptEngine->getTeamNamed(teamName);
  1152. if (!theSrcTeam) {
  1153. return;
  1154. }
  1155. if (theSrcTeam)
  1156. {
  1157. for (DLINK_ITERATOR<Object> iter = theSrcTeam->iterate_TeamMemberList(); !iter.done(); iter.advance())
  1158. {
  1159. Object *obj = iter.cur();
  1160. if (!obj)
  1161. {
  1162. continue;
  1163. }
  1164. obj->setStatus(OBJECT_STATUS_REPULSOR, repulsor);
  1165. }
  1166. }
  1167. }
  1168. //-------------------------------------------------------------------------------------------------
  1169. /** doNamedAttackArea */
  1170. //-------------------------------------------------------------------------------------------------
  1171. void ScriptActions::doNamedAttackArea(const AsciiString& unitName, const AsciiString& areaName)
  1172. {
  1173. Object *theSrcUnit = TheScriptEngine->getUnitNamed( unitName );
  1174. if (!theSrcUnit) {
  1175. return;
  1176. }
  1177. PolygonTrigger *pTrig = TheScriptEngine->getQualifiedTriggerAreaByName(areaName);
  1178. if (!pTrig) {
  1179. return;
  1180. }
  1181. AIUpdateInterface* aiUpdate = theSrcUnit->getAIUpdateInterface();
  1182. if( !aiUpdate )
  1183. {
  1184. return;
  1185. }
  1186. theSrcUnit->leaveGroup();
  1187. aiUpdate->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  1188. aiUpdate->aiAttackArea(pTrig, CMD_FROM_SCRIPT);
  1189. }
  1190. //-------------------------------------------------------------------------------------------------
  1191. /** doNamedAttackTeam */
  1192. //-------------------------------------------------------------------------------------------------
  1193. void ScriptActions::doNamedAttackTeam(const AsciiString& unitName, const AsciiString& teamName)
  1194. {
  1195. Object *theSrcUnit = TheScriptEngine->getUnitNamed( unitName );
  1196. if (!theSrcUnit) {
  1197. return;
  1198. }
  1199. const Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1200. if (!theTeam) {
  1201. return;
  1202. }
  1203. AIUpdateInterface* aiUpdate = theSrcUnit->getAIUpdateInterface();
  1204. if (!aiUpdate) {
  1205. return;
  1206. }
  1207. theSrcUnit->leaveGroup();
  1208. aiUpdate->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  1209. aiUpdate->aiAttackTeam(theTeam, NO_MAX_SHOTS_LIMIT, CMD_FROM_SCRIPT);
  1210. }
  1211. //-------------------------------------------------------------------------------------------------
  1212. /** doTeamAttackArea */
  1213. //-------------------------------------------------------------------------------------------------
  1214. void ScriptActions::doTeamAttackArea(const AsciiString& teamName, const AsciiString& areaName)
  1215. {
  1216. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1217. // The team is the team based on the name, and the calling team (if any) and the team that
  1218. // triggered the condition. jba. :)
  1219. if (!theTeam) {
  1220. return;
  1221. }
  1222. AIGroup* theGroup = TheAI->createGroup();
  1223. if (!theGroup) {
  1224. return;
  1225. }
  1226. theTeam->getTeamAsAIGroup(theGroup);
  1227. PolygonTrigger *pTrig = TheScriptEngine->getQualifiedTriggerAreaByName(areaName);
  1228. if (!pTrig) {
  1229. return;
  1230. }
  1231. theGroup->groupAttackArea(pTrig, CMD_FROM_SCRIPT);
  1232. }
  1233. //-------------------------------------------------------------------------------------------------
  1234. /** doTeamAttackNamed */
  1235. //-------------------------------------------------------------------------------------------------
  1236. void ScriptActions::doTeamAttackNamed(const AsciiString& teamName, const AsciiString& unitName)
  1237. {
  1238. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1239. // The team is the team based on the name, and the calling team (if any) and the team that
  1240. // triggered the condition. jba. :)
  1241. if (!theTeam) {
  1242. return;
  1243. }
  1244. Object *theVictim = TheScriptEngine->getUnitNamed( unitName );
  1245. if (!theVictim) {
  1246. return;
  1247. }
  1248. AIGroup* theGroup = TheAI->createGroup();
  1249. if (!theGroup) {
  1250. return;
  1251. }
  1252. theTeam->getTeamAsAIGroup(theGroup);
  1253. theGroup->groupAttackObject(theVictim, NO_MAX_SHOTS_LIMIT, CMD_FROM_SCRIPT);
  1254. }
  1255. //-------------------------------------------------------------------------------------------------
  1256. /** doLoadAllTransports */
  1257. //-------------------------------------------------------------------------------------------------
  1258. void ScriptActions::doLoadAllTransports(const AsciiString& teamName)
  1259. {
  1260. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1261. // The team is the team based on the name, and the calling team (if any) and the team that
  1262. // triggered the condition. jba. :)
  1263. if (!theTeam) {
  1264. return;
  1265. }
  1266. EntriesVec vecOfUnits;
  1267. SpacesVec vecOfTransports;
  1268. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance())
  1269. {
  1270. Object *obj = iter.cur();
  1271. if (!obj) {
  1272. continue;
  1273. }
  1274. if( obj->isKindOf(KINDOF_TRANSPORT) )
  1275. {
  1276. ContainModuleInterface *contain = obj->getContain();
  1277. if( contain )
  1278. {
  1279. vecOfTransports.push_back(std::make_pair(obj->getID(), ((TransportContain*)obj->getContain())->getContainMax()));
  1280. }
  1281. else
  1282. {
  1283. DEBUG_CRASH( ("doLoadAllTransports script -- transport doesn't have a container!") );
  1284. }
  1285. }
  1286. else
  1287. {
  1288. vecOfUnits.push_back(std::make_pair(obj->getID(), obj->getTransportSlotCount()));
  1289. }
  1290. }
  1291. // we've now built the necessary stuff. Partition the units.
  1292. PartitionSolver partition(vecOfUnits, vecOfTransports, PREFER_FAST_SOLUTION);
  1293. partition.solve();
  1294. SolutionVec solution = partition.getSolution();
  1295. for (int i = 0; i < solution.size(); ++i) {
  1296. Object *unit = TheGameLogic->findObjectByID(solution[i].first);
  1297. Object *trans = TheGameLogic->findObjectByID(solution[i].second);
  1298. if (!unit || !trans) {
  1299. continue;
  1300. }
  1301. if( unit->getAIUpdateInterface() )
  1302. {
  1303. unit->getAIUpdateInterface()->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  1304. unit->getAIUpdateInterface()->aiEnter(trans, CMD_FROM_SCRIPT);
  1305. }
  1306. }
  1307. }
  1308. //-------------------------------------------------------------------------------------------------
  1309. /** doNamedEnterNamed */
  1310. //-------------------------------------------------------------------------------------------------
  1311. void ScriptActions::doNamedEnterNamed(const AsciiString& unitSrcName, const AsciiString& unitDestName)
  1312. {
  1313. Object *theSrcUnit = TheScriptEngine->getUnitNamed( unitSrcName );
  1314. if (!theSrcUnit) {
  1315. return;
  1316. }
  1317. Object *theTransport = TheScriptEngine->getUnitNamed( unitDestName );
  1318. if (!theTransport) {
  1319. return;
  1320. }
  1321. AIUpdateInterface* aiUpdate = theSrcUnit->getAIUpdateInterface();
  1322. if (!aiUpdate) {
  1323. return;
  1324. }
  1325. theSrcUnit->leaveGroup();
  1326. aiUpdate->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  1327. aiUpdate->aiEnter(theTransport, CMD_FROM_SCRIPT);
  1328. }
  1329. //-------------------------------------------------------------------------------------------------
  1330. /** doTeamEnterNamed */
  1331. //-------------------------------------------------------------------------------------------------
  1332. void ScriptActions::doTeamEnterNamed(const AsciiString& teamName, const AsciiString& unitDestName)
  1333. {
  1334. Team *theSrcTeam = TheScriptEngine->getTeamNamed( teamName );
  1335. if (!theSrcTeam) {
  1336. return;
  1337. }
  1338. Object *theTransport = TheScriptEngine->getUnitNamed( unitDestName );
  1339. if (!theTransport) {
  1340. return;
  1341. }
  1342. AIGroup* theGroup = TheAI->createGroup();
  1343. theSrcTeam->getTeamAsAIGroup(theGroup);
  1344. theGroup->groupEnter(theTransport, CMD_FROM_SCRIPT);
  1345. }
  1346. //-------------------------------------------------------------------------------------------------
  1347. /** doNamedExitAll */
  1348. //-------------------------------------------------------------------------------------------------
  1349. void ScriptActions::doNamedExitAll(const AsciiString& unitName)
  1350. {
  1351. Object *theTransport = TheScriptEngine->getUnitNamed( unitName );
  1352. if (!theTransport) {
  1353. return;
  1354. }
  1355. AIUpdateInterface* aiUpdate = theTransport->getAIUpdateInterface();
  1356. if (!aiUpdate) {
  1357. return;
  1358. }
  1359. theTransport->leaveGroup();
  1360. aiUpdate->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  1361. aiUpdate->aiEvacuate( FALSE, CMD_FROM_SCRIPT );
  1362. }
  1363. //-------------------------------------------------------------------------------------------------
  1364. /** doTeamExitAll */
  1365. //-------------------------------------------------------------------------------------------------
  1366. void ScriptActions::doTeamExitAll(const AsciiString& teamName)
  1367. {
  1368. Team *theTeamOfTransports = TheScriptEngine->getTeamNamed( teamName );
  1369. if (!theTeamOfTransports) {
  1370. return;
  1371. }
  1372. AIGroup* theGroup = TheAI->createGroup();
  1373. theTeamOfTransports->getTeamAsAIGroup(theGroup);
  1374. theGroup->groupEvacuate( CMD_FROM_SCRIPT );
  1375. }
  1376. //-------------------------------------------------------------------------------------------------
  1377. /** doNamedFollowWaypoints */
  1378. //-------------------------------------------------------------------------------------------------
  1379. void ScriptActions::doNamedFollowWaypoints(const AsciiString& unitName, const AsciiString& waypointPathLabel)
  1380. {
  1381. Object *theUnit = TheScriptEngine->getUnitNamed( unitName );
  1382. if (!theUnit) {
  1383. return;
  1384. }
  1385. Coord3D pos = *theUnit->getPosition();
  1386. AIUpdateInterface* aiUpdate = theUnit->getAIUpdateInterface();
  1387. if (!aiUpdate) {
  1388. return;
  1389. }
  1390. Waypoint *way = TheTerrainLogic->getClosestWaypointOnPath( &pos, waypointPathLabel );
  1391. if (!way) {
  1392. return;
  1393. }
  1394. DEBUG_ASSERTLOG(TheTerrainLogic->isPurposeOfPath(way, waypointPathLabel), ("***Wrong waypoint purpose. Make jba fix this.\n"));
  1395. theUnit->leaveGroup();
  1396. aiUpdate->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  1397. aiUpdate->aiFollowWaypointPath(way, CMD_FROM_SCRIPT);
  1398. }
  1399. //-------------------------------------------------------------------------------------------------
  1400. /** doNamedFollowWaypointsExact */
  1401. //-------------------------------------------------------------------------------------------------
  1402. void ScriptActions::doNamedFollowWaypointsExact(const AsciiString& unitName, const AsciiString& waypointPathLabel)
  1403. {
  1404. Object *theUnit = TheScriptEngine->getUnitNamed( unitName );
  1405. if (!theUnit) {
  1406. return;
  1407. }
  1408. Coord3D pos = *theUnit->getPosition();
  1409. AIUpdateInterface* aiUpdate = theUnit->getAIUpdateInterface();
  1410. if (!aiUpdate) {
  1411. return;
  1412. }
  1413. Waypoint *way = TheTerrainLogic->getClosestWaypointOnPath( &pos, waypointPathLabel );
  1414. if (!way) {
  1415. return;
  1416. }
  1417. DEBUG_ASSERTLOG(TheTerrainLogic->isPurposeOfPath(way, waypointPathLabel), ("***Wrong waypoint purpose. Make jba fix this.\n"));
  1418. theUnit->leaveGroup();
  1419. aiUpdate->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  1420. aiUpdate->aiFollowWaypointPathExact(way, CMD_FROM_SCRIPT);
  1421. }
  1422. //-------------------------------------------------------------------------------------------------
  1423. /** doTeamFollowSkirmishApproachPath */
  1424. //-------------------------------------------------------------------------------------------------
  1425. void ScriptActions::doTeamFollowSkirmishApproachPath(const AsciiString& teamName, const AsciiString& waypointPathLabel, Bool asTeam)
  1426. {
  1427. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1428. if (!theTeam) {
  1429. return;
  1430. }
  1431. AIGroup* theGroup = TheAI->createGroup();
  1432. if (!theGroup) {
  1433. return;
  1434. }
  1435. theTeam->getTeamAsAIGroup(theGroup);
  1436. Int count = 0;
  1437. Coord3D pos;
  1438. pos.x=pos.y=pos.z=0;
  1439. Object *firstUnit=NULL;
  1440. // Get the center point for the team
  1441. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance())
  1442. {
  1443. Object *obj = iter.cur();
  1444. Coord3D objPos = *obj->getPosition();
  1445. pos.x += objPos.x;
  1446. pos.y += objPos.y;
  1447. pos.z += objPos.z; // Not actually used by getClosestWaypointOnPath, but hey, might as well be correct.
  1448. count++;
  1449. if (firstUnit==NULL) {
  1450. firstUnit = obj;
  1451. }
  1452. }
  1453. if (count==0) return; // empty team.
  1454. pos.x /= count;
  1455. pos.y /= count;
  1456. pos.z /= count;
  1457. Player *enemyPlayer = TheScriptEngine->getSkirmishEnemyPlayer();
  1458. if (enemyPlayer==NULL) return;
  1459. Int mpNdx = enemyPlayer->getMpStartIndex()+1;
  1460. AsciiString pathLabel;
  1461. pathLabel.format("%s%d", waypointPathLabel.str(), mpNdx);
  1462. Waypoint *way = TheTerrainLogic->getClosestWaypointOnPath( &pos, pathLabel );
  1463. if (!way) {
  1464. return;
  1465. }
  1466. Player *aiPlayer = TheScriptEngine->getCurrentPlayer();
  1467. if (aiPlayer && firstUnit) {
  1468. aiPlayer->checkBridges(firstUnit, way);
  1469. }
  1470. DEBUG_ASSERTLOG(TheTerrainLogic->isPurposeOfPath(way, pathLabel), ("***Wrong waypoint purpose. Make jba fix this.\n"));
  1471. if (asTeam)
  1472. {
  1473. theGroup->groupFollowWaypointPathAsTeam(way, CMD_FROM_SCRIPT);
  1474. } else {
  1475. theGroup->groupFollowWaypointPath(way, CMD_FROM_SCRIPT);
  1476. }
  1477. }
  1478. //-------------------------------------------------------------------------------------------------
  1479. /** doTeamFollowSkirmishApproachPath */
  1480. //-------------------------------------------------------------------------------------------------
  1481. void ScriptActions::doTeamMoveToSkirmishApproachPath(const AsciiString& teamName, const AsciiString& waypointPathLabel)
  1482. {
  1483. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1484. if (!theTeam) {
  1485. return;
  1486. }
  1487. AIGroup* theGroup = TheAI->createGroup();
  1488. if (!theGroup) {
  1489. return;
  1490. }
  1491. theTeam->getTeamAsAIGroup(theGroup);
  1492. Int count = 0;
  1493. Coord3D pos;
  1494. pos.x=pos.y=pos.z=0;
  1495. // Get the center point for the team
  1496. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance())
  1497. {
  1498. Object *obj = iter.cur();
  1499. Coord3D objPos = *obj->getPosition();
  1500. pos.x += objPos.x;
  1501. pos.y += objPos.y;
  1502. pos.z += objPos.z; // Not actually used by getClosestWaypointOnPath, but hey, might as well be correct.
  1503. count++;
  1504. }
  1505. if (count==0) return; // empty team.
  1506. pos.x /= count;
  1507. pos.y /= count;
  1508. pos.z /= count;
  1509. Player *enemyPlayer = TheScriptEngine->getSkirmishEnemyPlayer();
  1510. if (enemyPlayer==NULL) return;
  1511. Int mpNdx = enemyPlayer->getMpStartIndex()+1;
  1512. AsciiString pathLabel;
  1513. pathLabel.format("%s%d", waypointPathLabel.str(), mpNdx);
  1514. Waypoint *way = TheTerrainLogic->getClosestWaypointOnPath( &pos, pathLabel );
  1515. if (!way) {
  1516. return;
  1517. }
  1518. DEBUG_ASSERTLOG(TheTerrainLogic->isPurposeOfPath(way, pathLabel), ("***Wrong waypoint purpose. Make jba fix this.\n"));
  1519. theGroup->groupMoveToPosition(way->getLocation(), false, CMD_FROM_SCRIPT);
  1520. }
  1521. //-------------------------------------------------------------------------------------------------
  1522. /** doTeamFollowWaypoints */
  1523. //-------------------------------------------------------------------------------------------------
  1524. void ScriptActions::doTeamFollowWaypoints(const AsciiString& teamName, const AsciiString& waypointPathLabel, Bool asTeam)
  1525. {
  1526. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1527. if (!theTeam) {
  1528. return;
  1529. }
  1530. AIGroup* theGroup = TheAI->createGroup();
  1531. if (!theGroup) {
  1532. return;
  1533. }
  1534. theTeam->getTeamAsAIGroup(theGroup);
  1535. Int count = 0;
  1536. Coord3D pos;
  1537. pos.x=pos.y=pos.z=0;
  1538. // Get the center point for the team
  1539. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance())
  1540. {
  1541. Object *obj = iter.cur();
  1542. Coord3D objPos = *obj->getPosition();
  1543. pos.x += objPos.x;
  1544. pos.y += objPos.y;
  1545. pos.z += objPos.z; // Not actually used by getClosestWaypointOnPath, but hey, might as well be correct.
  1546. count++;
  1547. }
  1548. if (count==0) return; // empty team.
  1549. pos.x /= count;
  1550. pos.y /= count;
  1551. pos.z /= count;
  1552. Waypoint *way = TheTerrainLogic->getClosestWaypointOnPath( &pos, waypointPathLabel );
  1553. if (!way) {
  1554. return;
  1555. }
  1556. DEBUG_ASSERTLOG(TheTerrainLogic->isPurposeOfPath(way, waypointPathLabel), ("***Wrong waypoint purpose. Make jba fix this.\n"));
  1557. if (asTeam)
  1558. {
  1559. theGroup->groupFollowWaypointPathAsTeam(way, CMD_FROM_SCRIPT);
  1560. } else {
  1561. theGroup->groupFollowWaypointPath(way, CMD_FROM_SCRIPT);
  1562. }
  1563. }
  1564. //-------------------------------------------------------------------------------------------------
  1565. /** doTeamFollowWaypointsExact */
  1566. //-------------------------------------------------------------------------------------------------
  1567. void ScriptActions::doTeamFollowWaypointsExact(const AsciiString& teamName, const AsciiString& waypointPathLabel, Bool asTeam)
  1568. {
  1569. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1570. if (!theTeam) {
  1571. return;
  1572. }
  1573. AIGroup* theGroup = TheAI->createGroup();
  1574. if (!theGroup) {
  1575. return;
  1576. }
  1577. theTeam->getTeamAsAIGroup(theGroup);
  1578. Int count = 0;
  1579. Coord3D pos;
  1580. pos.x=pos.y=pos.z=0;
  1581. // Get the center point for the team
  1582. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance())
  1583. {
  1584. Object *obj = iter.cur();
  1585. Coord3D objPos = *obj->getPosition();
  1586. pos.x += objPos.x;
  1587. pos.y += objPos.y;
  1588. pos.z += objPos.z; // Not actually used by getClosestWaypointOnPath, but hey, might as well be correct.
  1589. count++;
  1590. }
  1591. if (count==0) return; // empty team.
  1592. pos.x /= count;
  1593. pos.y /= count;
  1594. pos.z /= count;
  1595. Waypoint *way = TheTerrainLogic->getClosestWaypointOnPath( &pos, waypointPathLabel );
  1596. if (!way) {
  1597. return;
  1598. }
  1599. DEBUG_ASSERTLOG(TheTerrainLogic->isPurposeOfPath(way, waypointPathLabel), ("***Wrong waypoint purpose. Make jba fix this.\n"));
  1600. if (asTeam)
  1601. {
  1602. theGroup->groupFollowWaypointPathAsTeamExact(way, CMD_FROM_SCRIPT);
  1603. } else {
  1604. theGroup->groupFollowWaypointPathExact(way, CMD_FROM_SCRIPT);
  1605. }
  1606. }
  1607. //-------------------------------------------------------------------------------------------------
  1608. /** doNamedGuard */
  1609. //-------------------------------------------------------------------------------------------------
  1610. void ScriptActions::doNamedGuard(const AsciiString& unitName)
  1611. {
  1612. Object *theUnit = TheScriptEngine->getUnitNamed( unitName );
  1613. if (!theUnit) {
  1614. return;
  1615. }
  1616. AIUpdateInterface* aiUpdate = theUnit->getAIUpdateInterface();
  1617. if (!aiUpdate) {
  1618. return;
  1619. }
  1620. theUnit->leaveGroup();
  1621. Coord3D position = *theUnit->getPosition();
  1622. aiUpdate->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  1623. aiUpdate->aiGuardPosition(&position, GUARDMODE_NORMAL, CMD_FROM_SCRIPT);
  1624. }
  1625. //-------------------------------------------------------------------------------------------------
  1626. /** doTeamGuard */
  1627. //-------------------------------------------------------------------------------------------------
  1628. void ScriptActions::doTeamGuard(const AsciiString& teamName)
  1629. {
  1630. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1631. if (!theTeam) {
  1632. return;
  1633. }
  1634. // Have all the members of the team guard at their current pos.
  1635. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance())
  1636. {
  1637. Object *obj = iter.cur();
  1638. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  1639. if (!ai) {
  1640. continue;
  1641. }
  1642. Coord3D pos = *obj->getPosition();
  1643. ai->aiGuardPosition(&pos, GUARDMODE_NORMAL, CMD_FROM_SCRIPT);
  1644. }
  1645. }
  1646. //-------------------------------------------------------------------------------------------------
  1647. /** doTeamGuardPosition */
  1648. //-------------------------------------------------------------------------------------------------
  1649. void ScriptActions::doTeamGuardPosition(const AsciiString& teamName, const AsciiString& waypointName)
  1650. {
  1651. Waypoint *way = TheTerrainLogic->getWaypointByName(waypointName);
  1652. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1653. if (!theTeam || !way) {
  1654. return;
  1655. }
  1656. AIGroup* theGroup = TheAI->createGroup();
  1657. if (!theGroup) {
  1658. return;
  1659. }
  1660. theTeam->getTeamAsAIGroup(theGroup);
  1661. Coord3D position = *way->getLocation();
  1662. theGroup->groupGuardPosition( &position, GUARDMODE_NORMAL, CMD_FROM_SCRIPT );
  1663. }
  1664. //-------------------------------------------------------------------------------------------------
  1665. /** doTeamGuardObject */
  1666. //-------------------------------------------------------------------------------------------------
  1667. void ScriptActions::doTeamGuardObject(const AsciiString& teamName, const AsciiString& unitName)
  1668. {
  1669. Object *theUnit = TheScriptEngine->getUnitNamed( unitName );
  1670. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1671. if (!theTeam || !theUnit) {
  1672. return;
  1673. }
  1674. AIGroup* theGroup = TheAI->createGroup();
  1675. if (!theGroup) {
  1676. return;
  1677. }
  1678. theTeam->getTeamAsAIGroup(theGroup);
  1679. theGroup->groupGuardObject( theUnit, GUARDMODE_NORMAL, CMD_FROM_SCRIPT );
  1680. }
  1681. //-------------------------------------------------------------------------------------------------
  1682. /** doTeamGuardArea */
  1683. //-------------------------------------------------------------------------------------------------
  1684. void ScriptActions::doTeamGuardArea(const AsciiString& teamName, const AsciiString& areaName)
  1685. {
  1686. PolygonTrigger *pTrig = TheScriptEngine->getQualifiedTriggerAreaByName(areaName);
  1687. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1688. if (!theTeam || !pTrig) {
  1689. return;
  1690. }
  1691. AIGroup* theGroup = TheAI->createGroup();
  1692. if (!theGroup) {
  1693. return;
  1694. }
  1695. theTeam->getTeamAsAIGroup(theGroup);
  1696. theGroup->groupGuardArea( pTrig, GUARDMODE_NORMAL, CMD_FROM_SCRIPT );
  1697. }
  1698. //-------------------------------------------------------------------------------------------------
  1699. /** doNamedHunt */
  1700. //-------------------------------------------------------------------------------------------------
  1701. void ScriptActions::doNamedHunt(const AsciiString& unitName)
  1702. {
  1703. Object *theUnit = TheScriptEngine->getUnitNamed( unitName );
  1704. if (!theUnit) {
  1705. return;
  1706. }
  1707. AIUpdateInterface* aiUpdate = theUnit->getAIUpdateInterface();
  1708. if (!aiUpdate) {
  1709. return;
  1710. }
  1711. aiUpdate->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  1712. aiUpdate->aiHunt( CMD_FROM_SCRIPT );
  1713. }
  1714. //-------------------------------------------------------------------------------------------------
  1715. /** doTeamHunt */
  1716. //-------------------------------------------------------------------------------------------------
  1717. void ScriptActions::doTeamHunt(const AsciiString& teamName)
  1718. {
  1719. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1720. if (!theTeam) {
  1721. return;
  1722. }
  1723. AIGroup* theGroup = TheAI->createGroup();
  1724. if (!theGroup) {
  1725. return;
  1726. }
  1727. theTeam->getTeamAsAIGroup(theGroup);
  1728. theGroup->groupHunt( CMD_FROM_SCRIPT );
  1729. }
  1730. //-------------------------------------------------------------------------------------------------
  1731. /** doTeamHunt */
  1732. //-------------------------------------------------------------------------------------------------
  1733. void ScriptActions::doTeamHuntWithCommandButton(const AsciiString& teamName, const AsciiString& ability)
  1734. {
  1735. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  1736. if (!theTeam) {
  1737. return;
  1738. }
  1739. const CommandButton *commandButton = TheControlBar->findCommandButton( ability );
  1740. if( !commandButton )
  1741. {
  1742. return;
  1743. }
  1744. switch( commandButton->getCommandType() )
  1745. {
  1746. case GUI_COMMAND_SPECIAL_POWER:
  1747. if( commandButton->getSpecialPowerTemplate() )
  1748. {
  1749. if (BitTest( commandButton->getOptions(), COMMAND_OPTION_NEED_OBJECT_TARGET ))
  1750. {
  1751. // OK, we can hunt with a power that targets an object.
  1752. break;
  1753. }
  1754. AsciiString msg = "ERROR-Team hunt with command button - cannot hunt with ability ";
  1755. msg.concat(ability);
  1756. TheScriptEngine->AppendDebugMessage(msg, false);
  1757. return;
  1758. }
  1759. return;
  1760. case GUI_COMMAND_SWITCH_WEAPON:
  1761. case GUI_COMMAND_FIRE_WEAPON:
  1762. {
  1763. // ok, we can hunt with a weapon.
  1764. break;
  1765. }
  1766. case GUI_COMMAND_OBJECT_UPGRADE:
  1767. case GUI_COMMAND_PLAYER_UPGRADE:
  1768. case GUI_COMMAND_DOZER_CONSTRUCT:
  1769. case GUI_COMMAND_DOZER_CONSTRUCT_CANCEL:
  1770. case GUI_COMMAND_UNIT_BUILD:
  1771. case GUI_COMMAND_CANCEL_UNIT_BUILD:
  1772. case GUI_COMMAND_CANCEL_UPGRADE:
  1773. case GUI_COMMAND_ATTACK_MOVE:
  1774. case GUI_COMMAND_GUARD:
  1775. case GUI_COMMAND_GUARD_WITHOUT_PURSUIT:
  1776. case GUI_COMMAND_GUARD_FLYING_UNITS_ONLY:
  1777. case GUI_COMMAND_WAYPOINTS:
  1778. case GUI_COMMAND_EXIT_CONTAINER:
  1779. case GUI_COMMAND_EVACUATE:
  1780. case GUI_COMMAND_EXECUTE_RAILED_TRANSPORT:
  1781. case GUI_COMMAND_BEACON_DELETE:
  1782. case GUI_COMMAND_SET_RALLY_POINT:
  1783. case GUI_COMMAND_SELL:
  1784. case GUI_COMMAND_HACK_INTERNET:
  1785. case GUI_COMMAND_TOGGLE_OVERCHARGE:
  1786. #ifdef ALLOW_SURRENDER
  1787. case GUI_COMMAND_POW_RETURN_TO_PRISON:
  1788. #endif
  1789. case GUICOMMANDMODE_HIJACK_VEHICLE:
  1790. case GUICOMMANDMODE_CONVERT_TO_CARBOMB:
  1791. #ifdef ALLOW_SURRENDER
  1792. case GUICOMMANDMODE_PICK_UP_PRISONER:
  1793. #endif
  1794. default:
  1795. {
  1796. AsciiString msg = "ERROR-Team hunt with command button - cannot hunt with ability ";
  1797. msg.concat(ability);
  1798. TheScriptEngine->AppendDebugMessage(msg, false);
  1799. return;
  1800. }
  1801. break;
  1802. }
  1803. // Have all the members of the team do the command button.
  1804. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance())
  1805. {
  1806. Object *obj = iter.cur();
  1807. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  1808. if (!ai) {
  1809. continue;
  1810. }
  1811. Bool foundCommand = false;
  1812. const CommandSet *commandSet = TheControlBar->findCommandSet( obj->getCommandSetString( ) );
  1813. if( commandSet )
  1814. {
  1815. for( int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
  1816. {
  1817. const CommandButton *aCommandButton = commandSet->getCommandButton(i);
  1818. if( commandButton == aCommandButton )
  1819. {
  1820. //We found the matching command button so now order the unit to do what the button wants.
  1821. foundCommand = true;
  1822. break;
  1823. }
  1824. }
  1825. }
  1826. if (!foundCommand) {
  1827. AsciiString msg = "Error - Team hunt with command button - unit type '";
  1828. msg.concat(obj->getTemplate()->getName().str());
  1829. msg.concat("' is not valid for ability ");
  1830. msg.concat(ability);
  1831. TheScriptEngine->AppendDebugMessage(msg, false);
  1832. continue;
  1833. }
  1834. switch( commandButton->getCommandType() )
  1835. {
  1836. case GUI_COMMAND_FIRE_WEAPON:
  1837. case GUI_COMMAND_SWITCH_WEAPON:
  1838. case GUI_COMMAND_SPECIAL_POWER:
  1839. {
  1840. static NameKeyType key_CommandButtonHuntUpdate = NAMEKEY("CommandButtonHuntUpdate");
  1841. CommandButtonHuntUpdate* huntUpdate = (CommandButtonHuntUpdate*)obj->findUpdateModule(key_CommandButtonHuntUpdate);
  1842. if( huntUpdate )
  1843. {
  1844. huntUpdate->setCommandButton(ability);
  1845. } else {
  1846. AsciiString msg = "Error - Team hunt with command button - unit type '";
  1847. msg.concat(obj->getTemplate()->getName().str());
  1848. msg.concat("' requires CommandButtonHuntUpdate in .ini definition to hunt with ");
  1849. msg.concat(ability);
  1850. TheScriptEngine->AppendDebugMessage(msg, false);
  1851. } // end if
  1852. }
  1853. break;
  1854. }
  1855. }
  1856. }
  1857. //-------------------------------------------------------------------------------------------------
  1858. /** doTeamHunt */
  1859. //-------------------------------------------------------------------------------------------------
  1860. void ScriptActions::doPlayerHunt(const AsciiString& playerName)
  1861. {
  1862. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  1863. if (!pPlayer) {
  1864. return;
  1865. }
  1866. pPlayer->setUnitsShouldHunt(true, CMD_FROM_SCRIPT);
  1867. }
  1868. //-------------------------------------------------------------------------------------------------
  1869. /** doPlayerSellEverything */
  1870. //-------------------------------------------------------------------------------------------------
  1871. void ScriptActions::doPlayerSellEverything(const AsciiString& playerName)
  1872. {
  1873. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  1874. if (!pPlayer) {
  1875. return;
  1876. }
  1877. pPlayer->sellEverythingUnderTheSun();
  1878. }
  1879. //-------------------------------------------------------------------------------------------------
  1880. /** doPlayerDisableBaseConstruction */
  1881. //-------------------------------------------------------------------------------------------------
  1882. void ScriptActions::doPlayerDisableBaseConstruction(const AsciiString& playerName)
  1883. {
  1884. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  1885. if (!pPlayer) {
  1886. return;
  1887. }
  1888. pPlayer->setCanBuildBase(false);
  1889. }
  1890. //-------------------------------------------------------------------------------------------------
  1891. /** doPlayerDisableFactories */
  1892. //-------------------------------------------------------------------------------------------------
  1893. void ScriptActions::doPlayerDisableFactories(const AsciiString& playerName, const AsciiString& objectName)
  1894. {
  1895. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  1896. if (!pPlayer) {
  1897. return;
  1898. }
  1899. pPlayer->setObjectsEnabled(objectName, false);
  1900. }
  1901. //-------------------------------------------------------------------------------------------------
  1902. /** doPlayerDisableUnitConstruction */
  1903. //-------------------------------------------------------------------------------------------------
  1904. void ScriptActions::doPlayerDisableUnitConstruction(const AsciiString& playerName)
  1905. {
  1906. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  1907. if (!pPlayer) {
  1908. return;
  1909. }
  1910. pPlayer->setCanBuildUnits(false);
  1911. }
  1912. //-------------------------------------------------------------------------------------------------
  1913. /** doPlayerEnableBaseConstruction */
  1914. //-------------------------------------------------------------------------------------------------
  1915. void ScriptActions::doPlayerEnableBaseConstruction(const AsciiString& playerName)
  1916. {
  1917. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  1918. if (!pPlayer) {
  1919. return;
  1920. }
  1921. pPlayer->setCanBuildBase(true);
  1922. }
  1923. //-------------------------------------------------------------------------------------------------
  1924. /** doPlayerEnableFactories */
  1925. //-------------------------------------------------------------------------------------------------
  1926. void ScriptActions::doPlayerEnableFactories(const AsciiString& playerName, const AsciiString& objectName)
  1927. {
  1928. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  1929. if (!pPlayer) {
  1930. return;
  1931. }
  1932. pPlayer->setObjectsEnabled(objectName, true);
  1933. }
  1934. //-------------------------------------------------------------------------------------------------
  1935. /** doPlayerRepairStructure */
  1936. //-------------------------------------------------------------------------------------------------
  1937. void ScriptActions::doPlayerRepairStructure(const AsciiString& playerName, const AsciiString& structureName)
  1938. {
  1939. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  1940. if (!pPlayer) {
  1941. return;
  1942. }
  1943. Object *pStructure = TheScriptEngine->getUnitNamed(structureName);
  1944. if (!pStructure) {
  1945. return;
  1946. }
  1947. pPlayer->repairStructure(pStructure->getID());
  1948. }
  1949. //-------------------------------------------------------------------------------------------------
  1950. /** doPlayerEnableUnitConstruction */
  1951. //-------------------------------------------------------------------------------------------------
  1952. void ScriptActions::doPlayerEnableUnitConstruction(const AsciiString& playerName)
  1953. {
  1954. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  1955. if (!pPlayer) {
  1956. return;
  1957. }
  1958. pPlayer->setCanBuildUnits(true);
  1959. }
  1960. //-------------------------------------------------------------------------------------------------
  1961. /** doCameraMoveHome */
  1962. //-------------------------------------------------------------------------------------------------
  1963. void ScriptActions::doCameraMoveHome(void)
  1964. {
  1965. }
  1966. //-------------------------------------------------------------------------------------------------
  1967. /** doBuildTeam */
  1968. //-------------------------------------------------------------------------------------------------
  1969. void ScriptActions::doBuildTeam(const AsciiString& teamName)
  1970. {
  1971. TeamPrototype *theTeamProto = TheTeamFactory->findTeamPrototype( teamName );
  1972. if (theTeamProto) {
  1973. Player *player = theTeamProto->getControllingPlayer();
  1974. if (player) {
  1975. player->buildSpecificTeam(theTeamProto);
  1976. }
  1977. }
  1978. }
  1979. //-------------------------------------------------------------------------------------------------
  1980. /** doRecruitTeam */
  1981. //-------------------------------------------------------------------------------------------------
  1982. void ScriptActions::doRecruitTeam(const AsciiString& teamName, Real recruitRadius)
  1983. {
  1984. TeamPrototype *theTeamProto = TheTeamFactory->findTeamPrototype( teamName );
  1985. if (theTeamProto) {
  1986. Player *player = theTeamProto->getControllingPlayer();
  1987. if (player) {
  1988. player->recruitSpecificTeam(theTeamProto, recruitRadius);
  1989. }
  1990. }
  1991. }
  1992. //-------------------------------------------------------------------------------------------------
  1993. /** doNamedDamage */
  1994. //-------------------------------------------------------------------------------------------------
  1995. void ScriptActions::doNamedDamage(const AsciiString& unitName, Int damageAmt)
  1996. {
  1997. Object *pUnit = TheScriptEngine->getUnitNamed(unitName);
  1998. if (!pUnit) {
  1999. return;
  2000. }
  2001. DamageInfo damageInfo;
  2002. damageInfo.in.m_damageType = DAMAGE_UNRESISTABLE;
  2003. damageInfo.in.m_deathType = DEATH_NORMAL;
  2004. damageInfo.in.m_sourceID = INVALID_ID;
  2005. damageInfo.in.m_amount = damageAmt;
  2006. pUnit->attemptDamage( &damageInfo );
  2007. }
  2008. //-------------------------------------------------------------------------------------------------
  2009. /** doNamedDelete */
  2010. //-------------------------------------------------------------------------------------------------
  2011. void ScriptActions::doNamedDelete(const AsciiString& unitName)
  2012. {
  2013. Object *theUnit = TheScriptEngine->getUnitNamed( unitName );
  2014. if (!theUnit) {
  2015. return;
  2016. }
  2017. TheGameLogic->destroyObject(theUnit);
  2018. }
  2019. //-------------------------------------------------------------------------------------------------
  2020. /** doTeamDelete */
  2021. //-------------------------------------------------------------------------------------------------
  2022. void ScriptActions::doTeamDelete(const AsciiString& teamName, Bool ignoreDead)
  2023. {
  2024. Team *team = TheScriptEngine->getTeamNamed(teamName);
  2025. if (!team) {
  2026. return;
  2027. }
  2028. team->deleteTeam(ignoreDead);
  2029. }
  2030. //-------------------------------------------------------------------------------------------------
  2031. /** doTeamWander */
  2032. //-------------------------------------------------------------------------------------------------
  2033. void ScriptActions::doTeamWander(const AsciiString& teamName, const AsciiString& waypointPathLabel)
  2034. {
  2035. Team *team = TheScriptEngine->getTeamNamed(teamName);
  2036. if (!team) {
  2037. return;
  2038. }
  2039. // Have all the members of the team wander.
  2040. for (DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance())
  2041. {
  2042. Object *obj = iter.cur();
  2043. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  2044. if (!ai) {
  2045. continue;
  2046. }
  2047. Coord3D pos = *obj->getPosition();
  2048. Waypoint *way = TheTerrainLogic->getClosestWaypointOnPath( &pos, waypointPathLabel );
  2049. if (!way) {
  2050. return;
  2051. }
  2052. ai->chooseLocomotorSet(LOCOMOTORSET_WANDER);
  2053. ai->aiWander(way, CMD_FROM_SCRIPT);
  2054. }
  2055. }
  2056. //-------------------------------------------------------------------------------------------------
  2057. /** doTeamIncreasePriority */
  2058. //-------------------------------------------------------------------------------------------------
  2059. void ScriptActions::doTeamIncreasePriority(const AsciiString& teamName)
  2060. {
  2061. Team *team = TheScriptEngine->getTeamNamed(teamName);
  2062. if (!team) {
  2063. return;
  2064. }
  2065. const TeamPrototype *theTeamProto = team->getPrototype();
  2066. if (!theTeamProto) {
  2067. return;
  2068. }
  2069. theTeamProto->increaseAIPriorityForSuccess();
  2070. AsciiString msg;
  2071. msg.format("Team '%s' priority increased to %d for success.", teamName.str(), theTeamProto->getTemplateInfo()->m_productionPriority);
  2072. TheScriptEngine->AppendDebugMessage(msg, false);
  2073. }
  2074. //-------------------------------------------------------------------------------------------------
  2075. /** doTeamDecreasePriority */
  2076. //-------------------------------------------------------------------------------------------------
  2077. void ScriptActions::doTeamDecreasePriority(const AsciiString& teamName)
  2078. {
  2079. Team *team = TheScriptEngine->getTeamNamed(teamName);
  2080. if (!team) {
  2081. return;
  2082. }
  2083. const TeamPrototype *theTeamProto = team->getPrototype();
  2084. if (!theTeamProto) {
  2085. return;
  2086. }
  2087. theTeamProto->decreaseAIPriorityForFailure();
  2088. AsciiString msg;
  2089. msg.format("Team '%s' priority decreased to %d for failure.", teamName.str(), theTeamProto->getTemplateInfo()->m_productionPriority);
  2090. TheScriptEngine->AppendDebugMessage(msg, false);
  2091. }
  2092. //-------------------------------------------------------------------------------------------------
  2093. /** doTeamWanderInPlace */
  2094. //-------------------------------------------------------------------------------------------------
  2095. void ScriptActions::doTeamWanderInPlace(const AsciiString& teamName)
  2096. {
  2097. Team *team = TheScriptEngine->getTeamNamed(teamName);
  2098. if (!team) {
  2099. return;
  2100. }
  2101. // Have all the members of the team wander.
  2102. for (DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance())
  2103. {
  2104. Object *obj = iter.cur();
  2105. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  2106. if (!ai) {
  2107. continue;
  2108. }
  2109. ai->chooseLocomotorSet(LOCOMOTORSET_WANDER);
  2110. ai->aiWanderInPlace(CMD_FROM_SCRIPT);
  2111. }
  2112. }
  2113. //-------------------------------------------------------------------------------------------------
  2114. /** doTeamPanic */
  2115. //-------------------------------------------------------------------------------------------------
  2116. void ScriptActions::doTeamPanic(const AsciiString& teamName, const AsciiString& waypointPathLabel)
  2117. {
  2118. Team *team = TheScriptEngine->getTeamNamed(teamName);
  2119. if (!team) {
  2120. return;
  2121. }
  2122. // Get the center point for the team
  2123. for (DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance())
  2124. {
  2125. Object *obj = iter.cur();
  2126. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  2127. if (!ai) {
  2128. continue;
  2129. }
  2130. Coord3D pos = *obj->getPosition();
  2131. Waypoint *way = TheTerrainLogic->getClosestWaypointOnPath( &pos, waypointPathLabel );
  2132. if (!way) {
  2133. return;
  2134. }
  2135. ai->chooseLocomotorSet(LOCOMOTORSET_PANIC);
  2136. ai->aiPanic(way, CMD_FROM_SCRIPT);
  2137. }
  2138. }
  2139. //-------------------------------------------------------------------------------------------------
  2140. /** doNamedKill */
  2141. //-------------------------------------------------------------------------------------------------
  2142. void ScriptActions::doNamedKill(const AsciiString& unitName)
  2143. {
  2144. Object *pUnit = TheScriptEngine->getUnitNamed(unitName);
  2145. if (!pUnit) {
  2146. return;
  2147. }
  2148. pUnit->kill();
  2149. }
  2150. //-------------------------------------------------------------------------------------------------
  2151. /** doTeamKill */
  2152. //-------------------------------------------------------------------------------------------------
  2153. void ScriptActions::doTeamKill(const AsciiString& teamName)
  2154. {
  2155. Team *team = TheScriptEngine->getTeamNamed(teamName);
  2156. if (!team) {
  2157. return;
  2158. }
  2159. team->killTeam();
  2160. }
  2161. //-------------------------------------------------------------------------------------------------
  2162. /** doPlayerKill */
  2163. //-------------------------------------------------------------------------------------------------
  2164. void ScriptActions::doPlayerKill(const AsciiString& playerName)
  2165. {
  2166. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  2167. if (!pPlayer) {
  2168. return;
  2169. }
  2170. pPlayer->killPlayer();
  2171. }
  2172. //-------------------------------------------------------------------------------------------------
  2173. /** doDisplayText */
  2174. //-------------------------------------------------------------------------------------------------
  2175. void ScriptActions::doDisplayText(const AsciiString& displayText)
  2176. {
  2177. TheInGameUI->message(displayText);
  2178. }
  2179. //-------------------------------------------------------------------------------------------------
  2180. /** doInGamePopupMessage */
  2181. //-------------------------------------------------------------------------------------------------
  2182. void ScriptActions::doInGamePopupMessage( const AsciiString& message, Int x, Int y, Int width, Bool pause )
  2183. {
  2184. TheInGameUI->popupMessage(message, x,y,width, pause, FALSE);
  2185. }
  2186. //-------------------------------------------------------------------------------------------------
  2187. /** doDisplayCinematicText */
  2188. //-------------------------------------------------------------------------------------------------
  2189. void ScriptActions::doDisplayCinematicText(const AsciiString& displayText, const AsciiString& fontType, Int timeInSeconds)
  2190. {
  2191. // set the text
  2192. UnicodeString uStr = TheGameText->fetch( displayText );
  2193. AsciiString aStr;
  2194. aStr.translate( uStr );
  2195. TheDisplay->setCinematicText( aStr );
  2196. // Gets the font info from parsing through fontType
  2197. // get the font name
  2198. AsciiString fontName = AsciiString::TheEmptyString;
  2199. char buf[256];
  2200. char *c;
  2201. strcpy(buf, fontType.str());
  2202. for( c = buf; c != '\0'; *c++ )
  2203. {
  2204. if( *c != ' ' && *c++ != '-' )
  2205. fontName.concat(c);
  2206. else
  2207. break;
  2208. }
  2209. while( *c != ':' )
  2210. *c++;
  2211. *c++; // eat through " - Size:"
  2212. // get font size
  2213. AsciiString fontSize = AsciiString::TheEmptyString;
  2214. for( ; *c != '\0'; *c++ )
  2215. {
  2216. if( *c != '\0' && *c != ' ' )
  2217. {
  2218. fontSize.concat( *c );
  2219. }
  2220. else
  2221. {
  2222. break;
  2223. }
  2224. }
  2225. Int size = atoi( fontSize.str() );
  2226. // get font fold
  2227. Bool bold = FALSE;
  2228. if( fontType.endsWith( "[Bold]" ) )
  2229. bold = TRUE;
  2230. // phew, now set as new font
  2231. GameFont *font = TheFontLibrary->getFont( fontName,
  2232. TheGlobalLanguageData->adjustFontSize(size), bold );
  2233. TheDisplay->setCinematicFont( font );
  2234. // set time
  2235. Int frames = LOGICFRAMES_PER_SECOND * timeInSeconds;
  2236. TheDisplay->setCinematicTextFrames( frames );
  2237. }
  2238. //-------------------------------------------------------------------------------------------------
  2239. /** doCameoFlash */
  2240. //-------------------------------------------------------------------------------------------------
  2241. void ScriptActions::doCameoFlash(const AsciiString& name, Int timeInSeconds)
  2242. {
  2243. const CommandButton *button;
  2244. //sanity
  2245. button = TheControlBar->findCommandButton( name );
  2246. if( button == NULL )
  2247. {
  2248. DEBUG_CRASH(( "ScriptActions::doCameoFlash can't find AsciiString cameoflash" ));
  2249. }
  2250. Int frames = LOGICFRAMES_PER_SECOND * timeInSeconds;
  2251. // every time the framecount % 20 == 0, controlbar:: update will do Cameo Flash
  2252. Int count = frames / DRAWABLE_FRAMES_PER_FLASH;
  2253. // make sure count is even, so the cameo will return to its original state
  2254. if( count % 2 == 1 )
  2255. count++;
  2256. button->setFlashCount(count);
  2257. TheControlBar->setFlash( TRUE );
  2258. }
  2259. //-------------------------------------------------------------------------------------------------
  2260. /** doNamedCustomColor */
  2261. //-------------------------------------------------------------------------------------------------
  2262. void ScriptActions::doNamedCustomColor(const AsciiString& unitName, Color c)
  2263. {
  2264. //sanity
  2265. Object *obj = TheScriptEngine->getUnitNamed( unitName );
  2266. if ( !obj )
  2267. {
  2268. return;
  2269. }
  2270. obj->setCustomIndicatorColor(c);
  2271. }
  2272. //-------------------------------------------------------------------------------------------------
  2273. /** doNamedFlash */
  2274. //-------------------------------------------------------------------------------------------------
  2275. void ScriptActions::doNamedFlash(const AsciiString& unitName, Int timeInSeconds, const RGBColor *color)
  2276. {
  2277. /** This is called the first time this unit is told by the script to flash. timeInSeconds will tell the drawable
  2278. how long to flash for. Sets drawable to start flashing but only allows drawable's update to
  2279. call the actual flash method */
  2280. //sanity
  2281. Object *obj = TheScriptEngine->getUnitNamed( unitName );
  2282. if ( !obj )
  2283. {
  2284. return;
  2285. }
  2286. Drawable *drawable = obj->getDrawable();
  2287. if( !drawable )
  2288. {
  2289. return;
  2290. }
  2291. if( timeInSeconds > 0 )
  2292. {
  2293. // set count for drawable, but do not flash, allow drawable update to handle it
  2294. /* The designer specifies how long he wants the unit to flash for. We will
  2295. convert this number into a count of how many times to call the doNamedFlash method */
  2296. Int frames = LOGICFRAMES_PER_SECOND * timeInSeconds;
  2297. // every time the framecount % 20 == 0, drawable::update will call doNamedFlash
  2298. Int count = frames / DRAWABLE_FRAMES_PER_FLASH;
  2299. Color flashy = (color == NULL) ? obj->getIndicatorColor() : color->getAsInt();
  2300. drawable->setFlashColor( flashy );
  2301. drawable->setFlashCount( count );
  2302. return;
  2303. }
  2304. }
  2305. //-------------------------------------------------------------------------------------------------
  2306. /** doTeamFlash */
  2307. //-------------------------------------------------------------------------------------------------
  2308. void ScriptActions::doTeamFlash(const AsciiString& teamName, Int timeInSeconds, const RGBColor *color)
  2309. {
  2310. Team *team = TheScriptEngine->getTeamNamed( teamName );
  2311. if (team == NULL || !team->hasAnyObjects())
  2312. return;
  2313. DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList();
  2314. while( !iter.done() ) {
  2315. Object *nextObj = iter.cur();
  2316. Object *obj = nextObj;
  2317. if (!obj) {
  2318. break;
  2319. }
  2320. iter.advance();
  2321. Drawable *draw = obj->getDrawable();
  2322. if( !draw )
  2323. break;
  2324. Int frames = LOGICFRAMES_PER_SECOND * timeInSeconds;
  2325. Int count = frames / DRAWABLE_FRAMES_PER_FLASH;
  2326. Color flashy = (color == NULL) ? obj->getIndicatorColor() : color->getAsInt();
  2327. draw->setFlashColor( flashy );
  2328. draw->setFlashCount( count );
  2329. }
  2330. }
  2331. #define ARBITRARY_BUFFER_SIZE 128
  2332. //-------------------------------------------------------------------------------------------------
  2333. /** doMoviePlayFullScreen */
  2334. //-------------------------------------------------------------------------------------------------
  2335. void ScriptActions::doMoviePlayFullScreen(const AsciiString& movieName)
  2336. {
  2337. TheDisplay->playMovie(movieName);
  2338. }
  2339. //-------------------------------------------------------------------------------------------------
  2340. /** doMoviePlayRadar */
  2341. //-------------------------------------------------------------------------------------------------
  2342. void ScriptActions::doMoviePlayRadar(const AsciiString& movieName)
  2343. {
  2344. TheInGameUI->playMovie(movieName);
  2345. }
  2346. //-------------------------------------------------------------------------------------------------
  2347. /** doSoundPlayFromNamed */
  2348. //-------------------------------------------------------------------------------------------------
  2349. void ScriptActions::doSoundPlayFromNamed(const AsciiString& soundName, const AsciiString& unitName)
  2350. {
  2351. Object *pUnit = TheScriptEngine->getUnitNamed(unitName);
  2352. if (!pUnit) {
  2353. return;
  2354. }
  2355. AudioEventRTS sfx(soundName, pUnit->getID());
  2356. sfx.setIsLogicalAudio(true);
  2357. TheAudio->addAudioEvent(&sfx);
  2358. }
  2359. //-------------------------------------------------------------------------------------------------
  2360. /** doSpeechPlay */
  2361. //-------------------------------------------------------------------------------------------------
  2362. void ScriptActions::doSpeechPlay(const AsciiString& speechName, Bool allowOverlap)
  2363. {
  2364. AudioEventRTS speech(speechName);
  2365. speech.setIsLogicalAudio(true);
  2366. speech.setPlayerIndex(ThePlayerList->getLocalPlayer()->getPlayerIndex());
  2367. speech.setUninterruptable(!allowOverlap);
  2368. TheAudio->addAudioEvent(&speech);
  2369. }
  2370. //-------------------------------------------------------------------------------------------------
  2371. /** doPlayerTransferAssetsToPlayer */
  2372. //-------------------------------------------------------------------------------------------------
  2373. void ScriptActions::doPlayerTransferAssetsToPlayer(const AsciiString& playerSrcName, const AsciiString& playerDstName)
  2374. {
  2375. Player *pPlayerDest = TheScriptEngine->getPlayerFromAsciiString(playerDstName);
  2376. Player *pPlayerSrc = TheScriptEngine->getPlayerFromAsciiString(playerSrcName);
  2377. if (!pPlayerDest || !pPlayerSrc) {
  2378. return;
  2379. }
  2380. pPlayerDest->transferAssetsFromThat(pPlayerSrc);
  2381. }
  2382. //-------------------------------------------------------------------------------------------------
  2383. /** doNamedTransferAssetsToPlayer */
  2384. //-------------------------------------------------------------------------------------------------
  2385. void ScriptActions::doNamedTransferAssetsToPlayer(const AsciiString& unitName, const AsciiString& playerDstName)
  2386. {
  2387. Object *pObj = TheScriptEngine->getUnitNamed(unitName);
  2388. Player *pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerDstName);
  2389. if (!pObj || !pPlayer) {
  2390. return;
  2391. }
  2392. Team *playerTeam = pPlayer->getDefaultTeam();
  2393. if (!playerTeam) {
  2394. return;
  2395. }
  2396. pObj->setTeam(playerTeam);
  2397. updateTeamAndPlayerStuff(pObj, NULL);
  2398. }
  2399. //-------------------------------------------------------------------------------------------------
  2400. /** excludePlayerFromScoreScreen */
  2401. //-------------------------------------------------------------------------------------------------
  2402. void ScriptActions::excludePlayerFromScoreScreen(const AsciiString& playerName)
  2403. {
  2404. Player *pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  2405. if (pPlayer == NULL) {
  2406. return;
  2407. }
  2408. pPlayer->setListInScoreScreen(FALSE);
  2409. }
  2410. //-------------------------------------------------------------------------------------------------
  2411. /** excludePlayerFromScoreScreen */
  2412. //-------------------------------------------------------------------------------------------------
  2413. void ScriptActions::enableScoring(Bool score)
  2414. {
  2415. TheGameLogic->enableScoring(score);
  2416. }
  2417. //-------------------------------------------------------------------------------------------------
  2418. /** updatePlayerRelationTowardPlayer */
  2419. //-------------------------------------------------------------------------------------------------
  2420. void ScriptActions::updatePlayerRelationTowardPlayer(const AsciiString& playerSrcName, Int relationType, const AsciiString& playerDstName)
  2421. {
  2422. Player *pPlayerDest = TheScriptEngine->getPlayerFromAsciiString(playerDstName);
  2423. Player *pPlayerSrc = TheScriptEngine->getPlayerFromAsciiString(playerSrcName);
  2424. if (!pPlayerDest || !pPlayerSrc) {
  2425. return;
  2426. }
  2427. pPlayerSrc->setPlayerRelationship(pPlayerDest, (Relationship) relationType);
  2428. }
  2429. //-------------------------------------------------------------------------------------------------
  2430. /** doRadarCreateEvent */
  2431. //-------------------------------------------------------------------------------------------------
  2432. void ScriptActions::doRadarCreateEvent(Coord3D *pos, Int eventType)
  2433. {
  2434. TheRadar->createEvent(pos, (RadarEventType)eventType);
  2435. }
  2436. //-------------------------------------------------------------------------------------------------
  2437. /** doObjectRadarCreateEvent */
  2438. //-------------------------------------------------------------------------------------------------
  2439. void ScriptActions::doObjectRadarCreateEvent(const AsciiString& unitName, Int eventType)
  2440. {
  2441. // get the building
  2442. Object *theBuilding = TheScriptEngine->getUnitNamed( unitName );
  2443. if (!theBuilding)
  2444. return;
  2445. // get building's position
  2446. const Coord3D *pos = theBuilding->getPosition();
  2447. if (!pos)
  2448. return;
  2449. // create event
  2450. TheRadar->createEvent(pos, (RadarEventType)eventType);
  2451. }
  2452. //-------------------------------------------------------------------------------------------------
  2453. /** doTeamRadarCreateEvent */
  2454. //-------------------------------------------------------------------------------------------------
  2455. void ScriptActions::doTeamRadarCreateEvent(const AsciiString& teamName, Int eventType)
  2456. {
  2457. // get the team
  2458. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  2459. if (!theTeam)
  2460. return;
  2461. if (!theTeam->hasAnyUnits())
  2462. return;
  2463. // get team's position
  2464. const Coord3D *pos = theTeam->getEstimateTeamPosition();
  2465. if (!pos)
  2466. return;
  2467. // create event
  2468. TheRadar->createEvent(pos, (RadarEventType)eventType);
  2469. }
  2470. //-------------------------------------------------------------------------------------------------
  2471. /** doRadarDisable */
  2472. //-------------------------------------------------------------------------------------------------
  2473. void ScriptActions::doRadarDisable(void)
  2474. {
  2475. TheRadar->hide(true);
  2476. }
  2477. //-------------------------------------------------------------------------------------------------
  2478. /** doRadarEnable */
  2479. //-------------------------------------------------------------------------------------------------
  2480. void ScriptActions::doRadarEnable(void)
  2481. {
  2482. TheRadar->hide(false);
  2483. }
  2484. //-------------------------------------------------------------------------------------------------
  2485. /** doCameraMotionBlurJump - zoom in at the current location, jump to waypoint, and zoom out.*/
  2486. //-------------------------------------------------------------------------------------------------
  2487. void ScriptActions::doCameraMotionBlurJump(const AsciiString& waypointName, Bool saturate)
  2488. {
  2489. Waypoint *way = TheTerrainLogic->getWaypointByName(waypointName);
  2490. if (!way) {
  2491. return;
  2492. }
  2493. Bool passed = FALSE; //assume all filters were applied correctly.
  2494. Coord3D pos = *way->getLocation();
  2495. if (TheTacticalView->setViewFilter(FT_VIEW_MOTION_BLUR_FILTER))
  2496. {
  2497. passed = TRUE;
  2498. if (saturate) {
  2499. if (!TheTacticalView->setViewFilterMode(FM_VIEW_MB_IN_AND_OUT_SATURATE))
  2500. { //failed to set filter so restore default state
  2501. TheTacticalView->setViewFilter(FT_NULL_FILTER);
  2502. passed = FALSE;
  2503. }
  2504. } else {
  2505. if (!TheTacticalView->setViewFilterMode(FM_VIEW_MB_IN_AND_OUT_ALPHA))
  2506. { //failed to set filter so restore default state
  2507. TheTacticalView->setViewFilter(FT_NULL_FILTER);
  2508. passed = FALSE;
  2509. };
  2510. }
  2511. if (passed)
  2512. TheTacticalView->setViewFilterPos(&pos);
  2513. }
  2514. if (!passed)
  2515. { //if we failed to apply the filter, we still need to get the camera to the target
  2516. //so do it another way:
  2517. TheTacticalView->lookAt(&pos);
  2518. }
  2519. }
  2520. //-------------------------------------------------------------------------------------------------
  2521. /** doCameraMotionBlurJump - zoom in at the current location, jump to waypoint, and zoom out.*/
  2522. //-------------------------------------------------------------------------------------------------
  2523. void ScriptActions::doCameraMotionBlur(Bool zoomIn, Bool saturate)
  2524. {
  2525. if (TheTacticalView->setViewFilter(FT_VIEW_MOTION_BLUR_FILTER))
  2526. {
  2527. enum FilterModes mode;
  2528. if (saturate) {
  2529. if (zoomIn) {
  2530. mode = FM_VIEW_MB_IN_SATURATE;
  2531. } else {
  2532. mode = FM_VIEW_MB_OUT_SATURATE;
  2533. }
  2534. } else {
  2535. if (zoomIn) {
  2536. mode = FM_VIEW_MB_IN_ALPHA;
  2537. } else {
  2538. mode = FM_VIEW_MB_OUT_ALPHA;
  2539. }
  2540. }
  2541. if (!TheTacticalView->setViewFilterMode(mode))
  2542. { //failed to set the filter so restore everything to normal
  2543. TheTacticalView->setViewFilter(FT_NULL_FILTER);
  2544. }
  2545. }
  2546. }
  2547. static PlayerMaskType getHumanPlayerMask( void )
  2548. {
  2549. PlayerMaskType mask;
  2550. for (Int i=0; i<ThePlayerList->getPlayerCount(); ++i)
  2551. {
  2552. const Player *player = ThePlayerList->getNthPlayer(i);
  2553. if (player->getPlayerType() == PLAYER_HUMAN)
  2554. mask &= player->getPlayerMask();
  2555. }
  2556. //DEBUG_LOG(("getHumanPlayerMask(): mask was %4.4X\n", mask));
  2557. return mask;
  2558. }
  2559. //-------------------------------------------------------------------------------------------------
  2560. /** doRevealMapAtWaypoint */
  2561. //-------------------------------------------------------------------------------------------------
  2562. void ScriptActions::doRevealMapAtWaypoint(const AsciiString& waypointName, Real radiusToReveal, const AsciiString& playerName)
  2563. {
  2564. Waypoint *way = TheTerrainLogic->getWaypointByName(waypointName);
  2565. if (!way) {
  2566. return;
  2567. }
  2568. Player* player = TheScriptEngine->getPlayerFromAsciiString(playerName);
  2569. PlayerMaskType playerMask;
  2570. if (player && playerName.isNotEmpty())
  2571. playerMask = player->getPlayerMask();
  2572. else
  2573. playerMask = getHumanPlayerMask();
  2574. Real positionX = way->getLocation()->x;
  2575. Real positionY = way->getLocation()->y;
  2576. // A reveal script is a quick look. That way a Radar Jammer will still function correctly.
  2577. ThePartitionManager->doShroudReveal(positionX, positionY, radiusToReveal, playerMask);
  2578. ThePartitionManager->undoShroudReveal(positionX, positionY, radiusToReveal, playerMask);
  2579. }
  2580. //-------------------------------------------------------------------------------------------------
  2581. /** doRevealMapAtWaypoint */
  2582. //-------------------------------------------------------------------------------------------------
  2583. void ScriptActions::doShroudMapAtWaypoint(const AsciiString& waypointName, Real radiusToShroud, const AsciiString& playerName)
  2584. {
  2585. Waypoint *way = TheTerrainLogic->getWaypointByName(waypointName);
  2586. if (!way) {
  2587. return;
  2588. }
  2589. Player* player = TheScriptEngine->getPlayerFromAsciiString(playerName);
  2590. PlayerMaskType playerMask;
  2591. if (player && playerName.isNotEmpty())
  2592. playerMask = player->getPlayerMask();
  2593. else
  2594. playerMask = getHumanPlayerMask();
  2595. Real positionX = way->getLocation()->x;
  2596. Real positionY = way->getLocation()->y;
  2597. // Likewise, this script does a dollop of shroud. Not permanent active shroud
  2598. ThePartitionManager->doShroudCover(positionX, positionY, radiusToShroud, playerMask);
  2599. ThePartitionManager->undoShroudCover(positionX, positionY, radiusToShroud, playerMask);
  2600. }
  2601. //-------------------------------------------------------------------------------------------------
  2602. /** doRevealMapEntire */
  2603. //-------------------------------------------------------------------------------------------------
  2604. void ScriptActions::doRevealMapEntire(const AsciiString& playerName)
  2605. {
  2606. DEBUG_LOG(("ScriptActions::doRevealMapEntire() for player named '%s'\n", playerName.str()));
  2607. Player* player = TheScriptEngine->getPlayerFromAsciiString(playerName);
  2608. if (player && playerName.isNotEmpty())
  2609. {
  2610. DEBUG_LOG(("ScriptActions::doRevealMapEntire() for player named '%ls' in position %d\n", player->getPlayerDisplayName().str(), player->getPlayerIndex()));
  2611. ThePartitionManager->revealMapForPlayer( player->getPlayerIndex() );
  2612. }
  2613. else
  2614. {
  2615. DEBUG_LOG(("ScriptActions::doRevealMapEntire() - no player, so doing all human players\n"));
  2616. for (Int i=0; i<ThePlayerList->getPlayerCount(); ++i)
  2617. {
  2618. Player *player = ThePlayerList->getNthPlayer(i);
  2619. if (player->getPlayerType() == PLAYER_HUMAN)
  2620. {
  2621. DEBUG_LOG(("ScriptActions::doRevealMapEntire() for player %d\n", i));
  2622. ThePartitionManager->revealMapForPlayer( i );
  2623. }
  2624. }
  2625. }
  2626. }
  2627. void ScriptActions::doRevealMapEntirePermanently( Bool reveal, const AsciiString& playerName )
  2628. {
  2629. Player* player = TheScriptEngine->getPlayerFromAsciiString(playerName);
  2630. if (player && playerName.isNotEmpty())
  2631. {
  2632. if( reveal )
  2633. ThePartitionManager->revealMapForPlayerPermanently( player->getPlayerIndex() );
  2634. else
  2635. ThePartitionManager->undoRevealMapForPlayerPermanently( player->getPlayerIndex() );
  2636. }
  2637. else
  2638. {
  2639. for (Int i=0; i<ThePlayerList->getPlayerCount(); ++i)
  2640. {
  2641. Player *player = ThePlayerList->getNthPlayer(i);
  2642. if (player->getPlayerType() == PLAYER_HUMAN)
  2643. {
  2644. DEBUG_LOG(("ScriptActions::doRevealMapEntirePermanently() for player %d\n", i));
  2645. if( reveal )
  2646. ThePartitionManager->revealMapForPlayerPermanently( i );
  2647. else
  2648. ThePartitionManager->undoRevealMapForPlayerPermanently( i );
  2649. }
  2650. }
  2651. }
  2652. }
  2653. //-------------------------------------------------------------------------------------------------
  2654. /** doShroudMapEntire */
  2655. //-------------------------------------------------------------------------------------------------
  2656. void ScriptActions::doShroudMapEntire(const AsciiString& playerName)
  2657. {
  2658. Player* player = TheScriptEngine->getPlayerFromAsciiString(playerName);
  2659. if (player && playerName.isNotEmpty())
  2660. {
  2661. ThePartitionManager->shroudMapForPlayer( player->getPlayerIndex() );
  2662. }
  2663. else
  2664. {
  2665. for (Int i=0; i<ThePlayerList->getPlayerCount(); ++i)
  2666. {
  2667. Player *player = ThePlayerList->getNthPlayer(i);
  2668. if (player->getPlayerType() == PLAYER_HUMAN)
  2669. {
  2670. DEBUG_LOG(("ScriptActions::doShroudMapEntire() for player %d\n", i));
  2671. ThePartitionManager->shroudMapForPlayer( i );
  2672. }
  2673. }
  2674. }
  2675. }
  2676. //-------------------------------------------------------------------------------------------------
  2677. /** doTeamAvailableForRecruitment */
  2678. //-------------------------------------------------------------------------------------------------
  2679. void ScriptActions::doTeamAvailableForRecruitment(const AsciiString& teamName, Bool availability)
  2680. {
  2681. Team *theTeam = TheScriptEngine->getTeamNamed(teamName);
  2682. if (!theTeam) {
  2683. return;
  2684. }
  2685. theTeam->setRecruitable(availability);
  2686. }
  2687. //-------------------------------------------------------------------------------------------------
  2688. /** doCollectNearbyForTeam */
  2689. //-------------------------------------------------------------------------------------------------
  2690. void ScriptActions::doCollectNearbyForTeam(const AsciiString& teamName)
  2691. {
  2692. DEBUG_CRASH(("You would think this has been implemented, but you'd be wrong. (doCollectNearbyForTeam)"));
  2693. }
  2694. //-------------------------------------------------------------------------------------------------
  2695. /** doMergeTeamIntoTeam */
  2696. //-------------------------------------------------------------------------------------------------
  2697. void ScriptActions::doMergeTeamIntoTeam(const AsciiString& teamSrcName, const AsciiString& teamDestName)
  2698. {
  2699. Team *teamSrc = TheScriptEngine->getTeamNamed(teamSrcName);
  2700. Team *teamDest = TheScriptEngine->getTeamNamed(teamDestName);
  2701. if (teamDest==NULL) {
  2702. teamDest = TheTeamFactory->findTeam( teamDestName );
  2703. }
  2704. if (!teamSrc || !teamDest) {
  2705. return;
  2706. }
  2707. // Bool done = FALSE;
  2708. DLINK_ITERATOR<Object> iter = teamSrc->iterate_TeamMemberList();
  2709. Object *nextObj = iter.cur();
  2710. while (!iter.done()) {
  2711. Object *obj = nextObj;
  2712. if (!obj) {
  2713. break;
  2714. }
  2715. // this has to be done here, setting the team will screw up the iterator. total bummer dude. jkmcd
  2716. nextObj = iter.cur();
  2717. iter.advance();
  2718. obj->setTeam(teamDest);
  2719. updateTeamAndPlayerStuff(obj, NULL);
  2720. }
  2721. if (nextObj) {
  2722. nextObj->setTeam(teamDest);
  2723. updateTeamAndPlayerStuff(nextObj, NULL);
  2724. }
  2725. teamSrc->deleteTeam();
  2726. teamDest->setActive(); // in case we just created him.
  2727. }
  2728. //-------------------------------------------------------------------------------------------------
  2729. /** doDisableInput */
  2730. //-------------------------------------------------------------------------------------------------
  2731. void ScriptActions::doDisableInput()
  2732. {
  2733. #if defined(_DEBUG) || defined(_INTERNAL)
  2734. if (!TheGlobalData->m_disableScriptedInputDisabling)
  2735. #endif
  2736. {
  2737. TheInGameUI->setInputEnabled(false);
  2738. TheMouse->setVisibility(false);
  2739. TheInGameUI->deselectAllDrawables();
  2740. TheInGameUI->clearAttackMoveToMode();
  2741. TheInGameUI->setWaypointMode( FALSE );
  2742. TheControlBar->deleteBuildTooltipLayout();
  2743. TheLookAtTranslator->resetModes();
  2744. }
  2745. }
  2746. //-------------------------------------------------------------------------------------------------
  2747. /** doEnableInput */
  2748. //-------------------------------------------------------------------------------------------------
  2749. void ScriptActions::doEnableInput()
  2750. {
  2751. TheInGameUI->setInputEnabled(true);
  2752. TheMouse->setVisibility(true);
  2753. }
  2754. //-------------------------------------------------------------------------------------------------
  2755. /** doSetBorderShroud */
  2756. //-------------------------------------------------------------------------------------------------
  2757. void ScriptActions::doSetBorderShroud( Bool setting )
  2758. {
  2759. if( setting )
  2760. TheDisplay->setBorderShroudLevel(TheGlobalData->m_shroudAlpha);
  2761. else
  2762. TheDisplay->setBorderShroudLevel(TheGlobalData->m_clearAlpha);
  2763. }
  2764. //-------------------------------------------------------------------------------------------------
  2765. /** doIdleAllPlayerUnits */
  2766. //-------------------------------------------------------------------------------------------------
  2767. void ScriptActions::doIdleAllPlayerUnits(const AsciiString& playerName)
  2768. {
  2769. Player* player = TheScriptEngine->getPlayerFromAsciiString(playerName);
  2770. if (player && playerName.isNotEmpty())
  2771. {
  2772. player->setUnitsShouldIdleOrResume(true);
  2773. }
  2774. else
  2775. {
  2776. for (Int i=0; i<ThePlayerList->getPlayerCount(); ++i)
  2777. {
  2778. Player *player = ThePlayerList->getNthPlayer(i);
  2779. if (player->getPlayerType() == PLAYER_HUMAN)
  2780. {
  2781. DEBUG_LOG(("ScriptActions::doIdleAllPlayerUnits() for player %d\n", i));
  2782. player->setUnitsShouldIdleOrResume(true);
  2783. }
  2784. }
  2785. }
  2786. }
  2787. //-------------------------------------------------------------------------------------------------
  2788. /** doResumeSupplyTruckingForIdleUnits */
  2789. //-------------------------------------------------------------------------------------------------
  2790. void ScriptActions::doResumeSupplyTruckingForIdleUnits(const AsciiString& playerName)
  2791. {
  2792. Player* player = TheScriptEngine->getPlayerFromAsciiString(playerName);
  2793. if (player && playerName.isNotEmpty())
  2794. {
  2795. player->setUnitsShouldIdleOrResume(false);
  2796. }
  2797. else
  2798. {
  2799. for (Int i=0; i<ThePlayerList->getPlayerCount(); ++i)
  2800. {
  2801. Player *player = ThePlayerList->getNthPlayer(i);
  2802. if (player->getPlayerType() == PLAYER_HUMAN)
  2803. {
  2804. DEBUG_LOG(("ScriptActions::doResumeSupplyTruckingForIdleUnits() for player %d\n", i));
  2805. player->setUnitsShouldIdleOrResume(false);
  2806. }
  2807. }
  2808. }
  2809. }
  2810. //-------------------------------------------------------------------------------------------------
  2811. /** doAmbientSoundsPause */
  2812. //-------------------------------------------------------------------------------------------------
  2813. void ScriptActions::doAmbientSoundsPause(Bool pausing) // if true, then pause, if false then resume.
  2814. {
  2815. TheAudio->pauseAmbient(pausing);
  2816. }
  2817. //-------------------------------------------------------------------------------------------------
  2818. /** doMusicTrackChange */
  2819. //-------------------------------------------------------------------------------------------------
  2820. void ScriptActions::doMusicTrackChange(const AsciiString& newTrackName, Bool fadeout, Bool fadein)
  2821. {
  2822. // Stop playing the music
  2823. if (fadeout) {
  2824. TheAudio->removeAudioEvent(AHSV_StopTheMusicFade);
  2825. } else {
  2826. TheAudio->removeAudioEvent(AHSV_StopTheMusic);
  2827. }
  2828. AudioEventRTS event(newTrackName);
  2829. event.setShouldFade(fadein);
  2830. event.setPlayerIndex(ThePlayerList->getLocalPlayer()->getPlayerIndex());
  2831. TheAudio->addAudioEvent(&event);
  2832. TheScriptEngine->setCurrentTrackName(newTrackName);
  2833. }
  2834. //-------------------------------------------------------------------------------------------------
  2835. /** doTeamGarrisonSpecificBuilding */
  2836. //-------------------------------------------------------------------------------------------------
  2837. void ScriptActions::doTeamGarrisonSpecificBuilding(const AsciiString& teamName, const AsciiString& buildingName)
  2838. {
  2839. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  2840. if (!theTeam) {
  2841. return;
  2842. }
  2843. Object *theBuilding = TheScriptEngine->getUnitNamed(buildingName);
  2844. if (!theBuilding) {
  2845. return;
  2846. }
  2847. if( !theBuilding->getContain() )
  2848. {
  2849. DEBUG_CRASH( ("doTeamGarrisonSpecificBuilding script -- building doesn't have a container!" ) );
  2850. return;
  2851. }
  2852. PlayerMaskType player = theBuilding->getContain()->getPlayerWhoEntered();
  2853. if (!(theBuilding->isKindOf(KINDOF_STRUCTURE) &&
  2854. (player == 0) || (player == theTeam->getControllingPlayer()->getPlayerMask()))) {
  2855. return;
  2856. }
  2857. AIGroup* theGroup = TheAI->createGroup();
  2858. if (!theGroup) {
  2859. return;
  2860. }
  2861. theTeam->getTeamAsAIGroup(theGroup);
  2862. theGroup->groupEnter(theBuilding, CMD_FROM_SCRIPT);
  2863. }
  2864. //-------------------------------------------------------------------------------------------------
  2865. /** doExitSpecificBuilding */
  2866. //-------------------------------------------------------------------------------------------------
  2867. void ScriptActions::doExitSpecificBuilding(const AsciiString& buildingName)
  2868. {
  2869. Object *theBuilding = TheScriptEngine->getUnitNamed(buildingName);
  2870. if (!theBuilding)
  2871. {
  2872. return;
  2873. }
  2874. if (!theBuilding->isKindOf(KINDOF_STRUCTURE))
  2875. {
  2876. return;
  2877. }
  2878. AIUpdateInterface *ai = theBuilding->getAIUpdateInterface();
  2879. if (ai)
  2880. {
  2881. ai->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  2882. ai->aiEvacuate( FALSE, CMD_FROM_SCRIPT );
  2883. return;
  2884. }
  2885. ContainModuleInterface *contain = theBuilding->getContain();
  2886. if (contain)
  2887. {
  2888. contain->removeAllContained( FALSE );
  2889. }
  2890. }
  2891. //-------------------------------------------------------------------------------------------------
  2892. /** doTeamGarrisonNearestBuilding */
  2893. //-------------------------------------------------------------------------------------------------
  2894. void ScriptActions::doTeamGarrisonNearestBuilding(const AsciiString& teamName)
  2895. {
  2896. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  2897. if (!theTeam) {
  2898. return;
  2899. }
  2900. DLINK_ITERATOR<Object> diter = theTeam->iterate_TeamMemberList();
  2901. Object *leader = diter.cur();
  2902. if (!leader) {
  2903. return;
  2904. }
  2905. PartitionFilterGarrisonableByPlayer f1(theTeam->getControllingPlayer(), true, CMD_FROM_SCRIPT);
  2906. PartitionFilterSameMapStatus filterMapStatus(leader);
  2907. PartitionFilter *filters[] = { &f1, &filterMapStatus, NULL };
  2908. ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange(leader, REALLY_FAR, FROM_CENTER_3D, filters, ITER_SORTED_NEAR_TO_FAR);
  2909. MemoryPoolObjectHolder hold(iter);
  2910. // here's what we do. Find out how many slots each building has open, and tell each unit individually to
  2911. // garrison a specific building. We won't use the partition solver because we've already done most of the work
  2912. for (Object *theBuilding = iter->first(); theBuilding; theBuilding = iter->next()) {
  2913. ContainModuleInterface *cmi = theBuilding->getContain();
  2914. if (!cmi) {
  2915. continue;
  2916. }
  2917. Int slotsAvailable = cmi->getContainMax() - cmi->getContainCount();
  2918. for (int i = 0; i < slotsAvailable; ) {
  2919. Object *obj = diter.cur();
  2920. if (diter.done() || !obj) {
  2921. return;
  2922. }
  2923. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  2924. if (ai && obj->isKindOf(KINDOF_INFANTRY) && !obj->isKindOf(KINDOF_NO_GARRISON)) {
  2925. ai->aiEnter(theBuilding, CMD_FROM_SCRIPT);
  2926. ++i;
  2927. }
  2928. diter.advance();
  2929. }
  2930. }
  2931. }
  2932. //-------------------------------------------------------------------------------------------------
  2933. /** doTeamExitAllBuildings */
  2934. //-------------------------------------------------------------------------------------------------
  2935. void ScriptActions::doTeamExitAllBuildings(const AsciiString& teamName)
  2936. {
  2937. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  2938. if (!theTeam) {
  2939. return;
  2940. }
  2941. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance()) {
  2942. Object *obj = iter.cur();
  2943. if (!obj) {
  2944. continue;
  2945. }
  2946. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  2947. if (!ai) {
  2948. continue;
  2949. }
  2950. ai->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  2951. ai->aiExit(NULL, CMD_FROM_SCRIPT);
  2952. }
  2953. }
  2954. //-------------------------------------------------------------------------------------------------
  2955. /** doUnitGarrisonSpecificBuilding */
  2956. //-------------------------------------------------------------------------------------------------
  2957. void ScriptActions::doUnitGarrisonSpecificBuilding(const AsciiString& unitName, const AsciiString& buildingName)
  2958. {
  2959. Object *theUnit = TheScriptEngine->getUnitNamed( unitName );
  2960. if (!theUnit) {
  2961. return;
  2962. }
  2963. Object *theBuilding = TheScriptEngine->getUnitNamed(buildingName);
  2964. if (!theBuilding) {
  2965. return;
  2966. }
  2967. ContainModuleInterface *contain = theBuilding->getContain();
  2968. if( !contain )
  2969. {
  2970. DEBUG_CRASH(("doUnitGarrisonSpecificBuilding script -- building doesn't have a container" ));
  2971. return;
  2972. }
  2973. PlayerMaskType player = theBuilding->getContain()->getPlayerWhoEntered();
  2974. if (!(theBuilding->isKindOf(KINDOF_STRUCTURE) &&
  2975. (player == 0) || (player == theUnit->getControllingPlayer()->getPlayerMask()))) {
  2976. return;
  2977. }
  2978. AIUpdateInterface *ai = theUnit->getAIUpdateInterface();
  2979. if (!ai) {
  2980. return;
  2981. }
  2982. ai->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  2983. ai->aiEnter(theBuilding, CMD_FROM_SCRIPT);
  2984. }
  2985. //-------------------------------------------------------------------------------------------------
  2986. /** doUnitGarrisonNearestBuilding */
  2987. //-------------------------------------------------------------------------------------------------
  2988. void ScriptActions::doUnitGarrisonNearestBuilding(const AsciiString& unitName)
  2989. {
  2990. Object *theUnit = TheScriptEngine->getUnitNamed( unitName );
  2991. if (!theUnit) {
  2992. return;
  2993. }
  2994. AIUpdateInterface *ai = theUnit->getAIUpdateInterface();
  2995. if (!ai) {
  2996. return;
  2997. }
  2998. PartitionFilterAcceptByKindOf f1(MAKE_KINDOF_MASK(KINDOF_STRUCTURE), KINDOFMASK_NONE);
  2999. PartitionFilterSameMapStatus filterMapStatus(theUnit);
  3000. PartitionFilter *filters[] = { &f1, &filterMapStatus, NULL };
  3001. ObjectIterator *iter = ThePartitionManager->iterateObjectsInRange(theUnit, REALLY_FAR, FROM_CENTER_3D, filters, ITER_SORTED_NEAR_TO_FAR);
  3002. MemoryPoolObjectHolder hold(iter);
  3003. for (Object *theBuilding = iter->first(); theBuilding; theBuilding = iter->next())
  3004. {
  3005. ContainModuleInterface *contain = theBuilding->getContain();
  3006. if( !contain )
  3007. {
  3008. DEBUG_CRASH( ("doUnitGarrisonNearestBuilding script -- building doesn't have a container.") );
  3009. continue;
  3010. }
  3011. PlayerMaskType player = theBuilding->getContain()->getPlayerWhoEntered();
  3012. if (!((player == 0) || (player == theUnit->getControllingPlayer()->getPlayerMask()))) {
  3013. continue;
  3014. }
  3015. ai->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  3016. ai->aiEnter(theBuilding, CMD_FROM_SCRIPT);
  3017. return;
  3018. }
  3019. }
  3020. //-------------------------------------------------------------------------------------------------
  3021. /** doNamedEnableStealth */
  3022. //-------------------------------------------------------------------------------------------------
  3023. void ScriptActions::doNamedEnableStealth( const AsciiString& unitName, Bool enabled )
  3024. {
  3025. Object *self = TheScriptEngine->getUnitNamed( unitName );
  3026. if( self )
  3027. {
  3028. self->setScriptStatus( OBJECT_STATUS_SCRIPT_UNSTEALTHED, !enabled );
  3029. }
  3030. }
  3031. //-------------------------------------------------------------------------------------------------
  3032. /** doTeamEnableStealth */
  3033. //-------------------------------------------------------------------------------------------------
  3034. void ScriptActions::doTeamEnableStealth( const AsciiString& teamName, Bool enabled )
  3035. {
  3036. Team *team = TheScriptEngine->getTeamNamed( teamName );
  3037. if( !team )
  3038. {
  3039. return;
  3040. }
  3041. for( DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance() )
  3042. {
  3043. Object *obj = iter.cur();
  3044. if( obj )
  3045. {
  3046. obj->setScriptStatus( OBJECT_STATUS_SCRIPT_UNSTEALTHED, !enabled );
  3047. }
  3048. }
  3049. }
  3050. //-------------------------------------------------------------------------------------------------
  3051. /** doUnitExitBuilding */
  3052. //-------------------------------------------------------------------------------------------------
  3053. void ScriptActions::doUnitExitBuilding(const AsciiString& unitName)
  3054. {
  3055. Object *theUnit = TheScriptEngine->getUnitNamed( unitName );
  3056. if (!theUnit) {
  3057. return;
  3058. }
  3059. AIUpdateInterface *ai = theUnit->getAIUpdateInterface();
  3060. if (!ai) {
  3061. return;
  3062. }
  3063. ai->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  3064. ai->aiExit(NULL, CMD_FROM_SCRIPT);
  3065. }
  3066. //-------------------------------------------------------------------------------------------------
  3067. /** doPlayerGarrisonAllBuildings */
  3068. //-------------------------------------------------------------------------------------------------
  3069. void ScriptActions::doPlayerGarrisonAllBuildings(const AsciiString& playerName)
  3070. {
  3071. Player* player = TheScriptEngine->getPlayerFromAsciiString(playerName);
  3072. if (!player) {
  3073. return;
  3074. }
  3075. player->garrisonAllUnits(CMD_FROM_SCRIPT);
  3076. }
  3077. //-------------------------------------------------------------------------------------------------
  3078. /** doPlayerExitAllBuildings */
  3079. //-------------------------------------------------------------------------------------------------
  3080. void ScriptActions::doPlayerExitAllBuildings(const AsciiString& playerName)
  3081. {
  3082. Player* player = TheScriptEngine->getPlayerFromAsciiString(playerName);
  3083. if (!player) {
  3084. return;
  3085. }
  3086. player->ungarrisonAllUnits(CMD_FROM_SCRIPT);
  3087. }
  3088. //-------------------------------------------------------------------------------------------------
  3089. /** doLetterBoxMode */
  3090. //-------------------------------------------------------------------------------------------------
  3091. void ScriptActions::doLetterBoxMode(Bool startLetterbox)
  3092. {
  3093. if (startLetterbox)
  3094. {
  3095. HideControlBar(TRUE);
  3096. TheDisplay->enableLetterBox(TRUE);
  3097. }
  3098. else
  3099. {
  3100. ShowControlBar(FALSE);
  3101. TheDisplay->enableLetterBox(FALSE);
  3102. }
  3103. }
  3104. //-------------------------------------------------------------------------------------------------
  3105. /** doBlackWhiteMode */
  3106. //-------------------------------------------------------------------------------------------------
  3107. void ScriptActions::doBlackWhiteMode(Bool startBWMode, Int frames)
  3108. {
  3109. if (startBWMode)
  3110. {
  3111. TheTacticalView->setViewFilterMode(FM_VIEW_BW_BLACK_AND_WHITE);
  3112. TheTacticalView->setViewFilter(FT_VIEW_BW_FILTER);
  3113. TheTacticalView->setFadeParameters(frames, 1);
  3114. }
  3115. else
  3116. {
  3117. if ((TheTacticalView->getViewFilterType()) == FT_VIEW_BW_FILTER)
  3118. { //mode already set, turn it off
  3119. TheTacticalView->setFadeParameters(frames, -1);
  3120. }
  3121. }
  3122. }
  3123. //-------------------------------------------------------------------------------------------------
  3124. /** doSkyBox */
  3125. //-------------------------------------------------------------------------------------------------
  3126. extern void doSkyBoxSet(Bool startDraw); //hack to avoid including globaldata here.
  3127. void ScriptActions::doSkyBox(Bool startDraw)
  3128. {
  3129. if (startDraw)
  3130. {
  3131. doSkyBoxSet(1);
  3132. }
  3133. else
  3134. {
  3135. doSkyBoxSet(0);
  3136. }
  3137. }
  3138. //-------------------------------------------------------------------------------------------------
  3139. /** Freeze time */
  3140. //-------------------------------------------------------------------------------------------------
  3141. void ScriptActions::doFreezeTime(void)
  3142. {
  3143. TheScriptEngine->doFreezeTime();
  3144. }
  3145. //-------------------------------------------------------------------------------------------------
  3146. /** Unfreeze time */
  3147. //-------------------------------------------------------------------------------------------------
  3148. void ScriptActions::doUnfreezeTime(void)
  3149. {
  3150. TheScriptEngine->doUnfreezeTime();
  3151. }
  3152. //-------------------------------------------------------------------------------------------------
  3153. /** Show a military briefing */
  3154. //-------------------------------------------------------------------------------------------------
  3155. void ScriptActions::doMilitaryCaption(const AsciiString& briefing, Int duration)
  3156. {
  3157. #if defined(_DEBUG) || defined(_INTERNAL)
  3158. if (TheGlobalData->m_disableMilitaryCaption)
  3159. duration = 1;
  3160. #endif
  3161. TheInGameUI->militarySubtitle(briefing, duration);
  3162. }
  3163. //-------------------------------------------------------------------------------------------------
  3164. /** Set the audible distance for shots in which the camera is up, and is therefore the center */
  3165. //-------------------------------------------------------------------------------------------------
  3166. void ScriptActions::doCameraSetAudibleDistance(Real audibleDistance)
  3167. {
  3168. // No-op
  3169. }
  3170. //-------------------------------------------------------------------------------------------------
  3171. /** doSetStoppingDistance */
  3172. //-------------------------------------------------------------------------------------------------
  3173. void ScriptActions::doSetStoppingDistance(const AsciiString& team, Real stoppingDistance)
  3174. {
  3175. Team *theTeam = TheScriptEngine->getTeamNamed( team );
  3176. if (theTeam)
  3177. {
  3178. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance())
  3179. {
  3180. Object *obj = iter.cur();
  3181. AIUpdateInterface *aiUpdate = obj->getAIUpdateInterface();
  3182. if (!aiUpdate || !aiUpdate->getCurLocomotor()) {
  3183. return;
  3184. }
  3185. if (stoppingDistance >= 0.5f)
  3186. {
  3187. aiUpdate->getCurLocomotor()->setCloseEnoughDist(stoppingDistance);
  3188. }
  3189. }
  3190. }
  3191. }
  3192. //-------------------------------------------------------------------------------------------------
  3193. /** doNamedSetHeld */
  3194. //-------------------------------------------------------------------------------------------------
  3195. void ScriptActions::doNamedSetHeld(const AsciiString& unit, Bool held)
  3196. {
  3197. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  3198. if (theObj)
  3199. {
  3200. theObj->setDisabledUntil( DISABLED_HELD, held ? FOREVER : NEVER );
  3201. }
  3202. }
  3203. //-------------------------------------------------------------------------------------------------
  3204. /** doNamedSetStoppingDistance */
  3205. //-------------------------------------------------------------------------------------------------
  3206. void ScriptActions::doNamedSetStoppingDistance(const AsciiString& unit, Real stoppingDistance)
  3207. {
  3208. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  3209. if (theObj)
  3210. {
  3211. AIUpdateInterface *aiUpdate = theObj->getAIUpdateInterface();
  3212. if (!aiUpdate || !aiUpdate->getCurLocomotor()) {
  3213. return;
  3214. }
  3215. if (stoppingDistance >= 0.5f)
  3216. {
  3217. aiUpdate->getCurLocomotor()->setCloseEnoughDist(stoppingDistance);
  3218. }
  3219. }
  3220. }
  3221. //-------------------------------------------------------------------------------------------------
  3222. /** doDisableSpecialPowerDisplay */
  3223. //-------------------------------------------------------------------------------------------------
  3224. void ScriptActions::doDisableSpecialPowerDisplay(void)
  3225. {
  3226. TheInGameUI->setSuperweaponDisplayEnabledByScript(false);
  3227. }
  3228. //-------------------------------------------------------------------------------------------------
  3229. /** doEnableSpecialPowerDisplay */
  3230. //-------------------------------------------------------------------------------------------------
  3231. void ScriptActions::doEnableSpecialPowerDisplay(void)
  3232. {
  3233. TheInGameUI->setSuperweaponDisplayEnabledByScript(true);
  3234. }
  3235. //-------------------------------------------------------------------------------------------------
  3236. /** doNamedHideSpecialPowerDisplay */
  3237. //-------------------------------------------------------------------------------------------------
  3238. void ScriptActions::doNamedHideSpecialPowerDisplay(const AsciiString& unit)
  3239. {
  3240. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  3241. if (theObj)
  3242. {
  3243. TheInGameUI->hideObjectSuperweaponDisplayByScript(theObj);
  3244. }
  3245. }
  3246. //-------------------------------------------------------------------------------------------------
  3247. /** doNamedShowSpecialPowerDisplay */
  3248. //-------------------------------------------------------------------------------------------------
  3249. void ScriptActions::doNamedShowSpecialPowerDisplay(const AsciiString& unit)
  3250. {
  3251. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  3252. if (theObj)
  3253. {
  3254. TheInGameUI->showObjectSuperweaponDisplayByScript(theObj);
  3255. }
  3256. }
  3257. //-------------------------------------------------------------------------------------------------
  3258. /** doAudioSetVolume */
  3259. //-------------------------------------------------------------------------------------------------
  3260. void ScriptActions::doAudioSetVolume(AudioAffect whichToAffect, Real newVolumeLevel)
  3261. {
  3262. newVolumeLevel /= 100.0f;
  3263. if (newVolumeLevel < 0.0f) {
  3264. newVolumeLevel = 0.0f;
  3265. } else if (newVolumeLevel > 1.0f) {
  3266. newVolumeLevel = 1.0f;
  3267. }
  3268. TheAudio->setVolume(newVolumeLevel, whichToAffect);
  3269. }
  3270. //-------------------------------------------------------------------------------------------------
  3271. /** doTransferTeamToPlayer */
  3272. //-------------------------------------------------------------------------------------------------
  3273. void ScriptActions::doTransferTeamToPlayer(const AsciiString& teamName, const AsciiString& playerName)
  3274. {
  3275. Team *theTeam = TheScriptEngine->getTeamNamed(teamName);
  3276. Player* playerDest = TheScriptEngine->getPlayerFromAsciiString(playerName);
  3277. if (!(theTeam && playerDest)) {
  3278. return;
  3279. }
  3280. theTeam->setControllingPlayer(playerDest);
  3281. // srj sez: ensure that all these guys get the upgrades that belong to the new player
  3282. theTeam->iterateObjects(updateTeamAndPlayerStuff, NULL);
  3283. }
  3284. //-------------------------------------------------------------------------------------------------
  3285. /** doSetMoney */
  3286. //-------------------------------------------------------------------------------------------------
  3287. void ScriptActions::doSetMoney(const AsciiString& playerName, Int money)
  3288. {
  3289. Player* player = TheScriptEngine->getPlayerFromAsciiString(playerName);
  3290. if (!player) {
  3291. return;
  3292. }
  3293. Money *m = player->getMoney();
  3294. if (!m)
  3295. return;
  3296. m->withdraw(m->countMoney());
  3297. m->deposit(money);
  3298. }
  3299. //-------------------------------------------------------------------------------------------------
  3300. /** doGiveMoney */
  3301. //-------------------------------------------------------------------------------------------------
  3302. void ScriptActions::doGiveMoney(const AsciiString& playerName, Int money)
  3303. {
  3304. Player* player = TheScriptEngine->getPlayerFromAsciiString(playerName);
  3305. if (!player) {
  3306. return;
  3307. }
  3308. Money *m = player->getMoney();
  3309. if (!m)
  3310. return;
  3311. if (money < 0)
  3312. m->withdraw(-money);
  3313. else
  3314. m->deposit(money);
  3315. }
  3316. //-------------------------------------------------------------------------------------------------
  3317. /** doDisplayCounter */
  3318. //-------------------------------------------------------------------------------------------------
  3319. void ScriptActions::doDisplayCounter(const AsciiString& counterName, const AsciiString& counterText)
  3320. {
  3321. TheInGameUI->addNamedTimer(counterName, TheGameText->fetch(counterText), false);
  3322. }
  3323. //-------------------------------------------------------------------------------------------------
  3324. /** doHideCounter */
  3325. //-------------------------------------------------------------------------------------------------
  3326. void ScriptActions::doHideCounter(const AsciiString& counterName)
  3327. {
  3328. TheInGameUI->removeNamedTimer(counterName);
  3329. }
  3330. //-------------------------------------------------------------------------------------------------
  3331. /** doDisplayCountdownTimer */
  3332. //-------------------------------------------------------------------------------------------------
  3333. void ScriptActions::doDisplayCountdownTimer(const AsciiString& timerName, const AsciiString& timerText)
  3334. {
  3335. TheInGameUI->addNamedTimer(timerName, TheGameText->fetch(timerText), true);
  3336. }
  3337. //-------------------------------------------------------------------------------------------------
  3338. /** doHideCountdownTimer */
  3339. //-------------------------------------------------------------------------------------------------
  3340. void ScriptActions::doHideCountdownTimer(const AsciiString& timerName)
  3341. {
  3342. TheInGameUI->removeNamedTimer(timerName);
  3343. }
  3344. //-------------------------------------------------------------------------------------------------
  3345. /** doDisableCountdownTimerDisplay */
  3346. //-------------------------------------------------------------------------------------------------
  3347. void ScriptActions::doDisableCountdownTimerDisplay(void)
  3348. {
  3349. TheInGameUI->showNamedTimerDisplay(FALSE);
  3350. }
  3351. //-------------------------------------------------------------------------------------------------
  3352. /** doEnableCountdownTimerDisplay */
  3353. //-------------------------------------------------------------------------------------------------
  3354. void ScriptActions::doEnableCountdownTimerDisplay(void)
  3355. {
  3356. TheInGameUI->showNamedTimerDisplay(TRUE);
  3357. }
  3358. //-------------------------------------------------------------------------------------------------
  3359. /** doNamedStopSpecialPowerCountdown */
  3360. //-------------------------------------------------------------------------------------------------
  3361. void ScriptActions::doNamedStopSpecialPowerCountdown(const AsciiString& unit, const AsciiString& specialPower, Bool stop)
  3362. {
  3363. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  3364. const SpecialPowerTemplate *power = TheSpecialPowerStore->findSpecialPowerTemplate(specialPower);
  3365. if (theObj && power)
  3366. {
  3367. SpecialPowerModuleInterface *mod = theObj->getSpecialPowerModule(power);
  3368. if (mod)
  3369. {
  3370. mod->pauseCountdown(stop);
  3371. }
  3372. }
  3373. }
  3374. //-------------------------------------------------------------------------------------------------
  3375. /** doNamedSetSpecialPowerCountdown */
  3376. //-------------------------------------------------------------------------------------------------
  3377. void ScriptActions::doNamedSetSpecialPowerCountdown( const AsciiString& unit, const AsciiString& specialPower, Int seconds )
  3378. {
  3379. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  3380. const SpecialPowerTemplate *power = TheSpecialPowerStore->findSpecialPowerTemplate(specialPower);
  3381. if (theObj && power)
  3382. {
  3383. SpecialPowerModuleInterface *mod = theObj->getSpecialPowerModule(power);
  3384. if (mod)
  3385. {
  3386. Int frames = LOGICFRAMES_PER_SECOND * seconds;
  3387. mod->setReadyFrame(TheGameLogic->getFrame() + frames);
  3388. }
  3389. }
  3390. }
  3391. //-------------------------------------------------------------------------------------------------
  3392. /** doNamedAddSpecialPowerCountdown */
  3393. //-------------------------------------------------------------------------------------------------
  3394. void ScriptActions::doNamedAddSpecialPowerCountdown( const AsciiString& unit, const AsciiString& specialPower, Int seconds )
  3395. {
  3396. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  3397. const SpecialPowerTemplate *power = TheSpecialPowerStore->findSpecialPowerTemplate(specialPower);
  3398. if (theObj && power)
  3399. {
  3400. SpecialPowerModuleInterface *mod = theObj->getSpecialPowerModule(power);
  3401. if (mod)
  3402. {
  3403. Int frames = LOGICFRAMES_PER_SECOND * seconds;
  3404. mod->setReadyFrame(mod->getReadyFrame() + frames);
  3405. }
  3406. }
  3407. }
  3408. //-------------------------------------------------------------------------------------------------
  3409. /** doNamedFireSpecialPowerAtArea */
  3410. //-------------------------------------------------------------------------------------------------
  3411. void ScriptActions::doNamedFireSpecialPowerAtWaypoint( const AsciiString& unit, const AsciiString& specialPower, const AsciiString& waypoint )
  3412. {
  3413. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  3414. const SpecialPowerTemplate *power = TheSpecialPowerStore->findSpecialPowerTemplate(specialPower);
  3415. if (theObj && power)
  3416. {
  3417. SpecialPowerModuleInterface *mod = theObj->getSpecialPowerModule(power);
  3418. if (mod)
  3419. {
  3420. Waypoint *way = TheTerrainLogic->getWaypointByName(waypoint);
  3421. if (!way) {
  3422. return;
  3423. }
  3424. mod->doSpecialPowerAtLocation(way->getLocation(), COMMAND_FIRED_BY_SCRIPT );
  3425. }
  3426. }
  3427. }
  3428. //-------------------------------------------------------------------------------------------------
  3429. /** doNamedFireSpecialPowerAtArea */
  3430. //-------------------------------------------------------------------------------------------------
  3431. void ScriptActions::doSkirmishFireSpecialPowerAtMostCost( const AsciiString &player, const AsciiString& specialPower )
  3432. {
  3433. #if !defined(_PLAYTEST)
  3434. Int enemyNdx;
  3435. Player *enemyPlayer = TheScriptEngine->getSkirmishEnemyPlayer();
  3436. if (enemyPlayer == NULL) return;
  3437. enemyNdx = enemyPlayer->getPlayerIndex();
  3438. const SpecialPowerTemplate *power = TheSpecialPowerStore->findSpecialPowerTemplate(specialPower);
  3439. if (power==NULL)
  3440. return;
  3441. Real radius = 50.0f;
  3442. if (power->getRadiusCursorRadius()>radius) {
  3443. radius = power->getRadiusCursorRadius();
  3444. }
  3445. Player::PlayerTeamList::const_iterator it;
  3446. Player *pPlayer = TheScriptEngine->getPlayerFromAsciiString(player);
  3447. if (pPlayer==NULL)
  3448. return;
  3449. Coord3D location;
  3450. pPlayer->computeSuperweaponTarget(power, &location, enemyNdx, radius);
  3451. for (it = pPlayer->getPlayerTeams()->begin(); it != pPlayer->getPlayerTeams()->end(); ++it) {
  3452. for (DLINK_ITERATOR<Team> iter = (*it)->iterate_TeamInstanceList(); !iter.done(); iter.advance()) {
  3453. Team *team = iter.cur();
  3454. if (!team) continue;
  3455. for (DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance()) {
  3456. Object *pObj = iter.cur();
  3457. if (!pObj) continue;
  3458. SpecialPowerModuleInterface *mod = pObj->getSpecialPowerModule(power);
  3459. if (mod)
  3460. {
  3461. mod->doSpecialPowerAtLocation( &location, COMMAND_FIRED_BY_SCRIPT );
  3462. break;
  3463. }
  3464. }
  3465. }
  3466. }
  3467. #endif
  3468. }
  3469. //-------------------------------------------------------------------------------------------------
  3470. /** doNamedFireSpecialPowerAtNamed */
  3471. //-------------------------------------------------------------------------------------------------
  3472. void ScriptActions::doNamedFireSpecialPowerAtNamed( const AsciiString& unit, const AsciiString& specialPower, const AsciiString& target )
  3473. {
  3474. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  3475. Object *theTarget = TheScriptEngine->getUnitNamed( target );
  3476. const SpecialPowerTemplate *power = TheSpecialPowerStore->findSpecialPowerTemplate(specialPower);
  3477. if (theObj && power && theTarget)
  3478. {
  3479. SpecialPowerModuleInterface *mod = theObj->getSpecialPowerModule(power);
  3480. if (mod)
  3481. {
  3482. mod->doSpecialPowerAtObject(theTarget, COMMAND_FIRED_BY_SCRIPT );
  3483. }
  3484. }
  3485. }
  3486. //-------------------------------------------------------------------------------------------------
  3487. void ScriptActions::doNamedUseCommandButtonAbility( const AsciiString& unit, const AsciiString& ability )
  3488. {
  3489. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  3490. //Sanity check
  3491. if( !theObj )
  3492. {
  3493. return;
  3494. }
  3495. const CommandSet *commandSet = TheControlBar->findCommandSet( theObj->getCommandSetString() );
  3496. if( commandSet )
  3497. {
  3498. for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
  3499. {
  3500. //Get the command button.
  3501. const CommandButton *commandButton = commandSet->getCommandButton(i);
  3502. if( commandButton )
  3503. {
  3504. if( !commandButton->getName().isEmpty() )
  3505. {
  3506. if( commandButton->getName() == ability )
  3507. {
  3508. theObj->doCommandButton( commandButton, CMD_FROM_SCRIPT );
  3509. }
  3510. }
  3511. }
  3512. }
  3513. }
  3514. }
  3515. //-------------------------------------------------------------------------------------------------
  3516. void ScriptActions::doNamedUseCommandButtonAbilityOnNamed( const AsciiString& unit, const AsciiString& ability, const AsciiString& target )
  3517. {
  3518. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  3519. Object *theTarget = TheScriptEngine->getUnitNamed( target );
  3520. //Sanity check
  3521. if( !theObj || !theTarget )
  3522. {
  3523. return;
  3524. }
  3525. const CommandSet *commandSet = TheControlBar->findCommandSet( theObj->getCommandSetString() );
  3526. if( commandSet )
  3527. {
  3528. for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
  3529. {
  3530. //Get the command button.
  3531. const CommandButton *commandButton = commandSet->getCommandButton(i);
  3532. if( commandButton )
  3533. {
  3534. if( !commandButton->getName().isEmpty() )
  3535. {
  3536. if( commandButton->getName() == ability )
  3537. {
  3538. theObj->doCommandButtonAtObject( commandButton, theTarget, CMD_FROM_SCRIPT );
  3539. }
  3540. }
  3541. }
  3542. }
  3543. }
  3544. }
  3545. //-------------------------------------------------------------------------------------------------
  3546. void ScriptActions::doNamedUseCommandButtonAbilityAtWaypoint( const AsciiString& unit, const AsciiString& ability, const AsciiString& waypoint )
  3547. {
  3548. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  3549. Waypoint *pWaypoint = TheTerrainLogic->getWaypointByName( waypoint );
  3550. //Sanity check
  3551. if( !theObj || !pWaypoint )
  3552. {
  3553. return;
  3554. }
  3555. const CommandSet *commandSet = TheControlBar->findCommandSet( theObj->getCommandSetString() );
  3556. if( commandSet )
  3557. {
  3558. for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
  3559. {
  3560. //Get the command button.
  3561. const CommandButton *commandButton = commandSet->getCommandButton(i);
  3562. if( commandButton )
  3563. {
  3564. if( !commandButton->getName().isEmpty() )
  3565. {
  3566. if( commandButton->getName() == ability )
  3567. {
  3568. theObj->doCommandButtonAtPosition( commandButton, pWaypoint->getLocation(), CMD_FROM_SCRIPT );
  3569. }
  3570. }
  3571. }
  3572. }
  3573. }
  3574. }
  3575. //-------------------------------------------------------------------------------------------------
  3576. void ScriptActions::doTeamUseCommandButtonAbility( const AsciiString& team, const AsciiString& ability )
  3577. {
  3578. Team *theTeam = TheScriptEngine->getTeamNamed( team );
  3579. // The team is the team based on the name, and the calling team (if any) and the team that
  3580. // triggered the condition. jba. :)
  3581. if( !theTeam )
  3582. {
  3583. return;
  3584. }
  3585. const CommandButton *commandButton = TheControlBar->findCommandButton( ability );
  3586. if( !commandButton )
  3587. {
  3588. return;
  3589. }
  3590. AIGroup* theGroup = TheAI->createGroup();
  3591. if( !theGroup )
  3592. {
  3593. return;
  3594. }
  3595. theTeam->getTeamAsAIGroup( theGroup );
  3596. theGroup->groupDoCommandButton( commandButton, CMD_FROM_SCRIPT );
  3597. }
  3598. //-------------------------------------------------------------------------------------------------
  3599. void ScriptActions::doTeamUseCommandButtonAbilityOnNamed( const AsciiString& team, const AsciiString& ability, const AsciiString& target )
  3600. {
  3601. Team *theTeam = TheScriptEngine->getTeamNamed( team );
  3602. // The team is the team based on the name, and the calling team (if any) and the team that
  3603. // triggered the condition. jba. :)
  3604. if( !theTeam )
  3605. {
  3606. return;
  3607. }
  3608. Object *theObj = TheScriptEngine->getUnitNamed( target );
  3609. if( !theObj )
  3610. {
  3611. return;
  3612. }
  3613. const CommandButton *commandButton = TheControlBar->findCommandButton( ability );
  3614. if( !commandButton )
  3615. {
  3616. return;
  3617. }
  3618. AIGroup* theGroup = TheAI->createGroup();
  3619. if( !theGroup )
  3620. {
  3621. return;
  3622. }
  3623. theTeam->getTeamAsAIGroup( theGroup );
  3624. theGroup->groupDoCommandButtonAtObject( commandButton, theObj, CMD_FROM_SCRIPT );
  3625. }
  3626. //-------------------------------------------------------------------------------------------------
  3627. void ScriptActions::doTeamUseCommandButtonAbilityAtWaypoint( const AsciiString& team, const AsciiString& ability, const AsciiString& waypoint )
  3628. {
  3629. Team *theTeam = TheScriptEngine->getTeamNamed( team );
  3630. // The team is the team based on the name, and the calling team (if any) and the team that
  3631. // triggered the condition. jba. :)
  3632. if( !theTeam )
  3633. {
  3634. return;
  3635. }
  3636. Waypoint *pWaypoint = TheTerrainLogic->getWaypointByName( waypoint );
  3637. if( !pWaypoint )
  3638. {
  3639. return;
  3640. }
  3641. const CommandButton *commandButton = TheControlBar->findCommandButton( ability );
  3642. if( !commandButton )
  3643. {
  3644. return;
  3645. }
  3646. AIGroup* theGroup = TheAI->createGroup();
  3647. if( !theGroup )
  3648. {
  3649. return;
  3650. }
  3651. theTeam->getTeamAsAIGroup( theGroup );
  3652. theGroup->groupDoCommandButtonAtPosition( commandButton, pWaypoint->getLocation(), CMD_FROM_SCRIPT );
  3653. }
  3654. //-------------------------------------------------------------------------------------------------
  3655. /** doRadarRefresh */
  3656. //-------------------------------------------------------------------------------------------------
  3657. void ScriptActions::doRadarRefresh( void )
  3658. {
  3659. TheRadar->refreshTerrain( TheTerrainLogic );
  3660. }
  3661. //-------------------------------------------------------------------------------------------------
  3662. /** doCameraTetherNamed */
  3663. //-------------------------------------------------------------------------------------------------
  3664. void ScriptActions::doCameraTetherNamed(const AsciiString& unit, Bool snapToUnit, Real play)
  3665. {
  3666. Object *theObj = TheScriptEngine->getUnitNamed( unit );
  3667. if (theObj)
  3668. {
  3669. TheTacticalView->setCameraLock(theObj->getID());
  3670. if (snapToUnit)
  3671. TheTacticalView->snapToCameraLock();
  3672. TheTacticalView->setSnapMode( View::LOCK_TETHER, play );
  3673. }
  3674. }
  3675. //-------------------------------------------------------------------------------------------------
  3676. /** doCameraStopTetherNamed */
  3677. //-------------------------------------------------------------------------------------------------
  3678. void ScriptActions::doCameraStopTetherNamed(void)
  3679. {
  3680. TheTacticalView->setCameraLock(INVALID_ID);
  3681. }
  3682. //-------------------------------------------------------------------------------------------------
  3683. /** doCameraSetDefault */
  3684. //-------------------------------------------------------------------------------------------------
  3685. void ScriptActions::doCameraSetDefault(Real pitch, Real angle, Real maxHeight)
  3686. {
  3687. TheTacticalView->setDefaultView(pitch, angle, maxHeight);
  3688. }
  3689. //-------------------------------------------------------------------------------------------------
  3690. /** doNamedStop */
  3691. //-------------------------------------------------------------------------------------------------
  3692. void ScriptActions::doNamedStop(const AsciiString& unitName)
  3693. {
  3694. Object *theObj = TheScriptEngine->getUnitNamed( unitName );
  3695. if (!theObj) {
  3696. return;
  3697. }
  3698. AIUpdateInterface *ai = theObj->getAIUpdateInterface();
  3699. if (!ai) {
  3700. return;
  3701. }
  3702. ai->aiIdle(CMD_FROM_SCRIPT);
  3703. }
  3704. //-------------------------------------------------------------------------------------------------
  3705. /** doTeamStop */
  3706. //-------------------------------------------------------------------------------------------------
  3707. void ScriptActions::doTeamStop(const AsciiString& teamName, Bool shouldDisband)
  3708. {
  3709. Team *theTeam = TheScriptEngine->getTeamNamed(teamName);
  3710. if (!theTeam) {
  3711. return;
  3712. }
  3713. AIGroup* theGroup = TheAI->createGroup();
  3714. if (!theGroup) {
  3715. return;
  3716. }
  3717. theTeam->getTeamAsAIGroup(theGroup);
  3718. theGroup->groupIdle(CMD_FROM_SCRIPT);
  3719. if (shouldDisband) {
  3720. Team *playerDefaultTeam = theTeam->getControllingPlayer()->getDefaultTeam();
  3721. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance()) {
  3722. Object *obj = iter.cur();
  3723. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  3724. if (!ai) {
  3725. continue;
  3726. }
  3727. ai->setIsRecruitable(TRUE);
  3728. }
  3729. doMergeTeamIntoTeam(teamName, playerDefaultTeam->getName());
  3730. }
  3731. }
  3732. //-------------------------------------------------------------------------------------------------
  3733. /** doTeamSetOverrideRelationToTeam */
  3734. //-------------------------------------------------------------------------------------------------
  3735. void ScriptActions::doTeamSetOverrideRelationToTeam(const AsciiString& teamName, const AsciiString& otherTeam, Int relation)
  3736. {
  3737. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  3738. Team *theOtherTeam = TheScriptEngine->getTeamNamed( otherTeam );
  3739. if (theTeam && theOtherTeam) {
  3740. theTeam->setOverrideTeamRelationship(theOtherTeam->getID(), (Relationship)relation);
  3741. }
  3742. }
  3743. //-------------------------------------------------------------------------------------------------
  3744. /** doTeamRemoveOverrideRelationToTeam */
  3745. //-------------------------------------------------------------------------------------------------
  3746. void ScriptActions::doTeamRemoveOverrideRelationToTeam(const AsciiString& teamName, const AsciiString& otherTeam)
  3747. {
  3748. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  3749. Team *theOtherTeam = TheScriptEngine->getTeamNamed( otherTeam );
  3750. if (theTeam && theOtherTeam) {
  3751. theTeam->removeOverrideTeamRelationship(theOtherTeam->getID());
  3752. }
  3753. }
  3754. //-------------------------------------------------------------------------------------------------
  3755. /** doPlayerSetOverrideRelationToTeam */
  3756. //-------------------------------------------------------------------------------------------------
  3757. void ScriptActions::doPlayerSetOverrideRelationToTeam(const AsciiString& playerName, const AsciiString& otherTeam, Int relation)
  3758. {
  3759. Player *thePlayer = ThePlayerList->findPlayerWithNameKey(NAMEKEY(playerName));
  3760. Team *theOtherTeam = TheScriptEngine->getTeamNamed( otherTeam );
  3761. if (thePlayer && theOtherTeam) {
  3762. thePlayer->setTeamRelationship(theOtherTeam, (Relationship)relation);
  3763. }
  3764. }
  3765. //-------------------------------------------------------------------------------------------------
  3766. /** doPlayerRemoveOverrideRelationToTeam */
  3767. //-------------------------------------------------------------------------------------------------
  3768. void ScriptActions::doPlayerRemoveOverrideRelationToTeam(const AsciiString& playerName, const AsciiString& otherTeam)
  3769. {
  3770. Player *thePlayer = ThePlayerList->findPlayerWithNameKey(NAMEKEY(playerName));
  3771. Team *theOtherTeam = TheScriptEngine->getTeamNamed( otherTeam );
  3772. if (thePlayer && theOtherTeam) {
  3773. thePlayer->removeTeamRelationship(theOtherTeam);
  3774. }
  3775. }
  3776. //-------------------------------------------------------------------------------------------------
  3777. /** doTeamSetOverrideRelationToPlayer */
  3778. //-------------------------------------------------------------------------------------------------
  3779. void ScriptActions::doTeamSetOverrideRelationToPlayer(const AsciiString& teamName, const AsciiString& otherPlayer, Int relation)
  3780. {
  3781. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  3782. Player *theOtherPlayer = ThePlayerList->findPlayerWithNameKey(NAMEKEY(otherPlayer));
  3783. if (theTeam && theOtherPlayer) {
  3784. theTeam->setOverridePlayerRelationship(theOtherPlayer->getPlayerIndex(), (Relationship)relation);
  3785. }
  3786. }
  3787. //-------------------------------------------------------------------------------------------------
  3788. /** doTeamRemoveOverrideRelationToTeam */
  3789. //-------------------------------------------------------------------------------------------------
  3790. void ScriptActions::doTeamRemoveOverrideRelationToPlayer(const AsciiString& teamName, const AsciiString& otherPlayer)
  3791. {
  3792. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  3793. Player *theOtherPlayer = ThePlayerList->findPlayerWithNameKey(NAMEKEY(otherPlayer));
  3794. if (theTeam && theOtherPlayer) {
  3795. theTeam->removeOverridePlayerRelationship(theOtherPlayer->getPlayerIndex());
  3796. }
  3797. }
  3798. //-------------------------------------------------------------------------------------------------
  3799. /** doTeamRemoveAllOverrideRelations */
  3800. //-------------------------------------------------------------------------------------------------
  3801. void ScriptActions::doTeamRemoveAllOverrideRelations(const AsciiString& teamName)
  3802. {
  3803. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  3804. if (theTeam) {
  3805. // invalid ID is OK -- it removes all relationships
  3806. theTeam->removeOverrideTeamRelationship( NULL );
  3807. theTeam->removeOverridePlayerRelationship( NULL );
  3808. }
  3809. }
  3810. //-------------------------------------------------------------------------------------------------
  3811. /** doUnitStartSequentialScript */
  3812. //-------------------------------------------------------------------------------------------------
  3813. void ScriptActions::doUnitStartSequentialScript(const AsciiString& unitName, const AsciiString& scriptName, Int loopVal)
  3814. {
  3815. Object *obj = TheScriptEngine->getUnitNamed(unitName);
  3816. if (!obj) {
  3817. return;
  3818. }
  3819. Script *script = const_cast<Script*>(TheScriptEngine->findScriptByName(scriptName));
  3820. if (!script) {
  3821. return;
  3822. }
  3823. SequentialScript* seqScript = newInstance(SequentialScript);
  3824. seqScript->m_objectID = obj->getID();
  3825. seqScript->m_scriptToExecuteSequentially = script;
  3826. seqScript->m_timesToLoop = loopVal;
  3827. TheScriptEngine->appendSequentialScript(seqScript);
  3828. seqScript->deleteInstance();
  3829. }
  3830. //-------------------------------------------------------------------------------------------------
  3831. /** doUnitStopSequentialScript */
  3832. //-------------------------------------------------------------------------------------------------
  3833. void ScriptActions::doUnitStopSequentialScript(const AsciiString& unitName)
  3834. {
  3835. Object *obj = TheScriptEngine->getUnitNamed(unitName);
  3836. if (!obj) {
  3837. return;
  3838. }
  3839. TheScriptEngine->removeAllSequentialScripts(obj);
  3840. }
  3841. //-------------------------------------------------------------------------------------------------
  3842. /** doTeamStartSequentialScript */
  3843. //-------------------------------------------------------------------------------------------------
  3844. /** doNamedFireWeaponFollowingWaypointPath -- Kris
  3845. Orders unit to fire a waypoint following capable weapon to follow a waypoint and attack the
  3846. final waypoint position. */
  3847. //-------------------------------------------------------------------------------------------------
  3848. void ScriptActions::doNamedFireWeaponFollowingWaypointPath( const AsciiString& unit, const AsciiString& waypointPath )
  3849. {
  3850. //Get the unit... if it fails, abort.
  3851. Object *theUnit = TheScriptEngine->getUnitNamed( unit );
  3852. if( !theUnit )
  3853. {
  3854. return;
  3855. }
  3856. Coord3D pos = *theUnit->getPosition();
  3857. //Find the closest waypoint on the path.
  3858. Waypoint *way = TheTerrainLogic->getClosestWaypointOnPath( &pos, waypointPath );
  3859. if( !way )
  3860. {
  3861. return;
  3862. }
  3863. //We have to do special checking to make sure our unit even has a waypoint following capable weapon.
  3864. Weapon *weapon = theUnit->findWaypointFollowingCapableWeapon();
  3865. if( !weapon )
  3866. {
  3867. return;
  3868. }
  3869. Object *projectile = weapon->forceFireWeapon( theUnit, &pos );
  3870. if( projectile )
  3871. {
  3872. //Get the AIUpdateInterface... if it fails, abort.
  3873. AIUpdateInterface* aiUpdate = projectile->getAIUpdateInterface();
  3874. if( !aiUpdate )
  3875. {
  3876. return;
  3877. }
  3878. DEBUG_ASSERTLOG(TheTerrainLogic->isPurposeOfPath(way, waypointPath), ("***Wrong waypoint purpose. Make jba fix this.\n"));
  3879. projectile->leaveGroup();
  3880. aiUpdate->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  3881. aiUpdate->aiFollowWaypointPath(way, CMD_FROM_SCRIPT);
  3882. }
  3883. }
  3884. //-------------------------------------------------------------------------------------------------
  3885. /** doTeamStartSequentialScript */
  3886. //-------------------------------------------------------------------------------------------------
  3887. void ScriptActions::doTeamStartSequentialScript(const AsciiString& teamName, const AsciiString& scriptName, Int loopVal)
  3888. {
  3889. Team *team = TheScriptEngine->getTeamNamed(teamName);
  3890. if (!team) {
  3891. return;
  3892. }
  3893. Script *script = const_cast<Script*>(TheScriptEngine->findScriptByName(scriptName));
  3894. if (!script) {
  3895. return;
  3896. }
  3897. // Idle the team so the seq script will start executing. jba.
  3898. AIGroup* theGroup = TheAI->createGroup();
  3899. if (!theGroup) {
  3900. return;
  3901. }
  3902. team->getTeamAsAIGroup(theGroup);
  3903. theGroup->groupIdle(CMD_FROM_SCRIPT);
  3904. SequentialScript* seqScript = newInstance(SequentialScript);
  3905. seqScript->m_teamToExecOn = team;
  3906. seqScript->m_scriptToExecuteSequentially = script;
  3907. seqScript->m_timesToLoop = loopVal;
  3908. TheScriptEngine->appendSequentialScript(seqScript);
  3909. seqScript->deleteInstance();
  3910. }
  3911. //-------------------------------------------------------------------------------------------------
  3912. /** doTeamStopSequentialScript */
  3913. //-------------------------------------------------------------------------------------------------
  3914. void ScriptActions::doTeamStopSequentialScript(const AsciiString& teamName)
  3915. {
  3916. Team *team = TheScriptEngine->getTeamNamed(teamName);
  3917. if (!team) {
  3918. return;
  3919. }
  3920. TheScriptEngine->removeAllSequentialScripts(team);
  3921. }
  3922. //-------------------------------------------------------------------------------------------------
  3923. /** doUnitGuardForFramecount */
  3924. //-------------------------------------------------------------------------------------------------
  3925. void ScriptActions::doUnitGuardForFramecount(const AsciiString& unitName, Int framecount)
  3926. {
  3927. Object *obj = TheScriptEngine->getUnitNamed(unitName);
  3928. if (!obj) {
  3929. return;
  3930. }
  3931. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  3932. if (!ai) {
  3933. return;
  3934. }
  3935. Coord3D pos = *obj->getPosition();
  3936. ai->chooseLocomotorSet(LOCOMOTORSET_NORMAL);
  3937. ai->aiGuardPosition(&pos, GUARDMODE_NORMAL, CMD_FROM_SCRIPT);
  3938. TheScriptEngine->setSequentialTimer(obj, framecount);
  3939. }
  3940. //-------------------------------------------------------------------------------------------------
  3941. /** doUnitIdleForFramecount */
  3942. //-------------------------------------------------------------------------------------------------
  3943. void ScriptActions::doUnitIdleForFramecount(const AsciiString& unitName, Int framecount)
  3944. {
  3945. Object *obj = TheScriptEngine->getUnitNamed(unitName);
  3946. if (!obj) {
  3947. return;
  3948. }
  3949. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  3950. if (!ai) {
  3951. return;
  3952. }
  3953. ai->aiIdle(CMD_FROM_SCRIPT);
  3954. TheScriptEngine->setSequentialTimer(obj, framecount);
  3955. }
  3956. //-------------------------------------------------------------------------------------------------
  3957. /** doTeamGuardForFramecount */
  3958. //-------------------------------------------------------------------------------------------------
  3959. void ScriptActions::doTeamGuardForFramecount(const AsciiString& teamName, Int framecount)
  3960. {
  3961. Team *theTeam = TheScriptEngine->getTeamNamed(teamName);
  3962. if (!theTeam) {
  3963. return;
  3964. }
  3965. // Have all the members of the team guard at their current pos.
  3966. for (DLINK_ITERATOR<Object> iter = theTeam->iterate_TeamMemberList(); !iter.done(); iter.advance())
  3967. {
  3968. Object *obj = iter.cur();
  3969. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  3970. if (!ai) {
  3971. continue;
  3972. }
  3973. Coord3D pos = *obj->getPosition();
  3974. ai->aiGuardPosition(&pos, GUARDMODE_NORMAL, CMD_FROM_SCRIPT);
  3975. }
  3976. TheScriptEngine->setSequentialTimer(theTeam, framecount);
  3977. }
  3978. //-------------------------------------------------------------------------------------------------
  3979. /** doTeamIdleForFramecount */
  3980. //-------------------------------------------------------------------------------------------------
  3981. void ScriptActions::doTeamIdleForFramecount(const AsciiString& teamName, Int framecount)
  3982. {
  3983. Team *theTeam = TheScriptEngine->getTeamNamed(teamName);
  3984. if (!theTeam) {
  3985. return;
  3986. }
  3987. AIGroup* theGroup = TheAI->createGroup();
  3988. if (!theGroup) {
  3989. return;
  3990. }
  3991. theTeam->getTeamAsAIGroup(theGroup);
  3992. Coord3D center;
  3993. theGroup->getCenter(&center);
  3994. theGroup->groupIdle(CMD_FROM_SCRIPT);
  3995. TheScriptEngine->setSequentialTimer(theTeam, framecount);
  3996. }
  3997. //-------------------------------------------------------------------------------------------------
  3998. /** doWaterChangeHeight */
  3999. //-------------------------------------------------------------------------------------------------
  4000. void ScriptActions::doWaterChangeHeight(const AsciiString& waterName, Real newHeight)
  4001. {
  4002. const WaterHandle *water = TheTerrainLogic->getWaterHandleByName(waterName);
  4003. if (!water) {
  4004. return;
  4005. }
  4006. TheTerrainLogic->setWaterHeight(water, newHeight, 999999.9f, TRUE );
  4007. }
  4008. //-------------------------------------------------------------------------------------------------
  4009. /** doWaterChangeHeightOverTime */
  4010. //-------------------------------------------------------------------------------------------------
  4011. void ScriptActions::doWaterChangeHeightOverTime( const AsciiString& waterName, Real newHeight, Real time, Real damage )
  4012. {
  4013. const WaterHandle *water = TheTerrainLogic->getWaterHandleByName( waterName );
  4014. if( water )
  4015. {
  4016. TheTerrainLogic->changeWaterHeightOverTime( water, newHeight, time, damage );
  4017. }
  4018. }
  4019. //-------------------------------------------------------------------------------------------------
  4020. /** doBorderSwitch */
  4021. //-------------------------------------------------------------------------------------------------
  4022. void ScriptActions::doBorderSwitch(Int borderToUse)
  4023. {
  4024. /*
  4025. * The observer player always has to have the map completely revealed for him.
  4026. * Border switching doesn't play nice with the permanent map reveal so for the
  4027. * observer player we need to undo the old permanent reveal, switch map borders,
  4028. * and re-reveal the map. BGC
  4029. */
  4030. Int observerPlayerIndex = -1;
  4031. if (ThePlayerList != NULL)
  4032. {
  4033. Player *observer = ThePlayerList->findPlayerWithNameKey(TheNameKeyGenerator->nameToKey("ReplayObserver"));
  4034. if (observer != NULL) {
  4035. observerPlayerIndex = observer->getPlayerIndex();
  4036. }
  4037. }
  4038. if (observerPlayerIndex != -1)
  4039. {
  4040. ThePartitionManager->undoRevealMapForPlayerPermanently( observerPlayerIndex );
  4041. }
  4042. TheTerrainLogic->setActiveBoundary(borderToUse);
  4043. if (observerPlayerIndex != -1)
  4044. {
  4045. ThePartitionManager->revealMapForPlayerPermanently( observerPlayerIndex );
  4046. }
  4047. ThePartitionManager->refreshShroudForLocalPlayer();
  4048. }
  4049. //-------------------------------------------------------------------------------------------------
  4050. /** doForceObjectSelection */
  4051. //-------------------------------------------------------------------------------------------------
  4052. void ScriptActions::doForceObjectSelection(const AsciiString& teamName, const AsciiString& objectType, Bool centerInView, const AsciiString& audioToPlay)
  4053. {
  4054. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4055. if (!team) {
  4056. return;
  4057. }
  4058. Object *bestGuess = NULL;
  4059. for (DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance()) {
  4060. Object *obj = iter.cur();
  4061. if (!obj) {
  4062. continue;
  4063. }
  4064. if (obj->getTemplate() && obj->getTemplate()->getName() == objectType) {
  4065. if (bestGuess == NULL || obj->getID() < bestGuess->getID()) { // lower ID means its newer
  4066. bestGuess = obj;
  4067. }
  4068. }
  4069. }
  4070. if (!(bestGuess && bestGuess->getDrawable())) {
  4071. return;
  4072. }
  4073. TheInGameUI->deselectAllDrawables();
  4074. TheInGameUI->selectDrawable(bestGuess->getDrawable());
  4075. // play the sound
  4076. AudioEventRTS audioEvent(audioToPlay);
  4077. audioEvent.setPlayerIndex(ThePlayerList->getLocalPlayer()->getPlayerIndex());
  4078. TheAudio->addAudioEvent(&audioEvent);
  4079. if (centerInView) {
  4080. Coord3D pos = *bestGuess->getPosition();
  4081. TheTacticalView->moveCameraTo(&pos, 0, 0, FALSE);
  4082. }
  4083. }
  4084. void* __cdecl killTheObject( Object *obj, void* userObj )
  4085. {
  4086. userObj;
  4087. if (obj)
  4088. obj->kill();
  4089. return NULL;
  4090. }
  4091. //-------------------------------------------------------------------------------------------------
  4092. /** doForceObjectSelection */
  4093. //-------------------------------------------------------------------------------------------------
  4094. void ScriptActions::doDestroyAllContained(const AsciiString& unitName, Int damageType )
  4095. {
  4096. Object *obj = TheScriptEngine->getUnitNamed(unitName);
  4097. if (!obj) {
  4098. return;
  4099. }
  4100. ContainModuleInterface *cmi = obj->getContain();
  4101. if( !cmi || cmi->getContainCount() == 0 )
  4102. {
  4103. return;
  4104. }
  4105. cmi->iterateContained((ContainIterateFunc)killTheObject, NULL, false);
  4106. }
  4107. //-------------------------------------------------------------------------------------------------
  4108. /** doRadarForceEnable */
  4109. //-------------------------------------------------------------------------------------------------
  4110. void ScriptActions::doRadarForceEnable(void)
  4111. {
  4112. TheRadar->forceOn(true);
  4113. }
  4114. //-------------------------------------------------------------------------------------------------
  4115. /** doRadarRevertNormal */
  4116. //-------------------------------------------------------------------------------------------------
  4117. void ScriptActions::doRadarRevertNormal(void)
  4118. {
  4119. TheRadar->forceOn(false);
  4120. }
  4121. //-------------------------------------------------------------------------------------------------
  4122. /** doScreenShake */
  4123. //-------------------------------------------------------------------------------------------------
  4124. void ScriptActions::doScreenShake( UnsignedInt intensity )
  4125. {
  4126. Coord3D pos;
  4127. TheTacticalView->getPosition( &pos );
  4128. TheTacticalView->shake( &pos, (View::CameraShakeType)intensity );
  4129. }
  4130. //-------------------------------------------------------------------------------------------------
  4131. /** doModifyBuildableStatus */
  4132. //-------------------------------------------------------------------------------------------------
  4133. void ScriptActions::doModifyBuildableStatus( const AsciiString& objectType, Int buildableStatus )
  4134. {
  4135. const ThingTemplate *templ = TheThingFactory->findTemplate(objectType);
  4136. if (!templ)
  4137. {
  4138. return;
  4139. }
  4140. TheGameLogic->setBuildableStatusOverride(templ, (BuildableStatus) buildableStatus);
  4141. }
  4142. //-------------------------------------------------------------------------------------------------
  4143. static CaveInterface* findCave(Object* obj)
  4144. {
  4145. for (BehaviorModule** i = obj->getBehaviorModules(); *i; ++i)
  4146. {
  4147. CaveInterface* c = (*i)->getCaveInterface();
  4148. if (c != NULL)
  4149. return c;
  4150. }
  4151. return NULL;
  4152. }
  4153. //-------------------------------------------------------------------------------------------------
  4154. /** doSetCaveIndex */
  4155. //-------------------------------------------------------------------------------------------------
  4156. void ScriptActions::doSetCaveIndex( const AsciiString& caveName, Int caveIndex )
  4157. {
  4158. Object *obj = TheScriptEngine->getUnitNamed(caveName);
  4159. if (!obj)
  4160. {
  4161. return;
  4162. }
  4163. CaveInterface *caveModule = findCave(obj);
  4164. if( caveModule == NULL )
  4165. return;
  4166. caveModule->tryToSetCaveIndex( caveIndex );
  4167. }
  4168. //-------------------------------------------------------------------------------------------------
  4169. /** doSetWarehouseValue */
  4170. //-------------------------------------------------------------------------------------------------
  4171. void ScriptActions::doSetWarehouseValue( const AsciiString& warehouseName, Int cashValue )
  4172. {
  4173. Object *obj = TheScriptEngine->getUnitNamed(warehouseName);
  4174. if (!obj)
  4175. {
  4176. return;
  4177. }
  4178. static const NameKeyType warehouseModuleKey = TheNameKeyGenerator->nameToKey( "SupplyWarehouseDockUpdate" );
  4179. SupplyWarehouseDockUpdate *warehouseModule = (SupplyWarehouseDockUpdate *)obj->findUpdateModule( warehouseModuleKey );
  4180. if( warehouseModule == NULL )
  4181. return;
  4182. warehouseModule->setCashValue( cashValue );
  4183. }
  4184. //-------------------------------------------------------------------------------------------------
  4185. /** doSoundEnableType */
  4186. //-------------------------------------------------------------------------------------------------
  4187. void ScriptActions::doSoundEnableType( const AsciiString& soundEventName, Bool enable )
  4188. {
  4189. TheAudio->setAudioEventEnabled(soundEventName, enable);
  4190. }
  4191. //-------------------------------------------------------------------------------------------------
  4192. void ScriptActions::doSoundRemoveAllDisabled()
  4193. {
  4194. TheAudio->removeDisabledEvents();
  4195. }
  4196. //-------------------------------------------------------------------------------------------------
  4197. void ScriptActions::doSoundRemoveType( const AsciiString& soundEventName )
  4198. {
  4199. TheAudio->removeAudioEvent( soundEventName );
  4200. }
  4201. //-------------------------------------------------------------------------------------------------
  4202. /** doSoundOverrideVolume */
  4203. //-------------------------------------------------------------------------------------------------
  4204. void ScriptActions::doSoundOverrideVolume( const AsciiString& soundEventName, Real newVolume )
  4205. {
  4206. TheAudio->setAudioEventVolumeOverride(soundEventName, newVolume / 100.0f);
  4207. }
  4208. //-------------------------------------------------------------------------------------------------
  4209. /** doSetToppleDirection */
  4210. //-------------------------------------------------------------------------------------------------
  4211. void ScriptActions::doSetToppleDirection( const AsciiString& unitName, const Coord3D *dir )
  4212. {
  4213. TheScriptEngine->setToppleDirection(unitName, dir);
  4214. }
  4215. //-------------------------------------------------------------------------------------------------
  4216. /** doMoveTeamTowardsNearest */
  4217. //-------------------------------------------------------------------------------------------------
  4218. void ScriptActions::doMoveUnitTowardsNearest( const AsciiString& unitName, const AsciiString& objectType, AsciiString triggerName)
  4219. {
  4220. Object *obj = TheScriptEngine->getUnitNamed(unitName);
  4221. if (!obj) {
  4222. return;
  4223. }
  4224. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  4225. if (!ai) {
  4226. return;
  4227. }
  4228. const ThingTemplate *templ = TheThingFactory->findTemplate(objectType);
  4229. if (!templ) {
  4230. return;
  4231. }
  4232. PolygonTrigger *trig = TheScriptEngine->getQualifiedTriggerAreaByName(triggerName);
  4233. if (!trig) {
  4234. return;
  4235. }
  4236. PartitionFilterThing thingsToAccept(templ, true);
  4237. PartitionFilterPolygonTrigger acceptWithin(trig);
  4238. PartitionFilterSameMapStatus filterMapStatus(obj);
  4239. PartitionFilter *filters[] = { &thingsToAccept, &acceptWithin, &filterMapStatus, NULL };
  4240. Object *dest = ThePartitionManager->getClosestObject(obj->getPosition(), REALLY_FAR, FROM_CENTER_2D, filters);
  4241. if (!dest) {
  4242. return;
  4243. }
  4244. ai->chooseLocomotorSet( LOCOMOTORSET_NORMAL );
  4245. ai->aiMoveToObject(dest, CMD_FROM_SCRIPT);
  4246. }
  4247. //-------------------------------------------------------------------------------------------------
  4248. /** doMoveTeamTowardsNearest */
  4249. //-------------------------------------------------------------------------------------------------
  4250. void ScriptActions::doMoveTeamTowardsNearest( const AsciiString& teamName, const AsciiString& objectType, AsciiString triggerName)
  4251. {
  4252. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4253. if (!team) {
  4254. return;
  4255. }
  4256. const ThingTemplate *templ = TheThingFactory->findTemplate(objectType);
  4257. if (!templ) {
  4258. return;
  4259. }
  4260. PolygonTrigger *trig = TheScriptEngine->getQualifiedTriggerAreaByName(triggerName);
  4261. if (!trig) {
  4262. return;
  4263. }
  4264. for (DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance())
  4265. {
  4266. Object *obj = iter.cur();
  4267. if (!obj) {
  4268. continue;
  4269. }
  4270. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  4271. if (!ai) {
  4272. continue;
  4273. }
  4274. PartitionFilterThing thingsToAccept(templ, true);
  4275. PartitionFilterPolygonTrigger acceptWithin(trig);
  4276. PartitionFilterSameMapStatus filterMapStatus(obj);
  4277. PartitionFilter *filters[] = { &thingsToAccept, &acceptWithin, &filterMapStatus, NULL };
  4278. Object *dest = ThePartitionManager->getClosestObject(obj->getPosition(), REALLY_FAR, FROM_CENTER_2D, filters);
  4279. if (!dest) {
  4280. return;
  4281. }
  4282. ai->chooseLocomotorSet( LOCOMOTORSET_NORMAL );
  4283. ai->aiMoveToObject(dest, CMD_FROM_SCRIPT);
  4284. }
  4285. }
  4286. //-------------------------------------------------------------------------------------------------
  4287. /** doUnitReceiveUpgrade */
  4288. //-------------------------------------------------------------------------------------------------
  4289. void ScriptActions::doUnitReceiveUpgrade( const AsciiString& unitName, const AsciiString& upgradeName )
  4290. {
  4291. Object *obj = TheScriptEngine->getUnitNamed(unitName);
  4292. if (!obj) {
  4293. return;
  4294. }
  4295. const UpgradeTemplate *templ = TheUpgradeCenter->findUpgrade(upgradeName);
  4296. if (!templ) {
  4297. return;
  4298. }
  4299. DEBUG_ASSERTCRASH(obj->affectedByUpgrade(templ), ("Design bug: Unit '%s' was given upgrade '%s', but he is unaffected.", unitName.str(), upgradeName.str()));
  4300. obj->giveUpgrade(templ);
  4301. }
  4302. //-------------------------------------------------------------------------------------------------
  4303. /** doSkirmishAttackNearestGroupWithValue */
  4304. //-------------------------------------------------------------------------------------------------
  4305. void ScriptActions::doSkirmishAttackNearestGroupWithValue( const AsciiString& teamName, Int comparison, Int value )
  4306. {
  4307. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4308. if (!team) {
  4309. return;
  4310. }
  4311. AIGroup* theGroup = TheAI->createGroup();
  4312. team->getTeamAsAIGroup(theGroup);
  4313. Player *player = team->getControllingPlayer();
  4314. if (!player)
  4315. return;
  4316. Coord3D loc;
  4317. Coord3D groupLoc;
  4318. theGroup->getCenter(&groupLoc);
  4319. if (comparison == Parameter::GREATER_EQUAL || comparison == Parameter::GREATER) {
  4320. ThePartitionManager->getNearestGroupWithValue(player->getPlayerIndex(), ALLOW_ENEMIES, VOT_CashValue,
  4321. &groupLoc, value, true, &loc);
  4322. }
  4323. theGroup->groupAttackMoveToPosition( &loc, NO_MAX_SHOTS_LIMIT, CMD_FROM_SCRIPT );
  4324. }
  4325. //-------------------------------------------------------------------------------------------------
  4326. /** doSkirmishCommandButtonOnMostValuable */
  4327. //-------------------------------------------------------------------------------------------------
  4328. void ScriptActions::doSkirmishCommandButtonOnMostValuable( const AsciiString& teamName, const AsciiString& ability, Real range, Bool allTeamMembers)
  4329. {
  4330. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4331. if (!team) {
  4332. return;
  4333. }
  4334. AIGroup *theGroup = TheAI->createGroup();
  4335. team->getTeamAsAIGroup(theGroup);
  4336. Player *player = team->getControllingPlayer();
  4337. if (!player)
  4338. return;
  4339. const CommandButton *commandButton = TheControlBar->findCommandButton( ability );
  4340. if( !commandButton ) {
  4341. return;
  4342. }
  4343. Object *srcObj = NULL;
  4344. if (commandButton->getSpecialPowerTemplate()) {
  4345. srcObj = theGroup->getSpecialPowerSourceObject(commandButton->getSpecialPowerTemplate()->getID());
  4346. } else {
  4347. srcObj = theGroup->getCommandButtonSourceObject(commandButton->getCommandType());
  4348. }
  4349. if ( !srcObj ) {
  4350. return;
  4351. }
  4352. Coord3D pos;
  4353. theGroup->getCenter(&pos);
  4354. PartitionFilterPlayerAffiliation f1(team->getControllingPlayer(), ALLOW_ENEMIES, true);
  4355. PartitionFilterValidCommandButtonTarget f2(srcObj, commandButton, true, CMD_FROM_SCRIPT);
  4356. PartitionFilterSameMapStatus filterMapStatus(srcObj);
  4357. PartitionFilter *filters[] = { &f1, &f2, &filterMapStatus, 0 };
  4358. // @todo: Should we add the group's radius to the range? Seems like a possibility.
  4359. SimpleObjectIterator *iter = ThePartitionManager->iterateObjectsInRange(&pos, range, FROM_CENTER_2D, filters, ITER_SORTED_EXPENSIVE_TO_CHEAP);
  4360. MemoryPoolObjectHolder hold(iter);
  4361. if (iter && iter->first()) {
  4362. theGroup->groupDoCommandButtonAtObject(commandButton, iter->first(), CMD_FROM_SCRIPT);
  4363. }
  4364. }
  4365. //-------------------------------------------------------------------------------------------------
  4366. /** doTeamSpinForFramecount */
  4367. //-------------------------------------------------------------------------------------------------
  4368. void ScriptActions::doTeamSpinForFramecount( const AsciiString& teamName, Int waitForFrames )
  4369. {
  4370. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4371. if (!team) {
  4372. return;
  4373. }
  4374. TheScriptEngine->setSequentialTimer(team, waitForFrames);
  4375. }
  4376. //-------------------------------------------------------------------------------------------------
  4377. /** doTeamUseCommandButtonOnNamed */
  4378. //-------------------------------------------------------------------------------------------------
  4379. void ScriptActions::doTeamUseCommandButtonOnNamed( const AsciiString& teamName, const AsciiString& commandAbility, const AsciiString& unitName )
  4380. {
  4381. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4382. if (!team) {
  4383. return;
  4384. }
  4385. AIGroup *theGroup = TheAI->createGroup();
  4386. team->getTeamAsAIGroup(theGroup);
  4387. const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
  4388. if(!commandButton) {
  4389. return;
  4390. }
  4391. Object *srcObj = NULL;
  4392. if (commandButton->getSpecialPowerTemplate()) {
  4393. srcObj = theGroup->getSpecialPowerSourceObject(commandButton->getSpecialPowerTemplate()->getID());
  4394. } else {
  4395. srcObj = theGroup->getCommandButtonSourceObject(commandButton->getCommandType());
  4396. }
  4397. if (!srcObj) {
  4398. return;
  4399. }
  4400. Object *obj = TheScriptEngine->getUnitNamed( unitName );
  4401. if (!obj) {
  4402. return;
  4403. }
  4404. if (commandButton->isValidToUseOn(srcObj, obj, NULL, CMD_FROM_SCRIPT)) {
  4405. theGroup->groupDoCommandButtonAtObject(commandButton, obj, CMD_FROM_SCRIPT);
  4406. }
  4407. }
  4408. //-------------------------------------------------------------------------------------------------
  4409. /** doTeamUseCommandButtonOnNearestEnemy */
  4410. //-------------------------------------------------------------------------------------------------
  4411. void ScriptActions::doTeamUseCommandButtonOnNearestEnemy( const AsciiString& teamName, const AsciiString& commandAbility )
  4412. {
  4413. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4414. if (!team) {
  4415. return;
  4416. }
  4417. AIGroup *theGroup = TheAI->createGroup();
  4418. team->getTeamAsAIGroup(theGroup);
  4419. const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
  4420. if(!commandButton) {
  4421. return;
  4422. }
  4423. Object *srcObj = NULL;
  4424. if (commandButton->getSpecialPowerTemplate()) {
  4425. srcObj = theGroup->getSpecialPowerSourceObject(commandButton->getSpecialPowerTemplate()->getID());
  4426. } else {
  4427. srcObj = theGroup->getCommandButtonSourceObject(commandButton->getCommandType());
  4428. }
  4429. if (!srcObj) {
  4430. return;
  4431. }
  4432. PartitionFilterPlayerAffiliation f1(team->getControllingPlayer(), ALLOW_ENEMIES, true);
  4433. PartitionFilterValidCommandButtonTarget f2(srcObj, commandButton, true, CMD_FROM_SCRIPT);
  4434. PartitionFilterSameMapStatus filterMapStatus(srcObj);
  4435. Coord3D pos;
  4436. theGroup->getCenter(&pos);
  4437. PartitionFilter *filters[] = { &f1, &f2, &filterMapStatus, 0 };
  4438. Object *obj = ThePartitionManager->getClosestObject(&pos, REALLY_FAR, FROM_CENTER_2D, filters);
  4439. if (!obj) {
  4440. return;
  4441. }
  4442. // already been checked for validity
  4443. theGroup->groupDoCommandButtonAtObject(commandButton, obj, CMD_FROM_SCRIPT);
  4444. }
  4445. //-------------------------------------------------------------------------------------------------
  4446. /** doTeamUseCommandButtonOnNearestGarrisonedBuilding */
  4447. //-------------------------------------------------------------------------------------------------
  4448. void ScriptActions::doTeamUseCommandButtonOnNearestGarrisonedBuilding( const AsciiString& teamName, const AsciiString& commandAbility )
  4449. {
  4450. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4451. if (!team) {
  4452. return;
  4453. }
  4454. AIGroup *theGroup = TheAI->createGroup();
  4455. team->getTeamAsAIGroup(theGroup);
  4456. const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
  4457. if(!commandButton) {
  4458. return;
  4459. }
  4460. Object *srcObj = NULL;
  4461. if (commandButton->getSpecialPowerTemplate()) {
  4462. srcObj = theGroup->getSpecialPowerSourceObject(commandButton->getSpecialPowerTemplate()->getID());
  4463. } else {
  4464. srcObj = theGroup->getCommandButtonSourceObject(commandButton->getCommandType());
  4465. }
  4466. if (!srcObj) {
  4467. return;
  4468. }
  4469. PartitionFilterPlayerAffiliation f1(team->getControllingPlayer(), ALLOW_ENEMIES, true);
  4470. PartitionFilterAcceptByKindOf f2(MAKE_KINDOF_MASK(KINDOF_STRUCTURE), KINDOFMASK_NONE);
  4471. PartitionFilterGarrisonable f3(true);
  4472. PartitionFilterValidCommandButtonTarget f4(srcObj, commandButton, true, CMD_FROM_SCRIPT);
  4473. PartitionFilterSameMapStatus filterMapStatus(srcObj);
  4474. Coord3D pos;
  4475. theGroup->getCenter(&pos);
  4476. PartitionFilter *filters[] = { &f1, &f2, &f3, &f4, &filterMapStatus, 0 };
  4477. Object *obj = ThePartitionManager->getClosestObject(&pos, REALLY_FAR, FROM_CENTER_2D, filters);
  4478. if (!obj) {
  4479. return;
  4480. }
  4481. // already been checked for validity
  4482. theGroup->groupDoCommandButtonAtObject(commandButton, obj, CMD_FROM_SCRIPT);
  4483. }
  4484. //-------------------------------------------------------------------------------------------------
  4485. /** doTeamUseCommandButtonOnNearestKindof */
  4486. //-------------------------------------------------------------------------------------------------
  4487. void ScriptActions::doTeamUseCommandButtonOnNearestKindof( const AsciiString& teamName, const AsciiString& commandAbility, Int kindofBit )
  4488. {
  4489. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4490. if (!team) {
  4491. return;
  4492. }
  4493. AIGroup *theGroup = TheAI->createGroup();
  4494. team->getTeamAsAIGroup(theGroup);
  4495. const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
  4496. if (!commandButton) {
  4497. return;
  4498. }
  4499. Object *srcObj = NULL;
  4500. if (commandButton->getSpecialPowerTemplate()) {
  4501. srcObj = theGroup->getSpecialPowerSourceObject(commandButton->getSpecialPowerTemplate()->getID());
  4502. } else {
  4503. srcObj = theGroup->getCommandButtonSourceObject(commandButton->getCommandType());
  4504. }
  4505. if (!srcObj) {
  4506. return;
  4507. }
  4508. PartitionFilterPlayerAffiliation f1(team->getControllingPlayer(), ALLOW_ENEMIES, true);
  4509. PartitionFilterAcceptByKindOf f2(MAKE_KINDOF_MASK(kindofBit), KINDOFMASK_NONE);
  4510. PartitionFilterValidCommandButtonTarget f3(srcObj, commandButton, true, CMD_FROM_SCRIPT);
  4511. PartitionFilterSameMapStatus filterMapStatus(srcObj);
  4512. Coord3D pos;
  4513. theGroup->getCenter(&pos);
  4514. PartitionFilter *filters[] = { &f1, &f2, &f3, &filterMapStatus, 0 };
  4515. Object *obj = ThePartitionManager->getClosestObject(&pos, REALLY_FAR, FROM_CENTER_2D, filters);
  4516. if (!obj) {
  4517. return;
  4518. }
  4519. // already been checked for validity
  4520. theGroup->groupDoCommandButtonAtObject(commandButton, obj, CMD_FROM_SCRIPT);
  4521. }
  4522. //-------------------------------------------------------------------------------------------------
  4523. /** doTeamUseCommandButtonOnNearestBuilding */
  4524. //-------------------------------------------------------------------------------------------------
  4525. void ScriptActions::doTeamUseCommandButtonOnNearestBuilding( const AsciiString& teamName, const AsciiString& commandAbility )
  4526. {
  4527. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4528. if (!team) {
  4529. return;
  4530. }
  4531. AIGroup *theGroup = TheAI->createGroup();
  4532. team->getTeamAsAIGroup(theGroup);
  4533. const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
  4534. if (!commandButton) {
  4535. return;
  4536. }
  4537. Object *srcObj = NULL;
  4538. if (commandButton->getSpecialPowerTemplate()) {
  4539. srcObj = theGroup->getSpecialPowerSourceObject(commandButton->getSpecialPowerTemplate()->getID());
  4540. } else {
  4541. srcObj = theGroup->getCommandButtonSourceObject(commandButton->getCommandType());
  4542. }
  4543. if (!srcObj) {
  4544. return;
  4545. }
  4546. PartitionFilterPlayerAffiliation f1(team->getControllingPlayer(), ALLOW_ENEMIES, true);
  4547. PartitionFilterAcceptByKindOf f2(MAKE_KINDOF_MASK(KINDOF_STRUCTURE), KINDOFMASK_NONE);
  4548. PartitionFilterValidCommandButtonTarget f3(srcObj, commandButton, true, CMD_FROM_SCRIPT);
  4549. PartitionFilterSameMapStatus filterMapStatus(srcObj);
  4550. Coord3D pos;
  4551. theGroup->getCenter(&pos);
  4552. PartitionFilter *filters[] = { &f1, &f2, &f3, &filterMapStatus, 0 };
  4553. Object *obj = ThePartitionManager->getClosestObject(&pos, REALLY_FAR, FROM_CENTER_2D, filters);
  4554. if (!obj) {
  4555. return;
  4556. }
  4557. // already been checked for validity
  4558. theGroup->groupDoCommandButtonAtObject(commandButton, obj, CMD_FROM_SCRIPT);
  4559. }
  4560. //-------------------------------------------------------------------------------------------------
  4561. /** doTeamUseCommandButtonOnNearestBuildingClass */
  4562. //-------------------------------------------------------------------------------------------------
  4563. void ScriptActions::doTeamUseCommandButtonOnNearestBuildingClass( const AsciiString& teamName, const AsciiString& commandAbility, Int kindofBit )
  4564. {
  4565. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4566. if (!team) {
  4567. return;
  4568. }
  4569. AIGroup *theGroup = TheAI->createGroup();
  4570. team->getTeamAsAIGroup(theGroup);
  4571. const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
  4572. if (!commandButton) {
  4573. return;
  4574. }
  4575. Object *srcObj = NULL;
  4576. if (commandButton->getSpecialPowerTemplate()) {
  4577. srcObj = theGroup->getSpecialPowerSourceObject(commandButton->getSpecialPowerTemplate()->getID());
  4578. } else {
  4579. srcObj = theGroup->getCommandButtonSourceObject(commandButton->getCommandType());
  4580. }
  4581. if (!srcObj) {
  4582. return;
  4583. }
  4584. PartitionFilterPlayerAffiliation f1(team->getControllingPlayer(), ALLOW_ENEMIES, true);
  4585. PartitionFilterAcceptByKindOf f2(MAKE_KINDOF_MASK(KINDOF_STRUCTURE), KINDOFMASK_NONE);
  4586. PartitionFilterAcceptByKindOf f3(MAKE_KINDOF_MASK(kindofBit), KINDOFMASK_NONE);
  4587. PartitionFilterValidCommandButtonTarget f4(srcObj, commandButton, true, CMD_FROM_SCRIPT);
  4588. PartitionFilterSameMapStatus filterMapStatus(srcObj);
  4589. Coord3D pos;
  4590. theGroup->getCenter(&pos);
  4591. PartitionFilter *filters[] = { &f1, &f2, &f3, &f4, &filterMapStatus, 0 };
  4592. Object *obj = ThePartitionManager->getClosestObject(&pos, REALLY_FAR, FROM_CENTER_2D, filters);
  4593. if (!obj) {
  4594. return;
  4595. }
  4596. // already been checked for validity
  4597. theGroup->groupDoCommandButtonAtObject(commandButton, obj, CMD_FROM_SCRIPT);
  4598. }
  4599. //-------------------------------------------------------------------------------------------------
  4600. /** doTeamUseCommandButtonOnNearestObjectType */
  4601. //-------------------------------------------------------------------------------------------------
  4602. void ScriptActions::doTeamUseCommandButtonOnNearestObjectType( const AsciiString& teamName, const AsciiString& commandAbility, const AsciiString& objectType )
  4603. {
  4604. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4605. if (!team) {
  4606. return;
  4607. }
  4608. AIGroup *theGroup = TheAI->createGroup();
  4609. team->getTeamAsAIGroup(theGroup);
  4610. const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
  4611. if (!commandButton) {
  4612. return;
  4613. }
  4614. Object *srcObj = NULL;
  4615. if (commandButton->getSpecialPowerTemplate()) {
  4616. srcObj = theGroup->getSpecialPowerSourceObject(commandButton->getSpecialPowerTemplate()->getID());
  4617. } else {
  4618. srcObj = theGroup->getCommandButtonSourceObject(commandButton->getCommandType());
  4619. }
  4620. if (!srcObj) {
  4621. return;
  4622. }
  4623. const ThingTemplate *thingTemplate = TheThingFactory->findTemplate(objectType);
  4624. if (!thingTemplate) {
  4625. return;
  4626. }
  4627. PartitionFilterPlayerAffiliation f1(team->getControllingPlayer(), ALLOW_ENEMIES | ALLOW_NEUTRAL, true);
  4628. PartitionFilterThing f2(thingTemplate, true);
  4629. PartitionFilterValidCommandButtonTarget f3(srcObj, commandButton, true, CMD_FROM_SCRIPT);
  4630. PartitionFilterSameMapStatus filterMapStatus(srcObj);
  4631. Coord3D pos;
  4632. theGroup->getCenter(&pos);
  4633. PartitionFilter *filters[] = { &f1, &f2, &f3, &filterMapStatus, 0 };
  4634. Object *obj = ThePartitionManager->getClosestObject(&pos, REALLY_FAR, FROM_CENTER_2D, filters);
  4635. if (!obj) {
  4636. return;
  4637. }
  4638. // already been checked for validity
  4639. theGroup->groupDoCommandButtonAtObject(commandButton, obj, CMD_FROM_SCRIPT);
  4640. }
  4641. //-------------------------------------------------------------------------------------------------
  4642. /** doTeamPartialUseCommandButton */
  4643. //-------------------------------------------------------------------------------------------------
  4644. void ScriptActions::doTeamPartialUseCommandButton( Real percentage, const AsciiString& teamName, const AsciiString& commandAbility )
  4645. {
  4646. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4647. if (!team) {
  4648. return;
  4649. }
  4650. const CommandButton *commandButton = TheControlBar->findCommandButton(commandAbility);
  4651. if (!commandButton) {
  4652. return;
  4653. }
  4654. std::vector<Object *> objList;
  4655. DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList();
  4656. for (iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance()) {
  4657. Object *obj = iter.cur();
  4658. if (commandButton->isValidToUseOn(obj, NULL, NULL, CMD_FROM_SCRIPT)) {
  4659. objList.push_back(obj);
  4660. }
  4661. }
  4662. Int numObjs = REAL_TO_INT_CEIL(percentage / 100.0f * objList.size());
  4663. Int count = 0;
  4664. for (std::vector<Object*>::const_iterator it = objList.begin(); it != objList.end(); ++it)
  4665. {
  4666. Object *obj = (*it);
  4667. if (count >= numObjs)
  4668. return;
  4669. obj->doCommandButton(commandButton, CMD_FROM_SCRIPT);
  4670. ++count;
  4671. }
  4672. }
  4673. //-------------------------------------------------------------------------------------------------
  4674. /** doTeamCaptureNearestUnownedFactionUnit */
  4675. //-------------------------------------------------------------------------------------------------
  4676. void ScriptActions::doTeamCaptureNearestUnownedFactionUnit( const AsciiString& teamName )
  4677. {
  4678. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4679. if (!team) {
  4680. return;
  4681. }
  4682. AIGroup *theGroup = TheAI->createGroup();
  4683. team->getTeamAsAIGroup(theGroup);
  4684. PartitionFilterPlayerAffiliation f1(team->getControllingPlayer(), ALLOW_ENEMIES | ALLOW_NEUTRAL, true);
  4685. PartitionFilterUnmannedObject f2(true);
  4686. PartitionFilterOnMap filterMapStatus;
  4687. Coord3D pos;
  4688. theGroup->getCenter(&pos);
  4689. PartitionFilter *filters[] = { &f1, &f2, &filterMapStatus, 0 };
  4690. Object *obj = ThePartitionManager->getClosestObject(&pos, REALLY_FAR, FROM_CENTER_2D, filters);
  4691. if (!obj) {
  4692. return;
  4693. }
  4694. theGroup->groupEnter(obj, CMD_FROM_SCRIPT);
  4695. }
  4696. //-------------------------------------------------------------------------------------------------
  4697. /** doCreateTeamFromCapturedUnits */
  4698. //-------------------------------------------------------------------------------------------------
  4699. void ScriptActions::doCreateTeamFromCapturedUnits( const AsciiString& playerName, const AsciiString& teamName )
  4700. {
  4701. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4702. if (!team) {
  4703. return;
  4704. }
  4705. }
  4706. //-------------------------------------------------------------------------------------------------
  4707. void ScriptActions::doPlayerAddSkillPoints(const AsciiString& playerName, Int delta)
  4708. {
  4709. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  4710. if (!pPlayer)
  4711. return;
  4712. pPlayer->addSkillPoints(delta);
  4713. }
  4714. //-------------------------------------------------------------------------------------------------
  4715. void ScriptActions::doPlayerAddRankLevels(const AsciiString& playerName, Int delta)
  4716. {
  4717. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  4718. if (!pPlayer)
  4719. return;
  4720. pPlayer->setRankLevel(pPlayer->getRankLevel() + delta);
  4721. }
  4722. //-------------------------------------------------------------------------------------------------
  4723. void ScriptActions::doPlayerSetRankLevel(const AsciiString& playerName, Int level)
  4724. {
  4725. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  4726. if (!pPlayer)
  4727. return;
  4728. pPlayer->setRankLevel(level);
  4729. }
  4730. //-------------------------------------------------------------------------------------------------
  4731. void ScriptActions::doMapSetRankLevelLimit(Int level)
  4732. {
  4733. if (TheGameLogic)
  4734. TheGameLogic->setRankLevelLimit(level);
  4735. }
  4736. //-------------------------------------------------------------------------------------------------
  4737. void ScriptActions::doPlayerGrantScience(const AsciiString& playerName, const AsciiString& scienceName)
  4738. {
  4739. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  4740. if (!pPlayer)
  4741. return;
  4742. ScienceType science = TheScienceStore->getScienceFromInternalName(scienceName);
  4743. if (science == SCIENCE_INVALID)
  4744. return;
  4745. pPlayer->grantScience(science);
  4746. }
  4747. //-------------------------------------------------------------------------------------------------
  4748. void ScriptActions::doPlayerPurchaseScience(const AsciiString& playerName, const AsciiString& scienceName)
  4749. {
  4750. Player* pPlayer = TheScriptEngine->getPlayerFromAsciiString(playerName);
  4751. if (!pPlayer)
  4752. return;
  4753. ScienceType science = TheScienceStore->getScienceFromInternalName(scienceName);
  4754. if (science == SCIENCE_INVALID)
  4755. return;
  4756. pPlayer->attemptToPurchaseScience(science);
  4757. }
  4758. //-------------------------------------------------------------------------------------------------
  4759. void ScriptActions::doPlayerSetScienceAvailability( const AsciiString& playerName, const AsciiString& scienceName, const AsciiString& scienceAvailability )
  4760. {
  4761. Player* player = TheScriptEngine->getPlayerFromAsciiString(playerName);
  4762. if( player )
  4763. {
  4764. ScienceAvailabilityType saType = player->getScienceAvailabilityTypeFromString( scienceAvailability );
  4765. if( saType != SCIENCE_AVAILABILITY_INVALID )
  4766. {
  4767. ScienceType science = TheScienceStore->getScienceFromInternalName( scienceName );
  4768. if( science != SCIENCE_INVALID )
  4769. {
  4770. player->setScienceAvailability( science, saType );
  4771. }
  4772. }
  4773. }
  4774. }
  4775. //-------------------------------------------------------------------------------------------------
  4776. void ScriptActions::doTeamEmoticon(const AsciiString& teamName, const AsciiString& emoticonName, Real duration)
  4777. {
  4778. Team *theTeam = TheScriptEngine->getTeamNamed( teamName );
  4779. if( !theTeam )
  4780. {
  4781. return;
  4782. }
  4783. AIGroup* theGroup = TheAI->createGroup();
  4784. if( !theGroup )
  4785. {
  4786. return;
  4787. }
  4788. theTeam->getTeamAsAIGroup( theGroup );
  4789. Int frames = (Int)( duration * LOGICFRAMES_PER_SECOND );
  4790. theGroup->groupSetEmoticon( emoticonName, frames );
  4791. }
  4792. //-------------------------------------------------------------------------------------------------
  4793. void ScriptActions::doNamedEmoticon(const AsciiString& unitName, const AsciiString& emoticonName, Real duration)
  4794. {
  4795. Object *obj = TheScriptEngine->getUnitNamed( unitName );
  4796. if( obj )
  4797. {
  4798. Drawable *draw = obj->getDrawable();
  4799. if( draw )
  4800. {
  4801. Int frames = (Int)( duration * LOGICFRAMES_PER_SECOND );
  4802. draw->setEmoticon( emoticonName, frames );
  4803. }
  4804. }
  4805. }
  4806. //-------------------------------------------------------------------------------------------------
  4807. // if addObject, we're adding an object to a list. If not addObject, we're removing the associated
  4808. // object.
  4809. //-------------------------------------------------------------------------------------------------
  4810. void ScriptActions::doObjectTypeListMaintenance(const AsciiString& objectList, const AsciiString& objectType, Bool addObject)
  4811. {
  4812. TheScriptEngine->doObjectTypeListMaintenance( objectList, objectType, addObject );
  4813. }
  4814. //-------------------------------------------------------------------------------------------------
  4815. void ScriptActions::doRevealMapAtWaypointPermanent(const AsciiString& waypointName, Real radiusToReveal, const AsciiString& playerName, const AsciiString& lookName)
  4816. {
  4817. TheScriptEngine->createNamedMapReveal(lookName, waypointName, radiusToReveal, playerName);
  4818. TheScriptEngine->doNamedMapReveal(lookName);
  4819. }
  4820. //-------------------------------------------------------------------------------------------------
  4821. void ScriptActions::doUndoRevealMapAtWaypointPermanent(const AsciiString& lookName)
  4822. {
  4823. TheScriptEngine->undoNamedMapReveal(lookName);
  4824. TheScriptEngine->removeNamedMapReveal(lookName);
  4825. }
  4826. //-------------------------------------------------------------------------------------------------
  4827. void ScriptActions::doEvaEnabledDisabled(Bool setEnabled)
  4828. {
  4829. TheEva->setEvaEnabled(setEnabled);
  4830. }
  4831. //-------------------------------------------------------------------------------------------------
  4832. void ScriptActions::doSetOcclusionMode(Bool setEnabled)
  4833. {
  4834. TheGameLogic->setShowBehindBuildingMarkers(setEnabled);
  4835. }
  4836. //-------------------------------------------------------------------------------------------------
  4837. void ScriptActions::doSetDrawIconUIMode(Bool setEnabled)
  4838. {
  4839. TheGameLogic->setDrawIconUI(setEnabled);
  4840. }
  4841. //-------------------------------------------------------------------------------------------------
  4842. void ScriptActions::doSetDynamicLODMode(Bool setEnabled)
  4843. {
  4844. TheGameLogic->setShowDynamicLOD(setEnabled);
  4845. }
  4846. //-------------------------------------------------------------------------------------------------
  4847. void ScriptActions::doOverrideHulkLifetime( Real seconds )
  4848. {
  4849. if( seconds < 0.0f )
  4850. {
  4851. // Turn it off.
  4852. TheGameLogic->setHulkMaxLifetimeOverride(-1);
  4853. }
  4854. else
  4855. {
  4856. // Convert real seconds into frames.
  4857. Int frames = (Int)(seconds * LOGICFRAMES_PER_SECOND);
  4858. TheGameLogic->setHulkMaxLifetimeOverride(frames);
  4859. }
  4860. }
  4861. //-------------------------------------------------------------------------------------------------
  4862. void ScriptActions::doNamedFaceNamed( const AsciiString &unitName, const AsciiString &faceUnitName )
  4863. {
  4864. Object *obj = TheScriptEngine->getUnitNamed( unitName );
  4865. if( obj )
  4866. {
  4867. Object *faceObj = TheScriptEngine->getUnitNamed( faceUnitName );
  4868. if( faceObj )
  4869. {
  4870. AIUpdateInterface *ai = obj->getAI();
  4871. if( ai )
  4872. {
  4873. ai->clearWaypointQueue();
  4874. obj->leaveGroup();
  4875. ai->chooseLocomotorSet( LOCOMOTORSET_NORMAL );
  4876. ai->aiFaceObject( faceObj, CMD_FROM_SCRIPT );
  4877. }
  4878. }
  4879. }
  4880. }
  4881. //-------------------------------------------------------------------------------------------------
  4882. void ScriptActions::doNamedFaceWaypoint( const AsciiString &unitName, const AsciiString &faceWaypointName )
  4883. {
  4884. Object *obj = TheScriptEngine->getUnitNamed( unitName );
  4885. if( obj )
  4886. {
  4887. Waypoint *way = TheTerrainLogic->getWaypointByName( faceWaypointName );
  4888. if( way )
  4889. {
  4890. AIUpdateInterface *ai = obj->getAI();
  4891. if( ai )
  4892. {
  4893. ai->clearWaypointQueue();
  4894. obj->leaveGroup();
  4895. ai->chooseLocomotorSet( LOCOMOTORSET_NORMAL );
  4896. ai->aiFacePosition( way->getLocation(), CMD_FROM_SCRIPT );
  4897. }
  4898. }
  4899. }
  4900. }
  4901. //-------------------------------------------------------------------------------------------------
  4902. void ScriptActions::doTeamFaceNamed( const AsciiString &teamName, const AsciiString &faceUnitName )
  4903. {
  4904. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4905. if( team )
  4906. {
  4907. Object *faceObj = TheScriptEngine->getUnitNamed( faceUnitName );
  4908. if( faceObj )
  4909. {
  4910. DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList();
  4911. for( iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance() )
  4912. {
  4913. Object *obj = iter.cur();
  4914. if( obj )
  4915. {
  4916. AIUpdateInterface *ai = obj->getAI();
  4917. if( ai )
  4918. {
  4919. ai->clearWaypointQueue();
  4920. obj->leaveGroup();
  4921. ai->chooseLocomotorSet( LOCOMOTORSET_NORMAL );
  4922. ai->aiFaceObject( faceObj, CMD_FROM_SCRIPT );
  4923. }
  4924. }
  4925. }
  4926. }
  4927. }
  4928. }
  4929. //-------------------------------------------------------------------------------------------------
  4930. void ScriptActions::doTeamFaceWaypoint( const AsciiString &teamName, const AsciiString &faceWaypointName )
  4931. {
  4932. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4933. if( team )
  4934. {
  4935. Waypoint *way = TheTerrainLogic->getWaypointByName( faceWaypointName );
  4936. if( way )
  4937. {
  4938. DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList();
  4939. for( iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance() )
  4940. {
  4941. Object *obj = iter.cur();
  4942. if( obj )
  4943. {
  4944. AIUpdateInterface *ai = obj->getAI();
  4945. if( ai )
  4946. {
  4947. ai->clearWaypointQueue();
  4948. obj->leaveGroup();
  4949. ai->chooseLocomotorSet( LOCOMOTORSET_NORMAL );
  4950. ai->aiFacePosition( way->getLocation(), CMD_FROM_SCRIPT );
  4951. }
  4952. }
  4953. }
  4954. }
  4955. }
  4956. }
  4957. //-------------------------------------------------------------------------------------------------
  4958. void ScriptActions::doAffectObjectPanelFlagsUnit(const AsciiString& unitName, const AsciiString& flagName, Bool enable)
  4959. {
  4960. Object *obj = TheScriptEngine->getUnitNamed( unitName );
  4961. if (!obj) {
  4962. return;
  4963. }
  4964. changeObjectPanelFlagForSingleObject(obj, flagName, enable);
  4965. }
  4966. //-------------------------------------------------------------------------------------------------
  4967. void ScriptActions::doAffectObjectPanelFlagsTeam(const AsciiString& teamName, const AsciiString& flagName, Bool enable)
  4968. {
  4969. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4970. if (!team) {
  4971. return;
  4972. }
  4973. DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList();
  4974. for (iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance()) {
  4975. Object *obj = iter.cur();
  4976. changeObjectPanelFlagForSingleObject(obj, flagName, enable);
  4977. }
  4978. }
  4979. //-------------------------------------------------------------------------------------------------
  4980. void ScriptActions::doAffectPlayerSkillset(const AsciiString& playerName, Int skillset)
  4981. {
  4982. Player *player = TheScriptEngine->getPlayerFromAsciiString(playerName);
  4983. if (!player) {
  4984. return;
  4985. }
  4986. --skillset;
  4987. player->friend_setSkillset(skillset);
  4988. }
  4989. //-------------------------------------------------------------------------------------------------
  4990. void ScriptActions::doGuardSupplyCenter(const AsciiString& teamName, Int supplies)
  4991. {
  4992. Team *team = TheScriptEngine->getTeamNamed(teamName);
  4993. if (!team) {
  4994. return;
  4995. }
  4996. Player *player = team->getControllingPlayer();
  4997. if (!player) {
  4998. return;
  4999. }
  5000. player->guardSupplyCenter(team, supplies);
  5001. }
  5002. //-------------------------------------------------------------------------------------------------
  5003. void ScriptActions::doTeamGuardInTunnelNetwork(const AsciiString& teamName)
  5004. {
  5005. Team *team = TheScriptEngine->getTeamNamed(teamName);
  5006. if (!team) {
  5007. return;
  5008. }
  5009. // Have all the members of the team guard at a tunnel network.
  5010. for (DLINK_ITERATOR<Object> iter = team->iterate_TeamMemberList(); !iter.done(); iter.advance())
  5011. {
  5012. Object *obj = iter.cur();
  5013. AIUpdateInterface *ai = obj->getAIUpdateInterface();
  5014. if (!ai) {
  5015. continue;
  5016. }
  5017. ai->aiGuardTunnelNetwork(GUARDMODE_NORMAL, CMD_FROM_SCRIPT);
  5018. }
  5019. }
  5020. //-------------------------------------------------------------------------------------------------
  5021. void ScriptActions::doRemoveCommandBarButton(const AsciiString& buttonName, const AsciiString& objectType)
  5022. {
  5023. const ThingTemplate *templ = TheThingFactory->findTemplate(objectType);
  5024. if (!templ) {
  5025. return;
  5026. }
  5027. const CommandSet *cs = TheControlBar->findCommandSet(templ->friend_getCommandSetString());
  5028. if (!cs) {
  5029. return;
  5030. }
  5031. Int slotNum = -1;
  5032. for (Int i = 0; i < MAX_COMMANDS_PER_SET; ++i)
  5033. {
  5034. if (cs->getCommandButton(i) && (cs->getCommandButton(i)->getName() == buttonName))
  5035. {
  5036. slotNum = i;
  5037. break;
  5038. }
  5039. }
  5040. if (slotNum >= 0)
  5041. {
  5042. TheGameLogic->setControlBarOverride(templ->friend_getCommandSetString(), slotNum, NULL);
  5043. }
  5044. }
  5045. //-------------------------------------------------------------------------------------------------
  5046. void ScriptActions::doAddCommandBarButton(const AsciiString& buttonName, const AsciiString& objectType, Int slotNum)
  5047. {
  5048. const ThingTemplate *templ = TheThingFactory->findTemplate(objectType);
  5049. if (!templ) {
  5050. return;
  5051. }
  5052. const CommandButton *commandButton = TheControlBar->findCommandButton( buttonName );
  5053. if (commandButton == NULL)
  5054. {
  5055. // not here. use doRemoveCommandBarButton to remove one.
  5056. return;
  5057. }
  5058. // decrement it, so we can present it as 1-12 for the designers.
  5059. --slotNum;
  5060. if (slotNum < 0 || slotNum >= MAX_COMMANDS_PER_SET)
  5061. return;
  5062. TheGameLogic->setControlBarOverride(templ->friend_getCommandSetString(), slotNum, commandButton);
  5063. }
  5064. //-------------------------------------------------------------------------------------------------
  5065. void ScriptActions::doAffectSkillPointsModifier(const AsciiString& playerName, Real newModifier)
  5066. {
  5067. Player *playerDst = TheScriptEngine->getPlayerFromAsciiString(playerName);
  5068. if (!playerDst) {
  5069. return;
  5070. }
  5071. playerDst->setSkillPointsModifier(newModifier);
  5072. }
  5073. //-------------------------------------------------------------------------------------------------
  5074. void ScriptActions::doResizeViewGuardband(const Real gbx, const Real gby)
  5075. {
  5076. Coord2D newGuardBand = { gbx, gby };
  5077. TheTacticalView->setGuardBandBias( &newGuardBand );
  5078. }
  5079. //-------------------------------------------------------------------------------------------------
  5080. void ScriptActions::deleteAllUnmanned()
  5081. {
  5082. Object *obj = TheGameLogic->getFirstObject();
  5083. while (obj) {
  5084. if (obj->isDisabledByType(DISABLED_UNMANNED))
  5085. TheGameLogic->destroyObject(obj);
  5086. obj = obj->getNextObject();
  5087. }
  5088. }
  5089. //-------------------------------------------------------------------------------------------------
  5090. void ScriptActions::doEnableOrDisableObjectDifficultyBonuses(Bool enableBonuses)
  5091. {
  5092. // Loops over every object in the game, applying bonuses or not.
  5093. Object *obj = TheGameLogic->getFirstObject();
  5094. while (obj) {
  5095. obj->setReceivingDifficultyBonus(enableBonuses);
  5096. obj = obj->getNextObject();
  5097. }
  5098. // notify the script engine of our decision
  5099. TheScriptEngine->setObjectsShouldReceiveDifficultyBonus(enableBonuses);
  5100. }
  5101. //-------------------------------------------------------------------------------------------------
  5102. void ScriptActions::doChooseVictimAlwaysUsesNormal(Bool enable)
  5103. {
  5104. TheScriptEngine->setChooseVictimAlwaysUsesNormal(enable);
  5105. }
  5106. //-------------------------------------------------------------------------------------------------
  5107. /** Execute an action */
  5108. //-------------------------------------------------------------------------------------------------
  5109. void ScriptActions::executeAction( ScriptAction *pAction )
  5110. {
  5111. switch (pAction->getActionType()) {
  5112. default:
  5113. DEBUG_CRASH(("Unknown ScriptAction type %d", pAction->getActionType())); return;
  5114. case ScriptAction::DEBUG_MESSAGE_BOX:
  5115. doDebugMessage(pAction->getParameter(0)->getString(), true);
  5116. return;
  5117. case ScriptAction::DEBUG_STRING:
  5118. doDebugMessage(pAction->getParameter(0)->getString(), false);
  5119. return;
  5120. case ScriptAction::DAMAGE_MEMBERS_OF_TEAM:
  5121. doDamageTeamMembers(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal());
  5122. return;
  5123. case ScriptAction::MOVE_TEAM_TO:
  5124. doMoveToWaypoint(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5125. return;
  5126. case ScriptAction::MOVE_NAMED_UNIT_TO:
  5127. doNamedMoveToWaypoint(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5128. return;
  5129. case ScriptAction::TEAM_SET_STATE:
  5130. doSetTeamState(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5131. return;
  5132. case ScriptAction::TEAM_FOLLOW_WAYPOINTS:
  5133. doTeamFollowWaypoints(pAction->getParameter(0)->getString(),
  5134. pAction->getParameter(1)->getString(),
  5135. pAction->getParameter(2)->getInt());
  5136. return;
  5137. case ScriptAction::TEAM_FOLLOW_WAYPOINTS_EXACT:
  5138. doTeamFollowWaypointsExact(pAction->getParameter(0)->getString(),
  5139. pAction->getParameter(1)->getString(),
  5140. pAction->getParameter(2)->getInt());
  5141. return;
  5142. case ScriptAction::NAMED_FOLLOW_WAYPOINTS_EXACT:
  5143. doNamedFollowWaypointsExact(pAction->getParameter(0)->getString(),
  5144. pAction->getParameter(1)->getString());
  5145. return;
  5146. case ScriptAction::SKIRMISH_FOLLOW_APPROACH_PATH:
  5147. doTeamFollowSkirmishApproachPath(pAction->getParameter(0)->getString(),
  5148. pAction->getParameter(1)->getString(),
  5149. pAction->getParameter(2)->getInt());
  5150. return;
  5151. case ScriptAction::SKIRMISH_MOVE_TO_APPROACH_PATH:
  5152. doTeamMoveToSkirmishApproachPath(pAction->getParameter(0)->getString(),
  5153. pAction->getParameter(1)->getString());
  5154. return;
  5155. case ScriptAction::CREATE_REINFORCEMENT_TEAM:
  5156. doCreateReinforcements(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5157. return;
  5158. case ScriptAction::SKIRMISH_BUILD_BUILDING:
  5159. doBuildBuilding(pAction->getParameter(0)->getString());
  5160. return;
  5161. case ScriptAction::AI_PLAYER_BUILD_SUPPLY_CENTER:
  5162. doBuildSupplyCenter(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getInt());
  5163. return;
  5164. case ScriptAction::AI_PLAYER_BUILD_UPGRADE:
  5165. doBuildUpgrade(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5166. return;
  5167. case ScriptAction::SKIRMISH_BUILD_BASE_DEFENSE_FRONT:
  5168. doBuildBaseDefense(false);
  5169. return;
  5170. case ScriptAction::SKIRMISH_BUILD_BASE_DEFENSE_FLANK:
  5171. doBuildBaseDefense(true);
  5172. return;
  5173. case ScriptAction::SKIRMISH_BUILD_STRUCTURE_FRONT:
  5174. doBuildBaseStructure(pAction->getParameter(0)->getString(), false);
  5175. return;
  5176. case ScriptAction::SKIRMISH_BUILD_STRUCTURE_FLANK:
  5177. doBuildBaseStructure(pAction->getParameter(0)->getString(), true);
  5178. return;
  5179. case ScriptAction::RECRUIT_TEAM:
  5180. doRecruitTeam(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal());
  5181. return;
  5182. case ScriptAction::PLAY_SOUND_EFFECT:
  5183. doPlaySoundEffect(pAction->getParameter(0)->getString());
  5184. return;
  5185. case ScriptAction::MOVE_CAMERA_TO:
  5186. doMoveCameraTo(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal(), pAction->getParameter(2)->getReal());
  5187. return;
  5188. case ScriptAction::SETUP_CAMERA:
  5189. doSetupCamera(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal(), pAction->getParameter(2)->getReal(), pAction->getParameter(3)->getString());
  5190. return;
  5191. case ScriptAction::ZOOM_CAMERA:
  5192. doZoomCamera(pAction->getParameter(0)->getReal(), pAction->getParameter(1)->getReal());
  5193. return;
  5194. case ScriptAction::PITCH_CAMERA:
  5195. doPitchCamera(pAction->getParameter(0)->getReal(), pAction->getParameter(1)->getReal());
  5196. return;
  5197. case ScriptAction::CAMERA_FOLLOW_NAMED:
  5198. doCameraFollowNamed(pAction->getParameter(0)->getString(), (pAction->getParameter(1) && pAction->getParameter(1)->getInt() != 0));
  5199. return;
  5200. case ScriptAction::CAMERA_STOP_FOLLOW:
  5201. doStopCameraFollowUnit();
  5202. return;
  5203. case ScriptAction::OVERSIZE_TERRAIN:
  5204. doOversizeTheTerrain(pAction->getParameter(0)->getInt());
  5205. return;
  5206. case ScriptAction::CAMERA_MOD_LOOK_TOWARD:
  5207. doModCameraLookToward(pAction->getParameter(0)->getString());
  5208. return;
  5209. case ScriptAction::CAMERA_MOD_FINAL_LOOK_TOWARD:
  5210. doModCameraFinalLookToward(pAction->getParameter(0)->getString());
  5211. return;
  5212. case ScriptAction::MOVE_CAMERA_ALONG_WAYPOINT_PATH:
  5213. doMoveCameraAlongWaypointPath(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal(), pAction->getParameter(2)->getReal());
  5214. return;
  5215. case ScriptAction::ROTATE_CAMERA:
  5216. doRotateCamera(pAction->getParameter(0)->getReal(), pAction->getParameter(1)->getReal());
  5217. return;
  5218. case ScriptAction::CAMERA_LOOK_TOWARD_OBJECT:
  5219. doRotateCameraTowardObject(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal(), pAction->getParameter(2)->getReal());
  5220. return;
  5221. case ScriptAction::CAMERA_LOOK_TOWARD_WAYPOINT:
  5222. doRotateCameraTowardWaypoint(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal());
  5223. return;
  5224. case ScriptAction::RESET_CAMERA:
  5225. doResetCamera(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal());
  5226. return;
  5227. case ScriptAction::MOVE_CAMERA_TO_SELECTION:
  5228. doModCameraMoveToSelection();
  5229. return;
  5230. case ScriptAction::CAMERA_MOD_FREEZE_TIME:
  5231. TheTacticalView->cameraModFreezeTime();
  5232. return;
  5233. case ScriptAction::CAMERA_MOD_FREEZE_ANGLE:
  5234. TheTacticalView->cameraModFreezeAngle();
  5235. return;
  5236. case ScriptAction::CAMERA_MOD_SET_FINAL_ZOOM:
  5237. TheTacticalView->cameraModFinalZoom(pAction->getParameter(0)->getReal());
  5238. return;
  5239. case ScriptAction::CAMERA_MOD_SET_FINAL_PITCH:
  5240. TheTacticalView->cameraModFinalPitch(pAction->getParameter(0)->getReal());
  5241. return;
  5242. case ScriptAction::CAMERA_MOD_SET_FINAL_SPEED_MULTIPLIER:
  5243. TheTacticalView->cameraModFinalTimeMultiplier(pAction->getParameter(0)->getInt());
  5244. return;
  5245. case ScriptAction::CAMERA_MOD_SET_ROLLING_AVERAGE:
  5246. TheTacticalView->cameraModRollingAverage(pAction->getParameter(0)->getInt());
  5247. return;
  5248. case ScriptAction::SET_VISUAL_SPEED_MULTIPLIER:
  5249. TheTacticalView->setTimeMultiplier(pAction->getParameter(0)->getInt());
  5250. return;
  5251. case ScriptAction::SUSPEND_BACKGROUND_SOUNDS:
  5252. TheAudio->pauseAudio(AudioAffect_Sound);
  5253. return;
  5254. case ScriptAction::RESUME_BACKGROUND_SOUNDS:
  5255. TheAudio->resumeAudio(AudioAffect_Sound);
  5256. return;
  5257. case ScriptAction::PLAY_SOUND_EFFECT_AT:
  5258. doPlaySoundEffectAt(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5259. return;
  5260. case ScriptAction::SET_INFANTRY_LIGHTING_OVERRIDE:
  5261. doSetInfantryLightingOverride(pAction->getParameter(0)->getReal());
  5262. return;
  5263. case ScriptAction::RESET_INFANTRY_LIGHTING_OVERRIDE:
  5264. doSetInfantryLightingOverride(-1.0f);
  5265. return;
  5266. case ScriptAction::QUICKVICTORY:
  5267. doQuickVictory();
  5268. return;
  5269. case ScriptAction::VICTORY:
  5270. doVictory();
  5271. return;
  5272. case ScriptAction::DEFEAT:
  5273. doDefeat();
  5274. return;
  5275. case ScriptAction::LOCALDEFEAT:
  5276. doLocalDefeat();
  5277. return;
  5278. case ScriptAction::CREATE_OBJECT:
  5279. {
  5280. Coord3D pos;
  5281. pAction->getParameter(2)->getCoord3D(&pos);
  5282. doCreateObject( m_unnamedUnit, pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), &pos, pAction->getParameter(3)->getReal() );
  5283. return;
  5284. }
  5285. case ScriptAction::TEAM_ATTACK_TEAM:
  5286. doAttack( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString() );
  5287. return;
  5288. case ScriptAction::NAMED_ATTACK_NAMED:
  5289. doNamedAttack( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString() );
  5290. return;
  5291. case ScriptAction::CREATE_NAMED_ON_TEAM_AT_WAYPOINT:
  5292. createUnitOnTeamAt( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString(), pAction->getParameter(3)->getString());
  5293. return;
  5294. case ScriptAction::CREATE_UNNAMED_ON_TEAM_AT_WAYPOINT:
  5295. createUnitOnTeamAt( AsciiString::TheEmptyString, pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString());
  5296. return;
  5297. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  5298. case ScriptAction::NAMED_APPLY_ATTACK_PRIORITY_SET:
  5299. updateNamedAttackPrioritySet(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5300. return;
  5301. case ScriptAction::TEAM_APPLY_ATTACK_PRIORITY_SET:
  5302. updateTeamAttackPrioritySet(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5303. return;
  5304. case ScriptAction::SET_BASE_CONSTRUCTION_SPEED:
  5305. updateBaseConstructionSpeed(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5306. return;
  5307. case ScriptAction::NAMED_SET_ATTITUDE:
  5308. updateNamedSetAttitude(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5309. return;
  5310. case ScriptAction::TEAM_SET_ATTITUDE:
  5311. updateTeamSetAttitude(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5312. return;
  5313. case ScriptAction::NAMED_SET_REPULSOR:
  5314. doNamedSetRepulsor(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5315. return;
  5316. case ScriptAction::TEAM_SET_REPULSOR:
  5317. doTeamSetRepulsor(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5318. return;
  5319. case ScriptAction::NAMED_ATTACK_AREA:
  5320. doNamedAttackArea(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5321. return;
  5322. case ScriptAction::NAMED_ATTACK_TEAM:
  5323. doNamedAttackTeam(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5324. return;
  5325. case ScriptAction::TEAM_ATTACK_AREA:
  5326. doTeamAttackArea(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5327. return;
  5328. case ScriptAction::TEAM_ATTACK_NAMED:
  5329. doTeamAttackNamed(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5330. return;
  5331. case ScriptAction::TEAM_LOAD_TRANSPORTS:
  5332. doLoadAllTransports(pAction->getParameter(0)->getString());
  5333. return;
  5334. case ScriptAction::NAMED_ENTER_NAMED:
  5335. doNamedEnterNamed(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5336. return;
  5337. case ScriptAction::TEAM_ENTER_NAMED:
  5338. doTeamEnterNamed(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5339. return;
  5340. case ScriptAction::NAMED_EXIT_ALL:
  5341. doNamedExitAll(pAction->getParameter(0)->getString());
  5342. return;
  5343. case ScriptAction::TEAM_EXIT_ALL:
  5344. doTeamExitAll(pAction->getParameter(0)->getString());
  5345. return;
  5346. case ScriptAction::NAMED_FOLLOW_WAYPOINTS:
  5347. doNamedFollowWaypoints(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5348. return;
  5349. case ScriptAction::NAMED_GUARD:
  5350. doNamedGuard(pAction->getParameter(0)->getString());
  5351. return;
  5352. case ScriptAction::TEAM_GUARD:
  5353. doTeamGuard(pAction->getParameter(0)->getString());
  5354. return;
  5355. case ScriptAction::TEAM_GUARD_POSITION:
  5356. doTeamGuardPosition(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5357. return;
  5358. case ScriptAction::TEAM_GUARD_OBJECT:
  5359. doTeamGuardObject(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5360. return;
  5361. case ScriptAction::TEAM_GUARD_AREA:
  5362. doTeamGuardArea(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5363. return;
  5364. case ScriptAction::NAMED_HUNT:
  5365. doNamedHunt(pAction->getParameter(0)->getString());
  5366. return;
  5367. case ScriptAction::TEAM_HUNT:
  5368. doTeamHunt(pAction->getParameter(0)->getString());
  5369. return;
  5370. case ScriptAction::TEAM_HUNT_WITH_COMMAND_BUTTON:
  5371. doTeamHuntWithCommandButton(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5372. return;
  5373. case ScriptAction::PLAYER_HUNT:
  5374. doPlayerHunt(pAction->getParameter(0)->getString());
  5375. return;
  5376. case ScriptAction::PLAYER_SELL_EVERYTHING:
  5377. doPlayerSellEverything(pAction->getParameter(0)->getString());
  5378. return;
  5379. case ScriptAction::PLAYER_DISABLE_BASE_CONSTRUCTION:
  5380. doPlayerDisableBaseConstruction(pAction->getParameter(0)->getString());
  5381. return;
  5382. case ScriptAction::PLAYER_DISABLE_FACTORIES:
  5383. doPlayerDisableFactories(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5384. return;
  5385. case ScriptAction::PLAYER_DISABLE_UNIT_CONSTRUCTION:
  5386. doPlayerDisableUnitConstruction(pAction->getParameter(0)->getString());
  5387. return;
  5388. case ScriptAction::PLAYER_ENABLE_BASE_CONSTRUCTION:
  5389. doPlayerEnableBaseConstruction(pAction->getParameter(0)->getString());
  5390. return;
  5391. case ScriptAction::PLAYER_ENABLE_FACTORIES:
  5392. doPlayerEnableFactories(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString() );
  5393. return;
  5394. case ScriptAction::PLAYER_REPAIR_NAMED_STRUCTURE:
  5395. doPlayerRepairStructure(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString() );
  5396. return;
  5397. case ScriptAction::PLAYER_ENABLE_UNIT_CONSTRUCTION:
  5398. doPlayerEnableUnitConstruction(pAction->getParameter(0)->getString());
  5399. return;
  5400. case ScriptAction::CAMERA_MOVE_HOME:
  5401. doCameraMoveHome();
  5402. return;
  5403. case ScriptAction::BUILD_TEAM:
  5404. doBuildTeam(pAction->getParameter(0)->getString());
  5405. return;
  5406. case ScriptAction::NAMED_DAMAGE:
  5407. doNamedDamage(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5408. return;
  5409. case ScriptAction::NAMED_DELETE:
  5410. doNamedDelete(pAction->getParameter(0)->getString());
  5411. return;
  5412. case ScriptAction::TEAM_DELETE:
  5413. doTeamDelete(pAction->getParameter(0)->getString(), FALSE);
  5414. return;
  5415. case ScriptAction::TEAM_DELETE_LIVING:
  5416. doTeamDelete(pAction->getParameter(0)->getString(), TRUE);
  5417. return;
  5418. case ScriptAction::TEAM_WANDER:
  5419. doTeamWander(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5420. return;
  5421. case ScriptAction::TEAM_WANDER_IN_PLACE:
  5422. doTeamWanderInPlace(pAction->getParameter(0)->getString());
  5423. return;
  5424. case ScriptAction::TEAM_INCREASE_PRIORITY:
  5425. doTeamIncreasePriority(pAction->getParameter(0)->getString());
  5426. return;
  5427. case ScriptAction::TEAM_DECREASE_PRIORITY:
  5428. doTeamDecreasePriority(pAction->getParameter(0)->getString());
  5429. return;
  5430. case ScriptAction::TEAM_PANIC:
  5431. doTeamPanic(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5432. return;
  5433. case ScriptAction::NAMED_KILL:
  5434. doNamedKill(pAction->getParameter(0)->getString());
  5435. return;
  5436. case ScriptAction::TEAM_KILL:
  5437. doTeamKill(pAction->getParameter(0)->getString());
  5438. return;
  5439. case ScriptAction::PLAYER_KILL:
  5440. doPlayerKill(pAction->getParameter(0)->getString());
  5441. return;
  5442. case ScriptAction::DISPLAY_TEXT:
  5443. doDisplayText(pAction->getParameter(0)->getString());
  5444. return;
  5445. case ScriptAction::DISPLAY_CINEMATIC_TEXT:
  5446. doDisplayCinematicText(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(),
  5447. pAction->getParameter(2)->getInt());
  5448. return;
  5449. case ScriptAction::DEBUG_CRASH_BOX:
  5450. #if defined(_DEBUG) || defined(_INTERNAL)
  5451. {
  5452. const char* MSG = "Your Script requested the following message be displayed:\n\n";
  5453. const char* MSG2 = "\n\nTHIS IS NOT A BUG. DO NOT REPORT IT.";
  5454. DEBUG_CRASH(("%s%s%s\n",MSG,pAction->getParameter(0)->getString().str(),MSG2));
  5455. }
  5456. #endif
  5457. return;
  5458. case ScriptAction::INGAME_POPUP_MESSAGE:
  5459. doInGamePopupMessage(pAction->getParameter(0)->getString(),pAction->getParameter(1)->getInt(),
  5460. pAction->getParameter(2)->getInt(), pAction->getParameter(3)->getInt(),
  5461. pAction->getParameter(4)->getInt() );
  5462. return;
  5463. case ScriptAction::CAMEO_FLASH:
  5464. doCameoFlash(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5465. return;
  5466. case ScriptAction::NAMED_FLASH:
  5467. doNamedFlash(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt(), NULL);
  5468. return;
  5469. case ScriptAction::TEAM_FLASH:
  5470. doTeamFlash(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt(), NULL);
  5471. return;
  5472. case ScriptAction::NAMED_FLASH_WHITE:
  5473. {
  5474. RGBColor c;
  5475. c.red = c.green = c.blue = 1.0f;
  5476. doNamedFlash(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt(), &c);
  5477. }
  5478. return;
  5479. case ScriptAction::NAMED_CUSTOM_COLOR:
  5480. {
  5481. doNamedCustomColor(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5482. }
  5483. return;
  5484. case ScriptAction::TEAM_FLASH_WHITE:
  5485. {
  5486. RGBColor c;
  5487. c.red = c.green = c.blue = 1.0f;
  5488. doTeamFlash(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt(), &c);
  5489. }
  5490. return;
  5491. case ScriptAction::MOVIE_PLAY_FULLSCREEN:
  5492. doMoviePlayFullScreen(pAction->getParameter(0)->getString());
  5493. return;
  5494. case ScriptAction::MOVIE_PLAY_RADAR:
  5495. doMoviePlayRadar(pAction->getParameter(0)->getString());
  5496. return;
  5497. case ScriptAction::SOUND_PLAY_NAMED:
  5498. doSoundPlayFromNamed(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5499. return;
  5500. case ScriptAction::SPEECH_PLAY:
  5501. doSpeechPlay(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5502. return;
  5503. case ScriptAction::PLAYER_TRANSFER_OWNERSHIP_PLAYER:
  5504. doPlayerTransferAssetsToPlayer(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5505. return;
  5506. case ScriptAction::NAMED_TRANSFER_OWNERSHIP_PLAYER:
  5507. doNamedTransferAssetsToPlayer(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5508. return;
  5509. case ScriptAction::PLAYER_EXCLUDE_FROM_SCORE_SCREEN:
  5510. excludePlayerFromScoreScreen(pAction->getParameter(0)->getString());
  5511. return;
  5512. case ScriptAction::ENABLE_SCORING:
  5513. enableScoring(TRUE);
  5514. return;
  5515. case ScriptAction::DISABLE_SCORING:
  5516. enableScoring(FALSE);
  5517. return;
  5518. case ScriptAction::PLAYER_RELATES_PLAYER:
  5519. updatePlayerRelationTowardPlayer(pAction->getParameter(0)->getString(), pAction->getParameter(2)->getInt(), pAction->getParameter(1)->getString());
  5520. return;
  5521. case ScriptAction::RADAR_CREATE_EVENT:
  5522. {
  5523. Coord3D pos;
  5524. pAction->getParameter(0)->getCoord3D(&pos);
  5525. doRadarCreateEvent(&pos, pAction->getParameter(1)->getInt());
  5526. return;
  5527. }
  5528. case ScriptAction::OBJECT_CREATE_RADAR_EVENT:
  5529. doObjectRadarCreateEvent(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5530. return;
  5531. case ScriptAction::TEAM_CREATE_RADAR_EVENT:
  5532. doTeamRadarCreateEvent(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5533. return;
  5534. case ScriptAction::RADAR_DISABLE:
  5535. doRadarDisable();
  5536. return;
  5537. case ScriptAction::RADAR_ENABLE:
  5538. doRadarEnable();
  5539. return;
  5540. case ScriptAction::NAMED_SET_STEALTH_ENABLED:
  5541. doNamedEnableStealth(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5542. return;
  5543. case ScriptAction::TEAM_SET_STEALTH_ENABLED:
  5544. doTeamEnableStealth(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5545. return;
  5546. case ScriptAction::MAP_REVEAL_AT_WAYPOINT:
  5547. doRevealMapAtWaypoint(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal(), pAction->getParameter(2)->getString());
  5548. return;
  5549. case ScriptAction::MAP_SHROUD_AT_WAYPOINT:
  5550. doShroudMapAtWaypoint(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal(), pAction->getParameter(2)->getString());
  5551. return;
  5552. case ScriptAction::MAP_REVEAL_ALL:
  5553. doRevealMapEntire(pAction->getParameter(0)->getString());
  5554. return;
  5555. case ScriptAction::MAP_REVEAL_ALL_PERM:
  5556. doRevealMapEntirePermanently(TRUE, pAction->getParameter(0)->getString());
  5557. return;
  5558. case ScriptAction::MAP_REVEAL_ALL_UNDO_PERM:
  5559. doRevealMapEntirePermanently(FALSE, pAction->getParameter(0)->getString());
  5560. return;
  5561. case ScriptAction::MAP_SHROUD_ALL:
  5562. doShroudMapEntire(pAction->getParameter(0)->getString());
  5563. return;
  5564. case ScriptAction::TEAM_AVAILABLE_FOR_RECRUITMENT:
  5565. doTeamAvailableForRecruitment(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5566. return;
  5567. case ScriptAction::TEAM_COLLECT_NEARBY_FOR_TEAM:
  5568. doCollectNearbyForTeam(pAction->getParameter(0)->getString());
  5569. return;
  5570. case ScriptAction::TEAM_MERGE_INTO_TEAM:
  5571. doMergeTeamIntoTeam(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5572. return;
  5573. case ScriptAction::IDLE_ALL_UNITS:
  5574. doIdleAllPlayerUnits(AsciiString::TheEmptyString);
  5575. return;
  5576. case ScriptAction::RESUME_SUPPLY_TRUCKING:
  5577. doResumeSupplyTruckingForIdleUnits(AsciiString::TheEmptyString);
  5578. return;
  5579. case ScriptAction::DISABLE_INPUT:
  5580. doDisableInput();
  5581. return;
  5582. case ScriptAction::ENABLE_INPUT:
  5583. doEnableInput();
  5584. return;
  5585. case ScriptAction::DISABLE_BORDER_SHROUD:
  5586. doSetBorderShroud(FALSE);
  5587. return;
  5588. case ScriptAction::ENABLE_BORDER_SHROUD:
  5589. doSetBorderShroud(TRUE);
  5590. return;
  5591. case ScriptAction::SOUND_AMBIENT_PAUSE:
  5592. doAmbientSoundsPause(true);
  5593. return;
  5594. case ScriptAction::SOUND_AMBIENT_RESUME:
  5595. doAmbientSoundsPause(false);
  5596. return;
  5597. case ScriptAction::MUSIC_SET_TRACK:
  5598. doMusicTrackChange(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt(), pAction->getParameter(2)->getInt());
  5599. return;
  5600. case ScriptAction::TEAM_GARRISON_SPECIFIC_BUILDING:
  5601. doTeamGarrisonSpecificBuilding(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5602. return;
  5603. case ScriptAction::EXIT_SPECIFIC_BUILDING:
  5604. doExitSpecificBuilding(pAction->getParameter(0)->getString());
  5605. return;
  5606. case ScriptAction::TEAM_GARRISON_NEAREST_BUILDING:
  5607. doTeamGarrisonNearestBuilding(pAction->getParameter(0)->getString());
  5608. return;
  5609. case ScriptAction::TEAM_EXIT_ALL_BUILDINGS:
  5610. doTeamExitAllBuildings(pAction->getParameter(0)->getString());
  5611. return;
  5612. case ScriptAction::NAMED_GARRISON_SPECIFIC_BUILDING:
  5613. doUnitGarrisonSpecificBuilding(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5614. return;
  5615. case ScriptAction::NAMED_GARRISON_NEAREST_BUILDING:
  5616. doUnitGarrisonNearestBuilding(pAction->getParameter(0)->getString());
  5617. return;
  5618. case ScriptAction::NAMED_EXIT_BUILDING:
  5619. doUnitExitBuilding(pAction->getParameter(0)->getString());
  5620. return;
  5621. case ScriptAction::PLAYER_GARRISON_ALL_BUILDINGS:
  5622. doPlayerGarrisonAllBuildings(pAction->getParameter(0)->getString());
  5623. return;
  5624. case ScriptAction::PLAYER_EXIT_ALL_BUILDINGS:
  5625. doPlayerExitAllBuildings(pAction->getParameter(0)->getString());
  5626. return;
  5627. case ScriptAction::CAMERA_LETTERBOX_BEGIN:
  5628. doLetterBoxMode(true);
  5629. return;
  5630. case ScriptAction::CAMERA_LETTERBOX_END:
  5631. doLetterBoxMode(false);
  5632. return;
  5633. case ScriptAction::CAMERA_BW_MODE_BEGIN:
  5634. doBlackWhiteMode(true, pAction->getParameter(0) ? pAction->getParameter(0)->getInt() : 0);
  5635. return;
  5636. case ScriptAction::CAMERA_BW_MODE_END:
  5637. doBlackWhiteMode(false, pAction->getParameter(0) ? pAction->getParameter(0)->getInt() : 0);
  5638. return;
  5639. case ScriptAction::DRAW_SKYBOX_BEGIN:
  5640. doSkyBox(true);
  5641. return;
  5642. case ScriptAction::DRAW_SKYBOX_END:
  5643. doSkyBox(false);
  5644. return;
  5645. case ScriptAction::CAMERA_MOTION_BLUR:
  5646. doCameraMotionBlur(pAction->getParameter(0)->getInt(), pAction->getParameter(1)->getInt());
  5647. return;
  5648. case ScriptAction::CAMERA_MOTION_BLUR_JUMP:
  5649. doCameraMotionBlurJump(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5650. return;
  5651. case ScriptAction::CAMERA_MOTION_BLUR_FOLLOW:
  5652. TheTacticalView->setViewFilterMode((enum FilterModes)(FM_VIEW_MB_PAN_ALPHA+pAction->getParameter(0)->getInt()));
  5653. TheTacticalView->setViewFilter(FT_VIEW_MOTION_BLUR_FILTER);
  5654. return;
  5655. case ScriptAction::CAMERA_MOTION_BLUR_END_FOLLOW:
  5656. TheTacticalView->setViewFilterMode(FM_VIEW_MB_END_PAN_ALPHA);
  5657. TheTacticalView->setViewFilter(FT_VIEW_MOTION_BLUR_FILTER);
  5658. return;
  5659. case ScriptAction::FREEZE_TIME:
  5660. doFreezeTime();
  5661. return;
  5662. case ScriptAction::UNFREEZE_TIME:
  5663. doUnfreezeTime();
  5664. return;
  5665. case ScriptAction::SHOW_MILITARY_CAPTION:
  5666. doMilitaryCaption(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5667. return;
  5668. case ScriptAction::CAMERA_SET_AUDIBLE_DISTANCE:
  5669. doCameraSetAudibleDistance(pAction->getParameter(0)->getReal());
  5670. return;
  5671. case ScriptAction::SET_STOPPING_DISTANCE:
  5672. doSetStoppingDistance(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal());
  5673. return;
  5674. case ScriptAction::SET_FPS_LIMIT:
  5675. if (!pAction->getParameter(0)->getInt())
  5676. {
  5677. TheGameEngine->setFramesPerSecondLimit(TheGlobalData->m_framesPerSecondLimit);
  5678. }
  5679. else
  5680. {
  5681. TheGameEngine->setFramesPerSecondLimit(pAction->getParameter(0)->getInt());
  5682. }
  5683. // Setting the fps limit doesn't do much good if we don't use it. jba.
  5684. TheWritableGlobalData->m_useFpsLimit = true;
  5685. return;
  5686. case ScriptAction::DISABLE_SPECIAL_POWER_DISPLAY:
  5687. doDisableSpecialPowerDisplay();
  5688. return;
  5689. case ScriptAction::ENABLE_SPECIAL_POWER_DISPLAY:
  5690. doEnableSpecialPowerDisplay();
  5691. return;
  5692. case ScriptAction::NAMED_HIDE_SPECIAL_POWER_DISPLAY:
  5693. doNamedHideSpecialPowerDisplay(pAction->getParameter(0)->getString());
  5694. return;
  5695. case ScriptAction::NAMED_SHOW_SPECIAL_POWER_DISPLAY:
  5696. doNamedShowSpecialPowerDisplay(pAction->getParameter(0)->getString());
  5697. return;
  5698. case ScriptAction::NAMED_SET_STOPPING_DISTANCE:
  5699. doNamedSetStoppingDistance(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal());
  5700. return;
  5701. case ScriptAction::NAMED_SET_HELD:
  5702. doNamedSetHeld(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5703. return;
  5704. case ScriptAction::MUSIC_SET_VOLUME:
  5705. doAudioSetVolume(AudioAffect_Music, pAction->getParameter(0)->getReal());
  5706. return;
  5707. case ScriptAction::SOUND_SET_VOLUME:
  5708. doAudioSetVolume((AudioAffect)(AudioAffect_Sound | AudioAffect_Sound3D), pAction->getParameter(0)->getReal());
  5709. return;
  5710. case ScriptAction::SPEECH_SET_VOLUME:
  5711. doAudioSetVolume(AudioAffect_Speech, pAction->getParameter(0)->getReal());
  5712. return;
  5713. case ScriptAction::TEAM_TRANSFER_TO_PLAYER:
  5714. doTransferTeamToPlayer(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5715. return;
  5716. case ScriptAction::PLAYER_SET_MONEY:
  5717. doSetMoney(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5718. return;
  5719. case ScriptAction::PLAYER_GIVE_MONEY:
  5720. doGiveMoney(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5721. return;
  5722. case ScriptAction::DISPLAY_COUNTDOWN_TIMER:
  5723. doDisplayCountdownTimer(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5724. return;
  5725. case ScriptAction::HIDE_COUNTDOWN_TIMER:
  5726. doHideCountdownTimer(pAction->getParameter(0)->getString());
  5727. return;
  5728. case ScriptAction::DISPLAY_COUNTER:
  5729. doDisplayCounter(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5730. return;
  5731. case ScriptAction::HIDE_COUNTER:
  5732. doHideCounter(pAction->getParameter(0)->getString());
  5733. return;
  5734. case ScriptAction::DISABLE_COUNTDOWN_TIMER_DISPLAY:
  5735. doDisableCountdownTimerDisplay();
  5736. return;
  5737. case ScriptAction::ENABLE_COUNTDOWN_TIMER_DISPLAY:
  5738. doEnableCountdownTimerDisplay();
  5739. return;
  5740. case ScriptAction::NAMED_STOP_SPECIAL_POWER_COUNTDOWN:
  5741. doNamedStopSpecialPowerCountdown(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), TRUE);
  5742. return;
  5743. case ScriptAction::NAMED_START_SPECIAL_POWER_COUNTDOWN:
  5744. doNamedStopSpecialPowerCountdown(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), FALSE);
  5745. return;
  5746. case ScriptAction::NAMED_SET_SPECIAL_POWER_COUNTDOWN:
  5747. doNamedSetSpecialPowerCountdown(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getInt());
  5748. return;
  5749. case ScriptAction::NAMED_ADD_SPECIAL_POWER_COUNTDOWN:
  5750. doNamedAddSpecialPowerCountdown(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getInt());
  5751. return;
  5752. case ScriptAction::NAMED_FIRE_SPECIAL_POWER_AT_WAYPOINT:
  5753. doNamedFireSpecialPowerAtWaypoint(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString());
  5754. return;
  5755. case ScriptAction::SKIRMISH_FIRE_SPECIAL_POWER_AT_MOST_COST:
  5756. doSkirmishFireSpecialPowerAtMostCost(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5757. return;
  5758. case ScriptAction::NAMED_FIRE_SPECIAL_POWER_AT_NAMED:
  5759. doNamedFireSpecialPowerAtNamed(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString());
  5760. return;
  5761. case ScriptAction::REFRESH_RADAR:
  5762. doRadarRefresh();
  5763. return;
  5764. case ScriptAction::NAMED_STOP:
  5765. doNamedStop(pAction->getParameter(0)->getString());
  5766. return;
  5767. case ScriptAction::TEAM_STOP:
  5768. doTeamStop(pAction->getParameter(0)->getString(), FALSE);
  5769. return;
  5770. case ScriptAction::TEAM_STOP_AND_DISBAND:
  5771. doTeamStop(pAction->getParameter(0)->getString(), TRUE);
  5772. return;
  5773. case ScriptAction::CAMERA_TETHER_NAMED:
  5774. doCameraTetherNamed(pAction->getParameter(0)->getString(), (Bool)(pAction->getParameter(1)->getInt()), pAction->getParameter(2)->getReal());
  5775. return;
  5776. case ScriptAction::CAMERA_STOP_TETHER_NAMED:
  5777. doCameraStopTetherNamed();
  5778. return;
  5779. case ScriptAction::CAMERA_SET_DEFAULT:
  5780. doCameraSetDefault(pAction->getParameter(0)->getReal(), pAction->getParameter(1)->getReal(), pAction->getParameter(2)->getReal());
  5781. return;
  5782. case ScriptAction::TEAM_SET_OVERRIDE_RELATION_TO_TEAM:
  5783. doTeamSetOverrideRelationToTeam(pAction->getParameter(0)->getString(), // first team
  5784. pAction->getParameter(1)->getString(), // second team
  5785. pAction->getParameter(2)->getInt()); // relation (ENEMIES, etc)
  5786. return;
  5787. case ScriptAction::TEAM_REMOVE_OVERRIDE_RELATION_TO_TEAM:
  5788. doTeamRemoveOverrideRelationToTeam(pAction->getParameter(0)->getString(), // first team
  5789. pAction->getParameter(1)->getString()); // second team
  5790. return;
  5791. case ScriptAction::TEAM_REMOVE_ALL_OVERRIDE_RELATIONS:
  5792. doTeamRemoveAllOverrideRelations(pAction->getParameter(0)->getString()); // first team
  5793. return;
  5794. case ScriptAction::TEAM_SET_OVERRIDE_RELATION_TO_PLAYER:
  5795. doTeamSetOverrideRelationToPlayer(pAction->getParameter(0)->getString(), // first team
  5796. pAction->getParameter(1)->getString(), // second player
  5797. pAction->getParameter(2)->getInt()); // relation (ENEMIES, etc)
  5798. return;
  5799. case ScriptAction::TEAM_REMOVE_OVERRIDE_RELATION_TO_PLAYER:
  5800. doTeamRemoveOverrideRelationToPlayer(pAction->getParameter(0)->getString(), // first team
  5801. pAction->getParameter(1)->getString()); // second player
  5802. return;
  5803. case ScriptAction::PLAYER_SET_OVERRIDE_RELATION_TO_TEAM:
  5804. doPlayerSetOverrideRelationToTeam(pAction->getParameter(0)->getString(), // first player
  5805. pAction->getParameter(1)->getString(), // second team
  5806. pAction->getParameter(2)->getInt()); // relation (ENEMIES, etc)
  5807. return;
  5808. case ScriptAction::PLAYER_REMOVE_OVERRIDE_RELATION_TO_TEAM:
  5809. doPlayerRemoveOverrideRelationToTeam(pAction->getParameter(0)->getString(), // first player
  5810. pAction->getParameter(1)->getString()); // second team
  5811. return;
  5812. case ScriptAction::NAMED_FIRE_WEAPON_FOLLOWING_WAYPOINT_PATH:
  5813. doNamedFireWeaponFollowingWaypointPath(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString() );
  5814. return;
  5815. case ScriptAction::NAMED_USE_COMMANDBUTTON_ABILITY:
  5816. doNamedUseCommandButtonAbility( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString() );
  5817. return;
  5818. case ScriptAction::NAMED_USE_COMMANDBUTTON_ABILITY_ON_NAMED:
  5819. doNamedUseCommandButtonAbilityOnNamed( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString() );
  5820. return;
  5821. case ScriptAction::NAMED_USE_COMMANDBUTTON_ABILITY_AT_WAYPOINT:
  5822. doNamedUseCommandButtonAbilityAtWaypoint( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString() );
  5823. return;
  5824. case ScriptAction::TEAM_USE_COMMANDBUTTON_ABILITY:
  5825. doTeamUseCommandButtonAbility( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString() );
  5826. return;
  5827. case ScriptAction::TEAM_USE_COMMANDBUTTON_ABILITY_ON_NAMED:
  5828. doTeamUseCommandButtonAbilityOnNamed( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString() );
  5829. return;
  5830. case ScriptAction::TEAM_USE_COMMANDBUTTON_ABILITY_AT_WAYPOINT:
  5831. doTeamUseCommandButtonAbilityAtWaypoint( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString() );
  5832. return;
  5833. case ScriptAction::UNIT_EXECUTE_SEQUENTIAL_SCRIPT:
  5834. doUnitStartSequentialScript(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), 0);
  5835. return;
  5836. case ScriptAction::UNIT_EXECUTE_SEQUENTIAL_SCRIPT_LOOPING:
  5837. doUnitStartSequentialScript(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getInt() - 1);
  5838. return;
  5839. case ScriptAction::UNIT_STOP_SEQUENTIAL_SCRIPT:
  5840. doUnitStopSequentialScript(pAction->getParameter(0)->getString());
  5841. return;
  5842. case ScriptAction::TEAM_EXECUTE_SEQUENTIAL_SCRIPT:
  5843. doTeamStartSequentialScript(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), 0);
  5844. return;
  5845. case ScriptAction::TEAM_EXECUTE_SEQUENTIAL_SCRIPT_LOOPING:
  5846. doTeamStartSequentialScript(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getInt() - 1);
  5847. return;
  5848. case ScriptAction::TEAM_STOP_SEQUENTIAL_SCRIPT:
  5849. doTeamStopSequentialScript(pAction->getParameter(0)->getString());
  5850. return;
  5851. case ScriptAction::UNIT_GUARD_FOR_FRAMECOUNT:
  5852. doUnitGuardForFramecount(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5853. return;
  5854. case ScriptAction::UNIT_IDLE_FOR_FRAMECOUNT:
  5855. doUnitIdleForFramecount(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5856. return;
  5857. case ScriptAction::TEAM_GUARD_FOR_FRAMECOUNT:
  5858. doTeamIdleForFramecount(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5859. return;
  5860. case ScriptAction::TEAM_IDLE_FOR_FRAMECOUNT:
  5861. doTeamIdleForFramecount(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5862. return;
  5863. case ScriptAction::WATER_CHANGE_HEIGHT:
  5864. doWaterChangeHeight(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal());
  5865. return;
  5866. case ScriptAction::WATER_CHANGE_HEIGHT_OVER_TIME:
  5867. doWaterChangeHeightOverTime( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal(),
  5868. pAction->getParameter(2)->getReal(), pAction->getParameter(3)->getReal() );
  5869. return;
  5870. case ScriptAction::MAP_SWITCH_BORDER:
  5871. doBorderSwitch(pAction->getParameter(0)->getInt());
  5872. return;
  5873. case ScriptAction::OBJECT_FORCE_SELECT:
  5874. doForceObjectSelection(pAction->getParameter(0)->getString(),
  5875. pAction->getParameter(1)->getString(),
  5876. pAction->getParameter(2)->getInt(),
  5877. pAction->getParameter(3)->getString());
  5878. return;
  5879. case ScriptAction::UNIT_DESTROY_ALL_CONTAINED:
  5880. doDestroyAllContained(pAction->getParameter(0)->getString(), 0);
  5881. return;
  5882. case ScriptAction::RADAR_FORCE_ENABLE:
  5883. doRadarForceEnable();
  5884. return;
  5885. case ScriptAction::RADAR_REVERT_TO_NORMAL:
  5886. doRadarRevertNormal();
  5887. return;
  5888. case ScriptAction::SCREEN_SHAKE:
  5889. doScreenShake( (View::CameraShakeType)pAction->getParameter( 0 )->getInt() );
  5890. return;
  5891. case ScriptAction::TECHTREE_MODIFY_BUILDABILITY_OBJECT:
  5892. doModifyBuildableStatus(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5893. return;
  5894. case ScriptAction::SET_CAVE_INDEX:
  5895. doSetCaveIndex(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5896. return;
  5897. case ScriptAction::WAREHOUSE_SET_VALUE:
  5898. doSetWarehouseValue(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5899. return;
  5900. case ScriptAction::SOUND_DISABLE_TYPE:
  5901. doSoundEnableType(pAction->getParameter(0)->getString(), false);
  5902. return;
  5903. case ScriptAction::SOUND_ENABLE_TYPE:
  5904. doSoundEnableType(pAction->getParameter(0)->getString(), true);
  5905. return;
  5906. case ScriptAction::SOUND_ENABLE_ALL:
  5907. doSoundEnableType(AsciiString::TheEmptyString, true);
  5908. return;
  5909. case ScriptAction::SOUND_REMOVE_ALL_DISABLED:
  5910. doSoundRemoveAllDisabled();
  5911. return;
  5912. case ScriptAction::SOUND_REMOVE_TYPE:
  5913. doSoundRemoveType(pAction->getParameter(0)->getString());
  5914. return;
  5915. case ScriptAction::AUDIO_OVERRIDE_VOLUME_TYPE:
  5916. doSoundOverrideVolume(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal());
  5917. return;
  5918. case ScriptAction::AUDIO_RESTORE_VOLUME_TYPE:
  5919. doSoundOverrideVolume(pAction->getParameter(0)->getString(), -100.0);
  5920. return;
  5921. case ScriptAction::AUDIO_RESTORE_VOLUME_ALL_TYPE:
  5922. doSoundOverrideVolume(AsciiString::TheEmptyString, -100.0);
  5923. return;
  5924. case ScriptAction::NAMED_SET_TOPPLE_DIRECTION:
  5925. {
  5926. Coord3D dir;
  5927. pAction->getParameter(1)->getCoord3D(&dir);
  5928. doSetToppleDirection(pAction->getParameter(0)->getString(), &dir);
  5929. return;
  5930. }
  5931. case ScriptAction::UNIT_MOVE_TOWARDS_NEAREST_OBJECT_TYPE:
  5932. doMoveUnitTowardsNearest(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString());
  5933. return;
  5934. case ScriptAction::TEAM_MOVE_TOWARDS_NEAREST_OBJECT_TYPE:
  5935. doMoveTeamTowardsNearest(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString());
  5936. return;
  5937. case ScriptAction::NAMED_RECEIVE_UPGRADE:
  5938. doUnitReceiveUpgrade(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5939. return;
  5940. case ScriptAction::SKIRMISH_ATTACK_NEAREST_GROUP_WITH_VALUE:
  5941. doSkirmishAttackNearestGroupWithValue(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt(), pAction->getParameter(2)->getInt());
  5942. return;
  5943. case ScriptAction::SKIRMISH_PERFORM_COMMANDBUTTON_ON_MOST_VALUABLE_OBJECT:
  5944. doSkirmishCommandButtonOnMostValuable(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getReal(), pAction->getParameter(3)->getInt());
  5945. return;
  5946. case ScriptAction::SKIRMISH_WAIT_FOR_COMMANDBUTTON_AVAILABLE_ALL:
  5947. // We should never get here.
  5948. DEBUG_CRASH(("\"[Skirmish] Wait for command button available - all\" should never be used outside of Sequential scripts. - jkmcd"));
  5949. return;
  5950. case ScriptAction::SKIRMISH_WAIT_FOR_COMMANDBUTTON_AVAILABLE_PARTIAL:
  5951. // We should never get here.
  5952. DEBUG_CRASH(("\"[Skirmish] Wait for command button available - partial\" should never be used outside of Sequential scripts. - jkmcd"));
  5953. return;
  5954. case ScriptAction::TEAM_WAIT_FOR_NOT_CONTAINED_ALL:
  5955. // We should never get here.
  5956. DEBUG_CRASH(("\"[Team] Wait for team no longer contained - all\" should never be used outside of Sequential scripts. - jkmcd"));
  5957. return;
  5958. case ScriptAction::TEAM_WAIT_FOR_NOT_CONTAINED_PARTIAL:
  5959. // We should never get here.
  5960. DEBUG_CRASH(("\"[Team] Wait for team no longer contained - partial\" should never be used outside of Sequential scripts. - jkmcd"));
  5961. return;
  5962. case ScriptAction::TEAM_SPIN_FOR_FRAMECOUNT:
  5963. doTeamSpinForFramecount( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt() );
  5964. return;
  5965. case ScriptAction::TEAM_ALL_USE_COMMANDBUTTON_ON_NAMED:
  5966. doTeamUseCommandButtonOnNamed(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString());
  5967. return;
  5968. case ScriptAction::TEAM_ALL_USE_COMMANDBUTTON_ON_NEAREST_ENEMY_UNIT:
  5969. doTeamUseCommandButtonOnNearestEnemy(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5970. return;
  5971. case ScriptAction::TEAM_ALL_USE_COMMANDBUTTON_ON_NEAREST_GARRISONED_BUILDING:
  5972. doTeamUseCommandButtonOnNearestGarrisonedBuilding(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5973. return;
  5974. case ScriptAction::TEAM_ALL_USE_COMMANDBUTTON_ON_NEAREST_KINDOF:
  5975. doTeamUseCommandButtonOnNearestKindof(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getInt());
  5976. return;
  5977. case ScriptAction::TEAM_ALL_USE_COMMANDBUTTON_ON_NEAREST_ENEMY_BUILDING:
  5978. doTeamUseCommandButtonOnNearestBuilding(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5979. return;
  5980. case ScriptAction::TEAM_ALL_USE_COMMANDBUTTON_ON_NEAREST_ENEMY_BUILDING_CLASS:
  5981. doTeamUseCommandButtonOnNearestBuildingClass(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getInt());
  5982. return;
  5983. case ScriptAction::TEAM_ALL_USE_COMMANDBUTTON_ON_NEAREST_OBJECTTYPE:
  5984. doTeamUseCommandButtonOnNearestObjectType(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString());
  5985. return;
  5986. case ScriptAction::TEAM_PARTIAL_USE_COMMANDBUTTON:
  5987. doTeamPartialUseCommandButton(pAction->getParameter(0)->getReal(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString());
  5988. return;
  5989. case ScriptAction::TEAM_CAPTURE_NEAREST_UNOWNED_FACTION_UNIT:
  5990. doTeamCaptureNearestUnownedFactionUnit(pAction->getParameter(0)->getString());
  5991. return;
  5992. case ScriptAction::PLAYER_CREATE_TEAM_FROM_CAPTURED_UNITS:
  5993. doCreateTeamFromCapturedUnits(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  5994. return;
  5995. case ScriptAction::PLAYER_ADD_SKILLPOINTS:
  5996. doPlayerAddSkillPoints(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  5997. return;
  5998. case ScriptAction::PLAYER_ADD_RANKLEVEL:
  5999. doPlayerAddRankLevels(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  6000. return;
  6001. case ScriptAction::PLAYER_SET_RANKLEVEL:
  6002. doPlayerSetRankLevel(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  6003. return;
  6004. case ScriptAction::PLAYER_SET_RANKLEVELLIMIT:
  6005. doMapSetRankLevelLimit(pAction->getParameter(0)->getInt());
  6006. return;
  6007. case ScriptAction::PLAYER_GRANT_SCIENCE:
  6008. doPlayerGrantScience(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  6009. return;
  6010. case ScriptAction::PLAYER_PURCHASE_SCIENCE:
  6011. doPlayerPurchaseScience(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  6012. return;
  6013. case ScriptAction::PLAYER_SCIENCE_AVAILABILITY:
  6014. doPlayerSetScienceAvailability(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString());
  6015. return;
  6016. case ScriptAction::TEAM_SET_EMOTICON:
  6017. doTeamEmoticon( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getReal() );
  6018. return;
  6019. case ScriptAction::NAMED_SET_EMOTICON:
  6020. doNamedEmoticon( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getReal() );
  6021. return;
  6022. case ScriptAction::OBJECTLIST_ADDOBJECTTYPE:
  6023. doObjectTypeListMaintenance(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), TRUE);
  6024. return;
  6025. case ScriptAction::OBJECTLIST_REMOVEOBJECTTYPE:
  6026. doObjectTypeListMaintenance(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), FALSE);
  6027. return;
  6028. case ScriptAction::MAP_REVEAL_PERMANENTLY_AT_WAYPOINT:
  6029. doRevealMapAtWaypointPermanent(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal(), pAction->getParameter(2)->getString(), pAction->getParameter(3)->getString());
  6030. return;
  6031. case ScriptAction::MAP_UNDO_REVEAL_PERMANENTLY_AT_WAYPOINT:
  6032. doUndoRevealMapAtWaypointPermanent(pAction->getParameter(0)->getString());
  6033. return;
  6034. case ScriptAction::EVA_SET_ENABLED_DISABLED:
  6035. doEvaEnabledDisabled(pAction->getParameter(0)->getInt());
  6036. return;
  6037. case ScriptAction::OPTIONS_SET_OCCLUSION_MODE:
  6038. doSetOcclusionMode(pAction->getParameter(0)->getInt());
  6039. return;
  6040. case ScriptAction::OPTIONS_SET_DRAWICON_UI_MODE:
  6041. doSetDrawIconUIMode(pAction->getParameter(0)->getInt());
  6042. return;
  6043. case ScriptAction::OPTIONS_SET_PARTICLE_CAP_MODE:
  6044. doSetDynamicLODMode(pAction->getParameter(0)->getInt());
  6045. return;
  6046. case ScriptAction::SCRIPTING_OVERRIDE_HULK_LIFETIME:
  6047. doOverrideHulkLifetime( pAction->getParameter( 0 )->getReal() );
  6048. return;
  6049. case ScriptAction::NAMED_FACE_NAMED:
  6050. doNamedFaceNamed( pAction->getParameter( 0 )->getString(), pAction->getParameter( 1 )->getString() );
  6051. return;
  6052. case ScriptAction::NAMED_FACE_WAYPOINT:
  6053. doNamedFaceWaypoint( pAction->getParameter( 0 )->getString(), pAction->getParameter( 1 )->getString() );
  6054. return;
  6055. case ScriptAction::TEAM_FACE_NAMED:
  6056. doTeamFaceNamed( pAction->getParameter( 0 )->getString(), pAction->getParameter( 1 )->getString() );
  6057. return;
  6058. case ScriptAction::TEAM_FACE_WAYPOINT:
  6059. doTeamFaceWaypoint( pAction->getParameter( 0 )->getString(), pAction->getParameter( 1 )->getString() );
  6060. return;
  6061. case ScriptAction::UNIT_AFFECT_OBJECT_PANEL_FLAGS:
  6062. doAffectObjectPanelFlagsUnit(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getInt());
  6063. return;
  6064. case ScriptAction::TEAM_AFFECT_OBJECT_PANEL_FLAGS:
  6065. doAffectObjectPanelFlagsTeam(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getInt());
  6066. return;
  6067. case ScriptAction::PLAYER_SELECT_SKILLSET:
  6068. doAffectPlayerSkillset(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  6069. return;
  6070. case ScriptAction::COMMANDBAR_REMOVE_BUTTON_OBJECTTYPE:
  6071. doRemoveCommandBarButton(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString());
  6072. return;
  6073. case ScriptAction::COMMANDBAR_ADD_BUTTON_OBJECTTYPE_SLOT:
  6074. doAddCommandBarButton(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getInt());
  6075. return;
  6076. case ScriptAction::UNIT_SPAWN_NAMED_LOCATION_ORIENTATION:
  6077. {
  6078. Coord3D pos;
  6079. pAction->getParameter(3)->getCoord3D(&pos);
  6080. doCreateObject( pAction->getParameter(0)->getString(), pAction->getParameter(1)->getString(), pAction->getParameter(2)->getString(), &pos, pAction->getParameter(4)->getReal() );
  6081. return;
  6082. }
  6083. case ScriptAction::PLAYER_AFFECT_RECEIVING_EXPERIENCE:
  6084. doAffectSkillPointsModifier(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getReal());
  6085. return;
  6086. case ScriptAction::TEAM_GUARD_SUPPLY_CENTER:
  6087. doGuardSupplyCenter(pAction->getParameter(0)->getString(), pAction->getParameter(1)->getInt());
  6088. return;
  6089. case ScriptAction::OBJECT_ALLOW_BONUSES:
  6090. doEnableOrDisableObjectDifficultyBonuses(pAction->getParameter(0)->getInt());
  6091. return;
  6092. case ScriptAction::TEAM_GUARD_IN_TUNNEL_NETWORK:
  6093. doTeamGuardInTunnelNetwork(pAction->getParameter(0)->getString());
  6094. return;
  6095. case ScriptAction::RESIZE_VIEW_GUARDBAND:
  6096. doResizeViewGuardband( pAction->getParameter(0)->getReal(), pAction->getParameter(1)->getReal() );
  6097. return;
  6098. case ScriptAction::DELETE_ALL_UNMANNED:
  6099. deleteAllUnmanned();
  6100. return;
  6101. case ScriptAction::CHOOSE_VICTIM_ALWAYS_USES_NORMAL:
  6102. doChooseVictimAlwaysUsesNormal(pAction->getParameter(0)->getInt());
  6103. return;
  6104. }
  6105. }