TECHNO.CPP 311 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972
  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/TECHNO.CPP 5 3/17/97 1:28a Steve_tall $ */
  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 : BASE.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : May 8, 1994 *
  26. * *
  27. * Last Update : November 1, 1996 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * TechnoClass::AI -- Handles AI processing for techno object. *
  32. * TechnoClass::Anti_Air -- Determines the anti-aircraft strength of the object. *
  33. * TechnoClass::Anti_Armor -- Determines the anti-armor strength of the object. *
  34. * TechnoClass::Anti_Infantry -- Calculates the anti-infantry strength of this object. *
  35. * TechnoClass::Area_Modify -- Determine the area scan modifier for the cell. *
  36. * TechnoClass::Assign_Destination -- Assigns movement destination to the object. *
  37. * TechnoClass::Assign_Target -- Assigns the targeting computer with specified target. *
  38. * TechnoClass::Base_Is_Attacked -- Handle panic response to base being attacked. *
  39. * TechnoClass::Can_Fire -- Determines if this techno object can fire. *
  40. * TechnoClass::Can_Player_Fire -- Determines if the player can give this object a fire order*
  41. * TechnoClass::Can_Player_Move -- Determines if the object can move be moved by player. *
  42. * TechnoClass::Can_Repair -- Determines if the object can and should be repaired. *
  43. * TechnoClass::Can_Teleport_Here -- Checks cell to see if a valid teleport destination. *
  44. * TechnoClass::Captured -- Handles capturing this object. *
  45. * TechnoClass::Clicked_As_Target -- Sets the flash count for this techno object. *
  46. * TechnoClass::Cloaking_AI -- Perform the AI maintenance for a cloaking device. *
  47. * TechnoClass::Combat_Damage -- Fetch the amount of damage infliced by the specified weapon.*
  48. * TechnoClass::Crew_Type -- Fetches the kind of crew this object contains. *
  49. * TechnoClass::Debug_Dump -- Displays the base class data to the monochrome screen. *
  50. * TechnoClass::Desired_Load_Dir -- Fetches loading parameters for this object. *
  51. * TechnoClass::Detach -- Handles removal of target from tracking system. *
  52. * TechnoClass::Do_Cloak -- Start the object into cloaking stage. *
  53. * TechnoClass::Do_Shimmer -- Causes this object to shimmer if it is cloaked. *
  54. * TechnoClass::Do_Uncloak -- Cause the stealth tank to uncloak. *
  55. * TechnoClass::Draw_It -- Draws the health bar (if necessary). *
  56. * TechnoClass::Draw_Pips -- Draws the transport pips and other techno graphics. *
  57. * TechnoClass::Electric_Zap -- Fires electric zap at the target specified. *
  58. * TechnoClass::Enter_Idle_Mode -- Object enters its default idle condition. *
  59. * TechnoClass::Evaluate_Cell -- Determine the value and object of specified cell. *
  60. * TechnoClass::Evaluate_Just_Cell -- Evaluate a cell as a target by itself. *
  61. * TechnoClass::Evaluate_Object -- Determines score value of specified object. *
  62. * TechnoClass::Exit_Object -- Causes specified object to leave this object. *
  63. * TechnoClass::Find_Docking_Bay -- Searches for a close docking bay. *
  64. * TechnoClass::Find_Exit_Cell -- Finds an appropriate exit cell for this object. *
  65. * TechnoClass::Fire_At -- Fires projectile at target specified. *
  66. * TechnoClass::Fire_Coord -- Determine the coordinate where bullets appear. *
  67. * TechnoClass::Fire_Direction -- Fetches the direction projectile fire will take. *
  68. * TechnoClass::Get_Ownable -- Fetches the ownable bits for this object. *
  69. * TechnoClass::Greatest_Threat -- Determines best target given search criteria. *
  70. * TechnoClass::Hidden -- Returns the object back into the hidden state. *
  71. * TechnoClass::How_Many_Survivors -- Determine the number of survivors to escape. *
  72. * TechnoClass::In_Range -- Determines if specified target is within weapon range. *
  73. * TechnoClass::In_Range -- Determines if specified target is within weapon range. *
  74. * TechnoClass::In_Range -- Determines if the specified coordinate is within range. *
  75. * TechnoClass::Is_Allowed_To_Recloak -- Can this object recloak? *
  76. * TechnoClass::Is_Allowed_To_Retaliate -- Checks object to see if it can retaliate. *
  77. * TechnoClass::Is_In_Same_Zone -- Determine if specified cell is in same zone as object. *
  78. * TechnoClass::Is_Players_Army -- Determines if this object is part of the player's army. *
  79. * TechnoClass::Is_Ready_To_Cloak -- Determines if this object is ready to begin cloaking. *
  80. * TechnoClass::Is_Ready_To_Random_Animate -- Determines if the object should random animate.*
  81. * TechnoClass::Is_Visible_On_Radar -- Is this object visible on player's radar screen? *
  82. * TechnoClass::Is_Weapon_Equipped -- Determines if this object has a combat weapon. *
  83. * TechnoClass::Kill_Cargo -- Destroys any cargo attached to this object. *
  84. * TechnoClass::Look -- Performs a look around (map reveal) action. *
  85. * TechnoClass::Mark -- Handles marking of techno objects. *
  86. * TechnoClass::Nearby_Location -- Radiates outward looking for clear cell nearby. *
  87. * TechnoClass::Owner -- Who is the owner of this object? *
  88. * TechnoClass::Per_Cell_Process -- Handles once-per-cell operations for techno type objects.*
  89. * TechnoClass::Pip_Count -- Fetches the number of pips to display on this object. *
  90. * TechnoClass::Player_Assign_Mission -- Assigns a mission as result of player input. *
  91. * TechnoClass::Rearm_Delay -- Calculates the delay before firing can occur. *
  92. * TechnoClass::Receive_Message -- Handles inbound message as appropriate. *
  93. * TechnoClass::Record_The_Kill -- Records the death of this object. *
  94. * TechnoClass::Refund_Amount -- Returns with the money to refund if this object is sold. *
  95. * TechnoClass::Remap_Table -- Fetches the appropriate remap table to use. *
  96. * TechnoClass::Renovate -- Heal a building to maximum *
  97. * TechnoClass::Response_Attack -- Handles the voice response when given attack order. *
  98. * TechnoClass::Response_Move -- Handles the voice response to a movement request. *
  99. * TechnoClass::Response_Select -- Handles the voice response when selected. *
  100. * TechnoClass::Revealed -- Handles revealing an object to the house specified. *
  101. * TechnoClass::Risk -- Fetches the risk associated with this object. *
  102. * TechnoClass::Select -- Selects object and checks to see if can be selected. *
  103. * TechnoClass::Set_Mission -- Forced mission set (used by editor). *
  104. * TechnoClass::Stun -- Prepares the object for removal from the game. *
  105. * TechnoClass::Take_Damage -- Records damage assessed to this object. *
  106. * TechnoClass::Target_Something_Nearby -- Handles finding and assigning a nearby target. *
  107. * TechnoClass::TechnoClass -- Constructor for techno type objects. *
  108. * TechnoClass::Techno_Draw_Object -- General purpose draw object routine. *
  109. * TechnoClass::Threat_Range -- Returns the range to scan based on threat control. *
  110. * TechnoClass::Tiberium_Load -- Fetches the current tiberium load percentage. *
  111. * TechnoClass::Time_To_Build -- Determines the time it would take to build this. *
  112. * TechnoClass::Unlimbo -- Performs unlimbo process for all techno type objects. *
  113. * TechnoClass::Value -- Fetches the target value for this object. *
  114. * TechnoClass::Visual_Character -- Determine the visual character of the object. *
  115. * TechnoClass::Weapon_Range -- Determines the maximum range for the weapon. *
  116. * TechnoClass::What_Action -- Determines action to perform if cell is clicked on. *
  117. * TechnoClass::What_Action -- Determines what action to perform if object is selected. *
  118. * TechnoClass::What_Weapon_Should_I_Use -- Determines what is the best weapon to use. *
  119. * TechnoTypeClass::Cost_Of -- Fetches the cost of this object type. *
  120. * TechnoTypeClass::Get_Cameo_Data -- Fetches the cameo image for this object type. *
  121. * TechnoTypeClass::Get_Ownable -- Fetches the ownable bits for this object type. *
  122. * TechnoTypeClass::Is_Two_Shooter -- Determines if this object is a double shooter. *
  123. * TechnoTypeClass::Raw_Cost -- Fetches the raw (base) cost of the object. *
  124. * TechnoTypeClass::Read_INI -- Reads the techno type data from the INI database. *
  125. * TechnoTypeClass::Repair_Cost -- Fetches the cost to repair one step. *
  126. * TechnoTypeClass::Repair_Step -- Fetches the health to repair one step. *
  127. * TechnoTypeClass::TechnoTypeClass -- Constructor for techno type objects. *
  128. * TechnoTypeClass::Time_To_Build -- Fetches the time to build this object. *
  129. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  130. #include "function.h"
  131. /***************************************************************************
  132. ** Cloaking control values.
  133. */
  134. #define MAX_UNCLOAK_STAGE 38
  135. //Added for getting the input for special character keys from the client
  136. // - 6/26/2019 JAS
  137. extern bool DLL_Export_Get_Input_Key_State(KeyNumType key);
  138. /***************************************************************************
  139. ** These are the pointers to the special shape data that the units may need.
  140. */
  141. void const * TechnoTypeClass::WakeShapes = 0;
  142. void const * TechnoTypeClass::TurretShapes = 0;
  143. void const * TechnoTypeClass::SamShapes = 0;
  144. void const * TechnoTypeClass::MGunShapes = 0;
  145. //Xlat Tables for French and German
  146. // For name overriding
  147. //#define NEWNAMES 22
  148. #ifdef GERMAN
  149. const char* NewName[] = {
  150. "Scout Ant", "Kundschafter-Ameise",
  151. "Warrior Ant", "Krieger-Ameise",
  152. "Fire Ant", "Feuer-Ameise",
  153. "Queen Ant", "Ameisenk”nigin",
  154. "ATS", "Angriffs-U-Boot",
  155. "Tesla Tank", "Telsapanzer",
  156. "Volkov", "Modell Volkov",
  157. "Chitzkoi", "Roboterhund",
  158. "Stavros", "Stavros",
  159. "F-A Longbow", "Jagdhubschrauber Longbow",
  160. "Civilian Specialist", "Wissenschaftler",
  161. "Alloy Facility", "Legierungswerk",
  162. NULL,
  163. };
  164. #endif
  165. #ifdef FRENCH
  166. const char* NewName[] = {
  167. "Scout Ant", "Fourmi de Reconnaissance",
  168. "Warrior Ant", "Fourmi GuerriŠre",
  169. "Fire Ant", "Fourmi Lance-Flammes",
  170. "Queen Ant", "Reine des Fourmis",
  171. "ATS", "SMTA",
  172. "Tesla Tank", "Tank Tesla",
  173. "Volkov", "Volkov",
  174. "Chitzkoi", "Cyber-Chien",
  175. "Stavros", "Stavros",
  176. "F-A Longbow", "HAA (H‚licoptŠre d'Assaut Avanc‚)",
  177. "Civilian Specialist", "Sp‚cialiste Civil",
  178. "Alloy Facility", "Usine M‚tallurgique",
  179. NULL,
  180. };
  181. #endif
  182. /***************************************************************************
  183. ** Which shape to use depending on which facing is controlled by these arrays.
  184. */
  185. int const TechnoClass::BodyShape[32] = {0,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1};
  186. /***********************************************************************************************
  187. * TechnoClass::Is_Players_Army -- Determines if this object is part of the player's army. *
  188. * *
  189. * The player's army is considered to be all those mobile units that can be selected *
  190. * and controlled by the player (they may or may not have weapons in the traditional *
  191. * sense). *
  192. * *
  193. * INPUT: none *
  194. * *
  195. * OUTPUT: bool; Is this object part of the player's selectable controllable army? *
  196. * *
  197. * WARNINGS: none *
  198. * *
  199. * HISTORY: *
  200. * 09/23/1996 JLB : Created. *
  201. *=============================================================================================*/
  202. bool TechnoClass::Is_Players_Army(void) const
  203. {
  204. /*
  205. ** An object that is dead (or about to be) is not considered part of
  206. ** the player's army.
  207. */
  208. if (Strength <= 0) {
  209. return(false);
  210. }
  211. /*
  212. ** If the object is not yet on the map or is otherwise indisposed, then
  213. ** don't consider it.
  214. */
  215. if (IsInLimbo || !IsLocked) {
  216. return(false);
  217. }
  218. /*
  219. ** Buildings, although sometimes serving a combat purpose, are not part
  220. ** of the player's army.
  221. */
  222. if (What_Am_I() == RTTI_BUILDING) {
  223. return(false);
  224. }
  225. /*
  226. ** If not discoverd by the player, then don't consider it part of the
  227. ** player's army (yet).
  228. */
  229. if (!Is_Discovered_By_Player()) {
  230. return(false);
  231. }
  232. /*
  233. ** If not selectable, then not really part of the player's active army.
  234. */
  235. if (!Techno_Type_Class()->IsSelectable) {
  236. return(false);
  237. }
  238. /*
  239. ** If not under player control, then it isn't part of the player's army.
  240. */
  241. if (!House->IsPlayerControl) {
  242. return(false);
  243. }
  244. return(true);
  245. }
  246. /***********************************************************************************************
  247. * TechnoClass::Can_Teleport_Here -- Checks cell to see if a valid teleport destination. *
  248. * *
  249. * Use this routine to examine the cell specified and if the cell could be a valid *
  250. * destination for a teleport, then return true. *
  251. * *
  252. * INPUT: cell -- The cell to examine as a possible legal teleport destination. *
  253. * *
  254. * OUTPUT: bool; Is the specified cell a legal teleport destination? *
  255. * *
  256. * WARNINGS: none *
  257. * *
  258. * HISTORY: *
  259. * 10/08/1996 JLB : Created. *
  260. *=============================================================================================*/
  261. bool TechnoClass::Can_Teleport_Here(CELL cell) const
  262. {
  263. /*
  264. ** Infantry are never allowed to teleport.
  265. */
  266. if (What_Am_I() == RTTI_INFANTRY) {
  267. return(false);
  268. }
  269. /*
  270. ** The destination cell must be on the playfield.
  271. */
  272. if (!Map.In_Radar(cell)) {
  273. return(false);
  274. }
  275. /*
  276. ** Teleporting directly onto the flag spot is not allowed. This is due to the
  277. ** requirement that entering that location must proceed under normal channels.
  278. */
  279. if (Map[cell].Overlay == OVERLAY_FLAG_SPOT) {
  280. return(false);
  281. }
  282. /*
  283. ** Determine if the object could enter the cell by normal means. If the
  284. ** cell is impassable, then it can't be teleported there.
  285. */
  286. TechnoTypeClass const * ttype = Techno_Type_Class();
  287. if (!Map[cell].Is_Clear_To_Move(ttype->Speed, true, true, -1, ttype->Speed == SPEED_FLOAT ? MZONE_WATER : MZONE_NORMAL)) {
  288. return(false);
  289. }
  290. return(true);
  291. }
  292. /***********************************************************************************************
  293. * TechnoClass::What_Weapon_Should_I_Use -- Determines what is the best weapon to use. *
  294. * *
  295. * This routine will compare the weapons this object is equipped with verses the *
  296. * candidate target object. The best weapon to use against the target will be returned. *
  297. * Special emphasis is given to weapons that can fire on the target without requiring *
  298. * this object to move within range. *
  299. * *
  300. * INPUT: target -- The candidate target to determine which weapon is best against. *
  301. * *
  302. * OUTPUT: Returns with an identifier the specifies what weapon to use against the target. *
  303. * The return value will be "0" for the primary weapon and "1" for the secondary. *
  304. * *
  305. * WARNINGS: This routine is called very frequently. It should be as efficient as possible. *
  306. * *
  307. * HISTORY: *
  308. * 08/12/1996 JLB : Created. *
  309. *=============================================================================================*/
  310. int TechnoClass::What_Weapon_Should_I_Use(TARGET target) const
  311. {
  312. if (!Target_Legal(target)) return(0);
  313. /*
  314. ** Fetch the armor of the candidate target object. Presume that if the target
  315. ** is not an object, then its armor is equivalent to wood. Who knows why?
  316. */
  317. ArmorType armor = ARMOR_WOOD;
  318. if (Is_Target_Object(target)) {
  319. armor = As_Object(target)->Class_Of().Armor;
  320. }
  321. TechnoTypeClass const * ttype = Techno_Type_Class();
  322. /*
  323. ** Get the value of the primary weapon verses the candidate target. Increase the
  324. ** value of the weapon if it happens to be in range.
  325. */
  326. int w1 = 0;
  327. WeaponTypeClass const * wptr = ttype->PrimaryWeapon;
  328. if (wptr != NULL && wptr->WarheadPtr != NULL) w1 = wptr->WarheadPtr->Modifier[armor] * 1000;
  329. if (In_Range(target, 0)) w1 *= 2;
  330. FireErrorType ok = Can_Fire(target, 0);
  331. if (ok == FIRE_CANT || ok == FIRE_ILLEGAL) w1 = 0;
  332. /*
  333. ** Calculate a similar value for the secondary weapon.
  334. */
  335. int w2 = 0;
  336. wptr = ttype->SecondaryWeapon;
  337. if (wptr != NULL && wptr->WarheadPtr != NULL) w2 = wptr->WarheadPtr->Modifier[armor] * 1000;
  338. if (In_Range(target, 1)) w2 *= 2;
  339. ok = Can_Fire(target, 1);
  340. if (ok == FIRE_CANT || ok == FIRE_ILLEGAL) w2 = 0;
  341. /*
  342. ** Return with the weapon identifier that should be used to fire upon the
  343. ** candidate target.
  344. */
  345. if (w2 > w1) return(1);
  346. return(0);
  347. }
  348. /***********************************************************************************************
  349. * TechnoClass::How_Many_Survivors -- Determine the number of survivors to escape. *
  350. * *
  351. * This routine will determine the number of survivors that should run from this object *
  352. * when it is destroyed. *
  353. * *
  354. * INPUT: none *
  355. * *
  356. * OUTPUT: Returns with the maximum number of survivors that should run from this object *
  357. * when the object gets destroyed. *
  358. * *
  359. * WARNINGS: none *
  360. * *
  361. * HISTORY: *
  362. * 08/04/1996 JLB : Created. *
  363. *=============================================================================================*/
  364. int TechnoClass::How_Many_Survivors(void) const
  365. {
  366. if (Techno_Type_Class()->IsCrew) {
  367. return(1);
  368. }
  369. return(0);
  370. }
  371. /***********************************************************************************************
  372. * TechnoClass::Combat_Damage -- Fetch the amount of damage infliced by the specified weapon. *
  373. * *
  374. * This routine will examine the specified weapon of this object and determine how much *
  375. * damage it could inflict -- best case. *
  376. * *
  377. * INPUT: which -- Which weapon to consider. If -1 is specified, then the average of both *
  378. * weapon types (if present) is returned. *
  379. * *
  380. * OUTPUT: Returns with the combat damage that could be inflicted by the specified weapon. *
  381. * *
  382. * WARNINGS: This routine could return a negative number if a medic is scanned. *
  383. * *
  384. * HISTORY: *
  385. * 09/16/1996 JLB : Created. *
  386. *=============================================================================================*/
  387. int TechnoClass::Combat_Damage(int which) const
  388. {
  389. TechnoTypeClass const * ttype = Techno_Type_Class();
  390. int divisor = 0;
  391. int value = 0;
  392. if (which == 0 || which == -1) {
  393. if (ttype->PrimaryWeapon != NULL) {
  394. value += ttype->PrimaryWeapon->Attack;
  395. divisor += 1;
  396. }
  397. }
  398. if (which == 1 || which == -1) {
  399. if (ttype->SecondaryWeapon != NULL) {
  400. value += ttype->SecondaryWeapon->Attack;
  401. divisor += 1;
  402. }
  403. }
  404. if (divisor > 1) {
  405. return(value / divisor);
  406. }
  407. return(value);
  408. }
  409. /***********************************************************************************************
  410. * TechnoClass::Is_Allowed_To_Recloak -- Can this object recloak? *
  411. * *
  412. * Determine is this object can recloak now and returns that info. Usually the answer is *
  413. * yes, but it can be overridden be derived classes. *
  414. * *
  415. * INPUT: none *
  416. * *
  417. * OUTPUT: bool; Can this object recloak now? (presumes it has the ability to cloak) *
  418. * *
  419. * WARNINGS: none *
  420. * *
  421. * HISTORY: *
  422. * 07/29/1996 JLB : Created. *
  423. *=============================================================================================*/
  424. bool TechnoClass::Is_Allowed_To_Recloak(void) const
  425. {
  426. return(true);
  427. }
  428. /***********************************************************************************************
  429. * TechnoClass::Fire_Coord -- Determine the coordinate where bullets appear. *
  430. * *
  431. * This routine will determine the coordinate to use when this object fires. The coordinate *
  432. * is the location where bullets appear (or fire effects appear) when the object fires *
  433. * its weapon. *
  434. * *
  435. * INPUT: which -- Which weapon is the coordinate to be calculated for? 0 means primary *
  436. * weapon, 1 means secondary weapon. *
  437. * *
  438. * OUTPUT: Returns with the coordinate that any bullets fired from the specified weapon *
  439. * should appear. *
  440. * *
  441. * WARNINGS: none *
  442. * *
  443. * HISTORY: *
  444. * 07/29/1996 JLB : Created. *
  445. *=============================================================================================*/
  446. FireDataType TechnoClass::Fire_Data(int which) const
  447. {
  448. assert(IsActive);
  449. TechnoTypeClass const * tclass = Techno_Type_Class();
  450. int dist = 0;
  451. if (which == 0) {
  452. dist = tclass->PrimaryOffset;
  453. } else {
  454. dist = tclass->SecondaryOffset;
  455. }
  456. COORDINATE coord = Coord_Move(Center_Coord(), DIR_N, tclass->VerticalOffset + Height);
  457. coord = Coord_Move(coord, DIR_E, tclass->HorizontalOffset);
  458. return{coord,dist};
  459. }
  460. COORDINATE TechnoClass::Fire_Coord(int which) const
  461. {
  462. assert(IsActive);
  463. DirType dir = Turret_Facing();
  464. TechnoTypeClass const * tclass = Techno_Type_Class();
  465. int dist = 0;
  466. int lateral = 0;
  467. if (which == 0) {
  468. dist = tclass->PrimaryOffset;
  469. lateral = tclass->PrimaryLateral;
  470. } else {
  471. dist = tclass->SecondaryOffset;
  472. lateral = tclass->SecondaryLateral;
  473. }
  474. COORDINATE coord = Coord_Move(Center_Coord(), DIR_N, tclass->VerticalOffset + Height);
  475. coord = Coord_Move(coord, DIR_E, tclass->HorizontalOffset);
  476. if (IsSecondShot) {
  477. coord = Coord_Move(coord, (DirType)(dir+DIR_E), lateral);
  478. } else {
  479. coord = Coord_Move(coord, (DirType)(dir+DIR_W), lateral);
  480. }
  481. coord = Coord_Move(coord, dir, dist);
  482. return(coord);
  483. }
  484. #ifdef CHEAT_KEYS
  485. /***********************************************************************************************
  486. * TechnoClass::Debug_Dump -- Displays the base class data to the monochrome screen. *
  487. * *
  488. * This routine is used to dump the status of the object class to the monochrome screen. *
  489. * This display can be used to track down or prevent bugs. *
  490. * *
  491. * INPUT: none *
  492. * *
  493. * OUTPUT: none *
  494. * *
  495. * WARNINGS: none *
  496. * *
  497. * HISTORY: *
  498. * 06/02/1994 JLB : Created. *
  499. *=============================================================================================*/
  500. void TechnoClass::Debug_Dump(MonoClass * mono) const
  501. {
  502. assert(IsActive);
  503. mono->Set_Cursor(10, 7);mono->Printf("%2d", Fetch_Rate());
  504. mono->Set_Cursor(14, 7);mono->Printf("%2d", Fetch_Stage());
  505. mono->Set_Cursor(49, 1);mono->Printf("%3d", Ammo);
  506. mono->Set_Cursor(71, 1);mono->Printf("$%4d", PurchasePrice);
  507. mono->Set_Cursor(54, 1);mono->Printf("%3d", (long)Arm);
  508. if (Is_Something_Attached()) {
  509. mono->Set_Cursor(1, 5);mono->Printf("%08X", Attached_Object());
  510. }
  511. if (Target_Legal(TarCom)) {
  512. mono->Set_Cursor(29, 3);mono->Printf("%08X", TarCom);
  513. }
  514. if (Target_Legal(SuspendedTarCom)) {
  515. mono->Set_Cursor(38, 3);mono->Printf("%08X", SuspendedTarCom);
  516. }
  517. if (Target_Legal(ArchiveTarget)) {
  518. mono->Set_Cursor(69, 5);mono->Printf("%08X", ArchiveTarget);
  519. }
  520. mono->Set_Cursor(47, 3);mono->Printf("%02X:%02X", PrimaryFacing.Current(), PrimaryFacing.Desired());
  521. mono->Set_Cursor(64, 1);mono->Printf("%d(%d)", Cloak, CloakingDevice);
  522. mono->Fill_Attrib(14, 15, 12, 1, IsUseless ? MonoClass::INVERSE : MonoClass::NORMAL);
  523. mono->Fill_Attrib(14, 16, 12, 1, IsTickedOff ? MonoClass::INVERSE : MonoClass::NORMAL);
  524. mono->Fill_Attrib(14, 17, 12, 1, IsCloakable ? MonoClass::INVERSE : MonoClass::NORMAL);
  525. mono->Fill_Attrib(27, 13, 12, 1, IsLeader ? MonoClass::INVERSE : MonoClass::NORMAL);
  526. mono->Fill_Attrib(27, 14, 12, 1, IsALoaner ? MonoClass::INVERSE : MonoClass::NORMAL);
  527. mono->Fill_Attrib(27, 15, 12, 1, IsLocked ? MonoClass::INVERSE : MonoClass::NORMAL);
  528. mono->Fill_Attrib(27, 16, 12, 1, IsInRecoilState ? MonoClass::INVERSE : MonoClass::NORMAL);
  529. mono->Fill_Attrib(27, 17, 12, 1, IsTethered ? MonoClass::INVERSE : MonoClass::NORMAL);
  530. mono->Fill_Attrib(40, 13, 12, 1, IsOwnedByPlayer ? MonoClass::INVERSE : MonoClass::NORMAL);
  531. mono->Fill_Attrib(40, 14, 12, 1, IsDiscoveredByPlayer ? MonoClass::INVERSE : MonoClass::NORMAL);
  532. mono->Fill_Attrib(40, 15, 12, 1, IsDiscoveredByComputer ? MonoClass::INVERSE : MonoClass::NORMAL);
  533. mono->Fill_Attrib(40, 16, 12, 1, IsALemon ? MonoClass::INVERSE : MonoClass::NORMAL);
  534. mono->Set_Cursor(47, 17);mono->Printf("%3d", (long)IronCurtainCountDown);
  535. mono->Fill_Attrib(40, 17, 12, 1, IronCurtainCountDown > 0 ? MonoClass::INVERSE : MonoClass::NORMAL);
  536. RadioClass::Debug_Dump(mono);
  537. }
  538. #endif
  539. /***********************************************************************************************
  540. * TechnoClass::TechnoClass -- Default constructor for techno objects. *
  541. * *
  542. * This default constructor for techno objects is used to reset all internal variables to *
  543. * their default state. *
  544. * *
  545. * INPUT: none *
  546. * *
  547. * OUTPUT: none *
  548. * *
  549. * WARNINGS: none *
  550. * *
  551. * HISTORY: *
  552. * 12/09/1994 JLB : Created. *
  553. *=============================================================================================*/
  554. TechnoClass::TechnoClass(RTTIType rtti, int id, HousesType house) :
  555. RadioClass(rtti, id),
  556. IsUseless(false),
  557. IsTickedOff(false),
  558. IsCloakable(false),
  559. IsLeader(false),
  560. IsALoaner(false),
  561. IsLocked(false),
  562. IsInRecoilState(false),
  563. IsTethered(false),
  564. IsOwnedByPlayer(false),
  565. IsDiscoveredByPlayer(false),
  566. IsDiscoveredByComputer(false),
  567. IsALemon(false),
  568. IsSecondShot(true),
  569. ArmorBias(1),
  570. FirepowerBias(1),
  571. IdleTimer(0),
  572. IronCurtainCountDown(0),
  573. SpiedBy(0),
  574. ArchiveTarget(TARGET_NONE),
  575. House(HouseClass::As_Pointer(house)),
  576. Cloak(UNCLOAKED),
  577. TarCom(TARGET_NONE),
  578. SuspendedTarCom(TARGET_NONE),
  579. PrimaryFacing(DIR_N),
  580. Arm(0),
  581. Ammo(-1),
  582. ElectricZapDelay(-1),
  583. ElectricZapTarget(0),
  584. ElectricZapWhich(0),
  585. PurchasePrice(0)
  586. {
  587. //IsOwnedByPlayer = (PlayerPtr == House);
  588. // Added for multiplayer changes. ST - 4/24/2019 10:40AM
  589. IsDiscoveredByPlayerMask = 0;
  590. if (Session.Type == GAME_NORMAL) {
  591. IsOwnedByPlayer = (PlayerPtr == House);
  592. } else {
  593. IsOwnedByPlayer = House->IsHuman;
  594. }
  595. }
  596. /***********************************************************************************************
  597. * TechnoClass::Is_Visible_On_Radar -- Is this object visible on player's radar screen? *
  598. * *
  599. * Use this routine to determine if this object should be visible on the player's radar *
  600. * screen. This routine doesn't take into consideration mapped terrain or whether the *
  601. * radar is active. It merely checks to see that if all else is functioning correctly, *
  602. * is this unit invisible or visible on the radar map. Typically, cloaked vehicles will *
  603. * not be visible. *
  604. * *
  605. * INPUT: none *
  606. * *
  607. * OUTPUT: bool; Is this object nominally visible on the player's radar screen? *
  608. * *
  609. * WARNINGS: none *
  610. * *
  611. * HISTORY: *
  612. * 05/27/1996 JLB : Created. *
  613. *=============================================================================================*/
  614. bool TechnoClass::Is_Visible_On_Radar(void) const
  615. {
  616. /*
  617. ** Hack: MRJ is invisible to radar, unless it's allied with the player.
  618. */
  619. if (What_Am_I() == RTTI_UNIT) {
  620. if(*((UnitClass *)this) == UNIT_MRJ) {
  621. if(!House->Is_Ally(PlayerPtr)) {
  622. return(false);
  623. }
  624. }
  625. }
  626. if (!Is_Cloaked(PlayerPtr, true)) {
  627. return(true);
  628. }
  629. return(false);
  630. }
  631. /***********************************************************************************************
  632. * TechnoClass::Revealed -- Handles revealing an object to the house specified. *
  633. * *
  634. * When a unit moves out from under the shroud or when it gets delivered into already *
  635. * explored terrain, then it must be "revealed". Objects that are revealed may be *
  636. * announced to the player. The discovered bit updated accordingly. *
  637. * *
  638. * INPUT: house -- The house that this object is revealed to. *
  639. * *
  640. * OUTPUT: none *
  641. * *
  642. * WARNINGS: none *
  643. * *
  644. * HISTORY: *
  645. * 06/02/1994 JLB : Created. *
  646. * 12/27/1994 JLB : Discovered trigger event processing. *
  647. *=============================================================================================*/
  648. bool TechnoClass::Revealed(HouseClass * house)
  649. {
  650. assert(IsActive);
  651. /* Replaced by client/server version from TD. ST - 8/7/2019 11:09AM
  652. if (house == PlayerPtr && IsDiscoveredByPlayer) return(false);
  653. if (house != PlayerPtr) {
  654. if (IsDiscoveredByComputer) return(false);
  655. IsDiscoveredByComputer = true;
  656. }
  657. */
  658. if (house == NULL) {
  659. return false;
  660. }
  661. if (Is_Discovered_By_Player(house)) {
  662. return false;
  663. }
  664. if (house->IsHuman == false) {
  665. if (IsDiscoveredByComputer) {
  666. return false;
  667. }
  668. IsDiscoveredByComputer = true;
  669. }
  670. if (RadioClass::Revealed(house)) {
  671. /*
  672. ** An enemy object that is discovered will go into hunt mode if
  673. ** its current mission is to ambush.
  674. */
  675. if (!house->IsHuman && Mission == MISSION_AMBUSH) {
  676. Assign_Mission(MISSION_HUNT);
  677. }
  678. if (Session.Type == GAME_NORMAL) {
  679. if (house == PlayerPtr) {
  680. IsDiscoveredByPlayer = true;
  681. if (!IsOwnedByPlayer) {
  682. /*
  683. ** If there is a trigger event associated with this object, then process
  684. ** it for discovery purposes.
  685. */
  686. if (!ScenarioInit && Trigger.Is_Valid()) {
  687. Trigger->Spring(TEVENT_DISCOVERED, this);
  688. }
  689. /*
  690. ** Alert the enemy house to presence of the friendly side.
  691. */
  692. House->IsDiscovered = true;
  693. if (house->IsHuman) {
  694. Set_Discovered_By_Player(house);
  695. } else {
  696. IsDiscoveredByComputer = true;
  697. }
  698. } else {
  699. if (house->IsHuman) {
  700. Set_Discovered_By_Player(house);
  701. } else {
  702. IsDiscoveredByComputer = true;
  703. }
  704. /*
  705. ** A newly revealed object will always perform a look operation.
  706. */
  707. Look();
  708. }
  709. } else {
  710. IsDiscoveredByComputer = true;
  711. }
  712. } else {
  713. if (house->IsHuman) {
  714. Set_Discovered_By_Player(house);
  715. }
  716. Look();
  717. }
  718. return(true);
  719. }
  720. return(false);
  721. }
  722. /***********************************************************************************************
  723. * TechnoClass::Hidden -- Returns the object back into the hidden state. *
  724. * *
  725. * This routine is called for every object that returns to the darkness shroud or when *
  726. * it gets destroyed. This also occurs when an object enters another (such as infantry *
  727. * entering a transport helicopter). *
  728. * *
  729. * INPUT: none *
  730. * *
  731. * OUTPUT: none *
  732. * *
  733. * WARNINGS: none *
  734. * *
  735. * HISTORY: *
  736. * 06/02/1994 JLB : Created. *
  737. *=============================================================================================*/
  738. void TechnoClass::Hidden(void)
  739. {
  740. assert(IsActive);
  741. //if (!IsDiscoveredByPlayer) return;
  742. if (!Is_Discovered_By_Player()) { // ST - 8/7/2019 11:17AM
  743. return;
  744. }
  745. if (!House->IsHuman) {
  746. Clear_Discovered_By_Players();
  747. }
  748. }
  749. /***********************************************************************************************
  750. * TechnoClass::Mark -- Handles marking of techno objects. *
  751. * *
  752. * On the Techno-level, marking handles transmission of the redraw command to any object *
  753. * that it is 'connected' with. This only occurs during loading and unloading. *
  754. * *
  755. * INPUT: mark -- The marking method. This routine just passes this on to base classes. *
  756. * *
  757. * OUTPUT: none *
  758. * *
  759. * WARNINGS: none *
  760. * *
  761. * HISTORY: *
  762. * 10/17/1994 JLB : Created. *
  763. *=============================================================================================*/
  764. bool TechnoClass::Mark(MarkType mark)
  765. {
  766. assert(IsActive);
  767. if (RadioClass::Mark(mark)) {
  768. /*
  769. ** When redrawing an object, if there is another object tethered to this one,
  770. ** redraw it as well.
  771. */
  772. if (IsTethered) {
  773. Transmit_Message(RADIO_REDRAW);
  774. }
  775. return(true);
  776. }
  777. return(false);
  778. }
  779. /***********************************************************************************************
  780. * TechnoClass::Receive_Message -- Handles inbound message as appropriate. *
  781. * *
  782. * This routine is used to handle inbound radio messages. It only handles those messages *
  783. * that deal with techno objects. Typically, these include loading and unloading. *
  784. * *
  785. * INPUT: from -- Pointer to the originator of the radio message. *
  786. * *
  787. * message -- The inbound radio message. *
  788. * *
  789. * param -- Reference to optional parameter that might be used to transfer *
  790. * more information than is possible with the simple radio message *
  791. * type. *
  792. * *
  793. * OUTPUT: Returns with the radio response. *
  794. * *
  795. * WARNINGS: none *
  796. * *
  797. * HISTORY: *
  798. * 10/17/1994 JLB : Created. *
  799. * 06/17/1995 JLB : Handles tether contact messages. *
  800. *=============================================================================================*/
  801. RadioMessageType TechnoClass::Receive_Message(RadioClass * from, RadioMessageType message, long & param)
  802. {
  803. assert(IsActive);
  804. switch (message) {
  805. /*
  806. ** Just received instructions to attack the specified target.
  807. */
  808. case RADIO_ATTACK_THIS:
  809. if (Techno_Type_Class()->PrimaryWeapon != NULL) {
  810. Assign_Target(param);
  811. Assign_Mission(MISSION_ATTACK);
  812. return(RADIO_ROGER);
  813. }
  814. break;
  815. /*
  816. ** Establish a tethered connection to the object in radio contact.
  817. */
  818. case RADIO_TETHER:
  819. if (!IsTethered) {
  820. IsTethered = true;
  821. Transmit_Message(RADIO_TETHER, from);
  822. return(RADIO_ROGER);
  823. }
  824. break;
  825. /*
  826. ** Break the tethered connection to the object in radio contact.
  827. */
  828. case RADIO_UNTETHER:
  829. if (IsTethered) {
  830. IsTethered = false;
  831. Transmit_Message(RADIO_UNTETHER, from);
  832. return(RADIO_ROGER);
  833. }
  834. break;
  835. /*
  836. ** A tethered unit has reached it's destination. All is
  837. ** clear, so radio contact can be broken.
  838. */
  839. case RADIO_UNLOADED:
  840. Transmit_Message(RADIO_UNTETHER, from);
  841. return(Transmit_Message(RADIO_OVER_OUT, from));
  842. /*
  843. ** When this message is received, it means that the other object
  844. ** has already turned its radio off. Turn this radio off as well.
  845. */
  846. case RADIO_OVER_OUT:
  847. Transmit_Message(RADIO_UNTETHER, from);
  848. RadioClass::Receive_Message(from, message, param);
  849. return(RADIO_ROGER);
  850. /*
  851. ** Request to be informed when unloaded. This message is transmitted
  852. ** by the transport unit to the transported unit as it is about to be
  853. ** unloaded. It is saying, "All is clear. Drive off now."
  854. */
  855. case RADIO_UNLOAD:
  856. case RADIO_BACKUP_NOW:
  857. case RADIO_HOLD_STILL:
  858. Transmit_Message(RADIO_TETHER, from);
  859. RadioClass::Receive_Message(from, message, param);
  860. return(RADIO_ROGER);
  861. /*
  862. ** Handle reloading one ammo point for this unit.
  863. */
  864. case RADIO_RELOAD:
  865. if (Ammo == Techno_Type_Class()->MaxAmmo) return(RADIO_NEGATIVE);
  866. /*BG*/ Mark(MARK_CHANGE_REDRAW);
  867. Ammo++;
  868. return(RADIO_ROGER);
  869. /*
  870. ** Handle repair of this unit.
  871. */
  872. case RADIO_REPAIR:
  873. /*
  874. ** If it's a mine layer, re-arm him if he's empty. This always takes precedence
  875. ** over repair, since this operation is free.
  876. */
  877. if (What_Am_I() == RTTI_UNIT && *((UnitClass *)this) == UNIT_MINELAYER && ((UnitClass *)this)->Ammo < ((UnitClass *)this)->Class->MaxAmmo) {
  878. ((UnitClass *)this)->Ammo = ((UnitClass *)this)->Class->MaxAmmo;
  879. return(RADIO_NEGATIVE);
  880. }
  881. /*
  882. ** Determine if this unit can be repaired becaause it is under strength. If so, then
  883. ** proceed with the repair process.
  884. */
  885. if (Health_Ratio() < Rule.ConditionGreen) {
  886. int cost = Techno_Type_Class()->Repair_Cost();
  887. cost = max(cost, 1);
  888. int step = Techno_Type_Class()->Repair_Step();
  889. step = max(step, 1);
  890. /*
  891. ** If there is sufficient money to repair the unit one step, then do so.
  892. ** Otherwise return with a "can't complete" radio response.
  893. ** Special case: in single-player campaigns, also try to use the repair pad house's money.
  894. */
  895. HouseClass* house = House;
  896. if (Session.Type == GAME_NORMAL && house->Available_Money() < cost) {
  897. house = HouseClass::As_Pointer(from->Owner());
  898. }
  899. if (house != NULL && house->Available_Money() >= cost) {
  900. house->Spend_Money(cost);
  901. Strength += step;
  902. /*
  903. ** Return with either an all ok or mission accomplished radio message. This
  904. ** lets the repairing object know if it should abort the repair control process
  905. ** or continue it.
  906. */
  907. if (Health_Ratio() < Rule.ConditionGreen) {
  908. return(RADIO_ROGER);
  909. } else {
  910. Strength = Techno_Type_Class()->MaxStrength;
  911. return(RADIO_ALL_DONE);
  912. }
  913. } else {
  914. return(RADIO_CANT);
  915. }
  916. }
  917. return(RADIO_NEGATIVE);
  918. default:
  919. break;
  920. }
  921. return(RadioClass::Receive_Message(from, message, param));
  922. }
  923. /***********************************************************************************************
  924. * TechnoClass::Per_Cell_Process -- Handles once-per-cell operations for techno type objects. *
  925. * *
  926. * This routine handles marking a game object as not a loaner. It is set only if the unit *
  927. * is not player owned and is on the regular map. This is necessary so that enemy objects *
  928. * can exist off-map but as soon as they move onto the map, are flagged so that can never *
  929. * leave it again. *
  930. * *
  931. * INPUT: why -- Specifies the circumstances under which this routine was called. *
  932. * *
  933. * OUTPUT: none *
  934. * *
  935. * WARNINGS: none *
  936. * *
  937. * HISTORY: *
  938. * 10/17/1994 JLB : Created. *
  939. * 10/26/94 JLB : Handles scanner units. *
  940. * 12/27/1994 JLB : Checks for an processes any trigger in cell. *
  941. *=============================================================================================*/
  942. void TechnoClass::Per_Cell_Process(PCPType why)
  943. {
  944. assert(IsActive);
  945. if (why == PCP_END) {
  946. CELL cell = Coord_Cell(Center_Coord());
  947. /*
  948. ** When enemy units enter the proper map area from off map, they are
  949. ** flagged so that they won't travel back off the map again.
  950. */
  951. if (!IsLocked && Map.In_Radar(cell)) {
  952. IsLocked = true;
  953. }
  954. /*
  955. ** If this object somehow moves into mapped terrain, but is not yet
  956. ** discovered, then flag it to be discovered.
  957. */
  958. // Change for client/server multiplayer ST - 8/7/2019 11:19AM
  959. //if (!IsDiscoveredByPlayer && Map[cell].IsVisible) {
  960. //Revealed(PlayerPtr);
  961. if (!Is_Discovered_By_Player() && Map[cell].Is_Visible(House)) {
  962. Revealed(House);
  963. }
  964. }
  965. }
  966. /***********************************************************************************************
  967. * TechnoClass::Draw_It -- Draws the health bar (if necessary). *
  968. * *
  969. * This routine will draw the common elements for techno type objects. This element is *
  970. * the health bar. The main game object has already been rendered by the time this *
  971. * routine is called. *
  972. * *
  973. * INPUT: x,y -- The coordinate of the center of the unit. *
  974. * *
  975. * OUTPUT: none *
  976. * *
  977. * WARNINGS: none *
  978. * *
  979. * HISTORY: *
  980. * 10/17/1994 JLB : Created. *
  981. * 10/26/94 JLB : Knows about radar scanned cells. *
  982. * 12/13/1994 JLB : Clips health bar against map edge. *
  983. * 01/23/1995 JLB : Dynamic selected object rectangle. *
  984. *=============================================================================================*/
  985. void TechnoClass::Draw_It(int x, int y, WindowNumberType window) const
  986. {
  987. assert(IsActive);
  988. /*
  989. ** Tells the door logic that it has been drawn.
  990. */
  991. ((TechnoClass *)this)->Clear_Redraw_Flag();
  992. /*
  993. ** Draw electric zap
  994. */
  995. if ((ElectricZapDelay >= 0) && ElectricZapTarget) {
  996. Electric_Zap(ElectricZapTarget, ElectricZapWhich, window);
  997. }
  998. int width, height;
  999. Class_Of().Dimensions(width, height);
  1000. const bool show_health_bar = (Strength > 0) && !Is_Cloaked(PlayerPtr) && (Is_Selected_By_Player() ||
  1001. ((Rule.HealthBarDisplayMode == RulesClass::HB_DAMAGED) && (Strength < Techno_Type_Class()->MaxStrength)) ||
  1002. (Rule.HealthBarDisplayMode == RulesClass::HB_ALWAYS));
  1003. /*
  1004. ** Draw the selected object graphic.
  1005. */
  1006. int lx = width / 2;
  1007. int ly = height / 2;
  1008. int dx = width / 5;
  1009. int dy = height / 5;
  1010. int fudge = show_health_bar ? 4 : 0;
  1011. if (What_Am_I() == RTTI_VESSEL) {
  1012. lx = width / 2;
  1013. }
  1014. //if (IsSelected) {
  1015. if (Is_Selected_By_Player() || show_health_bar) {
  1016. GraphicViewPortClass draw_window( LogicPage->Get_Graphic_Buffer(),
  1017. WindowList[window][WINDOWX] + LogicPage->Get_XPos(),
  1018. WindowList[window][WINDOWY] + LogicPage->Get_YPos(),
  1019. WindowList[window][WINDOWWIDTH],
  1020. WindowList[window][WINDOWHEIGHT]);
  1021. /*
  1022. ** The infantry select box should be a bit higher than normal.
  1023. */
  1024. if (What_Am_I() == RTTI_INFANTRY) {
  1025. y -= 6;
  1026. }
  1027. if (What_Am_I() == RTTI_BUILDING && ((BuildingTypeClass const &)Class_Of()).Type == STRUCT_BARRACKS) {
  1028. y -= 5;
  1029. }
  1030. /*
  1031. ** Fetch the dimensions of the object. These dimensions will be used to draw
  1032. ** the selection box and the health bar.
  1033. */
  1034. if (show_health_bar) {
  1035. fixed ratio = Health_Ratio();
  1036. int pwidth; // Pixel width of bar interior.
  1037. int color; // The color to give the interior of the bargraph.
  1038. int xx = x-width/2;
  1039. int yy = y-(height/2);
  1040. /*
  1041. ** Draw the outline of the bargraph.
  1042. */
  1043. draw_window.Remap(xx+1, yy+1, width-1, 3-1, Map.FadingShade);
  1044. draw_window.Draw_Rect(xx, yy, xx+width-1, yy+3, BLACK);
  1045. /*
  1046. ** Determine the width of the interior strength
  1047. ** graph.
  1048. */
  1049. pwidth = (width-2) * ratio;
  1050. pwidth = Bound(pwidth, 1, width-2);
  1051. color = LTGREEN;
  1052. if (ratio <= Rule.ConditionYellow) {
  1053. color = YELLOW;
  1054. }
  1055. if (ratio <= Rule.ConditionRed) {
  1056. color = RED;
  1057. }
  1058. draw_window.Fill_Rect(xx+1, yy+1, xx+pwidth, yy+(3-1), color);
  1059. }
  1060. /*
  1061. ** Draw the selected object graphic.
  1062. */
  1063. if (Is_Selected_By_Player()) {
  1064. // Upper left corner.
  1065. draw_window.Draw_Line(x - lx, fudge + y - ly, x - lx + dx, fudge + y - ly, WHITE);
  1066. draw_window.Draw_Line(x - lx, fudge + y - ly, x - lx, fudge + y - ly + dy, WHITE);
  1067. // Upper right corner.
  1068. draw_window.Draw_Line(x + lx, fudge + y - ly, x + lx - dx, fudge + y - ly, WHITE);
  1069. draw_window.Draw_Line(x + lx, fudge + y - ly, x + lx, fudge + y - ly + dy, WHITE);
  1070. // Lower right corner.
  1071. draw_window.Draw_Line(x + lx, y + ly, x + lx - dx, y + ly, WHITE);
  1072. draw_window.Draw_Line(x + lx, y + ly, x + lx, y + ly - dy, WHITE);
  1073. // Lower left corner.
  1074. draw_window.Draw_Line(x - lx, y + ly, x - lx + dx, y + ly, WHITE);
  1075. draw_window.Draw_Line(x - lx, y + ly, x - lx, y + ly - dy, WHITE);
  1076. }
  1077. }
  1078. // MBL 04.21.2020
  1079. bool selected = Is_Selected_By_Player() || Rule.ResourceBarDisplayMode == RulesClass::RB_ALWAYS;
  1080. // if ((window == WINDOW_VIRTUAL) || (Is_Selected_By_Player() && (House->Is_Ally(PlayerPtr) || (Spied_By() & (1 << (PlayerPtr->Class->House))))))
  1081. if ((window == WINDOW_VIRTUAL) || (selected && (House->Is_Ally(PlayerPtr) || (Spied_By() & (1 << (PlayerPtr->Class->House))))))
  1082. {
  1083. Draw_Pips((x-lx)+5, y+ly-3, window);
  1084. }
  1085. }
  1086. /***********************************************************************************************
  1087. * TechnoClass::Unlimbo -- Performs unlimbo process for all techno type objects. *
  1088. * *
  1089. * This routine handles the common operation between techno objects when they are *
  1090. * unlimboed. This includes revealing the map. *
  1091. * *
  1092. * INPUT: coord -- The coordinate to unlimbo object at. *
  1093. * *
  1094. * dir (optional) -- initial facing direction for this object *
  1095. * *
  1096. * OUTPUT: bool; Was the unlimbo successful? *
  1097. * *
  1098. * WARNINGS: none *
  1099. * *
  1100. * HISTORY: *
  1101. * 11/14/1994 JLB : Created. *
  1102. *=============================================================================================*/
  1103. bool TechnoClass::Unlimbo(COORDINATE coord, DirType dir)
  1104. {
  1105. assert(IsActive);
  1106. if (RadioClass::Unlimbo(coord, dir)) {
  1107. PrimaryFacing = dir;
  1108. Enter_Idle_Mode(true);
  1109. Commence();
  1110. IsLocked = Map.In_Radar(Coord_Cell(coord));
  1111. return(true);
  1112. }
  1113. return(false);
  1114. }
  1115. /***********************************************************************************************
  1116. * TechnoClass::In_Range -- Determines if specified target is within weapon range. *
  1117. * *
  1118. * This routine is used to compare the distance to the specified target with the range *
  1119. * of the weapon. If the target is outside of weapon range, then false is returned. *
  1120. * *
  1121. * INPUT: target -- The target to check if it is within weapon range. *
  1122. * *
  1123. * which -- Which weapon to use in determining range. 0=primary, 1=secondary. *
  1124. * *
  1125. * OUTPUT: bool; Is the specified target within weapon range? *
  1126. * *
  1127. * WARNINGS: none *
  1128. * *
  1129. * HISTORY: *
  1130. * 11/14/1994 JLB : Created. *
  1131. *=============================================================================================*/
  1132. bool TechnoClass::In_Range(TARGET target, int which, bool reciprocal_check) const
  1133. {
  1134. assert(IsActive);
  1135. if (IsLocked && Target_Legal(target)) {
  1136. int range = Weapon_Range(which);
  1137. BuildingClass const * building = As_Building(target);
  1138. if (building != NULL) {
  1139. range += ((building->Class->Width() + building->Class->Height()) * (ICON_LEPTON_W / 4));
  1140. }
  1141. FireDataType data = Fire_Data(which);
  1142. if (MAX(0, ::Distance(data.Center, As_Coord(target)) - data.Distance) <= range) {
  1143. return(true);
  1144. }
  1145. /*
  1146. ** There's a longstanding bug where enemy units aligned north/south may have different perceptions of whether they
  1147. ** are in range of each other due to the turrets offset on the unit. This check will say that if either considers the
  1148. ** the other to be in range, then they both do. ST - 3/18/2020 10:44AM
  1149. */
  1150. if (reciprocal_check && !building) {
  1151. ObjectClass *target_object = As_Object(target);
  1152. if (target_object) {
  1153. RTTIType my_type = What_Am_I();
  1154. if (target_object->What_Am_I() == my_type) {
  1155. if (range == target_object->Weapon_Range(which)) {
  1156. TechnoClass *tech = As_Techno(target);
  1157. if (tech->In_Range(As_Target(), which, false)) {
  1158. return true;
  1159. }
  1160. }
  1161. }
  1162. }
  1163. }
  1164. }
  1165. return(false);
  1166. }
  1167. /***********************************************************************************************
  1168. * TechnoClass::In_Range -- Determines if specified target is within weapon range. *
  1169. * *
  1170. * This routine will determine if the pointer to the target object passed into this *
  1171. * routine is within weapon range. *
  1172. * *
  1173. * INPUT: target -- Pointer to the target object to check if within weapon range. *
  1174. * *
  1175. * which -- Which weapon to use in determining range. 0=primary, 1=secondary. *
  1176. * *
  1177. * OUTPUT: bool; Is the target within weapon range? *
  1178. * *
  1179. * WARNINGS: none *
  1180. * *
  1181. * HISTORY: *
  1182. * 11/14/1994 JLB : Created. *
  1183. *=============================================================================================*/
  1184. bool TechnoClass::In_Range(ObjectClass const * target, int which, bool reciprocal_check) const
  1185. {
  1186. assert(IsActive);
  1187. if (IsLocked && target) {
  1188. int range = Weapon_Range(which);
  1189. if (target->What_Am_I() == RTTI_BUILDING) {
  1190. BuildingClass const * building = (BuildingClass const *)target;
  1191. range += ((building->Class->Width() + building->Class->Height()) * (ICON_LEPTON_W / 4));
  1192. }
  1193. FireDataType data = Fire_Data(which);
  1194. if (MAX(0, ::Distance(data.Center, target->Center_Coord()) - data.Distance) <= range) {
  1195. return(true);
  1196. }
  1197. /*
  1198. ** There's a longstanding bug where enemy units aligned north/south may have different perceptions of whether they
  1199. ** are in range of each other due to the turrets offset on the unit. This check will say that if either considers the
  1200. ** the other to be in range, then they both do. ST - 3/18/2020 10:44AM
  1201. */
  1202. if (reciprocal_check) {
  1203. RTTIType my_type = What_Am_I();
  1204. if (my_type != RTTI_BUILDING) {
  1205. if (target->What_Am_I() == my_type) {
  1206. if (range == target->Weapon_Range(which)) {
  1207. if (((TechnoClass*)target)->In_Range(this, which, false)) {
  1208. return true;
  1209. }
  1210. }
  1211. }
  1212. }
  1213. }
  1214. }
  1215. return(false);
  1216. }
  1217. /***********************************************************************************************
  1218. * TechnoClass::In_Range -- Determines if the specified coordinate is within range. *
  1219. * *
  1220. * Use this routine to determine if the specified coordinate is within weapon range. *
  1221. * *
  1222. * INPUT: coord -- The coordinate to examine against the object to determine range. *
  1223. * *
  1224. * which -- The weapon to consider when determining range. 0=primary, 1=secondary. *
  1225. * *
  1226. * OUTPUT: bool; Is the weapon within range? *
  1227. * *
  1228. * WARNINGS: none *
  1229. * *
  1230. * HISTORY: *
  1231. * 03/16/1995 JLB : Created. *
  1232. *=============================================================================================*/
  1233. bool TechnoClass::In_Range(COORDINATE coord, int which) const
  1234. {
  1235. assert(IsActive);
  1236. return(IsLocked && ::Distance(Fire_Coord(which), coord) <= Weapon_Range(which));
  1237. }
  1238. /***********************************************************************************************
  1239. * TechnoClass::Area_Modify -- Determine the area scan modifier for the cell. *
  1240. * *
  1241. * This routine scans around the cell specified and if there are any friendly buildings *
  1242. * nearby, the multiplier return value will be reduced. If there are no friendly buildings *
  1243. * nearby, then the return value will be 1. It checks to see if the primary weapon is *
  1244. * supposed to perform this scan and if so, the scan will be performed. Otherwise the *
  1245. * default value is quickly returned. *
  1246. * *
  1247. * INPUT: cell -- The cell where the potential target lies. An area around this cell will *
  1248. * be scanned for friendly buildings. *
  1249. * *
  1250. * OUTPUT: Returns with the multiplier to be multiplied by the potential target score value. *
  1251. * For less opportune targets, the multiplier fraction will be less than one. For *
  1252. * all other cases, it will return the default value of 1. *
  1253. * *
  1254. * WARNINGS: none *
  1255. * *
  1256. * HISTORY: *
  1257. * 08/23/1996 JLB : Created. *
  1258. *=============================================================================================*/
  1259. fixed TechnoClass::Area_Modify(CELL cell) const
  1260. {
  1261. // assert(Techno_Type_Class()->PrimaryWeapon != NULL);
  1262. if (Techno_Type_Class()->PrimaryWeapon == NULL || !Techno_Type_Class()->PrimaryWeapon->IsSupressed) return(1);
  1263. int crange = Lepton_To_Cell(Rule.SupressRadius);
  1264. fixed odds = 1;
  1265. for (int radius = 1; radius < crange; radius++) {
  1266. /*
  1267. ** Scan the top and bottom rows of the "box".
  1268. */
  1269. for (int x = -radius; x <= radius; x++) {
  1270. CELL newcell;
  1271. if ((Cell_X(cell) + x) < Map.MapCellX) continue;
  1272. if ((Cell_X(cell) + x) >= (Map.MapCellX+Map.MapCellWidth)) continue;
  1273. if ((Cell_Y(cell) - radius) >= Map.MapCellY) {
  1274. newcell = XY_Cell(Cell_X(cell) + x, Cell_Y(cell)-radius);
  1275. BuildingClass const * building = Map[newcell].Cell_Building();
  1276. if (building != NULL && House->Is_Ally(building)) {
  1277. odds /= 2;
  1278. }
  1279. }
  1280. if ((Cell_Y(cell) + radius) < (Map.MapCellY+Map.MapCellHeight)) {
  1281. newcell = XY_Cell(Cell_X(cell)+x, Cell_Y(cell)+radius);
  1282. BuildingClass const * building = Map[newcell].Cell_Building();
  1283. if (building != NULL && House->Is_Ally(building)) {
  1284. odds /= 2;
  1285. }
  1286. }
  1287. }
  1288. /*
  1289. ** Scan the left and right columns of the "box".
  1290. */
  1291. for (int y = -(radius-1); y < radius; y++) {
  1292. CELL newcell;
  1293. if ((Cell_Y(cell) + y) < Map.MapCellY) continue;
  1294. if ((Cell_Y(cell) + y) >= (Map.MapCellY+Map.MapCellHeight)) continue;
  1295. if ((Cell_X(cell) - radius) >= Map.MapCellX) {
  1296. newcell = XY_Cell(Cell_X(cell)-radius, Cell_Y(cell)+y);
  1297. BuildingClass const * building = Map[newcell].Cell_Building();
  1298. if (building != NULL && House->Is_Ally(building)) {
  1299. odds /= 2;
  1300. }
  1301. }
  1302. if ((Cell_X(cell) + radius) < (Map.MapCellX+Map.MapCellWidth)) {
  1303. newcell = XY_Cell(Cell_X(cell)+radius, Cell_Y(cell)+y);
  1304. BuildingClass const * building = Map[newcell].Cell_Building();
  1305. if (building != NULL && House->Is_Ally(building)) {
  1306. odds /= 2;
  1307. }
  1308. }
  1309. }
  1310. }
  1311. return(odds);
  1312. }
  1313. /***********************************************************************************************
  1314. * TechnoClass::Evaluate_Object -- Determines score value of specified object. *
  1315. * *
  1316. * This routine is used to determine the score value (value as a potential target) of the *
  1317. * object specified. This routine will check the specified object for all the various *
  1318. * legality checks that threat scanning requires. This is the main workhorse routine for *
  1319. * target searching. *
  1320. * *
  1321. * INPUT: method -- The threat method requested. This is a combined bitflag value that *
  1322. * not only specifies the kind of targets to consider, but how far away *
  1323. * they are allowed to be. *
  1324. * *
  1325. * mask -- This is an RTTI mask to use for quickly eliminating object types. *
  1326. * The mask is created outside of this routine because this routine is *
  1327. * usually called from within a loop and this value is constant in that *
  1328. * context. *
  1329. * *
  1330. * range -- The range at which potential target objects are rejected. *
  1331. * 0 = must be within weapon range. *
  1332. * >0 = must be within this lepton distance. *
  1333. * <0 = range doesn't matter. *
  1334. * *
  1335. * object -- Pointer to the object itself. *
  1336. * *
  1337. * value -- Reference to the value variable that this routine will fill in. The *
  1338. * higher the value the more likely this object will be selected as best. *
  1339. * *
  1340. * zone -- The zone restriction if any. A -1 means no zone check required. *
  1341. * *
  1342. * OUTPUT: Did the target pass all legality checks? If this value is returned true, then the *
  1343. * value parameter will be filled in correctly. *
  1344. * *
  1345. * WARNINGS: This routine is time consuming. Don't call unless necessary. *
  1346. * *
  1347. * HISTORY: *
  1348. * 06/30/1995 JLB : Created. *
  1349. * 07/14/1995 JLB : Forces SAM site to not fire on landed aircraft. *
  1350. * 09/22/1995 JLB : Zone checking enabled. *
  1351. * 10/05/1995 JLB : Gives greater weight to designated enemy house targets. *
  1352. * 02/16/1996 JLB : Added additional threat checks. *
  1353. *=============================================================================================*/
  1354. bool TechnoClass::Evaluate_Object(ThreatType method, int mask, int range, TechnoClass const * object, int & value, int zone) const
  1355. {
  1356. assert(IsActive);
  1357. assert(object != NULL);
  1358. BStart(BENCH_EVAL_OBJECT);
  1359. /*
  1360. ** An object in limbo can never be a valid target.
  1361. */
  1362. if (object == NULL || object->IsInLimbo) {
  1363. BEnd(BENCH_EVAL_OBJECT);
  1364. return(false);
  1365. }
  1366. /*
  1367. ** If the object is cloaked, then it isn't a legal target.
  1368. */
  1369. if (object->Is_Cloaked(this)) {
  1370. BEnd(BENCH_EVAL_OBJECT);
  1371. return(false);
  1372. }
  1373. /*
  1374. ** If the object is in a "harmless" state, then don't bother to consider it
  1375. ** a threat.
  1376. */
  1377. if (MissionControl[object->Mission].IsNoThreat) {
  1378. BEnd(BENCH_EVAL_OBJECT);
  1379. return(false);
  1380. }
  1381. /*
  1382. ** If the object is not within the desired zone, then ignore it, but only if
  1383. ** zone checking is desired.
  1384. */
  1385. COORDINATE objectcoord = object->Center_Coord();
  1386. if (zone != -1 && Map[objectcoord].Zones[Techno_Type_Class()->MZone] != zone) {
  1387. BEnd(BENCH_EVAL_OBJECT);
  1388. return(false);
  1389. }
  1390. /*
  1391. ** Friendly units are never considered a good target. Bail if this
  1392. ** object is a friend. Unless we're a medic, of course. But then,
  1393. ** only consider it a target if it's injured.
  1394. */
  1395. bool is_ally = House->Is_Ally(object);
  1396. bool is_medic = Combat_Damage() < 0;
  1397. bool green_health = object->Health_Ratio() == Rule.ConditionGreen;
  1398. if ((is_ally && (!is_medic || green_health)) || (!is_ally && is_medic)) {
  1399. BEnd(BENCH_EVAL_OBJECT);
  1400. return(false);
  1401. }
  1402. /*
  1403. ** If the object is further away than allowed, bail.
  1404. */
  1405. int dist = Distance(object);
  1406. if (range > 0 && dist > range) {
  1407. BEnd(BENCH_EVAL_OBJECT);
  1408. return(false);
  1409. }
  1410. if (range == 0) {
  1411. int primary = What_Weapon_Should_I_Use(object->As_Target());
  1412. if (!In_Range(object, primary)) {
  1413. BEnd(BENCH_EVAL_OBJECT);
  1414. return(false);
  1415. }
  1416. }
  1417. /*
  1418. ** If the object is not visible, then bail. Human controlled units
  1419. ** are always considered to be visible.
  1420. */
  1421. if (!object->IsOwnedByPlayer && !object->IsDiscoveredByPlayer && Session.Type == GAME_NORMAL && object->What_Am_I() != RTTI_AIRCRAFT) {
  1422. BEnd(BENCH_EVAL_OBJECT);
  1423. return(false);
  1424. }
  1425. /*
  1426. ** Quickly eliminate all unit types that are not allowed according to the mask
  1427. ** value.
  1428. */
  1429. RTTIType otype = object->What_Am_I();
  1430. if (!((1 << otype) & mask)) {
  1431. BEnd(BENCH_EVAL_OBJECT);
  1432. return(false); // Mask failure.
  1433. }
  1434. /*
  1435. ** Determine if the target is theoretically allowed to be a target. If
  1436. ** not, then bail.
  1437. */
  1438. TechnoTypeClass const * tclass = object->Techno_Type_Class();
  1439. if (!tclass->IsLegalTarget) {
  1440. BEnd(BENCH_EVAL_OBJECT);
  1441. return(false); // Legality failure.
  1442. }
  1443. /*
  1444. ** Never consider a spy to be a valid target, unless you're a dog
  1445. */
  1446. if (otype == RTTI_INFANTRY && ((InfantryTypeClass const *)tclass)->Type == INFANTRY_SPY) {
  1447. if (What_Am_I() == RTTI_INFANTRY && ((InfantryClass *)this)->Class->IsDog) {
  1448. // continue executing...
  1449. } else {
  1450. BEnd(BENCH_EVAL_OBJECT);
  1451. return(false);
  1452. }
  1453. }
  1454. /*
  1455. ** Special case so that SAM site doesn't fire on aircraft that are landed.
  1456. */
  1457. if (otype == RTTI_AIRCRAFT && What_Am_I() == RTTI_BUILDING && *((BuildingClass *)this) == STRUCT_SAM) {
  1458. if (((AircraftClass *)object)->Height == 0) {
  1459. BEnd(BENCH_EVAL_OBJECT);
  1460. return(false);
  1461. }
  1462. }
  1463. /*
  1464. ** If only allowed to attack civilians, then eliminate all other types.
  1465. */
  1466. if ((method & THREAT_CIVILIANS) && object->Owner() != HOUSE_NEUTRAL) {
  1467. BEnd(BENCH_EVAL_OBJECT);
  1468. return(false);
  1469. }
  1470. /*
  1471. ** If the scan is limited to capturable buildings only, then bail if the examined
  1472. ** object isn't a capturable building.
  1473. */
  1474. if ((method & THREAT_CAPTURE) && (otype != RTTI_BUILDING || !object->Can_Capture())) {
  1475. BEnd(BENCH_EVAL_OBJECT);
  1476. return(false);
  1477. }
  1478. /*
  1479. ** If we're a sub and the subject is a structure, bail if the structure
  1480. ** is other than a sub pen or shipyard.
  1481. */
  1482. if (otype == RTTI_BUILDING && What_Am_I() == RTTI_VESSEL && *(VesselClass *)this == VESSEL_SS) {
  1483. StructType ostruc = *(BuildingClass *)object;
  1484. if (ostruc != STRUCT_SUB_PEN && ostruc != STRUCT_SHIP_YARD) {
  1485. BEnd(BENCH_EVAL_OBJECT);
  1486. return(false);
  1487. }
  1488. }
  1489. /*
  1490. ** SPECIAL CASE: Friendly units won't automatically fire on buildings
  1491. ** if the building is not aggressive. That is, unless it is part of a team. A team
  1492. ** is allowed to pick any target it so chooses.
  1493. */
  1494. if ((!Is_Foot() || !((FootClass *)this)->Team.Is_Valid()) &&
  1495. (House->IsHuman || (House->IsPlayerControl && Session.Type == GAME_NORMAL)) &&
  1496. otype == RTTI_BUILDING && tclass->PrimaryWeapon == NULL) {
  1497. #ifdef OBSOLETE
  1498. if ((!Is_Foot() || ((FootClass *)this)->Team.Is_Valid()) && House->IsHuman && otype == RTTI_BUILDING && tclass->PrimaryWeapon == NULL) {
  1499. #endif
  1500. BEnd(BENCH_EVAL_OBJECT);
  1501. return(false);
  1502. }
  1503. /*
  1504. ** Player-controlled demo trucks never automatically target.
  1505. */
  1506. if ((House->IsHuman || (House->IsPlayerControl && Session.Type == GAME_NORMAL)) && What_Am_I() == RTTI_UNIT && *(UnitClass *)this == UNIT_DEMOTRUCK) {
  1507. BEnd(BENCH_EVAL_OBJECT);
  1508. return(false);
  1509. }
  1510. /*
  1511. ** If the search is restricted to Tiberium processing objects, then
  1512. ** perform the special qualification check now.
  1513. */
  1514. if (method & THREAT_TIBERIUM) {
  1515. switch (otype) {
  1516. case RTTI_UNIT:
  1517. if (!((UnitTypeClass const *)tclass)->IsToHarvest) {
  1518. BEnd(BENCH_EVAL_OBJECT);
  1519. return(false);
  1520. }
  1521. break;
  1522. case RTTI_BUILDING:
  1523. if (!((BuildingTypeClass const *)tclass)->Capacity && Session.Type != GAME_NORMAL) {
  1524. BEnd(BENCH_EVAL_OBJECT);
  1525. return(false);
  1526. }
  1527. break;
  1528. default:
  1529. BEnd(BENCH_EVAL_OBJECT);
  1530. return(false);
  1531. }
  1532. }
  1533. /*
  1534. ** If this target value is better than the previously recorded best
  1535. ** target value then record this target for possible return as the
  1536. ** best.
  1537. */
  1538. int rawval = object->Value();
  1539. value = rawval + object->Crew.Kills;
  1540. /*
  1541. ** If the candidate object is owned by the designated enemy of this house, then
  1542. ** give it a higher value. This will tend to gravitate attacks toward the main
  1543. ** antagonist of this house.
  1544. */
  1545. if (House->Enemy != HOUSE_NONE && House->Enemy == object->House->Class->House) {
  1546. value += 500;
  1547. value *= 3;
  1548. }
  1549. /*
  1550. ** If the object is outside of the protective umbrella of the enemy base, then give it
  1551. ** a target boost value.
  1552. */
  1553. if (object->House->Which_Zone(object) == ZONE_NONE) {
  1554. value *= 2;
  1555. }
  1556. /*
  1557. ** If fake buildings are considered to be a greater target option, then boost
  1558. ** the fake building's value.
  1559. */
  1560. if ((method & THREAT_FAKES) && otype == RTTI_BUILDING) {
  1561. //switch (!((BuildingTypeClass const *)tclass)->Type) {
  1562. //The '!' in front of the expression means we are switching on a bool instead of the type. Going to remove it so it compiles, but it might change behavior depending on what Watcom original made of this.
  1563. //Might be better to remove this switch altogether
  1564. //ST - 5/9/2019
  1565. switch (((BuildingTypeClass const *)tclass)->Type) {
  1566. case STRUCT_FAKECONST:
  1567. case STRUCT_FAKEWEAP:
  1568. case STRUCT_FAKE_YARD:
  1569. case STRUCT_FAKE_PEN:
  1570. case STRUCT_FAKE_RADAR:
  1571. break;
  1572. /*
  1573. ** Ignore all non-fake buildings.
  1574. */
  1575. default:
  1576. value = 0;
  1577. break;
  1578. }
  1579. }
  1580. /*
  1581. ** If power plants are to be considered a greater threat, then increase
  1582. ** their value here. Buildings that produce no power are not considered
  1583. ** a threat.
  1584. */
  1585. if ((method & THREAT_POWER) && otype == RTTI_BUILDING) {
  1586. if (((BuildingTypeClass const *)tclass)->Power > 0) {
  1587. value += ((BuildingTypeClass const *)tclass)->Power * 1000;
  1588. } else {
  1589. value = 0;
  1590. }
  1591. }
  1592. /*
  1593. ** If factories are to be considered a greater threat, then don't
  1594. ** consider any non-factory building.
  1595. */
  1596. if ((method & THREAT_FACTORIES) && otype == RTTI_BUILDING) {
  1597. if (((BuildingTypeClass const *)tclass)->ToBuild == RTTI_NONE) {
  1598. value = 0;
  1599. }
  1600. }
  1601. /*
  1602. ** If base defensive structures are to be considered a greater threat, then
  1603. ** don't consider an unarmed building to be a threat.
  1604. */
  1605. if ((method & THREAT_BASE_DEFENSE) /*&& otype == RTTI_BUILDING*/) {
  1606. if (tclass->PrimaryWeapon == NULL) {
  1607. value = 0;
  1608. }
  1609. }
  1610. /*
  1611. ** Possibly cause a reduction of the target's value if it is nearby friendly
  1612. ** structures and the primary weapon of this object is flagged for
  1613. ** friendly fire supression special check logic.
  1614. */
  1615. fixed areamod = Area_Modify(Coord_Cell(object->Center_Coord()));
  1616. if (areamod != 1) {
  1617. value = areamod * value;
  1618. }
  1619. /*
  1620. ** Adjust the target value upward if it is in the 'nervous zone' of the
  1621. ** owning base. This will tend to protect the base more thoroughly than
  1622. ** an unmodified scan would.
  1623. */
  1624. if (House->Which_Zone(object) != ZONE_NONE) {
  1625. value *= Rule.NervousBias;
  1626. }
  1627. /*
  1628. ** Lessen threat as a factor of distance.
  1629. */
  1630. if (value) {
  1631. // if (rawval) {
  1632. value = (value * 32000) / ((dist/ICON_LEPTON_W)+1);
  1633. // value = (value * 32000) / (((dist/ICON_LEPTON_W)*(dist/ICON_LEPTON_W))+1);
  1634. // if (value < MAP_CELL_W*2) value = dist/ICON_LEPTON_W;
  1635. value = max(value, 1);
  1636. BEnd(BENCH_EVAL_OBJECT);
  1637. return(true);
  1638. }
  1639. value = 0;
  1640. BEnd(BENCH_EVAL_OBJECT);
  1641. return(false);
  1642. }
  1643. /***********************************************************************************************
  1644. * TechnoClass::Evaluate_Cell -- Determine the value and object of specified cell. *
  1645. * *
  1646. * This routine will examine the specified cell and return with the potential target *
  1647. * object it contains and the value of it. Use this routine when searching for threats. *
  1648. * *
  1649. * INPUT: method -- The scan method to use for target searching. *
  1650. * *
  1651. * mask -- Prebuilt mask of object RTTI types acceptable for scanning. *
  1652. * *
  1653. * range -- Scan range limit to use for elimination purposes. This ensures that *
  1654. * objects in the "corner" of a square scan get properly discarded. *
  1655. * *
  1656. * object -- Pointer to object pointer to be filled in with the object at this *
  1657. * cell as a valid target. *
  1658. * *
  1659. * value -- Reference to the value of the object in this cell. It will be set *
  1660. * according to the object's value. *
  1661. * *
  1662. * zone -- The zone restriction if any. A -1 means no zone check required. *
  1663. * *
  1664. * OUTPUT: Was a valid potential target found in this cell? *
  1665. * *
  1666. * WARNINGS: none *
  1667. * *
  1668. * HISTORY: *
  1669. * 06/19/1995 JLB : Created. *
  1670. * 09/22/1995 JLB : Zone checking enabled. *
  1671. *=============================================================================================*/
  1672. bool TechnoClass::Evaluate_Cell(ThreatType method, int mask, CELL cell, int range, TechnoClass const * * object, int & value, int zone) const
  1673. {
  1674. assert(IsActive);
  1675. BStart(BENCH_EVAL_CELL);
  1676. *object = NULL;
  1677. value = 0;
  1678. /*
  1679. ** If the cell is not on the legal map, then always ignore it.
  1680. */
  1681. if ((unsigned)cell > MAP_CELL_TOTAL) {
  1682. BEnd(BENCH_EVAL_CELL);
  1683. return(false);
  1684. }
  1685. if (!Map.In_Radar(cell)) {
  1686. BEnd(BENCH_EVAL_CELL);
  1687. return(false);
  1688. }
  1689. /*
  1690. ** Fetch the techno object from the cell. If there is no
  1691. ** techno object there, then bail.
  1692. */
  1693. CellClass * cellptr = &Map[cell];
  1694. /*
  1695. ** Don't consider for evaluation a cell that is not within the same zone. Only
  1696. ** perform this check if zone checking is required.
  1697. */
  1698. if (zone != -1 && cellptr->Zones[Techno_Type_Class()->MZone] != zone) {
  1699. BEnd(BENCH_EVAL_CELL);
  1700. return(false);
  1701. }
  1702. TechnoClass const * tentative = (TechnoClass const *)cellptr->Cell_Occupier();
  1703. while (tentative != NULL) {
  1704. if (tentative != this) {
  1705. if (tentative->Is_Techno()) {
  1706. if (Combat_Damage() < 0) {
  1707. if (tentative->Health_Ratio() < Rule.ConditionGreen && House->Is_Ally(tentative)) break;
  1708. } else {
  1709. if (!House->Is_Ally(tentative)) break;
  1710. }
  1711. }
  1712. }
  1713. tentative = (TechnoClass const *)(ObjectClass *)tentative->Next;
  1714. }
  1715. if (tentative == NULL) {
  1716. BEnd(BENCH_EVAL_CELL);
  1717. return(false);
  1718. }
  1719. *object = tentative;
  1720. bool result = Evaluate_Object(method, mask, range, tentative, value);
  1721. BEnd(BENCH_EVAL_CELL);
  1722. return(result);
  1723. }
  1724. /***********************************************************************************************
  1725. * TechnoClass::Evaluate_Just_Cell -- Evaluate a cell as a target by itself. *
  1726. * *
  1727. * This will examine the cell (as if it contained no sentient objects) and determine a *
  1728. * target value to assign to it. Typically, this is only useful for wall destroyable *
  1729. * weapons when dealing with enemy walls. *
  1730. * *
  1731. * INPUT: cell -- The cell to examine and evaluate. *
  1732. * *
  1733. * OUTPUT: Returns with the target value to assign to this cell. *
  1734. * *
  1735. * WARNINGS: none *
  1736. * *
  1737. * HISTORY: *
  1738. * 09/10/1996 JLB : Created. *
  1739. *=============================================================================================*/
  1740. int TechnoClass::Evaluate_Just_Cell(CELL cell) const
  1741. {
  1742. BStart(BENCH_EVAL_WALL);
  1743. /*
  1744. ** Ships don't scan for walls.
  1745. */
  1746. if (What_Am_I() == RTTI_VESSEL) {
  1747. return(0);
  1748. }
  1749. /*
  1750. ** First, only computer objects are allowed to automatically scan for walls.
  1751. */
  1752. if (House->IsHuman) {
  1753. BEnd(BENCH_EVAL_WALL);
  1754. return(0);
  1755. }
  1756. /*
  1757. ** Even then, if the difficulty indicates that it shouldn't search for wall
  1758. ** targets, then don't allow it to do so.
  1759. */
  1760. if (!Rule.Diff[House->Difficulty].IsWallDestroyer) {
  1761. BEnd(BENCH_EVAL_WALL);
  1762. return(0);
  1763. }
  1764. /*
  1765. ** Determine if, in fact, a wall is located at this cell location.
  1766. */
  1767. CellClass const * cellptr = &Map[cell];
  1768. if (cellptr->Overlay == OVERLAY_NONE || !OverlayTypeClass::As_Reference(cellptr->Overlay).IsWall) {
  1769. BEnd(BENCH_EVAL_WALL);
  1770. return(0);
  1771. }
  1772. /*
  1773. ** As a convenience to the target scanning logic, don't consider any wall to be
  1774. ** a target if it isn't in range of the primary weapon.
  1775. */
  1776. int primary = What_Weapon_Should_I_Use(::As_Target(cell));
  1777. if (!In_Range(Cell_Coord(cell), primary)) {
  1778. BEnd(BENCH_EVAL_WALL);
  1779. return(0);
  1780. }
  1781. /*
  1782. ** See if the object has a weapon that can damage walls.
  1783. */
  1784. TechnoTypeClass const * ttype = (TechnoTypeClass const *)Techno_Type_Class();
  1785. if (ttype->PrimaryWeapon == NULL || ttype->PrimaryWeapon->WarheadPtr == NULL) {
  1786. BEnd(BENCH_EVAL_WALL);
  1787. return(0);
  1788. }
  1789. /*
  1790. ** If the weapon cannot deal with ground based targets, then don't consider
  1791. ** this a valid cell target.
  1792. */
  1793. if (ttype->PrimaryWeapon->Bullet != NULL && !ttype->PrimaryWeapon->Bullet->IsAntiGround) {
  1794. BEnd(BENCH_EVAL_WALL);
  1795. return(0);
  1796. }
  1797. /*
  1798. ** If the primary weapon cannot destroy a wall, then don't give the cell any
  1799. ** value as a target.
  1800. */
  1801. if (!ttype->PrimaryWeapon->WarheadPtr->IsWallDestroyer) {
  1802. BEnd(BENCH_EVAL_WALL);
  1803. return(0);
  1804. }
  1805. /*
  1806. ** If this is a friendly wall, then don't attack it.
  1807. */
  1808. if (House->Is_Ally(cellptr->Owner)) {
  1809. BEnd(BENCH_EVAL_WALL);
  1810. return(0);
  1811. }
  1812. /*
  1813. ** Since a wall was found, then return a value adjusted according to the range the wall
  1814. ** is from the object. The greater the range, the lesser the value returned.
  1815. */
  1816. BEnd(BENCH_EVAL_WALL);
  1817. return(Weapon_Range(0) - Distance(Cell_Coord(cell)));
  1818. }
  1819. bool TechnoClass::Is_Cloaked(HousesType house, bool check_invisible) const
  1820. {
  1821. const bool is_invisible = check_invisible && Techno_Type_Class()->IsInvisible;
  1822. return !House->Is_Ally(house) && ((Cloak == CLOAKED) || is_invisible);
  1823. }
  1824. bool TechnoClass::Is_Cloaked(HouseClass const * house, bool check_invisible) const
  1825. {
  1826. const bool is_invisible = check_invisible && Techno_Type_Class()->IsInvisible;
  1827. return !House->Is_Ally(house) && ((Cloak == CLOAKED) || is_invisible);
  1828. }
  1829. bool TechnoClass::Is_Cloaked(ObjectClass const * object, bool check_invisible) const
  1830. {
  1831. const bool is_invisible = check_invisible && Techno_Type_Class()->IsInvisible;
  1832. return !House->Is_Ally(object) && ((Cloak == CLOAKED) || is_invisible);
  1833. }
  1834. /***********************************************************************************************
  1835. * TechnoClass::Greatest_Threat -- Determines best target given search criteria. *
  1836. * *
  1837. * This routine will scan game objects looking for the best target. It is used by the *
  1838. * general target searching processes. The type of target scan to perform is controlled *
  1839. * by the method control parameter. *
  1840. * *
  1841. * INPUT: method -- The method control parameter is used to control the type of target *
  1842. * scan performed. It consists of a series of bit flags (see ThreatType) *
  1843. * that are combined to form the target scan desired. *
  1844. * *
  1845. * OUTPUT: Returns the target value of a suitable target. If no target was found then the *
  1846. * value TARGET_NONE is returned. *
  1847. * *
  1848. * WARNINGS: none *
  1849. * *
  1850. * HISTORY: *
  1851. * 11/14/1994 JLB : Created. *
  1852. * 06/20/1995 JLB : Greatly optimized scan method. *
  1853. * 09/22/1995 JLB : Takes into account the zone (if necessary). *
  1854. * 05/30/1996 JLB : Tighter elimination mask checking. *
  1855. *=============================================================================================*/
  1856. TARGET TechnoClass::Greatest_Threat(ThreatType method) const
  1857. {
  1858. assert(IsActive);
  1859. BStart(BENCH_GREATEST_THREAT);
  1860. ObjectClass const * bestobject = NULL;
  1861. int bestval = -1;
  1862. int zone = -1;
  1863. TargetScan++;
  1864. /*
  1865. ** Determine the zone that the target must be in. For aircraft and gunboats, they
  1866. ** ignore zones since they either can fly over any zone or are designed to fire into
  1867. ** other zones. If scanning for targets that are within range, then zone checking need
  1868. ** not be performed -- range checking is much more thorough and effective.
  1869. */
  1870. if (!(method & THREAT_RANGE) &&
  1871. What_Am_I() != RTTI_VESSEL &&
  1872. What_Am_I() != RTTI_BUILDING &&
  1873. What_Am_I() != RTTI_AIRCRAFT) {
  1874. zone = Map[Center_Coord()].Zones[Techno_Type_Class()->MZone];
  1875. }
  1876. /*
  1877. ** Hack for dogs, 'cause they can only consider infantrymen to be a
  1878. ** threat. Medics also.
  1879. */
  1880. if (What_Am_I() == RTTI_INFANTRY) {
  1881. if (((InfantryClass *)this)->Class->IsDog || Combat_Damage() < 0) {
  1882. method = THREAT_INFANTRY | (method & (THREAT_RANGE | THREAT_AREA));
  1883. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  1884. if(*(InfantryClass *)this == INFANTRY_MECHANIC) {
  1885. method = (THREAT_VEHICLES | THREAT_AIR) | (method & (THREAT_RANGE | THREAT_AREA));
  1886. }
  1887. #endif
  1888. }
  1889. }
  1890. /*
  1891. ** Build a quick elimination mask. If the RTTI of the object doesn't
  1892. ** qualify with this mask, then we KNOW that it shouldn't be considered.
  1893. */
  1894. int mask = 0;
  1895. if (method & THREAT_CIVILIANS) mask |= ((1 << RTTI_BUILDING) | (1 << RTTI_INFANTRY) | (1 << RTTI_UNIT));
  1896. if (method & THREAT_AIR) mask |= (1 << RTTI_AIRCRAFT);
  1897. if (method & THREAT_CAPTURE) mask |= (1 << RTTI_BUILDING);
  1898. if (method & (THREAT_CIVILIANS|THREAT_BUILDINGS|THREAT_FACTORIES|THREAT_POWER|THREAT_FAKES|THREAT_BASE_DEFENSE|THREAT_TIBERIUM)) mask |= (1 << RTTI_BUILDING);
  1899. if (method & (THREAT_CIVILIANS|THREAT_INFANTRY|THREAT_BASE_DEFENSE)) mask |= (1 << RTTI_INFANTRY);
  1900. if (method & THREAT_VEHICLES) mask |= (1 << RTTI_UNIT);
  1901. if (method & THREAT_BASE_DEFENSE) mask |= (1 << RTTI_BUILDING);
  1902. if (method & THREAT_BOATS) mask |= (1 << RTTI_VESSEL);
  1903. /*
  1904. ** Limit area target scans use a method where the actual map cells are
  1905. ** examined for occupants. The occupant is then examined in turn. The
  1906. ** best target within the area is returned as a target.
  1907. */
  1908. if (method & (THREAT_AREA|THREAT_RANGE)) {
  1909. int range = Threat_Range((method & THREAT_RANGE) ? 0 : 1);
  1910. int crange = range / ICON_LEPTON_W;
  1911. if (range == 0) {
  1912. crange = max(Weapon_Range(0), Weapon_Range(1)) / ICON_LEPTON_W;
  1913. crange++;
  1914. }
  1915. CELL cell = Coord_Cell(Fire_Coord(0));
  1916. /*
  1917. ** BG: Miserable hack to get the stupid doctor to actually do area
  1918. ** guarding.
  1919. */
  1920. if (Combat_Damage() < 0) {
  1921. /*if (method & THREAT_AREA)*/ crange++;
  1922. }
  1923. /*
  1924. ** If aircraft are a legal target, then scan through all of them at this time.
  1925. ** Scanning by cell is not possible for aircraft since they are not recorded
  1926. ** at the cell level.
  1927. */
  1928. if (method & THREAT_AIR) {
  1929. for (int index = 0; index < Aircraft.Count(); index++) {
  1930. TechnoClass * object = Aircraft.Ptr(index);
  1931. int value = 0;
  1932. if (object->In_Which_Layer() != LAYER_GROUND && Evaluate_Object(method, mask, range, object, value)) {
  1933. if (value > bestval) {
  1934. bestobject = object;
  1935. bestval = value;
  1936. }
  1937. }
  1938. }
  1939. }
  1940. /*
  1941. ** When scanning the ground, always consider landed aircraft as a valid
  1942. ** potential target. This is only true if vehicles are considered a
  1943. ** valid target. A landed aircraft is considered a vehicle.
  1944. */
  1945. if (method & THREAT_VEHICLES) {
  1946. mask |= (1 << RTTI_AIRCRAFT);
  1947. }
  1948. /*
  1949. ** Radiate outward from the object's location, looking for the best
  1950. ** target.
  1951. */
  1952. CELL bestcell = -1;
  1953. int bestcellvalue = 0;
  1954. TechnoClass const * object;
  1955. int value;
  1956. // int rad = 1;
  1957. // BG: Medics need to be able to look in their own cell too.
  1958. // if (Combat_Damage() < 0 || (What_Am_I() == RTTI_INFANTRY && ((InfantryClass*)this)->Class->IsDog)) {
  1959. // rad = 0;
  1960. // }
  1961. for (int radius = 0; radius < crange; radius++) {
  1962. /*
  1963. ** Scan the top and bottom rows of the "box".
  1964. */
  1965. for (int x = -radius; x <= radius; x++) {
  1966. CELL newcell;
  1967. if ((Cell_X(cell) + x) < Map.MapCellX) continue;
  1968. if ((Cell_X(cell) + x) >= (Map.MapCellX+Map.MapCellWidth)) continue;
  1969. if ((Cell_Y(cell) - radius) >= Map.MapCellY) {
  1970. newcell = XY_Cell(Cell_X(cell) + x, Cell_Y(cell)-radius);
  1971. if (Evaluate_Cell(method, mask, newcell, range, &object, value, zone)) {
  1972. if (bestval < value) {
  1973. bestobject = object;
  1974. }
  1975. }
  1976. if (bestobject == NULL) {
  1977. value = Evaluate_Just_Cell(newcell);
  1978. if (bestcellvalue < value) {
  1979. bestcellvalue = value;
  1980. bestcell = newcell;
  1981. }
  1982. }
  1983. }
  1984. if ((Cell_Y(cell) + radius) < (Map.MapCellY+Map.MapCellHeight)) {
  1985. newcell = XY_Cell(Cell_X(cell)+x, Cell_Y(cell)+radius);
  1986. if (Evaluate_Cell(method, mask, newcell, range, &object, value, zone)) {
  1987. if (bestval < value) {
  1988. bestobject = object;
  1989. }
  1990. }
  1991. if (bestobject == NULL) {
  1992. value = Evaluate_Just_Cell(newcell);
  1993. if (bestcellvalue < value) {
  1994. bestcellvalue = value;
  1995. bestcell = newcell;
  1996. }
  1997. }
  1998. }
  1999. }
  2000. /*
  2001. ** Scan the left and right columns of the "box".
  2002. */
  2003. for (int y = -(radius-1); y < radius; y++) {
  2004. CELL newcell;
  2005. if ((Cell_Y(cell) + y) < Map.MapCellY) continue;
  2006. if ((Cell_Y(cell) + y) >= (Map.MapCellY+Map.MapCellHeight)) continue;
  2007. if ((Cell_X(cell) - radius) >= Map.MapCellX) {
  2008. newcell = XY_Cell(Cell_X(cell)-radius, Cell_Y(cell)+y);
  2009. if (Evaluate_Cell(method, mask, newcell, range, &object, value, zone)) {
  2010. if (bestval < value) {
  2011. bestobject = object;
  2012. }
  2013. }
  2014. if (bestobject == NULL) {
  2015. value = Evaluate_Just_Cell(newcell);
  2016. if (bestcellvalue < value) {
  2017. bestcellvalue = value;
  2018. bestcell = newcell;
  2019. }
  2020. }
  2021. }
  2022. if ((Cell_X(cell) + radius) < (Map.MapCellX+Map.MapCellWidth)) {
  2023. newcell = XY_Cell(Cell_X(cell)+radius, Cell_Y(cell)+y);
  2024. if (Evaluate_Cell(method, mask, newcell, range, &object, value, zone)) {
  2025. if (bestval < value) {
  2026. bestobject = object;
  2027. }
  2028. }
  2029. if (bestobject == NULL) {
  2030. value = Evaluate_Just_Cell(newcell);
  2031. if (bestcellvalue < value) {
  2032. bestcellvalue = value;
  2033. bestcell = newcell;
  2034. }
  2035. }
  2036. }
  2037. }
  2038. /*
  2039. ** Bail early if a target has already been found and the range is at
  2040. ** one of the breaking points (i.e., normal range or range * 2).
  2041. */
  2042. if (bestobject != NULL) {
  2043. if (radius == crange/4) {
  2044. return(bestobject->As_Target());
  2045. }
  2046. if (radius == crange/2) {
  2047. return(bestobject->As_Target());
  2048. }
  2049. }
  2050. if (bestcell != -1) {
  2051. return(::As_Target(bestcell));
  2052. }
  2053. }
  2054. } else {
  2055. /*
  2056. ** A full map scan was requested. First scan through aircraft. The top map layer
  2057. ** is NOT scanned since that layer will probably contain more bullets and animations
  2058. ** than aircraft.
  2059. */
  2060. if (mask & (1L << RTTI_AIRCRAFT)) {
  2061. for (int index = 0; index < Aircraft.Count(); index++) {
  2062. TechnoClass * object = Aircraft.Ptr(index);
  2063. int value = 0;
  2064. if (Evaluate_Object(method, mask, -1, object, value)) {
  2065. if (value > bestval) {
  2066. bestobject = object;
  2067. bestval = value;
  2068. }
  2069. }
  2070. }
  2071. }
  2072. /*
  2073. ** When scanning the ground, always consider landed aircraft as a valid
  2074. ** potential target. This is only true if vehicles are considered a
  2075. ** valid target. A landed aircraft is considered a vehicle.
  2076. */
  2077. if (method & THREAT_VEHICLES) {
  2078. mask |= (1 << RTTI_AIRCRAFT);
  2079. }
  2080. /*
  2081. ** Now scan through the entire ground layer. This is painful, but what other
  2082. ** choice is there?
  2083. */
  2084. for (int index = 0; index < Map.Layer[LAYER_GROUND].Count(); index++) {
  2085. ObjectClass const * object = Map.Layer[LAYER_GROUND][index];
  2086. int value = 0;
  2087. if (object->Is_Techno() && Evaluate_Object(method, mask, -1, (TechnoClass const *)object, value, zone)) {
  2088. if (value > bestval) {
  2089. bestobject = object;
  2090. bestval = value;
  2091. }
  2092. }
  2093. }
  2094. }
  2095. BEnd(BENCH_GREATEST_THREAT);
  2096. /*
  2097. ** If a good target object was found, then return with the target value
  2098. ** of it.
  2099. */
  2100. if (bestobject != NULL) {
  2101. return(bestobject->As_Target());
  2102. }
  2103. return(TARGET_NONE);
  2104. }
  2105. /***********************************************************************************************
  2106. * TechnoClass::Owner -- Who is the owner of this object? *
  2107. * *
  2108. * Use this routine to examine this object and return who the owner is. *
  2109. * *
  2110. * INPUT: none *
  2111. * *
  2112. * OUTPUT: Returns with the house number of the owner of this object. *
  2113. * *
  2114. * WARNINGS: none *
  2115. * *
  2116. * HISTORY: *
  2117. * 12/09/1994 JLB : Created. *
  2118. *=============================================================================================*/
  2119. HousesType TechnoClass::Owner(void) const
  2120. {
  2121. assert(IsActive);
  2122. return(House->Class->House);
  2123. }
  2124. /***********************************************************************************************
  2125. * TechnoClass::Clicked_As_Target -- Sets the flash count for this techno object. *
  2126. * *
  2127. * Use this routine to set the flash count for the object. This flash count is the number *
  2128. * of times the object will "flash". Typically it is called as a result of the player *
  2129. * clicking on this object in order to make it the target of a move or attack. *
  2130. * *
  2131. * INPUT: count -- The number of times the object should flash. *
  2132. * *
  2133. * OUTPUT: none *
  2134. * *
  2135. * WARNINGS: none *
  2136. * *
  2137. * HISTORY: *
  2138. * 12/09/1994 JLB : Created. *
  2139. *=============================================================================================*/
  2140. void TechnoClass::Clicked_As_Target(HousesType house, int count) // 2019/09/20 JAS - Added record of who clicked on the object
  2141. {
  2142. assert(IsActive);
  2143. FlashCount = count;
  2144. // 2019/09/20 JAS - Flashing info needs to exist per player
  2145. if (house < HOUSE_COUNT)
  2146. {
  2147. FlashCountPerPlayer[house] = count;
  2148. }
  2149. else
  2150. {
  2151. //receiving HOUSE_COUNT means do it for every player
  2152. for (int i = 0; i < HOUSE_COUNT; ++i)
  2153. {
  2154. FlashCountPerPlayer[i] = count;
  2155. }
  2156. }
  2157. }
  2158. /***********************************************************************************************
  2159. * TechnoClass::AI -- Handles AI processing for techno object. *
  2160. * *
  2161. * This routine handles AI processing for techno objects. Typically, this merely dispatches *
  2162. * to the appropriate AI routines for the base classes. *
  2163. * *
  2164. * INPUT: none *
  2165. * *
  2166. * OUTPUT: none *
  2167. * *
  2168. * WARNINGS: Make sure that this routine is only called ONCE per game tick. *
  2169. * *
  2170. * HISTORY: *
  2171. * 12/09/1994 JLB : Created. *
  2172. *=============================================================================================*/
  2173. void TechnoClass::AI(void)
  2174. {
  2175. assert(IsActive);
  2176. /*
  2177. ** Handle recoil recovery here.
  2178. */
  2179. if (IsInRecoilState) {
  2180. IsInRecoilState = false;
  2181. Mark(MARK_CHANGE_REDRAW);
  2182. }
  2183. /*
  2184. ** If this building is being spied on by the player, need to redraw if selected
  2185. ** since the money amount is rendering.
  2186. */
  2187. if (Is_Selected_By_Player()) {
  2188. if (What_Am_I() == RTTI_BUILDING) {
  2189. int spiedby = Spied_By() & (1<<(PlayerPtr->Class->House));
  2190. if (spiedby) {
  2191. if (((BuildingClass *)this)->Class->Capacity) {
  2192. Mark(MARK_CHANGE_REDRAW);
  2193. }
  2194. }
  2195. }
  2196. }
  2197. CargoClass::AI();
  2198. RadioClass::AI();
  2199. if (!IsActive || (Height > 0 && What_Am_I() != RTTI_AIRCRAFT)) return;
  2200. DoorClass::AI();
  2201. /*
  2202. ** If this is a vehicle that heals itself (e.g., Mammoth Tank), then it will perform
  2203. ** the heal logic here.
  2204. */
  2205. if (Techno_Type_Class()->IsSelfHealing && (Frame % (Rule.RepairRate * TICKS_PER_MINUTE)) == 0 && Health_Ratio() <= Rule.ConditionYellow) {
  2206. Strength++;
  2207. Mark(MARK_CHANGE);
  2208. }
  2209. /*
  2210. ** Cloaking device processing.
  2211. */
  2212. Cloaking_AI();
  2213. /*
  2214. ** If for some strange reason, the computer is firing upon itself, then
  2215. ** tell it not to.
  2216. */
  2217. if (!House->IsHuman && As_Techno(TarCom) && As_Techno(TarCom)->House->Is_Ally(this) && Combat_Damage() >= 0) {
  2218. //#ifdef FIXIT_CSII // checked - ajw 9/28/98 (commented out)
  2219. //if(What_Am_I() == RTTI_INFANTRY && *(InfantryClass *)this==INFANTRY_GENERAL && Session.Type==GAME_NORMAL && House->Class->House==HOUSE_UKRAINE) {
  2220. //} else
  2221. //#endif
  2222. Assign_Target(TARGET_NONE);
  2223. }
  2224. /*
  2225. ** Perform a maintenance check to see that if somehow this object is trying to fire
  2226. ** upon an object it can never hit (because it can't reach it), then abort the tarcom
  2227. */
  2228. if (What_Am_I() != RTTI_AIRCRAFT && Target_Legal(TarCom) && (!Is_Foot() || !((FootClass *)this)->Team.Is_Valid()) && (!Is_Foot() || !Is_In_Same_Zone(As_Cell(TarCom)))) {
  2229. int primary = What_Weapon_Should_I_Use(TarCom);
  2230. if (!In_Range(TarCom, primary)) {
  2231. Assign_Target(TARGET_NONE);
  2232. }
  2233. }
  2234. /*
  2235. ** Update the animation timer system. If the animation stage
  2236. ** changes, then flag the object to be redrawn as well as determine
  2237. ** if the current animation process needs to change.
  2238. */
  2239. if (What_Am_I() != RTTI_BUILDING) {
  2240. if (StageClass::About_To_Change()) {
  2241. Mark(MARK_CHANGE_REDRAW);
  2242. }
  2243. if (StageClass::Graphic_Logic() || Time_To_Redraw()) {
  2244. Mark(MARK_CHANGE_REDRAW);
  2245. }
  2246. }
  2247. /*
  2248. ** If the object is flashing and a change of flash state has occurred, then mark the
  2249. ** object to be redrawn.
  2250. */
  2251. if (FlasherClass::Process()) {
  2252. Mark(MARK_CHANGE);
  2253. }
  2254. /*
  2255. ** Handle electric zap delay logic.
  2256. */
  2257. if (ElectricZapDelay >= 0) {
  2258. Map.Flag_To_Redraw(true);
  2259. if (--ElectricZapDelay < 0) {
  2260. ElectricZapTarget = 0;
  2261. ElectricZapWhich = 0;
  2262. }
  2263. }
  2264. }
  2265. /***********************************************************************************************
  2266. * TechnoClass::Cloaking_AI -- Perform the AI maintenance for a cloaking device. *
  2267. * *
  2268. * This routine handles the cloaking device logic for this object. It will handle the *
  2269. * transition effects as the object cloaks or decloaks. It will also try to start an *
  2270. * object to cloak if possible. *
  2271. * *
  2272. * INPUT: none *
  2273. * *
  2274. * OUTPUT: none *
  2275. * *
  2276. * WARNINGS: none *
  2277. * *
  2278. * HISTORY: *
  2279. * 09/09/1996 JLB : Created. *
  2280. *=============================================================================================*/
  2281. void TechnoClass::Cloaking_AI(void)
  2282. {
  2283. /*
  2284. ** Handle decision to re-cloak here. Process the cloaking/decloaking operation.
  2285. */
  2286. if (IsCloakable) {
  2287. /*
  2288. ** If this object is uncloaked, but it can be cloaked and it thinks that it
  2289. ** is a good time do so, then begin cloaking.
  2290. */
  2291. if (Cloak == UNCLOAKED) {
  2292. #ifdef PREDATOR
  2293. // Changed for multiplayer so we can visually see the different players in the original renderer. ST - 3/13/2019 5:40PM
  2294. //if (IsOwnedByPlayer) Mark(MARK_CHANGE);
  2295. if (Is_Owned_By_Player()) Mark(MARK_CHANGE);
  2296. #endif
  2297. CloakingDevice.Graphic_Logic();
  2298. if (Is_Ready_To_Cloak()) {
  2299. if (Health_Ratio() > Rule.ConditionRed) {
  2300. Do_Cloak();
  2301. } else {
  2302. if (Percent_Chance(4)) {
  2303. Do_Cloak();
  2304. }
  2305. }
  2306. }
  2307. } else {
  2308. CloakingDevice.Graphic_Logic();
  2309. switch (Cloak) {
  2310. /*
  2311. ** Handle the uncloaking process. Always mark to redraw
  2312. ** the object and when cloaking is complete, stabilize into
  2313. ** the normal uncloaked state.
  2314. */
  2315. case UNCLOAKING:
  2316. Mark(MARK_CHANGE);
  2317. if (Visual_Character(true) == VISUAL_NORMAL) {
  2318. CloakingDevice.Set_Rate(0);
  2319. CloakingDevice.Set_Stage(0); // re-start the stage counter
  2320. Cloak = UNCLOAKED;
  2321. CloakDelay = Rule.CloakDelay * TICKS_PER_MINUTE;
  2322. Mark(MARK_CHANGE);
  2323. }
  2324. break;
  2325. /*
  2326. ** Handle the cloaking process. Always mark to redraw the object
  2327. ** and when the cloaking process is complete, stabilize into the
  2328. ** normal cloaked state.
  2329. */
  2330. case CLOAKING:
  2331. Mark(MARK_CHANGE);
  2332. if(!CloakingDevice.Fetch_Rate()) {
  2333. CloakingDevice.Set_Rate(1);
  2334. }
  2335. switch (Visual_Character(true)) {
  2336. /*
  2337. ** If badly damaged, then it can never fully cloak.
  2338. */
  2339. case VISUAL_DARKEN:
  2340. if (Health_Ratio() <= Rule.ConditionRed && Percent_Chance(25)) {
  2341. Cloak = UNCLOAKING;
  2342. }
  2343. break;
  2344. case VISUAL_HIDDEN:
  2345. Cloak = CLOAKED;
  2346. CloakingDevice.Set_Rate(0);
  2347. CloakingDevice.Set_Stage(0);
  2348. Mark(MARK_CHANGE);
  2349. Map[Center_Coord()].Redraw_Objects(true);
  2350. Map.RadarClass::Flag_To_Redraw(true);
  2351. /*
  2352. ** Special check to ensure that if the unit is carrying a captured
  2353. ** flag, it will never fully cloak.
  2354. */
  2355. if (What_Am_I() == RTTI_UNIT && ((UnitClass *)this)->Flagged != HOUSE_NONE) {
  2356. Do_Shimmer();
  2357. } else {
  2358. Detach_All(false);
  2359. }
  2360. /*
  2361. ** A computer controlled unit will try to scatter if possible so
  2362. ** that it will be much harder to locate.
  2363. */
  2364. if (What_Am_I() == RTTI_UNIT && !House->IsHuman) {
  2365. Scatter(0, true);
  2366. }
  2367. break;
  2368. }
  2369. break;
  2370. /*
  2371. ** A cloaked object will always be redrawn if it is owned by the
  2372. ** player. This ensures that the shimmering effect will animate.
  2373. */
  2374. case CLOAKED:
  2375. #ifdef PREDATOR
  2376. //if (IsOwnedByPlayer) {
  2377. // Changed for multiplayer so we can visually see the different players in the original renderer. ST - 3/13/2019 5:40PM
  2378. if (Is_Owned_By_Player()) {
  2379. Mark(MARK_CHANGE);
  2380. }
  2381. #endif
  2382. break;
  2383. }
  2384. }
  2385. }
  2386. }
  2387. /***********************************************************************************************
  2388. * TechnoClass::Is_Ready_To_Cloak -- Determines if this object is ready to begin cloaking. *
  2389. * *
  2390. * This routine will examine this object and determine if it can and is ready and able *
  2391. * to begin cloaking. It will also check to make sure it appears to be a good time to cloak *
  2392. * as well. *
  2393. * *
  2394. * INPUT: none *
  2395. * *
  2396. * OUTPUT: bool; Is this unit ready and able to start cloaking? *
  2397. * *
  2398. * WARNINGS: none *
  2399. * *
  2400. * HISTORY: *
  2401. * 09/09/1996 JLB : Created. *
  2402. *=============================================================================================*/
  2403. bool TechnoClass::Is_Ready_To_Cloak(void) const
  2404. {
  2405. /*
  2406. ** If it is already cloaked or in the process of cloaking, then it can't start cloaking.
  2407. */
  2408. if (Cloak == CLOAKED || (Cloak == CLOAKING && CloakingDevice.Fetch_Rate())) {
  2409. return(false);
  2410. }
  2411. /*
  2412. ** If the object cannot recloak, then it certainly is not allowed to start.
  2413. */
  2414. if (!IsCloakable || !Is_Allowed_To_Recloak()) {
  2415. return(false);
  2416. }
  2417. /*
  2418. ** If the object is currently rearming, then don't begin to recloak.
  2419. */
  2420. if (Arm != 0) {
  2421. return(false);
  2422. }
  2423. /*
  2424. ** If it seems like this object is about to fire on a target, then don't begin
  2425. ** cloaking either.
  2426. */
  2427. if (Target_Legal(TarCom) && In_Range(TarCom)) {
  2428. return(false);
  2429. }
  2430. /*
  2431. ** Recloaking can only begin if the cloaking device is not already operating.
  2432. */
  2433. if (CloakingDevice.Fetch_Stage() != 0) {
  2434. return(false);
  2435. }
  2436. /*
  2437. ** If the arbitrary cloak delay value is still counting down, then don't
  2438. ** allow recloaking just yet.
  2439. */
  2440. if (CloakDelay != 0) {
  2441. return(false);
  2442. }
  2443. /*
  2444. ** All tests passed, so this object is allowed to begin cloaking.
  2445. */
  2446. return(true);
  2447. }
  2448. /***********************************************************************************************
  2449. * TechnoClass::Select -- Selects object and checks to see if can be selected. *
  2450. * *
  2451. * This function checks to see if this techno object can be selected. If it can, then it *
  2452. * is selected. *
  2453. * *
  2454. * INPUT: none *
  2455. * *
  2456. * OUTPUT: none *
  2457. * *
  2458. * WARNINGS: none *
  2459. * *
  2460. * HISTORY: *
  2461. * 12/11/1994 JLB : Created. *
  2462. *=============================================================================================*/
  2463. bool TechnoClass::Select(bool allow_mixed)
  2464. {
  2465. assert(IsActive);
  2466. //if (!IsDiscoveredByPlayer && !House->IsPlayerControl && !Debug_Unshroud) { // ST - 8/7/2019 11:24AM
  2467. if (!Is_Discovered_By_Player() && !House->IsPlayerControl && !Debug_Unshroud) {
  2468. return(false);
  2469. }
  2470. if (RadioClass::Select(allow_mixed)) {
  2471. /*
  2472. ** Speak a confirmation of selection.
  2473. */
  2474. if (House->IsPlayerControl && AllowVoice) {
  2475. Response_Select();
  2476. }
  2477. return(true);
  2478. }
  2479. return(false);
  2480. }
  2481. /***********************************************************************************************
  2482. * TechnoClass::Can_Fire -- Determines if this techno object can fire. *
  2483. * *
  2484. * This performs a simple check to make sure that this techno object can fire. At this *
  2485. * level, the only thing checked for is the rearming delay. *
  2486. * *
  2487. * INPUT: none *
  2488. * *
  2489. * OUTPUT: Returns with the fire legality control code. *
  2490. * *
  2491. * WARNINGS: none *
  2492. * *
  2493. * HISTORY: *
  2494. * 12/23/1994 JLB : Created. *
  2495. *=============================================================================================*/
  2496. FireErrorType TechnoClass::Can_Fire(TARGET target, int which) const
  2497. {
  2498. assert(IsActive);
  2499. /*
  2500. ** Don't allow firing if the target is illegal.
  2501. */
  2502. if (!Target_Legal(target)) {
  2503. return(FIRE_ILLEGAL);
  2504. }
  2505. ObjectClass * object = As_Object(target);
  2506. /*
  2507. ** If an enemy object is completely cloaked, then you can't fire on it.
  2508. */
  2509. if (object != NULL && object->Is_Techno() && ((TechnoClass *)object)->Is_Cloaked(this)) {
  2510. return(FIRE_CANT);
  2511. }
  2512. /*
  2513. ** A falling object is too busy falling to fire.
  2514. */
  2515. if (IsFalling) {
  2516. return(FIRE_CANT);
  2517. }
  2518. /*
  2519. ** If there is no weapon, then firing is not allowed.
  2520. */
  2521. WeaponTypeClass const * weapon = ((which == 0) ? Techno_Type_Class()->PrimaryWeapon : Techno_Type_Class()->SecondaryWeapon);
  2522. if (weapon == NULL) {
  2523. return(FIRE_CANT);
  2524. }
  2525. /*
  2526. ** Can only fire anti-aircraft weapons against aircraft unless the aircraft is
  2527. ** sitting on the ground.
  2528. */
  2529. if (object != NULL && object->What_Am_I() == RTTI_AIRCRAFT &&
  2530. !weapon->Bullet->IsAntiAircraft &&
  2531. ((AircraftClass *)object)->Height > 0) {
  2532. return(FIRE_CANT);
  2533. }
  2534. /*
  2535. ** If the object is on the ground, then don't allow firing if it can't fire upon ground objects.
  2536. */
  2537. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2538. if (object != NULL && object->Height == 0 && (object->What_Am_I() != RTTI_VESSEL || (*((VesselClass*)object) != VESSEL_SS && *((VesselClass*)object) != VESSEL_MISSILESUB )) &&
  2539. #else
  2540. if (object != NULL && object->Height == 0 && (object->What_Am_I() != RTTI_VESSEL || *((VesselClass*)object) != VESSEL_SS) &&
  2541. #endif
  2542. !weapon->Bullet->IsAntiGround) {
  2543. return(FIRE_CANT);
  2544. }
  2545. if (Is_Target_Cell(target) && !weapon->Bullet->IsAntiGround) {
  2546. return(FIRE_CANT);
  2547. }
  2548. /*
  2549. ** Don't allow firing if still rearming.
  2550. */
  2551. if (Arm != 0) return(FIRE_REARM);
  2552. /*
  2553. ** The target must be within range in order to allow firing.
  2554. */
  2555. if (!In_Range(target, which)) {
  2556. return(FIRE_RANGE);
  2557. }
  2558. /*
  2559. ** If there is no ammo left, then it can't fire.
  2560. */
  2561. if (!Ammo) {
  2562. return(FIRE_AMMO);
  2563. }
  2564. /*
  2565. ** If cloaked, then firing is disabled.
  2566. */
  2567. if (Cloak != UNCLOAKED) {
  2568. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2569. // Special hack for John Archer's Hunt-The-Wumpus multiplayer mission... if
  2570. // the object firing is a cloaked civilian, don't require uncloaking before
  2571. // allowing firing.
  2572. if (What_Am_I()==RTTI_INFANTRY && ((InfantryClass *)this)->Class->IsCivilian ) {
  2573. return(FIRE_OK);
  2574. }
  2575. #endif
  2576. return(FIRE_CLOAKED);
  2577. }
  2578. return(FIRE_OK);
  2579. }
  2580. /***********************************************************************************************
  2581. * TechnoClass::Stun -- Prepares the object for removal from the game. *
  2582. * *
  2583. * This routine handles cleaning up this techno object from the game system so that when *
  2584. * it is subsequently removed, it doesn't leave any loose ends. *
  2585. * *
  2586. * INPUT: none *
  2587. * *
  2588. * OUTPUT: none *
  2589. * *
  2590. * WARNINGS: none *
  2591. * *
  2592. * HISTORY: *
  2593. * 12/23/1994 JLB : Created. *
  2594. *=============================================================================================*/
  2595. void TechnoClass::Stun(void)
  2596. {
  2597. assert(IsActive);
  2598. Assign_Target(TARGET_NONE);
  2599. Assign_Destination(TARGET_NONE);
  2600. Transmit_Message(RADIO_OVER_OUT);
  2601. Detach_All();
  2602. //Unselect();
  2603. //When an object is stunned it needs to be deselected from all players, not just the current PlayerPtr.
  2604. // - 8/18/2019 JAS
  2605. Unselect_All_Players();
  2606. }
  2607. /***********************************************************************************************
  2608. * TechnoClass::Assign_Target -- Assigns the targeting computer with specified target. *
  2609. * *
  2610. * Use this routine to set the targeting computer for this object. It checks to make sure *
  2611. * that targeting of itself is prohibited. *
  2612. * *
  2613. * INPUT: target -- The target for this object to attack. *
  2614. * *
  2615. * OUTPUT: none *
  2616. * *
  2617. * WARNINGS: none *
  2618. * *
  2619. * HISTORY: *
  2620. * 12/23/1994 JLB : Created. *
  2621. *=============================================================================================*/
  2622. void TechnoClass::Assign_Target(TARGET target)
  2623. {
  2624. assert(IsActive);
  2625. if (target == TarCom) return;
  2626. if (!Target_Legal(target)) {
  2627. target = TARGET_NONE;
  2628. } else {
  2629. /*
  2630. ** Prevent targeting of self.
  2631. */
  2632. if (target == As_Target()) {
  2633. target = ::As_Target(Coord_Cell(Coord));
  2634. } else {
  2635. /*
  2636. ** Make sure that the target is not already dead.
  2637. */
  2638. ObjectClass * object = As_Object(target);
  2639. if (object != NULL && (object->IsActive == false || object->Strength == 0)) {
  2640. target = TARGET_NONE;
  2641. }
  2642. }
  2643. }
  2644. /*
  2645. ** Set the unit's targeting computer.
  2646. */
  2647. TarCom = target;
  2648. }
  2649. /***********************************************************************************************
  2650. * TechnoClass::Rearm_Delay -- Calculates the delay before firing can occur. *
  2651. * *
  2652. * This function calculates the delay between shots. It determines this from the standard *
  2653. * rate of fire (ROF) of the base class and modifies it according to game speed and *
  2654. * whether this is the first or second shot. All single shot attackers consider their *
  2655. * shots to be "second" since the second shot is the one handled normally. The first shot *
  2656. * usually gets assigned a much shorter delay time before the next shot can fire. *
  2657. * *
  2658. * INPUT: second -- bool; Is this the second of a two shot salvo? *
  2659. * *
  2660. * OUTPUT: Returns with the number of game frames to delay before the next shot may fire. *
  2661. * *
  2662. * WARNINGS: none *
  2663. * *
  2664. * HISTORY: *
  2665. * 12/26/1994 JLB : Created. *
  2666. *=============================================================================================*/
  2667. int TechnoClass::Rearm_Delay(bool second, int which) const
  2668. {
  2669. assert(IsActive);
  2670. if (What_Am_I() == RTTI_BUILDING && Ammo > 1) {
  2671. return(1);
  2672. }
  2673. WeaponTypeClass const * weapon = (which == 0) ? Techno_Type_Class()->PrimaryWeapon : Techno_Type_Class()->SecondaryWeapon;
  2674. if (second && weapon != NULL) {
  2675. return(weapon->ROF * House->ROFBias);
  2676. }
  2677. return(3);
  2678. }
  2679. /***********************************************************************************************
  2680. * TechnoClass::Electric_Zap -- Fires electric zap at the target specified. *
  2681. * *
  2682. * This routine is used to fire an electric zap at the target specified. *
  2683. * *
  2684. * INPUT: target -- The target to fire the zap at. *
  2685. * *
  2686. * which -- Which weapon is this zap associated with (0=primary, 1=secondary). *
  2687. * *
  2688. * window -- The clipping window to use when rendering. *
  2689. * *
  2690. * source_coord -- The coordinate that the zap is to originate from. This is an *
  2691. * override value and if not specifide, the normal fire coordinate *
  2692. * is used. *
  2693. * *
  2694. * remap -- Pointer to the zap animation remap override table. If not specified *
  2695. * then the zap remains the normal blue white color. *
  2696. * *
  2697. * OUTPUT: bool; Does this object need to redraw? *
  2698. * *
  2699. * WARNINGS: none *
  2700. * *
  2701. * HISTORY: *
  2702. * 09/30/1996 BWG : Created. *
  2703. * 09/30/1996 JLB : Uses standard facing conversion and distance routines. *
  2704. *=============================================================================================*/
  2705. bool TechnoClass::Electric_Zap(COORDINATE target_coord, int which, WindowNumberType window, COORDINATE source_coord, unsigned char * remap) const
  2706. {
  2707. //int x,y,x1,y1;
  2708. //PG init variables
  2709. int x = 0;
  2710. int y = 0;
  2711. int x1 = 0;
  2712. int y1 = 0;
  2713. COORDINATE source;
  2714. if (source_coord != 0) {
  2715. source = source_coord;
  2716. } else {
  2717. source = Fire_Coord(which);
  2718. }
  2719. if (What_Am_I() == RTTI_BUILDING) {
  2720. ((BuildingClass *)this)->IsCharging = false;
  2721. }
  2722. bool gonnadraw = false;
  2723. if (SpecialDialog == SDLG_NONE) {
  2724. Map.Coord_To_Pixel(source, x, y);
  2725. Map.Coord_To_Pixel(target_coord, x1, y1);
  2726. x += Map.TacPixelX;
  2727. x1 += Map.TacPixelX;
  2728. y += Map.TacPixelY;
  2729. y1 += Map.TacPixelY;
  2730. gonnadraw = true;
  2731. }
  2732. static int _shape[]={ 2, 3, 1, 0, 2, 3, 1, 0};
  2733. static int _xadd[8][8]={
  2734. { 0, 8, 8, 8, 0, 0, 0, 0},
  2735. { 0, 8, 8, 8, 0, 0, 0, 0},
  2736. { 0, 8, 8, 8, 0, 0, 0, 0},
  2737. { 0, 8, 8, 8, 0, 0, 0, 0},
  2738. { 0, 8, 8, 8, 0, 0, 0, 0},
  2739. {-8, 0, 0, 0,-8,-8,-8,-8},
  2740. {-8, 0, 0, 0,-8,-8,-8,-8},
  2741. {-8, 0, 0, 0,-8,-8,-8,-8}
  2742. };
  2743. static int _yadd[8][8]={
  2744. {-8,-8,-8, 0, 0, 0,-8,-8},
  2745. {-8,-8,-8, 0, 0, 0,-8,-8},
  2746. { 0, 0, 0, 8, 8, 8, 0, 0},
  2747. { 0, 0, 0, 8, 8, 8, 0, 0},
  2748. { 0, 0, 0, 8, 8, 8, 0, 0},
  2749. { 0, 0, 0, 8, 8, 8, 0, 0},
  2750. { 0, 0, 0, 8, 8, 8, 0, 0},
  2751. {-8,-8,-8, 0, 0, 0,-8,-8}
  2752. };
  2753. int savex = x, savey = y;
  2754. if (gonnadraw) {
  2755. for (int shots = 0; shots < 3; shots++) {
  2756. x = savex;
  2757. y = savey;
  2758. int lastfacing = 0;
  2759. while (::Distance(x, y, x1, y1) > 8) {
  2760. /*
  2761. ** Determine true (0..7) facing from current position to
  2762. ** destination (actually the source coordinate of the zap).
  2763. */
  2764. int facing = Dir_Facing(Desired_Facing8(x, y, x1, y1));
  2765. /*
  2766. ** If there's quite a bit of distance to go,
  2767. ** we may vary the desired facing to give the
  2768. ** bolt some randomness.
  2769. */
  2770. if (::Distance(x, y, x1, y1) > 40) {
  2771. switch (Sim_Random_Pick(1, 3 + ((shots==0) ? 3 : 0))) {
  2772. case 1:
  2773. facing++;
  2774. break;
  2775. case 2:
  2776. facing--;
  2777. break;
  2778. default:
  2779. break;
  2780. }
  2781. facing &= 7;
  2782. }
  2783. /*
  2784. ** Now that we have the direction of the bolt,
  2785. ** draw it and move the x & y coords in the right
  2786. ** direction for the next piece.
  2787. */
  2788. // Electric zap coordinates are always tactical, so don't use the partial window if passed - SKY
  2789. x += _xadd[facing][lastfacing];
  2790. y += _yadd[facing][lastfacing];
  2791. if (remap != NULL) {
  2792. CC_Draw_Shape(this, "LITNING", LightningShapes, _shape[facing]+(shots ? 4 : 0), x, y, (window != WINDOW_PARTIAL) ? window : WINDOW_TACTICAL, SHAPE_FADING|SHAPE_CENTER|SHAPE_WIN_REL, remap);
  2793. } else {
  2794. CC_Draw_Shape(this, "LITNING", LightningShapes, _shape[facing]+(shots ? 4 : 0), x, y, (window != WINDOW_PARTIAL) ? window : WINDOW_TACTICAL, SHAPE_CENTER|SHAPE_WIN_REL);
  2795. }
  2796. lastfacing = facing;
  2797. }
  2798. }
  2799. }
  2800. return (gonnadraw);
  2801. }
  2802. /***********************************************************************************************
  2803. * TechnoClass::Fire_At -- Fires projectile at target specified. *
  2804. * *
  2805. * This is the main projectile firing code. Buildings, units, and infantry route fire *
  2806. * requests through this function. *
  2807. * *
  2808. * INPUT: target -- The target that the projectile is to be fired at. *
  2809. * *
  2810. * which -- Which weapon to fire. *
  2811. * *
  2812. * OUTPUT: Returns with a pointer to the projectile object that was fired. If no projectile *
  2813. * could be created or there was some other illegality detected, the return value *
  2814. * will be NULL. *
  2815. * *
  2816. * WARNINGS: none *
  2817. * *
  2818. * HISTORY: *
  2819. * 12/26/1994 JLB : Created. *
  2820. * 07/03/1995 JLB : Moving platforms fire inaccurate projectiles. *
  2821. * 02/22/1996 JLB : Handles camera "weapon" case. *
  2822. *=============================================================================================*/
  2823. BulletClass * TechnoClass::Fire_At(TARGET target, int which)
  2824. {
  2825. assert(IsActive);
  2826. BulletClass * bullet; // Projectile.
  2827. DirType dir; // The facing to impart upon the projectile.
  2828. COORDINATE target_coord; // Coordinate of the target.
  2829. COORDINATE fire_coord; // Coordinate of firing position.
  2830. TechnoTypeClass const & tclass = *Techno_Type_Class();
  2831. ObjectClass * object;
  2832. WeaponTypeClass const * weapon = (which == 0) ? tclass.PrimaryWeapon : tclass.SecondaryWeapon;
  2833. /*
  2834. ** If this object doesn't have a weapon, then it is obvious that firing
  2835. ** cannot ever succeed. Return with failure flag.
  2836. */
  2837. if (weapon == NULL) return(NULL);
  2838. BulletTypeClass const & btype = *weapon->Bullet;
  2839. /*
  2840. ** Perform a quick legality check to see if firing can occur.
  2841. */
  2842. if (Debug_Map || !Target_Legal(target)) {
  2843. return(NULL);
  2844. }
  2845. /*
  2846. ** Fetch the target coordinate for the target specified.
  2847. */
  2848. object = As_Object(target);
  2849. if (object != NULL) {
  2850. target_coord = object->Target_Coord();
  2851. } else {
  2852. target_coord = As_Coord(target);
  2853. }
  2854. /*
  2855. ** Get the location where the projectile should appear.
  2856. */
  2857. fire_coord = Fire_Coord(which);
  2858. /*
  2859. ** If the projectile is a homing type (such as a missile), then it will
  2860. ** launch in the direction the turret is facing, NOT necessarily the same
  2861. ** direction as the target.
  2862. */
  2863. if (btype.ROT != 0 || btype.IsDropping) {
  2864. dir = Fire_Direction();
  2865. if (btype.IsDropping) {
  2866. fire_coord = Center_Coord();
  2867. }
  2868. } else {
  2869. dir = ::Direction(fire_coord, target_coord);
  2870. }
  2871. /*
  2872. ** Create the projectile. Then process any special operations that
  2873. ** need to be performed according to the style of projectile
  2874. ** created.
  2875. */
  2876. int firepower = weapon->Attack;
  2877. if (firepower > 0) {
  2878. firepower = weapon->Attack * FirepowerBias * House->FirepowerBias;
  2879. }
  2880. /*
  2881. ** Give the bullet a boost of speed if the weapon indicates that this is required. Only
  2882. ** need to perform this check if the target is an aircraft.
  2883. */
  2884. int firespeed = weapon->MaxSpeed;
  2885. if (weapon->IsTurboBoosted && Is_Target_Aircraft(target)) {
  2886. firespeed *= Rule.TurboBoost;
  2887. }
  2888. bullet = new BulletClass(weapon->Bullet->Type, target, this, firepower, WarheadType(weapon->WarheadPtr->ID), firespeed);
  2889. if (bullet != NULL) {
  2890. /*
  2891. ** If this is firing from a moving platform, then the projectile is inaccurate.
  2892. */
  2893. if (Is_Foot() && ((FootClass const *)this)->IsDriving) {
  2894. bullet->IsInaccurate = true;
  2895. }
  2896. if (bullet->Unlimbo(fire_coord, dir)) {
  2897. } else {
  2898. delete bullet;
  2899. }
  2900. if (tclass.IsTurretEquipped) {
  2901. IsInRecoilState = true;
  2902. Mark(MARK_CHANGE_REDRAW);
  2903. }
  2904. Arm = Rearm_Delay(IsSecondShot, which);
  2905. if (tclass.Is_Two_Shooter()) {
  2906. IsSecondShot = (IsSecondShot == false);
  2907. }
  2908. /*
  2909. ** Perform any animation effect for this weapon.
  2910. */
  2911. AnimType a = weapon->Anim;
  2912. switch (a) {
  2913. case ANIM_GUN_N:
  2914. a = AnimType(a + Dir_Facing(Fire_Direction()));
  2915. break;
  2916. case ANIM_SAM_N:
  2917. a = AnimType(ANIM_SAM_N + Dir_Facing(PrimaryFacing.Current()));
  2918. break;
  2919. }
  2920. /*
  2921. ** Play any sound effect tied to this weapon type.
  2922. */
  2923. Sound_Effect(weapon->Sound, Fire_Coord(which));
  2924. /*
  2925. ** If there is a special firing animation, then create and attach it
  2926. ** now.
  2927. */
  2928. if (a != ANIM_NONE) {
  2929. AnimClass * anim = new AnimClass(a, Fire_Coord(which));
  2930. if (anim != NULL) {
  2931. anim->Attach_To(this);
  2932. }
  2933. }
  2934. /*
  2935. ** Electric zap animation.
  2936. */
  2937. if (weapon->IsElectric) {
  2938. ElectricZapDelay = 3;
  2939. ElectricZapTarget = target_coord;
  2940. ElectricZapWhich = which;
  2941. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  2942. if(What_Am_I() != RTTI_INFANTRY) {
  2943. Set_Stage(0);
  2944. Set_Rate(0);
  2945. }
  2946. #else
  2947. Set_Stage(0);
  2948. Set_Rate(0);
  2949. #endif
  2950. if (Ammo <= 1 && What_Am_I() == RTTI_BUILDING) {
  2951. ((BuildingClass *)this)->IsCharged = false;
  2952. }
  2953. TechnoClass * tech = As_Techno(target);
  2954. if (tech != NULL) {
  2955. tech->Clicked_As_Target(PlayerPtr->Class->House, 4); // 2019/09/20 JAS - Added record of who clicked on the object
  2956. }
  2957. }
  2958. /*
  2959. ** Reduce ammunition for this object.
  2960. */
  2961. if (Ammo > 0) {
  2962. Ammo--;
  2963. }
  2964. /*
  2965. ** Firing will in all likelihood, require the unit to be redrawn. Flag it to be
  2966. ** redrawn here.
  2967. */
  2968. Mark(MARK_CHANGE);
  2969. /*
  2970. ** If a projectile was fired from a unit that is hidden in the darkness,
  2971. ** reveal that unit and a little area around it.
  2972. ** For multiplayer games, only reveal the unit if the target is the
  2973. ** local player.
  2974. */
  2975. #if (0)
  2976. if ((!IsOwnedByPlayer && !IsDiscoveredByPlayer) || (!Map[Center_Coord()].IsMapped && (What_Am_I()!=RTTI_AIRCRAFT || !IsOwnedByPlayer)) ) {
  2977. if (Session.Type == GAME_NORMAL) {
  2978. Map.Sight_From(Coord_Cell(Center_Coord()), 2, PlayerPtr, false);
  2979. } else {
  2980. ObjectClass * obj = As_Object(target);
  2981. if (obj != NULL) {
  2982. HousesType tgt_owner = obj->Owner();
  2983. if (PlayerPtr->Class->House == tgt_owner) {
  2984. Map.Sight_From(Coord_Cell(Center_Coord()), 2, PlayerPtr, false);
  2985. }
  2986. }
  2987. }
  2988. }
  2989. #else
  2990. /*
  2991. ** For client/server multiplayer, we need to reveal for any human player that is the target. ST - 3/13/2019 5:43PM
  2992. */
  2993. ObjectClass *obj = As_Object(target);
  2994. if (obj) {
  2995. HousesType tgt_owner = obj->Owner();
  2996. HouseClass *player = HouseClass::As_Pointer(tgt_owner);
  2997. if ((player != NULL) && player->IsHuman) {
  2998. if ((!Is_Owned_By_Player(player) && !Is_Discovered_By_Player(player)) || (!Map[Coord_Cell(Center_Coord())].Is_Mapped(House) && (What_Am_I()!=RTTI_AIRCRAFT || !Is_Owned_By_Player(player))) ) {
  2999. Map.Sight_From(Coord_Cell(Center_Coord()), 1, player, false);
  3000. }
  3001. }
  3002. }
  3003. /*
  3004. ** For electric zaps, immediately perform bullet logic.
  3005. */
  3006. if (weapon->IsElectric) {
  3007. bullet->AI();
  3008. }
  3009. #endif
  3010. }
  3011. return(bullet);
  3012. }
  3013. /***********************************************************************************************
  3014. * TechnoClass::Player_Assign_Mission -- Assigns a mission as result of player input. *
  3015. * *
  3016. * This routine is called when the mission for an object needs to change as a result of *
  3017. * player input. The basic operation would be to queue the event and let the action *
  3018. * occur at the frame dictated by the queuing system. However, if a voice response is *
  3019. * indicated, then perform it at this time. This will give a greater illusion of *
  3020. * immediate response. *
  3021. * *
  3022. * INPUT: mission -- The mission order to assign to this object. *
  3023. * *
  3024. * target -- The target of this object. This will be used for combat and attack. *
  3025. * *
  3026. * destination -- The movement destination for this object. *
  3027. * *
  3028. * OUTPUT: none *
  3029. * *
  3030. * WARNINGS: none *
  3031. * *
  3032. * HISTORY: *
  3033. * 05/22/1995 JLB : Created. *
  3034. *=============================================================================================*/
  3035. void TechnoClass::Player_Assign_Mission(MissionType mission, TARGET target, TARGET destination)
  3036. {
  3037. assert(IsActive);
  3038. if (AllowVoice) {
  3039. if (mission == MISSION_ATTACK) {
  3040. Response_Attack();
  3041. } else {
  3042. Response_Move();
  3043. }
  3044. }
  3045. if (FormMove) {
  3046. SpeedType speed = FormSpeed;
  3047. MPHType maxspeed = FormMaxSpeed;
  3048. if (Is_Foot()) {
  3049. const FootClass* foot = (const FootClass*)this;
  3050. if (foot->Group < MAX_TEAMS) {
  3051. TeamFormDataStruct& team_form_data = TeamFormData[foot->Owner()];
  3052. speed = team_form_data.TeamSpeed[foot->Group];
  3053. maxspeed = team_form_data.TeamMaxSpeed[foot->Group];
  3054. }
  3055. }
  3056. Queue_Mission(TargetClass(this), mission, target, destination, speed, maxspeed);
  3057. } else {
  3058. /*
  3059. ** Cooerce the movement mission into a queued movement mission if the ALT key was
  3060. ** held down.
  3061. */
  3062. //
  3063. // MBL 04.14.2020 Original code KO, since is still active and can still hit
  3064. //
  3065. // if (mission == MISSION_MOVE && (Keyboard->Down(Options.KeyQueueMove1) || Keyboard->Down(Options.KeyQueueMove2))) {
  3066. // mission = MISSION_QMOVE;
  3067. // }
  3068. //
  3069. // MBL 04.14.2020 - Apply the same logic as above, using what is assigned as hotkeys
  3070. //
  3071. if (PlayerPtr && House) {
  3072. if (PlayerPtr == House) {
  3073. if (mission == MISSION_MOVE && PlayerPtr->IsQueuedMovementToggle) {
  3074. mission = MISSION_QMOVE;
  3075. }
  3076. }
  3077. }
  3078. Queue_Mission(TargetClass(this), mission, target, destination);
  3079. }
  3080. }
  3081. /***********************************************************************************************
  3082. * TechnoClass::What_Action -- Determines what action to perform if object is selected. *
  3083. * *
  3084. * This routine will examine the object specified and return with the action that will *
  3085. * be performed if the mouse button were clicked over the object. *
  3086. * *
  3087. * INPUT: object -- The object that the mouse button might be clicked on. *
  3088. * *
  3089. * OUTPUT: Returns with the action that will be performed if the object was clicked on. *
  3090. * *
  3091. * WARNINGS: none *
  3092. * *
  3093. * HISTORY: *
  3094. * 01/19/1995 JLB : Created. *
  3095. * 03/21/1995 JLB : Special target control for trees. *
  3096. *=============================================================================================*/
  3097. ActionType TechnoClass::What_Action(ObjectClass const * object) const
  3098. {
  3099. assert(IsActive);
  3100. if (object != NULL) {
  3101. /*
  3102. ** Return the ACTION_SELF flag if clicking on itself. However, if this
  3103. ** object cannot do anything special with itself, then just return with
  3104. ** the no action flag.
  3105. */
  3106. if (object == this && CurrentObject.Count() == 1 && House->IsPlayerControl) {
  3107. return(ACTION_SELF);
  3108. }
  3109. //bool altdown = (Keyboard->Down(Options.KeyForceMove1) || Keyboard->Down(Options.KeyForceMove2));
  3110. //bool ctrldown = (Keyboard->Down(Options.KeyForceAttack1) || Keyboard->Down(Options.KeyForceAttack2));
  3111. //bool shiftdown = (Keyboard->Down(Options.KeySelect1) || Keyboard->Down(Options.KeySelect2));
  3112. //Added for getting the input for special character keys from the client
  3113. // - 6/26/2019 JAS
  3114. bool altdown = DLL_Export_Get_Input_Key_State(KN_LALT);
  3115. bool ctrldown = DLL_Export_Get_Input_Key_State(KN_LCTRL);
  3116. bool shiftdown = DLL_Export_Get_Input_Key_State(KN_LSHIFT);
  3117. /*
  3118. ** Special guard area mission is possible if both the control and the
  3119. ** alt keys are held down.
  3120. */
  3121. if (House->IsPlayerControl && ctrldown && altdown && Can_Player_Move() /*KO && Can_Player_Fire()*/) {
  3122. // if (House->IsPlayerControl && ctrldown && altdown && Can_Player_Move() && Can_Player_Fire()) {
  3123. return(ACTION_GUARD_AREA);
  3124. }
  3125. /*
  3126. ** Special override to force a move regardless of what is occupying the location.
  3127. */
  3128. if (altdown) {
  3129. if (House->IsPlayerControl && Can_Player_Move()) {
  3130. return(ACTION_MOVE);
  3131. }
  3132. }
  3133. /*
  3134. ** Override so that toggled select state can be performed while the <SHIFT> key
  3135. ** is held down.
  3136. */
  3137. bool is_a_loaner = object->Is_Techno() && ((TechnoClass*)object)->IsALoaner;
  3138. if (shiftdown) {
  3139. if (!is_a_loaner) {
  3140. return(ACTION_TOGGLE_SELECT);
  3141. }
  3142. }
  3143. /*
  3144. ** If the weapon is blatantly disallowed from firing on the object specified, then
  3145. ** don't allow the attach check logic to proceed.
  3146. */
  3147. TechnoTypeClass const * ttype = Techno_Type_Class();
  3148. if (Is_Weapon_Equipped() &&
  3149. ttype->PrimaryWeapon->Bullet != NULL &&
  3150. ttype->PrimaryWeapon->Bullet->IsSubSurface &&
  3151. Map[object->Target_Coord()].Land_Type() != LAND_WATER) {
  3152. // Do nothing.
  3153. } else {
  3154. /*
  3155. ** If firing is possible and legal, then return this action potential.
  3156. */
  3157. if (House->IsPlayerControl && (ctrldown || !House->Is_Ally(object)) && (ctrldown || object->Class_Of().IsLegalTarget || (Rule.IsTreeTarget && object->What_Am_I() == RTTI_TERRAIN))) {
  3158. if (Is_Weapon_Equipped() ||
  3159. (What_Am_I() == RTTI_INFANTRY &&
  3160. (((InfantryTypeClass const *)ttype)->IsBomber ||
  3161. ((InfantryTypeClass const *)ttype)->IsCapture)
  3162. )) {
  3163. // Check for anti-air capability
  3164. int primary = What_Weapon_Should_I_Use(object->As_Target());
  3165. WeaponTypeClass const * weapon = (primary == 0) ? Techno_Type_Class()->PrimaryWeapon : Techno_Type_Class()->SecondaryWeapon;
  3166. if ((object->What_Am_I() != RTTI_AIRCRAFT) ||
  3167. ((weapon != NULL) && weapon->Bullet->IsAntiAircraft) ||
  3168. (object->Is_Techno() && (((TechnoClass *)object)->Height == 0))) {
  3169. if (Can_Player_Move() || In_Range(object, primary)) {
  3170. if (In_Range(object, primary) || (What_Am_I() == RTTI_INFANTRY && ((InfantryClass *)this)->Class->IsCapture && object->What_Am_I() == RTTI_BUILDING && object->Can_Capture())) {
  3171. return(ACTION_ATTACK);
  3172. } else {
  3173. if (!Can_Player_Move()) {
  3174. return(ACTION_NONE);
  3175. } else {
  3176. return(ACTION_ATTACK);
  3177. }
  3178. }
  3179. }
  3180. }
  3181. }
  3182. }
  3183. }
  3184. /*
  3185. ** Possibly try to select the specified object, if that is warranted.
  3186. */
  3187. if (!Is_Weapon_Equipped() || !House->IsPlayerControl || object->Owner() == Owner()) {
  3188. if ((!is_a_loaner || !Is_Owned_By_Player()) && object->Class_Of().IsSelectable && (!object->Is_Selected_By_Player() || CurrentObject.Count())) {
  3189. return(ACTION_SELECT);
  3190. }
  3191. return(ACTION_NONE);
  3192. }
  3193. }
  3194. return(ACTION_NONE);
  3195. }
  3196. /***********************************************************************************************
  3197. * TechnoClass::What_Action -- Determines action to perform if cell is clicked on. *
  3198. * *
  3199. * Use this routine to determine what action will be performed if the specified cell *
  3200. * is clicked on. Usually this action is either a ACTION_MOVE or ACTION_NOMOVE. The action *
  3201. * nomove is used to perform special case checking for nearby cells if in fact the mouse *
  3202. * is clicked over the cell. *
  3203. * *
  3204. * INPUT: cell -- The cell to check for being clicked over. *
  3205. * *
  3206. * OUTPUT: Returns with the action that will occur if the cell is clicked on. *
  3207. * *
  3208. * WARNINGS: none *
  3209. * *
  3210. * HISTORY: *
  3211. * 01/19/1995 JLB : Created. *
  3212. * 07/10/1995 JLB : Force fire for buildings is explicitly disabled. *
  3213. *=============================================================================================*/
  3214. ActionType TechnoClass::What_Action(CELL cell) const
  3215. {
  3216. assert(IsActive);
  3217. CellClass const * cellptr = &Map[cell];
  3218. OverlayTypeClass const * optr = NULL;
  3219. //bool altdown = (Keyboard->Down(Options.KeyForceMove1) || Keyboard->Down(Options.KeyForceMove2));
  3220. //bool ctrldown = (Keyboard->Down(Options.KeyForceAttack1) || Keyboard->Down(Options.KeyForceAttack2));
  3221. //bool shiftdown = (Keyboard->Down(Options.KeySelect1) || Keyboard->Down(Options.KeySelect2));
  3222. //Added for getting the input for special character keys from the client
  3223. // - 6/26/2019 JAS
  3224. bool altdown = DLL_Export_Get_Input_Key_State(KN_LALT);
  3225. bool ctrldown = DLL_Export_Get_Input_Key_State(KN_LCTRL);
  3226. bool shiftdown = DLL_Export_Get_Input_Key_State(KN_LSHIFT);
  3227. /*
  3228. ** Disable recognizing the <CTRL> key forced fire option when dealing with buildings.
  3229. */
  3230. if (What_Am_I() == RTTI_BUILDING) ctrldown = false;
  3231. /*
  3232. ** Disable recognizing the <CTRL> key forced fire option when dealing with submarines.
  3233. */
  3234. if(What_Am_I() == RTTI_VESSEL) {
  3235. WeaponTypeClass const * weapon = ((VesselClass *)this)->Class->PrimaryWeapon;
  3236. if (weapon && weapon->Bullet->IsSubSurface) ctrldown = false;
  3237. }
  3238. if (cellptr->Overlay != OVERLAY_NONE) {
  3239. optr = &OverlayTypeClass::As_Reference(cellptr->Overlay);
  3240. }
  3241. /*
  3242. ** Special guard area mission is possible if both the control and the
  3243. ** alt keys are held down.
  3244. */
  3245. if (House->IsPlayerControl && ctrldown && altdown && Can_Player_Move() && Can_Player_Fire()) {
  3246. return(ACTION_GUARD_AREA);
  3247. }
  3248. if (House->IsPlayerControl && Techno_Type_Class()->PrimaryWeapon != NULL && (ctrldown || (optr && optr->IsLegalTarget))) {
  3249. WarheadTypeClass const * whead = Techno_Type_Class()->PrimaryWeapon->WarheadPtr;
  3250. // To be fixed for firing on ore by accounting for ore and ignoring the overlay in that case.
  3251. if (optr == NULL || (optr->IsWall && (whead->IsWallDestroyer || (whead->IsWoodDestroyer && optr->IsWooden)))) {
  3252. int primary = What_Weapon_Should_I_Use(::As_Target(cell));
  3253. if (Can_Player_Move() || In_Range(::As_Target(cell), primary)) {
  3254. return(ACTION_ATTACK);
  3255. }
  3256. }
  3257. }
  3258. if (House->IsPlayerControl && Can_Player_Move()) {
  3259. /*
  3260. ** Special override to force a move regardless of what is occupying the location.
  3261. */
  3262. if (shiftdown) {
  3263. return(ACTION_MOVE);
  3264. }
  3265. /*
  3266. ** If the object can enter the cell specified, then allow
  3267. ** movement to it.
  3268. */
  3269. if (Can_Enter_Cell(cell) <= MOVE_CLOAK) {
  3270. return(ACTION_MOVE);
  3271. }
  3272. return(ACTION_NOMOVE);
  3273. }
  3274. return(ACTION_NONE);
  3275. }
  3276. /***********************************************************************************************
  3277. * TechnoClass::Can_Player_Move -- Determines if the object can move be moved by player. *
  3278. * *
  3279. * Use this routine to determine whether a movement order can be given to this object. *
  3280. * *
  3281. * INPUT: none *
  3282. * *
  3283. * OUTPUT: bool; Can this object be given a movement order by the player? *
  3284. * *
  3285. * WARNINGS: none *
  3286. * *
  3287. * HISTORY: *
  3288. * 01/19/1995 JLB : Created. *
  3289. *=============================================================================================*/
  3290. bool TechnoClass::Can_Player_Move(void) const
  3291. {
  3292. assert(IsActive);
  3293. return(House->IsPlayerControl);
  3294. }
  3295. /***********************************************************************************************
  3296. * TechnoClass::Can_Player_Fire -- Determines if the player can give this object a fire order. *
  3297. * *
  3298. * Call this routine to determine if this object can be given a fire order by the player. *
  3299. * Such objects will affect the mouse cursor accordingly -- usually causes the targeting *
  3300. * cursor to appear. *
  3301. * *
  3302. * INPUT: none *
  3303. * *
  3304. * OUTPUT: bool; Can this object be given firing orders by the player? *
  3305. * *
  3306. * WARNINGS: none *
  3307. * *
  3308. * HISTORY: *
  3309. * 01/23/1995 JLB : Created. *
  3310. *=============================================================================================*/
  3311. bool TechnoClass::Can_Player_Fire(void) const
  3312. {
  3313. assert(IsActive);
  3314. if (House->IsPlayerControl && Is_Techno() && Techno_Type_Class()->PrimaryWeapon != NULL) {
  3315. return(true);
  3316. }
  3317. return(false);
  3318. }
  3319. /***********************************************************************************************
  3320. * TechnoClass::Is_Weapon_Equipped -- Determines if this object has a combat weapon. *
  3321. * *
  3322. * Use this routine to determine if this object is equipped with a combat weapon. Such *
  3323. * determination is used by the AI system to gauge the threat potential of the object. *
  3324. * *
  3325. * INPUT: none *
  3326. * *
  3327. * OUTPUT: bool; Is this object equipped with a combat weapon? *
  3328. * *
  3329. * WARNINGS: none *
  3330. * *
  3331. * HISTORY: *
  3332. * 01/23/1995 JLB : Created. *
  3333. *=============================================================================================*/
  3334. bool TechnoClass::Is_Weapon_Equipped(void) const
  3335. {
  3336. assert(IsActive);
  3337. return(Techno_Type_Class()->PrimaryWeapon != NULL);
  3338. }
  3339. /***********************************************************************************************
  3340. * TechnoClass::Can_Repair -- Determines if the object can and should be repaired. *
  3341. * *
  3342. * Use this routine to determine if the specified object is a candidate for repair. In *
  3343. * order to qualify, the object must be allowed to be repaired (in theory) and it must *
  3344. * be below full strength. If these conditions are met, then it can be repaired. *
  3345. * *
  3346. * INPUT: none *
  3347. * *
  3348. * OUTPUT: bool; May this unit be repaired? A return value of false may mean that the object *
  3349. * is not allowed to be repaired, or it might be full strength already. *
  3350. * *
  3351. * WARNINGS: none *
  3352. * *
  3353. * HISTORY: *
  3354. * 01/23/1995 JLB : Created. *
  3355. *=============================================================================================*/
  3356. bool TechnoClass::Can_Repair(void) const
  3357. {
  3358. assert(IsActive);
  3359. /*
  3360. ** Temporary hack to disable repair cursor over non-buildings.
  3361. */
  3362. if (What_Am_I() != RTTI_BUILDING) {
  3363. return(false);
  3364. }
  3365. return(Techno_Type_Class()->IsRepairable && Strength != Class_Of().MaxStrength);
  3366. }
  3367. /***********************************************************************************************
  3368. * TechnoClass::Weapon_Range -- Determines the maximum range for the weapon. *
  3369. * *
  3370. * Use this routine to determine the maximum range for the weapon indicated. *
  3371. * *
  3372. * INPUT: which -- Which weapon to use when determining the range. 0=primary, 1=secondary. *
  3373. * *
  3374. * OUTPUT: Returns with the range of the weapon (in leptons). *
  3375. * *
  3376. * WARNINGS: none *
  3377. * *
  3378. * HISTORY: *
  3379. * 03/19/1995 JLB : Created. *
  3380. *=============================================================================================*/
  3381. int TechnoClass::Weapon_Range(int which) const
  3382. {
  3383. assert(IsActive);
  3384. assert((unsigned)which < 2);
  3385. WeaponTypeClass const * weapon = NULL;
  3386. TechnoTypeClass const & ttype = *Techno_Type_Class();
  3387. switch (which) {
  3388. case 0:
  3389. weapon = ttype.PrimaryWeapon;
  3390. break;
  3391. case 1:
  3392. weapon = ttype.SecondaryWeapon;
  3393. break;
  3394. }
  3395. if (weapon != NULL) {
  3396. return(weapon->Range);
  3397. }
  3398. return(0);
  3399. }
  3400. /***************************************************************************
  3401. * TechnoClass::Override_Mission -- temporarily overrides a units mission *
  3402. * *
  3403. * *
  3404. * *
  3405. * INPUT: MissionType mission - the mission we want to override *
  3406. * TARGET tarcom - the new target we want to override *
  3407. * TARGET navcom - the new navigation point to override*
  3408. * *
  3409. * OUTPUT: none *
  3410. * *
  3411. * WARNINGS: If a mission is already overridden, the current mission is *
  3412. * just re-assigned. *
  3413. * *
  3414. * HISTORY: *
  3415. * 04/28/1995 PWG : Created. *
  3416. *=========================================================================*/
  3417. void TechnoClass::Override_Mission(MissionType mission, TARGET tarcom, TARGET navcom)
  3418. {
  3419. assert(IsActive);
  3420. SuspendedTarCom = TarCom;
  3421. RadioClass::Override_Mission(mission, tarcom, navcom);
  3422. Assign_Target(tarcom);
  3423. }
  3424. /***************************************************************************
  3425. * TechnoClass::Restore_Mission -- Restores an overridden mission *
  3426. * *
  3427. * INPUT: none *
  3428. * *
  3429. * OUTPUT: none *
  3430. * *
  3431. * WARNINGS: none *
  3432. * *
  3433. * HISTORY: *
  3434. * 04/28/1995 PWG : Created. *
  3435. *=========================================================================*/
  3436. bool TechnoClass::Restore_Mission(void)
  3437. {
  3438. assert(IsActive);
  3439. if (RadioClass::Restore_Mission()) {
  3440. Assign_Target(SuspendedTarCom);
  3441. return(true);
  3442. }
  3443. return(false);
  3444. }
  3445. /***********************************************************************************************
  3446. * TechnoClass::Renovate -- Heal a building to maximum *
  3447. * *
  3448. * *
  3449. * INPUT: none *
  3450. * *
  3451. * OUTPUT: none *
  3452. * *
  3453. * WARNINGS: none *
  3454. * *
  3455. * HISTORY: *
  3456. * 04/15/1996 BWG : Created. *
  3457. *=============================================================================================*/
  3458. void TechnoClass::Renovate(void)
  3459. {
  3460. assert(IsActive);
  3461. Mark(MARK_CHANGE);
  3462. Strength = Techno_Type_Class()->MaxStrength;
  3463. if (What_Am_I() == RTTI_BUILDING) {
  3464. ((BuildingClass *)this)->Repair(0);
  3465. }
  3466. }
  3467. /***********************************************************************************************
  3468. * TechnoClass::Captured -- Handles capturing this object. *
  3469. * *
  3470. * This routine is called when this object gets captured by the house specified. It handles *
  3471. * removing this object from any targeting computers and then changes the ownership of *
  3472. * the object to the new house. *
  3473. * *
  3474. * INPUT: newowner -- Pointer to the house that is now the new owner. *
  3475. * *
  3476. * OUTPUT: Was the object captured? Failure would mean that it is already under control of *
  3477. * the house specified. *
  3478. * *
  3479. * WARNINGS: none *
  3480. * *
  3481. * HISTORY: *
  3482. * 05/08/1995 JLB : Created. *
  3483. * 09/29/1995 JLB : Keeps track of quantity records. *
  3484. *=============================================================================================*/
  3485. bool TechnoClass::Captured(HouseClass * newowner)
  3486. {
  3487. assert(IsActive);
  3488. if (newowner != House) {
  3489. /*
  3490. ** Capture attempt springs any "entered" trigger. The entered trigger
  3491. ** occurs first since there may be a special trigger attached to this
  3492. ** object that flags a capture as a win and a destroy as a loss. This
  3493. ** order is necessary because the object is recorded as a kill as well.
  3494. */
  3495. if (Trigger.Is_Valid()) {
  3496. Trigger->Spring(TEVENT_PLAYER_ENTERED, this);
  3497. }
  3498. /*
  3499. ** Record this as a kill.
  3500. */
  3501. Record_The_Kill(NULL);
  3502. /*
  3503. ** Special kill record logic for capture process.
  3504. */
  3505. House->Tracking_Remove(this);
  3506. newowner->Tracking_Add(this);
  3507. switch (What_Am_I()) {
  3508. case RTTI_BUILDING:
  3509. newowner->BuildingsKilled[Owner()]++;
  3510. break;
  3511. case RTTI_AIRCRAFT:
  3512. case RTTI_INFANTRY:
  3513. case RTTI_UNIT:
  3514. case RTTI_VESSEL:
  3515. newowner->UnitsKilled[Owner()]++;
  3516. break;
  3517. default:
  3518. break;
  3519. }
  3520. House->WhoLastHurtMe = newowner->Class->House;
  3521. /*
  3522. ** Remove from targeting computers.
  3523. */
  3524. Detach_All(false);
  3525. /*
  3526. ** Change ownership now.
  3527. */
  3528. House = newowner;
  3529. IsOwnedByPlayer = (House == PlayerPtr);
  3530. return(true);
  3531. }
  3532. return(false);
  3533. }
  3534. /***********************************************************************************************
  3535. * TechnoClass::Take_Damage -- Records damage assessed to this object. *
  3536. * *
  3537. * This routine is called when this object has taken damage. It handles recording whether *
  3538. * this object has been destroyed. If it has, then mark the appropriate kill records as *
  3539. * necessary. *
  3540. * *
  3541. * INPUT: *
  3542. * *
  3543. * OUTPUT: *
  3544. * *
  3545. * WARNINGS: *
  3546. * *
  3547. * HISTORY: *
  3548. * 06/20/1995 JLB : Created. *
  3549. *=============================================================================================*/
  3550. ResultType TechnoClass::Take_Damage(int & damage, int distance, WarheadType warhead, TechnoClass * source, bool forced)
  3551. {
  3552. assert(IsActive);
  3553. ResultType result = RESULT_NONE;
  3554. /*
  3555. ** If not a forced damage condition, adjust damage according to house override armor
  3556. ** value.
  3557. */
  3558. if (!forced && damage > 0) {
  3559. damage = damage * ArmorBias * House->ArmorBias;
  3560. }
  3561. if (IronCurtainCountDown == 0) {
  3562. result = ObjectClass::Take_Damage(damage, distance, warhead, source, forced);
  3563. }
  3564. switch (result) {
  3565. case RESULT_DESTROYED:
  3566. Transmit_Message(RADIO_OVER_OUT);
  3567. Stun();
  3568. /*
  3569. ** If this object explodes with violent damage, then perform the explosion
  3570. ** now and use the warhead type and full strength as the explosion values.
  3571. */
  3572. if (Techno_Type_Class()->IsExploding) {
  3573. /*
  3574. ** The warhead to use is based on the weapon this object is equipped with.
  3575. */
  3576. WarheadType wh = WARHEAD_HE;
  3577. if (Techno_Type_Class()->PrimaryWeapon != NULL) {
  3578. wh = WarheadType(Techno_Type_Class()->PrimaryWeapon->WarheadPtr->ID);
  3579. }
  3580. int damage = Techno_Type_Class()->MaxStrength;
  3581. new AnimClass(Combat_Anim(damage, wh, Map[Center_Coord()].Land_Type()), Center_Coord());
  3582. int radius = damage * Rule.ExplosionSpread;
  3583. // int radius = damage/2;
  3584. Wide_Area_Damage(Center_Coord(), radius, damage, source, wh);
  3585. }
  3586. if (this == (TechnoClass *)::As_Object(House->UnitToTeleport)) {
  3587. House->UnitToTeleport = 0;
  3588. if (!Scen.IsFadingColor) {
  3589. Scen.IsFadingBW = false;
  3590. Scen.IsFadingColor = true;
  3591. Scen.FadeTimer = GRAYFADETIME;
  3592. }
  3593. if (Map.IsTargettingMode == SPC_CHRONO2) {
  3594. KeyNumType input = KN_RMOUSE;
  3595. Map.AI(input, 0, 0);
  3596. }
  3597. }
  3598. /*
  3599. ** May trigger an achievement. ST - 11/14/2019 1:56PM
  3600. */
  3601. if (Session.Type == GAME_NORMAL && !House->IsHuman && source && source->House && source->House->IsHuman) {
  3602. TechnoTypeClass const *object_type = Techno_Type_Class();
  3603. if (object_type) {
  3604. RTTIType what = What_Am_I();
  3605. if (what == RTTI_AIRCRAFT || what == RTTI_INFANTRY || what == RTTI_UNIT || what == RTTI_VESSEL) {
  3606. On_Achievement_Event(source->House, "UNIT_DESTROYED", object_type->IniName);
  3607. }
  3608. }
  3609. }
  3610. break;
  3611. /*
  3612. ** If some damage was received and this object is cloaked, shimmer
  3613. ** the cloak a bit.
  3614. */
  3615. default:
  3616. if (source != NULL && !House->Is_Ally(source)) {
  3617. IsTickedOff = true;
  3618. }
  3619. Do_Shimmer();
  3620. break;
  3621. case RESULT_NONE:
  3622. break;
  3623. }
  3624. return(result);
  3625. }
  3626. /***********************************************************************************************
  3627. * TechnoClass::Record_The_Kill -- Records the death of this object. *
  3628. * *
  3629. * This routine is used to record the death of this object. It will handle updating the *
  3630. * owner house with the kill record as well as springing any trigger events associated with *
  3631. * this object's death. *
  3632. * *
  3633. * INPUT: source -- Pointer to the source of this object's death (if there is a source). *
  3634. * *
  3635. * OUTPUT: none *
  3636. * *
  3637. * WARNINGS: none *
  3638. * *
  3639. * HISTORY: *
  3640. * 07/08/1995 JLB : Created. *
  3641. * 08/23/1995 JLB : Building loss is only counted if it received damage. *
  3642. *=============================================================================================*/
  3643. void TechnoClass::Record_The_Kill(TechnoClass * source)
  3644. {
  3645. assert(IsActive);
  3646. int total_recorded = 0;
  3647. int points = Techno_Type_Class()->Points;
  3648. /*
  3649. ** Handle any trigger event associated with this object.
  3650. */
  3651. if (Trigger.Is_Valid() && source) Trigger->Spring(TEVENT_ATTACKED, this);
  3652. if (Trigger.Is_Valid() && source) Trigger->Spring(TEVENT_DISCOVERED, this);
  3653. if (Trigger.Is_Valid()) Trigger->Spring(TEVENT_DESTROYED, this);
  3654. if (source != NULL) {
  3655. Crew.Made_A_Kill();
  3656. House->WhoLastHurtMe = source->Owner();
  3657. /*
  3658. ** Add up the score for killing this unit
  3659. */
  3660. source->House->PointTotal += points;
  3661. }
  3662. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  3663. // Hack check: if they were trying to teleport this unit when it died, take
  3664. // the map mode out of teleportation mode.
  3665. if(IsOwnedByPlayer && Map.IsTargettingMode == SPC_CHRONO2 && House->UnitToTeleport == As_Target()) {
  3666. Map.IsTargettingMode = SPC_NONE;
  3667. }
  3668. #endif
  3669. switch (What_Am_I()) {
  3670. case RTTI_BUILDING:
  3671. {
  3672. StructType bldg = *(BuildingClass *)this;
  3673. if (bldg != STRUCT_BARREL && bldg != STRUCT_BARREL3 &&
  3674. bldg != STRUCT_APMINE && bldg != STRUCT_AVMINE) {
  3675. if (((BuildingClass *)this)->WhoLastHurtMe != HOUSE_NONE) {
  3676. House->BuildingsLost++;
  3677. }
  3678. if (source != NULL) {
  3679. if (Session.Type == GAME_INTERNET) {
  3680. source->House->DestroyedBuildings->Increment_Unit_Total( ((BuildingClass*)this)->Class->Type );
  3681. }
  3682. source->House->BuildingsKilled[Owner()]++;
  3683. }
  3684. /*
  3685. ** If the map is displaying the multiplayer player names & their
  3686. ** # of kills, tell it to redraw.
  3687. */
  3688. if (Map.Is_Player_Names()) {
  3689. Map.Player_Names(true);
  3690. }
  3691. }
  3692. }
  3693. break;
  3694. case RTTI_AIRCRAFT:
  3695. if (source != NULL && Session.Type == GAME_INTERNET) {
  3696. source->House->DestroyedAircraft->Increment_Unit_Total( ((AircraftClass*)this)->Class->Type );
  3697. total_recorded++;
  3698. }
  3699. //Fall through.....
  3700. case RTTI_INFANTRY:
  3701. if (source != NULL && !total_recorded && Session.Type == GAME_INTERNET) {
  3702. source->House->DestroyedInfantry->Increment_Unit_Total( ((InfantryClass*)this)->Class->Type );
  3703. total_recorded++;
  3704. }
  3705. //Fall through.....
  3706. case RTTI_UNIT:
  3707. if (source != NULL && !total_recorded && Session.Type == GAME_INTERNET) {
  3708. source->House->DestroyedUnits->Increment_Unit_Total( ((UnitClass*)this)->Class->Type );
  3709. total_recorded++;
  3710. }
  3711. //Fall through.....
  3712. case RTTI_VESSEL:
  3713. if (source != NULL && !total_recorded && Session.Type == GAME_INTERNET) {
  3714. source->House->DestroyedUnits->Increment_Unit_Total( ((VesselClass*)this)->Class->Type );
  3715. }
  3716. House->UnitsLost++;
  3717. if (source != NULL) source->House->UnitsKilled[Owner()]++;
  3718. /*
  3719. ** If the map is displaying the multiplayer player names & their
  3720. ** # of kills, tell it to redraw.
  3721. */
  3722. if (Map.Is_Player_Names()) {
  3723. Map.Player_Names(true);
  3724. }
  3725. break;
  3726. default:
  3727. break;
  3728. }
  3729. /*
  3730. ** Since we lost an object, we lose the associated points as well.
  3731. */
  3732. House->PointTotal -= points;
  3733. }
  3734. /***********************************************************************************************
  3735. * TechnoClass::Nearby_Location -- Radiates outward looking for clear cell nearby. *
  3736. * *
  3737. * This routine is used to find a nearby location from center of this object. It can lean *
  3738. * toward finding a location closest to an optional object. *
  3739. * *
  3740. * INPUT: object -- Optional object that the finding algorithm will try to find a close *
  3741. * spot to. *
  3742. * *
  3743. * OUTPUT: Returns with the cell that is closest to this object. *
  3744. * *
  3745. * WARNINGS: none *
  3746. * *
  3747. * HISTORY: *
  3748. * 07/06/1995 JLB : Created. *
  3749. * 09/28/1995 JLB : Uses map scan function. *
  3750. *=============================================================================================*/
  3751. CELL TechnoClass::Nearby_Location(TechnoClass const * techno, int locationmod) const
  3752. {
  3753. assert(IsActive);
  3754. SpeedType speed = Techno_Type_Class()->Speed;
  3755. if (speed == SPEED_WINGED) {
  3756. speed = SPEED_TRACK;
  3757. }
  3758. CELL cell = 0;
  3759. if (techno != NULL) {
  3760. cell = Coord_Cell(techno->Center_Coord());
  3761. } else {
  3762. cell = Coord_Cell(Center_Coord());
  3763. }
  3764. return(Map.Nearby_Location(cell, speed, Map[cell].Zones[Techno_Type_Class()->MZone], Techno_Type_Class()->MZone, false, locationmod));
  3765. }
  3766. /***********************************************************************************************
  3767. * TechnoClass::Do_Uncloak -- Cause the stealth tank to uncloak. *
  3768. * *
  3769. * This routine will start the stealth tank to uncloak. *
  3770. * *
  3771. * INPUT: none *
  3772. * *
  3773. * OUTPUT: none *
  3774. * *
  3775. * WARNINGS: none *
  3776. * *
  3777. * HISTORY: *
  3778. * 05/08/1995 JLB : Created. *
  3779. *=============================================================================================*/
  3780. void TechnoClass::Do_Uncloak(void)
  3781. {
  3782. assert(IsActive);
  3783. if (IsCloakable && (Cloak == CLOAKED || Cloak == CLOAKING)) {
  3784. if (Cloak == CLOAKED) {
  3785. Map.RadarClass::Flag_To_Redraw(true);
  3786. }
  3787. Cloak = UNCLOAKING;
  3788. CloakingDevice.Set_Stage(0);
  3789. CloakingDevice.Set_Rate(1);
  3790. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  3791. if(What_Am_I() == RTTI_VESSEL) {
  3792. Sound_Effect(VOC_SUBSHOW, Coord);
  3793. } else {
  3794. Sound_Effect(VOC_IRON1, Coord);
  3795. }
  3796. #else
  3797. Sound_Effect(VOC_SUBSHOW, Coord);
  3798. #endif
  3799. }
  3800. }
  3801. /***********************************************************************************************
  3802. * TechnoClass::Do_Cloak -- Start the object into cloaking stage. *
  3803. * *
  3804. * This routine will start the object into its cloaking state. *
  3805. * *
  3806. * INPUT: none *
  3807. * *
  3808. * OUTPUT: none *
  3809. * *
  3810. * WARNINGS: none *
  3811. * *
  3812. * HISTORY: *
  3813. * 07/08/1995 JLB : Created. *
  3814. *=============================================================================================*/
  3815. void TechnoClass::Do_Cloak(void)
  3816. {
  3817. assert(IsActive);
  3818. if (IsCloakable && (Cloak == UNCLOAKED || Cloak == UNCLOAKING)) {
  3819. Detach_All(false);
  3820. if (Cloak == UNCLOAKED) {
  3821. Map.RadarClass::Flag_To_Redraw(true);
  3822. }
  3823. Cloak = CLOAKING;
  3824. CloakingDevice.Set_Stage(0);
  3825. CloakingDevice.Set_Rate(1);
  3826. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  3827. if(What_Am_I() == RTTI_VESSEL) {
  3828. Sound_Effect(VOC_SUBSHOW, Coord);
  3829. } else {
  3830. Sound_Effect(VOC_IRON1, Coord);
  3831. }
  3832. #else
  3833. Sound_Effect(VOC_SUBSHOW, Coord);
  3834. #endif
  3835. }
  3836. }
  3837. /***********************************************************************************************
  3838. * TechnoClass::Do_Shimmer -- Causes this object to shimmer if it is cloaked. *
  3839. * *
  3840. * This routine is called when this object should shimmer. If the object is cloaked, then *
  3841. * a shimmering effect (partial decloak) occurs. For objects that are not cloaked, no *
  3842. * effect occurs. *
  3843. * *
  3844. * INPUT: none *
  3845. * *
  3846. * OUTPUT: none *
  3847. * *
  3848. * WARNINGS: none *
  3849. * *
  3850. * HISTORY: *
  3851. * 07/29/1995 JLB : Created. *
  3852. *=============================================================================================*/
  3853. void TechnoClass::Do_Shimmer(void)
  3854. {
  3855. assert(IsActive);
  3856. #if(0)
  3857. if (IsCloakable && Cloak == CLOAKED) {
  3858. Cloak = CLOAKING;
  3859. CloakingDevice.Set_Stage(MAX_UNCLOAK_STAGE/2);
  3860. CloakingDevice.Set_Rate(1);
  3861. }
  3862. #else
  3863. Do_Uncloak();
  3864. #endif
  3865. }
  3866. /***********************************************************************************************
  3867. * TechnoClass::Visual_Character -- Determine the visual character of the object. *
  3868. * *
  3869. * This routine will determine how this object should be drawn. Typically, this is the *
  3870. * unmodified visible state, but cloaked objects have a different character. *
  3871. * *
  3872. * INPUT: raw -- Should the check be based on the unmodified cloak condition of the *
  3873. * object? If false, then an object owned by the player will never become *
  3874. * completely invisible. *
  3875. * *
  3876. * OUTPUT: Returns with the visual character to use when displaying this object. *
  3877. * *
  3878. * WARNINGS: none *
  3879. * *
  3880. * HISTORY: *
  3881. * 07/07/1995 JLB : Created. *
  3882. * 05/27/1996 JLB : Knows about invisible objects. *
  3883. *=============================================================================================*/
  3884. VisualType TechnoClass::Visual_Character(bool raw) const
  3885. {
  3886. assert(IsActive);
  3887. if (Techno_Type_Class()->IsInvisible) {
  3888. if ((Session.Type != GAME_NORMAL) || Is_Owned_By_Player()) return(VISUAL_NORMAL);
  3889. if (!Debug_Map) return(VISUAL_HIDDEN);
  3890. }
  3891. /*
  3892. ** When uncloaked or in map editor mode, always draw the object normally.
  3893. */
  3894. if (Cloak == UNCLOAKED || Debug_Map) return(VISUAL_NORMAL);
  3895. /*
  3896. ** A cloaked unit will not be visible at all unless it is owned
  3897. ** by the player.
  3898. */
  3899. if (Cloak == CLOAKED) {
  3900. // Changed for multiplayer. Not needed except to test in the old renderer. ST - 3/13/2019 5:56PM
  3901. if (!raw && Is_Owned_By_Player()) return(VISUAL_SHADOWY);
  3902. //if (!raw && IsOwnedByPlayer) return(VISUAL_SHADOWY);
  3903. return(VISUAL_HIDDEN);
  3904. }
  3905. int stage = CloakingDevice.Fetch_Stage();
  3906. if (Cloak == UNCLOAKING) stage = MAX_UNCLOAK_STAGE - stage;
  3907. if (stage <= 0) {
  3908. return(VISUAL_NORMAL);
  3909. }
  3910. stage = fixed(stage, MAX_UNCLOAK_STAGE) * 256;
  3911. if (stage < 0x0040) return(VISUAL_INDISTINCT);
  3912. if (stage < 0x0080) return(VISUAL_DARKEN);
  3913. if (stage < 0x00C0) return(VISUAL_SHADOWY);
  3914. //if (!raw && IsOwnedByPlayer) return(VISUAL_SHADOWY);
  3915. if (!raw && Is_Owned_By_Player()) return(VISUAL_SHADOWY); // Changed for multiplayer. Not needed except to test in the old renderer. ST - 3/13/2019 5:56PM
  3916. if (stage < 0x00FF) return(VISUAL_RIPPLE);
  3917. return(VISUAL_HIDDEN);
  3918. }
  3919. /***********************************************************************************************
  3920. * TechnoClass::Techno_Draw_Object -- General purpose draw object routine. *
  3921. * *
  3922. * This routine is used to draw the object. It will handle any remapping or cloaking *
  3923. * effects required. This logic is isolated here since all techno object share the same *
  3924. * render logic when it comes to remapping and cloaking. *
  3925. * *
  3926. * INPUT: shapefile -- Pointer to the shape file that the shape will be drawn from. *
  3927. * *
  3928. * shapenum -- The shape number of the object in the file to use. *
  3929. * *
  3930. * x,y -- Center pixel coordinate to use for rendering this object. *
  3931. * *
  3932. * window -- The clipping window to use when rendering. *
  3933. * *
  3934. * rotation -- The rotation of the object. *
  3935. * *
  3936. * scale -- The scaling factor to use (24.8 fixed point). *
  3937. * *
  3938. * OUTPUT: none *
  3939. * *
  3940. * WARNINGS: none *
  3941. * *
  3942. * HISTORY: *
  3943. * 07/08/1995 JLB : Created. *
  3944. * 01/11/1996 JLB : Added rotation and scaling. *
  3945. *=============================================================================================*/
  3946. void TechnoClass::Techno_Draw_Object(void const * shapefile, int shapenum, int x, int y, WindowNumberType window, DirType rotation, int scale) const
  3947. {
  3948. assert(IsActive);
  3949. if (rotation != DIR_N || scale != 0x0100) {
  3950. Disable_Uncompressed_Shapes();
  3951. }
  3952. if (shapefile != NULL) {
  3953. VisualType visual = Visual_Character();
  3954. void const * remap = Remap_Table();
  3955. void const * shadow = Map.UnitShadow;
  3956. #ifdef PARTIAL
  3957. /*
  3958. ** Create a minimum shape rectangle if one hasn't already been
  3959. ** calculated and the shape file matches the one that the
  3960. ** class thinks it should be using. This check is necessary because
  3961. ** the dimension rectangle pointer is referenced from the type class
  3962. ** object on the presumption that the shapefile pointer passed to this
  3963. ** routine matches. If it doesn't match, then the wrong rectangle information
  3964. ** will be stored into the type class object.
  3965. */
  3966. TechnoTypeClass * ttype = Techno_Type_Class();
  3967. if (shapefile == ttype->Get_Image_Data() && shapenum < Get_Build_Frame_Count(shapefile)-1) {
  3968. if (ttype->DimensionData == NULL) {
  3969. ttype->DimensionData = new Rect [Get_Build_Frame_Count(shapefile)];
  3970. }
  3971. if (ttype->DimensionData != NULL && !ttype->DimensionData[shapenum].Is_Valid()) {
  3972. ttype->DimensionData[shapenum] = Shape_Dimensions(shapefile, shapenum);
  3973. }
  3974. }
  3975. #endif
  3976. if (Height > 0) {
  3977. shadow = Map.UnitShadowAir;
  3978. }
  3979. y -= Lepton_To_Pixel(Height);
  3980. /*
  3981. ** If they're viewing a spy, and the spy belongs to some other house,
  3982. ** make it look like an infantryman from our house
  3983. */
  3984. if (What_Am_I() == RTTI_INFANTRY) {
  3985. if (!IsOwnedByPlayer) {
  3986. if (*(InfantryClass *)this == INFANTRY_SPY) remap = PlayerPtr->Remap_Table();
  3987. }
  3988. if (((InfantryClass *)this)->Class->IsRemapOverride) {
  3989. remap = ((InfantryClass *)this)->Class->OverrideRemap;
  3990. }
  3991. }
  3992. /*
  3993. ** Check for the special visual effect for the iron curtain
  3994. */
  3995. if (IronCurtainCountDown > 0) {
  3996. // remap = RemapEmber;
  3997. remap = DisplayClass::FadingRed;
  3998. }
  3999. #ifdef PREDATOR
  4000. if (visual != VISUAL_HIDDEN && visual != VISUAL_RIPPLE) {
  4001. if (visual == VISUAL_SHADOWY) {
  4002. CC_Draw_Shape(shapefile, shapenum, x, y, window, SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_FADING|SHAPE_PREDATOR, NULL, Map.FadingShade, rotation, scale);
  4003. } else {
  4004. CC_Draw_Shape(shapefile, shapenum, x, y, window, SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_FADING|SHAPE_GHOST, remap, shadow, rotation, scale);
  4005. }
  4006. if (visual == VISUAL_DARKEN) {
  4007. CC_Draw_Shape(shapefile, shapenum, x, y, window, SHAPE_PREDATOR|SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_FADING, remap, Map.FadingShade, rotation, scale);
  4008. }
  4009. }
  4010. if (visual != VISUAL_NORMAL && visual != VISUAL_HIDDEN) {
  4011. CC_Draw_Shape(shapefile, shapenum, x, y, window, SHAPE_PREDATOR|SHAPE_CENTER|SHAPE_WIN_REL, NULL, NULL, rotation, scale);
  4012. }
  4013. #else
  4014. switch (visual) {
  4015. case VISUAL_NORMAL:
  4016. // Add 'this' parameter to call new shape draw intercept. ST - 5/22/2019
  4017. CC_Draw_Shape(this, shapefile, shapenum, x, y, window, SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_FADING|SHAPE_GHOST, remap, shadow, rotation, scale);
  4018. break;
  4019. case VISUAL_INDISTINCT:
  4020. case VISUAL_DARKEN:
  4021. // Add 'this' parameter to call new shape draw intercept. ST - 5/22/2019
  4022. CC_Draw_Shape(this, shapefile, shapenum, x, y, window, SHAPE_FADING|SHAPE_CENTER|SHAPE_WIN_REL, remap, Map.FadingShade, rotation, scale);
  4023. break;
  4024. case VISUAL_SHADOWY:
  4025. case VISUAL_RIPPLE:
  4026. // Add 'this' parameter to call new shape draw intercept. ST - 5/22/2019
  4027. CC_Draw_Shape(this, shapefile, shapenum, x, y, window, SHAPE_PREDATOR|SHAPE_FADING|SHAPE_CENTER|SHAPE_WIN_REL, NULL, Map.FadingShade, rotation, scale);
  4028. break;
  4029. case VISUAL_HIDDEN:
  4030. // Server still needs to "render" hidden objects to the virtual window, so objects get created properly - SKY
  4031. if (window == WINDOW_VIRTUAL) {
  4032. CC_Draw_Shape(this, shapefile, shapenum, x, y, window, SHAPE_PREDATOR|SHAPE_FADING|SHAPE_CENTER|SHAPE_WIN_REL, NULL, Map.FadingShade, rotation, scale);
  4033. }
  4034. break;
  4035. }
  4036. #endif
  4037. }
  4038. Enable_Uncompressed_Shapes();
  4039. }
  4040. /***********************************************************************************************
  4041. * TechnoClass::Techno_Draw_Object_Virtual -- Draw object with virtual window support *
  4042. * *
  4043. * INPUT: shapefile -- Pointer to the shape file that the shape will be drawn from. *
  4044. * *
  4045. * shapenum -- The shape number of the object in the file to use. *
  4046. * *
  4047. * x,y -- Center pixel coordinate to use for rendering this object. *
  4048. * *
  4049. * window -- The clipping window to use when rendering. *
  4050. * *
  4051. * rotation -- The rotation of the object. *
  4052. * *
  4053. * scale -- The scaling factor to use (24.8 fixed point). *
  4054. * *
  4055. * shape_name -- The name of the shapefile *
  4056. * *
  4057. * OUTPUT: none *
  4058. * *
  4059. * WARNINGS: none *
  4060. * *
  4061. * HISTORY: *
  4062. * 8/1/2019 5:32PM - ST : Created. *
  4063. *=============================================================================================*/
  4064. void TechnoClass::Techno_Draw_Object_Virtual(void const * shapefile, int shapenum, int x, int y, WindowNumberType window, DirType rotation, int scale, const char *shape_name) const
  4065. {
  4066. assert(IsActive);
  4067. if (shape_name == NULL || *shape_name == 0) {
  4068. /*
  4069. ** If there's no override shape name, then call the regular draw
  4070. */
  4071. Techno_Draw_Object(shapefile, shapenum, x, y, window, rotation, scale);
  4072. return;
  4073. }
  4074. if (shapefile != NULL) {
  4075. VisualType visual = Visual_Character();
  4076. void const * remap = Remap_Table();
  4077. void const * shadow = Map.UnitShadow;
  4078. #ifdef PARTIAL
  4079. /*
  4080. ** Create a minimum shape rectangle if one hasn't already been
  4081. ** calculated and the shape file matches the one that the
  4082. ** class thinks it should be using. This check is necessary because
  4083. ** the dimension rectangle pointer is referenced from the type class
  4084. ** object on the presumption that the shapefile pointer passed to this
  4085. ** routine matches. If it doesn't match, then the wrong rectangle information
  4086. ** will be stored into the type class object.
  4087. */
  4088. TechnoTypeClass * ttype = Techno_Type_Class();
  4089. if (shapefile == ttype->Get_Image_Data() && shapenum < Get_Build_Frame_Count(shapefile)-1) {
  4090. if (ttype->DimensionData == NULL) {
  4091. ttype->DimensionData = new Rect [Get_Build_Frame_Count(shapefile)];
  4092. }
  4093. if (ttype->DimensionData != NULL && !ttype->DimensionData[shapenum].Is_Valid()) {
  4094. ttype->DimensionData[shapenum] = Shape_Dimensions(shapefile, shapenum);
  4095. }
  4096. }
  4097. #endif
  4098. if (Height > 0) {
  4099. shadow = Map.UnitShadowAir;
  4100. }
  4101. y -= Lepton_To_Pixel(Height);
  4102. /*
  4103. ** If they're viewing a spy, and the spy belongs to some other house,
  4104. ** make it look like an infantryman from our house
  4105. */
  4106. if (What_Am_I() == RTTI_INFANTRY) {
  4107. if (!IsOwnedByPlayer) {
  4108. if (*(InfantryClass *)this == INFANTRY_SPY) remap = PlayerPtr->Remap_Table();
  4109. }
  4110. if (((InfantryClass *)this)->Class->IsRemapOverride) {
  4111. remap = ((InfantryClass *)this)->Class->OverrideRemap;
  4112. }
  4113. }
  4114. /*
  4115. ** Check for the special visual effect for the iron curtain
  4116. */
  4117. if (IronCurtainCountDown > 0) {
  4118. // remap = RemapEmber;
  4119. remap = DisplayClass::FadingRed;
  4120. }
  4121. #ifdef PREDATOR
  4122. if (visual != VISUAL_HIDDEN && visual != VISUAL_RIPPLE) {
  4123. if (visual == VISUAL_SHADOWY) {
  4124. CC_Draw_Shape(shapefile, shapenum, x, y, window, SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_FADING|SHAPE_PREDATOR, NULL, Map.FadingShade, rotation, scale);
  4125. } else {
  4126. CC_Draw_Shape(shapefile, shapenum, x, y, window, SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_FADING|SHAPE_GHOST, remap, shadow, rotation, scale);
  4127. }
  4128. if (visual == VISUAL_DARKEN) {
  4129. CC_Draw_Shape(shapefile, shapenum, x, y, window, SHAPE_PREDATOR|SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_FADING, remap, Map.FadingShade, rotation, scale);
  4130. }
  4131. }
  4132. if (visual != VISUAL_NORMAL && visual != VISUAL_HIDDEN) {
  4133. CC_Draw_Shape(shapefile, shapenum, x, y, window, SHAPE_PREDATOR|SHAPE_CENTER|SHAPE_WIN_REL, NULL, NULL, rotation, scale);
  4134. }
  4135. #else
  4136. switch (visual) {
  4137. case VISUAL_NORMAL:
  4138. // Add 'this' parameter to call new shape draw intercept. ST - 5/22/2019
  4139. CC_Draw_Shape(this, shape_name, shapefile, shapenum, x, y, window, SHAPE_CENTER|SHAPE_WIN_REL|SHAPE_FADING|SHAPE_GHOST, remap, shadow, rotation, scale);
  4140. break;
  4141. case VISUAL_INDISTINCT:
  4142. case VISUAL_DARKEN:
  4143. // Add 'this' parameter to call new shape draw intercept. ST - 5/22/2019
  4144. CC_Draw_Shape(this, shape_name, shapefile, shapenum, x, y, window, SHAPE_FADING|SHAPE_CENTER|SHAPE_WIN_REL, remap, Map.FadingShade, rotation, scale);
  4145. break;
  4146. case VISUAL_SHADOWY:
  4147. case VISUAL_RIPPLE:
  4148. // Add 'this' parameter to call new shape draw intercept. ST - 5/22/2019
  4149. CC_Draw_Shape(this, shape_name, shapefile, shapenum, x, y, window, SHAPE_PREDATOR|SHAPE_FADING|SHAPE_CENTER|SHAPE_WIN_REL, NULL, Map.FadingShade, rotation, scale);
  4150. break;
  4151. case VISUAL_HIDDEN:
  4152. // Server still needs to "render" hidden objects to the virtual window, so objects get created properly - SKY
  4153. if (window == WINDOW_VIRTUAL) {
  4154. CC_Draw_Shape(this, shape_name, shapefile, shapenum, x, y, window, SHAPE_PREDATOR|SHAPE_FADING|SHAPE_CENTER|SHAPE_WIN_REL, NULL, Map.FadingShade, rotation, scale);
  4155. }
  4156. break;
  4157. }
  4158. #endif
  4159. }
  4160. }
  4161. /***********************************************************************************************
  4162. * TechnoClass::Remap_Table -- Fetches the appropriate remap table to use. *
  4163. * *
  4164. * This routine is used to fetch the appropriate remap table to use for this object. *
  4165. * *
  4166. * INPUT: none *
  4167. * *
  4168. * OUTPUT: Returns with a pointer to the remap table to use for this object. *
  4169. * *
  4170. * WARNINGS: none *
  4171. * *
  4172. * HISTORY: *
  4173. * 07/08/1995 JLB : Created. *
  4174. *=============================================================================================*/
  4175. void const * TechnoClass::Remap_Table(void) const
  4176. {
  4177. assert(IsActive);
  4178. if (Techno_Type_Class()->IsRemappable) {
  4179. return(House->Remap_Table(IsBlushing, Techno_Type_Class()->Remap));
  4180. }
  4181. return(ColorRemaps[PCOLOR_GOLD].RemapTable);
  4182. }
  4183. /***********************************************************************************************
  4184. * TechnoClass::Detach -- Handles removal of target from tracking system. *
  4185. * *
  4186. * This routine is called when the specified object is about to be removed from the game *
  4187. * system. The target object is removed from any tracking computers that this object may *
  4188. * have. *
  4189. * *
  4190. * INPUT: target -- The target object (as a target value) that is being removed from the *
  4191. * game. *
  4192. * *
  4193. * all -- Is the target about to die? A false value might indicate that the *
  4194. * object is merely cloaking. In such a case, radio contact will not *
  4195. * be affected. *
  4196. * *
  4197. * OUTPUT: none *
  4198. * *
  4199. * WARNINGS: none *
  4200. * *
  4201. * HISTORY: *
  4202. * 07/29/1995 JLB : Created. *
  4203. *=============================================================================================*/
  4204. void TechnoClass::Detach(TARGET target, bool all)
  4205. {
  4206. assert(IsActive);
  4207. RadioClass::Detach(target, all);
  4208. if (SuspendedMission != MISSION_NONE && SuspendedTarCom == target) {
  4209. SuspendedMission = MISSION_NONE;
  4210. SuspendedTarCom = TARGET_NONE;
  4211. }
  4212. /*
  4213. ** If the targeting computer is assigned to the target, then the targeting
  4214. ** computer must be cleared.
  4215. */
  4216. if (TarCom == target) {
  4217. Assign_Target(TARGET_NONE);
  4218. Restore_Mission();
  4219. }
  4220. /*
  4221. ** If it is in radio contact with another object, then that radio contact
  4222. ** must be broken.
  4223. */
  4224. if (all && In_Radio_Contact() && Contact_With_Whom()->As_Target() == target) {
  4225. Transmit_Message(RADIO_OVER_OUT);
  4226. }
  4227. }
  4228. /***********************************************************************************************
  4229. * TechnoClass::Kill_Cargo -- Destroys any cargo attached to this object. *
  4230. * *
  4231. * This routine handles the destruction of any cargo this object may contain. Typical of *
  4232. * this would be when a transport helicopter gets destroyed. *
  4233. * *
  4234. * INPUT: source -- The source of the destruction of the cargo. *
  4235. * *
  4236. * OUTPUT: none *
  4237. * *
  4238. * WARNINGS: none *
  4239. * *
  4240. * HISTORY: *
  4241. * 07/29/1995 JLB : Created. *
  4242. *=============================================================================================*/
  4243. void TechnoClass::Kill_Cargo(TechnoClass * source)
  4244. {
  4245. assert(IsActive);
  4246. while (Is_Something_Attached()) {
  4247. FootClass * foot = Detach_Object();
  4248. if (foot != NULL) {
  4249. foot->Record_The_Kill(source);
  4250. delete foot;
  4251. }
  4252. }
  4253. }
  4254. /***********************************************************************************************
  4255. * TechnoClass::Crew_Type -- Fetches the kind of crew this object contains. *
  4256. * *
  4257. * This routine is called when generating survivors to this object. This routine returns *
  4258. * the type of survivor to generate. *
  4259. * *
  4260. * INPUT: none *
  4261. * *
  4262. * OUTPUT: Returns the infantry type of a survivor. *
  4263. * *
  4264. * WARNINGS: This routine is designed to be called repeatedly. Once for each survivor to *
  4265. * generate. *
  4266. * *
  4267. * HISTORY: *
  4268. * 07/29/1995 JLB : Created. *
  4269. *=============================================================================================*/
  4270. InfantryType TechnoClass::Crew_Type(void) const
  4271. {
  4272. assert(IsActive);
  4273. /*
  4274. ** If this object contains no crew, then there can be no
  4275. ** crew inside, duh... return this news.
  4276. */
  4277. if (!Techno_Type_Class()->IsCrew) {
  4278. return(INFANTRY_NONE);
  4279. }
  4280. /*
  4281. ** The normal infantry survivor is the standard issue
  4282. ** minigunner. Certain buildings, especially neutral ones, tend to have
  4283. ** civilians exit them instead.
  4284. */
  4285. InfantryType infantry = INFANTRY_E1;
  4286. if (House->ActLike == HOUSE_NEUTRAL) {
  4287. infantry = Random_Pick(INFANTRY_C1, INFANTRY_C9);
  4288. } else {
  4289. if (Techno_Type_Class()->PrimaryWeapon == NULL && Percent_Chance(15)) {
  4290. if (Percent_Chance(50)) {
  4291. infantry = INFANTRY_C1;
  4292. } else {
  4293. infantry = INFANTRY_C7;
  4294. }
  4295. }
  4296. }
  4297. return(infantry);
  4298. }
  4299. /***********************************************************************************************
  4300. * TechnoClass::Value -- Fetches the target value for this object. *
  4301. * *
  4302. * This routine is used to fetch the target value for this object. The greater the value *
  4303. * returned, the better this object is as a target. *
  4304. * *
  4305. * INPUT: none *
  4306. * *
  4307. * OUTPUT: Returns with the target value for this object. *
  4308. * *
  4309. * WARNINGS: none *
  4310. * *
  4311. * HISTORY: *
  4312. * 07/29/1995 JLB : Created. *
  4313. * 08/16/1995 JLB : Adjusted for early mission lame-out. *
  4314. *=============================================================================================*/
  4315. int TechnoClass::Value(void) const
  4316. {
  4317. assert(IsActive);
  4318. int value = 0;
  4319. /*
  4320. ** In early missions, contents of transports are not figured
  4321. ** into the total value.
  4322. */
  4323. if (Rule.Diff[House->Difficulty].IsContentScan || House->IQ >= Rule.IQContentScan) {
  4324. if (Is_Something_Attached()) {
  4325. FootClass * object = Attached_Object();
  4326. while (object != NULL) {
  4327. value += object->Value();
  4328. object = (FootClass *)(ObjectClass *)object->Next;
  4329. }
  4330. }
  4331. }
  4332. #ifdef TOFIX
  4333. /*
  4334. ** Increase the value of power producing object when there is power critical
  4335. ** defensive structures.
  4336. */
  4337. if (What_Am_I() == RTTI_BUILDING && ((BuildingClass *)this)->Class->Power) {
  4338. if (House->BScan & (STRUCTF_ATOWER|STRUCTF_OBELISK)) {
  4339. value += Techno_Type_Class()->Reward;
  4340. }
  4341. }
  4342. #endif
  4343. return Risk() + Techno_Type_Class()->Reward + value;
  4344. }
  4345. /***********************************************************************************************
  4346. * TechnoClass::Threat_Range -- Returns the range to scan based on threat control. *
  4347. * *
  4348. * This routine will return the range to scan based on the control value specified. The *
  4349. * value returned by this routine is typically used when scanning for enemies. *
  4350. * *
  4351. * INPUT: control -- The range control parameter. *
  4352. * 0 = Use weapon range (zero is returned in this special case). *
  4353. * -1 = Scan without range restrictions (-1 is returned in this case). *
  4354. * 1 = Scan up to twice weapon range. *
  4355. * *
  4356. * OUTPUT: Returns with a range (or special value) that can be used in the threat scan *
  4357. * process. If zero is returned, then always check threat against In_Range(). If *
  4358. * -1 is returned, then no range limitation restriction exists. *
  4359. * *
  4360. * WARNINGS: none *
  4361. * *
  4362. * HISTORY: *
  4363. * 07/29/1995 JLB : Created. *
  4364. *=============================================================================================*/
  4365. int TechnoClass::Threat_Range(int control) const
  4366. {
  4367. assert(IsActive);
  4368. /*
  4369. ** Threat range means nothing if scanning the whole map. In such a case, just
  4370. ** return with the same control flag specified.
  4371. */
  4372. if (control == -1) return(-1);
  4373. /*
  4374. ** If simple guard range is requested, then return "0" since
  4375. ** this is a special control value that is calculated as the object's
  4376. ** weapon range.
  4377. */
  4378. if (control == 0) {
  4379. /*
  4380. ** For normal guard mode or for area guard mode, use the override
  4381. ** threat range value as specified by the object's type class.
  4382. */
  4383. if (Techno_Type_Class()->ThreatRange != 0) {
  4384. return(Techno_Type_Class()->ThreatRange);
  4385. }
  4386. return(0);
  4387. }
  4388. /*
  4389. ** Area guard range is specified, so figure twice the weapon range of the
  4390. ** longest range weapon this object is equipped with.
  4391. */
  4392. int range = Techno_Type_Class()->ThreatRange;
  4393. if (range == 0) {
  4394. range = max(Weapon_Range(0), Weapon_Range(1));
  4395. }
  4396. range *= 2;
  4397. range = Bound(range, 0x0000, 0x0A00);
  4398. return(range);
  4399. }
  4400. /***********************************************************************************************
  4401. * TechnoClass::Is_In_Same_Zone -- Determine if specified cell is in same zone as object. *
  4402. * *
  4403. * This will examine the specified cell to determine if it is in the same zone as this *
  4404. * object's location. *
  4405. * *
  4406. * INPUT: cell -- The cell that is to be checked against this object's current location. *
  4407. * *
  4408. * OUTPUT: bool; Is the specified cell in the same zone as this object is? *
  4409. * *
  4410. * WARNINGS: none *
  4411. * *
  4412. * HISTORY: *
  4413. * 10/06/1996 JLB : Created. *
  4414. *=============================================================================================*/
  4415. bool TechnoClass::Is_In_Same_Zone(CELL cell) const
  4416. {
  4417. MZoneType zone = Techno_Type_Class()->MZone;
  4418. return(Map[cell].Zones[zone] == Map[Center_Coord()].Zones[zone]);
  4419. }
  4420. /***********************************************************************************************
  4421. * TechnoClass::Base_Is_Attacked -- Handle panic response to base being attacked. *
  4422. * *
  4423. * This routine is called when the base is being attacked. It will pull units off of the *
  4424. * field and send them back to defend the base. This routine will make taking an enemy *
  4425. * base much more difficult. *
  4426. * *
  4427. * INPUT: enemy -- Pointer to the enemy object that did the damage on the base. *
  4428. * *
  4429. * OUTPUT: none *
  4430. * *
  4431. * WARNINGS: This routine can drastically affect the game play. The computer will probably *
  4432. * call off its attacks as a result. *
  4433. * *
  4434. * HISTORY: *
  4435. * 06/25/1995 JLB : Commented. *
  4436. * 10/15/1996 JLB : Alternates between guard area and attack. *
  4437. * 11/01/1996 JLB : Allow recruit of guard area units in multiplay. *
  4438. *=============================================================================================*/
  4439. void TechnoClass::Base_Is_Attacked(TechnoClass const * enemy)
  4440. {
  4441. assert(IsActive);
  4442. FootClass * defender[6];
  4443. memset(defender, '\0', sizeof(defender));
  4444. int value[ARRAY_SIZE(defender)];
  4445. memset(value, '\0', sizeof(value));
  4446. int count = 0;
  4447. int weakest = 0;
  4448. int desired = enemy->Risk() * House->Control.TechLevel;
  4449. int risktotal = 0;
  4450. int zone = Map[Center_Coord()].Zones[Techno_Type_Class()->MZone];
  4451. /*
  4452. ** Humans have to deal with their own base is attacked problems.
  4453. */
  4454. if (enemy == NULL || House->Is_Ally(enemy) || House->IsHuman) {
  4455. return;
  4456. }
  4457. /*
  4458. ** Don't overreact if this building can defend itself.
  4459. */
  4460. if (Session.Type == GAME_NORMAL && Techno_Type_Class()->PrimaryWeapon != NULL) return;
  4461. /*
  4462. ** If the enemy is not an infantry or a unit there is not much we can
  4463. ** do about it.
  4464. */
  4465. if (enemy->What_Am_I() != RTTI_INFANTRY && enemy->What_Am_I() != RTTI_UNIT) {
  4466. return;
  4467. }
  4468. /*
  4469. ** If we are a certain type of building, such as a barrel or land mine,
  4470. ** ignore the attack.
  4471. */
  4472. if (Techno_Type_Class()->IsInsignificant) {
  4473. return;
  4474. }
  4475. /*
  4476. ** If the threat has already been dealt with then we don't need to do
  4477. ** any work. Check for that here.
  4478. */
  4479. if (enemy->Is_Foot() && ((FootClass *)enemy)->BaseAttackTimer != 0) {
  4480. return;
  4481. }
  4482. /*
  4483. ** We will need units to defend our base. We need to suspend teams until
  4484. ** the situation has been dealt with.
  4485. */
  4486. TeamClass::Suspend_Teams(Rule.SuspendPriority, House);
  4487. /*
  4488. ** Loop through the infantry looking for those who are capable of going
  4489. ** on a rescue mission.
  4490. */
  4491. for (int index = 0; index < Infantry.Count() && desired > 0; index++) {
  4492. InfantryClass * infantry = Infantry.Ptr(index);
  4493. if (infantry != NULL && infantry->Owner() == Owner()) {
  4494. /*
  4495. ** Never recruit sticky guard units to defend a base.
  4496. */
  4497. if (!infantry->Is_Weapon_Equipped() ||
  4498. (!MissionControl[infantry->Mission].IsRecruitable && Session.Type == GAME_NORMAL)) continue;
  4499. // (Mission != MISSION_GUARD_AREA || Session.Type == GAME_NORMAL)) continue;
  4500. /*
  4501. ** Don't allow a response if it doesn't have a weapon that will affect the
  4502. ** enemy object.
  4503. */
  4504. if (infantry->Class->PrimaryWeapon->WarheadPtr->Modifier[enemy->Techno_Type_Class()->Armor] == 0) {
  4505. continue;
  4506. }
  4507. /*
  4508. ** Don't try to help if the building is on another planet.
  4509. */
  4510. if (Map[infantry->Center_Coord()].Zones[infantry->Class->MZone] != Map[Center_Coord()].Zones[infantry->Class->MZone]) continue;
  4511. /*
  4512. ** Find the amount of threat that this unit can apply to the
  4513. ** enemy.
  4514. */
  4515. int threat = infantry->Rescue_Mission(enemy->As_Target());
  4516. /*
  4517. ** If it can't apply any threat then do just skip it and do not
  4518. ** add it to the list.
  4519. */
  4520. if (!threat) {
  4521. continue;
  4522. }
  4523. /*
  4524. ** Greatly increase the threat value if this unit is already assigned to protect
  4525. ** the target.
  4526. */
  4527. if (ArchiveTarget == As_Target()) {
  4528. threat *= 100;
  4529. }
  4530. /*
  4531. ** If the value returned is negative then this unit is already
  4532. ** assigned to fighting the enemy, so subtract its value from
  4533. ** the enemy's desired value.
  4534. */
  4535. if (threat < 0) {
  4536. desired += threat;
  4537. continue;
  4538. }
  4539. if (count < ARRAY_SIZE(defender)) {
  4540. defender[count] = infantry;
  4541. value[count] = threat;
  4542. count++;
  4543. continue;
  4544. }
  4545. if (threat > weakest) {
  4546. int newweakest = threat;
  4547. for (int lp = 0; lp < count; lp++) {
  4548. if (value[lp] == weakest) {
  4549. value[lp] = threat;
  4550. defender[lp] = (FootClass *) infantry;
  4551. continue;
  4552. }
  4553. if (value[lp] < newweakest) {
  4554. newweakest = value[lp];
  4555. }
  4556. }
  4557. weakest = newweakest;
  4558. }
  4559. }
  4560. }
  4561. /*
  4562. ** Loop through the units looking for those who are capable of going
  4563. ** on a rescue mission.
  4564. */
  4565. for (int index = 0; index < Units.Count() && desired > 0; index++) {
  4566. UnitClass * unit = Units.Ptr(index);
  4567. if (unit != NULL && unit->Owner() == Owner()) {
  4568. /*
  4569. ** Never recruit sticky guard units to defend a base.
  4570. */
  4571. if (!unit->Is_Weapon_Equipped() ||
  4572. (!MissionControl[unit->Mission].IsRecruitable && Session.Type == GAME_NORMAL)) continue;
  4573. /*
  4574. ** Don't allow a response if it doesn't have a weapon that will affect the
  4575. ** enemy object.
  4576. */
  4577. if (unit->Class->PrimaryWeapon->WarheadPtr->Modifier[enemy->Techno_Type_Class()->Armor] == 0) {
  4578. continue;
  4579. }
  4580. /*
  4581. ** Don't try to help if the building is on another planet.
  4582. */
  4583. if (Map[unit->Center_Coord()].Zones[unit->Class->MZone] != Map[Center_Coord()].Zones[unit->Class->MZone]) continue;
  4584. /*
  4585. ** Find the amount of threat that this unit can apply to the
  4586. ** enemy.
  4587. */
  4588. int threat = unit->Rescue_Mission(enemy->As_Target());
  4589. /*
  4590. ** If it can't apply any threat then do just skip it and do not
  4591. ** add it to the list.
  4592. */
  4593. if (!threat) {
  4594. continue;
  4595. }
  4596. /*
  4597. ** Greatly increase the threat value if this unit is already assigned to protect
  4598. ** the target.
  4599. */
  4600. if (threat > 0 && ArchiveTarget == As_Target()) {
  4601. threat *= 10;
  4602. }
  4603. /*
  4604. ** If the value returned is negative then this unit is already
  4605. ** assigned to fighting the enemy, so subtract its value from
  4606. ** the enemy's desired value.
  4607. */
  4608. if (threat < 0) {
  4609. desired += threat;
  4610. continue;
  4611. }
  4612. if (count < ARRAY_SIZE(defender)) {
  4613. defender[count] = unit;
  4614. value[count] = threat;
  4615. count++;
  4616. continue;
  4617. }
  4618. if (threat > weakest) {
  4619. int newweakest = threat;
  4620. for (int lp = 0; lp < count; lp ++) {
  4621. if (value[lp] == weakest) {
  4622. value[lp] = threat;
  4623. defender[lp] = (FootClass *) unit;
  4624. continue;
  4625. }
  4626. if (value[lp] < newweakest) {
  4627. // if (value[count] < newweakest) {
  4628. newweakest = value[lp];
  4629. }
  4630. }
  4631. weakest = newweakest;
  4632. }
  4633. }
  4634. }
  4635. if (desired > 0) {
  4636. /*
  4637. ** Sort the defenders by value, this doesn't take very long and will
  4638. ** help the closest defenders to respond.
  4639. */
  4640. for (int lp = 0; lp < count - 1; lp ++) {
  4641. for (int lp2 = lp + 1; lp2 < count; lp2++) {
  4642. if (value[lp] < value[lp2]) {
  4643. value[lp] ^= value[lp2];
  4644. value[lp2] ^= value[lp];
  4645. value[lp] ^= value[lp2];
  4646. FootClass *temp;
  4647. temp = defender[lp];
  4648. defender[lp] = defender[lp2];
  4649. defender[lp2] = temp;
  4650. }
  4651. }
  4652. }
  4653. for (int lp = 0; lp < count; lp ++) {
  4654. if (Percent_Chance(50)) {
  4655. defender[lp]->Assign_Mission(MISSION_RESCUE);
  4656. } else {
  4657. defender[lp]->Assign_Mission(MISSION_GUARD_AREA);
  4658. defender[lp]->ArchiveTarget = As_Target();
  4659. }
  4660. defender[lp]->Assign_Target(enemy->As_Target());
  4661. risktotal += defender[lp]->Risk();
  4662. if (risktotal > desired) {
  4663. break;
  4664. }
  4665. }
  4666. }
  4667. if (risktotal > desired && enemy->Is_Foot()) {
  4668. ((FootClass *)enemy)->BaseAttackTimer = TICKS_PER_MINUTE * Rule.BaseDefenseDelay;
  4669. }
  4670. }
  4671. /***********************************************************************************************
  4672. * TechnoClass::Is_Allowed_To_Retaliate -- Checks object to see if it can retaliate. *
  4673. * *
  4674. * This routine is called when this object has suffered some damage and it needs to know *
  4675. * if it should fight back. The object that caused the damage is specifed as a parameter. *
  4676. * *
  4677. * INPUT: source -- The points to the object that was the source of the damage applied *
  4678. * to this object. *
  4679. * *
  4680. * OUTPUT: bool; Should retaliation occur? *
  4681. * *
  4682. * WARNINGS: none *
  4683. * *
  4684. * HISTORY: *
  4685. * 10/19/1996 JLB : Created. *
  4686. *=============================================================================================*/
  4687. bool TechnoClass::Is_Allowed_To_Retaliate(TechnoClass const * source) const
  4688. {
  4689. /*
  4690. ** If there is no source of the damage, then retaliation cannot occur.
  4691. */
  4692. if (source == NULL) return(false);
  4693. /*
  4694. ** If the mission precludes retaliation, then don't retaliate.
  4695. */
  4696. if (!MissionControl[Mission].IsRetaliate) return(false);
  4697. /*
  4698. ** Fixed wing aircraft are not responsive enough to retaliate to damage recieved.
  4699. */
  4700. if (What_Am_I() == RTTI_AIRCRAFT && ((AircraftClass *)this)->Class->IsFixedWing) {
  4701. return(false);
  4702. }
  4703. /*
  4704. ** If the source of the damage is an ally, then retaliation shouldn't
  4705. ** occur either.
  4706. */
  4707. if (House->Is_Ally(source)) return(false);
  4708. /*
  4709. ** Only objects that have a damaging weapon are allowed to retaliate.
  4710. */
  4711. if (Combat_Damage() <= 0 || !Is_Weapon_Equipped()) return(false);
  4712. /*
  4713. ** If this is not equipped with a weapon that can attack the molester, then
  4714. ** don't allow retaliation.
  4715. */
  4716. TechnoTypeClass const * ttype = Techno_Type_Class();
  4717. if (ttype->PrimaryWeapon->WarheadPtr != NULL &&
  4718. ttype->PrimaryWeapon->WarheadPtr->Modifier[source->Techno_Type_Class()->Armor] == 0) {
  4719. return(false);
  4720. }
  4721. /*
  4722. ** One can never retaliate against a dog because of their peculiar nature of attacking.
  4723. ** Dogs must be attacked using normal target processing.
  4724. */
  4725. if (source->What_Am_I() == RTTI_INFANTRY && ((InfantryClass *)source)->Class->IsDog) return(false);
  4726. /*
  4727. ** Don't allow retaliation if it isn't equipped with a weapon that can deal with the threat.
  4728. */
  4729. if (source->What_Am_I() == RTTI_AIRCRAFT && !ttype->PrimaryWeapon->Bullet->IsAntiAircraft) return(false);
  4730. /*
  4731. ** Tanya is not allowed to retaliate against buildings in the normal sense while in guard mode. That
  4732. ** is, unless it is owned by the computer. Normally, Tanya can't do anything substantial to a building
  4733. ** except to blow it up.
  4734. */
  4735. if ((House->IsHuman || (Session.Type == GAME_NORMAL && House->IsPlayerControl))
  4736. && source->What_Am_I() == RTTI_BUILDING && What_Am_I() == RTTI_INFANTRY && ((InfantryTypeClass const *)ttype)->IsBomber) {
  4737. return(false);
  4738. }
  4739. /*
  4740. ** If a human house is not allowed to retaliate automatically, then don't
  4741. */
  4742. if (House->IsHuman && !Rule.IsSmartDefense && (What_Am_I() != RTTI_INFANTRY || *((InfantryClass*)this) != INFANTRY_TANYA || source->What_Am_I() != RTTI_INFANTRY)) return(false);
  4743. /*
  4744. ** If this object is part of a team that prevents retaliation then don't allow retaliation.
  4745. */
  4746. if (Is_Foot() && ((FootClass *)this)->Team.Is_Valid() && ((FootClass *)this)->Team->Class->IsSuicide) {
  4747. return(false);
  4748. }
  4749. /*
  4750. ** Compare potential threat of the current target and the potential new target. Don't retaliate
  4751. ** if it is currently attacking the greater threat.
  4752. */
  4753. if (!House->IsHuman && Percent_Chance(50)) {
  4754. fixed source_val = 0;
  4755. int primary = What_Weapon_Should_I_Use(source->As_Target());
  4756. WeaponTypeClass const * weapon = (primary == 0) ? source->Techno_Type_Class()->PrimaryWeapon : source->Techno_Type_Class()->SecondaryWeapon;
  4757. if (weapon != NULL && weapon->WarheadPtr != NULL && In_Range(source, primary)) {
  4758. source_val = weapon->WarheadPtr->Modifier[Techno_Type_Class()->Armor];
  4759. }
  4760. fixed current_val = 0;
  4761. TechnoClass const * tech = As_Techno(TarCom);
  4762. if (tech != NULL) {
  4763. primary = What_Weapon_Should_I_Use(tech->As_Target());
  4764. weapon = (primary == 0) ? source->Techno_Type_Class()->PrimaryWeapon : source->Techno_Type_Class()->SecondaryWeapon;
  4765. if (weapon != NULL && weapon->WarheadPtr != NULL && In_Range(tech, primary)) {
  4766. current_val = weapon->WarheadPtr->Modifier[Techno_Type_Class()->Armor];
  4767. }
  4768. }
  4769. if (source_val <= current_val) return(false);
  4770. }
  4771. /*
  4772. ** If it is already busy attacking another target, then don't retaliate.
  4773. */
  4774. // if (In_Range(TarCom)) return(false);
  4775. /*
  4776. ** All checks passed, so return that retaliation is allowed.
  4777. */
  4778. return(true);
  4779. }
  4780. /***********************************************************************************************
  4781. * TechnoClass::Get_Ownable -- Fetches the ownable bits for this object. *
  4782. * *
  4783. * This routine will return the ownable bits for this object. The ownable bits represent *
  4784. * the houses that are allowed to own this object. *
  4785. * *
  4786. * INPUT: none *
  4787. * *
  4788. * OUTPUT: Returns the ownable bits for this object. *
  4789. * *
  4790. * WARNINGS: none *
  4791. * *
  4792. * HISTORY: *
  4793. * 07/29/1995 JLB : Created. *
  4794. *=============================================================================================*/
  4795. int TechnoClass::Get_Ownable(void) const
  4796. {
  4797. assert(IsActive);
  4798. return ((TechnoTypeClass const &)Class_Of()).Get_Ownable();
  4799. // return ((TechnoTypeClass const &)Class_Of()).Ownable;
  4800. }
  4801. /***********************************************************************************************
  4802. * TechnoClass::Risk -- Fetches the risk associated with this object. *
  4803. * *
  4804. * This routine is called when the risk value for this object needs to be determined. *
  4805. * *
  4806. * INPUT: none *
  4807. * *
  4808. * OUTPUT: Returns with the risk value for this object. *
  4809. * *
  4810. * WARNINGS: none *
  4811. * *
  4812. * HISTORY: *
  4813. * 07/29/1995 JLB : Created. *
  4814. *=============================================================================================*/
  4815. int TechnoClass::Risk(void) const
  4816. {
  4817. assert(IsActive);
  4818. return(Techno_Type_Class()->Risk);
  4819. }
  4820. /***********************************************************************************************
  4821. * TechnoClass::Tiberium_Load -- Fetches the current tiberium load percentage. *
  4822. * *
  4823. * This routine will return the current Tiberium load (expressed as a fixed point fraction) *
  4824. * that this object currently contains. Typical implementor of this function would be *
  4825. * the harvester. Any object that can return a non-zero value should derive from this *
  4826. * function in order to return the appropriate value. *
  4827. * *
  4828. * INPUT: none *
  4829. * *
  4830. * OUTPUT: Returns with the current Tiberium load expressed as a fixed point number. *
  4831. * 0x0000 = empty *
  4832. * 0x0080 = half full *
  4833. * 0x0100 = full *
  4834. * *
  4835. * WARNINGS: none *
  4836. * *
  4837. * HISTORY: *
  4838. * 07/29/1995 JLB : Created. *
  4839. *=============================================================================================*/
  4840. fixed TechnoClass::Tiberium_Load(void) const
  4841. {
  4842. assert(IsActive);
  4843. return(0);
  4844. }
  4845. /***********************************************************************************************
  4846. * TechnoClass::Desired_Load_Dir -- Fetches loading parameters for this object. *
  4847. * *
  4848. * This routine is called when an object desires to load up on this object. The object *
  4849. * desiring to load is specified. The cell that the loading object should move to is *
  4850. * determined. The direction that this object should face is also calculated. This routine *
  4851. * will be overridden by those objects that can actually load up passengers. *
  4852. * *
  4853. * INPUT: object -- The object that is desiring to load up. *
  4854. * *
  4855. * moveto -- Reference to the cell that the loading object should move to before *
  4856. * the final load process occurs (this value will be filled in). *
  4857. * *
  4858. * OUTPUT: Returns with the direction that the transport object should face. *
  4859. * *
  4860. * WARNINGS: none *
  4861. * *
  4862. * HISTORY: *
  4863. * 07/29/1995 JLB : Created. *
  4864. *=============================================================================================*/
  4865. DirType TechnoClass::Desired_Load_Dir(ObjectClass * , CELL & moveto) const
  4866. {
  4867. assert(IsActive);
  4868. moveto = 0;
  4869. return(DIR_N);
  4870. }
  4871. /***********************************************************************************************
  4872. * TechnoClass::Pip_Count -- Fetches the number of pips to display on this object. *
  4873. * *
  4874. * This routine will return the number of pips to display on this object when the object *
  4875. * is selected. The default condition is to return no pips at all. This routine is *
  4876. * derived for those objects that can have pips. *
  4877. * *
  4878. * INPUT: none *
  4879. * *
  4880. * OUTPUT: Returns with the number of pips to display on this object when selected. *
  4881. * *
  4882. * WARNINGS: none *
  4883. * *
  4884. * HISTORY: *
  4885. * 07/29/1995 JLB : Created. *
  4886. *=============================================================================================*/
  4887. int TechnoClass::Pip_Count(void) const
  4888. {
  4889. assert(IsActive);
  4890. return(0);
  4891. }
  4892. /***********************************************************************************************
  4893. * TechnoClass::Fire_Direction -- Fetches the direction projectile fire will take. *
  4894. * *
  4895. * This routine will fetch the direction that a fired projectile will take. This is *
  4896. * usually the facing of the object's weapon. This routine will be derived for the objects *
  4897. * that have their weapon barrel facing a different direction than the body. *
  4898. * *
  4899. * INPUT: none *
  4900. * *
  4901. * OUTPUT: Returns with the direction a fired projectile will take. *
  4902. * *
  4903. * WARNINGS: none *
  4904. * *
  4905. * HISTORY: *
  4906. * 07/29/1995 JLB : Created. *
  4907. *=============================================================================================*/
  4908. DirType TechnoClass::Fire_Direction(void) const
  4909. {
  4910. assert(IsActive);
  4911. return(Turret_Facing());
  4912. }
  4913. /***********************************************************************************************
  4914. * TechnoClass::Response_Select -- Handles the voice response when selected. *
  4915. * *
  4916. * This routine is called when a voice response to a select action is desired. This routine *
  4917. * should be overridden for any object that actually has a voice response. *
  4918. * *
  4919. * INPUT: none *
  4920. * *
  4921. * OUTPUT: none *
  4922. * *
  4923. * WARNINGS: This routine can generate an audio response. *
  4924. * *
  4925. * HISTORY: *
  4926. * 07/29/1995 JLB : Created. *
  4927. *=============================================================================================*/
  4928. void TechnoClass::Response_Select(void)
  4929. {
  4930. assert(IsActive);
  4931. }
  4932. /***********************************************************************************************
  4933. * TechnoClass::Response_Move -- Handles the voice response to a movement request. *
  4934. * *
  4935. * This routine is called when a voice response to a movement order is desired. This *
  4936. * routine should be overridden for any object that actually has a voice response. *
  4937. * *
  4938. * INPUT: none *
  4939. * *
  4940. * OUTPUT: none *
  4941. * *
  4942. * WARNINGS: This can generate an audio response. *
  4943. * *
  4944. * HISTORY: *
  4945. * 07/29/1995 JLB : Created. *
  4946. *=============================================================================================*/
  4947. void TechnoClass::Response_Move(void)
  4948. {
  4949. assert(IsActive);
  4950. }
  4951. /***********************************************************************************************
  4952. * TechnoClass::Response_Attack -- Handles the voice response when given attack order. *
  4953. * *
  4954. * This routine is called when a voice response to an attack order is desired. This routine *
  4955. * should be overridden for any object that actually have a voice response. *
  4956. * *
  4957. * INPUT: none *
  4958. * *
  4959. * OUTPUT: none *
  4960. * *
  4961. * WARNINGS: This can generate an audio response. *
  4962. * *
  4963. * HISTORY: *
  4964. * 07/29/1995 JLB : Created. *
  4965. *=============================================================================================*/
  4966. void TechnoClass::Response_Attack(void)
  4967. {
  4968. assert(IsActive);
  4969. }
  4970. /***********************************************************************************************
  4971. * TechnoClass::Target_Something_Nearby -- Handles finding and assigning a nearby target. *
  4972. * *
  4973. * This routine will search for a nearby target and assign it to this object's TarCom. *
  4974. * The method to use when scanning for a target is controlled by the parameter passed. *
  4975. * *
  4976. * INPUT: threat -- The threat control parameter used to control the range searched. The *
  4977. * only values recognized are THREAT_RANGE and THREAT_AREA. *
  4978. * *
  4979. * OUTPUT: Was a suitable target acquired and assigned to the TarCom? *
  4980. * *
  4981. * WARNINGS: none *
  4982. * *
  4983. * HISTORY: *
  4984. * 07/29/1995 JLB : Created. *
  4985. *=============================================================================================*/
  4986. bool TechnoClass::Target_Something_Nearby(ThreatType threat)
  4987. {
  4988. assert(IsActive);
  4989. threat = threat & (THREAT_RANGE|THREAT_AREA);
  4990. /*
  4991. ** Determine that if there is an existing target it is still legal
  4992. ** and within range.
  4993. */
  4994. if (Target_Legal(TarCom)) {
  4995. if ((threat & THREAT_RANGE)) {
  4996. int primary = What_Weapon_Should_I_Use(TarCom);
  4997. if (!In_Range(TarCom, primary)) {
  4998. Assign_Target(TARGET_NONE);
  4999. }
  5000. }
  5001. }
  5002. /*
  5003. ** If there is no target, then try to find one and assign it as
  5004. ** the target for this unit.
  5005. */
  5006. if (!Target_Legal(TarCom)) {
  5007. Assign_Target(Greatest_Threat(threat));
  5008. }
  5009. /*
  5010. ** Return with answer to question: Does this unit now have a target?
  5011. */
  5012. return(Target_Legal(TarCom));
  5013. }
  5014. /***********************************************************************************************
  5015. * TechnoClass::Exit_Object -- Causes specified object to leave this object. *
  5016. * *
  5017. * This routine is called when there is an attached object that should detach and leave *
  5018. * this object. Typical of this would be the refinery and APC. *
  5019. * *
  5020. * INPUT: object -- The object that is trying to leave this object. *
  5021. * *
  5022. * OUTPUT: Was the object successfully launched from this object? Failure might indicate that *
  5023. * there is insufficient room to detach the specified object. *
  5024. * *
  5025. * WARNINGS: none *
  5026. * *
  5027. * HISTORY: *
  5028. * 07/24/1995 JLB : Created. *
  5029. *=============================================================================================*/
  5030. int TechnoClass::Exit_Object(TechnoClass *)
  5031. {
  5032. assert(IsActive);
  5033. return(0);
  5034. }
  5035. /***********************************************************************************************
  5036. * TechnoClass::Is_Ready_To_Random_Animate -- Determines if the object should random animate. *
  5037. * *
  5038. * This will examine this object to determine if it is time and ready to perform some *
  5039. * kind of random animation. *
  5040. * *
  5041. * INPUT: none *
  5042. * *
  5043. * OUTPUT: bool; Is it time to perform an random animation? *
  5044. * *
  5045. * WARNINGS: none *
  5046. * *
  5047. * HISTORY: *
  5048. * 10/19/1996 JLB : Created. *
  5049. *=============================================================================================*/
  5050. bool TechnoClass::Is_Ready_To_Random_Animate(void) const
  5051. {
  5052. assert(IsActive);
  5053. return(IdleTimer == 0);
  5054. }
  5055. /***********************************************************************************************
  5056. * TechnoClass::Assign_Destination -- Assigns movement destination to the object. *
  5057. * *
  5058. * This routine is called when the object needs to have a new movement destination *
  5059. * assigned. This routine must be overridden since at this level, movement is not allowed. *
  5060. * *
  5061. * INPUT: destination -- The destination to assign to this object. *
  5062. * *
  5063. * OUTPUT: none *
  5064. * *
  5065. * WARNINGS: none *
  5066. * *
  5067. * HISTORY: *
  5068. * 07/24/1995 JLB : Created. *
  5069. *=============================================================================================*/
  5070. void TechnoClass::Assign_Destination(TARGET )
  5071. {
  5072. assert(IsActive);
  5073. }
  5074. /***********************************************************************************************
  5075. * TechnoClass::Enter_Idle_Mode -- Object enters its default idle condition. *
  5076. * *
  5077. * This routine is called when the object should intelligently revert to an idle state. *
  5078. * Typically this routine is called after some mission has completed. This routine must *
  5079. * be overridden by the various object types. It is located at this level merely to provide *
  5080. * a virtual function entry point. *
  5081. * *
  5082. * INPUT: initial -- Is this called when the unit just leaves a factory or is initially *
  5083. * or is initially placed on the map? *
  5084. * *
  5085. * OUTPUT: none *
  5086. * *
  5087. * WARNINGS: none *
  5088. * *
  5089. * HISTORY: *
  5090. * 07/24/1995 JLB : Created. *
  5091. *=============================================================================================*/
  5092. void TechnoClass::Enter_Idle_Mode(bool )
  5093. {
  5094. assert(IsActive);
  5095. }
  5096. /***********************************************************************************************
  5097. * TechnoClass::Draw_Pips -- Draws the transport pips and other techno graphics. *
  5098. * *
  5099. * This routine is used to render the small transportation pip (occupant feedback graphic) *
  5100. * used for transporter object. It will also display if the techno object is "primary" *
  5101. * if necessary. *
  5102. * *
  5103. * INPUT: x,y -- The pixel coordinate for the center of the first pip. Subsequent pips *
  5104. * are drawn rightward. *
  5105. * *
  5106. * window-- The window that pip clipping is relative to. *
  5107. * *
  5108. * OUTPUT: none *
  5109. * *
  5110. * WARNINGS: none *
  5111. * *
  5112. * HISTORY: *
  5113. * 08/08/1995 JLB : Created. *
  5114. * 10/06/1995 JLB : Displays the team group number. *
  5115. * 09/10/1996 JLB : Medic hack for red pip. *
  5116. *=============================================================================================*/
  5117. void TechnoClass::Draw_Pips(int x, int y, WindowNumberType window) const
  5118. {
  5119. assert(IsActive);
  5120. /*
  5121. ** Transporter type objects have a different graphic representation for the pips. The
  5122. ** pip color represents the type of occupant.
  5123. */
  5124. bool carrying_passengers = (Techno_Type_Class()->Max_Passengers() > 0) &&
  5125. ((What_Am_I() != RTTI_AIRCRAFT) || (*(AircraftClass*)this != AIRCRAFT_BADGER) || (Mission != MISSION_HUNT));
  5126. if (carrying_passengers) {
  5127. ObjectClass const * object = Attached_Object();
  5128. for (int index = 0; index < Class_Of().Max_Pips(); index++) {
  5129. PipEnum pip = PIP_EMPTY;
  5130. if (object != NULL) {
  5131. pip = PIP_FULL;
  5132. if (object->What_Am_I() == RTTI_INFANTRY) {
  5133. pip = ((InfantryClass *)object)->Class->Pip;
  5134. }
  5135. #ifdef FIXIT_CARRIER // checked - ajw 9/28/98
  5136. if (What_Am_I() == RTTI_VESSEL && *(VesselClass *)this == VESSEL_CARRIER) {
  5137. if (object->What_Am_I() == RTTI_AIRCRAFT) {
  5138. AircraftClass *heli = (AircraftClass *)object;
  5139. if (heli->Ammo != heli->Techno_Type_Class()->MaxAmmo) {
  5140. pip = PIP_ENGINEER;
  5141. if (!heli->Ammo) {
  5142. pip = PIP_COMMANDO;
  5143. }
  5144. }
  5145. }
  5146. }
  5147. #endif
  5148. object = object->Next;
  5149. }
  5150. CC_Draw_Pip(this, Class_Of().PipShapes, pip, x+index*3, y, window, SHAPE_CENTER|SHAPE_WIN_REL);
  5151. }
  5152. } else {
  5153. /*
  5154. ** Display number of how many attached objects there are. This is also used
  5155. ** to display the fullness rating for a harvester.
  5156. */
  5157. int pips = Pip_Count();
  5158. /*
  5159. ** Check if it's a harvester, to show the right type of pips for the
  5160. ** various minerals it could have harvested.
  5161. */
  5162. if (What_Am_I() == RTTI_UNIT && *(UnitClass *)this == UNIT_HARVESTER) {
  5163. UnitClass * harv = (UnitClass *)this;
  5164. int iron = harv->Gems;
  5165. int nickel = harv->Gold;
  5166. int graypips = pips * fixed(iron, Rule.BailCount);
  5167. int greenpips = pips * fixed(nickel, Rule.BailCount);
  5168. while (greenpips + graypips < pips) {
  5169. int ironnickelmax = max(iron, nickel);
  5170. if (iron > nickel) {
  5171. graypips++;
  5172. } else {
  5173. greenpips++;
  5174. }
  5175. }
  5176. for (int index = 0; index < Class_Of().Max_Pips(); index++) {
  5177. int shape = PIP_EMPTY;
  5178. if (index < pips) {
  5179. if (greenpips) {
  5180. shape = PIP_FULL;
  5181. greenpips--;
  5182. } else {
  5183. shape = PIP_COMMANDO;
  5184. graypips--;
  5185. }
  5186. }
  5187. CC_Draw_Pip(this, Class_Of().PipShapes, shape, x+index*3, y, window, SHAPE_CENTER|SHAPE_WIN_REL);
  5188. }
  5189. }
  5190. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  5191. /*
  5192. ** Check if it's a Chrono tank, to show the recharge gauge.
  5193. */
  5194. else if (What_Am_I() == RTTI_UNIT && *(UnitClass *)this == UNIT_CHRONOTANK) {
  5195. for (int index = 0; index < 5; index++) {
  5196. int shape = PIP_EMPTY;
  5197. if (index < pips) {
  5198. switch(index) {
  5199. case 0:
  5200. case 1:
  5201. shape = PIP_COMMANDO;
  5202. break;
  5203. case 2:
  5204. case 3:
  5205. shape = PIP_ENGINEER;
  5206. break;
  5207. case 4:
  5208. shape = PIP_FULL;
  5209. default:
  5210. break;
  5211. }
  5212. }
  5213. CC_Draw_Pip(this, Class_Of().PipShapes, shape, x+index*3, y, window, SHAPE_CENTER|SHAPE_WIN_REL);
  5214. }
  5215. #endif
  5216. } else {
  5217. bool building = false;
  5218. int pip = PIP_FULL; // green
  5219. if(!IsOwnedByPlayer && What_Am_I() == RTTI_BUILDING) {
  5220. if(*(BuildingClass *)this==STRUCT_POWER || *(BuildingClass *)this==STRUCT_ADVANCED_POWER) {
  5221. building = true;
  5222. if (House->Power_Fraction() < 1) {
  5223. pip = PIP_ENGINEER; // gold
  5224. if (House->Drain > (House->Power * 2) ) {
  5225. pip = PIP_COMMANDO;
  5226. }
  5227. }
  5228. }
  5229. }
  5230. // Ally/spied power display is handled separately in the virtual window
  5231. if (!building || (window != WINDOW_VIRTUAL)) {
  5232. for (int index = 0; index < (building ? 5 : Class_Of().Max_Pips()); index++) {
  5233. if (building) {
  5234. CC_Draw_Pip(this, Class_Of().PipShapes, pip, x, y-index*3, window, SHAPE_CENTER|SHAPE_WIN_REL);
  5235. } else {
  5236. CC_Draw_Pip(this, Class_Of().PipShapes, (index < pips) ? PIP_FULL : PIP_EMPTY, x+index*3, y, window, SHAPE_CENTER|SHAPE_WIN_REL);
  5237. }
  5238. }
  5239. //BG for (int index = 0; index < Class_Of().Max_Pips(); index++) {
  5240. //BG CC_Draw_Shape(Class_Of().PipShapes, (index < pips) ? PIP_FULL : PIP_EMPTY, x+index*3, y, window, SHAPE_CENTER|SHAPE_WIN_REL);
  5241. //BG }
  5242. }
  5243. }
  5244. }
  5245. /*
  5246. ** Special hack to display a red pip on the medic.
  5247. */
  5248. if (What_Am_I() == RTTI_INFANTRY && Combat_Damage() < 0) {
  5249. CC_Draw_Shape(Class_Of().PipShapes, PIP_MEDIC, x+8, y, window, SHAPE_CENTER|SHAPE_WIN_REL);
  5250. }
  5251. /*
  5252. ** Display whether this unit is a leader unit or not.
  5253. */
  5254. if (IsLeader && (window != WINDOW_VIRTUAL)) {
  5255. PipEnum prishape = PIP_PRIMARY;
  5256. if(What_Am_I() == RTTI_BUILDING) {
  5257. if(*((BuildingClass *)this) == STRUCT_KENNEL) {
  5258. prishape = PIP_PRI;
  5259. }
  5260. }
  5261. CC_Draw_Shape(Class_Of().PipShapes, prishape, x-2, y-3, window, /*SHAPE_CENTER|*/SHAPE_WIN_REL);
  5262. }
  5263. /*
  5264. ** Display what group this unit belongs to. This corresponds to the team
  5265. ** number assigned with the <CTRL> key.
  5266. */
  5267. if (Is_Foot() && ((FootClass *)this)->Group != 0xFF && ((FootClass *)this)->Group < 10) {
  5268. int yval = -1;
  5269. int group = ((FootClass *)this)->Group;
  5270. if (Class_Of().Max_Pips()) yval -= 4;
  5271. if (group == 10) group = 0;
  5272. CC_Draw_Shape(Class_Of().PipShapes, PIP_NUMBERS+group, x+2, y+yval, window, SHAPE_CENTER|SHAPE_WIN_REL);
  5273. /*
  5274. ** If this unit is part of a formation, draw an 'F' after the group
  5275. ** number.
  5276. */
  5277. if ( ((FootClass *)this)->XFormOffset != 0x80000000UL) {
  5278. CC_Draw_Shape(Class_Of().PipShapes, PIP_LETTERF, x+8, y+yval, window, SHAPE_CENTER|SHAPE_WIN_REL);
  5279. }
  5280. }
  5281. /*
  5282. ** If this building is being spied on by the player, draw the money or
  5283. ** factory-producing item or whatever.
  5284. */
  5285. if (What_Am_I() == RTTI_BUILDING) {
  5286. int spiedby = Spied_By() & (1<<(PlayerPtr->Class->House));
  5287. /*
  5288. ** Print word "Decoy" above buildings that are spied upon or fake
  5289. */
  5290. if (((BuildingClass *)this)->Class->IsFake) {
  5291. if (spiedby || IsOwnedByPlayer) {
  5292. CC_Draw_Shape(Class_Of().PipShapes, PIP_DECOY, x, y-16, window, SHAPE_WIN_REL);
  5293. }
  5294. }
  5295. /*
  5296. ** See if we should print the credits for a spied refinery
  5297. */
  5298. if (spiedby) {
  5299. // If it's a refinery/silo, print the enemy's money
  5300. if (((BuildingClass *)this)->Class->Capacity) {
  5301. long money = House->Available_Money();
  5302. /*
  5303. ** Determine how many digits will be printed.
  5304. */
  5305. int digits;
  5306. int factor = 10;
  5307. for (digits = 1; digits < 9; digits++) {
  5308. if (money < factor) break;
  5309. factor *= 10;
  5310. }
  5311. int startx = x + 6 * digits - 3;// + 6 * 8;
  5312. while (money) {
  5313. int xdigit = money % 10;
  5314. money /= 10;
  5315. CC_Draw_Shape(Class_Of().PipShapes, PIP_NUMBERS + xdigit, startx, y-6, window, SHAPE_CENTER|SHAPE_WIN_REL);
  5316. startx -= 6;
  5317. }
  5318. }
  5319. }
  5320. }
  5321. }
  5322. /***********************************************************************************************
  5323. * TechnoClass::Find_Docking_Bay -- Searches for a close docking bay. *
  5324. * *
  5325. * This routine will be used to find a building that can serve as a docking bay. The *
  5326. * closest building that qualifies will be returned. If no building could be found then *
  5327. * return with NULL. *
  5328. * *
  5329. * INPUT: b -- The structure type to look for. *
  5330. * *
  5331. * friendly -- Allow searching for allied buildings as well. *
  5332. * *
  5333. * OUTPUT: Returns with a pointer to the building that can serve as the best docking bay. *
  5334. * *
  5335. * WARNINGS: This routine might return NULL even if there are buildings of the specified *
  5336. * type available. This is the case when the building(s) are currently busy and *
  5337. * cannot serve as a docking bay at the moment. *
  5338. * *
  5339. * HISTORY: *
  5340. * 07/18/1995 JLB : Created. *
  5341. * 08/13/1995 JLB : Recognizes the "IsLeader" method of building preference. *
  5342. *=============================================================================================*/
  5343. BuildingClass * TechnoClass::Find_Docking_Bay(StructType b, bool friendly) const
  5344. {
  5345. assert(IsActive);
  5346. BuildingClass * best = 0;
  5347. /*
  5348. ** First check to see if there are ANY buildings of the specified
  5349. ** type in this house's inventory. If not, then don't bother to scan
  5350. ** for one.
  5351. */
  5352. if (House->Get_Quantity(b) != 0) {
  5353. int bestval = -1;
  5354. /*
  5355. ** Loop through all the buildings and find the one that matches the specification
  5356. ** and is willing to dock with this object.
  5357. */
  5358. for (int index = 0; index < Buildings.Count(); index++) {
  5359. BuildingClass * building = Buildings.Ptr(index);
  5360. /*
  5361. ** Check to see if the building qualifies (preliminary scan).
  5362. */
  5363. if (building != NULL &&
  5364. (friendly ? building->House->Is_Ally(this) : building->House == House) &&
  5365. !building->IsInLimbo &&
  5366. *building == b &&
  5367. (What_Am_I() == RTTI_AIRCRAFT || Map[building->Center_Coord()].Zones[Techno_Type_Class()->MZone] == Map[Center_Coord()].Zones[Techno_Type_Class()->MZone]) &&
  5368. ((TechnoClass *)this)->Transmit_Message(RADIO_CAN_LOAD, building) == RADIO_ROGER) {
  5369. /*
  5370. ** If the building qualifies and this building is better than the
  5371. ** last qualifying building (as rated by distance), then record
  5372. ** this building and keep scanning.
  5373. */
  5374. if (bestval == -1 || Distance(building) < bestval || building->IsLeader) {
  5375. best = building;
  5376. bestval = Distance(building);
  5377. }
  5378. }
  5379. }
  5380. }
  5381. return(best);
  5382. }
  5383. /***********************************************************************************************
  5384. * TechnoClass::Find_Exit_Cell -- Finds an appropriate exit cell for this object. *
  5385. * *
  5386. * This routine is called when an object would like to exit from this (presumed) transport. *
  5387. * A suitable cell should be returned by this routine. The specified object will probably *
  5388. * be unloaded at that cell. *
  5389. * *
  5390. * INPUT: techno -- Pointer to the object that would like to unload. This is used to *
  5391. * determine suitability for placement. *
  5392. * *
  5393. * OUTPUT: Returns with the cell that is recommended for object exit. *
  5394. * *
  5395. * WARNINGS: none *
  5396. * *
  5397. * HISTORY: *
  5398. * 08/12/1995 JLB : Created. *
  5399. *=============================================================================================*/
  5400. CELL TechnoClass::Find_Exit_Cell(TechnoClass const * ) const
  5401. {
  5402. assert(IsActive);
  5403. return(Coord_Cell(Docking_Coord()));
  5404. }
  5405. /***********************************************************************************************
  5406. * TechnoClass::Refund_Amount -- Returns with the money to refund if this object is sold. *
  5407. * *
  5408. * This routine is used by the selling back mechanism in order to credit the owning house *
  5409. * with some refund credits. The value returned is the credits to refund to the owner. *
  5410. * *
  5411. * INPUT: none *
  5412. * *
  5413. * OUTPUT: Returns with the credits to refund to the owner. *
  5414. * *
  5415. * WARNINGS: none *
  5416. * *
  5417. * HISTORY: *
  5418. * 08/13/1995 JLB : Created. *
  5419. *=============================================================================================*/
  5420. int TechnoClass::Refund_Amount(void) const
  5421. {
  5422. assert(IsActive);
  5423. int cost = Techno_Type_Class()->Raw_Cost() * House->CostBias;
  5424. #ifdef TOFIX
  5425. /*
  5426. ** If the object is carrying Tiberium directly (i.e., the harvester), then
  5427. ** account for the credits of the load.
  5428. */
  5429. // cost += Fixed_To_Cardinal(UnitTypeClass::FULL_LOAD_CREDITS, Tiberium_Load())/2;
  5430. #endif
  5431. if (House->IsHuman) {
  5432. cost = cost * Rule.RefundPercent;
  5433. // cost /= 2;
  5434. }
  5435. return(cost);
  5436. }
  5437. /***********************************************************************************************
  5438. * TechnoClass::Anti_Air -- Determines the anti-aircraft strength of the object. *
  5439. * *
  5440. * This routine will calculate and return the anti-aircraft strength of this object. *
  5441. * Typical users of this strength value is the base defense expert system AI. *
  5442. * *
  5443. * INPUT: none *
  5444. * *
  5445. * OUTPUT: Returns with the anti-aircraft defense value of this object. The value returned *
  5446. * is an abstract number to be used for relative comparisons only. *
  5447. * *
  5448. * WARNINGS: none *
  5449. * *
  5450. * HISTORY: *
  5451. * 10/02/1995 JLB : Created. *
  5452. *=============================================================================================*/
  5453. int TechnoClass::Anti_Air(void) const
  5454. {
  5455. assert(IsActive);
  5456. if (Is_Weapon_Equipped()) {
  5457. WeaponTypeClass const * weapon = Techno_Type_Class()->PrimaryWeapon;
  5458. BulletTypeClass const * bullet = weapon->Bullet;
  5459. WarheadTypeClass const * warhead = weapon->WarheadPtr;
  5460. if (bullet->IsAntiAircraft) {
  5461. int value = ((weapon->Attack * warhead->Modifier[ARMOR_ALUMINUM]) * weapon->Range) / weapon->ROF;
  5462. if (Techno_Type_Class()->Is_Two_Shooter()) {
  5463. value *= 2;
  5464. }
  5465. return(value/50);
  5466. }
  5467. }
  5468. return(0);
  5469. }
  5470. /***********************************************************************************************
  5471. * TechnoClass::Anti_Armor -- Determines the anti-armor strength of the object. *
  5472. * *
  5473. * This routine is used to examine and calculate the anti-armor strength of this object. *
  5474. * Typical user user of this would be the expert system base defense AI. *
  5475. * *
  5476. * INPUT: none *
  5477. * *
  5478. * OUTPUT: Returns with the relative anti-armor combat value for this object. The value *
  5479. * is abstract and is only to be used in relative comparisons. *
  5480. * *
  5481. * WARNINGS: none *
  5482. * *
  5483. * HISTORY: *
  5484. * 10/02/1995 JLB : Created. *
  5485. *=============================================================================================*/
  5486. int TechnoClass::Anti_Armor(void) const
  5487. {
  5488. assert(IsActive);
  5489. if (Is_Weapon_Equipped()) {
  5490. if (!Techno_Type_Class()->PrimaryWeapon->Bullet->IsAntiGround) return(0);
  5491. WeaponTypeClass const * weapon = Techno_Type_Class()->PrimaryWeapon;
  5492. BulletTypeClass const * bullet = weapon->Bullet;
  5493. WarheadTypeClass const * warhead = weapon->WarheadPtr;
  5494. int mrange = min(weapon->Range, 0x0400);
  5495. int value = ((weapon->Attack * warhead->Modifier[ARMOR_STEEL]) * mrange * warhead->SpreadFactor) / weapon->ROF;
  5496. if (Techno_Type_Class()->Is_Two_Shooter()) {
  5497. value *= 2;
  5498. }
  5499. if (bullet->IsInaccurate) {
  5500. value /= 2;
  5501. }
  5502. return(value/50);
  5503. }
  5504. return(0);
  5505. }
  5506. /***********************************************************************************************
  5507. * TechnoClass::Anti_Infantry -- Calculates the anti-infantry strength of this object. *
  5508. * *
  5509. * This routine is used to determine the anti-infantry strength of this object. The *
  5510. * typical user of this routine is the expert system base defense AI. *
  5511. * *
  5512. * INPUT: none *
  5513. * *
  5514. * OUTPUT: Returns with the anti-infantry strength of this object. The value returned is *
  5515. * abstract and should only be used for relative comparisons. *
  5516. * *
  5517. * WARNINGS: none *
  5518. * *
  5519. * HISTORY: *
  5520. * 10/02/1995 JLB : Created. *
  5521. *=============================================================================================*/
  5522. int TechnoClass::Anti_Infantry(void) const
  5523. {
  5524. assert(IsActive);
  5525. if (Is_Weapon_Equipped()) {
  5526. if (!Techno_Type_Class()->PrimaryWeapon->Bullet->IsAntiGround) return(0);
  5527. WeaponTypeClass const * weapon = Techno_Type_Class()->PrimaryWeapon;
  5528. BulletTypeClass const * bullet = weapon->Bullet;
  5529. WarheadTypeClass const * warhead = weapon->WarheadPtr;
  5530. int mrange = min(weapon->Range, 0x0400);
  5531. int value = ((weapon->Attack * warhead->Modifier[ARMOR_NONE]) * mrange * warhead->SpreadFactor) / weapon->ROF;
  5532. if (Techno_Type_Class()->Is_Two_Shooter()) {
  5533. value *= 2;
  5534. }
  5535. if (bullet->IsInaccurate) {
  5536. value /= 2;
  5537. }
  5538. return(value/50);
  5539. }
  5540. return(0);
  5541. }
  5542. /***********************************************************************************************
  5543. * TechnoClass::Look -- Performs a look around (map reveal) action. *
  5544. * *
  5545. * This routine will reveal the map around this object. *
  5546. * *
  5547. * INPUT: incremental -- This parameter can enable a more efficient map reveal logic. *
  5548. * If it is absolutely known that the object has only moved one *
  5549. * cell from its previous location that it performed a Look() at, *
  5550. * then set this parameter to TRUE. It will only perform the look *
  5551. * check on the perimeter cells. *
  5552. * *
  5553. * OUTPUT: none *
  5554. * *
  5555. * WARNINGS: This routine is slow, try to call it only when necessary. *
  5556. * *
  5557. * HISTORY: *
  5558. * 03/14/1996 JLB : Created. *
  5559. *=============================================================================================*/
  5560. void TechnoClass::Look(bool incremental)
  5561. {
  5562. assert(IsActive);
  5563. assert(!IsInLimbo);
  5564. int sight_range = Techno_Type_Class()->SightRange;
  5565. if (sight_range) {
  5566. Map.Sight_From(Coord_Cell(Coord), sight_range, House, incremental);
  5567. #if (0) // Leaving this here for posterity, in case we need it for revealing allies. ST - 10/17/2019 10:51AM
  5568. /*
  5569. ** Changed this function to reveal for the appropriate players in GlyphX multiplayer. ST - 8/7/2019 11:34AM
  5570. */
  5571. if (Session.Type != GAME_GLYPHX_MULTIPLAYER) {
  5572. Map.Sight_From(Coord_Cell(Coord), sight_range, House, incremental);
  5573. } else {
  5574. for (int i = 0; i < Session.Players.Count(); i++) {
  5575. HousesType house_type = Session.Players[i]->Player.ID;
  5576. HouseClass *house = HouseClass::As_Pointer(house_type);
  5577. if (Is_Owned_By_Player(house) || Is_Discovered_By_Player(house)) {
  5578. Map.Sight_From(Coord_Cell(Center_Coord()), sight_range, house, incremental);
  5579. }
  5580. }
  5581. }
  5582. #endif
  5583. }
  5584. }
  5585. //**********************************************************************************************
  5586. // MODULE SEPARATION -- TechnoTypeClass member functions follow.
  5587. //**********************************************************************************************
  5588. /***********************************************************************************************
  5589. * TechnoTypeClass::TechnoTypeClass -- Constructor for techno type objects. *
  5590. * *
  5591. * This is the normal constructor for techno type objects. It is called in the process of *
  5592. * constructing all the object type (constant) data for the various techno type objects. *
  5593. * *
  5594. * INPUT: see below... *
  5595. * *
  5596. * OUTPUT: none *
  5597. * *
  5598. * WARNINGS: none *
  5599. * *
  5600. * HISTORY: *
  5601. * 03/19/1995 JLB : Created. *
  5602. * 05/11/1996 JLB : Moderated risk calc so range doesn't dominate. *
  5603. *=============================================================================================*/
  5604. TechnoTypeClass::TechnoTypeClass(
  5605. RTTIType rtti,
  5606. int id,
  5607. int name,
  5608. char const * ininame,
  5609. RemapType remap,
  5610. int verticaloffset,
  5611. int primaryoffset,
  5612. int primarylateral,
  5613. int secondaryoffset,
  5614. int secondarylateral,
  5615. bool is_nominal,
  5616. bool is_stealthy,
  5617. bool is_selectable,
  5618. bool is_legal_target,
  5619. bool is_insignificant,
  5620. bool is_immune,
  5621. bool is_theater,
  5622. bool is_turret_equipped,
  5623. bool is_remappable,
  5624. bool is_footprint,
  5625. int rotation,
  5626. SpeedType speed,
  5627. int horizontaloffset) :
  5628. ObjectTypeClass( rtti,
  5629. id,
  5630. true,
  5631. is_stealthy,
  5632. is_selectable,
  5633. is_legal_target,
  5634. is_insignificant,
  5635. is_immune,
  5636. is_footprint,
  5637. name,
  5638. ininame),
  5639. Remap(remap),
  5640. IsDoubleOwned(false),
  5641. IsInvisible(false),
  5642. IsLeader(false),
  5643. IsScanner(false),
  5644. IsNominal(is_nominal),
  5645. IsTheater(is_theater),
  5646. IsTurretEquipped(is_turret_equipped),
  5647. IsCrew(false),
  5648. IsRepairable(true),
  5649. IsRemappable(is_remappable),
  5650. IsCloakable(false),
  5651. IsSelfHealing(false),
  5652. IsExploding(false),
  5653. MZone(MZONE_NORMAL),
  5654. ThreatRange(0),
  5655. MaxPassengers(0),
  5656. SightRange(0),
  5657. Cost(0),
  5658. Level(-1),
  5659. Prerequisite(STRUCTF_NONE),
  5660. Risk(0),Reward(0),
  5661. MaxSpeed(MPH_IMMOBILE),
  5662. Speed(speed),
  5663. MaxAmmo(-1),
  5664. Ownable(0),
  5665. CameoData(NULL),
  5666. Rotation(rotation),
  5667. ROT(0),
  5668. PrimaryWeapon(NULL),
  5669. SecondaryWeapon(NULL),
  5670. HorizontalOffset(horizontaloffset),
  5671. VerticalOffset(verticaloffset),
  5672. PrimaryOffset(primaryoffset),
  5673. PrimaryLateral(primarylateral),
  5674. SecondaryOffset(secondaryoffset),
  5675. SecondaryLateral(secondarylateral),
  5676. Points(0)
  5677. {
  5678. }
  5679. /***********************************************************************************************
  5680. * TechnoTypeClass::Raw_Cost -- Fetches the raw (base) cost of the object. *
  5681. * *
  5682. * This routine is used to find the underlying cost for this object. The underlying cost *
  5683. * does not include any free items that normally come with the object when purchased *
  5684. * directly. Example: The raw cost of a refinery is the normal cost minus the cost of a *
  5685. * harvester. *
  5686. * *
  5687. * INPUT: none *
  5688. * *
  5689. * OUTPUT: Returns with the credit cost of the base object type. *
  5690. * *
  5691. * WARNINGS: none *
  5692. * *
  5693. * HISTORY: *
  5694. * 08/13/1995 JLB : Created. *
  5695. *=============================================================================================*/
  5696. int TechnoTypeClass::Raw_Cost(void) const
  5697. {
  5698. return(Cost);
  5699. }
  5700. /***********************************************************************************************
  5701. * TechnoTypeClass::Get_Ownable -- Fetches the ownable bits for this object type. *
  5702. * *
  5703. * This routine will return the ownable bits for this object type. The ownable bits are *
  5704. * a bitflag composite of the houses that can own (build) this object type. *
  5705. * *
  5706. * INPUT: none *
  5707. * *
  5708. * OUTPUT: Returns with the ownable bits for this object type. *
  5709. * *
  5710. * WARNINGS: none *
  5711. * *
  5712. * HISTORY: *
  5713. * 07/29/1995 JLB : Created. *
  5714. *=============================================================================================*/
  5715. int TechnoTypeClass::Get_Ownable(void) const
  5716. {
  5717. if (IsDoubleOwned && Session.Type != GAME_NORMAL) {
  5718. return(Ownable | HOUSEF_SOVIET | HOUSEF_ALLIES);
  5719. }
  5720. return(Ownable);
  5721. }
  5722. /***********************************************************************************************
  5723. * TechnoTypeClass::Time_To_Build -- Fetches the time to build this object. *
  5724. * *
  5725. * This routine will return the time it takes to construct this object. Usually the time *
  5726. * to produce is directly related to cost. *
  5727. * *
  5728. * INPUT: none *
  5729. * *
  5730. * OUTPUT: Returns with the time to produce this object type. The time is expressed in the *
  5731. * form of game ticks. *
  5732. * *
  5733. * WARNINGS: none *
  5734. * *
  5735. * HISTORY: *
  5736. * 07/29/1995 JLB : Created. *
  5737. *=============================================================================================*/
  5738. //#define UNIT_BUILD_BIAS fixed(5,4)
  5739. //#define UNIT_BUILD_BIAS fixed(6,4)
  5740. #define UNIT_BUILD_BIAS fixed(1,1)
  5741. //#define UNIT_BUILD_BIAS fixed(5,1)
  5742. extern int UnitBuildPenalty;
  5743. int TechnoTypeClass::Time_To_Build(HousesType house) const
  5744. {
  5745. int time = Cost * Rule.BuildSpeedBias * fixed(TICKS_PER_MINUTE, 1000);
  5746. HouseClass* hptr = HouseClass::As_Pointer(house);
  5747. if (!hptr || !hptr->IsActive) {
  5748. return time;
  5749. }
  5750. #ifdef FIXIT_VERSION_3
  5751. if (Session.Type == GAME_NORMAL) {
  5752. #else
  5753. if (Session.Type == GAME_NORMAL ||
  5754. PlayingAgainstVersion == VERSION_RED_ALERT_104 ||
  5755. PlayingAgainstVersion == VERSION_RED_ALERT_107) {
  5756. #endif
  5757. time *= hptr->BuildSpeedBias;
  5758. }
  5759. else {
  5760. #if (0) // No longer desired. ST - 1/18/2021
  5761. /*
  5762. ** New feature - Turkey has a 10% build speed bonus even though it isn't specified in the rules
  5763. */
  5764. if (hptr->ActLike == HOUSE_TURKEY) {
  5765. if (hptr->BuildSpeedBias == fixed(1)) {
  5766. time *= 9;
  5767. time /= 10;
  5768. }
  5769. }
  5770. #endif
  5771. if (What_Am_I() == RTTI_BUILDINGTYPE || What_Am_I() == RTTI_INFANTRYTYPE) {
  5772. time *= hptr->BuildSpeedBias;
  5773. }
  5774. else {
  5775. time *= hptr->BuildSpeedBias * fixed(UnitBuildPenalty, 100); //UNIT_BUILD_BIAS;
  5776. }
  5777. }
  5778. /*
  5779. ** Adjust time according to IQ setting of computer controlled house. The
  5780. ** build time will range from double normal time at the slowest to
  5781. ** just normal time at the fastest.
  5782. */
  5783. if (!hptr->IsHuman && Rule.Diff[hptr->Difficulty].IsBuildSlowdown) {
  5784. time = time * Inverse(fixed(hptr->IQ + Rule.MaxIQ, Rule.MaxIQ * 2));
  5785. }
  5786. /*
  5787. ** Adjust the time to build based on the power output of the owning house.
  5788. */
  5789. fixed power = hptr->Power_Fraction();
  5790. fixed scale(1);
  5791. if (power == 0) {
  5792. scale = fixed(4, 1);
  5793. }
  5794. else if (power < fixed::_1_2) {
  5795. scale = fixed(5, 2);
  5796. }
  5797. else if (power < 1) {
  5798. scale = fixed(3, 2);
  5799. }
  5800. time *= scale;
  5801. int divisor = hptr->Factory_Count(What_Am_I());
  5802. if (divisor != 0) {
  5803. #ifdef FIXIT_CSII // checked - ajw 9/28/98
  5804. // Hack: allow the multiple-factory bonus, but only up to two factories if
  5805. // this is an AM<->AM game.
  5806. if (NewUnitsEnabled) {
  5807. time /= min(divisor, 2);
  5808. }
  5809. else {
  5810. time /= divisor;
  5811. }
  5812. #else
  5813. time /= divisor;
  5814. #endif
  5815. }
  5816. return(time);
  5817. }
  5818. /***********************************************************************************************
  5819. * TechnoTypeClass::Cost_Of -- Fetches the cost of this object type. *
  5820. * *
  5821. * This routine will return the cost to produce an object of this type. *
  5822. * *
  5823. * INPUT: none *
  5824. * *
  5825. * OUTPUT: Returns with the cost to produce one object of this type. *
  5826. * *
  5827. * WARNINGS: none *
  5828. * *
  5829. * HISTORY: *
  5830. * 07/29/1995 JLB : Created. *
  5831. *=============================================================================================*/
  5832. int TechnoTypeClass::Cost_Of(void) const
  5833. {
  5834. return(Cost);
  5835. }
  5836. /***********************************************************************************************
  5837. * TechnoTypeClass::Get_Cameo_Data -- Fetches the cameo image for this object type. *
  5838. * *
  5839. * This routine will fetch the cameo (sidebar small image) shape of this object type. *
  5840. * If there is no cameo data available (typical for non-produceable units), then NULL will *
  5841. * be returned. *
  5842. * *
  5843. * INPUT: none *
  5844. * *
  5845. * OUTPUT: Returns with a pointer to the cameo data for this object type if present. *
  5846. * *
  5847. * WARNINGS: none *
  5848. * *
  5849. * HISTORY: *
  5850. * 07/29/1995 JLB : Created. *
  5851. *=============================================================================================*/
  5852. void const * TechnoTypeClass::Get_Cameo_Data(void) const
  5853. {
  5854. return(CameoData);
  5855. }
  5856. /***********************************************************************************************
  5857. * TechnoTypeClass::Repair_Cost -- Fetches the cost to repair one step. *
  5858. * *
  5859. * This routine will return the cost to repair one step. At the TechnoTypeClass level, *
  5860. * this merely serves as a placeholder function. The derived classes will provide a *
  5861. * functional version of this routine. *
  5862. * *
  5863. * INPUT: none *
  5864. * *
  5865. * OUTPUT: Returns with the cost to repair one step. *
  5866. * *
  5867. * WARNINGS: none *
  5868. * *
  5869. * HISTORY: *
  5870. * 07/29/1995 JLB : Created. *
  5871. *=============================================================================================*/
  5872. int TechnoTypeClass::Repair_Cost(void) const
  5873. {
  5874. // MBL 04.28.2020 "Fix" for RA Barracks structures coming back with a repair cost of 0, and repairing for free
  5875. //
  5876. // if (Is_Foot()) {
  5877. // return((Raw_Cost()/(MaxStrength/Rule.URepairStep)) * Rule.URepairPercent);
  5878. // }
  5879. // return((Raw_Cost()/(MaxStrength/Rule.RepairStep)) * Rule.RepairPercent);
  5880. //
  5881. int repair_cost = 0;
  5882. if (Is_Foot()) {
  5883. repair_cost = ((Raw_Cost()/(MaxStrength/Rule.URepairStep)) * Rule.URepairPercent);
  5884. }
  5885. else
  5886. {
  5887. repair_cost = ((Raw_Cost()/(MaxStrength/Rule.RepairStep)) * Rule.RepairPercent);
  5888. }
  5889. repair_cost = MAX(repair_cost, 1);
  5890. return repair_cost;
  5891. }
  5892. /***********************************************************************************************
  5893. * TechnoTypeClass::Repair_Step -- Fetches the health to repair one step. *
  5894. * *
  5895. * This routine merely serves as placeholder virtual function. The various type classes *
  5896. * will override this routine to return the number of health points to repair in one *
  5897. * "step". *
  5898. * *
  5899. * INPUT: none *
  5900. * *
  5901. * OUTPUT: Returns with the number of health points to repair in one step. *
  5902. * *
  5903. * WARNINGS: none *
  5904. * *
  5905. * HISTORY: *
  5906. * 07/29/1995 JLB : Created. *
  5907. *=============================================================================================*/
  5908. int TechnoTypeClass::Repair_Step(void) const
  5909. {
  5910. if (Is_Foot()) {
  5911. return(Rule.URepairStep);
  5912. }
  5913. return(Rule.RepairStep);
  5914. }
  5915. /***********************************************************************************************
  5916. * TechnoTypeClass::Is_Two_Shooter -- Determines if this object is a double shooter. *
  5917. * *
  5918. * Some objects fire two shots in quick succession. If this is true for this object, then *
  5919. * a 'true' value will be returned from this routine. *
  5920. * *
  5921. * INPUT: none *
  5922. * *
  5923. * OUTPUT: bool; Is this object a two shooter? *
  5924. * *
  5925. * WARNINGS: none *
  5926. * *
  5927. * HISTORY: *
  5928. * 07/29/1996 JLB : Created. *
  5929. *=============================================================================================*/
  5930. bool TechnoTypeClass::Is_Two_Shooter(void) const
  5931. {
  5932. if (PrimaryWeapon != NULL && (PrimaryWeapon == SecondaryWeapon || PrimaryWeapon->Burst > 1)) {
  5933. return(true);
  5934. }
  5935. return(false);
  5936. }
  5937. /***********************************************************************************************
  5938. * _Scale_To_256 -- Scales a 1..100 number into a 1..255 number. *
  5939. * *
  5940. * This is a helper routine that will take a decimal percentage number and convert it *
  5941. * into a game based fixed point number. *
  5942. * *
  5943. * INPUT: val -- Decimal percent number to convert. *
  5944. * *
  5945. * OUTPUT: Returns with the decimal percent number converted to a game fixed point number. *
  5946. * *
  5947. * WARNINGS: none *
  5948. * *
  5949. * HISTORY: *
  5950. * 06/17/1996 JLB : Created. *
  5951. *=============================================================================================*/
  5952. static inline int _Scale_To_256(int val)
  5953. {
  5954. val = min(val, 100);
  5955. val = max(val, 0);
  5956. val = ((val * 256) / 100);
  5957. val = min(val, 255);
  5958. return(val);
  5959. }
  5960. /***********************************************************************************************
  5961. * TechnoTypeClass::Read_INI -- Reads the techno type data from the INI database. *
  5962. * *
  5963. * Use this routine to fill in the data for this techno type class object from the *
  5964. * database specified. Typical use of this is for the rules parsing. *
  5965. * *
  5966. * INPUT: ini -- Reference to the INI database that the information will be lifted from. *
  5967. * *
  5968. * OUTPUT: bool; Was the database used to extract information? A failure (false) response *
  5969. * would mean that the database didn't contain a section that applies to this *
  5970. * techno class object. *
  5971. * *
  5972. * WARNINGS: none *
  5973. * *
  5974. * HISTORY: *
  5975. * 07/19/1996 JLB : Created. *
  5976. *=============================================================================================*/
  5977. bool TechnoTypeClass::Read_INI(CCINIClass & ini)
  5978. {
  5979. if (ini.Is_Present(Name())) {
  5980. #ifdef FIXIT_NAME_OVERRIDE
  5981. char buffer[256];
  5982. int id = ((RTTI+1) * 100) + ID;
  5983. ini.Get_String(Name(), "Name", "", buffer, sizeof(buffer));
  5984. if (strlen(buffer) > 0) {
  5985. #if defined (GERMAN)||(FRENCH)
  5986. for(int xx=0; NewName[xx] != NULL; xx++){
  5987. if(!strcmp(NewName[xx], buffer)){
  5988. memcpy(buffer, "", sizeof(buffer));
  5989. memcpy(buffer, NewName[xx+1], sizeof(buffer));
  5990. break;
  5991. }
  5992. }
  5993. #endif
  5994. /*
  5995. ** Insert the new name text into the buffer list.
  5996. */
  5997. for (int index = 0; index < ARRAY_SIZE(NameOverride); index++) {
  5998. if (NameIDOverride[index] == 0) {
  5999. NameOverride[index] = strdup(buffer);
  6000. NameIDOverride[index] = id;
  6001. // FullName = -(index+1);
  6002. break;
  6003. }
  6004. }
  6005. }
  6006. #endif
  6007. IsDoubleOwned = ini.Get_Bool(Name(), "DoubleOwned", IsDoubleOwned);
  6008. ThreatRange = ini.Get_Lepton(Name(), "GuardRange", ThreatRange);
  6009. IsExploding = ini.Get_Bool(Name(), "Explodes", IsExploding);
  6010. PrimaryWeapon = WeaponTypeClass::As_Pointer(ini.Get_WeaponType(Name(), "Primary", PrimaryWeapon != NULL ? (WeaponType)(PrimaryWeapon->ID) : WEAPON_NONE));
  6011. SecondaryWeapon = WeaponTypeClass::As_Pointer(ini.Get_WeaponType(Name(), "Secondary", SecondaryWeapon != NULL ? (WeaponType)(SecondaryWeapon->ID) : WEAPON_NONE));
  6012. IsCloakable = ini.Get_Bool(Name(), "Cloakable", IsCloakable);
  6013. IsCrushable = ini.Get_Bool(Name(), "Crushable", IsCrushable);
  6014. IsScanner = ini.Get_Bool(Name(), "Sensors", IsScanner);
  6015. Armor = ini.Get_ArmorType(Name(), "Armor", Armor);
  6016. Prerequisite = ini.Get_Buildings(Name(), "Prerequisite", Prerequisite);
  6017. MaxStrength = ini.Get_Int(Name(), "Strength", MaxStrength);
  6018. SightRange = ini.Get_Int(Name(), "Sight", SightRange);
  6019. Level = ini.Get_Int(Name(), "TechLevel", Level);
  6020. MaxSpeed = MPHType(_Scale_To_256(ini.Get_Int(Name(), "Speed", fixed(MaxSpeed, 256) * 100)));
  6021. Cost = ini.Get_Int(Name(), "Cost", Cost);
  6022. MaxAmmo = ini.Get_Int(Name(), "Ammo", MaxAmmo);
  6023. Risk = Reward = Points = ini.Get_Int(Name(), "Points", Points);
  6024. Ownable = ini.Get_Owners(Name(), "Owner", Ownable);
  6025. IsCrew = ini.Get_Bool(Name(), "Crewed", IsCrew);
  6026. IsRepairable = ini.Get_Bool(Name(), "Repairable", IsRepairable);
  6027. IsInvisible = ini.Get_Bool(Name(), "Invisible", IsInvisible);
  6028. IsSelfHealing = ini.Get_Bool(Name(), "SelfHealing", IsSelfHealing);
  6029. ROT = ini.Get_Int(Name(), "ROT", ROT);
  6030. MaxPassengers = ini.Get_Int(Name(), "Passengers", MaxPassengers);
  6031. //Mono_Printf("before image=: %s\n",GraphicName);
  6032. ini.Get_String(Name(), "Image", GraphicName, GraphicName, sizeof(GraphicName));
  6033. //Mono_Printf("after image=: %s\n",GraphicName);if(Random_Pick(0,4)) Keyboard->Get();
  6034. IsLeader = false;
  6035. if (PrimaryWeapon != NULL && PrimaryWeapon->Attack > 0) {
  6036. IsLeader = true;
  6037. }
  6038. /*
  6039. ** Check to see what zone this object should recognize.
  6040. */
  6041. if (PrimaryWeapon != NULL && PrimaryWeapon->WarheadPtr != NULL && PrimaryWeapon->WarheadPtr->IsWallDestroyer) {
  6042. MZone = MZONE_DESTROYER;
  6043. }
  6044. if (Speed == SPEED_FLOAT) {
  6045. MZone = MZONE_WATER;
  6046. }
  6047. return(true);
  6048. }
  6049. return(false);
  6050. }
  6051. int TechnoTypeClass::Legal_Placement(CELL pos) const
  6052. {
  6053. if (pos == -1) return(0);
  6054. /*
  6055. ** Normal buildings must check to see that every foundation square is free of
  6056. ** obstacles. If this check passes for all foundation squares, only then does the
  6057. ** routine return that it is legal to place.
  6058. */
  6059. short const * offset = Occupy_List(true);
  6060. bool build = (What_Am_I() == RTTI_BUILDINGTYPE);
  6061. while (offset != NULL && *offset != REFRESH_EOL) {
  6062. CELL cell = pos + *offset++;
  6063. if (!Map.In_Radar(cell)) return(false);
  6064. if (build) {
  6065. if (!Map[cell].Is_Clear_To_Build(Speed)) {
  6066. return(0);
  6067. }
  6068. } else {
  6069. if (!Map[cell].Is_Clear_To_Move(Speed, false, false)) {
  6070. return(0);
  6071. }
  6072. }
  6073. }
  6074. return(1);
  6075. }
  6076. /*
  6077. ** Additions to TechnoClass to track discovery per-player. ST - 3/6/2019 11:18AM
  6078. **
  6079. **
  6080. **
  6081. **
  6082. **
  6083. */
  6084. /***********************************************************************************************
  6085. * TechnoClass::Is_Discovered_By_Player -- Has this object been disovered by the given player *
  6086. * *
  6087. * INPUT: Player pointer *
  6088. * *
  6089. * OUTPUT: True if discovered by that player *
  6090. * *
  6091. * WARNINGS: none *
  6092. * *
  6093. * HISTORY: *
  6094. * 3/6/2019 11:20AM - ST *
  6095. *=============================================================================================*/
  6096. bool TechnoClass::Is_Discovered_By_Player(HouseClass *player) const
  6097. {
  6098. if (player && player->Class) {
  6099. int shift = (int) player->Class->House;
  6100. return (IsDiscoveredByPlayerMask & (1 << shift)) ? true : false;
  6101. } else {
  6102. int shift = (int) PlayerPtr->Class->House;
  6103. return (IsDiscoveredByPlayerMask & (1 << shift)) ? true : false;
  6104. }
  6105. return false;
  6106. }
  6107. /***********************************************************************************************
  6108. * TechnoClass::Set_Discovered_By_Player -- Mark that this object been disovered by the player *
  6109. * *
  6110. * INPUT: Player pointer *
  6111. * *
  6112. * OUTPUT: *
  6113. * *
  6114. * WARNINGS: none *
  6115. * *
  6116. * HISTORY: *
  6117. * 3/6/2019 11:23AM - ST *
  6118. *=============================================================================================*/
  6119. void TechnoClass::Set_Discovered_By_Player(HouseClass *player)
  6120. {
  6121. int shift = 0;
  6122. if (player && player->Class) {
  6123. shift = (int) player->Class->House;
  6124. } else {
  6125. shift = (int)PlayerPtr->Class->House;
  6126. }
  6127. IsDiscoveredByPlayerMask |= (1 << shift);
  6128. if (Session.Type == GAME_NORMAL && player == PlayerPtr) {
  6129. IsDiscoveredByPlayer = true;
  6130. }
  6131. }
  6132. /***********************************************************************************************
  6133. * TechnoClass::Clear_Discovered_By_Players -- Clear player discovery flags *
  6134. * *
  6135. * INPUT: Player pointer *
  6136. * *
  6137. * OUTPUT: *
  6138. * *
  6139. * WARNINGS: none *
  6140. * *
  6141. * HISTORY: *
  6142. * 4/27/2020 - SKY *
  6143. *=============================================================================================*/
  6144. void TechnoClass::Clear_Discovered_By_Players()
  6145. {
  6146. IsDiscoveredByPlayerMask = 0;
  6147. IsDiscoveredByPlayer = false;
  6148. }
  6149. /***********************************************************************************************
  6150. * TechnoClass::Is_Owned_By_Player -- Is this object owned by the active human player *
  6151. * *
  6152. * INPUT: Player pointer *
  6153. * *
  6154. * OUTPUT: *
  6155. * *
  6156. * WARNINGS: none *
  6157. * *
  6158. * HISTORY: *
  6159. * 3/13/2019 5:00PM - ST *
  6160. *=============================================================================================*/
  6161. bool TechnoClass::Is_Owned_By_Player(HouseClass *player) const
  6162. {
  6163. if (player == NULL) {
  6164. return (PlayerPtr == House) ? true : false;
  6165. }
  6166. return (player == House) ? true : false;
  6167. }
  6168. /***********************************************************************************************
  6169. * TechnoClass::Spied_By -- Spied by flags for this object *
  6170. * *
  6171. * INPUT: Player pointer *
  6172. * *
  6173. * OUTPUT: *
  6174. * *
  6175. * WARNINGS: none *
  6176. * *
  6177. * HISTORY: *
  6178. * 10/31/2019 - SKY *
  6179. *=============================================================================================*/
  6180. unsigned TechnoClass::Spied_By() const
  6181. {
  6182. return SpiedBy;
  6183. }