BUILDING.CPP 247 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/BUILDING.CPP 5 3/13/97 5:18p Joe_b $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : BUILDING.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : September 10, 1993 *
  26. * *
  27. * Last Update : October 27, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * BuildingClass::AI -- Handles non-graphic AI processing for buildings. *
  32. * BuildingClass::Active_Click_With -- Handles cell selection for buildings. *
  33. * BuildingClass::Animation_AI -- Handles normal building animation processing. *
  34. * BuildingClass::Assign_Target -- Assigns a target to the building. *
  35. * BuildingClass::Begin_Mode -- Begins an animation mode for the building. *
  36. * BuildingClass::BuildingClass -- Constructor for buildings. *
  37. * BuildingClass::Can_Demolish -- Can the player demolish (sell back) the building? *
  38. * BuildingClass::Can_Enter_Cell -- Determines if building can be placed down. *
  39. * BuildingClass::Can_Fire -- Determines if this building can fire. *
  40. * BuildingClass::Can_Player_Move -- Can this building be moved? *
  41. * BuildingClass::Captured -- Captures the building. *
  42. * BuildingClass::Center_Coord -- Fetches the center coordinate for the building. *
  43. * BuildingClass::Charging_AI -- Handles the special charging logic for Tesla coils. *
  44. * BuildingClass::Check_Point -- Fetches the landing checkpoint for the given flight pattern.*
  45. * BuildingClass::Click_With -- Handles clicking on the map while the building is selected. *
  46. * BuildingClass::Crew_Type -- This determines the crew that this object generates. *
  47. * BuildingClass::Death_Announcement -- Announce the death of this building. *
  48. * BuildingClass::Debug_Dump -- Displays building status to the monochrome screen. *
  49. * BuildingClass::Detach -- Handles target removal from the game system. *
  50. * BuildingClass::Detach_All -- Possibly abandons production according to factory type. *
  51. * BuildingClass::Docking_Coord -- Fetches the coordinate to use for docking. *
  52. * BuildingClass::Draw_It -- Displays the building at the location specified. *
  53. * BuildingClass::Drop_Debris -- Drops rubble when building is destroyed. *
  54. * BuildingClass::Enter_Idle_Mode -- The building will enter its idle mode. *
  55. * BuildingClass::Exit_Coord -- Determines location where object will leave it. *
  56. * BuildingClass::Exit_Object -- Initiates an object to leave the building. *
  57. * BuildingClass::Factory_AI -- Handle factory production and initiation. *
  58. * BuildingClass::Find_Exit_Cell -- Find a clear location to exit an object from this buildin*
  59. * BuildingClass::Fire_Direction -- Fetches the direction of firing. *
  60. * BuildingClass::Fire_Out -- Handles when attached animation expires. *
  61. * BuildingClass::Flush_For_Placement -- Handles clearing a zone for object placement. *
  62. * BuildingClass::Get_Image_Data -- Fetch the image pointer for the building. *
  63. * BuildingClass::Grand_Opening -- Handles construction completed special operations. *
  64. * BuildingClass::Greatest_Threat -- Searches for target that building can fire upon. *
  65. * BuildingClass::How_Many_Survivors -- This determine the maximum number of survivors. *
  66. * BuildingClass::Init -- Initialize the building system to an empty null state. *
  67. * BuildingClass::Limbo -- Handles power adjustment as building goes into limbo. *
  68. * BuildingClass::Mark -- Building interface to map rendering system. *
  69. * BuildingClass::Mission_Attack -- Handles attack mission for building. *
  70. * BuildingClass::Mission_Construction -- Handles mission construction. *
  71. * BuildingClass::Mission_Deconstruction -- Handles building deconstruction. *
  72. * BuildingClass::Mission_Guard -- Handles guard mission for combat buildings. *
  73. * BuildingClass::Mission_Harvest -- Handles refinery unloading harvesters. *
  74. * BuildingClass::Mission_Missile -- State machine for nuclear missile launch. *
  75. * BuildingClass::Mission_Repair -- Handles the repair (active) state for building. *
  76. * BuildingClass::Mission_Unload -- Handles the unload mission for a building. *
  77. * BuildingClass::Pip_Count -- Determines "full" pips to display for building. *
  78. * BuildingClass::Power_Output -- Fetches the current power output from this building. *
  79. * BuildingClass::Read_INI -- Reads buildings from INI file. *
  80. * BuildingClass::Receive_Message -- Handle an incoming message to the building. *
  81. * BuildingClass::Remap_Table -- Fetches the remap table to use for this building. *
  82. * BuildingClass::Remove_Gap_Effect -- Stop a gap generator from jamming cells *
  83. * BuildingClass::Repair -- Initiates or terminates the repair process. *
  84. * BuildingClass::Repair_AI -- Handle the repair (and sell) logic for the building. *
  85. * BuildingClass::Revealed -- Reveals the building to the specified house. *
  86. * BuildingClass::Rotation_AI -- Process any turret rotation required of this building. *
  87. * BuildingClass::Sell_Back -- Controls the sell back (demolish) operation. *
  88. * BuildingClass::Shape_Number -- Fetch the shape number for this building. *
  89. * BuildingClass::Sort_Y -- Returns the building coordinate used for sorting. *
  90. * BuildingClass::Take_Damage -- Inflicts damage points upon a building. *
  91. * BuildingClass::Target_Coord -- Return the coordinate to use when firing on this building. *
  92. * BuildingClass::Toggle_Primary -- Toggles the primary factory state. *
  93. * BuildingClass::Turret_Facing -- Fetches the turret facing for this building. *
  94. * BuildingClass::Unlimbo -- Removes a building from limbo state. *
  95. * BuildingClass::Update_Buildables -- Informs sidebar of additional construction options. *
  96. * BuildingClass::Value -- Determine the value of this building. *
  97. * BuildingClass::What_Action -- Determines action to perform if click on specified object. *
  98. * BuildingClass::What_Action -- Determines what action will occur. *
  99. * BuildingClass::Write_INI -- Write out the building data to the INI file specified. *
  100. * BuildingClass::delete -- Deallocates building object. *
  101. * BuildingClass::new -- Allocates a building object from building pool. *
  102. * BuildingClass::~BuildingClass -- Destructor for building type objects. *
  103. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  104. #include "function.h"
  105. /*
  106. ** New sidebar for GlyphX multiplayer. ST - 8/2/2019 2:35PM
  107. */
  108. #include "SidebarGlyphx.h"
  109. enum SAMState {
  110. SAM_READY, // Launcher can be facing any direction tracking targets.
  111. SAM_FIRING // Stationary while missile is being fired.
  112. };
  113. /***************************************************************************
  114. ** Center of building offset table.
  115. */
  116. COORDINATE const BuildingClass::CenterOffset[BSIZE_COUNT] = {
  117. 0x00800080L,
  118. 0x008000FFL,
  119. 0x00FF0080L,
  120. 0x00FF00FFL,
  121. 0x018000FFL,
  122. 0x00FF0180L,
  123. 0x01800180L,
  124. 0x00FF0200L,
  125. 0x02800280L,
  126. };
  127. /***********************************************************************************************
  128. * BuildingClass::Receive_Message -- Handle an incoming message to the building. *
  129. * *
  130. * This routine handles an incoming message to the building. Messages regulate the *
  131. * various cooperative ventures between buildings and units. This might include such *
  132. * actions as coordinating the construction yard animation with the actual building's *
  133. * construction animation. *
  134. * *
  135. * INPUT: from -- The originator of the message received. *
  136. * *
  137. * message -- The radio message received. *
  138. * *
  139. * param -- Reference to an optional parameter that might be used to return *
  140. * extra information to the message originator. *
  141. * *
  142. * OUTPUT: Returns with the response to the message (typically, this is just RADIO_OK). *
  143. * *
  144. * WARNINGS: none *
  145. * *
  146. * HISTORY: *
  147. * 06/09/1994 JLB : Created. *
  148. * 06/26/1995 JLB : Forces refinery load anim to start immediately. *
  149. * 08/13/1995 JLB : Uses ScenarioInit for special loose "CAN_LOAD" check. *
  150. *=============================================================================================*/
  151. RadioMessageType BuildingClass::Receive_Message(RadioClass * from, RadioMessageType message, long & param)
  152. {
  153. assert(Buildings.ID(this) == ID);
  154. assert(IsActive);
  155. switch (message) {
  156. /*
  157. ** This message is received as a request to attach/load/dock with this building.
  158. ** Verify that this is allowed and return the appropriate response.
  159. */
  160. case RADIO_CAN_LOAD:
  161. TechnoClass::Receive_Message(from, message, param);
  162. if (!House->Is_Ally(from)) return(RADIO_STATIC);
  163. if (Mission == MISSION_CONSTRUCTION || Mission == MISSION_DECONSTRUCTION || BState == BSTATE_CONSTRUCTION || (!ScenarioInit && Class->Type != STRUCT_REFINERY && In_Radio_Contact())) return(RADIO_NEGATIVE);
  164. switch (Class->Type) {
  165. case STRUCT_AIRSTRIP:
  166. if (from->What_Am_I() == RTTI_AIRCRAFT && ((AircraftClass const *)from)->Class->IsFixedWing) {
  167. return(RADIO_ROGER);
  168. }
  169. break;
  170. case STRUCT_HELIPAD:
  171. if (from->What_Am_I() == RTTI_AIRCRAFT && !((AircraftClass const *)from)->Class->IsFixedWing) {
  172. return(RADIO_ROGER);
  173. }
  174. break;
  175. case STRUCT_REPAIR:
  176. if (from->What_Am_I() == RTTI_UNIT || (from->What_Am_I() == RTTI_AIRCRAFT)) {
  177. if (Transmit_Message(RADIO_ON_DEPOT, from) != RADIO_ROGER) {
  178. return(RADIO_ROGER);
  179. }
  180. }
  181. return(RADIO_NEGATIVE);
  182. case STRUCT_REFINERY:
  183. if (from->What_Am_I() == RTTI_UNIT &&
  184. *((UnitClass *)from) == UNIT_HARVESTER &&
  185. (ScenarioInit || !Is_Something_Attached())) {
  186. return((Contact_With_Whom() != from) ? RADIO_ROGER : RADIO_NEGATIVE);
  187. }
  188. break;
  189. default:
  190. break;
  191. }
  192. return(RADIO_STATIC);
  193. /*
  194. ** This message is received when the object has attached itself to this
  195. ** building.
  196. */
  197. case RADIO_IM_IN:
  198. if (Mission == MISSION_DECONSTRUCTION) {
  199. return(RADIO_NEGATIVE);
  200. }
  201. switch (Class->Type) {
  202. case STRUCT_REPAIR:
  203. IsReadyToCommence = true;
  204. Assign_Mission(MISSION_REPAIR);
  205. from->Assign_Mission(MISSION_SLEEP);
  206. return(RADIO_ROGER);
  207. case STRUCT_AIRSTRIP:
  208. case STRUCT_HELIPAD:
  209. Assign_Mission(MISSION_REPAIR);
  210. from->Assign_Mission(MISSION_SLEEP);
  211. return(RADIO_ROGER);
  212. case STRUCT_REFINERY:
  213. Mark(MARK_CHANGE);
  214. from->Assign_Mission(MISSION_UNLOAD);
  215. return(RADIO_ROGER);
  216. default:
  217. break;
  218. }
  219. break;
  220. /*
  221. ** Docking maneuver maintenance message. See if new order should be given to the
  222. ** unit trying to dock.
  223. */
  224. case RADIO_DOCKING:
  225. TechnoClass::Receive_Message(from, message, param);
  226. /*
  227. ** When in radio contact for loading, the refinery starts
  228. ** flashing the lights.
  229. */
  230. if (*this == STRUCT_REFINERY && BState != BSTATE_FULL) {
  231. Begin_Mode(BSTATE_FULL);
  232. }
  233. /*
  234. ** If this building is already in radio contact, then it might
  235. ** be able to satisfy the request to load by bumping off any
  236. ** preoccupying task.
  237. */
  238. if (*this == STRUCT_REPAIR) {
  239. if (Contact_With_Whom() != from) {
  240. if (Transmit_Message(RADIO_ON_DEPOT) == RADIO_ROGER) {
  241. if (Transmit_Message(RADIO_NEED_REPAIR) == RADIO_NEGATIVE) {
  242. Transmit_Message(RADIO_RUN_AWAY);
  243. Transmit_Message(RADIO_OVER_OUT);
  244. return(RADIO_ROGER);
  245. }
  246. }
  247. }
  248. }
  249. /*
  250. ** Establish contact with the object if this building isn't already in contact
  251. ** with another.
  252. */
  253. if (!In_Radio_Contact()) {
  254. Transmit_Message(RADIO_HELLO, from);
  255. }
  256. if (Transmit_Message(RADIO_NEED_TO_MOVE) == RADIO_ROGER) {
  257. switch (Class->Type) {
  258. case STRUCT_AIRSTRIP:
  259. param = As_Target();
  260. break;
  261. case STRUCT_HELIPAD:
  262. param = As_Target();
  263. break;
  264. case STRUCT_REPAIR:
  265. Transmit_Message(RADIO_TETHER);
  266. param = ::As_Target(Coord_Cell(Center_Coord()));
  267. break;
  268. case STRUCT_REFINERY:
  269. param = ::As_Target(Coord_Cell(Adjacent_Cell(Center_Coord(), DIR_S)));
  270. break;
  271. }
  272. /*
  273. ** Tell the harvester to move to the docking pad of the building.
  274. */
  275. if (Transmit_Message(RADIO_MOVE_HERE, param) == RADIO_YEA_NOW_WHAT) {
  276. /*
  277. ** Since the harvester is already there, tell it to begin the backup
  278. ** procedure now. If it can't, then tell it to get outta here.
  279. */
  280. Transmit_Message(RADIO_TETHER);
  281. if (*this == STRUCT_REFINERY && Transmit_Message(RADIO_BACKUP_NOW, from) != RADIO_ROGER) {
  282. from->Scatter(NULL, true, true);
  283. }
  284. }
  285. }
  286. return(RADIO_ROGER);
  287. /*
  288. ** If a transport or harvester is requesting permission to head toward, dock
  289. ** and load/unload, check to make sure that this is allowed given the current
  290. ** state of the building.
  291. */
  292. case RADIO_ARE_REFINERY:
  293. if (Is_Something_Attached() || In_Radio_Contact() || IsInLimbo || House->Class->House != from->Owner() || (*this != STRUCT_REFINERY/* && *this != STRUCT_REPAIR*/)) {
  294. return(RADIO_NEGATIVE);
  295. }
  296. return(RADIO_ROGER);
  297. /*
  298. ** Someone is telling us that it is starting construction. This should only
  299. ** occur if this is a construction yard and a building was just placed on
  300. ** the map.
  301. */
  302. case RADIO_BUILDING:
  303. Assign_Mission(MISSION_REPAIR);
  304. TechnoClass::Receive_Message(from, message, param);
  305. return(RADIO_ROGER);
  306. /*
  307. ** Someone is telling us that they have finished construction. This should
  308. ** only occur if this is a construction yard and the building that was being
  309. ** constructed has finished. In this case, stop the construction yard
  310. ** animation.
  311. */
  312. case RADIO_COMPLETE:
  313. if (Mission != MISSION_DECONSTRUCTION) {
  314. Assign_Mission(MISSION_GUARD);
  315. }
  316. TechnoClass::Receive_Message(from, message, param);
  317. return(RADIO_ROGER);
  318. /*
  319. ** This message may occur unexpectedly if the unit in contact with this
  320. ** building is suddenly destroyed. Handle any cleanup necessary. For example,
  321. ** a construction yard should stop its construction animation in this case.
  322. */
  323. case RADIO_OVER_OUT:
  324. Begin_Mode(BSTATE_IDLE);
  325. if (*this == STRUCT_REPAIR) {
  326. Assign_Mission(MISSION_GUARD);
  327. }
  328. TechnoClass::Receive_Message(from, message, param);
  329. return(RADIO_ROGER);
  330. /*
  331. ** This message is received when an object has completely left
  332. ** building. Sometimes special cleanup action is required when
  333. ** this event occurs.
  334. */
  335. case RADIO_UNLOADED:
  336. if (*this == STRUCT_REPAIR) {
  337. if (Distance(from) < 0x0180) {
  338. return(RADIO_ROGER);
  339. }
  340. }
  341. TechnoClass::Receive_Message(from, message, param);
  342. if (*this == STRUCT_WEAP || *this == STRUCT_AIRSTRIP || *this == STRUCT_REPAIR) return(RADIO_RUN_AWAY);
  343. return(RADIO_ROGER);
  344. default:
  345. break;
  346. }
  347. /*
  348. ** Pass along the message to the default message handler in the radio itself.
  349. */
  350. return(TechnoClass::Receive_Message(from, message, param));
  351. }
  352. #ifdef CHEAT_KEYS
  353. /***********************************************************************************************
  354. * BuildingClass::Debug_Dump -- Displays building status to the monochrome screen. *
  355. * *
  356. * This utility function will output the current status of the building class to the *
  357. * monochrome screen. It is through this data that bugs may be fixed or detected. *
  358. * *
  359. * INPUT: none *
  360. * *
  361. * OUTPUT: none *
  362. * *
  363. * WARNINGS: none *
  364. * *
  365. * HISTORY: *
  366. * 05/31/1994 JLB : Created. *
  367. *=============================================================================================*/
  368. void BuildingClass::Debug_Dump(MonoClass * mono) const
  369. {
  370. assert(Buildings.ID(this) == ID);
  371. assert(IsActive);
  372. mono->Set_Cursor(0, 0);
  373. mono->Print(Text_String(TXT_DEBUG_BUILDING));
  374. mono->Fill_Attrib(66, 13, 12, 1, IsRepairing ? MonoClass::INVERSE : MonoClass::NORMAL);
  375. mono->Fill_Attrib(66, 14, 12, 1, IsToRebuild ? MonoClass::INVERSE : MonoClass::NORMAL);
  376. mono->Fill_Attrib(66, 15, 12, 1, IsAllowedToSell ? MonoClass::INVERSE : MonoClass::NORMAL);
  377. mono->Fill_Attrib(66, 16, 12, 1, IsCharging ? MonoClass::INVERSE : MonoClass::NORMAL);
  378. mono->Fill_Attrib(66, 17, 12, 1, IsCharged ? MonoClass::INVERSE : MonoClass::NORMAL);
  379. mono->Fill_Attrib(66, 18, 12, 1, IsJamming ? MonoClass::INVERSE : MonoClass::NORMAL);
  380. mono->Fill_Attrib(66, 19, 12, 1, IsJammed ? MonoClass::INVERSE : MonoClass::NORMAL);
  381. mono->Set_Cursor(1, 11);
  382. if (Factory) {
  383. mono->Printf("%s %d%%", Factory->Get_Object()->Class_Of().IniName, (100*Factory->Completion())/FactoryClass::STEP_COUNT);
  384. }
  385. TechnoClass::Debug_Dump(mono);
  386. }
  387. #endif
  388. /***********************************************************************************************
  389. * BuildingClass::Draw_It -- Displays the building at the location specified. *
  390. * *
  391. * This is the low level graphic routine that displays the building at the location *
  392. * specified. *
  393. * *
  394. * INPUT: x,y -- The coordinate to draw the building at. *
  395. * *
  396. * window -- The clipping window to use. *
  397. * *
  398. * OUTPUT: none *
  399. * *
  400. * WARNINGS: none *
  401. * *
  402. * HISTORY: *
  403. * 06/20/1994 JLB : Created. *
  404. * 06/27/1994 JLB : Takes a clipping window parameter. *
  405. * 07/06/1995 JLB : Handles damaged silos correctly. *
  406. *=============================================================================================*/
  407. void BuildingClass::Draw_It(int x, int y, WindowNumberType window) const
  408. {
  409. assert(Buildings.ID(this) == ID);
  410. assert(IsActive);
  411. /*
  412. ** The shape file to use for rendering depends on whether the building
  413. ** is undergoing construction or not.
  414. */
  415. void const * shapefile = Get_Image_Data();
  416. if (shapefile == NULL) return;
  417. /*
  418. ** Actually draw the building shape.
  419. */
  420. IsTheaterShape = Class->IsTheater; //Let Build_Frame know if this is a theater specific shape
  421. Techno_Draw_Object(shapefile, Shape_Number(), x, y, window);
  422. IsTheaterShape = false;
  423. /*
  424. ** Patch for adding overlay onto weapon factory. Only add the overlay if
  425. ** the building has more than 1 hp. Also, if the building's in radio
  426. ** contact, he must be unloading a constructed vehicle, so draw that
  427. ** vehicle before drawing the overlay.
  428. */
  429. if (BState != BSTATE_CONSTRUCTION) {
  430. /*
  431. ** A Tethered object is always rendered AFTER the building.
  432. */
  433. if (*this == STRUCT_WEAP && IsTethered && In_Radio_Contact() && !Contact_With_Whom()->IsInLimbo && Contact_With_Whom()->What_Am_I() != RTTI_BUILDING) {
  434. TechnoClass * contact = Contact_With_Whom();
  435. assert(contact->IsActive);
  436. int xxx = x + ((int)Lepton_To_Pixel((int)Coord_X(contact->Render_Coord())) - (int)Lepton_To_Pixel((int)Coord_X(Render_Coord())));
  437. int yyy = y + ((int)Lepton_To_Pixel((int)Coord_Y(contact->Render_Coord())) - (int)Lepton_To_Pixel((int)Coord_Y(Render_Coord())));
  438. contact->Draw_It(xxx, yyy, window);
  439. contact->IsToDisplay = false;
  440. }
  441. /*
  442. ** Draw the weapon factory custom overlay graphic.
  443. */
  444. if ( (*this == STRUCT_WEAP || *this == STRUCT_FAKEWEAP)) {
  445. int shapenum = Door_Stage();
  446. if (Health_Ratio() <= Rule.ConditionYellow) shapenum += 4;
  447. // Added override shape file name. ST - 8/1/2019 5:24PM
  448. //Techno_Draw_Object(Class->WarFactoryOverlay, shapenum, x, y, window);
  449. Techno_Draw_Object_Virtual(Class->WarFactoryOverlay, shapenum, x, y, window, DIR_N, 0x0100, "WEAP2");
  450. }
  451. /*
  452. ** Draw any repair feedback graphic required.
  453. */
  454. if (IsRepairing && IsWrenchVisible) {
  455. CC_Draw_Shape(ObjectTypeClass::SelectShapes, SELECT_WRENCH, x, y, window, SHAPE_CENTER|SHAPE_WIN_REL);
  456. }
  457. }
  458. TechnoClass::Draw_It(x, y, window);
  459. /*
  460. ** If this is a factory that we're spying on, show what it's producing
  461. */
  462. if ((Spied_By() & (1<<(PlayerPtr->Class->House)) && Is_Selected_By_Player()) || ((window == WINDOW_VIRTUAL) && (Session.Type != GAME_NORMAL))) {
  463. /*
  464. ** Fetch the factory that is associate with this building. For computer controlled buildings, the
  465. ** factory pointer is integral to the building itself. For human controlled buildings, the factory
  466. ** pointer is part of the house structure and must be retrieved from there.
  467. */
  468. FactoryClass * factory = NULL;
  469. if (House->IsHuman) {
  470. factory = House->Fetch_Factory(Class->ToBuild);
  471. } else {
  472. factory = Factory;
  473. }
  474. /*
  475. ** If there is a factory associated with this building, then fetch any attached
  476. ** object under production and display its cameo image over the top of this building.
  477. */
  478. if (factory != NULL) {
  479. TechnoClass * obj = factory->Get_Object();
  480. if (obj != NULL) {
  481. #ifdef FIXIT_CSII
  482. CC_Draw_Shape(obj, obj->Techno_Type_Class()->Get_Cameo_Data(), 0, x, y, window, SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_NORMAL, NULL);
  483. #else
  484. void const * remapper = obj->House->Remap_Table(false, obj->Techno_Type_Class()->Remap);
  485. CC_Draw_Shape(obj->Techno_Type_Class()->Get_Cameo_Data(), 0, x, y, window, SHAPE_CENTER|SHAPE_WIN_REL | ((remapper != NULL) ? SHAPE_FADING : SHAPE_NORMAL), remapper);
  486. #endif
  487. }
  488. }
  489. }
  490. }
  491. /***********************************************************************************************
  492. * BuildingClass::Shape_Number -- Fetch the shape number for this building. *
  493. * *
  494. * This routine will examine the current state of the building and return with the shape *
  495. * number to use. The shape number is subordinate to the building graphic image data. *
  496. * *
  497. * INPUT: none *
  498. * *
  499. * OUTPUT: Returns with the shape number to use when rendering this building. *
  500. * *
  501. * WARNINGS: none *
  502. * *
  503. * HISTORY: *
  504. * 07/29/1996 JLB : Created. *
  505. *=============================================================================================*/
  506. int BuildingClass::Shape_Number(void) const
  507. {
  508. assert(Buildings.ID(this) == ID);
  509. assert(IsActive);
  510. int shapenum = Fetch_Stage();
  511. /*
  512. ** The shape file to use for rendering depends on whether the building
  513. ** is undergoing construction or not.
  514. */
  515. if (BState == BSTATE_CONSTRUCTION) {
  516. /*
  517. ** If the building is deconstructing, then the display frame progresses
  518. ** from the end to the beginning. Reverse the shape number accordingly.
  519. */
  520. if (Mission == MISSION_DECONSTRUCTION) {
  521. shapenum = (Class->Anims[BState].Start+Class->Anims[BState].Count-1)-shapenum;
  522. }
  523. } else {
  524. /*
  525. ** If this is a camouflaged pill box and it is not owned by the player, then
  526. ** it is displayed with the MEGA-camouflaged imagery.
  527. */
  528. if ((!IsOwnedByPlayer) && (*this == STRUCT_CAMOPILLBOX)) {
  529. shapenum += 1;
  530. }
  531. /*
  532. ** The Tesla Coil has a stage value that can be overridden by
  533. ** its current state.
  534. */
  535. if (*this == STRUCT_TESLA) {
  536. if (IsCharged) {
  537. shapenum = 3;
  538. } else {
  539. if (IsCharging) {
  540. shapenum = Fetch_Stage();
  541. } else {
  542. shapenum = 0;
  543. }
  544. }
  545. }
  546. /*
  547. ** Buildings that contain a turret handle their shape determination
  548. ** differently than normal buildings. They need to take into consideration
  549. ** the direction the turret is facing.
  550. */
  551. if (Class->IsTurretEquipped) {
  552. shapenum = UnitClass::BodyShape[Dir_To_32(PrimaryFacing.Current())];
  553. if (*this == STRUCT_SAM) {
  554. /*
  555. ** SAM sites that are free to rotate fetch their animation frame
  556. ** from the building's turret facing. All other animation stages
  557. ** fetch their frame from the embedded animation sequencer.
  558. */
  559. // if (Status == SAM_READY || Status == SAM_FIRING || Status == SAM_LOCKING) {
  560. // shapenum = Fetch_Stage();
  561. // }
  562. if (Health_Ratio() <= Rule.ConditionYellow) {
  563. shapenum += 35;
  564. }
  565. } else {
  566. if (IsInRecoilState) {
  567. shapenum += 32;
  568. }
  569. if (Health_Ratio() <= Rule.ConditionYellow) {
  570. shapenum += 64;
  571. }
  572. }
  573. } else {
  574. /*
  575. ** If it is a significantly damaged weapons factory, it is shown in
  576. ** the worst state possible.
  577. */
  578. if (*this == STRUCT_WEAP || *this == STRUCT_FAKEWEAP) {
  579. shapenum = 0;
  580. if (Health_Ratio() <= Rule.ConditionYellow) {
  581. shapenum = 1;
  582. }
  583. } else {
  584. /*
  585. ** Special render stage for silos. The stage is dependent on the current
  586. ** Tiberium collected as it relates to Tiberium capacity.
  587. */
  588. if (*this == STRUCT_STORAGE) {
  589. int level = 0;
  590. if (House->Capacity) {
  591. level = (House->Tiberium * 5) / House->Capacity;
  592. }
  593. shapenum += Bound(level, 0, 4);
  594. if (Health_Ratio() <= Rule.ConditionYellow) {
  595. shapenum += 5;
  596. }
  597. } else {
  598. /*
  599. ** If below half strenth, then show the damage frames of the
  600. ** building.
  601. */
  602. if (Health_Ratio() <= Rule.ConditionYellow) {
  603. if (*this == STRUCT_CHRONOSPHERE) {
  604. shapenum += 29;
  605. } else {
  606. int last1 = Class->Anims[BSTATE_IDLE].Start + Class->Anims[BSTATE_IDLE].Count;
  607. int last2 = Class->Anims[BSTATE_ACTIVE].Start + Class->Anims[BSTATE_ACTIVE].Count;
  608. int largest = max(last1, last2);
  609. last2 = Class->Anims[BSTATE_AUX1].Start + Class->Anims[BSTATE_AUX1].Count;
  610. largest = max(largest, last2);
  611. last2 = Class->Anims[BSTATE_AUX2].Start + Class->Anims[BSTATE_AUX2].Count;
  612. largest = max(largest, last2);
  613. shapenum += largest;
  614. }
  615. }
  616. }
  617. }
  618. }
  619. }
  620. return(shapenum);
  621. }
  622. /***********************************************************************************************
  623. * BuildingClass::Mark -- Building interface to map rendering system. *
  624. * *
  625. * This routine is used to mark the map cells so that when it renders *
  626. * the underlying icons will also be updated as necessary. *
  627. * *
  628. * INPUT: mark -- Type of image change (MARK_UP, _DOWN, _CHANGE) *
  629. * MARK_UP -- Building is removed. *
  630. * MARK_CHANGE -- Building changes shape. *
  631. * MARK_DOWN -- Building is added. *
  632. * *
  633. * OUTPUT: bool; Did the mark operation succeed? Failure could be the result of marking down *
  634. * when the building is already marked down, or visa versa. *
  635. * *
  636. * WARNINGS: none *
  637. * *
  638. * HISTORY: *
  639. * 03/31/1994 JLB : Created. *
  640. * 04/15/1994 JLB : Converted to member function. *
  641. * 04/16/1994 JLB : Added health bar tracking. *
  642. * 12/23/1994 JLB : Calls low level check before proceeding. *
  643. * 01/27/1995 JLB : Special road spacer template added. *
  644. *=============================================================================================*/
  645. bool BuildingClass::Mark(MarkType mark)
  646. {
  647. assert(Buildings.ID(this) == ID);
  648. assert(IsActive);
  649. if (TechnoClass::Mark(mark)) {
  650. short const * offset = Overlap_List();
  651. short const * occupy = Occupy_List();
  652. CELL cell = Coord_Cell(Coord);
  653. SmudgeType bib;
  654. switch (mark) {
  655. case MARK_UP:
  656. Map.Pick_Up(cell, this);
  657. if (Class->Bib_And_Offset(bib, cell)) {
  658. SmudgeClass * smudge = new SmudgeClass(bib);
  659. if (smudge != NULL) {
  660. smudge->Disown(cell);
  661. delete smudge;
  662. }
  663. }
  664. break;
  665. case MARK_DOWN:
  666. /*
  667. ** Special wall logic is handled here. A building that is really a wall
  668. ** gets converted into an overlay wall type when it is placed down. The
  669. ** actual building object itself is destroyed.
  670. */
  671. if (Class->IsWall) {
  672. switch (Class->Type) {
  673. case STRUCT_BRICK_WALL:
  674. new OverlayClass(OVERLAY_BRICK_WALL, cell, House->Class->House);
  675. break;
  676. case STRUCT_BARBWIRE_WALL:
  677. new OverlayClass(OVERLAY_BARBWIRE_WALL, cell, House->Class->House);
  678. break;
  679. case STRUCT_SANDBAG_WALL:
  680. new OverlayClass(OVERLAY_SANDBAG_WALL, cell, House->Class->House);
  681. break;
  682. case STRUCT_WOOD_WALL:
  683. new OverlayClass(OVERLAY_WOOD_WALL, cell, House->Class->House);
  684. break;
  685. case STRUCT_CYCLONE_WALL:
  686. new OverlayClass(OVERLAY_CYCLONE_WALL, cell, House->Class->House);
  687. break;
  688. case STRUCT_FENCE:
  689. new OverlayClass(OVERLAY_FENCE, cell, House->Class->House);
  690. break;
  691. default:
  692. break;
  693. }
  694. Transmit_Message(RADIO_OVER_OUT);
  695. delete this;
  696. } else {
  697. if (Can_Enter_Cell(cell) == MOVE_OK) {
  698. /*
  699. ** Determine if a bib is required for this building. If one is, then
  700. ** create and place it.
  701. */
  702. CELL newcell = cell;
  703. if (Class->Bib_And_Offset(bib, newcell)) {
  704. new SmudgeClass(bib, Cell_Coord(newcell), Class->IsBase ? House->Class->House : HOUSE_NONE);
  705. }
  706. Map.Place_Down(cell, this);
  707. } else {
  708. return(false);
  709. }
  710. }
  711. break;
  712. case MARK_CHANGE_REDRAW:
  713. Map.Refresh_Cells(cell, Overlap_List(true));
  714. break;
  715. default:
  716. Map.Refresh_Cells(cell, Overlap_List(false));
  717. Map.Refresh_Cells(cell, occupy);
  718. break;
  719. }
  720. return(true);
  721. }
  722. return(false);
  723. }
  724. /***********************************************************************************************
  725. * BuildingClass::AI -- Handles non-graphic AI processing for buildings. *
  726. * *
  727. * This function is to handle the AI logic for the building. The graphic logic (facing, *
  728. * firing, and animation) is handled elsewhere. *
  729. * *
  730. * INPUT: none *
  731. * *
  732. * OUTPUT: none *
  733. * *
  734. * WARNINGS: none *
  735. * *
  736. * HISTORY: *
  737. * 05/31/1994 JLB : Created. *
  738. * 12/26/1994 JLB : Handles production. *
  739. * 06/11/1995 JLB : Revamped. *
  740. *=============================================================================================*/
  741. void BuildingClass::AI(void)
  742. {
  743. assert(Buildings.ID(this) == ID);
  744. assert(IsActive);
  745. /*
  746. ** Process building animation state changes. Transition to a following state
  747. ** if there is one specified and the current animation sequence has expired.
  748. ** This process must occur before mission AI since the mission AI relies on
  749. ** the bstate change to occur immediately before the MissionClass::AI.
  750. */
  751. Animation_AI();
  752. /*
  753. ** If now is a good time to act on a new mission, then do so. This process occurs
  754. ** here because some outside event may have requested a mission change for the building.
  755. ** Such outside requests (player input) must be initiated BEFORE the normal AI process.
  756. */
  757. if (IsReadyToCommence && BState != BSTATE_CONSTRUCTION) {
  758. /*
  759. ** Clear the commencement flag ONLY if something actually occurred. By acting
  760. ** this way, a building can set the IsReadyToCommence flag before it goes
  761. ** to "sleep" knowing that it will wake up as soon as a new mission comes
  762. ** along.
  763. */
  764. if (Commence()) {
  765. IsReadyToCommence = false;
  766. }
  767. }
  768. /*
  769. ** Proceed with normal logic processing. This is where the mission processing
  770. ** occurs. This call must be located after the animation sequence makes the
  771. ** transition to the next frame (see above) in order for the mission logic to
  772. ** act at the exact moment of graphic transition BEFORE it has a chance to
  773. ** be displayed.
  774. */
  775. TechnoClass::AI();
  776. /*
  777. ** Bail if the object died in the AI routine.
  778. */
  779. if (!IsActive) {
  780. return;
  781. }
  782. /*
  783. ** Building ammo is instantly reloaded.
  784. */
  785. if (!Ammo) {
  786. Ammo = Class->MaxAmmo;
  787. }
  788. /*
  789. ** If now is a good time to act on a new mission, then do so. This occurs here because
  790. ** some AI event may have requested a mission change (usually from another mission
  791. ** state machine). This must occur here before it has a chance to render.
  792. */
  793. if (IsReadyToCommence) {
  794. /*
  795. ** Clear the commencement flag ONLY if something actually occurred. By acting
  796. ** this way, a building can set the IsReadyToCommence flag before it goes
  797. ** to "sleep" knowing that it will wake up as soon as a new mission comes
  798. ** along.
  799. */
  800. if (Commence()) {
  801. IsReadyToCommence = false;
  802. }
  803. }
  804. /*
  805. ** If a change of animation was requested, then make the change
  806. ** now. The building animation system acts independently but subordinate
  807. ** to the mission state machine system. By performing the animation change-up
  808. ** here, the mission AI system is ensured of immediate visual affect when it
  809. ** decides to change the animation state of the building.
  810. */
  811. if (QueueBState != BSTATE_NONE) {
  812. if (BState != QueueBState) {
  813. BState = QueueBState;
  814. BuildingTypeClass::AnimControlType const * ctrl = Fetch_Anim_Control();
  815. if (BState == BSTATE_CONSTRUCTION || BState == BSTATE_IDLE) {
  816. Set_Rate(Options.Normalize_Delay(ctrl->Rate));
  817. } else {
  818. Set_Rate(ctrl->Rate);
  819. }
  820. Set_Stage(ctrl->Start);
  821. }
  822. QueueBState = BSTATE_NONE;
  823. }
  824. /*
  825. ** If the building's strength has changed, then update the power
  826. ** accordingly.
  827. */
  828. if (Strength != LastStrength) {
  829. int oldpower = Power_Output();
  830. LastStrength = Strength;
  831. int newpower = Power_Output();
  832. House->Adjust_Power(newpower - oldpower);
  833. }
  834. /*
  835. ** Check to see if the destruction countdown timer is active. If so, then decrement it.
  836. ** When this timer reaches zero, the building is removed from the map. All the explosions
  837. ** are presumed to be in progress at this time.
  838. */
  839. if (Strength == 0) {
  840. if (CountDown == 0) {
  841. Limbo();
  842. Drop_Debris(WhomToRepay);
  843. delete this;
  844. }
  845. return;
  846. }
  847. /*
  848. ** Charging logic.
  849. */
  850. Charging_AI();
  851. /*
  852. ** Handle any repair process that may be going on.
  853. */
  854. Repair_AI();
  855. /*
  856. ** For computer controlled buildings, determine what should be produced and start
  857. ** production accordingly.
  858. */
  859. Factory_AI();
  860. /*
  861. ** Check for demolition timeout. When timeout has expired, the building explodes.
  862. */
  863. if (IsGoingToBlow && CountDown == 0) {
  864. /*
  865. ** Maybe trigger an achivement. ST - 11/14/2019 1:53PM
  866. */
  867. TechnoTypeClass const *object_type = Techno_Type_Class();
  868. if (object_type) {
  869. TechnoClass *saboteur = As_Techno(WhomToRepay);
  870. if (saboteur && saboteur->IsActive && saboteur->House && saboteur->House->IsHuman) {
  871. On_Achievement_Event(saboteur->House, "BUILDING_DESTROYED_C4", object_type->IniName);
  872. }
  873. }
  874. int damage = Strength;
  875. Take_Damage(damage, 0, WARHEAD_FIRE, As_Techno(WhomToRepay), true);
  876. if (!IsActive) {
  877. return;
  878. }
  879. Mark(MARK_CHANGE);
  880. }
  881. /*
  882. ** Turret equiped buildings must handle turret rotation logic here. This entails
  883. ** rotating the turret to the desired facing as well as figuring out what that
  884. ** desired facing should be.
  885. */
  886. Rotation_AI();
  887. /*
  888. ** Gap Generators need to scan if they've just become activated, or if
  889. ** the power has just come on enough so they can scan. Also, they need
  890. ** to un-jam if the power has just dropped off.
  891. */
  892. if (*this == STRUCT_GAP) {
  893. if (Arm == 0) {
  894. IsJamming = false;
  895. Arm = TICKS_PER_MINUTE * Rule.GapRegenInterval + Random_Pick(1, TICKS_PER_SECOND);
  896. }
  897. if (!IsJamming) {
  898. if (House->Power_Fraction() >= 1) {
  899. Map.Jam_From(Coord_Cell(Center_Coord()), Rule.GapShroudRadius, House);
  900. IsJamming = true;
  901. }
  902. } else {
  903. if (House->Power_Fraction() < 1) {
  904. IsJamming = false;
  905. Map.UnJam_From(Coord_Cell(Center_Coord()), Rule.GapShroudRadius, House);
  906. }
  907. }
  908. }
  909. /*
  910. ** Radar facilities and SAMs need to check for the proximity of a mobile
  911. ** radar jammer.
  912. */
  913. if ((*this == STRUCT_RADAR || *this == STRUCT_SAM) && (Frame % TICKS_PER_SECOND) == 0) {
  914. IsJammed = false;
  915. for (int index = 0; index < Units.Count(); index++) {
  916. UnitClass * obj = Units.Ptr(index);
  917. if (obj != NULL &&
  918. !obj->IsInLimbo &&
  919. !obj->House->Is_Ally(House) &&
  920. obj->Class->IsJammer &&
  921. Distance(obj) <= Rule.RadarJamRadius) {
  922. IsJammed = true;
  923. break;
  924. }
  925. }
  926. }
  927. /*
  928. ** Chronosphere active animation control.
  929. */
  930. if (*this == STRUCT_CHRONOSPHERE && BState == BSTATE_ACTIVE && QueueBState == BSTATE_NONE && Scen.FadeTimer == 0) {
  931. Begin_Mode(BSTATE_IDLE);
  932. }
  933. }
  934. /***********************************************************************************************
  935. * BuildingClass::Unlimbo -- Removes a building from limbo state. *
  936. * *
  937. * Use this routine to transform a building that has been held in limbo *
  938. * state, into one that really exists on the map. Once a building as *
  939. * been unlimboed, then it becomes a normal object in the game world. *
  940. * *
  941. * INPUT: pos -- The position to place the building on the map. *
  942. * *
  943. * dir (optional) -- not used for this class *
  944. * *
  945. * OUTPUT: bool; Was the unlimbo successful? *
  946. * *
  947. * WARNINGS: The unlimbo operation might not be successful if the *
  948. * building could not be placed at the location specified. *
  949. * *
  950. * HISTORY: *
  951. * 04/16/1994 JLB : Created. *
  952. * 06/07/1994 JLB : Matches virtual function format for base class. *
  953. * 05/09/1995 JLB : Handles wall placement. *
  954. * 06/18/1995 JLB : Checks for wall legality before placing down. *
  955. *=============================================================================================*/
  956. bool BuildingClass::Unlimbo(COORDINATE coord, DirType dir)
  957. {
  958. assert(Buildings.ID(this) == ID);
  959. assert(IsActive);
  960. /*
  961. ** If this is a wall type building, then it never gets unlimboed. Instead, it gets
  962. ** converted to an overlay type.
  963. */
  964. if (Class->IsWall) {
  965. if (Can_Enter_Cell(Coord_Cell(coord), FACING_NONE) == MOVE_OK) {
  966. OverlayType otype = OVERLAY_NONE;
  967. switch (Class->Type) {
  968. case STRUCT_SANDBAG_WALL:
  969. otype = OVERLAY_SANDBAG_WALL;
  970. break;
  971. case STRUCT_CYCLONE_WALL:
  972. otype = OVERLAY_CYCLONE_WALL;
  973. break;
  974. case STRUCT_BRICK_WALL:
  975. otype = OVERLAY_BRICK_WALL;
  976. break;
  977. case STRUCT_BARBWIRE_WALL:
  978. otype = OVERLAY_BARBWIRE_WALL;
  979. break;
  980. case STRUCT_WOOD_WALL:
  981. otype = OVERLAY_WOOD_WALL;
  982. break;
  983. case STRUCT_FENCE:
  984. otype = OVERLAY_FENCE;
  985. break;
  986. default:
  987. otype = OVERLAY_NONE;
  988. break;
  989. }
  990. if (otype != OVERLAY_NONE) {
  991. ObjectClass * o = OverlayTypeClass::As_Reference(otype).Create_One_Of(House);
  992. if (o && o->Unlimbo(coord)) {
  993. Map[coord].Owner = House->Class->House;
  994. Transmit_Message(RADIO_OVER_OUT);
  995. Map.Sight_From(Coord_Cell(coord), Class->SightRange, House);
  996. delete this;
  997. return(true);
  998. }
  999. }
  1000. }
  1001. return(false);
  1002. }
  1003. /*
  1004. ** Normal building unlimbo process.
  1005. */
  1006. if (TechnoClass::Unlimbo(coord, dir)) {
  1007. /*
  1008. ** Ensure that the owning house knows about the
  1009. ** new object.
  1010. */
  1011. House->BScan |= (1L << Class->Type);
  1012. House->ActiveBScan |= (1L << Class->Type);
  1013. /*
  1014. ** Recalculate the center point of the house's base.
  1015. */
  1016. House->Recalc_Center();
  1017. /*
  1018. ** Update the total factory type, assuming this building has a factory.
  1019. */
  1020. House->Active_Add(this);
  1021. /*
  1022. ** Possibly the sidebar will be affected by this addition.
  1023. */
  1024. House->IsRecalcNeeded = true;
  1025. LastStrength = 0;
  1026. // Changes to support client/server multiplayer. ST - 8/2/2019 2:36PM
  1027. //if ((!IsDiscoveredByPlayer && Map[coord].IsVisible) || Session.Type != GAME_NORMAL) {
  1028. if ((!Is_Discovered_By_Player(House) && Map[coord].Is_Visible(House)) || Session.Type != GAME_NORMAL) {
  1029. if (House->IsHuman) {
  1030. //Revealed(PlayerPtr);
  1031. Revealed(House);
  1032. }
  1033. }
  1034. if (!House->IsHuman) {
  1035. Revealed(House);
  1036. }
  1037. // Changes to support client/server multiplayer. ST - 8/2/2019 2:36PM
  1038. //if (IsOwnedByPlayer) {
  1039. if (Is_Owned_By_Player()) {
  1040. Map.PowerClass::IsToRedraw = true;
  1041. Map.Flag_To_Redraw(false);
  1042. }
  1043. if ((Class->Ownable & (HOUSEF_GOOD | HOUSEF_BAD)) != (HOUSEF_GOOD | HOUSEF_BAD)) {
  1044. if (Class->Ownable & HOUSEF_GOOD) {
  1045. ActLike = HOUSE_GREECE;
  1046. } else {
  1047. ActLike = HOUSE_USSR;
  1048. }
  1049. }
  1050. return(true);
  1051. }
  1052. return(false);
  1053. }
  1054. /***********************************************************************************************
  1055. * BuildingClass::Take_Damage -- Inflicts damage points upon a building. *
  1056. * *
  1057. * This routine will inflict damage points upon the specified building. *
  1058. * It will handle the damage animation and building destruction. Use *
  1059. * this routine whenever a building is attacked. *
  1060. * *
  1061. * INPUT: damage -- Amount of damage to inflict. *
  1062. * *
  1063. * distance -- The distance from the damage center point to the object's center point.*
  1064. * *
  1065. * warhead -- The kind of damage to inflict. *
  1066. * *
  1067. * source -- The source of the damage. This is used to change targeting. *
  1068. * *
  1069. * forced -- Is the damage forced upon the object regardless of whether it *
  1070. * is normally immune? *
  1071. * *
  1072. * OUTPUT: true/false; Was the building destroyed? *
  1073. * *
  1074. * WARNINGS: none *
  1075. * *
  1076. * HISTORY: *
  1077. * 07/21/1991 : Created. *
  1078. * 04/15/1994 JLB : Converted to member function. *
  1079. * 04/16/1994 JLB : Added warhead modifier to damage. *
  1080. * 06/03/1994 JLB : Added source of damage as target value. *
  1081. * 06/20/1994 JLB : Source is a base class pointer. *
  1082. * 11/22/1994 JLB : Shares base damage handler for techno objects. *
  1083. * 07/15/1995 JLB : Power ratio gets adjusted. *
  1084. *=============================================================================================*/
  1085. ResultType BuildingClass::Take_Damage(int & damage, int distance, WarheadType warhead, TechnoClass * source, bool forced)
  1086. {
  1087. assert(Buildings.ID(this) == ID);
  1088. assert(IsActive);
  1089. ResultType res = RESULT_NONE;
  1090. int shakes;
  1091. if (this != source /*&& !Class->IsInsignificant*/) {
  1092. if (source) {
  1093. House->LATime = Frame;
  1094. House->LAType = source->What_Am_I();
  1095. House->LAZone = House->Which_Zone(this);
  1096. House->LAEnemy = source->Owner();
  1097. if (!House->Is_Ally(source)) {
  1098. House->Enemy = source->Owner();
  1099. }
  1100. Base_Is_Attacked(source);
  1101. }
  1102. short const * offset = Occupy_List();
  1103. /*
  1104. ** Memorize who they used to be in radio contact with.
  1105. */
  1106. TechnoClass *tech = Contact_With_Whom();
  1107. /*
  1108. ** Perform the low level damage assessment.
  1109. */
  1110. res = TechnoClass::Take_Damage(damage, distance, warhead, source, forced);
  1111. switch (res) {
  1112. case RESULT_DESTROYED:
  1113. /*
  1114. ** Add the building to the base prebuild list if allowed. This will force
  1115. ** the computer to rebuild this structure if it can.
  1116. */
  1117. if (IsToRebuild && Class->Level != -1 && Base.House == House->Class->House && Base.Get_Node(this) == 0) {
  1118. // if (IsToRebuild && Class->IsBuildable && Base.House == House->Class->House && Base.Get_Node(this) == 0) {
  1119. Base.Nodes.Add(BaseNodeClass(Class->Type, Coord_Cell(Coord)));
  1120. }
  1121. /*
  1122. ** Destroy all attached objects.
  1123. */
  1124. while (Attached_Object()) {
  1125. FootClass * obj = Detach_Object();
  1126. Detach_All(true);
  1127. delete obj;
  1128. }
  1129. /*
  1130. ** If we were in contact with a landed plane, blow the plane up too.
  1131. */
  1132. if (tech && tech->IsActive && tech->What_Am_I() == RTTI_AIRCRAFT && ((AircraftClass *)tech)->Class->IsFixedWing && ((AircraftClass *)tech)->In_Which_Layer() == LAYER_GROUND) {
  1133. int damage = 500;
  1134. tech->Take_Damage(damage, 0, WARHEAD_AP, source, forced);
  1135. }
  1136. Sound_Effect(VOC_KABOOM22, Coord);
  1137. while (*offset != REFRESH_EOL) {
  1138. CELL cell = Coord_Cell(Coord) + *offset++;
  1139. /*
  1140. ** If the building is destroyed, then lots of
  1141. ** explosions occur.
  1142. */
  1143. new SmudgeClass(Random_Pick(SMUDGE_CRATER1, SMUDGE_CRATER6), Cell_Coord(cell));
  1144. if (Percent_Chance(50)) {
  1145. new AnimClass(ANIM_FIRE_SMALL, Coord_Scatter(Cell_Coord(cell), 0x0080), Random_Pick(0, 7), Random_Pick(1, 3));
  1146. if (Percent_Chance(50)) {
  1147. new AnimClass(ANIM_FIRE_MED, Coord_Scatter(Cell_Coord(cell), 0x0040), Random_Pick(0, 7), Random_Pick(1, 3));
  1148. }
  1149. }
  1150. new AnimClass(ANIM_FBALL1, Coord_Scatter(Cell_Coord(cell), 0x0040), Random_Pick(0, 3));
  1151. }
  1152. shakes = Class->Cost_Of() / 400;
  1153. if (shakes) {
  1154. Shake_The_Screen(shakes, Owner());
  1155. if (source && Owner() != source->Owner()) {
  1156. Shake_The_Screen(shakes, source->Owner());
  1157. }
  1158. }
  1159. Sound_Effect(VOC_CRUMBLE, Coord);
  1160. if (Mission == MISSION_DECONSTRUCTION) {
  1161. CountDown = 0;
  1162. Set_Rate(0);
  1163. } else {
  1164. CountDown = 8;
  1165. }
  1166. /*
  1167. ** If it is in radio contact and the object seems to be attached, then tell
  1168. ** it to run away.
  1169. */
  1170. if (In_Radio_Contact() && Transmit_Message(RADIO_NEED_TO_MOVE) == RADIO_ROGER) {
  1171. Transmit_Message(RADIO_RUN_AWAY);
  1172. }
  1173. /*
  1174. ** A force destruction will not generate survivors.
  1175. */
  1176. if (forced || *this == STRUCT_KENNEL) {
  1177. IsSurvivorless = true;
  1178. }
  1179. /*
  1180. ** Destruction of a radar facility or advanced communications
  1181. ** center will cause the spiedby field to change...
  1182. */
  1183. if (SpiedBy) {
  1184. SpiedBy = 0;
  1185. StructType struc = *this;
  1186. if (struc == STRUCT_RADAR /* || struc == STRUCT_EYE */) {
  1187. Update_Radar_Spied();
  1188. }
  1189. }
  1190. /*
  1191. ** Destruction of a gap generator will cause the cells it affects
  1192. ** to stop being jammed.
  1193. */
  1194. if (*this == STRUCT_GAP) {
  1195. Remove_Gap_Effect();
  1196. }
  1197. /*
  1198. ** Destruction of a shipyard or sub pen may cause attached ships
  1199. ** who are repairing themselves to discontinue repairs.
  1200. */
  1201. if (*this == STRUCT_SHIP_YARD || *this == STRUCT_SUB_PEN) {
  1202. for (int index = 0; index < Vessels.Count(); index++) {
  1203. VesselClass *obj = Vessels.Ptr(index);
  1204. if (obj && !obj->IsInLimbo && obj->House == House) {
  1205. if (obj->IsSelfRepairing) {
  1206. if (::Distance(Center_Coord(), obj->Center_Coord()) < 0x0200) {
  1207. obj->IsSelfRepairing = false;
  1208. obj->IsToSelfRepair = false;
  1209. }
  1210. }
  1211. }
  1212. }
  1213. }
  1214. /*
  1215. ** Destruction of a barrel will cause the surrounding squares to
  1216. ** be hit with damage.
  1217. */
  1218. if (*this == STRUCT_BARREL || *this == STRUCT_BARREL3) {
  1219. COORDINATE center = Center_Coord();
  1220. CELL cellcenter = Coord_Cell(center);
  1221. BulletClass * bullet;
  1222. bullet = new BulletClass(BULLET_INVISIBLE, ::As_Target(Adjacent_Cell(cellcenter, FACING_N)), 0, 200, WARHEAD_FIRE, MPH_MEDIUM_FAST);
  1223. if (bullet) {
  1224. bullet->Unlimbo(center, DIR_N);
  1225. }
  1226. bullet = new BulletClass(BULLET_INVISIBLE, ::As_Target(Adjacent_Cell(cellcenter, FACING_E)), 0, 200, WARHEAD_FIRE, MPH_MEDIUM_FAST);
  1227. if (bullet) {
  1228. bullet->Unlimbo(center, DIR_E);
  1229. }
  1230. bullet = new BulletClass(BULLET_INVISIBLE, ::As_Target(Adjacent_Cell(cellcenter, FACING_S)), 0, 200, WARHEAD_FIRE, MPH_MEDIUM_FAST);
  1231. if (bullet) {
  1232. bullet->Unlimbo(center, DIR_S);
  1233. }
  1234. bullet = new BulletClass(BULLET_INVISIBLE, ::As_Target(Adjacent_Cell(cellcenter, FACING_W)), 0, 200, WARHEAD_FIRE, MPH_MEDIUM_FAST);
  1235. if (bullet) {
  1236. bullet->Unlimbo(center, DIR_W);
  1237. }
  1238. }
  1239. if (House) {
  1240. House->Check_Pertinent_Structures();
  1241. }
  1242. break;
  1243. case RESULT_HALF:
  1244. if (*this == STRUCT_PUMP) {
  1245. AnimClass * anim = new AnimClass(ANIM_OILFIELD_BURN, Coord_Add(Coord, 0x00400130L), 1);
  1246. if (anim) {
  1247. anim->Attach_To(this);
  1248. }
  1249. }
  1250. // Fall into next case.
  1251. case RESULT_MAJOR:
  1252. Sound_Effect(VOC_KABOOM1, Coord);
  1253. while (*offset != REFRESH_EOL) {
  1254. CELL cell = Coord_Cell(Coord) + *offset++;
  1255. AnimClass * anim = NULL;
  1256. /*
  1257. ** Show pieces of fire to indicate that a significant change in
  1258. ** damage level has occurred.
  1259. */
  1260. if (warhead == WARHEAD_FIRE) {
  1261. switch (Random_Pick(0, 5+Class->Width()+Class->Height())) {
  1262. case 0:
  1263. break;
  1264. case 1:
  1265. case 2:
  1266. case 3:
  1267. case 4:
  1268. case 5:
  1269. anim = new AnimClass(ANIM_ON_FIRE_SMALL, Coord_Scatter(Cell_Coord(cell), 0x0060), 0, Random_Pick(1, 3));
  1270. break;
  1271. case 6:
  1272. case 7:
  1273. case 8:
  1274. anim = new AnimClass(ANIM_ON_FIRE_MED, Coord_Scatter(Cell_Coord(cell), 0x0060), 0, Random_Pick(1, 3));
  1275. break;
  1276. case 9:
  1277. anim = new AnimClass(ANIM_ON_FIRE_BIG, Coord_Scatter(Cell_Coord(cell), 0x0060), 0, 1);
  1278. break;
  1279. default:
  1280. break;
  1281. }
  1282. } else {
  1283. if (Percent_Chance(50)) {
  1284. /*
  1285. ** Building may catch on fire, but only if it wasn't a
  1286. ** renovator that caused the damage.
  1287. */
  1288. if (source == NULL || source->What_Am_I() != RTTI_INFANTRY || *(InfantryClass *)source != INFANTRY_RENOVATOR) {
  1289. anim = new AnimClass(ANIM_FIRE_SMALL, Coord_Scatter(Cell_Coord(cell), 0x0060), Random_Pick(0, 7), Random_Pick(1, 3));
  1290. }
  1291. }
  1292. }
  1293. /*
  1294. ** If the animation was created, then attach it to the building.
  1295. */
  1296. if (anim) {
  1297. anim->Attach_To(this);
  1298. }
  1299. }
  1300. break;
  1301. case RESULT_NONE:
  1302. break;
  1303. case RESULT_LIGHT:
  1304. break;
  1305. }
  1306. if (source && res != RESULT_NONE) {
  1307. /*
  1308. ** If any damage occurred, then inform the house of this fact. If it is the player's
  1309. ** house, it might announce this fact.
  1310. */
  1311. if (!Class->IsInsignificant) {
  1312. House->Attacked(this);
  1313. }
  1314. /*
  1315. ** Save the type of the house that's doing the damage, so if the building burns
  1316. ** to death credit can still be given for the kill
  1317. */
  1318. WhoLastHurtMe = source->Owner();
  1319. /*
  1320. ** When certain buildings are hit, they "snap out of it" and
  1321. ** return fire if they are able and allowed.
  1322. */
  1323. if (*this != STRUCT_SAM && *this != STRUCT_AAGUN &&
  1324. !House->Is_Ally(source) &&
  1325. Class->PrimaryWeapon != NULL &&
  1326. (!Target_Legal(TarCom) || !In_Range(TarCom))) {
  1327. if (source->What_Am_I() != RTTI_AIRCRAFT && (!House->IsHuman || Rule.IsSmartDefense)) {
  1328. Assign_Target(source->As_Target());
  1329. } else {
  1330. /*
  1331. ** Generate a random rotation effect since there is nothing else that this
  1332. ** building can do.
  1333. */
  1334. if (!PrimaryFacing.Is_Rotating()) {
  1335. PrimaryFacing.Set_Desired(Random_Pick(DIR_N, DIR_MAX));
  1336. }
  1337. }
  1338. }
  1339. }
  1340. }
  1341. return(res);
  1342. }
  1343. /***********************************************************************************************
  1344. * BuildingClass::new -- Allocates a building object from building pool. *
  1345. * *
  1346. * This routine will allocate a building slot from the building alloc *
  1347. * system. *
  1348. * *
  1349. * INPUT: none *
  1350. * *
  1351. * OUTPUT: Returns with a pointer to the allocated building. If NULL is *
  1352. * returned, then this indicates a failure to allocate. *
  1353. * *
  1354. * WARNINGS: none *
  1355. * *
  1356. * HISTORY: *
  1357. * 04/11/1994 JLB : Created. *
  1358. * 04/21/1994 JLB : Converted to operator new. *
  1359. * 05/17/1994 JLB : Revamped allocation scheme *
  1360. * 07/29/1994 JLB : Simplified. *
  1361. *=============================================================================================*/
  1362. void * BuildingClass::operator new(size_t )
  1363. {
  1364. void * ptr = Buildings.Allocate();
  1365. if (ptr) {
  1366. ((BuildingClass *)ptr)->Set_Active();
  1367. }
  1368. return(ptr);
  1369. }
  1370. /***********************************************************************************************
  1371. * BuildingClass::delete -- Deallocates building object. *
  1372. * *
  1373. * This is the memory deallocation operation for a building object. *
  1374. * Since buildings are allocated out of a fixed memory block, all that *
  1375. * is needed is to flag the unit as inactive. *
  1376. * *
  1377. * INPUT: ptr -- Pointer to building to deallocate. *
  1378. * *
  1379. * OUTPUT: none *
  1380. * *
  1381. * WARNINGS: none *
  1382. * *
  1383. * HISTORY: *
  1384. * 04/21/1994 JLB : Created. *
  1385. *=============================================================================================*/
  1386. void BuildingClass::operator delete(void *ptr)
  1387. {
  1388. if (ptr) {
  1389. ((BuildingClass *)ptr)->IsActive = false;
  1390. }
  1391. Buildings.Free((BuildingClass *)ptr);
  1392. }
  1393. /***********************************************************************************************
  1394. * BuildingClass::BuildingClass -- Constructor for buildings. *
  1395. * *
  1396. * This routine inserts a building into the object tracking system. *
  1397. * It is placed into a limbo state unless a location is provided for *
  1398. * it to unlimbo at. *
  1399. * *
  1400. * INPUT: type -- The structure type to make this object. *
  1401. * *
  1402. * house -- The owner of this building. *
  1403. * *
  1404. * pos -- The position to unlimbo the building. If -1 is *
  1405. * specified, then the building remains in a limbo *
  1406. * state. *
  1407. * *
  1408. * OUTPUT: none *
  1409. * *
  1410. * WARNINGS: none *
  1411. * *
  1412. * HISTORY: *
  1413. * 04/21/1994 JLB : Created. *
  1414. * 08/07/1995 JLB : Fixed act like value to match expected value. *
  1415. *=============================================================================================*/
  1416. BuildingClass::BuildingClass(StructType type, HousesType house) :
  1417. TechnoClass(RTTI_BUILDING, Buildings.ID(this), house),
  1418. Class(BuildingTypes.Ptr((int)type)),
  1419. Factory(0),
  1420. ActLike(House->ActLike),
  1421. IsToRebuild(false),
  1422. IsToRepair(false),
  1423. IsAllowedToSell(true),
  1424. IsReadyToCommence(false),
  1425. IsRepairing(false),
  1426. IsWrenchVisible(false),
  1427. IsGoingToBlow(false),
  1428. IsSurvivorless(false),
  1429. IsCharging(false),
  1430. IsCharged(false),
  1431. IsCaptured(false),
  1432. IsJamming(false),
  1433. IsJammed(false),
  1434. HasFired(false),
  1435. HasOpened(false),
  1436. CountDown(0),
  1437. BState(BSTATE_NONE),
  1438. QueueBState(BSTATE_NONE),
  1439. WhoLastHurtMe(house),
  1440. WhomToRepay(TARGET_NONE),
  1441. AnimToTrack(TARGET_NONE),
  1442. LastStrength(0),
  1443. PlacementDelay(0)
  1444. {
  1445. House->Tracking_Add(this);
  1446. IsSecondShot = !Class->Is_Two_Shooter();
  1447. Strength = Class->MaxStrength;
  1448. Ammo = Class->MaxAmmo;
  1449. /*
  1450. ** If the building could never be built, then it can never be sold either. This
  1451. ** is due to the lack of buildup animation.
  1452. */
  1453. if (Class->Get_Buildup_Data() != NULL) {
  1454. // if (!Class->IsBuildable) {
  1455. IsAllowedToSell = false;
  1456. }
  1457. // if (Session.Type == GAME_INTERNET) {
  1458. // House->BuildingTotals->Increment_Unit_Total( (int) type);
  1459. // }
  1460. }
  1461. /***********************************************************************************************
  1462. * BuildingClass::~BuildingClass -- Destructor for building type objects. *
  1463. * *
  1464. * This destructor for building objects will put the building in limbo if possible. *
  1465. * *
  1466. * INPUT: none *
  1467. * *
  1468. * OUTPUT: none *
  1469. * *
  1470. * WARNINGS: none *
  1471. * *
  1472. * HISTORY: *
  1473. * 01/18/1995 JLB : Created. *
  1474. *=============================================================================================*/
  1475. BuildingClass::~BuildingClass(void)
  1476. {
  1477. if (GameActive && Class) {
  1478. if (House) {
  1479. House->Tracking_Remove(this);
  1480. }
  1481. BuildingClass::Limbo();
  1482. }
  1483. Class = 0;
  1484. delete (FactoryClass *)Factory;
  1485. Factory = 0;
  1486. ID = -1;
  1487. }
  1488. /***********************************************************************************************
  1489. * BuildingClass::Drop_Debris -- Drops rubble when building is destroyed. *
  1490. * *
  1491. * This routine is called when a building is destroyed. It handles *
  1492. * placing the rubble down. *
  1493. * *
  1494. * INPUT: none *
  1495. * *
  1496. * OUTPUT: none *
  1497. * *
  1498. * WARNINGS: none *
  1499. * *
  1500. * HISTORY: *
  1501. * 05/14/1994 JLB : Created. *
  1502. * 06/13/1995 JLB : Added smoke and normal infantry survivor possibility. *
  1503. * 07/16/1995 JLB : Survival rate depends on if captured or sabotaged. *
  1504. *=============================================================================================*/
  1505. void BuildingClass::Drop_Debris(TARGET source)
  1506. {
  1507. assert(Buildings.ID(this) == ID);
  1508. assert(IsActive);
  1509. CELL const * offset;
  1510. CELL cell;
  1511. /*
  1512. ** Generate random survivors from the destroyed building.
  1513. */
  1514. cell = Coord_Cell(Coord);
  1515. offset = Occupy_List();
  1516. int odds = 2;
  1517. if (Target_Legal(WhomToRepay)) odds -= 1;
  1518. if (IsCaptured) odds += 6;
  1519. int count = How_Many_Survivors();
  1520. while (*offset != REFRESH_EOL) {
  1521. CELL newcell;
  1522. newcell = cell + *offset++;
  1523. CellClass const * cellptr = &Map[newcell];
  1524. /*
  1525. ** Infantry could run out of a destroyed building.
  1526. */
  1527. if (!House->IsToDie && count > 0) {
  1528. InfantryClass * i = NULL;
  1529. if (Random_Pick(0, odds) == 1) {
  1530. i = NULL;
  1531. InfantryType typ = Crew_Type();
  1532. if (typ != INFANTRY_NONE) i = new InfantryClass(typ, House->Class->House);
  1533. if (i != NULL) {
  1534. if (Class->Get_Buildup_Data() != NULL && i->Class->IsNominal) i->IsTechnician = true;
  1535. ScenarioInit++;
  1536. if (i->Unlimbo(Cell_Coord(newcell), DIR_N)) {
  1537. count--;
  1538. i->Strength = Random_Pick(5, (int)i->Class->MaxStrength);
  1539. i->Scatter(0, true);
  1540. if (source != TARGET_NONE && !House->Is_Ally(As_Object(source))) {
  1541. i->Assign_Mission(MISSION_ATTACK);
  1542. i->Assign_Target(source);
  1543. } else {
  1544. if (House->IsHuman) {
  1545. i->Assign_Mission(MISSION_GUARD);
  1546. } else {
  1547. i->Assign_Mission(MISSION_HUNT);
  1548. }
  1549. }
  1550. } else {
  1551. delete i;
  1552. }
  1553. ScenarioInit--;
  1554. }
  1555. }
  1556. }
  1557. /*
  1558. ** Smoke and fire only appear on terrestrail cells. They should not appear on
  1559. ** rivers, clifs, or water cells.
  1560. */
  1561. if (cellptr->Is_Clear_To_Move(SPEED_TRACK, true, true)) {
  1562. /*
  1563. ** Possibly add some smoke rising from the ashes of the building.
  1564. */
  1565. switch (Random_Pick(0, 5)) {
  1566. case 0:
  1567. case 1:
  1568. case 2:
  1569. new AnimClass(ANIM_SMOKE_M, Coord_Scatter(Cell_Coord(newcell), 0x0050, false), Random_Pick(0, 5), Random_Pick(1, 2));
  1570. break;
  1571. default:
  1572. break;
  1573. }
  1574. /*
  1575. ** The building always scars the ground in some fashion.
  1576. */
  1577. if (Percent_Chance(25)) {
  1578. new SmudgeClass(Random_Pick(SMUDGE_SCORCH1, SMUDGE_SCORCH6), Cell_Coord(newcell));
  1579. } else {
  1580. new SmudgeClass(Random_Pick(SMUDGE_CRATER1, SMUDGE_CRATER6), Coord_Scatter(Cell_Coord(newcell), 0x0080, false));
  1581. }
  1582. }
  1583. }
  1584. }
  1585. /***********************************************************************************************
  1586. * BuildingClass::Active_Click_With -- Handles clicking on the map while the building is selected.*
  1587. * *
  1588. * This interface routine handles when the player clicks on the map while this building *
  1589. * is currently selected. This is used to assign an override target to a turret or *
  1590. * guard tower. *
  1591. * *
  1592. * INPUT: target -- The target that was clicked upon. *
  1593. * *
  1594. * OUTPUT: none *
  1595. * *
  1596. * WARNINGS: none *
  1597. * *
  1598. * HISTORY: *
  1599. * 05/28/1994 JLB : Created. *
  1600. *=============================================================================================*/
  1601. void BuildingClass::Active_Click_With(ActionType action, ObjectClass * object)
  1602. {
  1603. assert(Buildings.ID(this) == ID);
  1604. assert(IsActive);
  1605. if (action == ACTION_ATTACK && object != NULL) {
  1606. Player_Assign_Mission(MISSION_ATTACK, object->As_Target());
  1607. }
  1608. if (action == ACTION_TOGGLE_PRIMARY && Class->Is_Factory()) {
  1609. OutList.Add(EventClass(EventClass::PRIMARY, TargetClass(this)));
  1610. }
  1611. }
  1612. /***********************************************************************************************
  1613. * BuildingClass::Active_Click_With -- Handles cell selection for buildings. *
  1614. * *
  1615. * This routine really only serves one purpose -- to allow targeting of the ground for *
  1616. * buildings that are equipped with weapons. *
  1617. * *
  1618. * INPUT: action -- The requested action to perform. *
  1619. * *
  1620. * cell -- The cell location to perform the action upon. *
  1621. * *
  1622. * OUTPUT: none *
  1623. * *
  1624. * WARNINGS: none *
  1625. * *
  1626. * HISTORY: *
  1627. * 07/04/1995 JLB : Created. *
  1628. * 10/04/1995 JLB : Handles construction yard undeploy to move logic. *
  1629. *=============================================================================================*/
  1630. void BuildingClass::Active_Click_With(ActionType action, CELL cell)
  1631. {
  1632. assert(Buildings.ID(this) == ID);
  1633. assert(IsActive);
  1634. if (action == ACTION_ATTACK) {
  1635. Player_Assign_Mission(MISSION_ATTACK, ::As_Target(cell));
  1636. }
  1637. if (action == ACTION_MOVE && *this == STRUCT_CONST) {
  1638. OutList.Add(EventClass(EventClass::ARCHIVE, TargetClass(this), TargetClass(::As_Target(cell))));
  1639. OutList.Add(EventClass(EventClass::SELL, TargetClass(this)));
  1640. COORDINATE coord = Map.Pixel_To_Coord(Get_Mouse_X(), Get_Mouse_Y());
  1641. OutList.Add(EventClass(ANIM_MOVE_FLASH, PlayerPtr->Class->House, coord, 1 << PlayerPtr->Class->House));
  1642. }
  1643. }
  1644. /***********************************************************************************************
  1645. * BuildingClass::Assign_Target -- Assigns a target to the building. *
  1646. * *
  1647. * Assigning of a target to a building makes sense if the building is one that can attack. *
  1648. * This routine would be used to assign the attack target to a turret or guard tower. *
  1649. * *
  1650. * INPUT: target -- The target that was clicked on while this building was selected. *
  1651. * *
  1652. * OUTPUT: none *
  1653. * *
  1654. * WARNINGS: none *
  1655. * *
  1656. * HISTORY: *
  1657. * 05/28/1994 JLB : Created. *
  1658. * 11/02/1994 JLB : Checks for range before assigning target. *
  1659. *=============================================================================================*/
  1660. void BuildingClass::Assign_Target(TARGET target)
  1661. {
  1662. assert(Buildings.ID(this) == ID);
  1663. assert(IsActive);
  1664. if (*this != STRUCT_SAM && *this != STRUCT_AAGUN && !In_Range(target, 0)) {
  1665. target = TARGET_NONE;
  1666. }
  1667. TechnoClass::Assign_Target(target);
  1668. }
  1669. /***********************************************************************************************
  1670. * BuildingClass::Init -- Initialize the building system to an empty null state. *
  1671. * *
  1672. * This routine initializes the building system in preparation for a scenario load. *
  1673. * *
  1674. * INPUT: none *
  1675. * *
  1676. * OUTPUT: none *
  1677. * *
  1678. * WARNINGS: none *
  1679. * *
  1680. * HISTORY: *
  1681. * 09/19/1994 JLB : Created. *
  1682. *=============================================================================================*/
  1683. void BuildingClass::Init(void)
  1684. {
  1685. Buildings.Free_All();
  1686. }
  1687. /***********************************************************************************************
  1688. * BuildingClass::Exit_Object -- Initiates an object to leave the building. *
  1689. * *
  1690. * This function is used to cause an object to exit the building. It is called when a *
  1691. * factory produces a vehicle or other mobile object and that object needs to exit the *
  1692. * building to join the ranks of a regular unit. Typically, the object is placed down on *
  1693. * the map such that it overlaps the building and then it is given a movement order so that *
  1694. * it will move to an adjacent free cell. *
  1695. * *
  1696. * INPUT: base -- Pointer to the object that is to exit the building. *
  1697. * *
  1698. * OUTPUT: Returns the success rating for the exit attempt; *
  1699. * 0 = complete failure (refund money please) *
  1700. * 1 = temporarily prevented (try again later please) *
  1701. * 2 = successful *
  1702. * *
  1703. * WARNINGS: The building is placed in radio contact with the object. The object is in a *
  1704. * tethered condition. This condition will be automatically broken when the *
  1705. * object reaches the adjacent square. *
  1706. * *
  1707. * HISTORY: *
  1708. * 11/28/1994 JLB : Created. *
  1709. * 04/10/1995 JLB : Handles building production by computer. *
  1710. * 06/17/1995 JLB : Handles refinery exit. *
  1711. *=============================================================================================*/
  1712. int BuildingClass::Exit_Object(TechnoClass * base)
  1713. {
  1714. assert(Buildings.ID(this) == ID);
  1715. assert(IsActive);
  1716. if (!base) return(0);
  1717. TechnoTypeClass const * ttype = (TechnoTypeClass const *)&base->Class_Of();
  1718. /*
  1719. ** A unit exiting a building is always considered to be "locked". That means, it
  1720. ** will be considered as to have legally entered the visible map domain.
  1721. */
  1722. base->IsLocked = true;
  1723. /*
  1724. ** Find a good cell to unload the object to. The object, probably a vehicle
  1725. ** will drive/walk to the adjacent free cell.
  1726. */
  1727. CELL cell = 0;
  1728. switch (base->What_Am_I()) {
  1729. case RTTI_AIRCRAFT:
  1730. if (!In_Radio_Contact()) {
  1731. AircraftClass * air = (AircraftClass *)base;
  1732. air->Height = 0;
  1733. ScenarioInit++;
  1734. if (air->Unlimbo(Docking_Coord(), air->Pose_Dir())) {
  1735. Transmit_Message(RADIO_HELLO, air);
  1736. Transmit_Message(RADIO_TETHER);
  1737. ScenarioInit--;
  1738. return(2);
  1739. }
  1740. ScenarioInit--;
  1741. } else {
  1742. AircraftClass * air = (AircraftClass *)base;
  1743. if (Cell_X(Coord_Cell(Center_Coord())) - Map.MapCellX < Map.MapCellWidth/2) {
  1744. cell = XY_Cell(Map.MapCellX-1, Random_Pick(0, Map.MapCellHeight-1)+Map.MapCellY);
  1745. } else {
  1746. cell = XY_Cell(Map.MapCellX+Map.MapCellWidth, Random_Pick(0, Map.MapCellHeight-1)+Map.MapCellY);
  1747. }
  1748. ScenarioInit++;
  1749. if (air->Unlimbo(Cell_Coord(cell), DIR_N)) {
  1750. //BG air->Assign_Destination(::As_Target(Nearby_Location(air)));
  1751. /*BG*/ air->Assign_Destination(::As_Target(air->Nearby_Location(this)));
  1752. air->Assign_Mission(MISSION_MOVE);
  1753. ScenarioInit--;
  1754. return(2);
  1755. }
  1756. ScenarioInit--;
  1757. }
  1758. break;
  1759. case RTTI_VESSEL:
  1760. switch (Class->Type) {
  1761. case STRUCT_SUB_PEN:
  1762. case STRUCT_SHIP_YARD:
  1763. ScenarioInit++;
  1764. cell = Find_Exit_Cell(base);
  1765. if (cell != 0 && base->Unlimbo(Cell_Coord(cell), Direction(Cell_Coord(cell)))) {
  1766. base->Assign_Mission(MISSION_GUARD);
  1767. ScenarioInit--;
  1768. return(2);
  1769. }
  1770. ScenarioInit--;
  1771. break;
  1772. default:
  1773. break;
  1774. }
  1775. break;
  1776. case RTTI_INFANTRY:
  1777. case RTTI_UNIT:
  1778. switch (Class->Type) {
  1779. case STRUCT_REFINERY:
  1780. if (base->What_Am_I() == RTTI_UNIT) {
  1781. cell = Coord_Cell(Center_Coord());
  1782. UnitClass * unit = (UnitClass *)base;
  1783. cell = Adjacent_Cell(cell, FACING_SW);
  1784. ScenarioInit++;
  1785. if (unit->Unlimbo(Cell_Coord(Adjacent_Cell(cell, DIR_S)), DIR_SW_X2)) {
  1786. unit->PrimaryFacing = DIR_S;
  1787. unit->Assign_Mission(MISSION_HARVEST);
  1788. }
  1789. ScenarioInit--;
  1790. } else {
  1791. base->Scatter(0, true);
  1792. }
  1793. break;
  1794. case STRUCT_WEAP:
  1795. if (Mission == MISSION_UNLOAD) {
  1796. for(int index = 0; index < Buildings.Count(); index++) {
  1797. BuildingClass *bldg = Buildings.Ptr(index);
  1798. if (bldg->Owner() == Owner() && *bldg == STRUCT_WEAP && bldg != this && bldg->Mission == MISSION_GUARD && !bldg->Factory) {
  1799. FactoryClass * temp = Factory;
  1800. bldg->Factory = Factory;
  1801. Factory = 0;
  1802. int retval = (bldg->Exit_Object(base));
  1803. bldg->Factory = 0;
  1804. Factory = temp;
  1805. return(retval);
  1806. }
  1807. }
  1808. return(1); // fail while we're still unloading previous
  1809. }
  1810. ScenarioInit++;
  1811. if (base->Unlimbo(Exit_Coord(), DIR_S)) {
  1812. base->Mark(MARK_UP);
  1813. base->Coord = Exit_Coord();
  1814. base->Mark(MARK_DOWN);
  1815. Transmit_Message(RADIO_HELLO, base);
  1816. Transmit_Message(RADIO_TETHER);
  1817. Assign_Mission(MISSION_UNLOAD);
  1818. ScenarioInit--;
  1819. return(2);
  1820. }
  1821. ScenarioInit--;
  1822. break;
  1823. case STRUCT_BARRACKS:
  1824. case STRUCT_TENT:
  1825. case STRUCT_KENNEL:
  1826. cell = Find_Exit_Cell(base);
  1827. if (cell != 0) {
  1828. DirType dir = Direction(cell);
  1829. COORDINATE start = Exit_Coord();
  1830. ScenarioInit++;
  1831. if (base->Unlimbo(start, dir)) {
  1832. base->Assign_Mission(MISSION_MOVE);
  1833. /*
  1834. ** When disembarking from a transport then guard an area around the
  1835. ** center of the base.
  1836. */
  1837. base->Assign_Destination(::As_Target(cell));
  1838. if (House->IQ >= Rule.IQGuardArea) {
  1839. base->Assign_Mission(MISSION_GUARD_AREA);
  1840. base->ArchiveTarget = ::As_Target(House->Where_To_Go((FootClass *)base));
  1841. }
  1842. /*
  1843. ** Establish radio contact so unload coordination can occur. This
  1844. ** radio contact should always succeed.
  1845. */
  1846. if (Transmit_Message(RADIO_HELLO, base) == RADIO_ROGER) {
  1847. Transmit_Message(RADIO_UNLOAD);
  1848. }
  1849. ScenarioInit--;
  1850. return(2);
  1851. }
  1852. ScenarioInit--;
  1853. }
  1854. break;
  1855. default:
  1856. cell = Find_Exit_Cell(base);
  1857. if (cell != 0) {
  1858. DirType dir = Direction(cell);
  1859. COORDINATE start = Exit_Coord();
  1860. ScenarioInit++;
  1861. if (base->Unlimbo(start, dir)) {
  1862. base->Assign_Mission(MISSION_MOVE);
  1863. /*
  1864. ** When disembarking from a transport then guard an area around the
  1865. ** center of the base.
  1866. */
  1867. base->Assign_Destination(::As_Target(cell));
  1868. if (House->IQ >= Rule.IQGuardArea) {
  1869. base->Assign_Mission(MISSION_GUARD_AREA);
  1870. base->ArchiveTarget = ::As_Target(House->Where_To_Go((FootClass *)base));
  1871. }
  1872. ScenarioInit--;
  1873. return(2);
  1874. }
  1875. ScenarioInit--;
  1876. }
  1877. break;
  1878. }
  1879. break;
  1880. case RTTI_BUILDING:
  1881. if (!House->IsHuman) {
  1882. /*
  1883. ** Find the next available spot to place this newly created building. If the
  1884. ** building could be placed at the desired location, fine. If not, then this
  1885. ** routine will return failure. The calling routine will probably abandon this
  1886. ** building in preference to building another.
  1887. */
  1888. BaseNodeClass * node = Base.Next_Buildable(((BuildingClass *)base)->Class->Type);
  1889. COORDINATE coord = 0;
  1890. if (node) {
  1891. coord = Cell_Coord(node->Cell);
  1892. } else {
  1893. /*
  1894. ** Find a suitable new spot to place.
  1895. */
  1896. coord = House->Find_Build_Location((BuildingClass *)base);
  1897. }
  1898. if (coord) {
  1899. if (Flush_For_Placement(base, Coord_Cell(coord))) {
  1900. return(1);
  1901. }
  1902. if (base->Unlimbo(coord)) {
  1903. if (node && ((BuildingClass *)base)->Class->Type == House->BuildStructure) {
  1904. House->BuildStructure = STRUCT_NONE;
  1905. }
  1906. return(2);
  1907. }
  1908. }
  1909. }
  1910. break;
  1911. default:
  1912. break;
  1913. }
  1914. /*
  1915. ** Failure to exit the object results in a false return value.
  1916. */
  1917. return(0);
  1918. }
  1919. /***********************************************************************************************
  1920. * BuildingClass::Update_Buildables -- Informs sidebar of additional construction options. *
  1921. * *
  1922. * This routine will tell the sidebar of objects that can be built. The function is called *
  1923. * whenever a building matures. *
  1924. * *
  1925. * INPUT: none *
  1926. * *
  1927. * OUTPUT: none *
  1928. * *
  1929. * WARNINGS: none *
  1930. * *
  1931. * HISTORY: *
  1932. * 11/11/1994 JLB : Created. *
  1933. * 12/23/1994 JLB : Only updates for PLAYER buildings. *
  1934. *=============================================================================================*/
  1935. void BuildingClass::Update_Buildables(void)
  1936. {
  1937. assert(Buildings.ID(this) == ID);
  1938. assert(IsActive);
  1939. /*
  1940. ** Only do this for real human players. ST - 3/22/2019 1:38PM
  1941. */
  1942. if (PlayerPtr != House) {
  1943. if (Session.Type != GAME_GLYPHX_MULTIPLAYER || House->IsHuman == false) {
  1944. return;
  1945. }
  1946. }
  1947. bool buildable_via_capture = (IsCaptured && ActLike != House->ActLike) ? true : false;
  1948. if (!IsInLimbo && Is_Discovered_By_Player()) {
  1949. switch (Class->ToBuild) {
  1950. int i;
  1951. int u;
  1952. int f;
  1953. int a;
  1954. int v;
  1955. case RTTI_VESSELTYPE:
  1956. for (v = VESSEL_FIRST; v < VESSEL_COUNT; v++) {
  1957. if (PlayerPtr->Can_Build(&VesselTypeClass::As_Reference((VesselType)v), ActLike)) {
  1958. if (Session.Type == GAME_GLYPHX_MULTIPLAYER) {
  1959. Sidebar_Glyphx_Add(RTTI_VESSELTYPE, v, House, buildable_via_capture);
  1960. } else {
  1961. Map.Add(RTTI_VESSELTYPE, v, buildable_via_capture);
  1962. }
  1963. }
  1964. }
  1965. break;
  1966. case RTTI_BUILDINGTYPE:
  1967. for (i = STRUCT_FIRST; i < STRUCT_COUNT; i++) {
  1968. if (PlayerPtr->Can_Build(&BuildingTypeClass::As_Reference((StructType)i), ActLike)) {
  1969. if (Session.Type == GAME_GLYPHX_MULTIPLAYER) {
  1970. Sidebar_Glyphx_Add(RTTI_BUILDINGTYPE, i, House, buildable_via_capture);
  1971. } else {
  1972. Map.Add(RTTI_BUILDINGTYPE, i, buildable_via_capture);
  1973. }
  1974. }
  1975. }
  1976. break;
  1977. case RTTI_UNITTYPE:
  1978. for (u = UNIT_FIRST; u < UNIT_COUNT; u++) {
  1979. if (PlayerPtr->Can_Build(&UnitTypeClass::As_Reference((UnitType)u), ActLike)) {
  1980. if (Session.Type == GAME_GLYPHX_MULTIPLAYER) {
  1981. Sidebar_Glyphx_Add(RTTI_UNITTYPE, u, House, buildable_via_capture);
  1982. } else {
  1983. Map.Add(RTTI_UNITTYPE, u, buildable_via_capture);
  1984. }
  1985. }
  1986. }
  1987. break;
  1988. case RTTI_INFANTRYTYPE:
  1989. for (f = INFANTRY_FIRST; f < INFANTRY_COUNT; f++) {
  1990. if (PlayerPtr->Can_Build(&InfantryTypeClass::As_Reference((InfantryType)f), ActLike)) {
  1991. if (InfantryTypeClass::As_Reference((InfantryType)f).IsDog) {
  1992. if (*this == STRUCT_KENNEL) {
  1993. if (Session.Type == GAME_GLYPHX_MULTIPLAYER) {
  1994. Sidebar_Glyphx_Add(RTTI_INFANTRYTYPE, f, House, buildable_via_capture);
  1995. } else {
  1996. Map.Add(RTTI_INFANTRYTYPE, f, buildable_via_capture);
  1997. }
  1998. }
  1999. } else {
  2000. if (*this != STRUCT_KENNEL) {
  2001. if (Session.Type == GAME_GLYPHX_MULTIPLAYER) {
  2002. Sidebar_Glyphx_Add(RTTI_INFANTRYTYPE, f, House, buildable_via_capture);
  2003. } else {
  2004. Map.Add(RTTI_INFANTRYTYPE, f, buildable_via_capture);
  2005. }
  2006. }
  2007. }
  2008. }
  2009. }
  2010. break;
  2011. case RTTI_AIRCRAFTTYPE:
  2012. for (a = AIRCRAFT_FIRST; a < AIRCRAFT_COUNT; a++) {
  2013. if (PlayerPtr->Can_Build(&AircraftTypeClass::As_Reference((AircraftType)a), ActLike)) {
  2014. if (Session.Type == GAME_GLYPHX_MULTIPLAYER) {
  2015. Sidebar_Glyphx_Add(RTTI_AIRCRAFTTYPE, a, House, buildable_via_capture);
  2016. } else {
  2017. Map.Add(RTTI_AIRCRAFTTYPE, a, buildable_via_capture);
  2018. }
  2019. }
  2020. }
  2021. break;
  2022. default:
  2023. break;
  2024. }
  2025. }
  2026. }
  2027. #if (0) //Old code for reference. ST - 8/2/2019 2:41PM
  2028. /***********************************************************************************************
  2029. * BuildingClass::Update_Buildables -- Informs sidebar of additional construction options. *
  2030. * *
  2031. * This routine will tell the sidebar of objects that can be built. The function is called *
  2032. * whenever a building matures. *
  2033. * *
  2034. * INPUT: none *
  2035. * *
  2036. * OUTPUT: none *
  2037. * *
  2038. * WARNINGS: none *
  2039. * *
  2040. * HISTORY: *
  2041. * 11/11/1994 JLB : Created. *
  2042. * 12/23/1994 JLB : Only updates for PLAYER buildings. *
  2043. *=============================================================================================*/
  2044. void BuildingClass::Update_Buildables(void)
  2045. {
  2046. assert(Buildings.ID(this) == ID);
  2047. assert(IsActive);
  2048. if (House == PlayerPtr && !IsInLimbo && IsDiscoveredByPlayer) {
  2049. switch (Class->ToBuild) {
  2050. int i;
  2051. int u;
  2052. int f;
  2053. int a;
  2054. int v;
  2055. case RTTI_VESSELTYPE:
  2056. for (v = VESSEL_FIRST; v < VESSEL_COUNT; v++) {
  2057. if (PlayerPtr->Can_Build(&VesselTypeClass::As_Reference((VesselType)v), ActLike)) {
  2058. Map.Add(RTTI_VESSELTYPE, v);
  2059. }
  2060. }
  2061. break;
  2062. case RTTI_BUILDINGTYPE:
  2063. for (i = STRUCT_FIRST; i < STRUCT_COUNT; i++) {
  2064. if (PlayerPtr->Can_Build(&BuildingTypeClass::As_Reference((StructType)i), ActLike)) {
  2065. Map.Add(RTTI_BUILDINGTYPE, i);
  2066. }
  2067. }
  2068. break;
  2069. case RTTI_UNITTYPE:
  2070. for (u = UNIT_FIRST; u < UNIT_COUNT; u++) {
  2071. if (PlayerPtr->Can_Build(&UnitTypeClass::As_Reference((UnitType)u), ActLike)) {
  2072. Map.Add(RTTI_UNITTYPE, u);
  2073. }
  2074. }
  2075. break;
  2076. case RTTI_INFANTRYTYPE:
  2077. for (f = INFANTRY_FIRST; f < INFANTRY_COUNT; f++) {
  2078. if (PlayerPtr->Can_Build(&InfantryTypeClass::As_Reference((InfantryType)f), ActLike)) {
  2079. if (InfantryTypeClass::As_Reference((InfantryType)f).IsDog) {
  2080. if (*this == STRUCT_KENNEL) {
  2081. Map.Add(RTTI_INFANTRYTYPE, f);
  2082. }
  2083. } else {
  2084. if (*this != STRUCT_KENNEL) {
  2085. Map.Add(RTTI_INFANTRYTYPE, f);
  2086. }
  2087. }
  2088. }
  2089. }
  2090. break;
  2091. case RTTI_AIRCRAFTTYPE:
  2092. for (a = AIRCRAFT_FIRST; a < AIRCRAFT_COUNT; a++) {
  2093. if (PlayerPtr->Can_Build(&AircraftTypeClass::As_Reference((AircraftType)a), ActLike)) {
  2094. Map.Add(RTTI_AIRCRAFTTYPE, a);
  2095. }
  2096. }
  2097. break;
  2098. default:
  2099. break;
  2100. }
  2101. }
  2102. }
  2103. #endif
  2104. /***********************************************************************************************
  2105. * BuildingClass::Fire_Out -- Handles when attached animation expires. *
  2106. * *
  2107. * This routine is used to perform any fixups necessary when the attached animation has *
  2108. * terminated. This occurs when the fire & smoke animation that a SAM site produces stops. *
  2109. * At that point, normal reload procedures can commence. *
  2110. * *
  2111. * INPUT: none *
  2112. * *
  2113. * OUTPUT: none *
  2114. * *
  2115. * WARNINGS: none *
  2116. * *
  2117. * HISTORY: *
  2118. * 11/30/1994 JLB : Created. *
  2119. *=============================================================================================*/
  2120. void BuildingClass::Fire_Out(void)
  2121. {
  2122. assert(Buildings.ID(this) == ID);
  2123. assert(IsActive);
  2124. }
  2125. /***********************************************************************************************
  2126. * BuildingClass::Limbo -- Handles power adjustment as building goes into limbo. *
  2127. * *
  2128. * This routine will handle the power adjustments for the associated house when the *
  2129. * building goes into limbo. This means that its power drain or production is subtracted *
  2130. * from the house accumulated totals. *
  2131. * *
  2132. * INPUT: none *
  2133. * *
  2134. * OUTPUT: bool; Was the building limboed? *
  2135. * *
  2136. * WARNINGS: none *
  2137. * *
  2138. * HISTORY: *
  2139. * 12/24/1994 JLB : Created. *
  2140. *=============================================================================================*/
  2141. bool BuildingClass::Limbo(void)
  2142. {
  2143. assert(Buildings.ID(this) == ID);
  2144. assert(IsActive);
  2145. if (!IsInLimbo) {
  2146. /*
  2147. ** Update the total factory type, assuming this building has a factory.
  2148. */
  2149. House->Active_Remove(this);
  2150. House->IsRecalcNeeded = true;
  2151. House->Recalc_Center();
  2152. /*
  2153. ** Update the power status of the owner's house.
  2154. */
  2155. House->Adjust_Power(-Power_Output());
  2156. House->Adjust_Drain(-Class->Drain);
  2157. House->Adjust_Capacity(-Class->Capacity, true);
  2158. if (House == PlayerPtr) {
  2159. Map.PowerClass::IsToRedraw = true;
  2160. Map.Flag_To_Redraw(false);
  2161. }
  2162. /*
  2163. ** This could be a building that builds. If so, then the sidebar may need adjustment.
  2164. ** Set IsInLimbo to true to "fool" the sidebar into knowing that this building
  2165. ** isn't available. Set it back to false so the rest of the Limbo code works.
  2166. ** Otherwise, the sidebar won't properly remove non-available buildables.
  2167. */
  2168. // if (IsOwnedByPlayer && !ScenarioInit) {
  2169. // IsInLimbo = true;
  2170. // Map.Recalc();
  2171. // IsInLimbo = false;
  2172. // }
  2173. }
  2174. return(TechnoClass::Limbo());
  2175. }
  2176. /***********************************************************************************************
  2177. * BuildingClass::Turret_Facing -- Fetches the turret facing for this building. *
  2178. * *
  2179. * This will return the turret facing for this building. Some buildings don't have a *
  2180. * visual turret (e.g., pillbox) so they return a turret facing that always faces their *
  2181. * current target. *
  2182. * *
  2183. * INPUT: none *
  2184. * *
  2185. * OUTPUT: Returns with the current facing of the turret. *
  2186. * *
  2187. * WARNINGS: none *
  2188. * *
  2189. * HISTORY: *
  2190. * 07/29/1996 JLB : Created. *
  2191. *=============================================================================================*/
  2192. DirType BuildingClass::Turret_Facing(void) const
  2193. {
  2194. if (!Class->IsTurretEquipped && Target_Legal(TarCom)) {
  2195. return(::Direction(Center_Coord(), As_Coord(TarCom)));
  2196. }
  2197. return(PrimaryFacing.Current());
  2198. }
  2199. /***********************************************************************************************
  2200. * BuildingClass::Greatest_Threat -- Searches for target that building can fire upon. *
  2201. * *
  2202. * This routine intercepts the Greatest_Threat function so that it can add the ability *
  2203. * to search for ground targets, if this isn't a SAM site. *
  2204. * *
  2205. * INPUT: threat -- The base threat control value. Typically, it might be THREAT_RANGE *
  2206. * or THREAT_NORMAL. *
  2207. * *
  2208. * OUTPUT: Returns with a suitable target. If none could be found, then TARGET_NONE is *
  2209. * returned instead. *
  2210. * *
  2211. * WARNINGS: none *
  2212. * *
  2213. * HISTORY: *
  2214. * 01/01/1995 JLB : Created. *
  2215. *=============================================================================================*/
  2216. TARGET BuildingClass::Greatest_Threat(ThreatType threat) const
  2217. {
  2218. assert(Buildings.ID(this) == ID);
  2219. assert(IsActive);
  2220. if (Class->PrimaryWeapon != NULL) {
  2221. threat = threat | Class->PrimaryWeapon->Allowed_Threats();
  2222. }
  2223. if (Class->SecondaryWeapon != NULL) {
  2224. threat = threat | Class->SecondaryWeapon->Allowed_Threats();
  2225. }
  2226. if (House->IsHuman) {
  2227. threat = threat & ~THREAT_BUILDINGS;
  2228. }
  2229. threat = threat | THREAT_RANGE;
  2230. // if (Class->PrimaryWeapon != NULL) {
  2231. // if (Class->PrimaryWeapon->Bullet->IsAntiAircraft) {
  2232. // threat = threat | THREAT_AIR;
  2233. // }
  2234. // if (Class->PrimaryWeapon->Bullet->IsAntiGround) {
  2235. // threat = threat | THREAT_BUILDINGS|THREAT_INFANTRY|THREAT_BOATS|THREAT_VEHICLES;
  2236. // }
  2237. // threat = threat | THREAT_RANGE;
  2238. // }
  2239. return(TechnoClass::Greatest_Threat(threat));
  2240. }
  2241. /***********************************************************************************************
  2242. * BuildingClass::Grand_Opening -- Handles construction completed special operations. *
  2243. * *
  2244. * This routine is called when construction has finished. Typically, this enables *
  2245. * new production options for factories. *
  2246. * *
  2247. * INPUT: none *
  2248. * *
  2249. * OUTPUT: none *
  2250. * *
  2251. * WARNINGS: none *
  2252. * *
  2253. * HISTORY: *
  2254. * 01/08/1995 JLB : Created. *
  2255. * 06/13/1995 JLB : Added helipad. *
  2256. *=============================================================================================*/
  2257. void BuildingClass::Grand_Opening(bool captured)
  2258. {
  2259. assert(Buildings.ID(this) == ID);
  2260. assert(IsActive);
  2261. if (!HasOpened || captured) {
  2262. HasOpened = true;
  2263. /*
  2264. ** Adjust the owning house according to the power, drain, and Tiberium capacity that
  2265. ** this building has.
  2266. */
  2267. House->Adjust_Drain(Class->Drain);
  2268. House->Adjust_Capacity(Class->Capacity);
  2269. House->IsRecalcNeeded = true;
  2270. /* SPECIAL CASE:
  2271. ** Tiberium Refineries get a free harvester. Add a harvester to the
  2272. ** reinforcement list at this time.
  2273. */
  2274. if (*this == STRUCT_REFINERY && !ScenarioInit && !captured && !Debug_Map && (!House->IsHuman || PurchasePrice == 0 || PurchasePrice > Class->Raw_Cost())) {
  2275. CELL cell = Coord_Cell(Adjacent_Cell(Center_Coord(), DIR_S));
  2276. UnitClass * unit = new UnitClass(UNIT_HARVESTER, House->Class->House);
  2277. if (unit != NULL) {
  2278. /*
  2279. ** Try to place down the harvesters. If it could not be placed, then try
  2280. ** to place it in a nearby location.
  2281. */
  2282. if (!unit->Unlimbo(Cell_Coord(cell), DIR_W)) {
  2283. /*
  2284. ** Check multiple times for clear locations.
  2285. */
  2286. for (int i = 0; i < 10; i++) {
  2287. cell = unit->Nearby_Location(this, i);
  2288. if (unit->Unlimbo(Cell_Coord(cell), DIR_SW)) {
  2289. break;
  2290. }
  2291. }
  2292. /*
  2293. ** If the harvester could still not be placed, then refund the money
  2294. ** to the owner and then bail.
  2295. */
  2296. if (unit->IsInLimbo) {
  2297. House->Refund_Money(unit->Class->Cost_Of());
  2298. delete unit;
  2299. }
  2300. }
  2301. } else {
  2302. /*
  2303. ** If the harvester could not be created in the first place, then give
  2304. ** the full refund price to the owning player.
  2305. */
  2306. House->Refund_Money(UnitTypeClass::As_Reference(UNIT_HARVESTER).Cost_Of());
  2307. }
  2308. }
  2309. /*
  2310. ** Helicopter pads get a free attack helicopter.
  2311. */
  2312. if (!Rule.IsSeparate && *this == STRUCT_HELIPAD && !captured) {
  2313. ScenarioInit++;
  2314. AircraftClass * air = 0;
  2315. if (House->ActLike == HOUSE_USSR || House->ActLike == HOUSE_BAD || House->ActLike == HOUSE_UKRAINE) {
  2316. air = new AircraftClass(AIRCRAFT_HIND, House->Class->House);
  2317. } else {
  2318. air = new AircraftClass(AIRCRAFT_LONGBOW, House->Class->House);
  2319. }
  2320. if (air) {
  2321. air->Height = 0;
  2322. if (air->Unlimbo(Docking_Coord(), air->Pose_Dir())) {
  2323. air->Assign_Mission(MISSION_GUARD);
  2324. air->Transmit_Message(RADIO_HELLO, this);
  2325. Transmit_Message(RADIO_TETHER);
  2326. }
  2327. }
  2328. ScenarioInit--;
  2329. }
  2330. }
  2331. }
  2332. /***********************************************************************************************
  2333. * BuildingClass::Repair -- Initiates or terminates the repair process. *
  2334. * *
  2335. * This routine will start, stop, or toggle the repair process. When a building repairs, it *
  2336. * occurs incrementally over time. *
  2337. * *
  2338. * INPUT: control -- Determines how to control the repair process. *
  2339. * 0: Turns repair process off (if it was on). *
  2340. * 1: Turns repair process on (if it was off). *
  2341. * -1:Toggles repair process to other state. *
  2342. * *
  2343. * OUTPUT: none *
  2344. * *
  2345. * WARNINGS: none *
  2346. * *
  2347. * HISTORY: *
  2348. * 01/08/1995 JLB : Created. *
  2349. *=============================================================================================*/
  2350. void BuildingClass::Repair(int control)
  2351. {
  2352. assert(Buildings.ID(this) == ID);
  2353. assert(IsActive);
  2354. switch (control) {
  2355. case -1:
  2356. IsRepairing = (IsRepairing == false);
  2357. break;
  2358. case 1:
  2359. if (IsRepairing) return;
  2360. IsRepairing = true;
  2361. break;
  2362. case 0:
  2363. if (!IsRepairing) return;
  2364. IsRepairing = false;
  2365. break;
  2366. default:
  2367. break;
  2368. }
  2369. /*
  2370. ** At this point, we know that the repair state has changed. Perform
  2371. ** appropriate action.
  2372. */
  2373. VocType soundid = VOC_NONE;
  2374. if (IsRepairing) {
  2375. if (Strength == Class->MaxStrength) {
  2376. soundid = VOC_SCOLD;
  2377. } else {
  2378. soundid = VOC_CLICK;
  2379. if (House->IsPlayerControl) {
  2380. Clicked_As_Target(PlayerPtr->Class->House); // 2019/09/20 JAS - Added record of who clicked on the object
  2381. }
  2382. IsWrenchVisible = true;
  2383. }
  2384. } else {
  2385. soundid = VOC_CLICK;
  2386. }
  2387. if (House->IsPlayerControl) {
  2388. Sound_Effect(soundid, Coord);
  2389. }
  2390. }
  2391. /***********************************************************************************************
  2392. * BuildingClass::Sell_Back -- Controls the sell back (demolish) operation. *
  2393. * *
  2394. * This routine will initiate or stop the sell back process for a building. It is called *
  2395. * when the player clicks on a building when the sell mode is active. *
  2396. * *
  2397. * INPUT: control -- The action to perform. 0 = turn deconstruction off, 1 = deconstruct, *
  2398. * -1 = toggle deconstruction state. *
  2399. * *
  2400. * OUTPUT: none *
  2401. * *
  2402. * WARNINGS: none *
  2403. * *
  2404. * HISTORY: *
  2405. * 06/25/1995 JLB : Created. *
  2406. *=============================================================================================*/
  2407. void BuildingClass::Sell_Back(int control)
  2408. {
  2409. assert(Buildings.ID(this) == ID);
  2410. assert(IsActive);
  2411. if (Class->Get_Buildup_Data()) {
  2412. bool decon = false;
  2413. switch (control) {
  2414. case -1:
  2415. decon = (Mission != MISSION_DECONSTRUCTION);
  2416. break;
  2417. case 1:
  2418. if (Mission == MISSION_DECONSTRUCTION) return;
  2419. if (IsGoingToBlow) return;
  2420. decon = true;
  2421. break;
  2422. case 0:
  2423. if (Mission != MISSION_DECONSTRUCTION) return;
  2424. decon = false;
  2425. break;
  2426. default:
  2427. break;
  2428. }
  2429. /*
  2430. ** At this point, we know that the repair state has changed. Perform
  2431. ** appropriate action.
  2432. */
  2433. if (decon) {
  2434. Assign_Mission(MISSION_DECONSTRUCTION);
  2435. Commence();
  2436. if (House->IsPlayerControl) {
  2437. Clicked_As_Target(PlayerPtr->Class->House);
  2438. }
  2439. }
  2440. if (House->IsPlayerControl) {
  2441. Sound_Effect(VOC_CLICK);
  2442. }
  2443. }
  2444. }
  2445. /***********************************************************************************************
  2446. * BuildingClass::What_Action -- Determines action to perform if click on specified object. *
  2447. * *
  2448. * This routine will determine what action to perform if the mouse was clicked on the *
  2449. * object specified. This determination is used to control the mouse imagery and the *
  2450. * function process when the mouse button is pressed. *
  2451. * *
  2452. * INPUT: object -- Pointer to the object that, if clicked on, will control what action *
  2453. * is to be performed. *
  2454. * *
  2455. * OUTPUT: Returns with the ActionType that will occur if the mouse is clicked over the *
  2456. * object specified while the building is currently selected. *
  2457. * *
  2458. * WARNINGS: none *
  2459. * *
  2460. * HISTORY: *
  2461. * 01/18/1995 JLB : Created. *
  2462. *=============================================================================================*/
  2463. ActionType BuildingClass::What_Action(ObjectClass const * object) const
  2464. {
  2465. assert(Buildings.ID(this) == ID);
  2466. assert(IsActive);
  2467. ActionType action = TechnoClass::What_Action(object);
  2468. if (action == ACTION_SELF) {
  2469. int index;
  2470. if (Class->Is_Factory() && PlayerPtr == House && *House->Factory_Counter(Class->ToBuild) > 1) {
  2471. switch (Class->ToBuild) {
  2472. case RTTI_INFANTRYTYPE:
  2473. case RTTI_INFANTRY:
  2474. action = ACTION_NONE;
  2475. if (*this == STRUCT_KENNEL) {
  2476. for (index = 0; index < Buildings.Count(); index++) {
  2477. BuildingClass *bldg = Buildings.Ptr(index);
  2478. if (bldg != this && bldg->Owner() == Owner() && *bldg == STRUCT_KENNEL) {
  2479. action = ACTION_TOGGLE_PRIMARY;
  2480. break;
  2481. }
  2482. }
  2483. } else {
  2484. for (index = 0; index < Buildings.Count(); index++) {
  2485. BuildingClass *bldg = Buildings.Ptr(index);
  2486. if (bldg != this && bldg->Owner() == Owner() && bldg->Class->ToBuild == RTTI_INFANTRYTYPE && *bldg != STRUCT_KENNEL) {
  2487. action = ACTION_TOGGLE_PRIMARY;
  2488. break;
  2489. }
  2490. }
  2491. }
  2492. break;
  2493. case RTTI_AIRCRAFTTYPE:
  2494. case RTTI_AIRCRAFT:
  2495. action = ACTION_NONE;
  2496. if (*this == STRUCT_AIRSTRIP) {
  2497. for (index = 0; index < Buildings.Count(); index++) {
  2498. BuildingClass *bldg = Buildings.Ptr(index);
  2499. if (bldg != this && bldg->Owner() == Owner() && *bldg == STRUCT_AIRSTRIP) {
  2500. action = ACTION_TOGGLE_PRIMARY;
  2501. break;
  2502. }
  2503. }
  2504. }
  2505. else {
  2506. for (index = 0; index < Buildings.Count(); index++) {
  2507. BuildingClass *bldg = Buildings.Ptr(index);
  2508. if (bldg != this && bldg->Owner() == Owner() && bldg->Class->ToBuild == RTTI_AIRCRAFTTYPE && *bldg != STRUCT_AIRSTRIP) {
  2509. action = ACTION_TOGGLE_PRIMARY;
  2510. break;
  2511. }
  2512. }
  2513. }
  2514. break;
  2515. case RTTI_UNITTYPE:
  2516. case RTTI_UNIT:
  2517. case RTTI_VESSELTYPE:
  2518. case RTTI_VESSEL:
  2519. action = ACTION_TOGGLE_PRIMARY;
  2520. break;
  2521. case RTTI_NONE:
  2522. action = ACTION_NONE;
  2523. break;
  2524. default:
  2525. break;
  2526. }
  2527. } else {
  2528. action = ACTION_NONE;
  2529. }
  2530. }
  2531. /*
  2532. ** Don't allow targeting of SAM sites, even if the CTRL key
  2533. ** is held down. Also don't allow targeting if the object is too
  2534. ** far away.
  2535. */
  2536. if (action == ACTION_ATTACK && (*this == STRUCT_SAM || *this == STRUCT_AAGUN || !In_Range(object, 0))) {
  2537. action = ACTION_NONE;
  2538. }
  2539. if (action == ACTION_MOVE) {
  2540. action = ACTION_NONE;
  2541. }
  2542. return(action);
  2543. }
  2544. /***********************************************************************************************
  2545. * BuildingClass::What_Action -- Determines what action will occur. *
  2546. * *
  2547. * This routine examines the cell specified and returns with the action that will be *
  2548. * performed if that cell were clicked upon while the building is selected. *
  2549. * *
  2550. * INPUT: cell -- The cell to examine. *
  2551. * *
  2552. * OUTPUT: Returns the ActionType that indicates what should occur if the mouse is clicked *
  2553. * on this cell. *
  2554. * *
  2555. * WARNINGS: none *
  2556. * *
  2557. * HISTORY: *
  2558. * 01/18/1995 JLB : Created. *
  2559. *=============================================================================================*/
  2560. ActionType BuildingClass::What_Action(CELL cell) const
  2561. {
  2562. assert(Buildings.ID(this) == ID);
  2563. assert(IsActive);
  2564. ActionType action = TechnoClass::What_Action(cell);
  2565. if (action == ACTION_MOVE && (*this != STRUCT_CONST || !Is_MCV_Deploy())) {
  2566. action = ACTION_NONE;
  2567. }
  2568. /*
  2569. ** Don't allow targeting of SAM sites, even if the CTRL key
  2570. ** is held down.
  2571. */
  2572. if (action == ACTION_ATTACK && Class->PrimaryWeapon != NULL && !Class->PrimaryWeapon->Bullet->IsAntiGround) {
  2573. // if (action == ACTION_ATTACK && (*this == STRUCT_SAM || *this == STRUCT_AAGUN)) {
  2574. action = ACTION_NONE;
  2575. }
  2576. return(action);
  2577. }
  2578. /***********************************************************************************************
  2579. * BuildingClass::Begin_Mode -- Begins an animation mode for the building. *
  2580. * *
  2581. * This routine will start the building animating. This animation will loop indefinitely *
  2582. * until explicitly stopped. *
  2583. * *
  2584. * INPUT: bstate -- The animation state to initiate. *
  2585. * *
  2586. * OUTPUT: none *
  2587. * *
  2588. * WARNINGS: The building graphic state will reflect the first stage of this animation the *
  2589. * very next time it is rendered. *
  2590. * *
  2591. * HISTORY: *
  2592. * 06/25/1995 JLB : Created. *
  2593. * 07/02/1995 JLB : Uses normalize animation rate where applicable. *
  2594. *=============================================================================================*/
  2595. void BuildingClass::Begin_Mode(BStateType bstate)
  2596. {
  2597. assert(Buildings.ID(this) == ID);
  2598. assert(IsActive);
  2599. QueueBState = bstate;
  2600. if (BState == BSTATE_NONE || bstate == BSTATE_CONSTRUCTION || ScenarioInit) {
  2601. BState = bstate;
  2602. QueueBState = BSTATE_NONE;
  2603. BuildingTypeClass::AnimControlType const * ctrl = Fetch_Anim_Control();
  2604. int rate = ctrl->Rate;
  2605. if (Class->IsRegulated && bstate != BSTATE_CONSTRUCTION) {
  2606. rate = Options.Normalize_Delay(rate);
  2607. }
  2608. Set_Rate(rate);
  2609. Set_Stage(ctrl->Start);
  2610. }
  2611. }
  2612. /***********************************************************************************************
  2613. * BuildingClass::Center_Coord -- Fetches the center coordinate for the building. *
  2614. * *
  2615. * This routine is used to set the center coordinate for this building. *
  2616. * *
  2617. * INPUT: none *
  2618. * *
  2619. * OUTPUT: Returns with the coordinate for the center location for the building. *
  2620. * *
  2621. * WARNINGS: none *
  2622. * *
  2623. * HISTORY: *
  2624. * 03/10/1995 JLB : Created. *
  2625. *=============================================================================================*/
  2626. COORDINATE BuildingClass::Center_Coord(void) const
  2627. {
  2628. assert(Buildings.ID(this) == ID);
  2629. assert(IsActive);
  2630. return(Coord_Add(Coord, CenterOffset[Class->Size]));
  2631. }
  2632. /***********************************************************************************************
  2633. * BuildingClass::Docking_Coord -- Fetches the coordinate to use for docking. *
  2634. * *
  2635. * This routine will return the coordinate to use when an object wishes to dock with this *
  2636. * building. Normally the docking coordinate would be the center of the building. *
  2637. * Exceptions to this would be the airfield and helipad. Their docking coordinates are *
  2638. * offset to match the building artwork. *
  2639. * *
  2640. * INPUT: none *
  2641. * *
  2642. * OUTPUT: Returns with the coordinate to head to when trying to dock with this building. *
  2643. * *
  2644. * WARNINGS: none *
  2645. * *
  2646. * HISTORY: *
  2647. * 09/21/1995 JLB : Created. *
  2648. *=============================================================================================*/
  2649. COORDINATE BuildingClass::Docking_Coord(void) const
  2650. {
  2651. assert(Buildings.ID(this) == ID);
  2652. assert(IsActive);
  2653. if (*this == STRUCT_HELIPAD) {
  2654. return(Coord_Add(Coord, XYP_COORD(24, 18)));
  2655. }
  2656. if (*this == STRUCT_AIRSTRIP) {
  2657. return(Coord_Add(Coord, XYP_COORD(ICON_PIXEL_W + ICON_PIXEL_W/2, 28)));
  2658. }
  2659. return(TechnoClass::Docking_Coord());
  2660. }
  2661. /***********************************************************************************************
  2662. * BuildingClass::Can_Fire -- Determines if this building can fire. *
  2663. * *
  2664. * Use this routine to see if the building can fire its weapon. *
  2665. * *
  2666. * *
  2667. * INPUT: target -- The target that firing upon is desired. *
  2668. * *
  2669. * which -- Which weapon to use when firing. 0=primary, 1=secondary. *
  2670. * *
  2671. * OUTPUT: Returns with the fire possibility code. If firing is allowed, then FIRE_OK is *
  2672. * returned. Other cases will result in appropriate fire code value that indicates *
  2673. * why firing is not allowed. *
  2674. * *
  2675. * WARNINGS: none *
  2676. * *
  2677. * HISTORY: *
  2678. * 05/03/1995 JLB : Created. *
  2679. *=============================================================================================*/
  2680. FireErrorType BuildingClass::Can_Fire(TARGET target, int which) const
  2681. {
  2682. assert(Buildings.ID(this) == ID);
  2683. assert(IsActive);
  2684. FireErrorType canfire = TechnoClass::Can_Fire(target, which);
  2685. if (canfire == FIRE_OK) {
  2686. /*
  2687. ** Double check to make sure that the facing is roughly toward
  2688. ** the target. If the difference is too great, then firing is
  2689. ** temporarily postponed.
  2690. */
  2691. if (Class->IsTurretEquipped) {
  2692. int diff = PrimaryFacing.Difference(Direction(TarCom));
  2693. diff = abs(diff);
  2694. if (ABS(diff) > (*this == STRUCT_SAM ? 64 : 8)) {
  2695. // if (ABS(diff) > 8) {
  2696. return(FIRE_FACING);
  2697. }
  2698. /*
  2699. ** If the turret is rotating then firing must be delayed.
  2700. */
  2701. // if (PrimaryFacing.Is_Rotating()) {
  2702. // return(FIRE_ROTATING);
  2703. // }
  2704. }
  2705. /*
  2706. ** Certain buildings cannot fire if there is insufficient power.
  2707. */
  2708. if (Class->IsPowered && House->Power_Fraction() < 1) {
  2709. return(FIRE_BUSY);
  2710. }
  2711. /*
  2712. ** If an obelisk can fire, check the state of charge.
  2713. */
  2714. if (Class->PrimaryWeapon != NULL && Class->PrimaryWeapon->IsElectric && !IsCharged) {
  2715. return(FIRE_BUSY);
  2716. }
  2717. }
  2718. return(canfire);
  2719. }
  2720. /***********************************************************************************************
  2721. * BuildingClass::Toggle_Primary -- Toggles the primary factory state. *
  2722. * *
  2723. * This routine will change the primary factory state of this building. The primary *
  2724. * factory is the one that units will be produced from (by default). *
  2725. * *
  2726. * INPUT: none *
  2727. * *
  2728. * OUTPUT: Is this building NOW the primary factory? *
  2729. * *
  2730. * WARNINGS: none *
  2731. * *
  2732. * HISTORY: *
  2733. * 05/03/1995 JLB : Created. *
  2734. *=============================================================================================*/
  2735. bool BuildingClass::Toggle_Primary(void)
  2736. {
  2737. assert(Buildings.ID(this) == ID);
  2738. assert(IsActive);
  2739. if (IsLeader) {
  2740. IsLeader = false;
  2741. } else {
  2742. for (int index = 0; index < Buildings.Count(); index++) {
  2743. BuildingClass * building = Buildings.Ptr(index);
  2744. if (!building->IsInLimbo && building->Owner() == Owner() && building->Class->ToBuild == Class->ToBuild) {
  2745. if (Class->ToBuild == RTTI_INFANTRYTYPE) {
  2746. if (*building == STRUCT_KENNEL && *this == STRUCT_KENNEL) {
  2747. building->IsLeader = false;
  2748. } else {
  2749. if (*building != STRUCT_KENNEL && *this != STRUCT_KENNEL) {
  2750. building->IsLeader = false;
  2751. }
  2752. }
  2753. } else if (Class->ToBuild == RTTI_AIRCRAFTTYPE) {
  2754. if (*building == STRUCT_AIRSTRIP && *this == STRUCT_AIRSTRIP) {
  2755. building->IsLeader = false;
  2756. } else {
  2757. if (*building != STRUCT_AIRSTRIP && *this != STRUCT_AIRSTRIP) {
  2758. building->IsLeader = false;
  2759. }
  2760. }
  2761. } else {
  2762. building->IsLeader = false;
  2763. }
  2764. }
  2765. }
  2766. IsLeader = true;
  2767. //
  2768. // MBL 04.20.2020 - Update so that each player in multiplayer will properly hear this when it applies to them
  2769. //
  2770. // if ((HouseClass *)House == PlayerPtr) {
  2771. // Speak(VOX_PRIMARY_SELECTED);
  2772. // }
  2773. if ((HouseClass *)House->IsHuman) {
  2774. Speak(VOX_PRIMARY_SELECTED, House);
  2775. }
  2776. }
  2777. Mark(MARK_CHANGE);
  2778. return(IsLeader);
  2779. }
  2780. /***********************************************************************************************
  2781. * BuildingClass::Captured -- Captures the building. *
  2782. * *
  2783. * This routine will change the owner of the building. It handles updating any related *
  2784. * game systems as a result. Factories are the most prone to have great game related *
  2785. * consequences when captured. This could also affect the sidebar and building ownership. *
  2786. * *
  2787. * INPUT: newowner -- Pointer to the house that is now the new owner. *
  2788. * *
  2789. * OUTPUT: Was the capture attempt successful? *
  2790. * *
  2791. * WARNINGS: Capturing could fail if the house is already owned by the one specified or *
  2792. * the building isn't allowed to be captured. *
  2793. * *
  2794. * HISTORY: *
  2795. * 05/03/1995 JLB : Created. *
  2796. * 07/05/1995 JLB : Fixed production problem with capturing enemy buildings. *
  2797. *=============================================================================================*/
  2798. bool BuildingClass::Captured(HouseClass * newowner)
  2799. {
  2800. assert(Buildings.ID(this) == ID);
  2801. assert(IsActive);
  2802. if (Can_Capture() && newowner != House) {
  2803. #ifdef TOFIX
  2804. switch (Owner()) {
  2805. case HOUSE_GOOD:
  2806. Speak(VOX_GDI_CAPTURED);
  2807. break;
  2808. case HOUSE_BAD:
  2809. Speak(VOX_NOD_CAPTURED);
  2810. break;
  2811. }
  2812. #endif
  2813. /*
  2814. ** Maybe trigger an achivement. ST - 11/14/2019 1:53PM
  2815. */
  2816. if (newowner->IsHuman) {
  2817. TechnoTypeClass const *object_type = Techno_Type_Class();
  2818. if (object_type) {
  2819. if (newowner->ActLike != House->ActLike) {
  2820. On_Achievement_Event(newowner, "OPPOSING_BUILDING_CAPTURED", object_type->IniName);
  2821. } else {
  2822. On_Achievement_Event(newowner, "BUILDING_CAPTURED", object_type->IniName);
  2823. }
  2824. }
  2825. }
  2826. /*
  2827. ** Make sure the capturer isn't spying on his own building, and if
  2828. ** it was a radar facility, update the target house's RadarSpied field.
  2829. */
  2830. if (SpiedBy & (1<<(newowner->Class->House)) ) {
  2831. SpiedBy -= (1<<(newowner->Class->House));
  2832. if (*this == STRUCT_RADAR) {
  2833. Update_Radar_Spied();
  2834. }
  2835. }
  2836. if (House == PlayerPtr) {
  2837. Map.PowerClass::IsToRedraw = true;
  2838. Map.Flag_To_Redraw(false);
  2839. }
  2840. if (*this == STRUCT_GAP) {
  2841. Remove_Gap_Effect();
  2842. IsJamming = false;
  2843. Arm = 0;
  2844. }
  2845. /*
  2846. ** Add this building to the list of buildings captured this game. For internet stats purposes.
  2847. */
  2848. if (Session.Type == GAME_INTERNET) {
  2849. newowner->CapturedBuildings->Increment_Unit_Total (Class->Type);
  2850. }
  2851. House->Adjust_Power(-Power_Output());
  2852. LastStrength = 0;
  2853. House->Adjust_Drain(-Class->Drain);
  2854. int booty = House->Adjust_Capacity(-Class->Capacity, true);
  2855. /*
  2856. ** If there is something loaded, then it gets captured as well.
  2857. */
  2858. TechnoClass * tech = Attached_Object();
  2859. if (tech) tech->Captured(newowner);
  2860. /*
  2861. ** If something isn't technically attached, but is sitting on this
  2862. ** building for another reason (e.g., helicopter on helipad), then it
  2863. ** gets captured as well.
  2864. */
  2865. tech = Contact_With_Whom();
  2866. if (tech) {
  2867. if (Transmit_Message(RADIO_NEED_TO_MOVE) == RADIO_ROGER && (::Distance(tech->Center_Coord(), Docking_Coord()) < 0x0040 ||
  2868. (tech->What_Am_I() == RTTI_AIRCRAFT && ((AircraftClass *)tech)->Class->IsFixedWing && ((AircraftClass *)tech)->In_Which_Layer() == LAYER_GROUND)) ) {
  2869. tech->Captured(newowner);
  2870. } else {
  2871. Transmit_Message(RADIO_RUN_AWAY);
  2872. Transmit_Message(RADIO_OVER_OUT);
  2873. }
  2874. }
  2875. /*
  2876. ** Abort any computer production in progress.
  2877. */
  2878. if (Factory) {
  2879. delete (FactoryClass *)Factory;
  2880. Factory = 0;
  2881. }
  2882. /*
  2883. ** Decrement the factory counter for the original owner.
  2884. */
  2885. House->Active_Remove(this);
  2886. /*
  2887. ** Flag that both owners now need to update their buildable lists.
  2888. */
  2889. House->IsRecalcNeeded = true;
  2890. newowner->IsRecalcNeeded = true;
  2891. HouseClass * oldowner = House;
  2892. TARGET tocap = As_Target();
  2893. IsCaptured = true;
  2894. TechnoClass::Captured(newowner);
  2895. oldowner->ToCapture = tocap;
  2896. oldowner->Recalc_Center();
  2897. House->Recalc_Center();
  2898. if (House->ToCapture == As_Target()) {
  2899. House->ToCapture = TARGET_NONE;
  2900. }
  2901. SmudgeType bib;
  2902. CELL cell = Coord_Cell(Coord);
  2903. if (Class->Bib_And_Offset(bib, cell)) {
  2904. SmudgeClass * smudge = new SmudgeClass(bib);
  2905. if (smudge) {
  2906. smudge->Disown(cell);
  2907. delete smudge;
  2908. }
  2909. #ifdef FIXIT_CAPTURE_BIB
  2910. if (Session.Type == GAME_NORMAL) {
  2911. new SmudgeClass(bib, Cell_Coord(cell), Class->IsBase ? House->Class->House : HOUSE_NONE);
  2912. } else {
  2913. new SmudgeClass(bib, Cell_Coord(cell), House->Class->House);
  2914. }
  2915. #else
  2916. new SmudgeClass(bib, Cell_Coord(cell), House->Class->House);
  2917. #endif
  2918. }
  2919. House->Stole(Refund_Amount());
  2920. /*
  2921. ** Increment the factory count for the new owner.
  2922. */
  2923. House->Active_Add(this);
  2924. IsRepairing = false;
  2925. Grand_Opening(true);
  2926. House->Harvested(booty);
  2927. Mark(MARK_CHANGE);
  2928. /*
  2929. ** Perform a look operation when captured if it was the player
  2930. ** that performed the capture.
  2931. */
  2932. if (Session.Type == GAME_GLYPHX_MULTIPLAYER && House->IsHuman) {
  2933. Look(false);
  2934. } else {
  2935. if (House == PlayerPtr) {
  2936. Look(false);
  2937. }
  2938. }
  2939. /*
  2940. ** If it was spied upon by the player who just captured it, clear the
  2941. ** spiedby flag for that house.
  2942. */
  2943. if (SpiedBy & (1 << (newowner->Class->House))) {
  2944. SpiedBy &= ~(1 << (newowner->Class->House));
  2945. }
  2946. /*
  2947. ** Update the new building's colors on the radar map.
  2948. */
  2949. short const * offset = Occupy_List();
  2950. while (*offset != REFRESH_EOL) {
  2951. CELL cell = Coord_Cell(Coord) + *offset++;
  2952. Map.Radar_Pixel(cell);
  2953. }
  2954. if (oldowner) {
  2955. oldowner->Check_Pertinent_Structures();
  2956. }
  2957. return(true);
  2958. }
  2959. return(false);
  2960. }
  2961. /***********************************************************************************************
  2962. * BuildingClass::Sort_Y -- Returns the building coordinate used for sorting. *
  2963. * *
  2964. * The coordinate value returned from this function should be used for sorting purposes. *
  2965. * It has special offset adjustment applied so that vehicles don't overlap (as much). *
  2966. * *
  2967. * INPUT: none *
  2968. * *
  2969. * OUTPUT: Returns with a coordinate value suitable to be used for sorting. *
  2970. * *
  2971. * WARNINGS: none *
  2972. * *
  2973. * HISTORY: *
  2974. * 05/23/1995 JLB : Created. *
  2975. * 06/19/1995 JLB : Handles buildings that come with bibs built-in. *
  2976. *=============================================================================================*/
  2977. COORDINATE BuildingClass::Sort_Y(void) const
  2978. {
  2979. assert(Buildings.ID(this) == ID);
  2980. assert(IsActive);
  2981. if (*this == STRUCT_REPAIR) {
  2982. return(Coord);
  2983. }
  2984. if (*this == STRUCT_HELIPAD) {
  2985. return(Center_Coord());
  2986. }
  2987. if (*this == STRUCT_AIRSTRIP) {
  2988. return(Center_Coord());
  2989. }
  2990. if (*this == STRUCT_BARRACKS /*|| *this == STRUCT_POWER*/) {
  2991. return(Center_Coord());
  2992. }
  2993. if (*this == STRUCT_REFINERY) {
  2994. return(Center_Coord());
  2995. }
  2996. /*
  2997. ** Mines need to bias their sort location such that they are typically drawn
  2998. ** before any objects that might overlap them.
  2999. */
  3000. if (*this == STRUCT_AVMINE || *this == STRUCT_APMINE) {
  3001. return(Coord_Move(Center_Coord(), DIR_N, CELL_LEPTON_H));
  3002. }
  3003. return(Coord_Add(Center_Coord(), XY_Coord(0, (Class->Height()*256)/3)));
  3004. }
  3005. /***********************************************************************************************
  3006. * BuildingClass::Can_Enter_Cell -- Determines if building can be placed down. *
  3007. * *
  3008. * This routine will determine if the building can be placed down at the location *
  3009. * specified. *
  3010. * *
  3011. * INPUT: cell -- The cell to examine. This is usually the cell of the upper left corner *
  3012. * of the building if it were to be placed down. *
  3013. * *
  3014. * OUTPUT: Returns with the move legality value for placement at the location specified. This *
  3015. * will either be MOVE_OK or MOVE_NO. *
  3016. * *
  3017. * WARNINGS: none *
  3018. * *
  3019. * HISTORY: *
  3020. * 06/25/1995 JLB : Created. *
  3021. *=============================================================================================*/
  3022. MoveType BuildingClass::Can_Enter_Cell(CELL cell, FacingType) const
  3023. {
  3024. assert(Buildings.ID(this) == ID);
  3025. assert(IsActive);
  3026. if (*this == STRUCT_CONST && IsDown) {
  3027. return(Map[cell].Is_Clear_To_Build(Class->Speed) ? MOVE_OK : MOVE_NO);
  3028. }
  3029. if (!Debug_Map && ScenarioInit == 0 && Session.Type == GAME_NORMAL && House->IsPlayerControl && !Map[cell].IsMapped) {
  3030. return(MOVE_NO);
  3031. }
  3032. return(Class->Legal_Placement(cell) ? MOVE_OK : MOVE_NO);
  3033. }
  3034. /***********************************************************************************************
  3035. * BuildingClass::Can_Demolish -- Can the player demolish (sell back) the building? *
  3036. * *
  3037. * Determines if the player can sell this building. Selling is possible if the building *
  3038. * is not currently in construction or deconstruction animation. *
  3039. * *
  3040. * INPUT: none *
  3041. * *
  3042. * OUTPUT: Can the building be demolished at this time? *
  3043. * *
  3044. * WARNINGS: none *
  3045. * *
  3046. * HISTORY: *
  3047. * 06/25/1995 JLB : Created. *
  3048. * 07/01/1995 JLB : If there is no buildup data, then the building can't be sold. *
  3049. * 07/17/1995 JLB : Cannot sell a refinery that has a harvester attached. *
  3050. *=============================================================================================*/
  3051. bool BuildingClass::Can_Demolish(void) const
  3052. {
  3053. assert(Buildings.ID(this) == ID);
  3054. assert(IsActive);
  3055. if (Class->IsUnsellable) return(false);
  3056. if (Class->Get_Buildup_Data() && BState != BSTATE_CONSTRUCTION && Mission != MISSION_DECONSTRUCTION && Mission != MISSION_CONSTRUCTION) {
  3057. if (*this == STRUCT_REFINERY && Is_Something_Attached()) return(false);
  3058. return(true);
  3059. }
  3060. return(false);
  3061. }
  3062. bool BuildingClass::Can_Demolish_Unit(void) const
  3063. {
  3064. return((*this == STRUCT_REPAIR || *this == STRUCT_AIRSTRIP) && In_Radio_Contact() && Distance(Contact_With_Whom()) < 0x0080);
  3065. }
  3066. bool BuildingClass::Can_Capture(void) const
  3067. {
  3068. bool can_capture = Class->IsCaptureable && Mission != MISSION_DECONSTRUCTION;
  3069. // Only allow capturing of multiplayer-owned structures
  3070. if (Session.Type != GAME_NORMAL) {
  3071. if (*this == STRUCT_V01) { // Check to fix exploit in specific map 'Tournament Ore Rift'
  3072. can_capture = false;
  3073. }
  3074. }
  3075. return(can_capture);
  3076. }
  3077. /***********************************************************************************************
  3078. * BuildingClass::Mission_Guard -- Handles guard mission for combat buildings. *
  3079. * *
  3080. * Buildings that can attack are given this mission. They will wait until a suitable target *
  3081. * comes within range and then launch into the attack mission. Buildings that have no *
  3082. * weaponry will just sit in this routine forever. *
  3083. * *
  3084. * INPUT: none *
  3085. * *
  3086. * OUTPUT: Returns with the number of game frames to delay before this routine will be called *
  3087. * again. *
  3088. * *
  3089. * WARNINGS: none *
  3090. * *
  3091. * HISTORY: *
  3092. * 06/25/1995 JLB : Created. *
  3093. *=============================================================================================*/
  3094. int BuildingClass::Mission_Guard(void)
  3095. {
  3096. assert(Buildings.ID(this) == ID);
  3097. assert(IsActive);
  3098. /*
  3099. ** If this building has a weapon, then search for a target to attack. When
  3100. ** a target is found, switch into attack mode to deal with the threat.
  3101. */
  3102. if (Is_Weapon_Equipped()) {
  3103. /*
  3104. ** Weapon equipped buildings are ALWAYS ready to launch into another mission if
  3105. ** they are sitting around in guard mode.
  3106. */
  3107. IsReadyToCommence = true;
  3108. /*
  3109. ** If there is no target available, then search for one.
  3110. */
  3111. if (!Target_Legal(TarCom)) {
  3112. ThreatType threat = THREAT_NORMAL;
  3113. Assign_Target(Greatest_Threat(threat));
  3114. }
  3115. /*
  3116. ** There is a valid target. Switch into attack mode right away.
  3117. */
  3118. if (Target_Legal(TarCom)) {
  3119. Assign_Mission(MISSION_ATTACK);
  3120. Commence();
  3121. return(1);
  3122. }
  3123. } else {
  3124. /*
  3125. ** This is the very simple state machine that basically does
  3126. ** nothing. This is the mode that non weapon equipped buildings
  3127. ** are normally in.
  3128. */
  3129. enum {
  3130. INITIAL_ENTRY,
  3131. IDLE
  3132. };
  3133. switch (Status) {
  3134. case INITIAL_ENTRY:
  3135. Begin_Mode(BSTATE_IDLE);
  3136. Status = IDLE;
  3137. break;
  3138. case IDLE:
  3139. /*
  3140. ** Special case to break out of guard mode if this is a repair
  3141. ** facility and there is a customer waiting at the grease pit.
  3142. */
  3143. if (*this == STRUCT_REPAIR &&
  3144. In_Radio_Contact() &&
  3145. Contact_With_Whom()->Is_Techno() &&
  3146. ((TechnoClass *)Contact_With_Whom())->Mission == MISSION_ENTER &&
  3147. Distance(Contact_With_Whom()) < 0x0040 &&
  3148. Transmit_Message(RADIO_NEED_TO_MOVE) == RADIO_ROGER) {
  3149. Assign_Mission(MISSION_REPAIR);
  3150. return(1);
  3151. }
  3152. break;
  3153. default:
  3154. break;
  3155. }
  3156. if (*this == STRUCT_REPAIR) {
  3157. return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  3158. } else {
  3159. return(MissionControl[Mission].Normal_Delay() * 3 + Random_Pick(0, 2));
  3160. }
  3161. }
  3162. return(MissionControl[Mission].AA_Delay() + Random_Pick(0, 2));
  3163. }
  3164. /***********************************************************************************************
  3165. * BuildingClass::Mission_Construction -- Handles mission construction. *
  3166. * *
  3167. * This routine will handle mission construction. When this mission is complete, the *
  3168. * building will begin normal operation. *
  3169. * *
  3170. * INPUT: none *
  3171. * *
  3172. * OUTPUT: Returns with the number of game frames to delay before calling this routine *
  3173. * again. *
  3174. * *
  3175. * WARNINGS: none *
  3176. * *
  3177. * HISTORY: *
  3178. * 06/25/1995 JLB : Created. *
  3179. *=============================================================================================*/
  3180. int BuildingClass::Mission_Construction(void)
  3181. {
  3182. assert(Buildings.ID(this) == ID);
  3183. assert(IsActive);
  3184. enum {
  3185. INITIAL,
  3186. DURING
  3187. };
  3188. switch (Status) {
  3189. case INITIAL:
  3190. Begin_Mode(BSTATE_CONSTRUCTION);
  3191. Transmit_Message(RADIO_BUILDING);
  3192. if (House->IsPlayerControl) {
  3193. Sound_Effect(VOC_CONSTRUCTION, Coord);
  3194. }
  3195. Status = DURING;
  3196. break;
  3197. case DURING:
  3198. if (IsReadyToCommence) {
  3199. /*
  3200. ** When construction is complete, then transmit this
  3201. ** to the construction yard so that it can stop its
  3202. ** construction animation.
  3203. */
  3204. Transmit_Message(RADIO_COMPLETE); // "I'm finished."
  3205. Transmit_Message(RADIO_OVER_OUT); // "You're free."
  3206. Begin_Mode(BSTATE_IDLE);
  3207. Grand_Opening();
  3208. Assign_Mission(MISSION_GUARD);
  3209. PrimaryFacing = Class->StartFace;
  3210. }
  3211. break;
  3212. default:
  3213. break;
  3214. }
  3215. return(1);
  3216. }
  3217. /***********************************************************************************************
  3218. * BuildingClass::Mission_Deconstruction -- Handles building deconstruction. *
  3219. * *
  3220. * This state machine is only used when the building is deconstructing as a result of *
  3221. * selling. When this mission is finished, the building will no longer exist. *
  3222. * *
  3223. * INPUT: none *
  3224. * *
  3225. * OUTPUT: Returns with the number of game frames to delay before calling this routine again. *
  3226. * *
  3227. * WARNINGS: none *
  3228. * *
  3229. * HISTORY: *
  3230. * 06/25/1995 JLB : Created. *
  3231. * 08/13/1995 JLB : Enable selling of units on a repair bay. *
  3232. * 08/20/1995 JLB : Scatters infantry from scattered starting points. *
  3233. *=============================================================================================*/
  3234. int BuildingClass::Mission_Deconstruction(void)
  3235. {
  3236. assert(Buildings.ID(this) == ID);
  3237. assert(IsActive);
  3238. /*
  3239. ** Always force repair off.
  3240. */
  3241. Repair(0);
  3242. enum {
  3243. INITIAL,
  3244. HOLDING,
  3245. DURING
  3246. };
  3247. switch (Status) {
  3248. case INITIAL:
  3249. /*
  3250. ** Special check for the repair bay which has the ability to sell
  3251. ** whatever is on it. If there is something on the repair bay, then
  3252. ** it will be sold. If there is nothing on the repair bay, then
  3253. ** the repair bay itself will be sold.
  3254. */
  3255. if (Can_Demolish_Unit() && Transmit_Message(RADIO_NEED_TO_MOVE) == RADIO_ROGER) {
  3256. TechnoClass * tech = Contact_With_Whom();
  3257. Transmit_Message(RADIO_OVER_OUT);
  3258. if (IsOwnedByPlayer) Speak(VOX_UNIT_SOLD);
  3259. tech->Sell_Back(1);
  3260. Assign_Mission(MISSION_GUARD);
  3261. return(1);
  3262. }
  3263. /*
  3264. ** Selling off a shipyard or sub pen may cause attached ships
  3265. ** who are repairing themselves to discontinue repairs.
  3266. */
  3267. if (*this == STRUCT_SHIP_YARD || *this == STRUCT_SUB_PEN) {
  3268. for (int index = 0; index < Vessels.Count(); index++) {
  3269. VesselClass * obj = Vessels.Ptr(index);
  3270. if (obj && !obj->IsInLimbo && obj->House == House) {
  3271. if (obj->IsSelfRepairing) {
  3272. if (::Distance(Center_Coord(), obj->Center_Coord()) < 0x0200) {
  3273. obj->IsSelfRepairing = false;
  3274. obj->IsToSelfRepair = false;
  3275. }
  3276. }
  3277. }
  3278. }
  3279. }
  3280. IsReadyToCommence = false;
  3281. Transmit_Message(RADIO_RUN_AWAY);
  3282. Status = HOLDING;
  3283. break;
  3284. case HOLDING:
  3285. if (!IsTethered) {
  3286. /*
  3287. ** The crew will evacuate from the building. The number of crew
  3288. ** members leaving is equal to the unrecovered cost of the building
  3289. ** divided by 100 (the typical cost of a minigunner infantryman).
  3290. */
  3291. if (!Target_Legal(ArchiveTarget) || !Is_MCV_Deploy() || *this != STRUCT_CONST) {
  3292. int count = How_Many_Survivors();
  3293. bool engine = false;
  3294. while (count) {
  3295. /*
  3296. ** Ensure that the player only gets ONE engineer and not from a captured
  3297. ** construction yard.
  3298. */
  3299. InfantryType typ = Crew_Type();
  3300. while (typ == INFANTRY_RENOVATOR && engine) {
  3301. typ = Crew_Type();
  3302. }
  3303. if (typ == INFANTRY_RENOVATOR) engine = true;
  3304. InfantryClass * infantry = 0;
  3305. if (typ != INFANTRY_NONE) infantry = new InfantryClass(typ, House->Class->House);
  3306. if (infantry != NULL) {
  3307. ScenarioInit++;
  3308. COORDINATE coord = Coord_Add(Center_Coord(), XYP_COORD(0, -12));
  3309. coord = Map[coord].Closest_Free_Spot(coord, false);
  3310. if (infantry->Unlimbo(coord, DIR_N)) {
  3311. infantry->IsZoneCheat = infantry->Can_Enter_Cell(Coord_Cell(infantry->Center_Coord())) != MOVE_OK;
  3312. if (infantry->Class->IsNominal) infantry->IsTechnician = true;
  3313. ScenarioInit--;
  3314. infantry->Scatter(0, true);
  3315. ScenarioInit++;
  3316. infantry->Assign_Mission(MISSION_GUARD_AREA);
  3317. } else {
  3318. delete infantry;
  3319. }
  3320. ScenarioInit--;
  3321. }
  3322. count--;
  3323. }
  3324. }
  3325. // MBL 07.10.2020 - In 1v1, sometimes both players will hear this SFX, or neither player will hear it
  3326. // Making it so all players hear it positionally in the map; Per thread discussion in https://jaas.ea.com/browse/TDRA-7245
  3327. //
  3328. #if 0
  3329. if (House->IsPlayerControl) {
  3330. Sound_Effect(VOC_CASHTURN, Coord);
  3331. }
  3332. #else
  3333. Sound_Effect(VOC_CASHTURN, Coord);
  3334. #endif
  3335. /*
  3336. ** Destroy all attached objects. ST - 4/24/2020 9:38PM
  3337. */
  3338. while (Attached_Object()) {
  3339. FootClass * obj = Detach_Object();
  3340. Detach_All(true);
  3341. delete obj;
  3342. }
  3343. Transmit_Message(RADIO_OVER_OUT);
  3344. Status = DURING;
  3345. Begin_Mode(BSTATE_CONSTRUCTION);
  3346. IsReadyToCommence = false;
  3347. IsSurvivorless = true;
  3348. break;
  3349. }
  3350. Transmit_Message(RADIO_RUN_AWAY);
  3351. break;
  3352. case DURING:
  3353. if (IsReadyToCommence) {
  3354. House->IsRecalcNeeded = true;
  3355. // MBL 05.06.2020 - "Structure Sold" is being heard when selecting/moving a redepolyable Con Yard to turn back into an MCV (RA only), so moving below
  3356. #if 0
  3357. // MBL 04.06.2020: Fix being heard by wrong player
  3358. // if (IsOwnedByPlayer) Speak(VOX_STRUCTURE_SOLD);
  3359. if (IsOwnedByPlayer) {
  3360. if ((HouseClass *)House == PlayerPtr) {
  3361. Speak(VOX_STRUCTURE_SOLD);
  3362. }
  3363. }
  3364. #endif
  3365. bool mcv_redeployed = false;
  3366. /*
  3367. ** Construction yards that deconstruct, really just revert back
  3368. ** to an MCV.
  3369. */
  3370. if (Target_Legal(ArchiveTarget) && *this == STRUCT_CONST && House->IsHuman && Strength > 0) {
  3371. ScenarioInit++;
  3372. UnitClass * unit = new UnitClass(UNIT_MCV, House->Class->House);
  3373. ScenarioInit--;
  3374. if (unit != NULL) {
  3375. /*
  3376. ** Unlimbo the MCV onto the map. The MCV should start in the same
  3377. ** health condition that the construction yard was in.
  3378. */
  3379. fixed ratio = Health_Ratio();
  3380. int money = Refund_Amount();
  3381. TARGET arch = ArchiveTarget;
  3382. COORDINATE place = Coord_Snap(Adjacent_Cell(Coord, DIR_SE));
  3383. delete this;
  3384. if (unit->Unlimbo(place, DIR_SW)) {
  3385. unit->Strength = (int)unit->Class_Of().MaxStrength * ratio; // Cast to (int). ST - 5/8/2019
  3386. /*
  3387. ** Lift the move destination from the building and assign
  3388. ** it to the unit.
  3389. */
  3390. if (Target_Legal(arch)) {
  3391. unit->Assign_Destination(arch);
  3392. unit->Assign_Mission(MISSION_MOVE);
  3393. }
  3394. mcv_redeployed = true;
  3395. } else {
  3396. /*
  3397. ** If, for some strange reason, the MCV could not be placed on the
  3398. ** map, then give the player some money to compensate.
  3399. */
  3400. House->Refund_Money(money);
  3401. }
  3402. } else {
  3403. House->Refund_Money(Refund_Amount());
  3404. delete this;
  3405. }
  3406. } else {
  3407. /*
  3408. ** Selling off a gap generator will cause the cells it affects
  3409. ** to stop being jammed.
  3410. */
  3411. if (*this == STRUCT_GAP) {
  3412. Remove_Gap_Effect();
  3413. }
  3414. /*
  3415. ** A sold building still counts as a kill, but it just isn't directly
  3416. ** attributed to the enemy.
  3417. */
  3418. WhoLastHurtMe = HOUSE_NONE;
  3419. Record_The_Kill(NULL);
  3420. /*
  3421. ** The player gets part of the money back for the sell.
  3422. */
  3423. House->Refund_Money(Refund_Amount());
  3424. House->Stole(-Refund_Amount());
  3425. Limbo();
  3426. if (House) {
  3427. House->Check_Pertinent_Structures();
  3428. }
  3429. /*
  3430. ** Finally, delete the building from the game.
  3431. */
  3432. delete this;
  3433. }
  3434. // MBL 05.06.2020 - "Structure Sold" was being heard when selecting/moving a redepolyable Con Yard to turn back into an MCV (RA only) above, so moved here
  3435. #if 1
  3436. if (!mcv_redeployed)
  3437. {
  3438. if (IsOwnedByPlayer) {
  3439. if ((HouseClass *)House == PlayerPtr) {
  3440. Speak(VOX_STRUCTURE_SOLD);
  3441. }
  3442. }
  3443. }
  3444. #endif
  3445. }
  3446. break;
  3447. default:
  3448. break;
  3449. }
  3450. return(1);
  3451. }
  3452. /***********************************************************************************************
  3453. * BuildingClass::Mission_Attack -- Handles attack mission for building. *
  3454. * *
  3455. * Buildings that can attack are processed by this attack mission state machine. *
  3456. * *
  3457. * INPUT: none *
  3458. * *
  3459. * OUTPUT: Returns with the number of game frames to delay before calling this routine *
  3460. * again. *
  3461. * *
  3462. * WARNINGS: none *
  3463. * *
  3464. * HISTORY: *
  3465. * 06/25/1995 JLB : Created. *
  3466. * 02/22/1996 JLB : SAM doesn't lower back into ground. *
  3467. *=============================================================================================*/
  3468. int BuildingClass::Mission_Attack(void)
  3469. {
  3470. assert(Buildings.ID(this) == ID);
  3471. assert(IsActive);
  3472. if (*this == STRUCT_SAM) {
  3473. switch (Status) {
  3474. /*
  3475. ** This is the target tracking state of the launcher. It will rotate
  3476. ** to face the current TarCom of the launcher.
  3477. */
  3478. case SAM_READY:
  3479. if ((Class->IsPowered && House->Power_Fraction() < 1) || IsJammed) {
  3480. return(1);
  3481. }
  3482. if (!Target_Legal(TarCom) || !Is_Target_Aircraft(TarCom) || As_Aircraft(TarCom)->Height == 0) {
  3483. Assign_Target(TARGET_NONE);
  3484. Status = SAM_READY;
  3485. Assign_Mission(MISSION_GUARD);
  3486. Commence();
  3487. return(1);
  3488. } else {
  3489. if (!PrimaryFacing.Is_Rotating()) {
  3490. DirType facing = Direction(TarCom);
  3491. if (PrimaryFacing.Difference(facing)) {
  3492. PrimaryFacing.Set_Desired(facing);
  3493. } else {
  3494. Status = SAM_FIRING;
  3495. }
  3496. }
  3497. }
  3498. return(1);
  3499. /*
  3500. ** The launcher is in the process of firing.
  3501. */
  3502. case SAM_FIRING:
  3503. if (!Target_Legal(TarCom) || !Is_Target_Aircraft(TarCom) || As_Aircraft(TarCom)->Height == 0) {
  3504. Assign_Target(TARGET_NONE);
  3505. Status = SAM_READY;
  3506. } else {
  3507. FireErrorType error = Can_Fire(TarCom, 0);
  3508. if (error == FIRE_ILLEGAL || error == FIRE_CANT || error == FIRE_RANGE) {
  3509. Assign_Target(TARGET_NONE);
  3510. Status = SAM_READY;
  3511. } else {
  3512. if (error == FIRE_FACING) {
  3513. Status = SAM_READY;
  3514. } else {
  3515. if (error == FIRE_OK) {
  3516. Fire_At(TarCom, 0);
  3517. Fire_At(TarCom, 1);
  3518. Status = SAM_READY;
  3519. }
  3520. }
  3521. }
  3522. }
  3523. return(1);
  3524. default:
  3525. break;
  3526. }
  3527. return(MissionControl[Mission].AA_Delay() + Random_Pick(0, 2));
  3528. }
  3529. if (!Target_Legal(TarCom)) {
  3530. Assign_Target(TARGET_NONE);
  3531. Assign_Mission(MISSION_GUARD);
  3532. Commence();
  3533. return(1);
  3534. }
  3535. int primary = What_Weapon_Should_I_Use(TarCom);
  3536. IsReadyToCommence = true;
  3537. switch (Can_Fire(TarCom, primary)) {
  3538. case FIRE_ILLEGAL:
  3539. case FIRE_CANT:
  3540. case FIRE_RANGE:
  3541. case FIRE_AMMO:
  3542. Assign_Target(TARGET_NONE);
  3543. Assign_Mission(MISSION_GUARD);
  3544. Commence();
  3545. break;
  3546. case FIRE_FACING:
  3547. PrimaryFacing.Set_Desired(Direction(TarCom));
  3548. return(2);
  3549. case FIRE_REARM:
  3550. PrimaryFacing.Set_Desired(Direction(TarCom));
  3551. return(Arm);
  3552. case FIRE_BUSY:
  3553. return(1);
  3554. case FIRE_CLOAKED:
  3555. Do_Uncloak();
  3556. break;
  3557. case FIRE_OK:
  3558. Fire_At(TarCom, primary);
  3559. return(1);
  3560. default:
  3561. break;
  3562. }
  3563. PrimaryFacing.Set_Desired(Direction(TarCom));
  3564. return(1);
  3565. // return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  3566. }
  3567. /***********************************************************************************************
  3568. * BuildingClass::Mission_Harvest -- Handles refinery unloading harvesters. *
  3569. * *
  3570. * This state machine handles the refinery when it unloads the harvester. *
  3571. * *
  3572. * INPUT: none *
  3573. * *
  3574. * OUTPUT: Returns with the number of game frames to delay before calling this routine *
  3575. * again. *
  3576. * *
  3577. * WARNINGS: none *
  3578. * *
  3579. * HISTORY: *
  3580. * 06/25/1995 JLB : Created. *
  3581. *=============================================================================================*/
  3582. int BuildingClass::Mission_Harvest(void)
  3583. {
  3584. assert(Buildings.ID(this) == ID);
  3585. assert(IsActive);
  3586. enum {
  3587. INITIAL, // Dock the Tiberium cannister.
  3588. WAIT_FOR_DOCK, // Waiting for docking to complete.
  3589. MIDDLE, // Offload "bails" of tiberium.
  3590. WAIT_FOR_UNDOCK // Waiting for undocking to complete.
  3591. };
  3592. switch (Status) {
  3593. case INITIAL:
  3594. Status = WAIT_FOR_DOCK;
  3595. break;
  3596. case WAIT_FOR_DOCK:
  3597. if (IsReadyToCommence) {
  3598. IsReadyToCommence = false;
  3599. Status = MIDDLE;
  3600. }
  3601. break;
  3602. case MIDDLE:
  3603. if (IsReadyToCommence) {
  3604. IsReadyToCommence = false;
  3605. /*
  3606. ** Force any bib squatters to scatter.
  3607. */
  3608. Map[Adjacent_Cell(Coord_Cell(Center_Coord()), DIR_S)].Incoming(0, true, true);
  3609. FootClass * techno = Attached_Object();
  3610. if (techno) {
  3611. int bail = techno->Offload_Tiberium_Bail();
  3612. if (bail) {
  3613. House->Harvested(bail);
  3614. if (techno->Tiberium_Load() > 0) {
  3615. return(1);
  3616. }
  3617. }
  3618. }
  3619. Status = WAIT_FOR_UNDOCK;
  3620. }
  3621. break;
  3622. case WAIT_FOR_UNDOCK:
  3623. if (IsReadyToCommence) {
  3624. /*
  3625. ** Detach harvester and go back into idle state.
  3626. */
  3627. Assign_Mission(MISSION_GUARD);
  3628. }
  3629. break;
  3630. default:
  3631. break;
  3632. }
  3633. return(1);
  3634. }
  3635. /***********************************************************************************************
  3636. * BuildingClass::Mission_Repair -- Handles the repair (active) state for building. *
  3637. * *
  3638. * This state machine is used when the building is active in some sort of repair or *
  3639. * construction mode. The construction yard will animate. The repair facility will repair *
  3640. * anything that it docked on it. *
  3641. * *
  3642. * INPUT: none *
  3643. * *
  3644. * OUTPUT: Returns with the number of game frames to delay before calling this routine again. *
  3645. * *
  3646. * WARNINGS: none *
  3647. * *
  3648. * HISTORY: *
  3649. * 06/25/1995 JLB : Created. *
  3650. * 06/25/1995 JLB : Handles repair facility *
  3651. * 07/29/1995 JLB : Repair rate is controlled by power rating. *
  3652. *=============================================================================================*/
  3653. int BuildingClass::Mission_Repair(void)
  3654. {
  3655. assert(Buildings.ID(this) == ID);
  3656. assert(IsActive);
  3657. if (*this == STRUCT_CONST) {
  3658. enum {
  3659. INITIAL,
  3660. DURING
  3661. };
  3662. switch (Status) {
  3663. case INITIAL:
  3664. Begin_Mode(BSTATE_ACTIVE);
  3665. Status = DURING;
  3666. break;
  3667. case DURING:
  3668. if (!In_Radio_Contact()) {
  3669. Assign_Mission(MISSION_GUARD);
  3670. }
  3671. break;
  3672. default:
  3673. break;
  3674. }
  3675. return(1);
  3676. }
  3677. if (*this == STRUCT_REPAIR) {
  3678. enum {
  3679. INITIAL,
  3680. IDLE,
  3681. DURING
  3682. };
  3683. switch (Status) {
  3684. case INITIAL:
  3685. {
  3686. if (!In_Radio_Contact()) {
  3687. Begin_Mode(BSTATE_IDLE);
  3688. Assign_Mission(MISSION_GUARD);
  3689. return(1);
  3690. }
  3691. IsReadyToCommence = false;
  3692. int distance = 0x10;
  3693. TechnoClass *tech = Contact_With_Whom();
  3694. /*
  3695. ** BG: If the unit to repair is an aircraft, and the aircraft is
  3696. ** fixed-wing, and it's landed, be much more liberal with the
  3697. ** distance check. Fixed-wing aircraft are very inaccurate with
  3698. ** their landings.
  3699. */
  3700. if (tech->What_Am_I() == RTTI_AIRCRAFT) {
  3701. if ( ((AircraftClass *)tech)->Class->IsFixedWing &&
  3702. ((AircraftClass *)tech)->In_Which_Layer() == LAYER_GROUND) {
  3703. distance = 0x80;
  3704. }
  3705. }
  3706. if (Transmit_Message(RADIO_NEED_TO_MOVE) == RADIO_ROGER && Distance(Contact_With_Whom()) < distance) {
  3707. Status = IDLE;
  3708. return(TICKS_PER_SECOND/4);
  3709. }
  3710. break;
  3711. }
  3712. case IDLE:
  3713. if (!In_Radio_Contact()) {
  3714. Assign_Mission(MISSION_GUARD);
  3715. return(1);
  3716. }
  3717. if (Transmit_Message(RADIO_NEED_TO_MOVE) == RADIO_ROGER) {
  3718. TechnoClass * radio = Contact_With_Whom();
  3719. if ( ((radio->Health_Ratio() < Rule.ConditionGreen) ||
  3720. (radio->What_Am_I() == RTTI_UNIT && *(UnitClass *)radio == UNIT_MINELAYER))
  3721. && Transmit_Message(RADIO_REPAIR) == RADIO_ROGER) {
  3722. /*
  3723. ** If the object over the repair bay is marked as useless, then
  3724. ** sell it back to get some money.
  3725. */
  3726. if (radio->IsUseless) {
  3727. if (!radio->House->IsHuman) {
  3728. radio->Sell_Back(1);
  3729. }
  3730. Status = INITIAL;
  3731. IsReadyToCommence = true;
  3732. } else {
  3733. //
  3734. // MBL 04.27.2020: Legacy VOX_REPAIRING seems to be never called in TD, but only in RA.
  3735. // It is currently supported as a client GUI event when standard repairing begins, with "REPAIR1" on both TD and RA
  3736. //
  3737. // This repairing is in reference to the repair bay
  3738. // There is a newer bug (https://jaas.ea.com/browse/TDRA-6224) reporting that it is heard in multiplayer by
  3739. // other players, from this call, so modifiying the original call here:
  3740. //
  3741. // if (IsOwnedByPlayer) Speak(VOX_REPAIRING);
  3742. if (IsOwnedByPlayer) Speak(VOX_REPAIRING, House);
  3743. Status = DURING;
  3744. Begin_Mode(BSTATE_ACTIVE);
  3745. IsReadyToCommence = false;
  3746. }
  3747. } else {
  3748. // Transmit_Message(RADIO_RUN_AWAY);
  3749. ///*BG*/ if(radio->Health_Ratio() >= Rule.ConditionGreen) {
  3750. // Transmit_Message(RADIO_RUN_AWAY);
  3751. // }
  3752. }
  3753. }
  3754. break;
  3755. case DURING:
  3756. if (!In_Radio_Contact()) {
  3757. Begin_Mode(BSTATE_IDLE);
  3758. Status = IDLE;
  3759. return(1);
  3760. }
  3761. /*
  3762. ** Check to see if the repair light blink has completed and the attached
  3763. ** unit is not doing something else. If these conditions are favorable,
  3764. ** the repair can proceed another step.
  3765. */
  3766. if (IsReadyToCommence && Transmit_Message(RADIO_NEED_TO_MOVE) == RADIO_ROGER) {
  3767. IsReadyToCommence = false;
  3768. /*
  3769. ** Tell the attached unit to repair one step. It will respond with how
  3770. ** it fared.
  3771. */
  3772. switch (Transmit_Message(RADIO_REPAIR)) {
  3773. /*
  3774. ** The repair step proceeded smoothly. Proceed normally with the
  3775. ** repair process.
  3776. */
  3777. case RADIO_ROGER:
  3778. break;
  3779. /*
  3780. ** The repair operation was aborted because of some reason. Presume
  3781. ** that the reason is because of low cash.
  3782. */
  3783. case RADIO_CANT:
  3784. if (IsOwnedByPlayer) Speak(VOX_NO_CASH);
  3785. Begin_Mode(BSTATE_IDLE);
  3786. Status = IDLE;
  3787. break;
  3788. /*
  3789. ** The repair step resulted in a completely repaired unit.
  3790. */
  3791. case RADIO_ALL_DONE:
  3792. // MBL 04.27.2020: Make only audible to the correct player
  3793. // if (IsOwnedByPlayer) Speak(VOX_UNIT_REPAIRED);
  3794. if (IsOwnedByPlayer) Speak(VOX_UNIT_REPAIRED, House);
  3795. // Transmit_Message(RADIO_RUN_AWAY);
  3796. Begin_Mode(BSTATE_IDLE);
  3797. Status = IDLE;
  3798. break;
  3799. /*
  3800. ** The repair step could not be completed because this unit is already
  3801. ** at full strength.
  3802. */
  3803. case RADIO_NEGATIVE:
  3804. default:
  3805. // Transmit_Message(RADIO_RUN_AWAY);
  3806. Begin_Mode(BSTATE_IDLE);
  3807. Status = IDLE;
  3808. break;
  3809. }
  3810. }
  3811. return(1);
  3812. default:
  3813. break;
  3814. }
  3815. return(MissionControl[Mission].Normal_Delay());
  3816. }
  3817. if (*this == STRUCT_HELIPAD || *this == STRUCT_AIRSTRIP) {
  3818. enum {
  3819. INITIAL,
  3820. DURING
  3821. };
  3822. switch (Status) {
  3823. case INITIAL:
  3824. if (Transmit_Message(RADIO_NEED_TO_MOVE) == RADIO_ROGER && Transmit_Message(RADIO_PREPARED) == RADIO_NEGATIVE) {
  3825. Begin_Mode(BSTATE_ACTIVE);
  3826. Contact_With_Whom()->Assign_Mission(MISSION_SLEEP);
  3827. Status = DURING;
  3828. return(1);
  3829. }
  3830. Assign_Mission(MISSION_GUARD);
  3831. break;
  3832. case DURING:
  3833. if (IsReadyToCommence) {
  3834. if (!In_Radio_Contact() || Transmit_Message(RADIO_NEED_TO_MOVE) == RADIO_NEGATIVE) {
  3835. Assign_Mission(MISSION_GUARD);
  3836. return(1);
  3837. }
  3838. if (Transmit_Message(RADIO_PREPARED) == RADIO_ROGER) {
  3839. Contact_With_Whom()->Assign_Mission(MISSION_GUARD);
  3840. Assign_Mission(MISSION_GUARD);
  3841. return(1);
  3842. }
  3843. if (Transmit_Message(RADIO_RELOAD) != RADIO_ROGER) {
  3844. Assign_Mission(MISSION_GUARD);
  3845. Contact_With_Whom()->Assign_Mission(MISSION_GUARD);
  3846. return(1);
  3847. } else {
  3848. fixed pfrac = Saturate(House->Power_Fraction(), 1);
  3849. if (pfrac < fixed::_1_2) pfrac = fixed::_1_2;
  3850. int time = Inverse(pfrac) * Rule.ReloadRate * TICKS_PER_MINUTE;
  3851. // int time = Bound((int)(TICKS_PER_SECOND * Saturate(House->Power_Fraction(), 1)), 0, TICKS_PER_SECOND);
  3852. // time = (TICKS_PER_SECOND*3) - time;
  3853. IsReadyToCommence = false;
  3854. return(time);
  3855. }
  3856. }
  3857. break;
  3858. default:
  3859. break;
  3860. }
  3861. return(3);
  3862. }
  3863. return(TICKS_PER_SECOND);
  3864. }
  3865. /***********************************************************************************************
  3866. * BuildingClass::Mission_Missile -- State machine for nuclear missile launch. *
  3867. * *
  3868. * This handles the Temple of Nod launching its nuclear missile. *
  3869. * *
  3870. * INPUT: none *
  3871. * *
  3872. * OUTPUT: Returns with the number of frames to delay before calling this routine again. *
  3873. * *
  3874. * WARNINGS: none *
  3875. * *
  3876. * HISTORY: *
  3877. * 07/04/1995 JLB : Commented. *
  3878. *=============================================================================================*/
  3879. int BuildingClass::Mission_Missile(void)
  3880. {
  3881. assert(Buildings.ID(this) == ID);
  3882. assert(IsActive);
  3883. if (*this == STRUCT_ADVANCED_TECH) {
  3884. enum {
  3885. DOOR_OPENING,
  3886. LAUNCH_UP,
  3887. SATELLITE_DEPLOY,
  3888. DONE_LAUNCH
  3889. };
  3890. switch (Status) {
  3891. /*
  3892. ** The initial case is responsible for starting the door
  3893. ** opening on the building, the missile rising, and smoke broiling.
  3894. */
  3895. case DOOR_OPENING:
  3896. {
  3897. #ifdef FIXIT_VERSION_3
  3898. COORDINATE door = Coord_Move(Center_Coord(), (DirType)0xC0, 0x30);
  3899. AnimClass * sput = new AnimClass(ANIM_SPUTDOOR, door);
  3900. if (sput) {
  3901. IsReadyToCommence = false;
  3902. Status = LAUNCH_UP;
  3903. AnimToTrack = sput->As_Target();
  3904. }
  3905. #else
  3906. IsReadyToCommence = false;
  3907. COORDINATE door = Coord_Move(Center_Coord(), (DirType)0xC0, 0x30);
  3908. AnimClass * sput = new AnimClass(ANIM_SPUTDOOR, door);
  3909. Status = LAUNCH_UP;
  3910. AnimToTrack = sput->As_Target();
  3911. return(1);
  3912. #endif
  3913. }
  3914. /*
  3915. ** Once the smoke has been going for a little while this
  3916. ** actually handles launching the missile into the air.
  3917. */
  3918. case LAUNCH_UP:
  3919. {
  3920. AnimClass * sput = As_Animation(AnimToTrack);
  3921. if (sput) {
  3922. if (sput->Fetch_Stage() >= 19) {
  3923. CELL center = Coord_Cell(Center_Coord());
  3924. CELL cell = XY_Cell( Cell_X(center), 1);
  3925. TARGET targ = ::As_Target(cell);
  3926. BulletClass * bullet = new BulletClass(BULLET_GPS_SATELLITE, targ, this, 200, WARHEAD_FIRE, MPH_ROCKET);
  3927. if (bullet) {
  3928. COORDINATE launch = Coord_Move(Center_Coord(), (DirType)0xC0, 0x30);
  3929. if (!bullet->Unlimbo(launch, DIR_N)) {
  3930. delete bullet;
  3931. bullet = NULL;
  3932. }
  3933. }
  3934. if (bullet) {
  3935. Assign_Mission(MISSION_GUARD);
  3936. }
  3937. }
  3938. }
  3939. }
  3940. return(1);
  3941. }
  3942. }
  3943. if (*this == STRUCT_MSLO) {
  3944. enum {
  3945. INITIAL,
  3946. DOOR_OPENING,
  3947. LAUNCH_UP,
  3948. LAUNCH_DOWN,
  3949. DONE_LAUNCH
  3950. };
  3951. switch (Status) {
  3952. /*
  3953. ** The initial case is responsible for starting the door
  3954. ** opening on the building.
  3955. */
  3956. case INITIAL:
  3957. IsReadyToCommence = false;
  3958. Begin_Mode(BSTATE_ACTIVE); // open the door
  3959. Status = DOOR_OPENING;
  3960. return(1);
  3961. /*
  3962. ** This polls for the case when the door is actually open and
  3963. ** then kicks off the missile smoke.
  3964. */
  3965. case DOOR_OPENING:
  3966. if (IsReadyToCommence) {
  3967. Begin_Mode(BSTATE_AUX1); // hold the door open
  3968. Status = LAUNCH_UP;
  3969. return(14);
  3970. }
  3971. return(1);
  3972. /*
  3973. ** Once the smoke has been going for a little while this
  3974. ** actually handles launching the missile into the air.
  3975. */
  3976. case LAUNCH_UP:
  3977. {
  3978. CELL center = Coord_Cell(Center_Coord());
  3979. CELL cell = XY_Cell( Cell_X(center), 1);
  3980. TARGET targ = ::As_Target(cell);
  3981. BulletClass * bullet = new BulletClass(BULLET_NUKE_UP, targ, this, 200, WARHEAD_HE, MPH_VERY_FAST);
  3982. if (bullet) {
  3983. COORDINATE launch = Coord_Move(Center_Coord(), (DirType)28, 0xA0);
  3984. if (!bullet->Unlimbo(launch, DIR_N)) {
  3985. delete bullet;
  3986. bullet = NULL;
  3987. }
  3988. }
  3989. if (bullet) {
  3990. Speak(VOX_ABOMB_LAUNCH);
  3991. Status = LAUNCH_DOWN;
  3992. /*
  3993. ** Hack: If it's the artificial nukes, don't let the bullets come down (as
  3994. ** they're the only ones that blow up). We know it's artificial if you're
  3995. ** at tech level 10 or below, because you can't build the nuclear silo until
  3996. ** tech level 15 or so.
  3997. */
  3998. if (House->Control.TechLevel <= 10) {
  3999. return(6);
  4000. }
  4001. bullet = new BulletClass(BULLET_NUKE_DOWN, ::As_Target(House->NukeDest), this, 200, WARHEAD_NUKE, MPH_VERY_FAST);
  4002. if (bullet) {
  4003. int celly = Cell_Y(House->NukeDest);
  4004. celly -= 64;
  4005. if (celly < 1) celly = 1;
  4006. COORDINATE start = Cell_Coord(XY_Cell(Cell_X(House->NukeDest), celly));
  4007. if (!bullet->Unlimbo(start, DIR_S)) {
  4008. delete bullet;
  4009. }
  4010. }
  4011. return(8 * TICKS_PER_SECOND);
  4012. }
  4013. }
  4014. return(1);
  4015. /*
  4016. ** Once the missile is in the air, this handles waiting for
  4017. ** the missile to be off the screen and then launching one down
  4018. ** over the target.
  4019. */
  4020. case LAUNCH_DOWN:
  4021. {
  4022. Begin_Mode(BSTATE_AUX2); // start the door closing
  4023. #ifdef OBSOLETE
  4024. /*
  4025. ** Hack: If it's the artificial nukes, don't let the bullets come down (as
  4026. ** they're the only ones that blow up). We know it's artificial if you're
  4027. ** at tech level 10 or below, because you can't build the nuclear silo until
  4028. ** tech level 15 or so.
  4029. */
  4030. if (House->Control.TechLevel <= 10) {
  4031. Status = DONE_LAUNCH;
  4032. return(6);
  4033. }
  4034. BulletClass * bullet = new BulletClass(BULLET_NUKE_DOWN, ::As_Target(House->NukeDest), this, 200, WARHEAD_NUKE, MPH_VERY_FAST);
  4035. if (bullet) {
  4036. int celly = Cell_Y(House->NukeDest);
  4037. celly -= 15;
  4038. if (celly < 1) celly = 1;
  4039. COORDINATE start = Cell_Coord(XY_Cell(Cell_X(House->NukeDest), celly));
  4040. if (!bullet->Unlimbo(start, DIR_S)) {
  4041. delete bullet;
  4042. }
  4043. }
  4044. if (bullet) {
  4045. #endif
  4046. Status = DONE_LAUNCH;
  4047. return(6);
  4048. }
  4049. #ifdef OBSOLETE
  4050. }
  4051. return(1);
  4052. #endif
  4053. /*
  4054. ** Once the missile is done launching this handles allowing
  4055. ** the building to sit there with its door closed.
  4056. */
  4057. case DONE_LAUNCH:
  4058. Begin_Mode(BSTATE_IDLE); // keep the door closed.
  4059. Assign_Mission(MISSION_GUARD);
  4060. return(60);
  4061. }
  4062. }
  4063. return(MissionControl[Mission].Normal_Delay());
  4064. }
  4065. /***********************************************************************************************
  4066. * BuildingClass::Revealed -- Reveals the building to the specified house. *
  4067. * *
  4068. * This routine will reveal the building to the specified house. It will handle updating *
  4069. * the sidebar for player owned buildings. A player owned building that hasn't been *
  4070. * revealed, is in a state of pseudo-limbo. It cannot be used for any of its special *
  4071. * abilities even though it exists on the map for all other purposes. *
  4072. * *
  4073. * INPUT: house -- The house that this building is being revealed to. *
  4074. * *
  4075. * OUTPUT: Was this building revealed by this procedure? *
  4076. * *
  4077. * WARNINGS: none *
  4078. * *
  4079. * HISTORY: *
  4080. * 06/25/1995 JLB : Created. *
  4081. *=============================================================================================*/
  4082. bool BuildingClass::Revealed(HouseClass * house)
  4083. {
  4084. assert(Buildings.ID(this) == ID);
  4085. assert(IsActive);
  4086. if (TechnoClass::Revealed(house)) {
  4087. if (!ScenarioInit) {
  4088. House->JustBuiltStructure = Class->Type;
  4089. House->IsBuiltSomething = true;
  4090. }
  4091. House->IsRecalcNeeded = true;
  4092. /*
  4093. ** Perform any grand opening here so that in the scenarios where a player
  4094. ** owned house is not yet revealed, it won't be reflected in the sidebar
  4095. ** selection icons.
  4096. */
  4097. if (!In_Radio_Contact() && House->IsHuman && Mission != MISSION_CONSTRUCTION) {
  4098. Grand_Opening();
  4099. } else {
  4100. if (!In_Radio_Contact() && !House->IsHuman && house == House && Mission != MISSION_CONSTRUCTION) {
  4101. Grand_Opening();
  4102. }
  4103. }
  4104. return(true);
  4105. }
  4106. return(false);
  4107. }
  4108. /***********************************************************************************************
  4109. * BuildingClass::Enter_Idle_Mode -- The building will enter its idle mode. *
  4110. * *
  4111. * This routine is called when the exact mode of the building isn't known. By examining *
  4112. * the building's condition, this routine will assign an appropriate mission. *
  4113. * *
  4114. * INPUT: initial -- This this being called during scenario init? *
  4115. * *
  4116. * OUTPUT: none *
  4117. * *
  4118. * WARNINGS: none *
  4119. * *
  4120. * HISTORY: *
  4121. * 06/25/1995 JLB : Created. *
  4122. *=============================================================================================*/
  4123. void BuildingClass::Enter_Idle_Mode(bool initial)
  4124. {
  4125. assert(Buildings.ID(this) == ID);
  4126. assert(IsActive);
  4127. /*
  4128. ** Assign an appropriate mission for the building. If the ScenarioInit flag is true, then
  4129. ** this must be an initial building. Start such buildings in idle state. For other buildings
  4130. ** it indicates that it is being placed during game play and thus it must start in
  4131. ** the "construction" mission.
  4132. */
  4133. MissionType mission = MISSION_GUARD;
  4134. if (!initial || ScenarioInit || Debug_Map) {
  4135. Begin_Mode(BSTATE_IDLE);
  4136. mission = MISSION_GUARD;
  4137. } else {
  4138. Begin_Mode(BSTATE_CONSTRUCTION);
  4139. mission = MISSION_CONSTRUCTION;
  4140. }
  4141. Assign_Mission(mission);
  4142. }
  4143. /***********************************************************************************************
  4144. * BuildingClass::Pip_Count -- Determines "full" pips to display for building. *
  4145. * *
  4146. * This routine will determine the number of pips that should be filled in when rendering *
  4147. * the building. *
  4148. * *
  4149. * INPUT: none *
  4150. * *
  4151. * OUTPUT: Returns the number of pips to display as filled in. *
  4152. * *
  4153. * WARNINGS: none *
  4154. * *
  4155. * HISTORY: *
  4156. * 06/28/1995 JLB : Created. *
  4157. *=============================================================================================*/
  4158. int BuildingClass::Pip_Count(void) const
  4159. {
  4160. assert(Buildings.ID(this) == ID);
  4161. assert(IsActive);
  4162. return(Class->Max_Pips() * House->Tiberium_Fraction());
  4163. }
  4164. /***********************************************************************************************
  4165. * BuildingClass::Death_Announcement -- Announce the death of this building. *
  4166. * *
  4167. * This routine is called when the building is destroyed by "unnatural" means. Typically *
  4168. * as a result of combat. If the building is known to the player, then it should be *
  4169. * announced. *
  4170. * *
  4171. * INPUT: source -- The object most directly responsible for the building's death. *
  4172. * *
  4173. * OUTPUT: none *
  4174. * *
  4175. * WARNINGS: none *
  4176. * *
  4177. * HISTORY: *
  4178. * 07/04/1995 JLB : Created. *
  4179. *=============================================================================================*/
  4180. void BuildingClass::Death_Announcement(TechnoClass const * source) const
  4181. {
  4182. assert(Buildings.ID(this) == ID);
  4183. assert(IsActive);
  4184. if (source != NULL && House->IsPlayerControl) {
  4185. Speak(VOX_STRUCTURE_DESTROYED);
  4186. }
  4187. }
  4188. /***********************************************************************************************
  4189. * BuildingClass::Fire_Direction -- Fetches the direction of firing. *
  4190. * *
  4191. * This routine will return with the default direction to use when firing from this *
  4192. * building. This is the facing of the turret except for the case of non-turret equipped *
  4193. * buildings that have a weapon (e.g., guard tower). *
  4194. * *
  4195. * INPUT: none *
  4196. * *
  4197. * OUTPUT: Returns with the default firing direction for this building. *
  4198. * *
  4199. * WARNINGS: none *
  4200. * *
  4201. * HISTORY: *
  4202. * 07/04/1995 JLB : Created. *
  4203. *=============================================================================================*/
  4204. DirType BuildingClass::Fire_Direction(void) const
  4205. {
  4206. assert(Buildings.ID(this) == ID);
  4207. assert(IsActive);
  4208. if (Class->IsTurretEquipped) {
  4209. return(PrimaryFacing.Current());
  4210. }
  4211. return(Direction(TarCom));
  4212. }
  4213. /***********************************************************************************************
  4214. * BuildingClass::Remap_Table -- Fetches the remap table to use for this building. *
  4215. * *
  4216. * Use this routine to fetch the remap table to use. This override function is needed *
  4217. * because the default remap table for techno objects presumes the object is a unit. *
  4218. * Buildings aren't units. *
  4219. * *
  4220. * INPUT: none *
  4221. * *
  4222. * OUTPUT: Returns with the proper remap table to use for this building. *
  4223. * *
  4224. * WARNINGS: none *
  4225. * *
  4226. * HISTORY: *
  4227. * 07/08/1995 JLB : Created. *
  4228. *=============================================================================================*/
  4229. void const * BuildingClass::Remap_Table(void)
  4230. {
  4231. assert(Buildings.ID(this) == ID);
  4232. assert(IsActive);
  4233. return(House->Remap_Table(IsBlushing, Class->Remap));
  4234. }
  4235. /***********************************************************************************************
  4236. * BuildingClass::Mission_Unload -- Handles the unload mission for a building. *
  4237. * *
  4238. * This is the unload mission for a building. This really only applies to the weapon's *
  4239. * factory, since it needs the sophistication of an unload mission due to the door *
  4240. * animation. *
  4241. * *
  4242. * INPUT: none *
  4243. * *
  4244. * OUTPUT: Returns with the number of game frames to delay before calling this routine *
  4245. * again. *
  4246. * *
  4247. * WARNINGS: none *
  4248. * *
  4249. * HISTORY: *
  4250. * 07/29/1995 JLB : Created. *
  4251. *=============================================================================================*/
  4252. int BuildingClass::Mission_Unload(void)
  4253. {
  4254. assert(Buildings.ID(this) == ID);
  4255. assert(IsActive);
  4256. if (*this == STRUCT_WEAP) {
  4257. CELL cell = Coord_Cell(Coord) + Class->ExitList[0];
  4258. COORDINATE coord = Cell_Coord(cell);
  4259. CellClass * cellptr = &Map[cell];
  4260. enum {
  4261. INITIAL,
  4262. CLEAR_BIB,
  4263. OPEN,
  4264. LEAVE,
  4265. CLOSE
  4266. };
  4267. enum {
  4268. DOOR_STAGES = 5,
  4269. DOOR_RATE = 8
  4270. };
  4271. UnitClass * unit;
  4272. switch (Status) {
  4273. /*
  4274. ** Start the door opening.
  4275. */
  4276. case INITIAL:
  4277. // if (cellptr->Cell_Techno()) {
  4278. // cellptr->Incoming(0, true);
  4279. // }
  4280. unit = (UnitClass *)Contact_With_Whom();
  4281. if (unit) {
  4282. unit->Assign_Mission(MISSION_GUARD);
  4283. unit->Commence();
  4284. }
  4285. Open_Door(DOOR_RATE, DOOR_STAGES);
  4286. Status = CLEAR_BIB;
  4287. break;
  4288. /*
  4289. ** Now that the occupants can peek out the door, they will tell
  4290. ** everyone that could be blocking the way, that they should
  4291. ** scatter away.
  4292. */
  4293. case CLEAR_BIB:
  4294. if (cellptr->Cell_Techno()) {
  4295. cellptr->Incoming(0, true, true);
  4296. /*
  4297. ** Scatter everything around the weapon's factory door.
  4298. */
  4299. for (FacingType f = FACING_FIRST; f < FACING_COUNT; f++) {
  4300. CellClass * cptr = cellptr->Adjacent_Cell(f);
  4301. if (cptr && cptr->Cell_Building() == NULL) {
  4302. cptr->Incoming(coord, true, true);
  4303. }
  4304. }
  4305. } else {
  4306. Status = OPEN;
  4307. }
  4308. break;
  4309. /*
  4310. ** When the door is finally open and the way is clear, tell the
  4311. ** unit to drive out.
  4312. */
  4313. case OPEN:
  4314. if (Is_Door_Open()) {
  4315. unit = (UnitClass *)Contact_With_Whom();
  4316. if (unit) {
  4317. unit->Assign_Mission(MISSION_MOVE);
  4318. if (House->IQ >= Rule.IQGuardArea) {
  4319. unit->Assign_Mission(MISSION_GUARD_AREA);
  4320. unit->ArchiveTarget = ::As_Target(House->Where_To_Go(unit));
  4321. }
  4322. unit->Force_Track(DriveClass::OUT_OF_WEAPON_FACTORY, coord);
  4323. // unit->Force_Track(DriveClass::OUT_OF_WEAPON_FACTORY, Adjacent_Cell(Adjacent_Cell(Center_Coord(), FACING_S), FACING_S));
  4324. unit->Set_Speed(128);
  4325. Status = LEAVE;
  4326. } else {
  4327. Close_Door(DOOR_RATE, DOOR_STAGES);
  4328. Status = CLOSE;
  4329. }
  4330. }
  4331. break;
  4332. /*
  4333. ** Wait until the unit has completely left the building.
  4334. */
  4335. case LEAVE:
  4336. if (!IsTethered) {
  4337. Close_Door(DOOR_RATE, DOOR_STAGES);
  4338. Status = CLOSE;
  4339. } else {
  4340. // if (In_Radio_Contact() && !((FootClass *)Contact_With_Whom())->IsDriving) {
  4341. // Transmit_Message(RADIO_OVER_OUT);
  4342. // }
  4343. }
  4344. break;
  4345. /*
  4346. ** Wait while the door closes.
  4347. */
  4348. case CLOSE:
  4349. if (Is_Door_Closed()) {
  4350. Enter_Idle_Mode();
  4351. }
  4352. break;
  4353. default:
  4354. break;
  4355. }
  4356. return(MissionControl[Mission].Normal_Delay() + Random_Pick(0, 2));
  4357. }
  4358. Assign_Mission(MISSION_GUARD);
  4359. return(1);
  4360. }
  4361. /***********************************************************************************************
  4362. * BuildingClass::Power_Output -- Fetches the current power output from this building. *
  4363. * *
  4364. * This routine will return the current power output for this building. The power output *
  4365. * is adjusted according to the damage level of the building. *
  4366. * *
  4367. * INPUT: none *
  4368. * *
  4369. * OUTPUT: Returns the current power output for this building. *
  4370. * *
  4371. * WARNINGS: none *
  4372. * *
  4373. * HISTORY: *
  4374. * 07/29/1995 JLB : Created. *
  4375. *=============================================================================================*/
  4376. int BuildingClass::Power_Output(void) const
  4377. {
  4378. assert(Buildings.ID(this) == ID);
  4379. assert(IsActive);
  4380. if (Class->Power) {
  4381. return(Class->Power * fixed(LastStrength, Class->MaxStrength));
  4382. }
  4383. return(0);
  4384. }
  4385. /***********************************************************************************************
  4386. * BuildingClass::Detach -- Handles target removal from the game system. *
  4387. * *
  4388. * This routine is called when the specified target is about to be removed from the game *
  4389. * system. *
  4390. * *
  4391. * INPUT: target -- The target to be removed from this building's targeting computer. *
  4392. * *
  4393. * all -- Is the target about to be completely eliminated? *
  4394. * *
  4395. * OUTPUT: none *
  4396. * *
  4397. * WARNINGS: none *
  4398. * *
  4399. * HISTORY: *
  4400. * 07/29/1995 JLB : Created. *
  4401. *=============================================================================================*/
  4402. void BuildingClass::Detach(TARGET target, bool all)
  4403. {
  4404. assert(Buildings.ID(this) == ID);
  4405. assert(IsActive);
  4406. TechnoClass::Detach(target, all);
  4407. if (target == WhomToRepay) {
  4408. WhomToRepay = TARGET_NONE;
  4409. }
  4410. if (target == AnimToTrack) {
  4411. AnimToTrack = TARGET_NONE;
  4412. }
  4413. }
  4414. /***********************************************************************************************
  4415. * BuildingClass::Crew_Type -- This determines the crew that this object generates. *
  4416. * *
  4417. * When selling very cheap buildings (such as the silo), a technician will pop out since *
  4418. * generating minigunners would be overkill -- the player could use this loophole to *
  4419. * gain an advantage. *
  4420. * *
  4421. * INPUT: none *
  4422. * *
  4423. * OUTPUT: Returns the infantry type that this building will generate as a survivor. *
  4424. * *
  4425. * WARNINGS: none *
  4426. * *
  4427. * HISTORY: *
  4428. * 08/05/1995 JLB : Created. *
  4429. *=============================================================================================*/
  4430. InfantryType BuildingClass::Crew_Type(void) const
  4431. {
  4432. assert(Buildings.ID(this) == ID);
  4433. assert(IsActive);
  4434. switch (Class->Type) {
  4435. case STRUCT_STORAGE:
  4436. if (Percent_Chance(50)) {
  4437. return(INFANTRY_C1);
  4438. } else {
  4439. return(INFANTRY_C7);
  4440. }
  4441. case STRUCT_CONST:
  4442. if (!IsCaptured && House->IsHuman && Percent_Chance(25)) {
  4443. return(INFANTRY_RENOVATOR);
  4444. }
  4445. break;
  4446. case STRUCT_KENNEL:
  4447. if (Percent_Chance(50)) {
  4448. return(INFANTRY_DOG);
  4449. } else {
  4450. return(INFANTRY_NONE);
  4451. }
  4452. case STRUCT_TENT:
  4453. case STRUCT_BARRACKS:
  4454. return(INFANTRY_E1);
  4455. default:
  4456. break;
  4457. }
  4458. return(TechnoClass::Crew_Type());
  4459. }
  4460. /***********************************************************************************************
  4461. * BuildingClass::Detach_All -- Possibly abandons production according to factory type. *
  4462. * *
  4463. * When this routine is called, it indicates that the building is about to be destroyed *
  4464. * or captured. In such a case any production it may be doing, must be abandoned. *
  4465. * *
  4466. * INPUT: all -- Is the object about the be completely destroyed? *
  4467. * *
  4468. * OUTPUT: none *
  4469. * *
  4470. * WARNINGS: none *
  4471. * *
  4472. * HISTORY: *
  4473. * 08/05/1995 JLB : Created. *
  4474. *=============================================================================================*/
  4475. void BuildingClass::Detach_All(bool all)
  4476. {
  4477. assert(Buildings.ID(this) == ID);
  4478. assert(IsActive);
  4479. /*
  4480. ** If it is producing something, then it must be abandoned.
  4481. */
  4482. if (Factory) {
  4483. Factory->Abandon();
  4484. delete (FactoryClass *)Factory;
  4485. Factory = 0;
  4486. }
  4487. /*
  4488. ** If the owner HouseClass is building something, and this building can
  4489. ** build that thing, we may be the last building for that house that can
  4490. ** build that thing; if so, abandon production of it.
  4491. */
  4492. if (House) {
  4493. FactoryClass * factory = House->Fetch_Factory(Class->ToBuild);
  4494. /*
  4495. ** If a factory was found, then temporarily disable this building and then
  4496. ** determine if any object that is being produced can still be produced. If
  4497. ** not, then the object being produced must be abandoned.
  4498. */
  4499. if (factory) {
  4500. TechnoClass * object = factory->Get_Object();
  4501. IsInLimbo = true;
  4502. if (object && !object->Techno_Type_Class()->Who_Can_Build_Me(true, false, House->Class->House)) {
  4503. House->Abandon_Production(Class->ToBuild);
  4504. }
  4505. IsInLimbo = false;
  4506. }
  4507. }
  4508. TechnoClass::Detach_All(all);
  4509. }
  4510. /***********************************************************************************************
  4511. * BuildingClass::Flush_For_Placement -- Handles clearing a zone for object placement. *
  4512. * *
  4513. * This routine is used to clear the way for placement of the specified object (usually *
  4514. * a building). If there are friendly units blocking the placement area, they are told *
  4515. * to scatter. Enemy blocking units are attacked. *
  4516. * *
  4517. * INPUT: techno -- Pointer to the object that is desired to be placed. *
  4518. * *
  4519. * cell -- The cell that placement wants to occur at. *
  4520. * *
  4521. * OUTPUT: none *
  4522. * *
  4523. * WARNINGS: none *
  4524. * *
  4525. * HISTORY: *
  4526. * 08/06/1995 JLB : Created. *
  4527. * 09/27/1995 JLB : Revised to use type class function. *
  4528. *=============================================================================================*/
  4529. bool BuildingClass::Flush_For_Placement(TechnoClass * techno, CELL cell)
  4530. {
  4531. assert(Buildings.ID(this) == ID);
  4532. assert(IsActive);
  4533. if (techno) {
  4534. return (((BuildingTypeClass const &)techno->Class_Of()).Flush_For_Placement(cell, House));
  4535. }
  4536. return(false);
  4537. }
  4538. /***********************************************************************************************
  4539. * BuildingClass::Find_Exit_Cell -- Find a clear location to exit an object from this building *
  4540. * *
  4541. * This routine is called when the building needs to discharge a unit. It will find a *
  4542. * nearby (adjacent) cell that is clear enough for the specified object to enter. Typical *
  4543. * use of this routine is when the airfield disgorges its cargo. *
  4544. * *
  4545. * INPUT: techno -- Pointer to the object that wishes to exit this building. *
  4546. * *
  4547. * OUTPUT: Returns with the cell number to use for object placement. If no free location *
  4548. * could be found, then zero (0) is returned. *
  4549. * *
  4550. * WARNINGS: none *
  4551. * *
  4552. * HISTORY: *
  4553. * 09/21/1995 JLB : Created. *
  4554. * 02/20/1996 JLB : Added default case for exit cell calculation. *
  4555. *=============================================================================================*/
  4556. CELL BuildingClass::Find_Exit_Cell(TechnoClass const * techno) const
  4557. {
  4558. assert(Buildings.ID(this) == ID);
  4559. assert(IsActive);
  4560. CELL const * ptr;
  4561. CELL origin = Coord_Cell(Coord);
  4562. ptr = Class->ExitList;
  4563. if (ptr != NULL) {
  4564. while (*ptr != REFRESH_EOL) {
  4565. CELL cell = origin + *ptr++;
  4566. if (Map.In_Radar(cell) && techno->Can_Enter_Cell(cell) == MOVE_OK) {
  4567. return(cell);
  4568. }
  4569. }
  4570. } else {
  4571. int x1, x2;
  4572. int y1, y2;
  4573. CELL cell;
  4574. y1 = -1;
  4575. y2 = Class->Height();
  4576. for (x1 = -1; x1 <= Class->Width(); x1++) {
  4577. cell = origin + x1 + (y1 * MAP_CELL_W);
  4578. if (Map.In_Radar(cell) && techno->Can_Enter_Cell(cell) == MOVE_OK) {
  4579. return(cell);
  4580. }
  4581. cell = origin + x1 + (y2 * MAP_CELL_W);
  4582. if (Map.In_Radar(cell) && techno->Can_Enter_Cell(cell) == MOVE_OK) {
  4583. return(cell);
  4584. }
  4585. }
  4586. x1 = -1;
  4587. x2 = Class->Width();
  4588. for (y1 = -1; y1 <= Class->Height(); y1++) {
  4589. cell = origin + (y1 * MAP_CELL_W) + x1;
  4590. if (Map.In_Radar(cell) && techno->Can_Enter_Cell(cell) == MOVE_OK) {
  4591. return(cell);
  4592. }
  4593. cell = origin + (y1 * MAP_CELL_W) + x2;
  4594. if (Map.In_Radar(cell) && techno->Can_Enter_Cell(cell) == MOVE_OK) {
  4595. return(cell);
  4596. }
  4597. }
  4598. }
  4599. return(0);
  4600. }
  4601. /***********************************************************************************************
  4602. * BuildingClass::Can_Player_Move -- Can this building be moved? *
  4603. * *
  4604. * This routine answers the question 'can this building be moved?' Typically, only the *
  4605. * construction yard can be moved and it does this by undeploying back into a MCV. *
  4606. * *
  4607. * INPUT: none *
  4608. * *
  4609. * OUTPUT: Can the building move to a new location under player control? *
  4610. * *
  4611. * WARNINGS: none *
  4612. * *
  4613. * HISTORY: *
  4614. * 10/04/1995 JLB : Created. *
  4615. *=============================================================================================*/
  4616. bool BuildingClass::Can_Player_Move(void) const
  4617. {
  4618. assert(Buildings.ID(this) == ID);
  4619. assert(IsActive);
  4620. return(*this == STRUCT_CONST && (Mission == MISSION_GUARD) && Special.IsMCVDeploy);
  4621. }
  4622. /***********************************************************************************************
  4623. * BuildingClass::Exit_Coord -- Determines location where object will leave it. *
  4624. * *
  4625. * This routine will return the coordinate where an object that wishes to leave the *
  4626. * building will exit at. *
  4627. * *
  4628. * INPUT: none *
  4629. * *
  4630. * OUTPUT: Returns with the coordinate that the object should be created at. *
  4631. * *
  4632. * WARNINGS: none *
  4633. * *
  4634. * HISTORY: *
  4635. * 02/20/1996 JLB : Created. *
  4636. *=============================================================================================*/
  4637. COORDINATE BuildingClass::Exit_Coord(void) const
  4638. {
  4639. assert(Buildings.ID(this) == ID);
  4640. assert(IsActive);
  4641. if (Class->ExitCoordinate) {
  4642. return(Coord_Add(Coord, Class->ExitCoordinate));
  4643. }
  4644. return(TechnoClass::Exit_Coord());
  4645. }
  4646. /***********************************************************************************************
  4647. * BuildingClass::Check_Point -- Fetches the landing checkpoint for the given flight pattern. *
  4648. * *
  4649. * Use this routine to coordinate a landing operation. The specified checkpoint is *
  4650. * converted into a cell number. The landing aircraft should fly over that cell and then *
  4651. * request the next check point. *
  4652. * *
  4653. * INPUT: cp -- The check point to convert to a cell number. *
  4654. * *
  4655. * OUTPUT: Returns with the cell that the aircraft should fly over in order to complete *
  4656. * that portion of the landing pattern. *
  4657. * *
  4658. * WARNINGS: none *
  4659. * *
  4660. * HISTORY: *
  4661. * 07/06/1996 JLB : Created. *
  4662. *=============================================================================================*/
  4663. CELL BuildingClass::Check_Point(CheckPointType cp) const
  4664. {
  4665. CELL xoffset = 6; // Downwind offset.
  4666. CELL yoffset = 5; // Crosswind offset.
  4667. CELL cell = Coord_Cell(Center_Coord());
  4668. switch (cp) {
  4669. case CHECK_STACK:
  4670. xoffset = 0;
  4671. break;
  4672. case CHECK_CROSSWIND:
  4673. yoffset = 0;
  4674. break;
  4675. case CHECK_DOWNWIND:
  4676. default:
  4677. break;
  4678. }
  4679. if ((Cell_X(cell) - Map.MapCellX) > Map.MapCellWidth/2) {
  4680. xoffset = -xoffset;
  4681. }
  4682. if ((Cell_Y(cell) - Map.MapCellY) > Map.MapCellHeight/2) {
  4683. yoffset = -yoffset;
  4684. }
  4685. return(XY_Cell(Cell_X(cell)+xoffset, Cell_Y(cell)+yoffset));
  4686. }
  4687. /***********************************************************************************************
  4688. * BuildingClass::Update_Radar_Spied - set house's RadarSpied field appropriately. *
  4689. * *
  4690. * This routine is called when a radar facility is captured or destroyed. It fills in the *
  4691. * RadarSpied field of the house based on whether there's a spied-upon radar facility or not*
  4692. * *
  4693. * INPUT: none *
  4694. * *
  4695. * OUTPUT: House->RadarSpied field gets set appropriately. *
  4696. * *
  4697. * WARNINGS: none *
  4698. * *
  4699. * HISTORY: *
  4700. * 03/22/1996 BWG : Created. *
  4701. *=============================================================================================*/
  4702. void BuildingClass::Update_Radar_Spied(void)
  4703. {
  4704. House->RadarSpied = 0;
  4705. for (int index = 0; index < Buildings.Count(); index++) {
  4706. BuildingClass * obj = Buildings.Ptr(index);
  4707. if (obj && !obj->IsInLimbo && obj->House == House) {
  4708. if (*obj == STRUCT_RADAR /* || *obj == STRUCT_EYE */) {
  4709. House->RadarSpied |= obj->Spied_By();
  4710. }
  4711. }
  4712. }
  4713. Map.RadarClass::Flag_To_Redraw(true);
  4714. }
  4715. /***********************************************************************************************
  4716. * BuildingClass::Read_INI -- Reads buildings from INI file. *
  4717. * *
  4718. * This is the basic scenario initialization of building function. It *
  4719. * is called when reading the scenario startup INI file and it handles *
  4720. * creation of all specified buildings. *
  4721. * *
  4722. * INI entry format: *
  4723. * Housename, Typename, Strength, Cell, Facing, Triggername *
  4724. * *
  4725. * INPUT: buffer -- Pointer to the loaded INI file data. *
  4726. * *
  4727. * OUTPUT: none *
  4728. * *
  4729. * WARNINGS: none *
  4730. * *
  4731. * HISTORY: *
  4732. * 05/24/1994 JLB : Created. *
  4733. *=============================================================================================*/
  4734. void BuildingClass::Read_INI(CCINIClass & ini)
  4735. {
  4736. BuildingClass * b; // Working unit pointer.
  4737. HousesType bhouse; // Building house.
  4738. StructType classid; // Building type.
  4739. CELL cell; // Cell of building.
  4740. char buf[128];
  4741. char * trigname; // building's trigger's name
  4742. int len = ini.Entry_Count(INI_Name());
  4743. for (int index = 0; index < len; index++) {
  4744. char const * entry = ini.Get_Entry(INI_Name(), index);
  4745. /*
  4746. ** Get a building entry.
  4747. */
  4748. ini.Get_String(INI_Name(), entry, NULL, buf, sizeof(buf));
  4749. /*
  4750. ** 1st token: house name.
  4751. */
  4752. bhouse = HouseTypeClass::From_Name(strtok(buf, ","));
  4753. /*
  4754. ** 2nd token: building name.
  4755. */
  4756. classid = BuildingTypeClass::From_Name(strtok(NULL, ","));
  4757. if (bhouse != HOUSE_NONE && classid != STRUCT_NONE) {
  4758. int strength;
  4759. DirType facing;
  4760. /*
  4761. ** 3rd token: strength.
  4762. */
  4763. strength = atoi(strtok(NULL, ","));
  4764. /*
  4765. ** 4th token: cell #.
  4766. */
  4767. cell = atoi(strtok(NULL, ","));
  4768. /*
  4769. ** 5th token: facing.
  4770. */
  4771. facing = (DirType)atoi(strtok(NULL, ","));
  4772. /*
  4773. ** 6th token: triggername (can be NULL).
  4774. */
  4775. trigname = strtok(NULL, ",");
  4776. bool sellable = false;
  4777. char * token_pointer = strtok(NULL, ",");
  4778. if (token_pointer) {
  4779. sellable = atoi(token_pointer);
  4780. }
  4781. bool rebuild = false;
  4782. token_pointer = strtok(NULL, ",");
  4783. if (token_pointer) {
  4784. rebuild = atoi(token_pointer);
  4785. }
  4786. if (HouseClass::As_Pointer(bhouse) != NULL) {
  4787. b = new BuildingClass(classid, bhouse);
  4788. if (b) {
  4789. TriggerTypeClass * tp = TriggerTypeClass::From_Name(trigname);
  4790. if (tp) {
  4791. TriggerClass * tt = Find_Or_Make(tp);
  4792. if (tt) {
  4793. tt->AttachCount++;
  4794. b->Trigger = tt;
  4795. }
  4796. }
  4797. b->IsAllowedToSell = sellable;
  4798. b->IsToRebuild = rebuild;
  4799. b->IsToRepair = rebuild || *b == STRUCT_CONST;
  4800. if (b->Unlimbo(Cell_Coord(cell), facing)) {
  4801. strength = min(strength, 0x100);
  4802. strength = (int)b->Class->MaxStrength * fixed(strength, 256); // Cast to (int). ST - 5/8/2019
  4803. b->Strength = strength;
  4804. if (b->Strength > b->Class->MaxStrength-3) b->Strength = b->Class->MaxStrength;
  4805. b->IsALemon = false;
  4806. } else {
  4807. /*
  4808. ** If the building could not be unlimboed on the map, then this indicates
  4809. ** a serious error. Delete the building.
  4810. */
  4811. delete b;
  4812. }
  4813. }
  4814. }
  4815. }
  4816. }
  4817. }
  4818. /***********************************************************************************************
  4819. * BuildingClass::Write_INI -- Write out the building data to the INI file specified. *
  4820. * *
  4821. * This will store the building data (as it relates to scenario initialization) to the *
  4822. * INI database specified. *
  4823. * *
  4824. * INPUT: ini -- Reference to the INI database that the building data will be stored to. *
  4825. * *
  4826. * OUTPUT: none *
  4827. * *
  4828. * WARNINGS: none *
  4829. * *
  4830. * HISTORY: *
  4831. * 07/06/1996 JLB : Created. *
  4832. *=============================================================================================*/
  4833. void BuildingClass::Write_INI(CCINIClass & ini)
  4834. {
  4835. /*
  4836. ** First, clear out all existing building data from the ini file.
  4837. */
  4838. ini.Clear(INI_Name());
  4839. /*
  4840. ** Write the data out.
  4841. */
  4842. for (int index = 0; index < Buildings.Count(); index++) {
  4843. BuildingClass * building = Buildings.Ptr(index);
  4844. if (!building->IsInLimbo) {
  4845. char uname[10];
  4846. char buf[127];
  4847. sprintf(uname, "%d", index);
  4848. sprintf(buf, "%s,%s,%d,%u,%d,%s,%d,%d",
  4849. building->House->Class->IniName,
  4850. building->Class->IniName,
  4851. building->Health_Ratio()*256,
  4852. Coord_Cell(building->Coord),
  4853. building->PrimaryFacing.Current(),
  4854. building->Trigger.Is_Valid() ? building->Trigger->Class->IniName : "None",
  4855. building->IsAllowedToSell,
  4856. building->IsToRebuild
  4857. );
  4858. ini.Put_String(INI_Name(), uname, buf);
  4859. }
  4860. }
  4861. }
  4862. /***********************************************************************************************
  4863. * BuildingClass::Target_Coord -- Return the coordinate to use when firing on this building. *
  4864. * *
  4865. * This routine will determine the "center" location of this building for purposes of *
  4866. * targeting. Usually, this location is somewhere near the foundation of the building. *
  4867. * *
  4868. * INPUT: none *
  4869. * *
  4870. * OUTPUT: Returns with the coordinate to use when firing upon this building (or trying to *
  4871. * walk onto it). *
  4872. * *
  4873. * WARNINGS: none *
  4874. * *
  4875. * HISTORY: *
  4876. * 07/19/1996 JLB : Created. *
  4877. *=============================================================================================*/
  4878. COORDINATE BuildingClass::Target_Coord(void) const
  4879. {
  4880. COORDINATE coord = Center_Coord();
  4881. if (Class->FoundationFace != FACING_NONE) {
  4882. return(Adjacent_Cell(coord, Class->FoundationFace));
  4883. }
  4884. return(coord);
  4885. }
  4886. /***********************************************************************************************
  4887. * BuildingClass::Factory_AI -- Handle factory production and initiation. *
  4888. * *
  4889. * Some building (notably the computer controlled ones) can have a factory object attached. *
  4890. * This routine handles processing of that factory and also detecting when production *
  4891. * should begin in order to initiate production. *
  4892. * *
  4893. * INPUT: none *
  4894. * *
  4895. * OUTPUT: none *
  4896. * *
  4897. * WARNINGS: Only call this routine once per building per game logic loop. *
  4898. * *
  4899. * HISTORY: *
  4900. * 07/29/1996 JLB : Created. *
  4901. *=============================================================================================*/
  4902. void BuildingClass::Factory_AI(void)
  4903. {
  4904. /*
  4905. ** Handle any production tied to this building. Only computer controlled buildings have
  4906. ** production attached to the building itself. The player uses the sidebar interface for
  4907. ** all production control.
  4908. */
  4909. if (Factory.Is_Valid() && Factory->Has_Completed() && PlacementDelay == 0) {
  4910. TechnoClass * product = Factory->Get_Object();
  4911. // FactoryClass * fact = Factory;
  4912. switch (Exit_Object(product)) {
  4913. /*
  4914. ** If the object could not leave the factory, then either request
  4915. ** a transport, place the (what must be a) building using another method, or
  4916. ** abort the production and refund money.
  4917. */
  4918. case 0:
  4919. Factory->Abandon();
  4920. delete (FactoryClass *)Factory;
  4921. Factory = 0;
  4922. break;
  4923. /*
  4924. ** Exiting this building is prevented by some temporary blockage. Wait
  4925. ** a bit before trying again.
  4926. */
  4927. case 1:
  4928. PlacementDelay = TICKS_PER_SECOND*3;
  4929. break;
  4930. /*
  4931. ** The object was successfully sent from this factory. Inform the house
  4932. ** tracking logic that the requested object has been produced.
  4933. */
  4934. case 2:
  4935. switch (product->What_Am_I()) {
  4936. case RTTI_VESSEL:
  4937. House->JustBuiltVessel = ((VesselClass*)product)->Class->Type;
  4938. House->IsBuiltSomething = true;
  4939. break;
  4940. case RTTI_UNIT:
  4941. House->JustBuiltUnit = ((UnitClass*)product)->Class->Type;
  4942. House->IsBuiltSomething = true;
  4943. break;
  4944. case RTTI_INFANTRY:
  4945. House->JustBuiltInfantry = ((InfantryClass*)product)->Class->Type;
  4946. House->IsBuiltSomething = true;
  4947. break;
  4948. case RTTI_BUILDING:
  4949. House->JustBuiltStructure = ((BuildingClass*)product)->Class->Type;
  4950. House->IsBuiltSomething = true;
  4951. break;
  4952. case RTTI_AIRCRAFT:
  4953. House->JustBuiltAircraft = ((AircraftClass*)product)->Class->Type;
  4954. House->IsBuiltSomething = true;
  4955. break;
  4956. default:
  4957. break;
  4958. }
  4959. // fact->Completed();
  4960. Factory->Completed();
  4961. // delete fact;
  4962. delete (FactoryClass *)Factory;
  4963. Factory = 0;
  4964. break;
  4965. default:
  4966. break;
  4967. }
  4968. }
  4969. /*
  4970. ** Pick something to create for this factory.
  4971. */
  4972. if (House->IsStarted && Mission != MISSION_CONSTRUCTION && Mission != MISSION_DECONSTRUCTION) {
  4973. /*
  4974. ** Buildings that produce other objects have special factory logic handled here.
  4975. */
  4976. if (Class->ToBuild != RTTI_NONE) {
  4977. if (Factory.Is_Valid()) {
  4978. /*
  4979. ** If production has halted, then just abort production and make the
  4980. ** funds available for something else.
  4981. */
  4982. if (PlacementDelay == 0 && !Factory->Is_Building()) {
  4983. Factory->Abandon();
  4984. delete (FactoryClass *)Factory;
  4985. Factory = 0;
  4986. }
  4987. } else {
  4988. /*
  4989. ** Only look to start production if there is at least a small amount of
  4990. ** money available. In cases where there is no practical money left, then
  4991. ** production can never complete -- don't bother starting it.
  4992. */
  4993. if (House->IsStarted && House->Available_Money() > 10) {
  4994. TechnoTypeClass const * techno = House->Suggest_New_Object(Class->ToBuild, *this == STRUCT_KENNEL);
  4995. /*
  4996. ** If a suitable object type was selected for production, then start
  4997. ** producing it now.
  4998. */
  4999. if (techno != NULL) {
  5000. Factory = new FactoryClass;
  5001. if (Factory.Is_Valid()) {
  5002. if (!Factory->Set(*techno, *House)) {
  5003. delete (FactoryClass *)Factory;
  5004. Factory = 0;
  5005. } else {
  5006. House->Production_Begun(Factory->Get_Object());
  5007. Factory->Start();
  5008. }
  5009. }
  5010. }
  5011. }
  5012. }
  5013. }
  5014. }
  5015. }
  5016. /***********************************************************************************************
  5017. * BuildingClass::Rotation_AI -- Process any turret rotation required of this building. *
  5018. * *
  5019. * Some buildings have a turret and this routine handles processing the turret rotation. *
  5020. * *
  5021. * INPUT: none *
  5022. * *
  5023. * OUTPUT: none *
  5024. * *
  5025. * WARNINGS: Only call this routine once per building per game logic loop. *
  5026. * *
  5027. * HISTORY: *
  5028. * 07/29/1996 JLB : Created. *
  5029. * 10/27/1996 JLB : Rotation does not occur if power and no power avail. *
  5030. *=============================================================================================*/
  5031. void BuildingClass::Rotation_AI(void)
  5032. {
  5033. if (Class->IsTurretEquipped &&
  5034. Mission != MISSION_CONSTRUCTION &&
  5035. Mission != MISSION_DECONSTRUCTION &&
  5036. (!Class->IsPowered || House->Power_Fraction() >= 1)) {
  5037. /*
  5038. ** Rotate turret to match desired facing.
  5039. */
  5040. if (PrimaryFacing.Is_Rotating()) {
  5041. if (PrimaryFacing.Rotation_Adjust(Class->ROT)) {
  5042. Mark(MARK_CHANGE);
  5043. }
  5044. }
  5045. }
  5046. }
  5047. /***********************************************************************************************
  5048. * BuildingClass::Charging_AI -- Handles the special charging logic for Tesla coils. *
  5049. * *
  5050. * This handles the special logic required of the charging tesla coil. It requires special *
  5051. * processing since its charge up is dependant upon the target and power surplus of the *
  5052. * owning house. *
  5053. * *
  5054. * INPUT: none *
  5055. * *
  5056. * OUTPUT: none *
  5057. * *
  5058. * WARNINGS: none *
  5059. * *
  5060. * HISTORY: *
  5061. * 07/29/1996 JLB : Created. *
  5062. *=============================================================================================*/
  5063. void BuildingClass::Charging_AI(void)
  5064. {
  5065. if (Class->PrimaryWeapon != NULL && Class->PrimaryWeapon->IsElectric && BState != BSTATE_CONSTRUCTION) {
  5066. if (Target_Legal(TarCom) && House->Power_Fraction() >= 1) {
  5067. if (!IsCharged) {
  5068. if (IsCharging) {
  5069. // if (stagechange) {
  5070. Mark(MARK_CHANGE);
  5071. if (Fetch_Stage() >= 9) {
  5072. IsCharged = true;
  5073. IsCharging = false;
  5074. Set_Rate(0);
  5075. }
  5076. // }
  5077. } else if (!Arm) {
  5078. IsCharged = false;
  5079. IsCharging = true;
  5080. Set_Stage(0);
  5081. Set_Rate(3);
  5082. Sound_Effect(VOC_TESLA_POWER_UP, Coord);
  5083. }
  5084. }
  5085. } else {
  5086. if (IsCharging || IsCharged) {
  5087. Mark(MARK_CHANGE);
  5088. IsCharging = false;
  5089. IsCharged = false;
  5090. Set_Stage(0);
  5091. Set_Rate(0);
  5092. }
  5093. }
  5094. }
  5095. }
  5096. /***********************************************************************************************
  5097. * BuildingClass::Repair_AI -- Handle the repair (and sell) logic for the building. *
  5098. * *
  5099. * This routine handle the repair animation and healing logic. It also detects when the *
  5100. * (computer controlled) building should begin repair or sell itself. *
  5101. * *
  5102. * INPUT: none *
  5103. * *
  5104. * OUTPUT: none *
  5105. * *
  5106. * WARNINGS: Only call this routine once per building per game logic loop. *
  5107. * *
  5108. * HISTORY: *
  5109. * 07/29/1996 JLB : Created. *
  5110. *=============================================================================================*/
  5111. void BuildingClass::Repair_AI(void)
  5112. {
  5113. if (House->IQ >= Rule.IQRepairSell && Mission != MISSION_CONSTRUCTION && Mission != MISSION_DECONSTRUCTION) {
  5114. /*
  5115. ** Possibly start repair process if the building is below half strength.
  5116. */
  5117. // unsigned ratio = MIN(House->Smartness, 0x00F0);
  5118. if (Can_Repair()) {
  5119. if (House->Available_Money() >= Rule.RepairThreshhold) {
  5120. if (!House->DidRepair) {
  5121. if (!IsRepairing && (IsCaptured || IsToRepair || House->IsHuman || Session.Type != GAME_NORMAL)) {
  5122. House->DidRepair = true; // flag that this house did its repair allocation for this frame
  5123. Repair(1);
  5124. if (!House->IsHuman) {
  5125. House->RepairTimer = Random_Pick((int)(House->RepairDelay * (TICKS_PER_MINUTE/4)), (int)(House->RepairDelay * TICKS_PER_MINUTE * 2));
  5126. }
  5127. }
  5128. }
  5129. } else {
  5130. if ((Session.Type != GAME_NORMAL || IsAllowedToSell) && IsTickedOff && House->Control.TechLevel >= Rule.IQSellBack && Random_Pick(0, 50) < House->Control.TechLevel && !Trigger.Is_Valid() && *this != STRUCT_CONST && Health_Ratio() < Rule.ConditionRed) {
  5131. Sell_Back(1);
  5132. }
  5133. }
  5134. }
  5135. }
  5136. /*
  5137. ** If it is repairing, then apply any repair effects as necessary.
  5138. */
  5139. if (IsRepairing && (Frame % (Rule.RepairRate * TICKS_PER_MINUTE)) == 0) {
  5140. IsWrenchVisible = (IsWrenchVisible == false);
  5141. Mark(MARK_CHANGE);
  5142. int cost = Class->Repair_Cost();
  5143. int step = Class->Repair_Step();
  5144. /*
  5145. ** Check for and expend any necessary monies to continue the repair.
  5146. */
  5147. if (House->Available_Money() >= cost) {
  5148. House->Spend_Money(cost);
  5149. Strength += step;
  5150. if (Strength >= Class->MaxStrength) {
  5151. Strength = Class->MaxStrength;
  5152. IsRepairing = false;
  5153. }
  5154. } else {
  5155. IsRepairing = false;
  5156. }
  5157. }
  5158. }
  5159. /***********************************************************************************************
  5160. * BuildingClass::Animation_AI -- Handles normal building animation processing. *
  5161. * *
  5162. * This will process the general building animation mechanism. It detects when the *
  5163. * building animation sequence has completed and flags the building to perform mission *
  5164. * changes as a result. *
  5165. * *
  5166. * INPUT: none *
  5167. * *
  5168. * OUTPUT: none *
  5169. * *
  5170. * WARNINGS: Call this routine only once per building per game logic loop. *
  5171. * *
  5172. * HISTORY: *
  5173. * 07/29/1996 JLB : Created. *
  5174. *=============================================================================================*/
  5175. void BuildingClass::Animation_AI(void)
  5176. {
  5177. bool stagechange = Graphic_Logic();
  5178. bool toloop = false;
  5179. /*
  5180. ** Always refresh the SAM site if it has an animation change.
  5181. */
  5182. if (*this == STRUCT_SAM && stagechange) Mark(MARK_CHANGE);
  5183. if ((!Class->IsTurretEquipped && *this != STRUCT_TESLA) || Mission == MISSION_CONSTRUCTION || Mission == MISSION_DECONSTRUCTION) {
  5184. if (stagechange) {
  5185. /*
  5186. ** Check for animation end or if special case of MCV deconstructing when it is allowed
  5187. ** to convert back into an MCV.
  5188. */
  5189. BuildingTypeClass::AnimControlType const * ctrl = Fetch_Anim_Control();
  5190. /*
  5191. ** When the last frame of the current animation sequence is reached, flag that
  5192. ** a new mission may be started. This must occur before the animation actually
  5193. ** loops so that if a mission change does occur, it will have a chance to change
  5194. ** the building graphic before the last frame is replaced by the first frame of
  5195. ** the loop.
  5196. */
  5197. if (Fetch_Stage() == ctrl->Start+ctrl->Count-1 || (!Target_Legal(ArchiveTarget) /*Is_MCV_Deploy()*/ && *this == STRUCT_CONST && Mission == MISSION_DECONSTRUCTION && Fetch_Stage() == (42-19))) {
  5198. IsReadyToCommence = true;
  5199. }
  5200. /*
  5201. ** If the animation advances beyond the last frame, then start the animation
  5202. ** sequence over from the beginning.
  5203. */
  5204. if (Fetch_Stage() >= ctrl->Start+ctrl->Count) {
  5205. toloop = true;
  5206. }
  5207. Mark(MARK_CHANGE);
  5208. } else {
  5209. if (BState == BSTATE_NONE || Fetch_Rate() == 0) {
  5210. IsReadyToCommence = true;
  5211. }
  5212. }
  5213. }
  5214. /*
  5215. ** If there is a door that is animating, then it might cause this building
  5216. ** to be redrawn. Check for and flag to redraw as necessary.
  5217. */
  5218. if (Time_To_Redraw()) {
  5219. Clear_Redraw_Flag();
  5220. Mark(MARK_CHANGE);
  5221. }
  5222. /*
  5223. ** The animation sequence has looped. Restart it and flag this loop condition.
  5224. ** This is used to tell the mission system that the animation has completed. It
  5225. ** also signals that now is a good time to act on any pending mission.
  5226. */
  5227. if (toloop) {
  5228. BuildingTypeClass::AnimControlType const * ctrl = Fetch_Anim_Control();
  5229. if (BState == BSTATE_CONSTRUCTION || BState == BSTATE_IDLE) {
  5230. Set_Rate(Options.Normalize_Delay(ctrl->Rate));
  5231. } else {
  5232. Set_Rate(ctrl->Rate);
  5233. }
  5234. Set_Stage(ctrl->Start);
  5235. Mark(MARK_CHANGE);
  5236. }
  5237. }
  5238. /***********************************************************************************************
  5239. * BuildingClass::How_Many_Survivors -- This determine the maximum number of survivors. *
  5240. * *
  5241. * This routine is called to determine how many survivors should run from this building *
  5242. * when it is either sold or destroyed. Buildings that are captured have fewer survivors. *
  5243. * The number of survivors is a portion of the cost of the building divided by the cost *
  5244. * of a minigunner. *
  5245. * *
  5246. * INPUT: none *
  5247. * *
  5248. * OUTPUT: Returns with the number of soldiers that should run from this building. *
  5249. * *
  5250. * WARNINGS: none *
  5251. * *
  5252. * HISTORY: *
  5253. * 08/04/1996 JLB : Created. *
  5254. *=============================================================================================*/
  5255. int BuildingClass::How_Many_Survivors(void) const
  5256. {
  5257. if (IsSurvivorless || !Class->IsCrew) return(0);
  5258. int divisor = InfantryTypeClass::As_Reference(INFANTRY_E1).Raw_Cost();
  5259. if (divisor == 0) return(0);
  5260. if (IsCaptured) divisor *= 2;
  5261. int count = (Class->Raw_Cost() * Rule.SurvivorFraction) / divisor;
  5262. return(Bound(count, 1, 5));
  5263. }
  5264. /***********************************************************************************************
  5265. * BuildingClass::Get_Image_Data -- Fetch the image pointer for the building. *
  5266. * *
  5267. * This routine will return with a pointer to the shape data for the building. The shape *
  5268. * data is different than normal when the building is undergoing construction and *
  5269. * disassembly. *
  5270. * *
  5271. * INPUT: none *
  5272. * *
  5273. * OUTPUT: Returns with a pointer to the shape data for this building. *
  5274. * *
  5275. * WARNINGS: none *
  5276. * *
  5277. * HISTORY: *
  5278. * 08/06/1996 JLB : Created. *
  5279. *=============================================================================================*/
  5280. void const * BuildingClass::Get_Image_Data(void) const
  5281. {
  5282. if (BState == BSTATE_CONSTRUCTION) {
  5283. return(Class->Get_Buildup_Data());
  5284. }
  5285. return(TechnoClass::Get_Image_Data());
  5286. }
  5287. /***********************************************************************************************
  5288. * BuildingClass::Value -- Determine the value of this building. *
  5289. * *
  5290. * The value of the building is normally just its ordinary assigned value. However, in the *
  5291. * case of fakes, the value is artificially enhanced to match the structure that is *
  5292. * being faked. *
  5293. * *
  5294. * INPUT: none *
  5295. * *
  5296. * OUTPUT: Returns with the point value of the building type. *
  5297. * *
  5298. * WARNINGS: The point value returned should not be used for scoring, only for target *
  5299. * scanning. *
  5300. * *
  5301. * HISTORY: *
  5302. * 09/16/1996 JLB : Created. *
  5303. *=============================================================================================*/
  5304. int BuildingClass::Value(void) const
  5305. {
  5306. if (Class->IsFake) {
  5307. switch (Class->Type) {
  5308. case STRUCT_FAKEWEAP:
  5309. return(BuildingTypeClass::As_Reference(STRUCT_WEAP).Reward + BuildingTypeClass::As_Reference(STRUCT_WEAP).Risk);
  5310. case STRUCT_FAKECONST:
  5311. return(BuildingTypeClass::As_Reference(STRUCT_CONST).Reward + BuildingTypeClass::As_Reference(STRUCT_CONST).Risk);
  5312. case STRUCT_FAKE_YARD:
  5313. return(BuildingTypeClass::As_Reference(STRUCT_SHIP_YARD).Reward + BuildingTypeClass::As_Reference(STRUCT_SHIP_YARD).Risk);
  5314. case STRUCT_FAKE_PEN:
  5315. return(BuildingTypeClass::As_Reference(STRUCT_SUB_PEN).Reward + BuildingTypeClass::As_Reference(STRUCT_SUB_PEN).Risk);
  5316. case STRUCT_FAKE_RADAR:
  5317. return(BuildingTypeClass::As_Reference(STRUCT_RADAR).Reward + BuildingTypeClass::As_Reference(STRUCT_RADAR).Risk);
  5318. default:
  5319. break;
  5320. }
  5321. }
  5322. return(TechnoClass::Value());
  5323. }
  5324. /***********************************************************************************************
  5325. * BuildingClass::Remove_Gap_Effect -- Stop a gap generator from jamming cells. *
  5326. * *
  5327. * INPUT: none *
  5328. * *
  5329. * OUTPUT: none *
  5330. * *
  5331. * WARNINGS: *
  5332. * *
  5333. * HISTORY: *
  5334. * 09/20/1996 BWG : Created. *
  5335. *=============================================================================================*/
  5336. void BuildingClass::Remove_Gap_Effect(void)
  5337. {
  5338. // unjam this one's field...
  5339. Map.UnJam_From(Coord_Cell(Center_Coord()), Rule.GapShroudRadius, House);
  5340. /*
  5341. ** Updated for client/server multiplayer. ST - 8/12/2019 11:14AM
  5342. */
  5343. if (Session.Type != GAME_GLYPHX_MULTIPLAYER) {
  5344. if (!House->IsPlayerControl && PlayerPtr->IsGPSActive) {
  5345. Map.Sight_From(Coord_Cell(Center_Coord()), Rule.GapShroudRadius, PlayerPtr);
  5346. }
  5347. } else {
  5348. for (int i = 0; i < Session.Players.Count(); i++) {
  5349. HouseClass *player_house = HouseClass::As_Pointer(Session.Players[i]->Player.ID);
  5350. if (player_house->IsGPSActive && player_house != House) {
  5351. Map.Sight_From(Coord_Cell(Center_Coord()), Rule.GapShroudRadius, player_house);
  5352. }
  5353. }
  5354. }
  5355. // and rejam any overlapping buildings' fields
  5356. for (int index = 0; index < Buildings.Count(); index++) {
  5357. BuildingClass *obj = Buildings.Ptr(index);
  5358. if (obj && !obj->IsInLimbo && obj->House == House && *obj == STRUCT_GAP && obj!=this) {
  5359. obj->IsJamming = false;
  5360. obj->Arm = 0;
  5361. // Map.Jam_From(Coord_Cell(obj->Center_Coord()), Rule.GapShroudRadius, PlayerPtr);
  5362. }
  5363. }
  5364. }
  5365. short const * BuildingClass::Overlap_List(bool redraw) const
  5366. {
  5367. if ((Spied_By() & (1 << PlayerPtr->Class->House)) != 0 && Is_Selected_By_Player()) {
  5368. if (*this == STRUCT_BARRACKS || *this == STRUCT_TENT) {
  5369. static short const _list[] = {
  5370. -1, 2, (MAP_CELL_W*1)-1, (MAP_CELL_W*1)+2, REFRESH_EOL
  5371. };
  5372. return(_list);
  5373. } else if (*this == STRUCT_REFINERY) {
  5374. static short const _list[] = {
  5375. 0, 2, (MAP_CELL_W*2)+0, (MAP_CELL_W*2)+1, (MAP_CELL_W*2)+2, REFRESH_EOL
  5376. };
  5377. return(_list);
  5378. }
  5379. }
  5380. return(TechnoClass::Overlap_List(redraw));
  5381. }
  5382. unsigned BuildingClass::Spied_By() const
  5383. {
  5384. unsigned spiedby = TechnoClass::Spied_By();
  5385. /*
  5386. ** If it's an ore refinery or other such storage-capable building,
  5387. ** loop thru all of their buildings to see if ANY of them are spied
  5388. ** upon, 'cause once you spy any money, you've spied all of it.
  5389. */
  5390. if (Class->Capacity) {
  5391. for (int index = 0; index < Buildings.Count(); index++) {
  5392. BuildingClass * building = Buildings.Ptr(index);
  5393. if (building->House == House && building->Class->Capacity) {
  5394. spiedby |= building->SpiedBy;
  5395. }
  5396. }
  5397. }
  5398. return spiedby;
  5399. }