mech.cpp 306 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239
  1. //***************************************************************************
  2. //
  3. // mech.cpp - This file contains the BattleMech Class header
  4. //
  5. // MechCommander 2
  6. //
  7. //---------------------------------------------------------------------------//
  8. // Copyright (C) Microsoft Corporation. All rights reserved. //
  9. //===========================================================================//
  10. #ifndef MCLIB_H
  11. #include "mclib.h"
  12. #endif
  13. #ifndef GAMEOBJ_H
  14. #include "gameobj.h"
  15. #endif
  16. #ifndef MECH_H
  17. #include "mech.h"
  18. #endif
  19. #ifndef GVEHICL_H
  20. #include "gvehicl.h"
  21. #endif
  22. #ifndef MISSION_H
  23. #include "mission.h"
  24. #endif
  25. #ifndef CMPONENT_H
  26. #include "cmponent.h"
  27. #endif
  28. #ifndef WARRIOR_H
  29. #include "warrior.h"
  30. #endif
  31. #ifndef WEAPONBOLT_H
  32. #include "weaponbolt.h"
  33. #endif
  34. #ifdef USE_DEBRIS
  35. #ifndef DEBRIS_H
  36. #include "debris.h"
  37. #endif
  38. #endif
  39. #ifdef USE_JETS
  40. #ifndef JET_H
  41. #include <jet.h>
  42. #endif
  43. #endif
  44. #ifndef TACORDR_H
  45. #include "tacordr.h"
  46. #endif
  47. #ifndef GAMESOUND_H
  48. #include "gamesound.h"
  49. #endif
  50. #ifndef SOUNDS_H
  51. #include "sounds.h"
  52. #endif
  53. #ifndef COLLSN_H
  54. #include "collsn.h"
  55. #endif
  56. #ifndef WEAPONFX_H
  57. #include "weaponfx.h"
  58. #endif
  59. #ifndef OBJMGR_H
  60. #include "objmgr.h"
  61. #endif
  62. #ifndef MULTPLYR_H
  63. #include "multplyr.h"
  64. #endif
  65. #ifdef OBJTYPE_H
  66. #include "objtype.h"
  67. #endif
  68. #ifndef TEAM_H
  69. #include "team.h"
  70. #endif
  71. #ifndef MECH3D_H
  72. #include "mech3d.h"
  73. #endif
  74. #ifndef GROUP_H
  75. #include "group.h"
  76. #endif
  77. #ifndef UNITDESG_H
  78. #include "unitdesg.h"
  79. #endif
  80. #ifdef USE_ELEMENTALS
  81. #ifndef ELEMNTL_H
  82. #include <elemntl.h>
  83. #endif
  84. #endif
  85. #ifndef CONTACT_H
  86. #include "contact.h"
  87. #endif
  88. #ifndef TURRET_h
  89. #include "turret.h"
  90. #endif
  91. #ifndef GAMEOLOG_H
  92. #include "gamelog.h"
  93. #endif
  94. #ifndef COMNDR_H
  95. #include "comndr.h"
  96. #endif
  97. #ifndef LOGISTICSDATA_H
  98. #include "LogisticsData.h"
  99. #endif
  100. #include "..\resource.h"
  101. //--------
  102. // DEFINES
  103. #define GOALMAP_DIM 21
  104. #define BLIP_FRAME_RATE 0.067
  105. //--------
  106. // GLOBALS
  107. extern float MaxVisualRadius;
  108. //--------
  109. // EXTERNS
  110. extern unsigned long NextIdNumber;
  111. extern float MetersPerCell;
  112. extern long AttitudeEffectOnMovePath[NUM_ATTITUDES][3];
  113. extern bool useSound;
  114. extern bool friendlyDestroyed;
  115. extern bool enemyDestroyed;
  116. extern TeamPtr homeTeam;
  117. extern long MechSalvageChance;
  118. extern long woundFatigue[5];
  119. extern float FireOddsTable[NUM_FIREODDS];
  120. extern float MovementUpdateFrequency;
  121. extern float CombatUpdateFrequency;
  122. extern float CommandUpdateFrequency;
  123. extern float ContactUpdateFrequency;
  124. extern float OrderRequestFrequency;
  125. extern float elmDamageOnImpact;
  126. extern bool drawTerrainGrid;
  127. extern unsigned char footPrints;
  128. extern float MaxTimeRevealed;
  129. extern GameLog* CombatLog;
  130. extern float MineDamage;
  131. extern float MineSplashDamage;
  132. extern float MineSplashRange;
  133. extern long MineExplosion;
  134. extern float SkillTry[4];
  135. extern float SkillSuccess[4];
  136. extern void addMoverToList (long blockNum);
  137. extern char mechSpeedStateArray[28];
  138. extern long TargetRolo;
  139. extern float MapCellDiagonal;
  140. extern GlobalMapPtr GlobalMoveMap[3];
  141. extern bool CantTouchThis;
  142. extern WeaponFireChunk CurMoverWeaponFireChunk;
  143. extern void DebugWeaponFireChunk (WeaponFireChunkPtr chunk1, WeaponFireChunkPtr chunk2, GameObjectPtr attacker);
  144. extern long StatusChunkUnpackErr;
  145. extern float worldUnitsPerMeter;
  146. float ContactFadeTime = 2.0f;
  147. bool invulnerableON = false;
  148. //**********************************************************************************
  149. long NumLocationCriticalSpaces[NUM_BODY_LOCATIONS] = {
  150. NUM_CRITICAL_SPACES_HEAD,
  151. NUM_CRITICAL_SPACES_CTORSO,
  152. NUM_CRITICAL_SPACES_LTORSO,
  153. NUM_CRITICAL_SPACES_RTORSO,
  154. NUM_CRITICAL_SPACES_LARM,
  155. NUM_CRITICAL_SPACES_RARM,
  156. NUM_CRITICAL_SPACES_LLEG,
  157. NUM_CRITICAL_SPACES_RLEG
  158. };
  159. long MechHitSectionTable[NUM_ATTACKSOURCES] = {
  160. MECH_HIT_SECTION_MIDDLE, // Weapon Fire
  161. MECH_HIT_SECTION_MIDDLE, // Collision
  162. MECH_HIT_SECTION_TOP, // Death From Above
  163. MECH_HIT_SECTION_BOTTOM, // Mine
  164. MECH_HIT_SECTION_MIDDLE // Artillery
  165. };
  166. #define numHotSpots 7
  167. #define DRAW_EVERY_TIME 1
  168. #define DRAW_ONCE -1
  169. #define DRAW_NEVER 0
  170. #define MECH_BASE_ROTATIONS 9
  171. #define MECH_BASE_ANGLE float(40)
  172. #define MECH_MAGIC_ALIAS_CONVERSION_FACTOR float(20.0)
  173. #define NUM_FEET 2
  174. #define OTHER_POSITIONS 7
  175. #define MAX_FRAMES 60
  176. #define GestureGoalFallenBackward 8
  177. #ifdef USEHEAT
  178. HeatEffectEntryPtr HeatEffectTable = NULL;
  179. long NumHeatLevels = 0;
  180. #endif
  181. #define NUM_DAMAGE_SPOTS 3
  182. #define MECH_FOOTPRINT_BASE_ANGLE 22.5
  183. //=================
  184. // DEBUG HACK!!!!!
  185. extern GameObjectPtr mech1;
  186. extern GameObjectPtr mech2;
  187. //=================
  188. //OLD One... In case someone changes their mind. I know that never happens!!
  189. /*
  190. float tonnageTurnRate[110] =
  191. {
  192. 360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f, //0 through 9 tons
  193. 360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f, //10 through 19 tons
  194. 360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f, //20 through 29 tons
  195. 360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f,360.0f, //30 through 39 tons
  196. 270.0f,270.0f,270.0f,270.0f,270.0f,270.0f,270.0f,270.0f,270.0f,270.0f, //40 through 49 tons
  197. 240.0f,240.0f,240.0f,240.0f,240.0f,240.0f,240.0f,240.0f,240.0f,240.0f, //50 through 59 tons
  198. 210.0f,210.0f,210.0f,210.0f,210.0f,210.0f,210.0f,210.0f,210.0f,210.0f, //60 through 69 tons
  199. 140.0f,140.0f,140.0f,140.0f,140.0f,140.0f,140.0f,140.0f,140.0f,140.0f, //70 through 79 tons
  200. 120.0f,120.0f,120.0f,120.0f,120.0f,120.0f,120.0f,120.0f,120.0f,120.0f, //80 through 89 tons
  201. 90.0f, 90.0f, 90.0f, 90.0f, 90.0f, 90.0f, 90.0f, 90.0f, 90.0f, 90.0f, //90 through 99 tons
  202. 90.0f, 90.0f, 90.0f, 90.0f, 90.0f, 90.0f, 90.0f, 90.0f, 90.0f, 90.0f //100 through 109 tons
  203. };
  204. */
  205. float tonnageTurnRate[110] =
  206. {
  207. 720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f, //0 through 9 tons
  208. 720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f, //10 through 19 tons
  209. 720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f, //20 through 29 tons
  210. 720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f, //30 through 39 tons
  211. 720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f, //40 through 49 tons
  212. 720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f, //50 through 59 tons
  213. 720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f, //60 through 69 tons
  214. 720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f, //70 through 79 tons
  215. 720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f, //80 through 89 tons
  216. 720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f, //90 through 99 tons
  217. 720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f,720.0f //100 through 109 tons
  218. };
  219. long stupidNewSageColumns[8] =
  220. {
  221. 2,7,5,6,3,4,8,9
  222. };
  223. #define ARMOR_POINTS_PER_NEWARMOR 32.0f
  224. #define ARMOR_HEAD_PERCENT 0.0f
  225. #define ARMOR_CTORSO_PERCENT 0.17f
  226. #define ARMOR_RTORSO_PERCENT 0.125f
  227. #define ARMOR_LTORSO_PERCENT 0.125f
  228. #define ARMOR_LARM_PERCENT 0.12f
  229. #define ARMOR_RARM_PERCENT 0.12f
  230. #define ARMOR_LLEG_PERCENT 0.13f
  231. #define ARMOR_RLEG_PERCENT 0.13f
  232. #define ARMOR_RCTORSO_PERCENT 0.03f
  233. #define ARMOR_RLTORSO_PERCENT 0.02f
  234. #define ARMOR_RRTORSO_PERCENT 0.02f
  235. //---------------------------------------------------------------------------
  236. // Game System Tweakable Data
  237. //---------------------------------------------------------------------------
  238. extern float PilotingCheckFactor;
  239. extern long hitLevel[2];
  240. extern long PilotCheckModifierTable[2];
  241. extern long ClusterSizeSRM;
  242. extern long ClusterSizeLRM;
  243. extern long AntiMissileSystemStats[2][2];
  244. extern float PilotCheckHalfRate;
  245. extern float WeaponRange[NUM_FIRERANGES];
  246. extern float WeaponRanges[NUM_WEAPON_RANGE_TYPES][2];
  247. extern float DisableAttackModifier;
  248. extern float DisableGunneryModifier;
  249. extern float SalvageAttackModifier;
  250. long adjClippedCell[8][2] = {
  251. {0, 0},
  252. {0, 2},
  253. {2, 2},
  254. {2, 4},
  255. {4, 4},
  256. {4, 6},
  257. {6, 6},
  258. {6, 0}
  259. };
  260. float MechClassScale[NUM_MECH_CLASSES] = {
  261. 0.0,
  262. 15.0,
  263. 40.0,
  264. 75.0,
  265. 200.0
  266. };
  267. float RankVersusChassisCombatModifier[NUM_WARRIOR_RANKS][NUM_MECH_CLASSES] = {
  268. {0.0, 0.0, -5.0, -15.0, -25.0},
  269. {0.0, 5.0, 0.0, -5.0, -15.0},
  270. {0.0, 10.0, 5.0, 0.0, -5.0},
  271. {0.0, 15.0, 10.0, 5.0, 0.0}
  272. };
  273. float WeaponFireJumpTime = 3.0;
  274. extern float WeaponFireModifiers[NUM_WEAPONFIRE_MODIFIERS];
  275. long AttackerMoveModifier[NUM_MECH_STATES] = {
  276. 0, // Parked
  277. 0, // Standing
  278. 10, // Walking
  279. 20, // Running
  280. 10, // Reverse
  281. 5, // Limping
  282. 30, // Jumping
  283. 0, // Fallen Forward
  284. 0 // Fallen Backward
  285. };
  286. char CriticalHitTable[4] = {
  287. 58, // 0 Hits
  288. 83, // 1 Hits
  289. 97, // 2 Hits
  290. 100 // Head\Limb Destroyed or 3 Hits if Torso
  291. };
  292. long TargetMoveModifierTable [5][2] = {
  293. {6, 0},
  294. {12, 1},
  295. {18, 2},
  296. {27, 3},
  297. {999, 4}
  298. };
  299. float MechClassWeights[NUM_MECH_CLASSES] =
  300. {
  301. 0.0,
  302. 35.0,
  303. 55.0,
  304. 75.0,
  305. 100.0
  306. };
  307. #ifdef USEHEAT
  308. float HeatCheckFrequency = 10.0;
  309. float StandUpHeat = 15.0;
  310. float BodyStateHeat[NUM_MECH_STATES] = {
  311. 0.0, // Parked
  312. 0.0, // Standing
  313. 0.15, // Walking
  314. 0.3, // Running
  315. 0.15, // Reverse
  316. 0.1, // Limping
  317. 0.75, // Jumping
  318. 0.0, // Fallen Forward
  319. 0.0 // Fallen Backward
  320. };
  321. #endif
  322. char MechHitLocationTable[NUM_MECH_HIT_SECTIONS * NUM_MECH_HIT_ARCS * NUM_MECH_ARMOR_LOCATIONS] = {
  323. 30, 20, 25, 25, 0, 0, 0, 0, 0, 0, 0, // Top Front
  324. 30, 0, 0, 0, 0, 0, 0, 0, 20, 25, 25, // Top Rear
  325. 20, 15, 25, 0, 0, 0, 0, 0, 15, 25, 0, // Top Left
  326. 20, 15, 0, 25, 0, 0, 0, 0, 15, 0, 25, // Top Right
  327. 0, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, // Middle Front
  328. 0, 0, 0, 0, 20, 20, 0, 0, 20, 20, 20, // Middle Rear
  329. 0, 0, 25, 0, 50, 0, 0, 0, 0, 25, 0, // Middle Left
  330. 0, 0, 0, 25, 0, 50, 0, 0, 0, 0, 25, // Middle Right
  331. 0, 10, 0, 0, 0, 0, 45, 45, 0, 0, 0, // Bottom Front
  332. 0, 0, 0, 0, 0, 0, 45, 45, 10, 0, 0, // Bottom Rear
  333. 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, // Bottom Left
  334. 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0 // Bottom Right
  335. };
  336. char MechTransferHitTable[NUM_MECH_BODY_LOCATIONS] = {
  337. MECH_BODY_LOCATION_CTORSO,
  338. -1,
  339. MECH_BODY_LOCATION_CTORSO,
  340. MECH_BODY_LOCATION_CTORSO,
  341. MECH_BODY_LOCATION_LTORSO,
  342. MECH_BODY_LOCATION_RTORSO,
  343. MECH_BODY_LOCATION_LTORSO,
  344. MECH_BODY_LOCATION_RTORSO
  345. };
  346. char MechArmorToBodyLocation[NUM_MECH_ARMOR_LOCATIONS] = {
  347. MECH_BODY_LOCATION_HEAD,
  348. MECH_BODY_LOCATION_CTORSO,
  349. MECH_BODY_LOCATION_LTORSO,
  350. MECH_BODY_LOCATION_RTORSO,
  351. MECH_BODY_LOCATION_LARM,
  352. MECH_BODY_LOCATION_RARM,
  353. MECH_BODY_LOCATION_LLEG,
  354. MECH_BODY_LOCATION_RLEG,
  355. MECH_BODY_LOCATION_CTORSO,
  356. MECH_BODY_LOCATION_LTORSO,
  357. MECH_BODY_LOCATION_RTORSO,
  358. };
  359. long MechPilotCheckConditions[2] = {
  360. 25,
  361. 25
  362. };
  363. long MechPilotCheckTerrainEffect[64] = {
  364. 0, 0, 0, 0, 0, 0, 0, 0,
  365. 0, 0, 0, 0, 0, 0, 0, 0,
  366. 0, 0, 0, 0, 0, 0, 0, 0,
  367. 0, 0, 0, 0, 0, 0, 0, 0,
  368. 0, 0, 0, 0, 0, 0, 0, 0,
  369. 0, 0, 0, 0, 0, 0, 0, 0,
  370. 0, 0, 0, 0, 0, 0, 0, 0,
  371. 0, 0, 0, 0, 0, 0, 0, 0
  372. };
  373. #ifdef USEHEAT
  374. long HeatInjuryTable[2][2] = {
  375. {15, 1},
  376. {26, 2}
  377. };
  378. float heatSinkEfficiency = 1.0;
  379. long heatShutdown = 30;
  380. #endif
  381. extern long AimedFireAbort;
  382. extern long AimedFireHitTable[3];
  383. float mechCollisionThreshold = 0.0;
  384. float objectCollisionThreshold = 0.0;
  385. float tonnageCollisionThreshold = 0.0;
  386. float treeDeflection = 0.0;
  387. float mechPivotAngle = 0.0;
  388. float mechPivotThrottle = 0.0;
  389. float MaxVelocityMag = 0.0;
  390. float NewRotation = 0.0;
  391. long DefaultMechCrashAvoidSelf = 1;
  392. long DefaultMechCrashAvoidPath = 1;
  393. long DefaultMechCrashBlockSelf = 1;
  394. long DefaultMechCrashBlockPath = 1;
  395. float DefaultMechCrashYieldTime = 2.0;
  396. long DefaultMechJumpCost = COST_BLOCKED / 3;
  397. GameObjectPtr BadGuy = NULL;
  398. extern DebuggerPtr debugger;
  399. //#define USE_MECHDEBUGFILE
  400. #ifdef USE_MECHDEBUGFILE
  401. UserFile* MechDebugFile = NULL;
  402. #endif
  403. extern bool ShowMovers;
  404. extern void LogWeaponFireChunk (WeaponFireChunkPtr chunk, GameObjectPtr attacker, GameObjectPtr target);
  405. //**********************************************************************************
  406. // BATTLEMECH TYPE class
  407. //**********************************************************************************
  408. long BattleMech::loadGameSystem (FitIniFilePtr mechFile) {
  409. long result = 0;
  410. result = mechFile->seekBlock("Mech:Class");
  411. if (result != NO_ERR)
  412. return(result);
  413. result = mechFile->readIdFloat("MaxLightMech",MechClassWeights[MECH_CLASS_LIGHT]);
  414. if (result != NO_ERR)
  415. return(result);
  416. result = mechFile->readIdFloat("MaxHeavyMech",MechClassWeights[MECH_CLASS_MEDIUM]);
  417. if (result != NO_ERR)
  418. return(result);
  419. result = mechFile->readIdFloat("MaxHeavyMech",MechClassWeights[MECH_CLASS_HEAVY]);
  420. if (result != NO_ERR)
  421. return(result);
  422. result = mechFile->seekBlock("Mech:Movement");
  423. if (result != NO_ERR)
  424. return(result);
  425. long jumpCost = 0;
  426. result = mechFile->readIdLong("JumpCost", jumpCost);
  427. if (result == NO_ERR)
  428. DefaultMechJumpCost = jumpCost;
  429. long crashSize = 0;
  430. result = mechFile->readIdLong("CrashAvoidSelf", crashSize);
  431. if (result == NO_ERR)
  432. DefaultMechCrashAvoidSelf = crashSize;
  433. result = mechFile->readIdLong("CrashAvoidPath", crashSize);
  434. if (result == NO_ERR)
  435. DefaultMechCrashAvoidPath = crashSize;
  436. result = mechFile->readIdLong("CrashBlockSelf", crashSize);
  437. if (result == NO_ERR)
  438. DefaultMechCrashBlockSelf = crashSize;
  439. result = mechFile->readIdLong("CrashBlockPath", crashSize);
  440. if (result == NO_ERR)
  441. DefaultMechCrashBlockPath = crashSize;
  442. float crashYield = 0.0;
  443. result = mechFile->readIdFloat("CrashYieldTime", crashYield);
  444. if (result == NO_ERR)
  445. DefaultMechCrashYieldTime = crashYield;
  446. result = mechFile->readIdLongArray("PilotCheckConditions", MechPilotCheckConditions, NUM_MECH_PILOT_CHECK_CONDITIONS);
  447. if (result != NO_ERR)
  448. return(result);
  449. result = mechFile->readIdLongArray("PilotCheckTerrainEffect", MechPilotCheckTerrainEffect, 64);
  450. if (result != NO_ERR)
  451. return(result);
  452. result = mechFile->seekBlock("Mech:FireWeapon");
  453. if (result != NO_ERR)
  454. return(result);
  455. result = mechFile->readIdLongArray("AttackerMoveModifier", AttackerMoveModifier, NUM_MECH_STATES);
  456. if (result != NO_ERR)
  457. return(result);
  458. result = mechFile->readIdCharArray("HitLocationTable", MechHitLocationTable, NUM_MECH_HIT_SECTIONS * NUM_MECH_HIT_ARCS * NUM_MECH_ARMOR_LOCATIONS);
  459. if (result != NO_ERR)
  460. return(result);
  461. long longData[5 * 2];
  462. result = mechFile->readIdLongArray("TargetMoveModifierTable", longData, 5 * 2);
  463. if (result != NO_ERR)
  464. return(result);
  465. for (long i = 0; i < 5; i++)
  466. {
  467. TargetMoveModifierTable[i][0] = longData[2 * i];
  468. TargetMoveModifierTable[i][1] = longData[2 * i + 1];
  469. }
  470. result = mechFile->seekBlock("Mech:Damage");
  471. if (result != NO_ERR)
  472. return(result);
  473. result = mechFile->readIdCharArray("CriticalHitTable", CriticalHitTable, 4);
  474. if (result != NO_ERR)
  475. return(result);
  476. result = mechFile->readIdCharArray("MechTransferHitTable", MechTransferHitTable, NUM_BODY_LOCATIONS);
  477. if (result != NO_ERR)
  478. return(result);
  479. result = mechFile->readIdLong("MechSalvageChance", MechSalvageChance);
  480. if (result != NO_ERR)
  481. return(result);
  482. result = mechFile->seekBlock("Mech:Collision");
  483. if (result != NO_ERR)
  484. return(result);
  485. result = mechFile->readIdFloat("collisionThreshold", mechCollisionThreshold);
  486. if (result != NO_ERR)
  487. return(result);
  488. result = mechFile->readIdFloat("objectThreshold", objectCollisionThreshold);
  489. if (result != NO_ERR)
  490. return(result);
  491. result = mechFile->readIdFloat("tonnageThreshold", tonnageCollisionThreshold);
  492. if (result != NO_ERR)
  493. return(result);
  494. result = mechFile->readIdFloat("treeDeflection", treeDeflection);
  495. if (result != NO_ERR)
  496. return(result);
  497. result = mechFile->readIdFloat("pivotAngle", mechPivotAngle);
  498. if (result != NO_ERR)
  499. return(result);
  500. result = mechFile->readIdFloat("pivotThrottle", mechPivotThrottle);
  501. if (result != NO_ERR)
  502. return(result);
  503. return(NO_ERR);
  504. }
  505. //---------------------------------------------------------------------------
  506. void BattleMechType::init (void) {
  507. objectTypeClass = BATTLEMECH_TYPE;
  508. objectClass = BATTLEMECH;
  509. anim = NULL;
  510. rightArmDebrisId = -1;
  511. leftArmDebrisId = -1;
  512. destroyedDebrisId = -1;
  513. crashAvoidSelf = DefaultMechCrashAvoidSelf;
  514. crashAvoidPath = DefaultMechCrashAvoidPath;
  515. crashBlockSelf = DefaultMechCrashBlockSelf;
  516. crashBlockPath = DefaultMechCrashBlockPath;
  517. crashYieldTime = DefaultMechCrashYieldTime;
  518. moveType = MOVETYPE_GROUND;
  519. explDmg = 0.0;
  520. explRad = 0.0;
  521. LOSFactor = 1.0f;
  522. destructDamage = 0.0f;
  523. }
  524. //--------------------------------------------------------------------------
  525. long BattleMechType::init (FilePtr objFile, unsigned long fileSize)
  526. {
  527. long result = 0;
  528. FitIniFile mechFile;
  529. result = mechFile.open(objFile,fileSize);
  530. if (result != NO_ERR)
  531. return(result);
  532. result = mechFile.seekBlock("MechProfile");
  533. if (result != NO_ERR)
  534. return(result);
  535. char fileType[512];
  536. result = mechFile.readIdString ("ProfileName", fileType, 511);
  537. if (result != NO_ERR)
  538. return(result);
  539. result = mechFile.readIdLong("MoveType", moveType);
  540. if (result != NO_ERR)
  541. moveType = MOVETYPE_GROUND;
  542. result = mechFile.readIdFloat("LOSFactor",LOSFactor);
  543. if (result != NO_ERR)
  544. LOSFactor = 1.0f;
  545. result = mechFile.readIdFloat("DestructDamage",destructDamage);
  546. if (result != NO_ERR)
  547. destructDamage = 20.0f;
  548. result = mechFile.readIdFloat("ExplosionDamage",explDmg);
  549. if (result != NO_ERR)
  550. explDmg = 10.0f;
  551. result = mechFile.readIdFloat("ExplosionRadius",explRad);
  552. if (result != NO_ERR)
  553. explRad = 25.0f;
  554. //--------------------------------------------------------------
  555. // New from here on down. Now gets data from Mech CSV file.
  556. FullPathFileName mechCSVName;
  557. mechCSVName.init(objectPath,fileType,".csv");
  558. CSVFile mechCSVFile;
  559. result = mechCSVFile.open(mechCSVName);
  560. if (result != NO_ERR)
  561. return result;
  562. //----------------------------------------------------
  563. // No splash damage until designers say they need it.
  564. //explRad = 0.0;
  565. //explDmg = 0.0;
  566. //------------------------------------------------------------------
  567. // Now, read in the max internal structure for each body location...
  568. // Reader reads rows from 1 just like spreadsheet.
  569. // Row 4, Cols 2,4,6,8,10,12,14,16
  570. for (long curLocation = 0; curLocation < NUM_BODY_LOCATIONS; curLocation++)
  571. {
  572. result = mechCSVFile.readUChar(17,stupidNewSageColumns[curLocation],maxInternalStructure[curLocation]);
  573. if (result != NO_ERR)
  574. return(result);
  575. }
  576. //-----------------------------------------------------------
  577. // No more debris.
  578. rightArmDebrisId = leftArmDebrisId = destroyedDebrisId = -1;
  579. //Assume Mech Dynamics
  580. dynamics.setType(DYNAMICS_MECH);
  581. dynamics.init(&mechCSVFile);
  582. //------------------------------------------------------------------
  583. // Initialize the base object Type from the current file.
  584. result = ObjectType::init(&mechFile);
  585. return(result);
  586. }
  587. //-----------------------------------------------------------------------------------
  588. void BattleMechType::destroy (void)
  589. {
  590. ObjectType::destroy();
  591. }
  592. //----------------------------------------------------------------------------------
  593. bool BattleMechType::handleCollision (GameObjectPtr collidee, GameObjectPtr collider) {
  594. //---------------------------------------------
  595. // The default reaction of any object in the world
  596. // is to simply explode. This just returns true
  597. // to facilitate this behaviour.
  598. //
  599. // Don't blow us up unless we hit another mech.
  600. if (MPlayer && !MPlayer->isServer())
  601. return(false);
  602. bool sameTeam = false;
  603. bool collide = true;
  604. bool collideeJumping = ((BattleMechPtr)collidee)->isJumping();
  605. bool colliderJumping = false;
  606. BattleMechPtr mech = (BattleMechPtr)collidee;
  607. switch (collider->getObjectClass())
  608. {
  609. case TRAINCAR:
  610. {
  611. if ((collidee->getCollisionFreeFromWID() != collider->getWatchID()) || (collidee->getCollisionFreeTime() < scenarioTime))
  612. collide = true;
  613. else
  614. collide = false;
  615. if (collide)
  616. {
  617. //----------------------------------------------------------------------
  618. // Don't allow collision between these two again for a period of time...
  619. collidee->setCollisionFreeFromWID(collider->getWatchID());
  620. collidee->setCollisionFreeTime(scenarioTime + 2.0);
  621. //------------------------------------
  622. // Adjust my velocity and direction...
  623. //collidee->setVelocity(collider->getVelocity());
  624. /*
  625. frame_of_ref workFrame = collidee->getFrame();
  626. float turnAround = 90.0;
  627. workFrame.rotate_about_k(turnAround);
  628. collidee->setFrame(workFrame);
  629. */
  630. collidee->rotate(90.0);
  631. //--------------------------------------------------------------------------
  632. // Check to be sure at least one is moving. If not, move them apart!!!
  633. // They must be moved at least extentRadius1 + extentRadius2 apart!!
  634. /*
  635. vector_3d collideeVel = collidee->getVelocity();
  636. float collideeSpeed = collideeVel.magnitude();
  637. if (collideeSpeed <= mechCollisionThreshold)
  638. {
  639. float extentRadius1 = collider->getObjectType()->getExtentRadius();
  640. extentRadius1 += extentRadius;
  641. //------------------------------
  642. // Find vector to move collidee
  643. vector_3d cPosition = collidee->getPosition();
  644. vector_3d direction = cPosition - collider->getPosition();
  645. direction.normalize();
  646. direction *= extentRadius1;
  647. cPosition += direction;
  648. collidee->setPosition(cPosition);
  649. }
  650. */
  651. ((MoverPtr)collidee)->bounceToAdjCell();
  652. //---------------------------------------------
  653. // Train will take care of administering damage from this collision...
  654. soundSystem->playDigitalSample(MECH_COLLIDE,collidee->getPosition());
  655. return(false);
  656. }
  657. }
  658. break;
  659. case BATTLEMECH:
  660. if (collidee->getTeam() != collider->getTeam())
  661. {
  662. if (((MoverPtr)collider)->getPilot()->getCurTacOrder()->code == TACTICAL_ORDER_ATTACK_OBJECT)
  663. ((MoverPtr)collider)->getPilot()->numPhysicalAttacks[PHYSICAL_ATTACK_RAM][COMBAT_STAT_MISSION]++;
  664. else if (((MoverPtr)collider)->getPilot()->getCurTacOrder()->code == TACTICAL_ORDER_JUMPTO_POINT)
  665. {
  666. if (mech->getPilot()->getCurTacOrder()->getJumpTarget() == collidee)
  667. mech->getPilot()->numPhysicalAttacks[PHYSICAL_ATTACK_DFA][COMBAT_STAT_MISSION]++;
  668. }
  669. }
  670. colliderJumping = ((BattleMechPtr)collider)->isJumping();
  671. if (!colliderJumping && (((BattleMechPtr)collider)->lastJumpTime >= 0.0)) {
  672. float timeSinceLanding = scenarioTime - ((BattleMechPtr)collider)->lastJumpTime;
  673. //((BattleMechPtr)collider)->lastJumpTime = -1.0;
  674. colliderJumping = (timeSinceLanding < 0.5);
  675. }
  676. case GROUNDVEHICLE:
  677. {
  678. //--------------------------
  679. // Was a jump involved here?
  680. if (!collideeJumping && (((BattleMechPtr)collidee)->lastJumpTime >= 0.0)) {
  681. float timeSinceLanding = scenarioTime - ((BattleMechPtr)collidee)->lastJumpTime;
  682. ((BattleMechPtr)collidee)->lastJumpTime = -1.0;
  683. collideeJumping = (timeSinceLanding < 0.5);
  684. }
  685. bool jumpCollision = (collideeJumping || colliderJumping);
  686. //-----------------------------------------------------------------------
  687. // Typically, same-alignment movers don't collide unless a DFA or RAM was
  688. // involved...
  689. if (collidee->isFriendly(collider))
  690. sameTeam = true;
  691. if (sameTeam)
  692. collide = jumpCollision;
  693. else if (jumpCollision)
  694. collide = true;
  695. else {
  696. GameObjectPtr collideeRamTarget = ((MoverPtr)collidee)->getPilot()->getCurTacOrder()->getRamTarget();
  697. GameObjectPtr colliderRamTarget = ((MoverPtr)collider)->getPilot()->getCurTacOrder()->getRamTarget();
  698. collide = ((collideeRamTarget == collider) || (colliderRamTarget == collidee));
  699. }
  700. if (collide)
  701. collide = ((collidee->getCollisionFreeFromWID() != collider->getWatchID()) || (collidee->getCollisionFreeTime() < scenarioTime));
  702. if (collide) {
  703. //----------------------------------------------------------------------
  704. // Don't allow collision between these two again for a period of time...
  705. collidee->setCollisionFreeFromWID(collider->getWatchID());
  706. collidee->setCollisionFreeTime(scenarioTime + 2.0);
  707. collidee->rotate(90.0);
  708. //--------------------------------------------------------------------------
  709. // Check to be sure at least one is moving. If not, move them apart!!!
  710. // They must be moved at least extentRadius1 + extentRadius2 apart!!
  711. /*
  712. vector_3d collideeVel = collidee->getVelocity();
  713. float collideeSpeed = collideeVel.magnitude();
  714. if (collideeSpeed <= mechCollisionThreshold)
  715. {
  716. float extentRadius1 = collider->getObjectType()->getExtentRadius();
  717. extentRadius1 += extentRadius;
  718. //------------------------------
  719. // Find vector to move collidee
  720. vector_3d cPosition = collidee->getPosition();
  721. vector_3d direction = cPosition - collider->getPosition();
  722. direction.normalize();
  723. direction *= extentRadius1;
  724. cPosition += direction;
  725. collidee->setPosition(cPosition);
  726. }
  727. */
  728. //---------------------------------------------
  729. // Administer the damage from this collision...
  730. if (jumpCollision)
  731. {
  732. //-----------------------------------------------------------
  733. // Since we reset the jumping mech's lastJumpTime right here,
  734. // we should apply the damage to the collider here, as well.
  735. // If both are jumping...well then, double damage is taken!
  736. if (collideeJumping && !sameTeam)
  737. {
  738. WeaponShotInfo shotInfo;
  739. //-----------------------
  740. // First, the collidee...
  741. // I jumped on the below, therefore, my legs should be preferentially damaged!!!
  742. long hitLocation = collidee->calcHitLocation(collider, -1, ATTACKSOURCE_MINE, 0);
  743. if (sameTeam)
  744. shotInfo.init(collider->getWatchID(), -1, collider->getTonnage() / 100.0 + 0.5, hitLocation, collidee->relFacingTo(collider->getPosition()));
  745. else
  746. shotInfo.init(collider->getWatchID(), -1, collider->getTonnage() / 10.0 + 0.5, hitLocation, collidee->relFacingTo(collider->getPosition()));
  747. collidee->handleWeaponHit(&shotInfo, (MPlayer != NULL));
  748. //----------------------
  749. // Next, the collider...
  750. hitLocation = collider->calcHitLocation(collidee, -1, ATTACKSOURCE_DFA, 0);
  751. if (sameTeam)
  752. shotInfo.init(collidee->getWatchID(), -1, collider->getTonnage() / 100.0 + 0.5, hitLocation, collider->relFacingTo(collidee->getPosition()));
  753. else
  754. shotInfo.init(collidee->getWatchID(), -1, collider->getTonnage() / 10.0 + 0.5, hitLocation, collider->relFacingTo(collidee->getPosition()));
  755. collider->handleWeaponHit(&shotInfo, (MPlayer != NULL));
  756. Stuff::Vector3D tmpPosition = collider->getPosition();
  757. ObjectManager->createExplosion(DFA_BOOM_EFFECT, NULL, tmpPosition);
  758. }
  759. }
  760. else
  761. {
  762. if (!sameTeam)
  763. {
  764. long hitLocation = collidee->calcHitLocation(collider, -1, ATTACKSOURCE_COLLISION, 0);
  765. WeaponShotInfo shotInfo;
  766. shotInfo.init(collider->getWatchID(), -1, collider->getTonnage() / 10.0 + 0.5, hitLocation, collidee->relFacingTo(collider->getPosition()));
  767. collidee->handleWeaponHit(&shotInfo, (MPlayer != NULL));
  768. collidee->handleWeaponHit(&shotInfo, (MPlayer != NULL));
  769. }
  770. }
  771. long bounceDir = ((MoverPtr)collidee)->bounceToAdjCell();
  772. if (jumpCollision && (bounceDir == -1)) {
  773. //----------------------
  774. // Nowhere to bounce to!
  775. }
  776. //---------------------------------------------
  777. if (!sameTeam && (collidee->getWindowsVisible() == turn))
  778. soundSystem->playDigitalSample(MECH_COLLIDE,collidee->getPosition());
  779. return(false);
  780. }
  781. }
  782. break;
  783. case BUILDING:
  784. case TREEBUILDING:
  785. {
  786. //Should Never collide with Buildings. Only Steppables which ARE not this king of building!!
  787. }
  788. break;
  789. case TREE:
  790. case TERRAINOBJECT:
  791. {
  792. if ((collidee->getCollisionFreeFromWID() != collider->getWatchID()) || (collidee->getCollisionFreeTime() < scenarioTime))
  793. {
  794. //----------------------------------------------------------------------
  795. // Don't allow collision between these two again for a period of time...
  796. collidee->setCollisionFreeFromWID(collider->getWatchID());
  797. collidee->setCollisionFreeTime(scenarioTime + 2.0);
  798. //------------------------------------
  799. // Adjust my velocity and direction...
  800. //collidee->setVelocity(collider->getVelocity());
  801. float turnAround = 0.0;
  802. float tonnageClass = collidee->getTonnage();
  803. if (tonnageClass < tonnageCollisionThreshold)
  804. turnAround = (tonnageCollisionThreshold / tonnageClass) * treeDeflection;
  805. if (turnAround > 0.0)
  806. collidee->rotate(turnAround);
  807. //---------------------------------------------
  808. if (collidee->getWindowsVisible() == turn)
  809. soundSystem->playDigitalSample(MECH_COLLIDE,collidee->getPosition());
  810. return(false);
  811. }
  812. }
  813. break;
  814. }
  815. return(false);
  816. }
  817. //-----------------------------------------------------------------------------------
  818. bool BattleMechType::handleDestruction (GameObjectPtr collidee, GameObjectPtr collider)
  819. {
  820. //-------------------------------------------------------------------
  821. // BUG ALERT!!!!!!!!!
  822. //-------------------------------------------------------------------
  823. // This could get called multiple times for a mech before it's
  824. // truly destroyed (if multiple weapon hits are taken in an update).
  825. // This should be prevented by checking if the mech is already
  826. // destroyed. BUT, for fear that this could break something this late
  827. // in the game (4/4/98), it would be best to address the symptoms
  828. // for now (e.g. # of kills in handleTargetKilled). After release
  829. // (or demo), fix this and seriously test it doesn't "break"
  830. // anything!!!!!!!!!!! Should also be fixed for other objects'
  831. // handleDestruction().
  832. //-------------------------------------------------------------------
  833. //-------------------------------------------------------
  834. // For now, a BattleMech will play a default explosion
  835. // and disappear after the explosion is half way through
  836. BattleMechPtr mech = (BattleMechPtr)collidee;
  837. if (!mech->getPilot())
  838. Fatal(0, " No Pilot in this mech! ");
  839. //--------------------------------------------------------
  840. // Let's let the unit know we're dying if we're a point...
  841. if (mech->getPoint() == mech) {
  842. mech->getGroup()->setPoint(NULL);
  843. //--------------------------------------------------------
  844. // If there is no new point, all units must be blown away.
  845. // How do we want to handle this?
  846. }
  847. //-----------------------------
  848. // Immediately lose contacts...
  849. if (mech->sensorSystem)
  850. mech->sensorSystem->disable();
  851. if (mech->withdrawing) {
  852. mech->timeLeft = 0.8f;
  853. //-----------------------------------------------
  854. // Let the pilot know we are about to withdraw...
  855. mech->getPilot()->handleAlarm(PILOT_ALARM_VEHICLE_WITHDRAWN, 0);
  856. }
  857. else {
  858. if (!mech->startDisabled)
  859. mech->timeLeft = 0.8f;
  860. //------------------------------------------
  861. // Let the pilot know we are about to die...
  862. mech->getPilot()->handleAlarm(PILOT_ALARM_VEHICLE_DESTROYED, collider ? collider->getWatchID() : 0);
  863. //ONLY the server may DESTROY a mech. All other clients must await the statusChunk!!
  864. if (!MPlayer || (MPlayer && MPlayer->isServer()))
  865. mech->setStatus(OBJECT_STATUS_DESTROYED);
  866. mech->fallen = false;
  867. mech->exploding = false;
  868. for (long i=0;i<mech->numBodyLocations;i++) //Blow all of the components. NO SALVAGE!!
  869. mech->destroyBodyLocation(i);
  870. #ifdef USE_MOODMUSIC
  871. //------------------------------------
  872. // What heroic music should be played?
  873. if (collidee->getAlignment() == Team::home->getAlignment())
  874. friendlyDestroyed = true;
  875. else
  876. enemyDestroyed = true;
  877. #endif
  878. if (CombatLog) {
  879. char s[1024];
  880. sprintf(s, "[%.2f] mech.destroyed HD: [%05d]%s", scenarioTime, mech->getPartId(), mech->getName());
  881. CombatLog->write(s);
  882. CombatLog->write(" ");
  883. }
  884. }
  885. return(true);
  886. }
  887. //----------------------------------------------------------------------------------
  888. GameObjectPtr BattleMechType::createInstance (void) {
  889. BattleMechPtr newMech = new BattleMech;
  890. if (!newMech)
  891. return(NULL);
  892. newMech->init(true, this);
  893. //newMech->setIdNumber(NextIdNumber++);
  894. return newMech;
  895. }
  896. //**********************************************************************************
  897. // BATTLEMECH class
  898. //**********************************************************************************
  899. void BattleMech::operator = (BattleMech copy) {
  900. }
  901. //----------------------------------------------------------------------------------
  902. void BattleMech::handleStaticCollision (void) {
  903. bool endOfJump = false;
  904. if (getTangible() || endOfJump)
  905. {
  906. //-----------------------------------------------------
  907. // What is our block and vertex number?
  908. long blockNumber = 0;
  909. long vertexNumber = 0;
  910. getBlockAndVertexNumber(blockNumber,vertexNumber);
  911. long numCollidables = ObjectManager->getObjBlockNumCollidables(blockNumber);
  912. long terrainObjHandle = ObjectManager->getObjBlockFirstHandle(blockNumber);
  913. long colliderBlockNumber = -1;
  914. long colliderVertexNumber = -1;
  915. for (long i = 0; i < numCollidables; i++)
  916. {
  917. GameObjectPtr terrainObj = ObjectManager->get(terrainObjHandle + i);
  918. bool isTangible = false;
  919. switch (terrainObj->getObjectClass())
  920. {
  921. case TREE:
  922. case TREEBUILDING:
  923. case TERRAINOBJECT:
  924. case BUILDING:
  925. terrainObj->getBlockAndVertexNumber(colliderBlockNumber, colliderVertexNumber);
  926. isTangible = terrainObj->getTangible();
  927. break;
  928. case CAMERADRONE:
  929. case MINE:
  930. break;
  931. }
  932. if (isTangible)
  933. ObjectManager->detectStaticCollision(this, terrainObj);
  934. }
  935. }
  936. }
  937. //---------------------------------------------------------------------------
  938. void BattleMech::init (bool create) {
  939. //Mover::init(create);
  940. objectClass = BATTLEMECH;
  941. overlayWeightClass = OVERLAY_WEIGHT_MECH;
  942. cBills = 0;
  943. playedHeloDestruct = false;
  944. numBodyLocations = NUM_MECH_BODY_LOCATIONS;
  945. for (long i = 0; i < numBodyLocations; i++) {
  946. body[i].CASE = false;
  947. body[i].totalSpaces = 0;
  948. body[i].curInternalStructure = 0.0;
  949. body[i].hotSpotNumber = 0;
  950. body[i].maxInternalStructure = 0;
  951. body[i].damageState = IS_DAMAGE_NONE;
  952. }
  953. numArmorLocations = NUM_MECH_ARMOR_LOCATIONS;
  954. #ifdef USEHEAT
  955. heatDissipation = 0.0;
  956. heatCheckTime = 0.0;
  957. #endif
  958. chassisClass = MECH_CLASS_LIGHT;
  959. chassisBR = 0;
  960. damageThisFrame = 0.0f;
  961. numArmorComponents = 0;
  962. playedCriticalHit = false;
  963. legStatus = LEG_STATUS_NORMAL;
  964. torsoStatus = TORSO_STATUS_NORMAL;
  965. sentCrippledMsg = false;
  966. for (i = 0; i < NUM_ACTUATORS; i++)
  967. actuator[i] = 255;
  968. gyro = 255;
  969. numJumpJets = 0;
  970. lastJumpTime = -100.0;
  971. inJump = false;
  972. jumpGoal.Zero();
  973. centerTorsoBlowTime = -1.0;
  974. hitFromBehindThisFrame = false;
  975. hitFromFrontThisFrame = false;
  976. leftArmBlownThisFrame = false;
  977. rightArmBlownThisFrame = false;
  978. torsoRotation = 0;
  979. leftArmRotation = 0;
  980. rightArmRotation = 0;
  981. fallen = false;
  982. mechRemoved = false;
  983. pivotTurnRate = 0.0;
  984. #ifdef USE_JETS
  985. jumpJets[0] = NULL;
  986. jumpJets[1] = NULL;
  987. #endif
  988. maxWeaponDamage = 0.0;
  989. longName[0] = NULL;
  990. pilotNum = 0;
  991. captureable = false;
  992. notMineYet = true;
  993. descID = -1;
  994. // variant = 0;
  995. exploding = false;
  996. blipFrame = 0;
  997. drawFlags = 0;
  998. lowestWeaponNodeID = -2;
  999. damageAfterDisabled = 0.0f;
  1000. for (long l = 0; l < 6; l++)
  1001. rotateValues[l] = 0;
  1002. #ifdef USE_MECHDEBUGFILE
  1003. if (!MechDebugFile) {
  1004. MechDebugFile = UserFile::getNewFile();
  1005. if (!MechDebugFile)
  1006. Fatal(0, " Couldn't create Mech Debug File ");
  1007. long err = MechDebugFile->open("mech.dbg");
  1008. if (err)
  1009. Fatal(0, " Couldn't open Mech Debug File ");
  1010. MechDebugFile->write("Name Target Turn Rot RelFacing torsoRot newRot torsoRelFacing turnRate");
  1011. }
  1012. #endif
  1013. }
  1014. //----------------------------------------------------------------------------------
  1015. void BattleMech::clear (void) {
  1016. }
  1017. //----------------------------------------------------------------------------------
  1018. void BattleMech::init (bool create, ObjectTypePtr _type) {
  1019. // Call down the chain to init everybody else.
  1020. GameObject::init(create, _type);
  1021. creationTime = scenarioTime;
  1022. //-------------------------------------------------------------
  1023. // In here will reside the code which initializes all of the
  1024. // variables for a battleMech based upon the type.
  1025. // For starters, these are tangible objects
  1026. setTangible(true);
  1027. //-------------------------------------------------
  1028. // Set some mech traits based upon the Mech Type...
  1029. BattleMechTypePtr mechT = (BattleMechTypePtr)_type;
  1030. for (long curLocation = 0; curLocation < NUM_BODY_LOCATIONS; curLocation++)
  1031. body[curLocation].maxInternalStructure = mechT->maxInternalStructure[curLocation];
  1032. crashAvoidSelf = mechT->crashAvoidSelf;
  1033. crashAvoidPath = mechT->crashAvoidPath;
  1034. crashBlockSelf = mechT->crashBlockSelf;
  1035. crashBlockPath = mechT->crashBlockPath;
  1036. crashYieldTime = mechT->crashYieldTime;
  1037. setMoveType(mechT->moveType);
  1038. control.init();
  1039. dynamics = ((BattleMechTypePtr)_type)->dynamics;
  1040. //-------------------------------------------------------------
  1041. // The appearance is initialized here using data from the type
  1042. char *appearanceName = _type->getAppearanceTypeName();
  1043. //--------------------------------------------------------------
  1044. // New code!!!
  1045. // We need to append the sprite type to the appearance num now.
  1046. // The MechEdit tool does not assume a sprite type, nor should it.
  1047. // MechCmdr2 features much simpler objects which only use 1 type of sprite!
  1048. long appearanceType = (MECH_TYPE << 24);
  1049. AppearanceTypePtr mechAppearanceType = appearanceTypeList->getAppearance(appearanceType,appearanceName);
  1050. if (!mechAppearanceType)
  1051. {
  1052. //------------------------------------------------
  1053. // This mech probably is not done. Use the MADCAT
  1054. mechAppearanceType = appearanceTypeList->getAppearance(appearanceType,"MADCAT");
  1055. }
  1056. //------------------------------------------------------------
  1057. // Ultimately, try to re-use rather then keep re-allocating...
  1058. if (appearance)
  1059. delete appearance;
  1060. appearance = new Mech3DAppearance;
  1061. gosASSERT(appearance != NULL);
  1062. //--------------------------------------------------------------
  1063. // The only kind of appearanceType the mechs currently know how
  1064. // to work with is a spriteTree. Anything else is wrong.
  1065. appearance->init((Mech3DAppearanceTypePtr)mechAppearanceType, this);
  1066. appearance->initFX();
  1067. appearance->setAlphaValue(alphaValue);
  1068. objectClass = BATTLEMECH;
  1069. setObscured(true);
  1070. markDistanceMoved = 1000.0;
  1071. }
  1072. //----------------------------------------------------------------------------------
  1073. float BattleMech::getStatusRating (void) {
  1074. //-------------------------------
  1075. // calculate Weapon effectiveness
  1076. float weaponEffect = (float)weaponEffectiveness / (float)maxWeaponEffectiveness;
  1077. //----------------
  1078. // Calculate armor
  1079. float armorHead = armor[MECH_ARMOR_LOCATION_HEAD].curArmor / armor[MECH_ARMOR_LOCATION_HEAD].maxArmor * 0.6 + 0.4;
  1080. float armorCTorso = armor[MECH_ARMOR_LOCATION_CTORSO].curArmor / armor[MECH_ARMOR_LOCATION_CTORSO].maxArmor * 0.5 + 0.5;
  1081. if (armor[MECH_ARMOR_LOCATION_CTORSO].curArmor > armor[MECH_ARMOR_LOCATION_RCTORSO].curArmor)
  1082. armorCTorso = armor[MECH_ARMOR_LOCATION_RCTORSO].curArmor / armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor * 0.5 + 0.5;
  1083. float curTorso = armor[MECH_ARMOR_LOCATION_RLTORSO].curArmor +
  1084. armor[MECH_ARMOR_LOCATION_LTORSO].curArmor +
  1085. armor[MECH_ARMOR_LOCATION_RRTORSO].curArmor +
  1086. armor[MECH_ARMOR_LOCATION_RTORSO].curArmor;
  1087. float maxTorso = armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor +
  1088. armor[MECH_ARMOR_LOCATION_LTORSO].maxArmor+
  1089. armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor +
  1090. armor[MECH_ARMOR_LOCATION_RTORSO].maxArmor;
  1091. float armorTorso = curTorso / maxTorso * 0.25 + 0.75;
  1092. float curArm = armor[MECH_ARMOR_LOCATION_LARM].curArmor + armor[MECH_ARMOR_LOCATION_RARM].curArmor;
  1093. float maxArm = armor[MECH_ARMOR_LOCATION_LARM].maxArmor + armor[MECH_ARMOR_LOCATION_RARM].maxArmor;
  1094. float armorArm = curArm / maxArm * 0.25 + 0.75;
  1095. float curLeg = armor[MECH_ARMOR_LOCATION_LLEG].curArmor + armor[MECH_ARMOR_LOCATION_RLEG].curArmor;
  1096. float maxLeg = armor[MECH_ARMOR_LOCATION_LLEG].maxArmor + armor[MECH_ARMOR_LOCATION_RLEG].maxArmor;
  1097. float armorLeg = curLeg / maxLeg * 0.25 + 0.75;
  1098. float armorEffect = armorHead * armorCTorso * armorTorso * armorArm * armorLeg;
  1099. //-----------------------
  1100. // Calculate pilot Wounds
  1101. float pilotWoundTable[7] = {1.00f, 0.95f, 0.85f, 0.75f, 0.50f, 0.30f, 0.00f};
  1102. float pilotEffect = pilotWoundTable[(long)getPilot()->getWounds()];
  1103. if (isDestroyed() || isDisabled())
  1104. pilotEffect = 0.0;
  1105. float rating = weaponEffect * armorEffect * pilotEffect;
  1106. return(rating);
  1107. }
  1108. //----------------------------------------------------------------------------------
  1109. void BattleMech::setControl (ControlType ctrlType) {
  1110. control.init(ctrlType, CONTROL_DATA_MECH);
  1111. }
  1112. //----------------------------------------------------------------------------------
  1113. long BattleMech::init (DWORD variantNum)
  1114. {
  1115. //----------------------------------------------
  1116. // Open the mech's CSV file.
  1117. CSVFile *mechFile = new CSVFile;
  1118. FullPathFileName csvName;
  1119. csvName.init(objectPath,getObjectType()->getAppearanceTypeName(),".csv");
  1120. variantID = variantNum;
  1121. long result = mechFile->open(csvName);
  1122. if (result != NO_ERR)
  1123. {
  1124. delete mechFile;
  1125. mechFile = NULL;
  1126. return result;
  1127. }
  1128. //--------------------------------------------------------------------
  1129. // CSV file open. Variant Num controls offsets to data in the file.
  1130. // Same rules as before, Rows start at one. Columns start at zero.
  1131. char thisMechName[128];
  1132. mechFile->readString(3,2,thisMechName,127);
  1133. strncpy(name, thisMechName, MAXLEN_MOVER_NAME - 1);
  1134. name[MAXLEN_MOVER_NAME] = NULL;
  1135. mechFile->readLong(10,5,chassisBR);
  1136. mechFile->readFloat(3,5,tonnage);
  1137. mechFile->readLong(5,2,descID);
  1138. cLoadString( descID, thisMechName, 127 );
  1139. char tmp[256];
  1140. cLoadString( IDS_MFDMCH_PRINTSTRING, tmp, 256 );
  1141. sprintf( longName, tmp, thisMechName, tonnage );
  1142. mechFile->readLong( 12, 2, iconPictureIndex );
  1143. unsigned char speed;
  1144. mechFile->readUChar(7,5,speed);
  1145. maxMoveSpeed = (float)speed;
  1146. result = mechFile->readString( 23 + ( 97 * variantNum ), 2, variantName, 63 );
  1147. if (result == 1)
  1148. {
  1149. PAUSE(("Variant Number %d does not exist for mech %s. Please set variant in editor!",variantNum,csvName));
  1150. variantNum = 0;
  1151. variantID = 0;
  1152. result = mechFile->readString( 23 + ( 97 * variantNum ), 2, variantName, 63 );
  1153. if (result == 1)
  1154. STOP(("Can't even find Variant 0 for mech %s",csvName));
  1155. }
  1156. status = 0;
  1157. mechFile->readUChar(18,2,armor[MECH_ARMOR_LOCATION_HEAD].maxArmor);
  1158. mechFile->readUChar(18,7,armor[MECH_ARMOR_LOCATION_CTORSO].maxArmor);
  1159. mechFile->readUChar(18,5,armor[MECH_ARMOR_LOCATION_LTORSO].maxArmor);
  1160. mechFile->readUChar(18,6,armor[MECH_ARMOR_LOCATION_RTORSO].maxArmor);
  1161. mechFile->readUChar(18,3,armor[MECH_ARMOR_LOCATION_LARM].maxArmor);
  1162. mechFile->readUChar(18,4,armor[MECH_ARMOR_LOCATION_RARM].maxArmor);
  1163. mechFile->readUChar(18,8,armor[MECH_ARMOR_LOCATION_LLEG].maxArmor);
  1164. mechFile->readUChar(18,9,armor[MECH_ARMOR_LOCATION_RLEG].maxArmor);
  1165. mechFile->readUChar(18,12,armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor);
  1166. mechFile->readUChar(18,10,armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor);
  1167. mechFile->readUChar(18,11,armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor);
  1168. unsigned char currentArmor;
  1169. mechFile->readUChar(115 + (97 * variantNum),2,currentArmor);
  1170. armor[MECH_ARMOR_LOCATION_HEAD].curArmor = currentArmor;
  1171. mechFile->readUChar(115 + (97 * variantNum),7,currentArmor);
  1172. armor[MECH_ARMOR_LOCATION_CTORSO].curArmor = currentArmor;
  1173. mechFile->readUChar(115 + (97 * variantNum),5,currentArmor);
  1174. armor[MECH_ARMOR_LOCATION_LTORSO].curArmor = currentArmor;
  1175. mechFile->readUChar(115 + (97 * variantNum),6,currentArmor);
  1176. armor[MECH_ARMOR_LOCATION_RTORSO].curArmor = currentArmor;
  1177. mechFile->readUChar(115 + (97 * variantNum),3,currentArmor);
  1178. armor[MECH_ARMOR_LOCATION_LARM].curArmor = currentArmor;
  1179. mechFile->readUChar(115 + (97 * variantNum),4,currentArmor);
  1180. armor[MECH_ARMOR_LOCATION_RARM].curArmor = currentArmor;
  1181. mechFile->readUChar(115 + (97 * variantNum),8,currentArmor);
  1182. armor[MECH_ARMOR_LOCATION_LLEG].curArmor = currentArmor;
  1183. mechFile->readUChar(115 + (97 * variantNum),9,currentArmor);
  1184. armor[MECH_ARMOR_LOCATION_RLEG].curArmor = currentArmor;
  1185. mechFile->readUChar(115 + (97 * variantNum),12,currentArmor);
  1186. armor[MECH_ARMOR_LOCATION_RCTORSO].curArmor = currentArmor;
  1187. mechFile->readUChar(115 + (97 * variantNum),10,currentArmor);
  1188. armor[MECH_ARMOR_LOCATION_RLTORSO].curArmor = currentArmor;
  1189. mechFile->readUChar(115 + (97 * variantNum),11,currentArmor);
  1190. armor[MECH_ARMOR_LOCATION_RRTORSO].curArmor = currentArmor;
  1191. //---------------------------------------------------------------------------
  1192. // Build the mech's inventory (all components, and where they are located)...
  1193. // Check through all 30 possible. Create the numOther, numWeapons and numAmmo from that.
  1194. // Sanity check what the designers have input.
  1195. numAntiMissileSystems = numOther = numWeapons = numAmmos = 0;
  1196. numArmorComponents = 0;
  1197. //-----------------------------------------------------
  1198. // Read in the mech's non-weapon/non-ammo components...
  1199. long realItemNum = 0;
  1200. memset(ItemLocationToInvLocation,0xff,sizeof(long)*MAX_MOVER_INVENTORY_ITEMS);
  1201. //Read in everything but weapons and AMMO
  1202. for (long curItem = 0;curItem < MAX_MOVER_INVENTORY_ITEMS;curItem++)
  1203. {
  1204. mechFile->readUChar((26 + (97 * variantNum)) + curItem, 5, inventory[realItemNum].masterID);
  1205. if (inventory[realItemNum].masterID && (inventory[realItemNum].masterID != 255))
  1206. {
  1207. //---------------------------------------------------------------
  1208. // If the component is a JumpJet, increment our jump jet count...
  1209. switch (MasterComponent::masterList[inventory[realItemNum].masterID].getForm())
  1210. {
  1211. case COMPONENT_FORM_JUMPJET:
  1212. numJumpJets = 5;
  1213. case COMPONENT_FORM_COCKPIT:
  1214. case COMPONENT_FORM_SENSOR:
  1215. case COMPONENT_FORM_LIFESUPPORT:
  1216. case COMPONENT_FORM_GYROSCOPE:
  1217. case COMPONENT_FORM_POWER_AMPLIFIER:
  1218. case COMPONENT_FORM_ECM:
  1219. case COMPONENT_FORM_PROBE:
  1220. case COMPONENT_FORM_JAMMER:
  1221. case COMPONENT_FORM_CASE:
  1222. case COMPONENT_FORM_ACTUATOR:
  1223. case COMPONENT_FORM_ENGINE:
  1224. case COMPONENT_FORM_HEATSINK:
  1225. numOther++;
  1226. inventory[realItemNum].health = MasterComponent::masterList[inventory[realItemNum].masterID].getHealth();
  1227. inventory[realItemNum].disabled = false;
  1228. inventory[realItemNum].amount = 1;
  1229. inventory[realItemNum].ammoIndex = -1;
  1230. inventory[realItemNum].readyTime = 0.0;
  1231. inventory[realItemNum].bodyLocation = 255;
  1232. ItemLocationToInvLocation[curItem] = realItemNum;
  1233. realItemNum++;
  1234. break;
  1235. case COMPONENT_FORM_BULK: //Special case now.
  1236. //This is an armor component.
  1237. //DO NOT store with other components
  1238. //It becomes a free hit then!!
  1239. numArmorComponents++;
  1240. break;
  1241. case COMPONENT_FORM_WEAPON:
  1242. case COMPONENT_FORM_WEAPON_ENERGY:
  1243. case COMPONENT_FORM_WEAPON_BALLISTIC:
  1244. case COMPONENT_FORM_WEAPON_MISSILE:
  1245. //Ignore weapons until second pass
  1246. break;
  1247. case COMPONENT_FORM_AMMO:
  1248. //Ignore AMMO until third pass
  1249. break;
  1250. }
  1251. }
  1252. }
  1253. //NOW read in the weapons.
  1254. for (curItem = 0;curItem < MAX_MOVER_INVENTORY_ITEMS;curItem++)
  1255. {
  1256. mechFile->readUChar((26 + (97 * variantNum)) + curItem, 5, inventory[realItemNum].masterID);
  1257. if (inventory[realItemNum].masterID && (inventory[realItemNum].masterID != 255))
  1258. {
  1259. //---------------------------------------------------------------
  1260. // If the component is a JumpJet, increment our jump jet count...
  1261. long sourceWeaponType;
  1262. if (MasterComponent::masterList[inventory[realItemNum].masterID].getForm() == COMPONENT_FORM_WEAPON_MISSILE)
  1263. sourceWeaponType = MECH3D_WEAPONTYPE_MISSILE;
  1264. else if (MasterComponent::masterList[inventory[realItemNum].masterID].getForm() == COMPONENT_FORM_WEAPON_BALLISTIC)
  1265. sourceWeaponType = MECH3D_WEAPONTYPE_BALLISTIC;
  1266. else if (MasterComponent::masterList[inventory[realItemNum].masterID].getForm() == COMPONENT_FORM_WEAPON_ENERGY)
  1267. sourceWeaponType = MECH3D_WEAPONTYPE_ENERGY;
  1268. else
  1269. sourceWeaponType = MECH3D_WEAPONTYPE_ANY;
  1270. switch (MasterComponent::masterList[inventory[realItemNum].masterID].getForm())
  1271. {
  1272. case COMPONENT_FORM_JUMPJET:
  1273. case COMPONENT_FORM_COCKPIT:
  1274. case COMPONENT_FORM_SENSOR:
  1275. case COMPONENT_FORM_LIFESUPPORT:
  1276. case COMPONENT_FORM_GYROSCOPE:
  1277. case COMPONENT_FORM_POWER_AMPLIFIER:
  1278. case COMPONENT_FORM_ECM:
  1279. case COMPONENT_FORM_PROBE:
  1280. case COMPONENT_FORM_JAMMER:
  1281. case COMPONENT_FORM_BULK:
  1282. case COMPONENT_FORM_CASE:
  1283. case COMPONENT_FORM_ACTUATOR:
  1284. case COMPONENT_FORM_ENGINE:
  1285. case COMPONENT_FORM_HEATSINK:
  1286. //We did these Above here.
  1287. break;
  1288. case COMPONENT_FORM_WEAPON:
  1289. case COMPONENT_FORM_WEAPON_ENERGY:
  1290. case COMPONENT_FORM_WEAPON_BALLISTIC:
  1291. case COMPONENT_FORM_WEAPON_MISSILE:
  1292. numWeapons++;
  1293. inventory[realItemNum].health = MasterComponent::masterList[inventory[realItemNum].masterID].getHealth();
  1294. inventory[realItemNum].disabled = false;
  1295. inventory[realItemNum].amount = 1;
  1296. inventory[realItemNum].ammoIndex = -1;
  1297. inventory[realItemNum].facing = appearance->getWeaponNode(sourceWeaponType);
  1298. inventory[realItemNum].readyTime = 0.0;
  1299. inventory[realItemNum].bodyLocation = 255;
  1300. inventory[realItemNum].effectiveness = (short)(MasterComponent::masterList[inventory[realItemNum].masterID].getWeaponDamage() * 10.0 / // damage over 10 seconds
  1301. MasterComponent::masterList[inventory[realItemNum].masterID].getWeaponRecycleTime());
  1302. inventory[realItemNum].effectiveness *= WeaponRanges[MasterComponent::masterList[inventory[realItemNum].masterID].getWeaponRange()][1] / 24;
  1303. ItemLocationToInvLocation[curItem] = realItemNum;
  1304. realItemNum++;
  1305. //-------------------------------------
  1306. // Cache in the weapon special effect.
  1307. break;
  1308. case COMPONENT_FORM_AMMO:
  1309. //Do these next.
  1310. break;
  1311. }
  1312. }
  1313. }
  1314. //NOW read in the AMMO
  1315. for (curItem = 0;curItem < MAX_MOVER_INVENTORY_ITEMS;curItem++)
  1316. {
  1317. mechFile->readUChar((26 + (97 * variantNum)) + curItem, 5, inventory[realItemNum].masterID);
  1318. if (inventory[realItemNum].masterID && (inventory[realItemNum].masterID != 255))
  1319. {
  1320. //---------------------------------------------------------------
  1321. // If the component is a JumpJet, increment our jump jet count...
  1322. switch (MasterComponent::masterList[inventory[realItemNum].masterID].getForm())
  1323. {
  1324. case COMPONENT_FORM_JUMPJET:
  1325. case COMPONENT_FORM_COCKPIT:
  1326. case COMPONENT_FORM_SENSOR:
  1327. case COMPONENT_FORM_LIFESUPPORT:
  1328. case COMPONENT_FORM_GYROSCOPE:
  1329. case COMPONENT_FORM_POWER_AMPLIFIER:
  1330. case COMPONENT_FORM_ECM:
  1331. case COMPONENT_FORM_PROBE:
  1332. case COMPONENT_FORM_JAMMER:
  1333. case COMPONENT_FORM_BULK:
  1334. case COMPONENT_FORM_CASE:
  1335. case COMPONENT_FORM_ACTUATOR:
  1336. case COMPONENT_FORM_ENGINE:
  1337. case COMPONENT_FORM_HEATSINK:
  1338. //Did these above.
  1339. break;
  1340. case COMPONENT_FORM_WEAPON:
  1341. case COMPONENT_FORM_WEAPON_ENERGY:
  1342. case COMPONENT_FORM_WEAPON_BALLISTIC:
  1343. case COMPONENT_FORM_WEAPON_MISSILE:
  1344. //Did These Above, too...
  1345. break;
  1346. case COMPONENT_FORM_AMMO:
  1347. numAmmos++;
  1348. inventory[realItemNum].health = MasterComponent::masterList[inventory[realItemNum].masterID].getHealth();
  1349. inventory[realItemNum].disabled = false;
  1350. inventory[realItemNum].amount = 1;
  1351. inventory[realItemNum].ammoIndex = -1;
  1352. inventory[realItemNum].readyTime = 0.0;
  1353. inventory[realItemNum].bodyLocation = 255;
  1354. //-----------------------------------------------------------------------
  1355. // Since the ammo amount in the profile is amount per ton, let's make the
  1356. // amount equal to the number of missiles/bullets/whatever. If it's set
  1357. // to 255, use the default amount per ton as defined in the component
  1358. // table...
  1359. //
  1360. // Ammo per ton is always fully stocked. I.e. always -1 or 255
  1361. inventory[realItemNum].amount = MasterComponent::masterList[inventory[realItemNum].masterID].getAmmoPerTon();
  1362. inventory[realItemNum].ammoIndex = -1;
  1363. inventory[realItemNum].startAmount = inventory[realItemNum].amount;
  1364. inventory[realItemNum].health = MasterComponent::masterList[inventory[realItemNum].masterID].getHealth();
  1365. inventory[realItemNum].disabled = false;
  1366. inventory[realItemNum].readyTime = 0.0;
  1367. inventory[realItemNum].bodyLocation = 255;
  1368. ItemLocationToInvLocation[curItem] = realItemNum;
  1369. realItemNum++;
  1370. break;
  1371. }
  1372. }
  1373. }
  1374. //------------------------------------------------------------
  1375. // Now, read in the component layout for each body location...
  1376. for (long curLocation = 0; curLocation < NUM_MECH_BODY_LOCATIONS; curLocation++)
  1377. {
  1378. body[curLocation].CASE = true; //ALL MC2 Mechs have CASE everywhere.
  1379. unsigned char internalStructure;
  1380. mechFile->readUChar(114 + (97 * variantNum), stupidNewSageColumns[curLocation], internalStructure);
  1381. body[curLocation].curInternalStructure = internalStructure;
  1382. //---------------------------------------------------------
  1383. // Now, determine the damage state for the body location...
  1384. float damageLevel = (float)body[curLocation].curInternalStructure / body[curLocation].maxInternalStructure;
  1385. if (damageLevel <= 0.0)
  1386. body[curLocation].damageState = IS_DAMAGE_DESTROYED;
  1387. else if (damageLevel <= 0.5)
  1388. body[curLocation].damageState = IS_DAMAGE_PARTIAL;
  1389. else
  1390. body[curLocation].damageState = IS_DAMAGE_NONE;
  1391. long numSpaces = NumLocationCriticalSpaces[curLocation];
  1392. body[curLocation].totalSpaces = 0;
  1393. for (long curSpace = 0; curSpace < numSpaces; curSpace++)
  1394. {
  1395. unsigned char spaceData;
  1396. mechFile->readUChar((102 + (97*variantNum))+curSpace,stupidNewSageColumns[curLocation], spaceData);
  1397. spaceData = ItemLocationToInvLocation[spaceData];
  1398. body[curLocation].criticalSpaces[curSpace].inventoryID = spaceData;
  1399. body[curLocation].criticalSpaces[curSpace].hit = false; //Everything always repaired now.
  1400. if (spaceData < 255)
  1401. {
  1402. if (spaceData >= numOther+numWeapons+numAmmos)
  1403. //Just ignore this space. Sage has filled them all in now.
  1404. // ACTUALLY, we should stop here.
  1405. continue;
  1406. inventory[spaceData].bodyLocation = curLocation;
  1407. //--------------------------------------------------------
  1408. // The following line assumes the "new" crit hit system...
  1409. body[curLocation].totalSpaces += MasterComponent::masterList[inventory[spaceData].masterID].getSize();
  1410. //--------------------------------------------------------
  1411. // Preserve critical component indices for quick access...
  1412. switch (MasterComponent::masterList[inventory[spaceData].masterID].getForm())
  1413. {
  1414. case COMPONENT_FORM_COCKPIT:
  1415. cockpit = spaceData;
  1416. break;
  1417. case COMPONENT_FORM_JUMPJET:
  1418. jumpJets = spaceData;
  1419. break;
  1420. case COMPONENT_FORM_SENSOR:
  1421. sensor = spaceData;
  1422. sensorSystem = SensorManager->newSensor();
  1423. sensorSystem->setOwner(this);
  1424. sensorSystem->setRange(MasterComponent::masterList[inventory[sensor].masterID].getSensorRange());
  1425. break;
  1426. case COMPONENT_FORM_HEATSINK:
  1427. inventory[spaceData].bodyLocation = curLocation;
  1428. break;
  1429. case COMPONENT_FORM_AMMO:
  1430. inventory[spaceData].bodyLocation = curLocation;
  1431. break;
  1432. case COMPONENT_FORM_WEAPON:
  1433. case COMPONENT_FORM_WEAPON_ENERGY:
  1434. inventory[spaceData].bodyLocation = curLocation;
  1435. break;
  1436. case COMPONENT_FORM_WEAPON_BALLISTIC:
  1437. inventory[spaceData].bodyLocation = curLocation;
  1438. if ((inventory[spaceData].masterID == MasterComponent::clanAntiMissileSystemID) ||
  1439. (inventory[spaceData].masterID == MasterComponent::innerSphereAntiMissileSystemID))
  1440. {
  1441. //------------------------------------------------------
  1442. // Add to Anti-Missile System list for fast reference...
  1443. if (numAntiMissileSystems == MAX_ANTI_MISSILE_SYSTEMS)
  1444. Fatal(0, "Too many Anti-Missile Systems");
  1445. antiMissileSystem[numAntiMissileSystems++] = spaceData;
  1446. }
  1447. break;
  1448. case COMPONENT_FORM_WEAPON_MISSILE:
  1449. inventory[spaceData].bodyLocation = curLocation;
  1450. break;
  1451. case COMPONENT_FORM_ACTUATOR:
  1452. if (inventory[spaceData].masterID == MasterComponent::armActuatorID)
  1453. {
  1454. if (curLocation == MECH_BODY_LOCATION_LARM)
  1455. actuator[ACTUATOR_LSHOULDER] = spaceData;
  1456. else if (curLocation == MECH_BODY_LOCATION_RARM)
  1457. actuator[ACTUATOR_RSHOULDER] = spaceData;
  1458. }
  1459. else if (inventory[spaceData].masterID == MasterComponent::legActuatorID)
  1460. {
  1461. if (curLocation == MECH_BODY_LOCATION_LLEG)
  1462. actuator[ACTUATOR_LHIP] = spaceData;
  1463. else if (curLocation == MECH_BODY_LOCATION_RLEG)
  1464. actuator[ACTUATOR_RHIP] = spaceData;
  1465. }
  1466. break;
  1467. case COMPONENT_FORM_ENGINE:
  1468. engine = spaceData;
  1469. break;
  1470. case COMPONENT_FORM_LIFESUPPORT:
  1471. lifeSupport = spaceData;
  1472. break;
  1473. case COMPONENT_FORM_GYROSCOPE:
  1474. gyro = spaceData;
  1475. break;
  1476. case COMPONENT_FORM_ECM:
  1477. ecm = spaceData;
  1478. break;
  1479. case COMPONENT_FORM_JAMMER:
  1480. break;
  1481. case COMPONENT_FORM_PROBE:
  1482. probe = spaceData;
  1483. break;
  1484. }
  1485. }
  1486. }
  1487. }
  1488. calcAmmoTotals();
  1489. for (long item = numOther; item < (numOther + numWeapons); item++)
  1490. {
  1491. //----------------------------------------------------------
  1492. // Each weapon should point to its appropriate ammo total in
  1493. // the ammo type total list...
  1494. for (long ammoIndex = 0; ammoIndex < numAmmoTypes; ammoIndex++)
  1495. {
  1496. if ((long)MasterComponent::masterList[inventory[item].masterID].getWeaponAmmoMasterId() == ammoTypeTotal[ammoIndex].masterId)
  1497. {
  1498. inventory[item].ammoIndex = ammoIndex;
  1499. break;
  1500. }
  1501. }
  1502. }
  1503. for (item = numOther+numWeapons;item<(numOther+numWeapons+numAmmos);item++)
  1504. {
  1505. //----------------------------------------------------------
  1506. // Each weapon should point to its appropriate ammo total in
  1507. // the ammo type total list...
  1508. for (long ammoIndex = 0; ammoIndex < numAmmoTypes; ammoIndex++)
  1509. {
  1510. if (inventory[item].masterID == ammoTypeTotal[ammoIndex].masterId)
  1511. {
  1512. inventory[item].ammoIndex = ammoIndex;
  1513. break;
  1514. }
  1515. }
  1516. }
  1517. for (item = 0; item < numOther; item++)
  1518. {
  1519. if ((inventory[item].masterID == MasterComponent::clanAntiMissileSystemID) || (inventory[item].masterID == MasterComponent::innerSphereAntiMissileSystemID))
  1520. {
  1521. for (long ammoIndex = 0; ammoIndex < numAmmoTypes; ammoIndex++) {
  1522. if ((long)MasterComponent::masterList[inventory[item].masterID].getWeaponAmmoMasterId() == ammoTypeTotal[ammoIndex].masterId)
  1523. {
  1524. inventory[item].ammoIndex = ammoIndex;
  1525. break;
  1526. }
  1527. }
  1528. }
  1529. }
  1530. //--------------------------------------------------------------------------
  1531. // If we added BULK to the mech, adjust the max and current armor settings.
  1532. if (numArmorComponents)
  1533. {
  1534. float totalArmorPoints = ARMOR_POINTS_PER_NEWARMOR * numArmorComponents;
  1535. float armorPercent = ARMOR_HEAD_PERCENT * totalArmorPoints;
  1536. armor[MECH_ARMOR_LOCATION_HEAD].maxArmor += armorPercent;
  1537. armor[MECH_ARMOR_LOCATION_HEAD].curArmor = armor[MECH_ARMOR_LOCATION_HEAD].maxArmor;
  1538. armorPercent = ARMOR_CTORSO_PERCENT * totalArmorPoints;
  1539. armor[MECH_ARMOR_LOCATION_CTORSO].maxArmor += armorPercent;
  1540. armor[MECH_ARMOR_LOCATION_CTORSO].curArmor = armor[MECH_ARMOR_LOCATION_CTORSO].maxArmor;
  1541. armorPercent = ARMOR_LTORSO_PERCENT * totalArmorPoints;
  1542. armor[MECH_ARMOR_LOCATION_LTORSO].maxArmor += armorPercent;
  1543. armor[MECH_ARMOR_LOCATION_LTORSO].curArmor = armor[MECH_ARMOR_LOCATION_LTORSO].maxArmor;
  1544. armorPercent = ARMOR_RTORSO_PERCENT * totalArmorPoints;
  1545. armor[MECH_ARMOR_LOCATION_RTORSO].maxArmor += armorPercent;
  1546. armor[MECH_ARMOR_LOCATION_RTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RTORSO].maxArmor;
  1547. armorPercent = ARMOR_LARM_PERCENT * totalArmorPoints;
  1548. armor[MECH_ARMOR_LOCATION_LARM].maxArmor += armorPercent;
  1549. armor[MECH_ARMOR_LOCATION_LARM].curArmor = armor[MECH_ARMOR_LOCATION_LARM].maxArmor;
  1550. armorPercent = ARMOR_RARM_PERCENT * totalArmorPoints;
  1551. armor[MECH_ARMOR_LOCATION_RARM].maxArmor += armorPercent;
  1552. armor[MECH_ARMOR_LOCATION_RARM].curArmor = armor[MECH_ARMOR_LOCATION_RARM].maxArmor;
  1553. armorPercent = ARMOR_LLEG_PERCENT * totalArmorPoints;
  1554. armor[MECH_ARMOR_LOCATION_LLEG].maxArmor += armorPercent;
  1555. armor[MECH_ARMOR_LOCATION_LLEG].curArmor = armor[MECH_ARMOR_LOCATION_LLEG].maxArmor;
  1556. armorPercent = ARMOR_RLEG_PERCENT * totalArmorPoints;
  1557. armor[MECH_ARMOR_LOCATION_RLEG].maxArmor += armorPercent;
  1558. armor[MECH_ARMOR_LOCATION_RLEG].curArmor = armor[MECH_ARMOR_LOCATION_RLEG].maxArmor;
  1559. armorPercent = ARMOR_RCTORSO_PERCENT * totalArmorPoints;
  1560. armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor += armorPercent;
  1561. armor[MECH_ARMOR_LOCATION_RCTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor;
  1562. armorPercent = ARMOR_RLTORSO_PERCENT * totalArmorPoints;
  1563. armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor += armorPercent;
  1564. armor[MECH_ARMOR_LOCATION_RLTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor;
  1565. armorPercent = ARMOR_RRTORSO_PERCENT * totalArmorPoints;
  1566. armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor += armorPercent;
  1567. armor[MECH_ARMOR_LOCATION_RRTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor;
  1568. }
  1569. //---------------------------------------------------------------------------
  1570. // We need to set the status states for legs and torso based upon our current
  1571. // condition...
  1572. calcLegStatus();
  1573. calcTorsoStatus();
  1574. calcFireRanges();
  1575. maxCV = calcCV(true);
  1576. curCV = calcCV(false);
  1577. setThreatRating(-1);
  1578. maxWeaponDamage = calcMaxTargetDamage();
  1579. ObjectTypePtr type = ObjectManager->getObjectType(typeHandle);
  1580. if (type->getExplosionObject() > 0)
  1581. ObjectManager->objTypeManager->load(type->getExplosionObject(), true);
  1582. //-----------------------------
  1583. // Calc mech's chassis class...
  1584. chassisClass = getMechClass();
  1585. // logistics data needs to be initialized if you're going to get values
  1586. LogisticsData::instance->init();
  1587. cBills = 10;
  1588. LogisticsVariant* mechVariant = LogisticsData::instance->getVariant(variantName);
  1589. if (mechVariant)
  1590. cBills = mechVariant->getCost();
  1591. mechFile->close();
  1592. delete mechFile;
  1593. mechFile = NULL;
  1594. return(NO_ERR);
  1595. }
  1596. typedef struct _LogisticsMasterLocationTableEntry
  1597. {
  1598. bool clearOut;
  1599. long bodyLocation;
  1600. long slotNumber; //Starting at zero!
  1601. } LogisticsMasterLocationTableEntry;
  1602. LogisticsMasterLocationTableEntry logisticsTable[MAX_MOVER_INVENTORY_ITEMS] =
  1603. {
  1604. false,MECH_BODY_LOCATION_CTORSO, 0, // 0-Always Fusion Engine
  1605. false,MECH_BODY_LOCATION_CTORSO, 1, // 1-Always Gyroscope
  1606. false,MECH_BODY_LOCATION_LARM, 1, // 2-Always Arm Actuator
  1607. false,MECH_BODY_LOCATION_RARM, 1, // 3-Always Arm Actuator
  1608. false,MECH_BODY_LOCATION_LLEG, 1, // 4-Always Leg Actuator
  1609. false,MECH_BODY_LOCATION_RLEG, 1, // 5-Always Leg Actuator
  1610. false,MECH_BODY_LOCATION_HEAD, 0, // 6-Always COckpit
  1611. false,MECH_BODY_LOCATION_HEAD, 1, // 7-Always Life Support
  1612. false,MECH_BODY_LOCATION_LARM, 0, // 8-Always Shoulder
  1613. false,MECH_BODY_LOCATION_RARM, 0, // 9-Always Shoulder
  1614. false,MECH_BODY_LOCATION_LLEG, 0, //10-Always Hip
  1615. false,MECH_BODY_LOCATION_RLEG, 0, //11-Always Hip
  1616. false,MECH_BODY_LOCATION_HEAD, 2, //12-Sensor -Change back to true to be able to replace these.
  1617. false,MECH_BODY_LOCATION_HEAD, 3, //13-Other Electronic Warfare Component
  1618. false,MECH_BODY_LOCATION_HEAD, 4, //14-Other Electronic Warfare Component
  1619. false,MECH_BODY_LOCATION_HEAD, 5, //15-Other Electronic Warfare Component
  1620. true ,MECH_BODY_LOCATION_LLEG, 3, //16-JumpJet
  1621. false,MECH_BODY_LOCATION_LLEG, 4, //17-Always NOTHING
  1622. false,MECH_BODY_LOCATION_LLEG, 5, //18-Always NOTHING
  1623. false,MECH_BODY_LOCATION_RLEG, 3, //19-Always NOTHING
  1624. false,MECH_BODY_LOCATION_RLEG, 4, //20-Always NOTHING
  1625. false,MECH_BODY_LOCATION_RLEG, 5, //21-Always NOTHING
  1626. true ,MECH_BODY_LOCATION_LARM, 4, //22-Weapon or Ammo - 22
  1627. true ,MECH_BODY_LOCATION_LTORSO, 0, //38-Weapon or Ammo - 23
  1628. true ,MECH_BODY_LOCATION_CTORSO, 2, //62-Weapon or Ammo - 24
  1629. true ,MECH_BODY_LOCATION_RTORSO, 0, //50-Weapon or Ammo - 25
  1630. true ,MECH_BODY_LOCATION_RARM, 4, //30-Weapon or Ammo - 26
  1631. true ,MECH_BODY_LOCATION_LARM, 5, //23-Weapon or Ammo - 27
  1632. true ,MECH_BODY_LOCATION_LTORSO, 1, //39-Weapon or Ammo - 28
  1633. true ,MECH_BODY_LOCATION_CTORSO, 3, //63-Weapon or Ammo - 29
  1634. true ,MECH_BODY_LOCATION_RTORSO, 1, //51-Weapon or Ammo - 30
  1635. true ,MECH_BODY_LOCATION_RARM, 5, //31-Weapon or Ammo - 31
  1636. true ,MECH_BODY_LOCATION_LARM, 6, //24-Weapon or Ammo - 32
  1637. true ,MECH_BODY_LOCATION_LTORSO, 2, //40-Weapon or Ammo - 33
  1638. true ,MECH_BODY_LOCATION_CTORSO, 4, //64-Weapon or Ammo - 34
  1639. true ,MECH_BODY_LOCATION_RTORSO, 2, //52-Weapon or Ammo - 35
  1640. true ,MECH_BODY_LOCATION_RARM, 6, //32-Weapon or Ammo - 36
  1641. true ,MECH_BODY_LOCATION_LARM, 7, //25-Weapon or Ammo - 37
  1642. true ,MECH_BODY_LOCATION_LTORSO, 3, //41-Weapon or Ammo - 38
  1643. true ,MECH_BODY_LOCATION_CTORSO, 5, //65-Weapon or Ammo - 39
  1644. true ,MECH_BODY_LOCATION_RTORSO, 3, //53-Weapon or Ammo - 40
  1645. true ,MECH_BODY_LOCATION_RARM, 7, //33-Weapon or Ammo - 41
  1646. true ,MECH_BODY_LOCATION_LARM, 8, //26-Weapon or Ammo - 42
  1647. true ,MECH_BODY_LOCATION_LTORSO, 4, //42-Weapon or Ammo - 43
  1648. true ,MECH_BODY_LOCATION_CTORSO, 6, //66-Weapon or Ammo - 44
  1649. true ,MECH_BODY_LOCATION_RTORSO, 4, //54-Weapon or Ammo - 45
  1650. true ,MECH_BODY_LOCATION_RARM, 8, //34-Weapon or Ammo - 46
  1651. true ,MECH_BODY_LOCATION_LARM, 9, //27-Weapon or Ammo - 47
  1652. true ,MECH_BODY_LOCATION_LTORSO, 5, //43-Weapon or Ammo - 48
  1653. true ,MECH_BODY_LOCATION_CTORSO, 7, //67-Weapon or Ammo - 49
  1654. true ,MECH_BODY_LOCATION_RTORSO, 5, //55-Weapon or Ammo - 50
  1655. true ,MECH_BODY_LOCATION_RARM, 9, //35-Weapon or Ammo - 51
  1656. true ,MECH_BODY_LOCATION_LARM, 10, //28-Weapon or Ammo- 52
  1657. true ,MECH_BODY_LOCATION_LTORSO, 6, //44-Weapon or Ammo - 53
  1658. true ,MECH_BODY_LOCATION_CTORSO, 8, //68-Weapon or Ammo - 54
  1659. true ,MECH_BODY_LOCATION_RTORSO, 6, //56-Weapon or Ammo - 55
  1660. true ,MECH_BODY_LOCATION_RARM, 10, //36-Weapon or Ammo- 56
  1661. true ,MECH_BODY_LOCATION_LARM, 11, //29-Weapon or Ammo- 57
  1662. true ,MECH_BODY_LOCATION_LTORSO, 7, //45-Weapon or Ammo - 58
  1663. true ,MECH_BODY_LOCATION_CTORSO, 9, //69-Weapon or Ammo - 59
  1664. true ,MECH_BODY_LOCATION_RTORSO, 7, //57-Weapon or Ammo - 60
  1665. true ,MECH_BODY_LOCATION_RARM, 11, //37-Weapon or Ammo- 61
  1666. true ,MECH_BODY_LOCATION_LTORSO, 8, //46-Weapon or Ammo - 62
  1667. true ,MECH_BODY_LOCATION_CTORSO, 10, //70-Weapon or Ammo - 63
  1668. true ,MECH_BODY_LOCATION_RTORSO, 8, //58-Weapon or Ammo - 64
  1669. true ,MECH_BODY_LOCATION_LTORSO, 9, //47-Weapon or Ammo - 65
  1670. true ,MECH_BODY_LOCATION_CTORSO, 11, //71-Weapon or Ammo - 66
  1671. true ,MECH_BODY_LOCATION_RTORSO, 9, //59-Weapon or Ammo - 67
  1672. true ,MECH_BODY_LOCATION_LTORSO, 10, //48-Weapon or Ammo - 68
  1673. true ,MECH_BODY_LOCATION_RTORSO, 10, //60-Weapon or Ammo - 69
  1674. true ,MECH_BODY_LOCATION_LTORSO, 11, //49-Weapon or Ammo - 70
  1675. true ,MECH_BODY_LOCATION_RTORSO, 11 //61-Weapon or Ammo - 71
  1676. };
  1677. #define JUMPJET_SLOT 16
  1678. #define SENSOR_SLOT 12
  1679. #define ELECTRONIC_SLOT 13
  1680. #define WEAPONAMMO_SLOT 17
  1681. //----------------------------------------------------------------------------------
  1682. void BattleMech::resetComponents (long totalComponents, long *componentList)
  1683. {
  1684. //------------------------------------------------------------
  1685. // Create a master component list for this mech.
  1686. // Remove all of the components logistics can replace.
  1687. // Add back in all of the components logistics replaced.
  1688. // Put in the right body locations using the above table.
  1689. long localMasterComponentList[MAX_MOVER_INVENTORY_ITEMS];
  1690. memset(localMasterComponentList,0xff,sizeof(long)*MAX_MOVER_INVENTORY_ITEMS);
  1691. //Copy current itemList to localLists
  1692. //Remove all logistics replacable components
  1693. for (long item = 0;item<MAX_MOVER_INVENTORY_ITEMS;item++)
  1694. {
  1695. localMasterComponentList[item] = inventory[item].masterID;
  1696. if (inventory[item].masterID != 255)
  1697. {
  1698. long ItemLocation = -1;
  1699. for (long i=0;i<MAX_MOVER_INVENTORY_ITEMS;i++)
  1700. {
  1701. if (ItemLocationToInvLocation[i] == item)
  1702. {
  1703. ItemLocation = i;
  1704. break;
  1705. }
  1706. }
  1707. if (ItemLocation == -1)
  1708. STOP(("Could Not Find Item %d on Mech",item));
  1709. if (logisticsTable[ItemLocation].clearOut)
  1710. {
  1711. localMasterComponentList[item] = 0xff;
  1712. }
  1713. }
  1714. }
  1715. //-----------------------------------------------------------------------------
  1716. // Reset the weapon Node Data in the mech Appearance..ˆ.
  1717. appearance->resetWeaponNodes();
  1718. //--------------------------------------------------------------------------
  1719. //If we added Armor to the mech, remove the armor so that player's new armor
  1720. // components are all that is added, adjust the max and current armor settings.
  1721. //
  1722. if (numArmorComponents)
  1723. {
  1724. float totalArmorPoints = ARMOR_POINTS_PER_NEWARMOR * numArmorComponents;
  1725. long armorPercent = ARMOR_HEAD_PERCENT * totalArmorPoints;
  1726. armor[MECH_ARMOR_LOCATION_HEAD].maxArmor -= armorPercent;
  1727. armor[MECH_ARMOR_LOCATION_HEAD].curArmor = armor[MECH_ARMOR_LOCATION_HEAD].maxArmor;
  1728. armorPercent = ARMOR_CTORSO_PERCENT * totalArmorPoints;
  1729. armor[MECH_ARMOR_LOCATION_CTORSO].maxArmor -= armorPercent;
  1730. armor[MECH_ARMOR_LOCATION_CTORSO].curArmor = armor[MECH_ARMOR_LOCATION_CTORSO].maxArmor;
  1731. armorPercent = ARMOR_LTORSO_PERCENT * totalArmorPoints;
  1732. armor[MECH_ARMOR_LOCATION_LTORSO].maxArmor -= armorPercent;
  1733. armor[MECH_ARMOR_LOCATION_LTORSO].curArmor = armor[MECH_ARMOR_LOCATION_LTORSO].maxArmor;
  1734. armorPercent = ARMOR_RTORSO_PERCENT * totalArmorPoints;
  1735. armor[MECH_ARMOR_LOCATION_RTORSO].maxArmor -= armorPercent;
  1736. armor[MECH_ARMOR_LOCATION_RTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RTORSO].maxArmor;
  1737. armorPercent = ARMOR_LARM_PERCENT * totalArmorPoints;
  1738. armor[MECH_ARMOR_LOCATION_LARM].maxArmor -= armorPercent;
  1739. armor[MECH_ARMOR_LOCATION_LARM].curArmor = armor[MECH_ARMOR_LOCATION_LARM].maxArmor;
  1740. armorPercent = ARMOR_RARM_PERCENT * totalArmorPoints;
  1741. armor[MECH_ARMOR_LOCATION_RARM].maxArmor -= armorPercent;
  1742. armor[MECH_ARMOR_LOCATION_RARM].curArmor = armor[MECH_ARMOR_LOCATION_RARM].maxArmor;
  1743. armorPercent = ARMOR_LLEG_PERCENT * totalArmorPoints;
  1744. armor[MECH_ARMOR_LOCATION_LLEG].maxArmor -= armorPercent;
  1745. armor[MECH_ARMOR_LOCATION_LLEG].curArmor = armor[MECH_ARMOR_LOCATION_LLEG].maxArmor;
  1746. armorPercent = ARMOR_RLEG_PERCENT * totalArmorPoints;
  1747. armor[MECH_ARMOR_LOCATION_RLEG].maxArmor -= armorPercent;
  1748. armor[MECH_ARMOR_LOCATION_RLEG].curArmor = armor[MECH_ARMOR_LOCATION_RLEG].maxArmor;
  1749. armorPercent = ARMOR_RCTORSO_PERCENT * totalArmorPoints;
  1750. armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor -= armorPercent;
  1751. armor[MECH_ARMOR_LOCATION_RCTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor;
  1752. armorPercent = ARMOR_RLTORSO_PERCENT * totalArmorPoints;
  1753. armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor -= armorPercent;
  1754. armor[MECH_ARMOR_LOCATION_RLTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor;
  1755. armorPercent = ARMOR_RRTORSO_PERCENT * totalArmorPoints;
  1756. armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor -= armorPercent;
  1757. armor[MECH_ARMOR_LOCATION_RRTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor;
  1758. }
  1759. long numNewArmors = 0;
  1760. numJumpJets = 0;
  1761. long numElectronics = 0;
  1762. long numWeaponsAmmo = 0;
  1763. //Add Heidi's new Components to open locations.
  1764. for (long newItems = 0;newItems < totalComponents;newItems++)
  1765. {
  1766. switch (MasterComponent::masterList[componentList[newItems]].getForm())
  1767. {
  1768. case COMPONENT_FORM_HEATSINK:
  1769. continue;
  1770. break;
  1771. case COMPONENT_FORM_COCKPIT:
  1772. case COMPONENT_FORM_LIFESUPPORT:
  1773. case COMPONENT_FORM_GYROSCOPE:
  1774. case COMPONENT_FORM_POWER_AMPLIFIER:
  1775. case COMPONENT_FORM_CASE:
  1776. case COMPONENT_FORM_ACTUATOR:
  1777. case COMPONENT_FORM_ENGINE:
  1778. //If any of these are in Heidi's list its REALLY BAD
  1779. STOP(("Invalid component added in Logistics %d",componentList[newItems]));
  1780. break;
  1781. case COMPONENT_FORM_SENSOR:
  1782. localMasterComponentList[SENSOR_SLOT] = componentList[newItems];
  1783. break;
  1784. case COMPONENT_FORM_ECM:
  1785. case COMPONENT_FORM_PROBE:
  1786. case COMPONENT_FORM_JAMMER:
  1787. localMasterComponentList[ELECTRONIC_SLOT+numElectronics] = componentList[newItems];
  1788. numElectronics++;
  1789. if (numElectronics > 3)
  1790. STOP(("TOO many electronic warfare components on this mech"));
  1791. break;
  1792. case COMPONENT_FORM_WEAPON:
  1793. case COMPONENT_FORM_WEAPON_ENERGY:
  1794. case COMPONENT_FORM_WEAPON_BALLISTIC:
  1795. case COMPONENT_FORM_WEAPON_MISSILE:
  1796. case COMPONENT_FORM_AMMO:
  1797. localMasterComponentList[WEAPONAMMO_SLOT+numWeaponsAmmo] = componentList[newItems];
  1798. numWeaponsAmmo++;
  1799. //Heidi does not give me ammo. Add manually here.
  1800. if (MasterComponent::masterList[componentList[newItems]].getWeaponAmmoMasterId())
  1801. {
  1802. localMasterComponentList[WEAPONAMMO_SLOT+numWeaponsAmmo] = MasterComponent::masterList[componentList[newItems]].getWeaponAmmoMasterId();
  1803. numWeaponsAmmo++;
  1804. }
  1805. if (numWeaponsAmmo > 54)
  1806. STOP(("TOO many weapons and/or Ammo components on this mech"));
  1807. break;
  1808. case COMPONENT_FORM_BULK:
  1809. numNewArmors++;
  1810. break;
  1811. case COMPONENT_FORM_JUMPJET:
  1812. localMasterComponentList[JUMPJET_SLOT] = componentList[newItems];
  1813. break;
  1814. }
  1815. }
  1816. //Now use the above lists to re-component out the mech!
  1817. numAntiMissileSystems = numOther = numWeapons = numAmmos = 0;
  1818. //-----------------------------------------------------
  1819. // Read in the mech's non-weapon/non-ammo components...
  1820. long realItemNum = 0;
  1821. memset(ItemLocationToInvLocation,0xff,sizeof(long)*MAX_MOVER_INVENTORY_ITEMS);
  1822. //Read in everything but weapons and AMMO
  1823. for (long curItem = 0;curItem < MAX_MOVER_INVENTORY_ITEMS;curItem++)
  1824. {
  1825. inventory[realItemNum].masterID = localMasterComponentList[curItem];
  1826. if (inventory[realItemNum].masterID && (inventory[realItemNum].masterID != 255))
  1827. {
  1828. //---------------------------------------------------------------
  1829. // If the component is a JumpJet, increment our jump jet count...
  1830. switch (MasterComponent::masterList[inventory[realItemNum].masterID].getForm())
  1831. {
  1832. case COMPONENT_FORM_JUMPJET:
  1833. numJumpJets = 5;
  1834. case COMPONENT_FORM_COCKPIT:
  1835. case COMPONENT_FORM_SENSOR:
  1836. case COMPONENT_FORM_LIFESUPPORT:
  1837. case COMPONENT_FORM_GYROSCOPE:
  1838. case COMPONENT_FORM_POWER_AMPLIFIER:
  1839. case COMPONENT_FORM_ECM:
  1840. case COMPONENT_FORM_PROBE:
  1841. case COMPONENT_FORM_JAMMER:
  1842. case COMPONENT_FORM_BULK:
  1843. case COMPONENT_FORM_CASE:
  1844. case COMPONENT_FORM_ACTUATOR:
  1845. case COMPONENT_FORM_ENGINE:
  1846. case COMPONENT_FORM_HEATSINK:
  1847. numOther++;
  1848. inventory[realItemNum].health = MasterComponent::masterList[inventory[realItemNum].masterID].getHealth();
  1849. inventory[realItemNum].disabled = false;
  1850. inventory[realItemNum].amount = 1;
  1851. inventory[realItemNum].ammoIndex = -1;
  1852. inventory[realItemNum].readyTime = 0.0;
  1853. inventory[realItemNum].bodyLocation = 255;
  1854. ItemLocationToInvLocation[curItem] = realItemNum;
  1855. realItemNum++;
  1856. break;
  1857. case COMPONENT_FORM_WEAPON:
  1858. case COMPONENT_FORM_WEAPON_ENERGY:
  1859. case COMPONENT_FORM_WEAPON_BALLISTIC:
  1860. case COMPONENT_FORM_WEAPON_MISSILE:
  1861. //Ignore weapons until second pass
  1862. break;
  1863. case COMPONENT_FORM_AMMO:
  1864. //Ignore AMMO until third pass
  1865. break;
  1866. }
  1867. }
  1868. }
  1869. //NOW read in the weapons.
  1870. for (curItem = 0;curItem < MAX_MOVER_INVENTORY_ITEMS;curItem++)
  1871. {
  1872. inventory[realItemNum].masterID = localMasterComponentList[curItem];
  1873. if (inventory[realItemNum].masterID && (inventory[realItemNum].masterID != 255))
  1874. {
  1875. //---------------------------------------------------------------
  1876. // If the component is a JumpJet, increment our jump jet count...
  1877. long sourceWeaponType;
  1878. if (MasterComponent::masterList[inventory[realItemNum].masterID].getForm() == COMPONENT_FORM_WEAPON_MISSILE)
  1879. sourceWeaponType = MECH3D_WEAPONTYPE_MISSILE;
  1880. else if (MasterComponent::masterList[inventory[realItemNum].masterID].getForm() == COMPONENT_FORM_WEAPON_BALLISTIC)
  1881. sourceWeaponType = MECH3D_WEAPONTYPE_BALLISTIC;
  1882. else if (MasterComponent::masterList[inventory[realItemNum].masterID].getForm() == COMPONENT_FORM_WEAPON_ENERGY)
  1883. sourceWeaponType = MECH3D_WEAPONTYPE_ENERGY;
  1884. else
  1885. sourceWeaponType = MECH3D_WEAPONTYPE_ANY;
  1886. //---------------------------------------------------------------
  1887. // If the component is a JumpJet, increment our jump jet count...
  1888. switch (MasterComponent::masterList[inventory[realItemNum].masterID].getForm())
  1889. {
  1890. case COMPONENT_FORM_JUMPJET:
  1891. case COMPONENT_FORM_COCKPIT:
  1892. case COMPONENT_FORM_SENSOR:
  1893. case COMPONENT_FORM_LIFESUPPORT:
  1894. case COMPONENT_FORM_GYROSCOPE:
  1895. case COMPONENT_FORM_POWER_AMPLIFIER:
  1896. case COMPONENT_FORM_ECM:
  1897. case COMPONENT_FORM_PROBE:
  1898. case COMPONENT_FORM_JAMMER:
  1899. case COMPONENT_FORM_BULK:
  1900. case COMPONENT_FORM_CASE:
  1901. case COMPONENT_FORM_ACTUATOR:
  1902. case COMPONENT_FORM_ENGINE:
  1903. case COMPONENT_FORM_HEATSINK:
  1904. //We did these Above here.
  1905. break;
  1906. case COMPONENT_FORM_WEAPON:
  1907. case COMPONENT_FORM_WEAPON_ENERGY:
  1908. case COMPONENT_FORM_WEAPON_BALLISTIC:
  1909. case COMPONENT_FORM_WEAPON_MISSILE:
  1910. numWeapons++;
  1911. inventory[realItemNum].health = MasterComponent::masterList[inventory[realItemNum].masterID].getHealth();
  1912. inventory[realItemNum].disabled = false;
  1913. inventory[realItemNum].amount = 1;
  1914. inventory[realItemNum].ammoIndex = -1;
  1915. inventory[realItemNum].facing = appearance->getWeaponNode(sourceWeaponType);
  1916. inventory[realItemNum].readyTime = 0.0;
  1917. inventory[realItemNum].bodyLocation = 255;
  1918. inventory[realItemNum].effectiveness = (short)(MasterComponent::masterList[inventory[realItemNum].masterID].getWeaponDamage() * 10.0 / // damage over 10 seconds
  1919. MasterComponent::masterList[inventory[realItemNum].masterID].getWeaponRecycleTime());
  1920. inventory[realItemNum].effectiveness *= WeaponRanges[MasterComponent::masterList[inventory[realItemNum].masterID].getWeaponRange()][1] / 24;
  1921. ItemLocationToInvLocation[curItem] = realItemNum;
  1922. realItemNum++;
  1923. //-------------------------------------
  1924. // Cache in the weapon special effect.
  1925. break;
  1926. case COMPONENT_FORM_AMMO:
  1927. //Do these next.
  1928. break;
  1929. }
  1930. }
  1931. }
  1932. //NOW read in the AMMO
  1933. for (curItem = 0;curItem < MAX_MOVER_INVENTORY_ITEMS;curItem++)
  1934. {
  1935. inventory[realItemNum].masterID = localMasterComponentList[curItem];
  1936. if (inventory[realItemNum].masterID && (inventory[realItemNum].masterID != 255))
  1937. {
  1938. //---------------------------------------------------------------
  1939. // If the component is a JumpJet, increment our jump jet count...
  1940. switch (MasterComponent::masterList[inventory[realItemNum].masterID].getForm())
  1941. {
  1942. case COMPONENT_FORM_JUMPJET:
  1943. case COMPONENT_FORM_COCKPIT:
  1944. case COMPONENT_FORM_SENSOR:
  1945. case COMPONENT_FORM_LIFESUPPORT:
  1946. case COMPONENT_FORM_GYROSCOPE:
  1947. case COMPONENT_FORM_POWER_AMPLIFIER:
  1948. case COMPONENT_FORM_ECM:
  1949. case COMPONENT_FORM_PROBE:
  1950. case COMPONENT_FORM_JAMMER:
  1951. case COMPONENT_FORM_BULK:
  1952. case COMPONENT_FORM_CASE:
  1953. case COMPONENT_FORM_ACTUATOR:
  1954. case COMPONENT_FORM_ENGINE:
  1955. case COMPONENT_FORM_HEATSINK:
  1956. //Did these above.
  1957. break;
  1958. case COMPONENT_FORM_WEAPON:
  1959. case COMPONENT_FORM_WEAPON_ENERGY:
  1960. case COMPONENT_FORM_WEAPON_BALLISTIC:
  1961. case COMPONENT_FORM_WEAPON_MISSILE:
  1962. //Did These Above, too...
  1963. break;
  1964. case COMPONENT_FORM_AMMO:
  1965. numAmmos++;
  1966. inventory[realItemNum].health = MasterComponent::masterList[inventory[realItemNum].masterID].getHealth();
  1967. inventory[realItemNum].disabled = false;
  1968. inventory[realItemNum].amount = 1;
  1969. inventory[realItemNum].ammoIndex = -1;
  1970. inventory[realItemNum].readyTime = 0.0;
  1971. inventory[realItemNum].bodyLocation = 255;
  1972. //-----------------------------------------------------------------------
  1973. // Since the ammo amount in the profile is amount per ton, let's make the
  1974. // amount equal to the number of missiles/bullets/whatever. If it's set
  1975. // to 255, use the default amount per ton as defined in the component
  1976. // table...
  1977. //
  1978. // Ammo per ton is always fully stocked. I.e. always -1 or 255
  1979. inventory[realItemNum].amount = MasterComponent::masterList[inventory[realItemNum].masterID].getAmmoPerTon();
  1980. inventory[realItemNum].ammoIndex = -1;
  1981. inventory[realItemNum].startAmount = inventory[realItemNum].amount;
  1982. inventory[realItemNum].health = MasterComponent::masterList[inventory[realItemNum].masterID].getHealth();
  1983. inventory[realItemNum].disabled = false;
  1984. inventory[realItemNum].readyTime = 0.0;
  1985. inventory[realItemNum].bodyLocation = 255;
  1986. ItemLocationToInvLocation[curItem] = realItemNum;
  1987. realItemNum++;
  1988. break;
  1989. }
  1990. }
  1991. }
  1992. //--------------------------------------------------------------------------
  1993. // If we added BULK to the mech, adjust the max and current armor settings.
  1994. if (numNewArmors)
  1995. {
  1996. float totalArmorPoints = ARMOR_POINTS_PER_NEWARMOR * numNewArmors;
  1997. float armorPercent = ARMOR_HEAD_PERCENT * totalArmorPoints;
  1998. armor[MECH_ARMOR_LOCATION_HEAD].maxArmor += armorPercent;
  1999. armor[MECH_ARMOR_LOCATION_HEAD].curArmor = armor[MECH_ARMOR_LOCATION_HEAD].maxArmor;
  2000. armorPercent = ARMOR_CTORSO_PERCENT * totalArmorPoints;
  2001. armor[MECH_ARMOR_LOCATION_CTORSO].maxArmor += armorPercent;
  2002. armor[MECH_ARMOR_LOCATION_CTORSO].curArmor = armor[MECH_ARMOR_LOCATION_CTORSO].maxArmor;
  2003. armorPercent = ARMOR_LTORSO_PERCENT * totalArmorPoints;
  2004. armor[MECH_ARMOR_LOCATION_LTORSO].maxArmor += armorPercent;
  2005. armor[MECH_ARMOR_LOCATION_LTORSO].curArmor = armor[MECH_ARMOR_LOCATION_LTORSO].maxArmor;
  2006. armorPercent = ARMOR_RTORSO_PERCENT * totalArmorPoints;
  2007. armor[MECH_ARMOR_LOCATION_RTORSO].maxArmor += armorPercent;
  2008. armor[MECH_ARMOR_LOCATION_RTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RTORSO].maxArmor;
  2009. armorPercent = ARMOR_LARM_PERCENT * totalArmorPoints;
  2010. armor[MECH_ARMOR_LOCATION_LARM].maxArmor += armorPercent;
  2011. armor[MECH_ARMOR_LOCATION_LARM].curArmor = armor[MECH_ARMOR_LOCATION_LARM].maxArmor;
  2012. armorPercent = ARMOR_RARM_PERCENT * totalArmorPoints;
  2013. armor[MECH_ARMOR_LOCATION_RARM].maxArmor += armorPercent;
  2014. armor[MECH_ARMOR_LOCATION_RARM].curArmor = armor[MECH_ARMOR_LOCATION_RARM].maxArmor;
  2015. armorPercent = ARMOR_LLEG_PERCENT * totalArmorPoints;
  2016. armor[MECH_ARMOR_LOCATION_LLEG].maxArmor += armorPercent;
  2017. armor[MECH_ARMOR_LOCATION_LLEG].curArmor = armor[MECH_ARMOR_LOCATION_LLEG].maxArmor;
  2018. armorPercent = ARMOR_RLEG_PERCENT * totalArmorPoints;
  2019. armor[MECH_ARMOR_LOCATION_RLEG].maxArmor += armorPercent;
  2020. armor[MECH_ARMOR_LOCATION_RLEG].curArmor = armor[MECH_ARMOR_LOCATION_RLEG].maxArmor;
  2021. armorPercent = ARMOR_RCTORSO_PERCENT * totalArmorPoints;
  2022. armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor += armorPercent;
  2023. armor[MECH_ARMOR_LOCATION_RCTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor;
  2024. armorPercent = ARMOR_RLTORSO_PERCENT * totalArmorPoints;
  2025. armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor += armorPercent;
  2026. armor[MECH_ARMOR_LOCATION_RLTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor;
  2027. armorPercent = ARMOR_RRTORSO_PERCENT * totalArmorPoints;
  2028. armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor += armorPercent;
  2029. armor[MECH_ARMOR_LOCATION_RRTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor;
  2030. }
  2031. //---------------------------------------------------------------
  2032. // Reset the quick Access components in case they removed them in logistics.
  2033. // SHould only need to do jump jets!!
  2034. jumpJets = 255;
  2035. //------------------------------------------------------------
  2036. // Now, read in the component layout for each body location...
  2037. for (long curLocation = 0; curLocation < NUM_MECH_BODY_LOCATIONS; curLocation++)
  2038. {
  2039. body[curLocation].CASE = true; //ALL MC2 Mechs have CASE everywhere.
  2040. //Internal Structure is ALREADY set!
  2041. //---------------------------------------------------------
  2042. // Damage and states are already set.
  2043. long numSpaces = NumLocationCriticalSpaces[curLocation];
  2044. body[curLocation].totalSpaces = 0;
  2045. for (long curSpace = 0; curSpace < numSpaces; curSpace++)
  2046. {
  2047. //Find out where in the space table this location lies.
  2048. unsigned char spaceData = 0xff;
  2049. for (long curTable = 0;curTable < MAX_MOVER_INVENTORY_ITEMS;curTable++)
  2050. {
  2051. if ((logisticsTable[curTable].bodyLocation == curLocation) &&
  2052. (logisticsTable[curTable].slotNumber == curSpace))
  2053. {
  2054. spaceData = curTable;
  2055. break;
  2056. }
  2057. }
  2058. spaceData = ItemLocationToInvLocation[spaceData];
  2059. body[curLocation].criticalSpaces[curSpace].inventoryID = spaceData;
  2060. body[curLocation].criticalSpaces[curSpace].hit = false; //Everything always repaired now.
  2061. if (spaceData < 255)
  2062. {
  2063. if (spaceData >= numOther+numWeapons+numAmmos)
  2064. //Just ignore this space. Sage has filled them all in now.
  2065. // ACTUALLY, we should stop here.
  2066. continue;
  2067. inventory[spaceData].bodyLocation = curLocation;
  2068. //--------------------------------------------------------
  2069. // The following line assumes the "new" crit hit system...
  2070. body[curLocation].totalSpaces += MasterComponent::masterList[inventory[spaceData].masterID].getSize();
  2071. //--------------------------------------------------------
  2072. // Preserve critical component indices for quick access...
  2073. switch (MasterComponent::masterList[inventory[spaceData].masterID].getForm())
  2074. {
  2075. case COMPONENT_FORM_COCKPIT:
  2076. cockpit = spaceData;
  2077. break;
  2078. case COMPONENT_FORM_JUMPJET:
  2079. jumpJets = spaceData;
  2080. break;
  2081. case COMPONENT_FORM_SENSOR:
  2082. sensor = spaceData;
  2083. //Sensor already defined in the first component pass.
  2084. // Not possible to replace sensors or EW components in logistics now!!
  2085. /*
  2086. sensorSystem = SensorManager->newSensor();
  2087. sensorSystem->setOwner(this);
  2088. sensorSystem->setRange(MasterComponent::masterList[inventory[sensor].masterID].getSensorRange());
  2089. */
  2090. break;
  2091. case COMPONENT_FORM_HEATSINK:
  2092. inventory[spaceData].bodyLocation = curLocation;
  2093. break;
  2094. case COMPONENT_FORM_AMMO:
  2095. inventory[spaceData].bodyLocation = curLocation;
  2096. break;
  2097. case COMPONENT_FORM_WEAPON:
  2098. case COMPONENT_FORM_WEAPON_ENERGY:
  2099. inventory[spaceData].bodyLocation = curLocation;
  2100. break;
  2101. case COMPONENT_FORM_WEAPON_BALLISTIC:
  2102. inventory[spaceData].bodyLocation = curLocation;
  2103. if ((inventory[spaceData].masterID == MasterComponent::clanAntiMissileSystemID) ||
  2104. (inventory[spaceData].masterID == MasterComponent::innerSphereAntiMissileSystemID))
  2105. {
  2106. //------------------------------------------------------
  2107. // Add to Anti-Missile System list for fast reference...
  2108. if (numAntiMissileSystems == MAX_ANTI_MISSILE_SYSTEMS)
  2109. Fatal(0, "Too many Anti-Missile Systems");
  2110. antiMissileSystem[numAntiMissileSystems++] = spaceData;
  2111. }
  2112. break;
  2113. case COMPONENT_FORM_WEAPON_MISSILE:
  2114. inventory[spaceData].bodyLocation = curLocation;
  2115. break;
  2116. case COMPONENT_FORM_ACTUATOR:
  2117. if (inventory[spaceData].masterID == MasterComponent::armActuatorID)
  2118. {
  2119. if (curLocation == MECH_BODY_LOCATION_LARM)
  2120. actuator[ACTUATOR_LSHOULDER] = spaceData;
  2121. else if (curLocation == MECH_BODY_LOCATION_RARM)
  2122. actuator[ACTUATOR_RSHOULDER] = spaceData;
  2123. }
  2124. else if (inventory[spaceData].masterID == MasterComponent::legActuatorID)
  2125. {
  2126. if (curLocation == MECH_BODY_LOCATION_LLEG)
  2127. actuator[ACTUATOR_LHIP] = spaceData;
  2128. else if (curLocation == MECH_BODY_LOCATION_RLEG)
  2129. actuator[ACTUATOR_RHIP] = spaceData;
  2130. }
  2131. break;
  2132. case COMPONENT_FORM_ENGINE:
  2133. engine = spaceData;
  2134. break;
  2135. case COMPONENT_FORM_LIFESUPPORT:
  2136. lifeSupport = spaceData;
  2137. break;
  2138. case COMPONENT_FORM_GYROSCOPE:
  2139. gyro = spaceData;
  2140. break;
  2141. case COMPONENT_FORM_ECM:
  2142. ecm = spaceData;
  2143. break;
  2144. case COMPONENT_FORM_JAMMER:
  2145. break;
  2146. case COMPONENT_FORM_PROBE:
  2147. probe = spaceData;
  2148. break;
  2149. }
  2150. }
  2151. }
  2152. }
  2153. calcAmmoTotals();
  2154. for (item = numOther; item < (numOther + numWeapons); item++)
  2155. {
  2156. //----------------------------------------------------------
  2157. // Each weapon should point to its appropriate ammo total in
  2158. // the ammo type total list...
  2159. for (long ammoIndex = 0; ammoIndex < numAmmoTypes; ammoIndex++)
  2160. {
  2161. if ((long)MasterComponent::masterList[inventory[item].masterID].getWeaponAmmoMasterId() == ammoTypeTotal[ammoIndex].masterId)
  2162. {
  2163. inventory[item].ammoIndex = ammoIndex;
  2164. break;
  2165. }
  2166. }
  2167. }
  2168. for (item = numOther+numWeapons;item<(numOther+numWeapons+numAmmos);item++)
  2169. {
  2170. //----------------------------------------------------------
  2171. // Each weapon should point to its appropriate ammo total in
  2172. // the ammo type total list...
  2173. for (long ammoIndex = 0; ammoIndex < numAmmoTypes; ammoIndex++)
  2174. {
  2175. if (inventory[item].masterID == ammoTypeTotal[ammoIndex].masterId)
  2176. {
  2177. inventory[item].ammoIndex = ammoIndex;
  2178. break;
  2179. }
  2180. }
  2181. }
  2182. for (item = 0; item < numOther; item++)
  2183. {
  2184. if ((inventory[item].masterID == MasterComponent::clanAntiMissileSystemID) || (inventory[item].masterID == MasterComponent::innerSphereAntiMissileSystemID))
  2185. {
  2186. for (long ammoIndex = 0; ammoIndex < numAmmoTypes; ammoIndex++) {
  2187. if ((long)MasterComponent::masterList[inventory[item].masterID].getWeaponAmmoMasterId() == ammoTypeTotal[ammoIndex].masterId)
  2188. {
  2189. inventory[item].ammoIndex = ammoIndex;
  2190. break;
  2191. }
  2192. }
  2193. }
  2194. }
  2195. //---------------------------------------------------------------------------
  2196. // We need to set the status states for legs and torso based upon our current
  2197. // condition...
  2198. calcFireRanges();
  2199. maxCV = calcCV(true);
  2200. curCV = calcCV(false);
  2201. setThreatRating(-1);
  2202. maxWeaponDamage = calcMaxTargetDamage();
  2203. // local variable needs to be set for class
  2204. numJumpJets = numJumpJets;
  2205. }
  2206. long BattleMech::init (FitIniFile* mechFile) {
  2207. char* BodyLocationBlockString[NUM_BODY_LOCATIONS] = {
  2208. "Head",
  2209. "CenterTorso",
  2210. "LeftTorso",
  2211. "RightTorso",
  2212. "LeftArm",
  2213. "RightArm",
  2214. "LeftLeg",
  2215. "RightLeg"
  2216. };
  2217. //-----------------------
  2218. // Read in the mech data.
  2219. long result = mechFile->seekBlock("Header");
  2220. if (result != NO_ERR)
  2221. return(result);
  2222. char fileType[128];
  2223. result = mechFile->readIdString ("FileType", fileType, 127);
  2224. if (result != NO_ERR)
  2225. return(result);
  2226. if (strcmp(fileType, "MechProfile"))
  2227. return(-1);
  2228. result = mechFile->seekBlock("General");
  2229. if (result != NO_ERR)
  2230. return(result);
  2231. char thisMechName[128];
  2232. result = mechFile->readIdString ("Name", thisMechName, 127);
  2233. strncpy(name, thisMechName, MAXLEN_MOVER_NAME - 1);
  2234. name[MAXLEN_MOVER_NAME] = NULL;
  2235. result = mechFile->readIdLong("ChassisBR", chassisBR);
  2236. if (result != NO_ERR)
  2237. chassisBR = 100;
  2238. result = mechFile->readIdFloat("CurTonnage", tonnage);
  2239. if (result != NO_ERR)
  2240. return(result);
  2241. result = mechFile->readIdLong("DescIndex", descID);
  2242. if (result != NO_ERR)
  2243. descID = -1;
  2244. longName[0] = NULL;
  2245. // result = mechFile->readIdLong("NameIndex", nameIndex);
  2246. // if (result != NO_ERR)
  2247. // return result;
  2248. // result = mechFile->readIdLong("NameVariant", variant);
  2249. // if (result != NO_ERR)
  2250. // return result;
  2251. result = mechFile->readIdLong("Pilot",pilotNum);
  2252. if (result != NO_ERR)
  2253. pilotNum = -1;
  2254. char cStatus = 0;
  2255. //result = mechFile->readIdChar("Status", cStatus);
  2256. //if (result != NO_ERR)
  2257. // return(result);
  2258. status = cStatus;
  2259. result = mechFile->readIdBoolean("NotMineYet",notMineYet);
  2260. if (result != NO_ERR)
  2261. notMineYet = true; //We weren't written by logistics. I.E. Not mine Yet.
  2262. #ifdef USEHEAT
  2263. result = mechFile->seekBlock("HeatSinks");
  2264. if (result != NO_ERR)
  2265. return(result);
  2266. result = mechFile->readIdUChar("HeatSinkType", heatSinkType);
  2267. if (result != NO_ERR)
  2268. return(result);
  2269. result = mechFile->readIdUChar("ExtraHeatSinks", extraHeatSinks);
  2270. if (result != NO_ERR)
  2271. return(result);
  2272. unsigned char heat;
  2273. result = mechFile->readIdUChar("HeatBuildUp", heat);
  2274. if (result != NO_ERR)
  2275. return(result);
  2276. heat = (float)heat;
  2277. disabledHeatSinks = 0;
  2278. curLegHeatSinks = 0;
  2279. heatDissipation = calcHeatDissipation();
  2280. #endif
  2281. result = mechFile->seekBlock("Engine");
  2282. if (result != NO_ERR)
  2283. return(result);
  2284. unsigned char speed;
  2285. result = mechFile->readIdUChar("MaxRunSpeed", speed);
  2286. if (result != NO_ERR)
  2287. return(result);
  2288. maxMoveSpeed = (float)speed;
  2289. result = mechFile->seekBlock("MovementSystem");
  2290. if (result == NO_ERR) {
  2291. long crashSize = 0;
  2292. result = mechFile->readIdLong("CrashAvoidSelf", crashSize);
  2293. if (result == NO_ERR)
  2294. crashAvoidSelf = crashSize;
  2295. result = mechFile->readIdLong("CrashAvoidPath", crashSize);
  2296. if (result == NO_ERR)
  2297. crashAvoidPath = crashSize;
  2298. result = mechFile->readIdLong("CrashBlockSelf", crashSize);
  2299. if (result == NO_ERR)
  2300. crashBlockSelf = crashSize;
  2301. result = mechFile->readIdLong("CrashBlockPath", crashSize);
  2302. if (result == NO_ERR)
  2303. crashBlockPath = crashSize;
  2304. float crashYield = 0.0;
  2305. result = mechFile->readIdFloat("CrashYieldTime", crashYield);
  2306. if (result == NO_ERR)
  2307. crashYieldTime = crashSize;
  2308. }
  2309. result = mechFile->seekBlock("MaxArmorPoints");
  2310. if (result != NO_ERR)
  2311. return(result);
  2312. result = mechFile->readIdUChar("Head", armor[MECH_ARMOR_LOCATION_HEAD].maxArmor);
  2313. if (result != NO_ERR)
  2314. return(result);
  2315. result = mechFile->readIdUChar("CenterTorso", armor[MECH_ARMOR_LOCATION_CTORSO].maxArmor);
  2316. if (result != NO_ERR)
  2317. return(result);
  2318. result = mechFile->readIdUChar("LeftTorso", armor[MECH_ARMOR_LOCATION_LTORSO].maxArmor);
  2319. if (result != NO_ERR)
  2320. return(result);
  2321. result = mechFile->readIdUChar("RightTorso", armor[MECH_ARMOR_LOCATION_RTORSO].maxArmor);
  2322. if (result != NO_ERR)
  2323. return(result);
  2324. result = mechFile->readIdUChar("LeftArm", armor[MECH_ARMOR_LOCATION_LARM].maxArmor);
  2325. if (result != NO_ERR)
  2326. return(result);
  2327. result = mechFile->readIdUChar("RightArm", armor[MECH_ARMOR_LOCATION_RARM].maxArmor);
  2328. if (result != NO_ERR)
  2329. return(result);
  2330. result = mechFile->readIdUChar("LeftLeg", armor[MECH_ARMOR_LOCATION_LLEG].maxArmor);
  2331. if (result != NO_ERR)
  2332. return(result);
  2333. result = mechFile->readIdUChar("RightLeg", armor[MECH_ARMOR_LOCATION_RLEG].maxArmor);
  2334. if (result != NO_ERR)
  2335. return(result);
  2336. result = mechFile->readIdUChar("RearCenterTorso", armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor);
  2337. if (result != NO_ERR)
  2338. return(result);
  2339. result = mechFile->readIdUChar("RearLeftTorso", armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor);
  2340. if (result != NO_ERR)
  2341. return(result);
  2342. result = mechFile->readIdUChar("RearRightTorso", armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor);
  2343. if (result != NO_ERR)
  2344. return(result);
  2345. result = mechFile->seekBlock("CurArmorPoints");
  2346. if (result != NO_ERR)
  2347. return(result);
  2348. unsigned char currentArmor;
  2349. result = mechFile->readIdUChar("Head", currentArmor);
  2350. if (result != NO_ERR)
  2351. return(result);
  2352. armor[MECH_ARMOR_LOCATION_HEAD].curArmor = currentArmor;
  2353. result = mechFile->readIdUChar("CenterTorso", currentArmor);
  2354. if (result != NO_ERR)
  2355. return(result);
  2356. armor[MECH_ARMOR_LOCATION_CTORSO].curArmor = currentArmor;
  2357. result = mechFile->readIdUChar("LeftTorso", currentArmor);
  2358. if (result != NO_ERR)
  2359. return(result);
  2360. armor[MECH_ARMOR_LOCATION_LTORSO].curArmor = currentArmor;
  2361. result = mechFile->readIdUChar("RightTorso", currentArmor);
  2362. if (result != NO_ERR)
  2363. return(result);
  2364. armor[MECH_ARMOR_LOCATION_RTORSO].curArmor = currentArmor;
  2365. result = mechFile->readIdUChar("LeftArm", currentArmor);
  2366. if (result != NO_ERR)
  2367. return(result);
  2368. armor[MECH_ARMOR_LOCATION_LARM].curArmor = currentArmor;
  2369. result = mechFile->readIdUChar("RightArm", currentArmor);
  2370. if (result != NO_ERR)
  2371. return(result);
  2372. armor[MECH_ARMOR_LOCATION_RARM].curArmor = currentArmor;
  2373. result = mechFile->readIdUChar("LeftLeg", currentArmor);
  2374. if (result != NO_ERR)
  2375. return(result);
  2376. armor[MECH_ARMOR_LOCATION_LLEG].curArmor = currentArmor;
  2377. result = mechFile->readIdUChar("RightLeg", currentArmor);
  2378. if (result != NO_ERR)
  2379. return(result);
  2380. armor[MECH_ARMOR_LOCATION_RLEG].curArmor = currentArmor;
  2381. result = mechFile->readIdUChar("RearCenterTorso", currentArmor);
  2382. if (result != NO_ERR)
  2383. return(result);
  2384. armor[MECH_ARMOR_LOCATION_RCTORSO].curArmor = currentArmor;
  2385. result = mechFile->readIdUChar("RearLeftTorso", currentArmor);
  2386. if (result != NO_ERR)
  2387. return(result);
  2388. armor[MECH_ARMOR_LOCATION_RLTORSO].curArmor = currentArmor;
  2389. result = mechFile->readIdUChar("RearRightTorso", currentArmor);
  2390. if (result != NO_ERR)
  2391. return(result);
  2392. armor[MECH_ARMOR_LOCATION_RRTORSO].curArmor = currentArmor;
  2393. //---------------------------------------------------------------------------
  2394. // Build the mech's inventory (all components, and where they are located)...
  2395. result = mechFile->seekBlock("InventoryInfo");
  2396. if (result != NO_ERR)
  2397. return(result);
  2398. result = mechFile->readIdUChar("NumOther", numOther);
  2399. if (result != NO_ERR)
  2400. return(result);
  2401. result = mechFile->readIdUChar("NumWeapons", numWeapons);
  2402. if (result != NO_ERR)
  2403. return(result);
  2404. result = mechFile->readIdUChar("NumAmmo", numAmmos);
  2405. if (result != NO_ERR)
  2406. return(result);
  2407. if ((numOther + numWeapons + numAmmos) > MAX_MOVER_INVENTORY_ITEMS)
  2408. Fatal(numOther + numWeapons + numAmmos, " Battlemech.init: too many inventory items ");
  2409. numAntiMissileSystems = 0;
  2410. //-----------------------------------------------------
  2411. // Read in the mech's non-weapon/non-ammo components...
  2412. long curItem = 0;
  2413. while (curItem < numOther) {
  2414. char itemString[128];
  2415. sprintf(itemString, "Item:%d", curItem);
  2416. result = mechFile->seekBlock(itemString);
  2417. if (result != NO_ERR)
  2418. return(result);
  2419. result = mechFile->readIdUChar("MasterID", inventory[curItem].masterID);
  2420. if (result != NO_ERR)
  2421. return(result);
  2422. inventory[curItem].health = MasterComponent::masterList[inventory[curItem].masterID].getHealth();
  2423. inventory[curItem].disabled = false;
  2424. inventory[curItem].amount = 1;
  2425. inventory[curItem].ammoIndex = -1;
  2426. inventory[curItem].readyTime = 0.0;
  2427. inventory[curItem].bodyLocation = 255;
  2428. #ifdef USEHEAT
  2429. inventory[curItem].heatPerSec = 0.0;
  2430. #endif
  2431. //---------------------------------------------------------------
  2432. // If the component is a JumpJet, increment our jump jet count...
  2433. switch (MasterComponent::masterList[inventory[curItem].masterID].getForm()) {
  2434. case COMPONENT_FORM_JUMPJET:
  2435. numJumpJets = 5;
  2436. break;
  2437. case COMPONENT_FORM_HEATSINK:
  2438. //maxHeatSinks++;
  2439. break;
  2440. }
  2441. curItem++;
  2442. }
  2443. //------------------------------
  2444. // Read in the mech's weapons...
  2445. while (curItem < (numOther + numWeapons)) {
  2446. char itemString[128];
  2447. sprintf(itemString, "Item:%d", curItem);
  2448. result = mechFile->seekBlock(itemString);
  2449. if (result != NO_ERR)
  2450. return(result);
  2451. result = mechFile->readIdUChar("MasterID", inventory[curItem].masterID);
  2452. if (result != NO_ERR)
  2453. return(result);
  2454. result = mechFile->readIdUChar("FacesForward", inventory[curItem].facing);
  2455. if (result != NO_ERR)
  2456. return(result);
  2457. inventory[curItem].health = MasterComponent::masterList[inventory[curItem].masterID].getHealth();
  2458. inventory[curItem].disabled = false;
  2459. inventory[curItem].amount = 1;
  2460. inventory[curItem].ammoIndex = -1;
  2461. inventory[curItem].readyTime = 0.0;
  2462. inventory[curItem].bodyLocation = 255;
  2463. inventory[curItem].effectiveness = (short)(MasterComponent::masterList[inventory[curItem].masterID].getWeaponDamage() * 10.0 / // damage over 10 seconds
  2464. MasterComponent::masterList[inventory[curItem].masterID].getWeaponRecycleTime());
  2465. inventory[curItem].effectiveness *= WeaponRanges[MasterComponent::masterList[inventory[curItem].masterID].getWeaponRange()][1] / 24;
  2466. //-------------------------------------
  2467. // Cache in the weapon special effect.
  2468. curItem++;
  2469. }
  2470. //---------------------------
  2471. // Read in the mech's ammo...
  2472. while (curItem < (numOther + numWeapons + numAmmos)) {
  2473. char itemString[128];
  2474. sprintf(itemString, "Item:%d", curItem);
  2475. result = mechFile->seekBlock(itemString);
  2476. if (result != NO_ERR)
  2477. return(result);
  2478. result = mechFile->readIdUChar("MasterID", inventory[curItem].masterID);
  2479. if (result != NO_ERR)
  2480. return(result);
  2481. long itemAmount;
  2482. result = mechFile->readIdLong("Amount", itemAmount);
  2483. if (result != NO_ERR) {
  2484. unsigned char itemAmount2;
  2485. result = mechFile->readIdUChar("Amount", itemAmount2);
  2486. if (result != NO_ERR)
  2487. return(result);
  2488. else
  2489. itemAmount = itemAmount2;
  2490. }
  2491. //-----------------------------------------------------------------------
  2492. // Since the ammo amount in the profile is amount per ton, let's make the
  2493. // amount equal to the number of missiles/bullets/whatever. If it's set
  2494. // to 255, use the default amount per ton as defined in the component
  2495. // table...
  2496. if (itemAmount == -1)
  2497. inventory[curItem].amount = MasterComponent::masterList[inventory[curItem].masterID].getAmmoPerTon();
  2498. else
  2499. inventory[curItem].amount = itemAmount;
  2500. inventory[curItem].ammoIndex = -1;
  2501. inventory[curItem].startAmount = inventory[curItem].amount;
  2502. inventory[curItem].health = MasterComponent::masterList[inventory[curItem].masterID].getHealth();
  2503. inventory[curItem].disabled = false;
  2504. inventory[curItem].readyTime = 0.0;
  2505. inventory[curItem].bodyLocation = 255;
  2506. #ifdef USEHEAT
  2507. inventory[curItem].heatPerSec = 0.0;
  2508. #endif
  2509. curItem++;
  2510. }
  2511. //------------------------------------------------------------
  2512. // Now, read in the component layout for each body location...
  2513. for (long curLocation = 0; curLocation < NUM_MECH_BODY_LOCATIONS; curLocation++) {
  2514. result = mechFile->seekBlock(BodyLocationBlockString[curLocation]);
  2515. if (result != NO_ERR)
  2516. return(result);
  2517. unsigned char caseHere;
  2518. result = mechFile->readIdUChar("CASE", caseHere);
  2519. if (result != NO_ERR)
  2520. return(result);
  2521. body[curLocation].CASE = caseHere ? true : false;
  2522. unsigned char internalStructure;
  2523. result = mechFile->readIdUChar("CurInternalStructure", internalStructure);
  2524. if (result != NO_ERR)
  2525. return(result);
  2526. body[curLocation].curInternalStructure = internalStructure;
  2527. result = mechFile->readIdUChar("HotSpotNumber", body[curLocation].hotSpotNumber);
  2528. if (result != NO_ERR)
  2529. return(result);
  2530. //---------------------------------------------------------
  2531. // Now, determine the damage state for the body location...
  2532. float damageLevel = (float)body[curLocation].curInternalStructure / body[curLocation].maxInternalStructure;
  2533. if (damageLevel <= 0.0)
  2534. body[curLocation].damageState = IS_DAMAGE_DESTROYED;
  2535. else if (damageLevel <= 0.5)
  2536. body[curLocation].damageState = IS_DAMAGE_PARTIAL;
  2537. else
  2538. body[curLocation].damageState = IS_DAMAGE_NONE;
  2539. long numSpaces = NumLocationCriticalSpaces[curLocation];
  2540. body[curLocation].totalSpaces = 0;
  2541. for (long curSpace = 0; curSpace < numSpaces; curSpace++)
  2542. {
  2543. char componentString[128];
  2544. sprintf(componentString, "Component:%d", curSpace);
  2545. unsigned char spaceData[2];
  2546. result = mechFile->readIdUCharArray(componentString, spaceData, 2);
  2547. if (result != NO_ERR)
  2548. return(result);
  2549. body[curLocation].criticalSpaces[curSpace].inventoryID = spaceData[0];
  2550. body[curLocation].criticalSpaces[curSpace].hit = spaceData[1] ? true : false;
  2551. if (spaceData[0] < 255)
  2552. {
  2553. #ifdef _DEBUG
  2554. char msg[256];
  2555. sprintf(msg," Bad Mech Profile : %s ",mechFile->getFilename());
  2556. Assert(spaceData[0] < numOther+numWeapons+numAmmos,spaceData[0],msg);
  2557. #endif
  2558. inventory[spaceData[0]].bodyLocation = curLocation;
  2559. //--------------------------------------------------------
  2560. // The following line assumes the "new" crit hit system...
  2561. body[curLocation].totalSpaces += MasterComponent::masterList[inventory[spaceData[0]].masterID].getSize();
  2562. #if 0
  2563. if (body[curLocation].totalSpaces > NumLocationCriticalSpaces[curLocation])
  2564. {
  2565. char fatalMsg[250];
  2566. sprintf(fatalMsg,"Too Many Critical Spaces in %s",mechFile->getFilename());
  2567. Fatal(curLocation,fatalMsg);
  2568. }
  2569. #endif
  2570. //--------------------------------------------------------
  2571. // Preserve critical component indices for quick access...
  2572. switch (MasterComponent::masterList[inventory[spaceData[0]].masterID].getForm())
  2573. {
  2574. case COMPONENT_FORM_COCKPIT:
  2575. cockpit = spaceData[0];
  2576. break;
  2577. case COMPONENT_FORM_JUMPJET:
  2578. jumpJets = spaceData[0];
  2579. break;
  2580. case COMPONENT_FORM_SENSOR:
  2581. sensor = spaceData[0];
  2582. sensorSystem = SensorManager->newSensor();
  2583. sensorSystem->setOwner(this);
  2584. sensorSystem->setRange(MasterComponent::masterList[inventory[sensor].masterID].getSensorRange());
  2585. break;
  2586. case COMPONENT_FORM_HEATSINK:
  2587. inventory[spaceData[0]].bodyLocation = curLocation;
  2588. break;
  2589. case COMPONENT_FORM_AMMO:
  2590. inventory[spaceData[0]].bodyLocation = curLocation;
  2591. break;
  2592. case COMPONENT_FORM_WEAPON:
  2593. case COMPONENT_FORM_WEAPON_ENERGY:
  2594. inventory[spaceData[0]].bodyLocation = curLocation;
  2595. break;
  2596. case COMPONENT_FORM_WEAPON_BALLISTIC:
  2597. inventory[spaceData[0]].bodyLocation = curLocation;
  2598. if ((inventory[spaceData[0]].masterID == MasterComponent::clanAntiMissileSystemID) ||
  2599. (inventory[spaceData[0]].masterID == MasterComponent::innerSphereAntiMissileSystemID))
  2600. {
  2601. //------------------------------------------------------
  2602. // Add to Anti-Missile System list for fast reference...
  2603. if (numAntiMissileSystems == MAX_ANTI_MISSILE_SYSTEMS)
  2604. Fatal(0, "Too many Anti-Missile Systems");
  2605. antiMissileSystem[numAntiMissileSystems++] = spaceData[0];
  2606. }
  2607. break;
  2608. case COMPONENT_FORM_WEAPON_MISSILE:
  2609. inventory[spaceData[0]].bodyLocation = curLocation;
  2610. break;
  2611. case COMPONENT_FORM_ACTUATOR:
  2612. if (inventory[spaceData[0]].masterID == MasterComponent::armActuatorID)
  2613. {
  2614. if (curLocation == MECH_BODY_LOCATION_LARM)
  2615. actuator[ACTUATOR_LSHOULDER] = spaceData[0];
  2616. else if (curLocation == MECH_BODY_LOCATION_RARM)
  2617. actuator[ACTUATOR_RSHOULDER] = spaceData[0];
  2618. }
  2619. else if (inventory[spaceData[0]].masterID == MasterComponent::legActuatorID)
  2620. {
  2621. if (curLocation == MECH_BODY_LOCATION_LLEG)
  2622. actuator[ACTUATOR_LHIP] = spaceData[0];
  2623. else if (curLocation == MECH_BODY_LOCATION_RLEG)
  2624. actuator[ACTUATOR_RHIP] = spaceData[0];
  2625. }
  2626. break;
  2627. case COMPONENT_FORM_ENGINE:
  2628. engine = spaceData[0];
  2629. break;
  2630. case COMPONENT_FORM_LIFESUPPORT:
  2631. lifeSupport = spaceData[0];
  2632. break;
  2633. case COMPONENT_FORM_GYROSCOPE:
  2634. gyro = spaceData[0];
  2635. break;
  2636. case COMPONENT_FORM_ECM:
  2637. ecm = spaceData[0];
  2638. break;
  2639. case COMPONENT_FORM_JAMMER:
  2640. break;
  2641. case COMPONENT_FORM_PROBE:
  2642. probe = spaceData[0];
  2643. break;
  2644. }
  2645. }
  2646. }
  2647. }
  2648. calcAmmoTotals();
  2649. for (long item = numOther; item < (numOther + numWeapons); item++) {
  2650. //----------------------------------------------------------
  2651. // Each weapon should point to its appropriate ammo total in
  2652. // the ammo type total list...
  2653. for (long ammoIndex = 0; ammoIndex < numAmmoTypes; ammoIndex++) {
  2654. if ((long)MasterComponent::masterList[inventory[item].masterID].getWeaponAmmoMasterId() == ammoTypeTotal[ammoIndex].masterId) {
  2655. inventory[item].ammoIndex = ammoIndex;
  2656. break;
  2657. }
  2658. }
  2659. }
  2660. for (item = numOther+numWeapons;item<(numOther+numWeapons+numAmmos);item++) {
  2661. //----------------------------------------------------------
  2662. // Each weapon should point to its appropriate ammo total in
  2663. // the ammo type total list...
  2664. for (long ammoIndex = 0; ammoIndex < numAmmoTypes; ammoIndex++) {
  2665. if (inventory[item].masterID == ammoTypeTotal[ammoIndex].masterId) {
  2666. inventory[item].ammoIndex = ammoIndex;
  2667. break;
  2668. }
  2669. }
  2670. }
  2671. for (item = 0; item < numOther; item++) {
  2672. if ((inventory[item].masterID == MasterComponent::clanAntiMissileSystemID) || (inventory[item].masterID == MasterComponent::innerSphereAntiMissileSystemID)) {
  2673. for (long ammoIndex = 0; ammoIndex < numAmmoTypes; ammoIndex++) {
  2674. if ((long)MasterComponent::masterList[inventory[item].masterID].getWeaponAmmoMasterId() == ammoTypeTotal[ammoIndex].masterId) {
  2675. inventory[item].ammoIndex = ammoIndex;
  2676. break;
  2677. }
  2678. }
  2679. }
  2680. }
  2681. #ifdef USEHEAT
  2682. //---------------------------
  2683. // Calc the leg heat sinks...
  2684. curLegHeatSinks = calcHeatSinks(MECH_BODY_LOCATION_RLEG, true) + calcHeatSinks(MECH_BODY_LOCATION_LLEG, true);
  2685. #endif
  2686. //------------------------------------------------------------------------------
  2687. // Now that we've loaded inventory, let's set aside which weapon has the longest
  2688. // range...
  2689. //---------------------------------------------------------------------------
  2690. // We need to set the status states for legs and torso based upon our current
  2691. // condition...
  2692. calcLegStatus();
  2693. calcTorsoStatus();
  2694. calcFireRanges();
  2695. maxCV = calcCV(true);
  2696. curCV = calcCV(false);
  2697. maxWeaponDamage = calcMaxTargetDamage();
  2698. ObjectTypePtr type = ObjectManager->getObjectType(typeHandle);
  2699. if (type->getExplosionObject() > 0)
  2700. ObjectManager->objTypeManager->load(type->getExplosionObject(), true);
  2701. //-----------------------------
  2702. // Calc mech's chassis class...
  2703. chassisClass = getMechClass();
  2704. return(NO_ERR);
  2705. }
  2706. //---------------------------------------------------------------------------
  2707. long BattleMech::init (FilePtr mechFile) {
  2708. return(NO_ERR);
  2709. }
  2710. //---------------------------------------------------------------------------
  2711. long BattleMech::write (FilePtr mechFile) {
  2712. #if 0
  2713. GameObject::write(mechFile);
  2714. mechFile->writeString(moverName);
  2715. mechFile->writeString(icon);
  2716. mechFile->writeByte(chassis);
  2717. mechFile->writeLong((long)isEndoSteel);
  2718. mechFile->writeFloat(maxTonnage);
  2719. mechFile->writeFloat(tonsInternalStructure);
  2720. //mechFile->writeByte(NUM_MECH_BODY_LOCATIONS); //obviously we know this...
  2721. for (long i = 0; i < NUM_MECH_BODY_LOCATIONS; i++) {
  2722. mechFile->writeLong((long)body[i].CASE);
  2723. mechFile->write((MemoryPtr)body[i].criticalSpaces, sizeof(CriticalSpace) * NumLocationCriticalSpaces[i]);
  2724. mechFile->writeFloat(body[i].curInternalStructure);
  2725. mechFile->writeByte((byte)body[i].maxInternalStructure);
  2726. mechFile->writeByte((byte)body[i].hotSpotNumber);
  2727. //mechFile->writeByte((byte)damageState); //calc this upon load
  2728. }
  2729. //mechFile->writeLong(maxCV); //calc upon load
  2730. //mechFile->writeLong(curCV); //calc upon load
  2731. //mechFile->writeLong(fieldedCV); // only used in combat
  2732. mechFile->writeByte((byte)armorType);
  2733. mechFile->writeFloat(armorTonnage);
  2734. //mechFile->writeByte(NUM_MECH_ARMOR_LOCATIONS); //again, we know this for mechs...
  2735. mechFile->write((MemoryPtr)armor, sizeof(ArmorLocation) * NUM_MECH_ARMOR_LOCATIONS);
  2736. //--------------------------------------------------------------------------
  2737. // NOTE: The following line will be needed once we have the Team Data Files.
  2738. //mechFile->writeByte(pilotIndex); //points to pilot on PlayerTeam, or -1 if none
  2739. mechFile->writeLong(numOther);
  2740. mechFile->writeLong(numWeapons);
  2741. mechFile->writeLong(numAmmos);
  2742. for (i = 0; i < numOther; i++) {
  2743. mechFile->writeByte((byte)inventory[i].masterID);
  2744. mechFile->writeByte((byte)inventory[i].health);
  2745. mechFile->writeByte((byte)(inventory[i].disabled == true));
  2746. mechFile->writeByte((byte)inventory[i].facing);
  2747. mechFile->writeShort(inventory[i].amount);
  2748. mechFile->writeByte((byte)inventory[i].bodyLocation);
  2749. }
  2750. for (i = 0; i < numWeapons; i++) {
  2751. mechFile->writeByte((byte)inventory[i].masterID);
  2752. mechFile->writeByte((byte)inventory[i].health);
  2753. mechFile->writeByte((byte)(inventory[i].disabled == true));
  2754. mechFile->writeByte((byte)inventory[i].facing);
  2755. mechFile->writeShort(inventory[i].amount);
  2756. mechFile->writeByte((byte)inventory[i].bodyLocation);
  2757. }
  2758. for (i = 0; i < numAmmos; i++) {
  2759. mechFile->writeByte((byte)inventory[i].masterID);
  2760. mechFile->writeByte((byte)inventory[i].health);
  2761. mechFile->writeByte((byte)(inventory[i].disabled == true));
  2762. mechFile->writeByte((byte)inventory[i].facing);
  2763. mechFile->writeShort(inventory[i].amount);
  2764. mechFile->writeByte((byte)inventory[i].bodyLocation);
  2765. }
  2766. mechFile->writeByte((byte)cockpit);
  2767. mechFile->writeByte((byte)engine);
  2768. mechFile->writeByte((byte)lifeSupport);
  2769. mechFile->writeByte((byte)sensor);
  2770. mechFile->writeByte((byte)ecm);
  2771. mechFile->writeByte((byte)probe);
  2772. mechFile->writeByte((byte)jammer);
  2773. mechFile->writeByte((byte)numAntiMissileSystems);
  2774. mechFile->write((MemoryPtr)antiMissileSystem, MAX_ANTI_MISSILE_SYSTEMS);
  2775. mechFile->writeFloat(maxMoveSpeed);
  2776. //---------------------------------------------------------------------------------
  2777. // Do we need to preserve the object type data? Yes, at least the type id so we can
  2778. // recreate the pointer to it upon load...
  2779. #endif
  2780. return(NO_ERR);
  2781. }
  2782. //---------------------------------------------------------------------------
  2783. #ifdef USEHEAT
  2784. long BattleMech::calcHeatSinks (long location, bool calcCurrent) {
  2785. //--------------------------------------------------
  2786. // IMPORTANT: This needs to be properly implemented!
  2787. long tally = 0;
  2788. for (long item = 0; item < numOther; item++) {
  2789. if (MasterComponent::masterList[inventory[item].masterID].getForm() == COMPONENT_FORM_HEATSINK)
  2790. if (inventory[item].bodyLocation == location)
  2791. if (!calcCurrent || !inventory[item].disabled)
  2792. tally++;
  2793. }
  2794. return(tally);
  2795. }
  2796. #endif
  2797. //------------------------------------------------------------------------------------------
  2798. long BattleMech::calcCV (bool calcMax) {
  2799. //------------------------------------------------------------------------
  2800. // Due to quality communication, the components have float BR ratings, but
  2801. // the mechs have integer BR ratings. Ahhhh, love those casts...
  2802. float totalCV = (float)chassisBR;
  2803. //-----------------------
  2804. // Total Component BRs...
  2805. long numComponents = numWeapons + numAmmos + numOther;
  2806. for (long itemIndex = 0; itemIndex < numComponents; itemIndex++)
  2807. if (calcMax || !inventory[itemIndex].disabled)
  2808. totalCV += MasterComponent::masterList[inventory[itemIndex].masterID].getCV();
  2809. return((long)totalCV);
  2810. }
  2811. //-------------------------------------------------------------------------------------------
  2812. long BattleMech::calcLegStatus (void)
  2813. {
  2814. if (body[MECH_BODY_LOCATION_RLEG].damageState == IS_DAMAGE_DESTROYED)
  2815. {
  2816. if (body[MECH_BODY_LOCATION_LLEG].damageState == IS_DAMAGE_DESTROYED)
  2817. {
  2818. legStatus = LEG_STATUS_DESTROYED;
  2819. if (pilot && !inRecoverUpdate)
  2820. {
  2821. pilot->triggerAlarm(PILOT_ALARM_VEHICLE_INCAPACITATED, 66);
  2822. }
  2823. }
  2824. else
  2825. {
  2826. if (!sentCrippledMsg && !inRecoverUpdate)
  2827. {
  2828. pilot->radioMessage(RADIO_CRIPPLED);
  2829. legStatus = LEG_STATUS_IMPAIRED_RIGHT;
  2830. sentCrippledMsg = true;
  2831. }
  2832. }
  2833. }
  2834. else if (body[MECH_BODY_LOCATION_LLEG].damageState == IS_DAMAGE_DESTROYED)
  2835. {
  2836. if (!sentCrippledMsg && !inRecoverUpdate)
  2837. {
  2838. pilot->radioMessage(RADIO_CRIPPLED);
  2839. legStatus = LEG_STATUS_IMPAIRED_LEFT;
  2840. sentCrippledMsg = true;
  2841. }
  2842. }
  2843. else
  2844. {
  2845. legStatus = LEG_STATUS_NORMAL;
  2846. }
  2847. return(legStatus);
  2848. }
  2849. //-------------------------------------------------------------------------------------------
  2850. long BattleMech::calcTorsoStatus (void)
  2851. {
  2852. if (body[MECH_BODY_LOCATION_CTORSO].damageState == IS_DAMAGE_PARTIAL)
  2853. torsoStatus = TORSO_STATUS_IMPAIRED;
  2854. else
  2855. torsoStatus = TORSO_STATUS_NORMAL;
  2856. return(torsoStatus);
  2857. }
  2858. //-------------------------------------------------------------------------------------------
  2859. void BattleMech::pilotingCheck (unsigned long situation, float modifier) {
  2860. if (MPlayer && !MPlayer->isServer())
  2861. return;
  2862. if (failedPilotingCheck)
  2863. return;
  2864. float pilotRoll = RandomNumber(100);
  2865. //--------------------
  2866. // Mech's situation...
  2867. // if (situation & PILOTCHECK_SITUATION_JUMPING)
  2868. // pilotRoll += 20.0;
  2869. if (situation & PILOTCHECK_SITUATION_COLLISION)
  2870. pilotRoll += 20.0;
  2871. //---------------------------------
  2872. // If leg(s) gone, it's hopeless...
  2873. if ((body[MECH_BODY_LOCATION_RLEG].curInternalStructure == 0) || (body[MECH_BODY_LOCATION_LLEG].curInternalStructure == 0))
  2874. pilotRoll += 100.0;
  2875. //-----------------
  2876. // Is gyro damaged?
  2877. if (gyro >= (numOther+numWeapons+numAmmos))
  2878. STOP(("Gyro Was not loaded correctly and would have crashed here %d",gyro));
  2879. long gyroHealth = inventory[gyro].health;
  2880. if (gyroHealth == 0)
  2881. pilotRoll += 100.0;
  2882. else if (gyroHealth < getInventoryMax(gyro))
  2883. pilotRoll += 30.0;
  2884. //---------------------------
  2885. // Leg actuator(s) destroyed?
  2886. if (inventory[actuator[ACTUATOR_LHIP]].health == 0)
  2887. pilotRoll += 10.0;
  2888. if (inventory[actuator[ACTUATOR_RHIP]].health == 0)
  2889. pilotRoll += 10.0;
  2890. //----------------
  2891. // Terrain type...
  2892. //long terrainType = GameMap->getTileType(tilePosition[0], tilePosition[1]);
  2893. //-----------------
  2894. // So, did we pass?
  2895. #if 0
  2896. if (situation & PILOTCHECK_SITUATION_JUMPING)
  2897. {
  2898. failedPilotingCheck = (pilotRoll >= pilot->getSkill(MWS_JUMPING) + PilotJumpMod);
  2899. pilot->skillPoints[MWS_JUMPING] += SkillTry[MWS_JUMPING];
  2900. if (!failedPilotingCheck)
  2901. pilot->skillPoints[MWS_JUMPING] += SkillSuccess[MWS_JUMPING];
  2902. }
  2903. else
  2904. #endif
  2905. {
  2906. failedPilotingCheck = (pilotRoll >= pilot->getSkill(MWS_PILOTING));
  2907. pilot->skillPoints[MWS_PILOTING] += SkillTry[MWS_PILOTING];
  2908. if (!failedPilotingCheck)
  2909. pilot->skillPoints[MWS_PILOTING] += SkillSuccess[MWS_PILOTING];
  2910. }
  2911. }
  2912. //-------------------------------------------------------------------------------------------
  2913. bool BattleMech::canPowerUp (void)
  2914. {
  2915. #ifdef USEHEAT
  2916. long heatIndex = (long)heat;
  2917. if (heatIndex > 0)
  2918. {
  2919. if (heatIndex >= NumHeatLevels)
  2920. heatIndex = NumHeatLevels - 1;
  2921. //-------------------------------------------
  2922. // Check if we've cooled enough to restart...
  2923. if (heatIndex >= heatShutdown)
  2924. return(false);
  2925. }
  2926. #endif
  2927. return(true);
  2928. }
  2929. //-------------------------------------------------------------------------------------------
  2930. #ifdef USEHEAT
  2931. void BattleMech::updateHeat (void)
  2932. {
  2933. float heatChange = 0.0;
  2934. if (!isDisabled()) {
  2935. if (((MechActor*)appearance)->currentGestureId == GestureGetUp)
  2936. heatChange += (StandUpHeat * frameLength);
  2937. else
  2938. heatChange += (BodyStateHeat[getBodyState()] * frameLength);
  2939. //----------------------------------------
  2940. // Engine damage may cause heat buildup...
  2941. long numEngineHits = getInventoryDamage(engine);
  2942. if (numEngineHits > 2)
  2943. numEngineHits = 2;
  2944. heatChange += (numEngineHits * 0.6 * frameLength);
  2945. }
  2946. //--------------------------------------------
  2947. // The terrain we're in may affect our heat...
  2948. long terrainHere = GameMap->getTerrain(position);
  2949. switch (terrainHere) {
  2950. case TILE_WATER/*_SHALLOW*/: {
  2951. float heatSinkEffect = (curLegHeatSinks * -0.15);
  2952. if (heatSinkType == HEATSINK_TYPE_DOUBLE)
  2953. heatSinkEffect *= 2.0;
  2954. if (heatSinkEffect < -0.9)
  2955. heatSinkEffect = -0.9;
  2956. heatChange += heatSinkEffect;
  2957. }
  2958. break;
  2959. }
  2960. //---------------------
  2961. // Apply weapon heat...
  2962. for (long weaponIndex = numOther; weaponIndex < (numOther + numWeapons); weaponIndex++)
  2963. if (inventory[weaponIndex].readyTime > scenarioTime) {
  2964. //------------------------------------------
  2965. // Weapon is recycling, so apply the heat...
  2966. heatChange += (inventory[weaponIndex].heatPerSec * frameLength);
  2967. }
  2968. //-------------------------------------------------------------------
  2969. // Now, apply the dissipation amount (never allowing heat to go below
  2970. // zero, of course)...
  2971. heatChange -= (heatDissipation * frameLength * heatSinkEfficiency);
  2972. heat += heatChange;
  2973. if (heat < 0.0)
  2974. heat = 0.0;
  2975. long heatIndex = (long)heat;
  2976. if (!isDisabled()) {
  2977. if (inventory[lifeSupport].disabled) {
  2978. if (heatIndex >= HeatInjuryTable[1][0])
  2979. pilot->injure(HeatInjuryTable[1][1] * frameLength, true);
  2980. else if (heatIndex >= HeatInjuryTable[0][0])
  2981. pilot->injure(HeatInjuryTable[0][1] * frameLength, true);
  2982. }
  2983. }
  2984. //-------------------------------------------------------------------------
  2985. // Now, let's make a HEAT CHECK.
  2986. // NOTE: Disabled vehicles CAN still overheat and explode...
  2987. if ((heatCheckTime < scenarioTime) && !isDisabled())
  2988. {
  2989. if (heatIndex >= NumHeatLevels)
  2990. heatIndex = NumHeatLevels - 1;
  2991. if (heatIndex == 0)
  2992. {
  2993. if (status == OBJECT_STATUS_SHUTDOWN)
  2994. {
  2995. if (pilot->getCurTacOrder()->code != TACTICAL_ORDER_POWERDOWN)
  2996. startUp();
  2997. }
  2998. }
  2999. else if (heatIndex > 0)
  3000. {
  3001. if (status == OBJECT_STATUS_SHUTDOWN)
  3002. {
  3003. if ((pilot->getCurTacOrder()->code != TACTICAL_ORDER_POWERDOWN) && (pilot->getCurTacOrder()->code != TACTICAL_ORDER_POWERUP))
  3004. {
  3005. //-------------------------------------------
  3006. // Check if we've cooled enough to restart...
  3007. if (canPowerUp())
  3008. startUp();
  3009. }
  3010. }
  3011. else
  3012. {
  3013. if ((status != OBJECT_STATUS_DISABLED) && !canPowerUp())
  3014. {
  3015. //-------------
  3016. // Shut Down...
  3017. shutDown();
  3018. pilot->triggerAlarm(PILOT_ALARM_OVERHEAT, heatIndex);
  3019. }
  3020. //----------------------------------------------------------------------------------
  3021. // This can't happen here this way. No randoms!!!!!!!!!!!!!
  3022. // This should set a flag a in ControlData to inform the update to blow the ammo!!
  3023. // In this way, we can still play network MechCommander.
  3024. if (RandomNumber(100) < HeatEffectTable[heatIndex - 1].ammoExplosionChance)
  3025. {
  3026. long numExplodables = 0;
  3027. long ammoList[100];
  3028. for (long ammoIndex = numOther + numWeapons; ammoIndex < (numOther + numWeapons + numAmmos); ammoIndex++)
  3029. {
  3030. if (!inventory[ammoIndex].disabled)
  3031. ammoList[numExplodables++] = ammoIndex;
  3032. }
  3033. if (numExplodables > 0)
  3034. {
  3035. MechControlDataPtr mechCtrlData = (MechControlDataPtr)(control->controlData);
  3036. mechCtrlData->blowAmmo = true;
  3037. mechCtrlData->ammoLocation = ammoList[RandomNumber(numExplodables)];
  3038. }
  3039. }
  3040. }
  3041. }
  3042. heatCheckTime += HeatCheckFrequency;
  3043. }
  3044. }
  3045. #endif
  3046. //-------------------------------------------------------------------------------------------
  3047. void BattleMech::destroy (void)
  3048. {
  3049. if (appearance)
  3050. {
  3051. delete appearance;
  3052. appearance = NULL;
  3053. }
  3054. }
  3055. //---------------------------------------------------------------------------
  3056. long BattleMech::getResourcePointValue (void) {
  3057. long resourcePointsForMechs[15][2] = {
  3058. {30, 1500},
  3059. {35, 1750},
  3060. {40, 2000},
  3061. {45, 2250},
  3062. {50, 3000},
  3063. {55, 3300},
  3064. {60, 3600},
  3065. {65, 3900},
  3066. {70, 4200},
  3067. {75, 5250},
  3068. {80, 5600},
  3069. {85, 5950},
  3070. {90, 6300},
  3071. {95, 6650},
  3072. {100, 7000}
  3073. };
  3074. for (long i = 0; i < 15; i++)
  3075. if (tonnage <= resourcePointsForMechs[i][0])
  3076. return(resourcePointsForMechs[i][1]);
  3077. return(resourcePointsForMechs[14][1]);
  3078. };
  3079. //---------------------------------------------------------------------------
  3080. void BattleMech::mineCheck (void)
  3081. {
  3082. if (MPlayer && !MPlayer->isServer())
  3083. return;
  3084. if (isJumping()) //Can't set 'em off while flying!!
  3085. return;
  3086. //Can't have those damned helicopters setting stuff off.
  3087. if ((getMoveLevel() == 2) && (status != OBJECT_STATUS_SHUTDOWN))
  3088. return;
  3089. //------------------------------------------------------------
  3090. // Must mark the end of the path as desirable or much badness
  3091. // NOT NEEDED ANYMORE. Everyone can see mines all of the time.
  3092. unsigned long mine = 0;
  3093. mine = GameMap->getMine(cellPositionRow, cellPositionCol);
  3094. if (mine == 1)
  3095. {
  3096. //---------------------------
  3097. // Mine here, deal with it...
  3098. if ((tonnage > 35.0f))
  3099. {
  3100. //---------------------------------------------------------
  3101. // Mark this tile as empty. (we just set the mine off!!)
  3102. GameMap->setMine(cellPositionRow, cellPositionCol, 2);
  3103. if (MPlayer)
  3104. MPlayer->addMineChunk(cellPositionRow,
  3105. cellPositionCol,
  3106. 1,
  3107. 2,
  3108. 2);
  3109. pilot->clearCurTacOrder(); //Force the pilot to recalc based on new data.
  3110. //---------------------------
  3111. // Mine here, deal with it...
  3112. Stuff::Vector3D explosionPosition;
  3113. explosionPosition = getPosition();
  3114. ObjectManager->createExplosion(MINE_EXPLOSION_ID, NULL, explosionPosition, MineSplashDamage, MineSplashRange * worldUnitsPerMeter);
  3115. WeaponShotInfo shot;
  3116. shot.init(NULL, -2, MineDamage, calcHitLocation(NULL,-1,ATTACKSOURCE_MINE,0), 0);
  3117. handleWeaponHit(&shot, (MPlayer != NULL));
  3118. }
  3119. }
  3120. }
  3121. //---------------------------------------------------------------------------
  3122. // AI MOVEMENT UPDATE ROUTINES
  3123. //---------------------------------------------------------------------------
  3124. bool BattleMech::updateJump (void) {
  3125. //-----------------------------------------------------------------------------
  3126. // We can turn after lifting off in a jump.
  3127. if (!isJumping())
  3128. return(false);
  3129. if (appearance->isJumpSetup())
  3130. {
  3131. //--------------------------------
  3132. // We should be jumping, dammit...
  3133. if (MPlayer && !MPlayer->isServer())
  3134. {
  3135. //---------------------------------
  3136. // Handled elsewhere, for client...
  3137. if (distanceFrom(jumpGoal) > 8.0)
  3138. {
  3139. appearance->setJumpParameters(jumpGoal);
  3140. appearance->setGestureGoal(6);
  3141. control.settings.mech.throttle = 100;
  3142. }
  3143. }
  3144. else
  3145. {
  3146. //appearance->setJumpParameters(jumpGoal);
  3147. appearance->setGestureGoal(6);
  3148. control.settings.mech.throttle = 100;
  3149. return(true);
  3150. }
  3151. }
  3152. else if (appearance->isJumpAirborne())
  3153. {
  3154. if (!playedJumpSFX)
  3155. {
  3156. playedJumpSFX = true;
  3157. soundSystem->playDigitalSample(JUMPJETS,getPosition(),true);
  3158. }
  3159. /*
  3160. //---------------------------------------------
  3161. float turnRate = 0.0;
  3162. float relFacing = relFacingTo(jumpGoal);
  3163. if ((relFacing < -2.0) || (relFacing > 2.0))
  3164. {
  3165. //-----------------------------------------------
  3166. // We can and will shift facing to destination...
  3167. turnRate = -relFacing * frameLength;
  3168. float maxRate = tonnageTurnRate[long(tonnage)] * frameLength;
  3169. if (turnRate < 0.0f)
  3170. maxRate = -maxRate;
  3171. if (turnRate > 0.0f)
  3172. {
  3173. if (maxRate > turnRate)
  3174. maxRate = turnRate;
  3175. }
  3176. else if (turnRate < 0.0f)
  3177. {
  3178. if (maxRate < turnRate)
  3179. maxRate = turnRate;
  3180. }
  3181. }
  3182. */
  3183. // Do not rotate mech anymore in the jumps!
  3184. // Mech's velocity take it right to point.
  3185. control.settings.mech.rotate = 0.0f;
  3186. return(true);
  3187. }
  3188. else if (!appearance->isInJump())
  3189. {
  3190. //------------------------------------------------------------
  3191. // If we made it into here, then we're at the end of the jump.
  3192. inJump = false;
  3193. playedJumpSFX = false;
  3194. lastJumpTime = scenarioTime;
  3195. MovePathPtr path = pilot->getMovePath();
  3196. //path->numSteps = path->numStepsWhenNotPaused;
  3197. pilot->resumePath();
  3198. path->curStep++;
  3199. //---------------------------------------------------------
  3200. // Let's record our last valid position, in case we need to
  3201. // crawl back from impassable terrain we get knocked onto.
  3202. // Ultimately, this SHOULD NOT be necessary once we agree
  3203. // on a new gesture/movement system... gd 6/2/97
  3204. lastValidPosition = position;
  3205. //----------------------------------------
  3206. // We've landed, so do a piloting check...
  3207. pilotingCheck(PILOTCHECK_SITUATION_JUMPING);
  3208. pilot->getCurTacOrder()->setStage(3); //We're done.
  3209. return(true);
  3210. }
  3211. return(true);
  3212. }
  3213. //---------------------------------------------------------------------------
  3214. bool BattleMech::pivotTo (void) {
  3215. MovePathPtr path = pilot->getMovePath();
  3216. long moveState = pilot->getMoveState();
  3217. long moveStateGoal = pilot->getMoveStateGoal();
  3218. bool isRunning = false;
  3219. if (MPlayer && !MPlayer->isServer())
  3220. isRunning = moveChunk.run;
  3221. else
  3222. isRunning = (pilot->getMovePath()->numStepsWhenNotPaused > 0) && pilot->getMoveRun();
  3223. bool hasTarget = false;
  3224. Stuff::Vector3D targetPosition;
  3225. GameObjectPtr target = pilot->getCurrentTarget();
  3226. float relFacingToTarget = 0.0;
  3227. if (target)
  3228. {
  3229. targetPosition = target->getPosition();
  3230. relFacingToTarget = relFacingTo(targetPosition);
  3231. hasTarget = true;
  3232. }
  3233. else if (pilot->getCurTacOrder()->code == TACTICAL_ORDER_ATTACK_POINT)
  3234. {
  3235. targetPosition = pilot->getAttackTargetPoint();
  3236. relFacingToTarget = relFacingTo(targetPosition);
  3237. hasTarget = true;
  3238. }
  3239. if (moveState == MOVESTATE_PIVOT_FORWARD)
  3240. {
  3241. if ((moveStateGoal == MOVESTATE_PIVOT_FORWARD) || (moveStateGoal == MOVESTATE_FORWARD))
  3242. {
  3243. //----------------------------------------------------------
  3244. // We want to pivot forward (if we have a path to follow)...
  3245. if ((path->numStepsWhenNotPaused > 0) && (path->curStep < path->numStepsWhenNotPaused))
  3246. {
  3247. Stuff::Vector3D wayPt = path->stepList[path->curStep].destination;
  3248. appearance->setGestureGoal(MECH_STATE_STANDING);
  3249. control.settings.mech.throttle = 100;
  3250. float relFacingToWayPt = relFacingTo(wayPt);
  3251. if ((relFacingToWayPt < -5.0) || (relFacingToWayPt > 5.0)) {
  3252. float turnRate = -relFacingToWayPt;
  3253. float maxRate = tonnageTurnRate[long(tonnage)] * frameLength;
  3254. if (turnRate < 0.0f)
  3255. maxRate = -maxRate;
  3256. if (fabs(turnRate) > maxRate) {
  3257. if (turnRate > 0)
  3258. turnRate = maxRate;
  3259. else
  3260. turnRate = -maxRate;
  3261. }
  3262. control.settings.mech.rotate = turnRate;
  3263. control.settings.mech.pivot = true;
  3264. NewRotation = turnRate;
  3265. return(true);
  3266. }
  3267. else
  3268. {
  3269. pilot->setMoveState(MOVESTATE_FORWARD);
  3270. if (pilot->getMoveTwisting())
  3271. pilot->setMoveTwisting(false);
  3272. }
  3273. }
  3274. else
  3275. pilot->setMoveStateGoal(MOVESTATE_FORWARD /*MOVESTATE_STAND*/);
  3276. }
  3277. else
  3278. pilot->setMoveState(MOVESTATE_FORWARD /*MOVESTATE_STAND*/);
  3279. }
  3280. else if (moveState == MOVESTATE_PIVOT_REVERSE)
  3281. {
  3282. if ((moveStateGoal == MOVESTATE_PIVOT_REVERSE) || (moveStateGoal == MOVESTATE_REVERSE))
  3283. {
  3284. //----------------------------------------------------------
  3285. // We want to pivot forward (if we have a path to follow)...
  3286. if ((path->numStepsWhenNotPaused > 0) && (path->curStep < path->numStepsWhenNotPaused))
  3287. {
  3288. Stuff::Vector3D wayPt = path->stepList[path->curStep].destination;
  3289. appearance->setGestureGoal(MECH_STATE_STANDING);
  3290. control.settings.mech.throttle = 100;
  3291. float relFacingToWayPt = relFacingTo(wayPt);
  3292. if ((relFacingToWayPt > -175.0) && (relFacingToWayPt < 175.0)) {
  3293. float turnRate = 0.0;
  3294. if (hasTarget && !isRunning) {
  3295. if (pivotDirection == -1) {
  3296. if (relFacingToTarget < 0)
  3297. pivotDirection = 0;
  3298. else
  3299. pivotDirection = 1;
  3300. }
  3301. if (pivotDirection == 0)
  3302. turnRate = 180.0 - relFacingToWayPt;
  3303. else
  3304. turnRate = -180.0 - relFacingToWayPt;
  3305. }
  3306. else {
  3307. if (relFacingToWayPt < 0)
  3308. turnRate = -180.0 - relFacingToWayPt;
  3309. else
  3310. turnRate = 180.0 - relFacingToWayPt;
  3311. }
  3312. //------------------------------------------------------------------------
  3313. float maxRate = tonnageTurnRate[long(tonnage)] * frameLength;
  3314. if (fabs(turnRate) > maxRate) {
  3315. if (turnRate > 0)
  3316. turnRate = maxRate;
  3317. else
  3318. turnRate = -maxRate;
  3319. }
  3320. control.settings.mech.rotate = turnRate;
  3321. control.settings.mech.pivot = true;
  3322. NewRotation = turnRate;
  3323. return(true);
  3324. }
  3325. else {
  3326. //--------------------------
  3327. // Facing reverse. Now what?
  3328. if (pilot->getMoveTwisting())
  3329. pilot->setMoveTwisting(false);
  3330. if (moveStateGoal == MOVESTATE_REVERSE)
  3331. pilot->setMoveState(MOVESTATE_REVERSE);
  3332. else
  3333. pilot->setMoveStateGoal(MOVESTATE_FORWARD /*MOVESTATE_STAND*/);
  3334. }
  3335. }
  3336. else
  3337. pilot->setMoveStateGoal(MOVESTATE_FORWARD /*MOVESTATE_STAND*/);
  3338. }
  3339. else
  3340. pilot->setMoveState(MOVESTATE_FORWARD /*MOVESTATE_STAND*/);
  3341. }
  3342. else if (moveState == MOVESTATE_PIVOT_TARGET) {
  3343. if (moveStateGoal == MOVESTATE_PIVOT_TARGET) {
  3344. //------------------------------------------
  3345. // We want to pivot to our current target...
  3346. if (isRunning || !hasTarget) {
  3347. pilot->setMoveStateGoal(MOVESTATE_FORWARD /*MOVESTATE_STAND*/);
  3348. if (!pilot->isYielding() && !pilot->isWaitingForPoint())
  3349. pilot->resumePath();
  3350. pivotDirection = -1;
  3351. return(false);
  3352. }
  3353. appearance->setGestureGoal(MECH_STATE_STANDING);
  3354. control.settings.mech.throttle = 100;
  3355. float fireArc = getFireArc();
  3356. if ((relFacingToTarget < -fireArc) || (relFacingToTarget > fireArc)) {
  3357. float turnRate = -relFacingToTarget;
  3358. float maxRate = tonnageTurnRate[long(tonnage)] * frameLength;
  3359. if (fabs(turnRate) > maxRate) {
  3360. if (turnRate > 0)
  3361. turnRate = maxRate;
  3362. else
  3363. turnRate = -maxRate;
  3364. }
  3365. control.settings.mech.rotate = turnRate;
  3366. control.settings.mech.pivot = true;
  3367. NewRotation = turnRate;
  3368. return(true);
  3369. }
  3370. else
  3371. pilot->setMoveStateGoal(MOVESTATE_FORWARD /*MOVESTATE_STAND*/);
  3372. }
  3373. else
  3374. pilot->setMoveState(MOVESTATE_FORWARD /*MOVESTATE_STAND*/);
  3375. }
  3376. else {
  3377. //--------------------------------------------------------
  3378. // If we're supposed to be pivoting, set the move state...
  3379. if ((moveStateGoal == MOVESTATE_PIVOT_TARGET) || (moveStateGoal == MOVESTATE_PIVOT_FORWARD) || (moveStateGoal == MOVESTATE_PIVOT_REVERSE))
  3380. pilot->setMoveState(moveStateGoal);
  3381. }
  3382. if (!pilot->isYielding() && !pilot->isWaitingForPoint())
  3383. pilot->resumePath();
  3384. pivotDirection = -1;
  3385. return(false);
  3386. }
  3387. //---------------------------------------------------------------------------
  3388. long BattleMech::getSpeedState (void) {
  3389. return(mechSpeedStateArray[appearance->getCurrentGestureId()]);
  3390. }
  3391. //---------------------------------------------------------------------------
  3392. void BattleMech::updateMoveStateGoal (void) {
  3393. //----------------------------------------------------------------
  3394. // Have we reached the destination? Make sure we're looking at the
  3395. // right step in the path...
  3396. MovePathPtr path = pilot->getMovePath();
  3397. #if 0
  3398. if (path->numSteps > 0) {
  3399. Stuff::Vector3D wayPt = path->stepList[path->curStep].destination;
  3400. float distanceFromWayPt = distanceFrom(wayPt);
  3401. float cushion = Mover::marginOfError[0];
  3402. if (path->curStep == (path->numSteps - 1))
  3403. cushion = Mover::marginOfError[1];
  3404. if (distanceFromWayPt < cushion) {
  3405. //-------------------------------------------
  3406. // Reached it, so go to the next waypoint...
  3407. //pilot->setMoveTimeOfLastStep(scenarioTime);
  3408. if ((path->curStep + 1) < path->numSteps) {
  3409. long curDir = path->stepList[path->curStep + 1].direction;
  3410. if (curDir > 7) {
  3411. //--------------------------
  3412. // Jump to next path step...
  3413. //newGestureStateGoal = 6;
  3414. //return(false);
  3415. }
  3416. else
  3417. wayPt = path->stepList[path->curStep + 1].destination;
  3418. }
  3419. }
  3420. }
  3421. #endif
  3422. Stuff::Vector3D targetPosition;
  3423. targetPosition.Zero();
  3424. GameObjectPtr target = pilot->getLastTarget();
  3425. bool hasTarget = false;
  3426. if (target) {
  3427. targetPosition = target->getPosition();
  3428. hasTarget = true;
  3429. }
  3430. else if (pilot->getCurTacOrder()->code == TACTICAL_ORDER_ATTACK_POINT) {
  3431. targetPosition = pilot->getAttackTargetPoint();
  3432. hasTarget = true;
  3433. }
  3434. long moveStateGoal = pilot->getMoveStateGoal();
  3435. if (path->numSteps > 0) {
  3436. if (MPlayer && !MPlayer->isServer()) {
  3437. if (moveChunk.run || (legStatus == LEG_STATUS_IMPAIRED_LEFT) || (legStatus == LEG_STATUS_IMPAIRED_RIGHT)) {
  3438. pilot->setMoveStateGoal(MOVESTATE_FORWARD);
  3439. return;
  3440. }
  3441. }
  3442. else {
  3443. if (pilot->getMoveRun() || (legStatus == LEG_STATUS_IMPAIRED_LEFT) || (legStatus == LEG_STATUS_IMPAIRED_RIGHT)) {
  3444. pilot->setMoveStateGoal(MOVESTATE_FORWARD);
  3445. return;
  3446. }
  3447. }
  3448. //----------------------------------------
  3449. // Facing choice for movement goes here...
  3450. if (hasTarget) {
  3451. //------------------------------------------------
  3452. // Check if we want to go forward or in reverse...
  3453. if ((path->numStepsWhenNotPaused > 0) && (path->curStep < path->numStepsWhenNotPaused)) {
  3454. Stuff::Vector3D wayPt = path->stepList[path->curStep].destination;
  3455. float facingDelta = relFacingDelta(wayPt, targetPosition);
  3456. float totalFireArc = getFireArc() + dynamics.max.mech.torsoYaw;
  3457. long moveStateGoal = pilot->getMoveStateGoal();
  3458. if (moveStateGoal == MOVESTATE_FORWARD) {
  3459. if (facingDelta > totalFireArc) {
  3460. if ((180.0 - facingDelta) <= totalFireArc) {
  3461. if (!pilot->getMoveTwisting()) {
  3462. pilot->setMoveTwisting(true);
  3463. pilot->setMoveStateGoal(MOVESTATE_REVERSE);
  3464. }
  3465. }
  3466. }
  3467. }
  3468. else {
  3469. if ((180.0 - facingDelta) > totalFireArc) {
  3470. if (facingDelta <= totalFireArc) {
  3471. if (!pilot->getMoveTwisting()) {
  3472. pilot->setMoveTwisting(true);
  3473. pilot->setMoveStateGoal(MOVESTATE_FORWARD);
  3474. }
  3475. }
  3476. }
  3477. }
  3478. }
  3479. }
  3480. else
  3481. pilot->setMoveStateGoal(MOVESTATE_FORWARD);
  3482. }
  3483. else if ((moveStateGoal != MOVESTATE_PIVOT_TARGET) && (moveStateGoal != MOVESTATE_PIVOT_FORWARD) && (moveStateGoal != MOVESTATE_PIVOT_REVERSE)) {
  3484. if (!hasTarget && (path->numStepsWhenNotPaused == 0))
  3485. pilot->setMoveStateGoal(MOVESTATE_FORWARD);
  3486. }
  3487. }
  3488. //---------------------------------------------------------------------------
  3489. #define DEBUG_MECH_UPDATE 0
  3490. float DistanceToWaypoint;
  3491. bool BattleMech::updateMovePath (float& newRotate, char& newThrottleSetting, long& newGestureStateGoal, long& newMoveState, long& minThrottle, long& maxThrottle, float &facingRotate) {
  3492. DistanceToWaypoint = 9999.0;
  3493. MovePathPtr path = pilot->getMovePath();
  3494. TacticalOrderPtr curOrder = pilot->getCurTacOrder();
  3495. bool allowedToRun = canRun() && pilot->getMoveRun();
  3496. long curThrottleSetting = control.settings.mech.throttle;
  3497. newThrottleSetting = curThrottleSetting;
  3498. newRotate = 0.0;
  3499. #if DEBUG_MECH_UPDATE
  3500. if (selected) {
  3501. long area = GlobalMoveMap->calcArea(objPosition->tileRow, objPosition->tileCol);
  3502. char debugStr[256];
  3503. sprintf(debugStr, "Area = %d\n", area);
  3504. OutputDebugString(debugStr);
  3505. }
  3506. #endif
  3507. updateHustleTime();
  3508. bool hustle = (lastHustleTime + 2.0) > scenarioTime;
  3509. //-----------------------------------------------
  3510. // Am I ahead of my point vehicle, if I have one?
  3511. bool aheadOfPointVehicle = false;
  3512. bool stopForPointVehicle = false;
  3513. MoverPtr pointVehicle = (MoverPtr)pilot->getPoint();
  3514. bool hasGroupMoveOrder = (curOrder->isGroupOrder() && curOrder->isMoveOrder());
  3515. if (!allowedToRun && !hustle && pointVehicle && !pointVehicle->isDisabled() && (pointVehicle != this) && hasGroupMoveOrder) {
  3516. MechWarriorPtr pointPilot = pointVehicle->getPilot();
  3517. float pointDistanceFromGoal = pointPilot->getMoveDistanceLeft();
  3518. float myDistanceFromGoal = pilot->getMoveDistanceLeft();
  3519. aheadOfPointVehicle = (myDistanceFromGoal < pointDistanceFromGoal);
  3520. if (aheadOfPointVehicle) {
  3521. allowedToRun = false;
  3522. if (getSpeedState() == SPEED_STATE_MOVING_FAST) {
  3523. //-------------------------------------------------
  3524. // Running. So, slow to a walk for a few seconds...
  3525. if (!pilot->isWaitingForPoint())
  3526. pilot->setMoveWaitForPointTime(scenarioTime + 5.0);
  3527. }
  3528. else {
  3529. //--------------------------------------------------------------
  3530. // Already walking, so let's just stop until point catches up...
  3531. if (pilot->getMoveWaitForPointTime() < scenarioTime) {
  3532. stopForPointVehicle = true;
  3533. pilot->pausePath(); //path->numSteps = 0;
  3534. pilot->setMoveWaitForPointTime(999999.0);
  3535. }
  3536. }
  3537. }
  3538. else {
  3539. //-------------------
  3540. // No need to wait...
  3541. pilot->setMoveWaitForPointTime(-1.0);
  3542. if (!pilot->isYielding()) {
  3543. pilot->resumePath();
  3544. }
  3545. }
  3546. }
  3547. else {
  3548. pilot->setMoveWaitForPointTime(-1.0);
  3549. }
  3550. //-----------------------------------------------------------------------------
  3551. // May want to call separate updateMovement() routines based upon the legStatus
  3552. // to begin with. For now, we'll handle all cases here...
  3553. bool goalReached = false;
  3554. if ((legStatus == LEG_STATUS_NORMAL) || (legStatus == LEG_STATUS_HURTING) || (legStatus == LEG_STATUS_IMPAIRED_LEFT) || (legStatus == LEG_STATUS_IMPAIRED_RIGHT)) {
  3555. if (path->numSteps > 0) {
  3556. //---------------------------------------------------------------
  3557. // First, make sure we are not already at the end of this path...
  3558. if (path->curStep == path->numSteps)
  3559. goalReached = true;
  3560. else {
  3561. Stuff::Vector3D wayPt = path->stepList[path->curStep].destination;
  3562. //---------------------------------------------------------
  3563. // Let's record our last valid position, in case we need to
  3564. // crawl back from impassable terrain we get knocked onto.
  3565. // Ultimately, this SHOULD NOT be necessary once we agree
  3566. // on a new gesture/movement system... gd 6/2/97
  3567. lastValidPosition = wayPt;
  3568. //---------------------------------
  3569. // Have we reached the destination?
  3570. float distanceFromWayPt = distanceFrom(wayPt);
  3571. DistanceToWaypoint = distanceFromWayPt;
  3572. //--------------------------------------------------
  3573. //Calculate how far the mech will move this frame.
  3574. // Vel is in m/s
  3575. float vel = appearance->getVelocityMagnitude();
  3576. float distanceThisFrame = vel * frameLength;
  3577. float cushion = Mover::marginOfError[0];
  3578. if (path->curStep == (path->numSteps - 1))
  3579. cushion = Mover::marginOfError[1];
  3580. if (cushion < distanceThisFrame)
  3581. {
  3582. //------------------------------------------------------------------------
  3583. //We are going to move farther then the current cushion would allow for.
  3584. // Make the cushion larger.
  3585. // Maybe we should make cushion this value all of the time?
  3586. cushion = distanceThisFrame;
  3587. }
  3588. if (distanceFromWayPt < cushion) {
  3589. //-------------------------------------------
  3590. // Reached it, so go to the next waypoint...
  3591. path->curStep++;
  3592. pilot->setMoveTimeOfLastStep(scenarioTime);
  3593. if (path->curStep < path->numSteps) {
  3594. long curDir = path->stepList[path->curStep].direction;
  3595. if (curDir > 7) {
  3596. //--------------------------
  3597. // Jump to next path step...
  3598. newGestureStateGoal = 6;
  3599. return(false);
  3600. }
  3601. else
  3602. wayPt = path->stepList[path->curStep].destination;
  3603. }
  3604. else
  3605. goalReached = true;
  3606. }
  3607. else {
  3608. //-------------------------------------
  3609. // Not there yet. Should we be jumping?
  3610. long curDir = path->stepList[path->curStep].direction;
  3611. if (curDir > 7) {
  3612. //--------------------------
  3613. // Jump to next path step...
  3614. newGestureStateGoal = 6;
  3615. return(false);
  3616. }
  3617. }
  3618. //MaxVelocityMag = distanceFromWayPt * worldUnitsPerMeter;
  3619. if (!goalReached)
  3620. {
  3621. //---------------------------------------------
  3622. // First, rotate the mech's body (if moving)...
  3623. float relFacingToWayPt = relFacingTo(wayPt, MECH_BODY_LOCATION_LLEG);
  3624. long moveState = pilot->getMoveState();
  3625. long moveStateGoal = pilot->getMoveStateGoal();
  3626. if (moveState == MOVESTATE_FORWARD)
  3627. {
  3628. if (moveStateGoal == MOVESTATE_FORWARD)
  3629. {
  3630. //----------------------
  3631. // Keep going forward...
  3632. if (legStatus == LEG_STATUS_IMPAIRED_LEFT)
  3633. {
  3634. newGestureStateGoal = MECH_STATE_LIMPING_LEFT;
  3635. }
  3636. else if (legStatus == LEG_STATUS_IMPAIRED_RIGHT)
  3637. {
  3638. newGestureStateGoal = MECH_STATE_LIMPING_RIGHT;
  3639. }
  3640. else if (allowedToRun)
  3641. {
  3642. newGestureStateGoal = MECH_STATE_RUNNING;
  3643. }
  3644. else
  3645. newGestureStateGoal = MECH_STATE_WALKING;
  3646. if ((relFacingToWayPt < -5.0) || (relFacingToWayPt > 5.0))
  3647. {
  3648. //-----------------------------------------------
  3649. // We can and will shift facing to destination...
  3650. // Don't know that we need to force walk to turn!!
  3651. // -fs
  3652. newRotate = -relFacingToWayPt;
  3653. float maxRate = tonnageTurnRate[long(tonnage)] * frameLength;
  3654. if (fabs(newRotate) > maxRate)
  3655. {
  3656. if (fabs(newRotate) < 50.0f)
  3657. newThrottleSetting = 100.0f - fabs(newRotate);
  3658. else
  3659. newThrottleSetting = 0.0f;
  3660. if (newRotate > 0.0)
  3661. newRotate = maxRate;
  3662. else
  3663. newRotate = -maxRate;
  3664. }
  3665. else
  3666. {
  3667. //------------------------------------
  3668. // Try to attain current goal speed...
  3669. newThrottleSetting = pilot->calcMoveSpeedThrottle(getBodyState(), control.settings.mech.throttle);
  3670. }
  3671. }
  3672. else
  3673. newThrottleSetting = 100.0f;
  3674. }
  3675. else if (moveStateGoal == MOVESTATE_REVERSE) {
  3676. //---------------------------------------------------
  3677. // Stop, and pivot fully reverse to next path step...
  3678. //((MechActor*)appearance)->forceStop();
  3679. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  3680. newMoveState = MOVESTATE_PIVOT_REVERSE;
  3681. }
  3682. else if (moveStateGoal == MOVESTATE_PIVOT_FORWARD) {
  3683. //---------------------------------------------------
  3684. // Stop, and pivot fully forward to next path step...
  3685. //((MechActor*)appearance)->forceStop();
  3686. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  3687. newMoveState = MOVESTATE_PIVOT_FORWARD;
  3688. }
  3689. else if (moveStateGoal == MOVESTATE_PIVOT_REVERSE) {
  3690. //---------------------------------------------------
  3691. // Stop, and pivot fully reverse to next path step...
  3692. //((MechActor*)appearance)->forceStop();
  3693. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  3694. newMoveState = MOVESTATE_PIVOT_REVERSE;
  3695. }
  3696. else {
  3697. //--------
  3698. // Stop...
  3699. //((MechActor*)appearance)->forceStop();
  3700. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  3701. newMoveState = MOVESTATE_FORWARD /*MOVESTATE_STAND*/;
  3702. }
  3703. }
  3704. else if (moveState == MOVESTATE_REVERSE)
  3705. {
  3706. if (moveStateGoal == MOVESTATE_FORWARD)
  3707. {
  3708. //---------------------------------------------------
  3709. // Stop, and pivot fully forward to next path step...
  3710. //((MechActor*)appearance)->forceStop();
  3711. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  3712. newMoveState = MOVESTATE_PIVOT_FORWARD;
  3713. }
  3714. else if (moveStateGoal == MOVESTATE_REVERSE)
  3715. {
  3716. newGestureStateGoal = MECH_STATE_REVERSE;
  3717. //--------------------------
  3718. // Keep moving in reverse...
  3719. if (relFacingToWayPt < 0)
  3720. newRotate = -(relFacingToWayPt + 180.0);
  3721. else
  3722. newRotate = -(relFacingToWayPt - 180.0);
  3723. //-----------------------------------------------
  3724. // We can and will shift facing to destination...
  3725. // Don't know that we need to force walk to turn!!
  3726. // -fs
  3727. float maxRate = tonnageTurnRate[long(tonnage)] * frameLength;
  3728. if (fabs(newRotate) > maxRate)
  3729. {
  3730. if (fabs(newRotate) < 50.0f)
  3731. newThrottleSetting = 100.0f - fabs(newRotate);
  3732. else
  3733. newThrottleSetting = 0.0f;
  3734. if (newRotate > 0.0)
  3735. newRotate = maxRate;
  3736. else
  3737. newRotate = -maxRate;
  3738. }
  3739. else
  3740. {
  3741. //------------------------------------
  3742. // Try to attain current goal speed...
  3743. newThrottleSetting = pilot->calcMoveSpeedThrottle(getBodyState(), control.settings.mech.throttle);
  3744. }
  3745. }
  3746. else if (moveStateGoal == MOVESTATE_PIVOT_FORWARD)
  3747. {
  3748. //---------------------------------------------------
  3749. // Stop, and pivot fully forward to next path step...
  3750. //((MechActor*)appearance)->forceStop();
  3751. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  3752. newMoveState = MOVESTATE_PIVOT_FORWARD;
  3753. }
  3754. else if (moveStateGoal == MOVESTATE_PIVOT_REVERSE)
  3755. {
  3756. //---------------------------------------------------
  3757. // Stop, and pivot fully reverse to next path step...
  3758. //((MechActor*)appearance)->forceStop();
  3759. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  3760. newMoveState = MOVESTATE_PIVOT_REVERSE;
  3761. }
  3762. else
  3763. {
  3764. //--------
  3765. // Stop...
  3766. //((MechActor*)appearance)->forceStop();
  3767. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  3768. newMoveState = MOVESTATE_FORWARD /*MOVESTATE_STAND*/;
  3769. }
  3770. }
  3771. else
  3772. {
  3773. //--------------------------
  3774. // Not moving--should we be?
  3775. if ((moveStateGoal == MOVESTATE_FORWARD) || (moveStateGoal == MOVESTATE_PIVOT_FORWARD))
  3776. {
  3777. //((MechActor*)appearance)->forceStop();
  3778. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  3779. newMoveState = MOVESTATE_PIVOT_FORWARD;
  3780. }
  3781. else if ((moveStateGoal == MOVESTATE_REVERSE) || (moveStateGoal == MOVESTATE_PIVOT_REVERSE))
  3782. {
  3783. //((MechActor*)appearance)->forceStop();
  3784. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  3785. newMoveState = MOVESTATE_PIVOT_REVERSE;
  3786. }
  3787. }
  3788. }
  3789. }
  3790. }
  3791. else
  3792. {
  3793. //-------------------------------------------
  3794. // We better not be walking or running, then!
  3795. newGestureStateGoal = MECH_STATE_STANDING;
  3796. }
  3797. }
  3798. else
  3799. {
  3800. //---------------------
  3801. // Cannot move, period!
  3802. newGestureStateGoal = MECH_STATE_STANDING;
  3803. }
  3804. if (goalReached)
  3805. {
  3806. //--------------------------------------------------
  3807. // Did we finish just a local part of a global path?
  3808. if (pilot->getMovePathType() == MOVEPATH_COMPLEX)
  3809. {
  3810. if (pilot->getMovePathGlobalStep() < (pilot->getMoveNumGlobalSteps() - 1))
  3811. {
  3812. //-----------------------------------------------------------
  3813. // We've reached the end of our current short-range path, but
  3814. // we have more to go before we've reached our long-range
  3815. // goal, so calc our next short-range path...
  3816. goalReached = false;
  3817. }
  3818. }
  3819. pilot->clearMovePath(0);
  3820. }
  3821. return(goalReached);
  3822. }
  3823. //---------------------------------------------------------------------------
  3824. void BattleMech::setNextMovePath (char& newThrottleSetting, long& newGestureStateGoal) {
  3825. //----------------------------------------
  3826. // If this is only an intermediate path,
  3827. // let's check where we need to go next...
  3828. //pilot->clearMovePath(ORDER_CURRENT);
  3829. Stuff::Vector3D nextWayPoint;
  3830. bool haveWayPoint = pilot->getNextWayPoint(nextWayPoint, true);
  3831. if (haveWayPoint) {
  3832. pilot->setMoveGoal(MOVEGOAL_LOCATION, &nextWayPoint);
  3833. TacticalOrderPtr curTacOrder = pilot->getCurTacOrder();
  3834. pilot->requestMovePath(curTacOrder->selectionIndex, MOVEPARAM_FACE_TARGET/*+MOVEPARAM_INIT*/, 1);
  3835. }
  3836. else {
  3837. //-----------------------------------------------------------
  3838. // This may be a hack--do we want to be able to follow moving
  3839. // objects that we don't necessarily have tracked? We will
  3840. // for now...
  3841. //GameObjectPtr moveGoalObject = NULL;
  3842. //long goalType = pilot->getMoveGoal(ORDER_CURRENT, NULL, &moveGoalObject);
  3843. //pilot->setMoveGoal(ORDER_CURRENT, MOVEGOAL_NONE, NULL);
  3844. pilot->clearMoveOrders();
  3845. newGestureStateGoal = MECH_STATE_STANDING;
  3846. }
  3847. }
  3848. //---------------------------------------------------------------------------
  3849. void BattleMech::updateTorso (float newRotatePerSec)
  3850. {
  3851. //---------------------------------------------------
  3852. // Now, rotate the torso toward our current target...
  3853. float torsoRelFacing = 0.0;
  3854. GameObjectPtr target = pilot->getCurrentTarget();
  3855. rotateValues[0] = target ? relFacingTo(target->getPosition()) : 0.0;
  3856. rotateValues[1] = torsoRotation;
  3857. rotateValues[2] = newRotatePerSec;
  3858. if (target)
  3859. torsoRelFacing = relFacingTo(target->getPosition()) + torsoRotation + newRotatePerSec;
  3860. else if (pilot->getCurTacOrder()->code == TACTICAL_ORDER_ATTACK_POINT)
  3861. torsoRelFacing = relFacingTo(pilot->getAttackTargetPoint()) + torsoRotation + newRotatePerSec;
  3862. else
  3863. torsoRelFacing = torsoRotation;
  3864. rotateValues[3] = torsoRelFacing;
  3865. //if (torsoRelFacing < -180.0)
  3866. // torsoRelFacing += 360.0;
  3867. //else if (torsoRelFacing > 180)
  3868. // torsoRelFacing -= 360.0;
  3869. rotateValues[4] = torsoRelFacing;
  3870. //if (torsoRelFacing < -180.0)
  3871. // Assert(0, 0, "oops");
  3872. //else if (torsoRelFacing > 180)
  3873. // Assert(0, 0, "oops");
  3874. float fireArc = getFireArc();
  3875. if ((torsoRelFacing < -fireArc) || (torsoRelFacing > fireArc))
  3876. {
  3877. float turnRate = -torsoRelFacing;
  3878. rotateValues[5] = turnRate;
  3879. //-----------------------------------------------
  3880. // We can and will shift facing to destination...
  3881. float maxRate = (float)dynamics.max.mech.torsoYawRate * frameLength;
  3882. if (fabs(turnRate) > maxRate) {
  3883. if (turnRate < 0.0)
  3884. turnRate = -maxRate;
  3885. else
  3886. turnRate = maxRate;
  3887. }
  3888. control.settings.mech.rotateTorso = turnRate;
  3889. }
  3890. /*
  3891. if (target && CombatLog) {
  3892. static char moveStateChar[NUM_MOVESTATES] = {' ', ' ', ' ', '*', '*', '*'};
  3893. static char s[512];
  3894. sprintf(s, "TORSO ROTATE: %-15s %-06d %-05d %-5c, relF = %-06d torR = %06d nRot = %06d torRF = %06d(%06d) turnR = %06d",
  3895. getName(),
  3896. target->getWatchID(),
  3897. turn,
  3898. moveStateChar[getMoveState()],
  3899. (long)rotateValues[0],
  3900. (long)rotateValues[1],
  3901. (long)rotateValues[2],
  3902. (long)rotateValues[3],
  3903. (long)rotateValues[4],
  3904. (long)rotateValues[5]);
  3905. CombatLog->write(s);
  3906. CombatLog->write(" ");
  3907. }
  3908. */
  3909. }
  3910. //---------------------------------------------------------------------------
  3911. void BattleMech::setControlSettings (float& newRotate, char& newThrottleSetting, long& newGestureStateGoal, long& minThrottle, long& maxThrottle, float &facingRotate) {
  3912. //-----------------------------------------
  3913. // Clean up and handle any jump settings...
  3914. if (inJump && !appearance->isInJump()) {
  3915. inJump = false;
  3916. //MovePathPtr path = pilot->getMovePath();
  3917. //path->numSteps = path->numStepsWhenNotPaused;
  3918. pilot->resumePath();
  3919. }
  3920. if (newGestureStateGoal == 6) {
  3921. MovePathPtr path = pilot->getMovePath();
  3922. pilot->pausePath(); //path->numSteps = 0;
  3923. jumpGoal = path->stepList[path->curStep].destination;
  3924. appearance->setJumpParameters(jumpGoal);
  3925. }
  3926. if (MPlayer && !MPlayer->isServer()) {
  3927. if (statusChunk.jumpOrder && !inJump) {
  3928. land->cellToWorld(statusChunk.targetCellRC[0], statusChunk.targetCellRC[1], jumpGoal);
  3929. if (distanceFrom(jumpGoal) > 8.0) {
  3930. newGestureStateGoal = 6;
  3931. appearance->setJumpParameters(jumpGoal);
  3932. }
  3933. }
  3934. }
  3935. else {
  3936. if (pilot->getCurTacOrder()->isJumpOrder() && !inJump) {
  3937. newGestureStateGoal = 6;
  3938. jumpGoal.x = pilot->getCurTacOrder()->moveParams.wayPath.points[0];
  3939. jumpGoal.y = pilot->getCurTacOrder()->moveParams.wayPath.points[1];
  3940. jumpGoal.z = pilot->getCurTacOrder()->moveParams.wayPath.points[2];
  3941. appearance->setJumpParameters(jumpGoal);
  3942. }
  3943. }
  3944. if (newGestureStateGoal != -1)
  3945. {
  3946. control.settings.mech.gestureGoal = newGestureStateGoal;
  3947. //appearance->setGestureGoal(newGestureStateGoal);
  3948. switch (newGestureStateGoal) {
  3949. case 6:
  3950. control.settings.mech.throttle = 100.0f;
  3951. inJump = true;
  3952. break;
  3953. case MECH_STATE_WALKING:
  3954. if (newThrottleSetting != -1) {
  3955. if (newThrottleSetting < minThrottle)
  3956. newThrottleSetting = minThrottle;
  3957. else if (newThrottleSetting > maxThrottle)
  3958. newThrottleSetting = maxThrottle;
  3959. control.settings.mech.throttle = newThrottleSetting;
  3960. }
  3961. break;
  3962. default:
  3963. control.settings.mech.throttle = newThrottleSetting;
  3964. }
  3965. }
  3966. if (newRotate != 0.0f)
  3967. control.settings.mech.rotate = newRotate;
  3968. if (facingRotate != 0.0f)
  3969. control.settings.mech.facingRotate = facingRotate;
  3970. }
  3971. //---------------------------------------------------------------------------
  3972. void BattleMech::startShutDown (void)
  3973. {
  3974. appearance->setGesture(0); //Force us to parked
  3975. shutDownThisFrame = false;
  3976. startUpThisFrame = false;
  3977. setStatus(OBJECT_STATUS_SHUTDOWN);
  3978. sensorSystem->setShutdown(true);
  3979. }
  3980. //---------------------------------------------------------------------------
  3981. void BattleMech::updateMovement (void) {
  3982. long minThrottle = 35;
  3983. long maxThrottle = 100;
  3984. NewRotation = 0.0;
  3985. if (disableThisFrame)
  3986. {
  3987. long fallGesture = RandomNumber(2) ? MECH_STATE_FALLEN_FORWARD : MECH_STATE_FALLEN_BACKWARD;
  3988. if (hitFromBehindThisFrame)
  3989. fallGesture = MECH_STATE_FALLEN_FORWARD;
  3990. else if (hitFromFrontThisFrame)
  3991. fallGesture = MECH_STATE_FALLEN_BACKWARD;
  3992. appearance->setGestureGoal(fallGesture);
  3993. //---------------------------------------------------------
  3994. // If we just switched to running, we need to make sure the
  3995. // throttle is set to max...
  3996. disableThisFrame = false;
  3997. //------------------------------------------------------
  3998. // In case we shut down this frame, as well, clear it...
  3999. shutDownThisFrame = false;
  4000. startUpThisFrame = false;
  4001. hitFromFrontThisFrame = false;
  4002. hitFromBehindThisFrame = false;
  4003. control.settings.mech.throttle = maxThrottle;
  4004. return;
  4005. }
  4006. if (shutDownThisFrame)
  4007. {
  4008. //Confusing, but is used to display the helicopter dust cloud.
  4009. // Could also use as a fall dust cloud?
  4010. if (getMoveType() == MOVETYPE_AIR)
  4011. appearance->playEjection();
  4012. appearance->setGestureGoal(MECH_STATE_PARKED);
  4013. if ((scenarioTime > 8.0) || (getTeam() == Team::home))
  4014. {
  4015. if (getMoveType() != MOVETYPE_AIR)
  4016. soundSystem->playDigitalSample(POWERDOWN_SFX,getPosition());
  4017. else
  4018. soundSystem->playDigitalSample(COPTER_POWERUP,getPosition());
  4019. }
  4020. shutDownThisFrame = false;
  4021. startUpThisFrame = false;
  4022. setStatus(OBJECT_STATUS_SHUTDOWN);
  4023. control.settings.mech.throttle = maxThrottle;
  4024. sensorSystem->setShutdown(true);
  4025. return;
  4026. }
  4027. long gID = appearance->getCurrentGestureId();
  4028. if (pilot && pilot->getCurTacOrder()->code == TACTICAL_ORDER_POWERUP) {
  4029. if (gID != 2)
  4030. appearance->setGestureGoal(MECH_STATE_STANDING);
  4031. else //Otherwise, we were ordered to powerUp and we are. Clear iT!!
  4032. pilot->clearCurTacOrder();
  4033. }
  4034. if (startUpThisFrame)
  4035. {
  4036. //Confusing, but is used to display the helicopter dust cloud.
  4037. // Could also use as a fall dust cloud?
  4038. if (getMoveType() == MOVETYPE_AIR)
  4039. appearance->playEjection();
  4040. if (getMoveType() != MOVETYPE_AIR)
  4041. soundSystem->playDigitalSample(POWERUP_SFX,getPosition());
  4042. else
  4043. soundSystem->playDigitalSample(COPTER_POWERDN,getPosition());
  4044. startUpThisFrame = false;
  4045. shutDownThisFrame = false;
  4046. setStatus(OBJECT_STATUS_NORMAL);
  4047. control.settings.mech.throttle = maxThrottle;
  4048. if (useSound && !MPlayer && Team::home->isEnemy(getTeam()) && (getMoveType() != MOVETYPE_AIR))
  4049. soundSystem->playBettySample(BETTY_POWERUP);
  4050. sensorSystem->setShutdown(false);
  4051. return;
  4052. }
  4053. if ((status == OBJECT_STATUS_SHUTTING_DOWN) ||
  4054. (status == OBJECT_STATUS_SHUTDOWN) ||
  4055. (status == OBJECT_STATUS_DISABLED))
  4056. return;
  4057. if (isCaptured())
  4058. return;
  4059. if (engineBlowTime > -1.0)
  4060. return;
  4061. if (failedPilotingCheck && (getMoveType() != MOVETYPE_AIR)) {
  4062. long fallGesture = RandomNumber(2) ? MECH_STATE_FALLEN_FORWARD : MECH_STATE_FALLEN_BACKWARD;
  4063. if (hitFromBehindThisFrame)
  4064. fallGesture = MECH_STATE_FALLEN_FORWARD;
  4065. else if (hitFromFrontThisFrame)
  4066. fallGesture = MECH_STATE_FALLEN_BACKWARD;
  4067. appearance->setGestureGoal(fallGesture);
  4068. failedPilotingCheck = false;
  4069. control.settings.mech.throttle = maxThrottle;
  4070. return;
  4071. }
  4072. if (updateJump())
  4073. return;
  4074. if (pivotTo())
  4075. return;
  4076. float newRotate = 0.0;
  4077. float facingRotate = 0.0f;
  4078. long newGestureStateGoal = -1;
  4079. long newMoveState = -1;
  4080. char newThrottleSetting = -1;
  4081. bool goalReached = false;
  4082. goalReached = updateMovePath(newRotate, newThrottleSetting, newGestureStateGoal, newMoveState, minThrottle, maxThrottle, facingRotate);
  4083. if (goalReached)
  4084. setNextMovePath(newThrottleSetting, newGestureStateGoal);
  4085. if (newMoveState != -1)
  4086. pilot->setMoveState(newMoveState);
  4087. setControlSettings(newRotate, newThrottleSetting, newGestureStateGoal, minThrottle, maxThrottle,facingRotate);
  4088. updateMoveStateGoal();
  4089. NewRotation = newRotate;
  4090. }
  4091. //---------------------------------------------------------------------------
  4092. // NETWORK MOVEMENT UPDATE ROUTINES
  4093. //---------------------------------------------------------------------------
  4094. bool BattleMech::netUpdateMovePath (float& newRotate, char& newThrottleSetting, long& newGestureStateGoal, long& newMoveState, long& minThrottle, long& maxThrottle) {
  4095. DistanceToWaypoint = 9999.0;
  4096. MovePathPtr path = pilot->getMovePath();
  4097. bool allowedToRun = canRun() && moveChunk.run;
  4098. long curThrottleSetting = control.settings.mech.throttle;
  4099. newThrottleSetting = curThrottleSetting;
  4100. newRotate = 0.0;
  4101. bool goalReached = false;
  4102. if ((legStatus == LEG_STATUS_NORMAL) || (legStatus == LEG_STATUS_HURTING) || (legStatus == LEG_STATUS_IMPAIRED_LEFT) || (legStatus == LEG_STATUS_IMPAIRED_RIGHT)) {
  4103. if (path->numSteps > 0) {
  4104. //---------------------------------------------------------------
  4105. // First, make sure we are not already at the end of this path...
  4106. if (path->curStep == path->numSteps)
  4107. goalReached = true;
  4108. else {
  4109. Stuff::Vector3D wayPt = path->stepList[path->curStep].destination;
  4110. //---------------------------------------------------------
  4111. // Let's record our last valid position, in case we need to
  4112. // crawl back from impassable terrain we get knocked onto.
  4113. // Ultimately, this SHOULD NOT be necessary once we agree
  4114. // on a new gesture/movement system... gd 6/2/97
  4115. lastValidPosition = wayPt;
  4116. //---------------------------------
  4117. // Have we reached the destination?
  4118. float distanceFromWayPt = distanceFrom(wayPt);
  4119. DistanceToWaypoint = distanceFromWayPt;
  4120. float cushion = Mover::marginOfError[0];
  4121. if (path->curStep == (path->numSteps - 1))
  4122. cushion = Mover::marginOfError[1];
  4123. if (distanceFromWayPt < cushion) {
  4124. //-------------------------------------------
  4125. // Reached it, so go to the next waypoint...
  4126. path->curStep++;
  4127. pilot->setMoveTimeOfLastStep(scenarioTime);
  4128. if (path->curStep < path->numSteps) {
  4129. long curDir = path->stepList[path->curStep].direction;
  4130. if (!MPlayer && (curDir > 7)) {
  4131. //--------------------------
  4132. // Jump to next path step...
  4133. newGestureStateGoal = 6;
  4134. return(false);
  4135. }
  4136. else
  4137. wayPt = path->stepList[path->curStep].destination;
  4138. }
  4139. else
  4140. goalReached = true;
  4141. }
  4142. else {
  4143. //-------------------------------------
  4144. // Not there yet. Should we be jumping?
  4145. long curDir = path->stepList[path->curStep].direction;
  4146. if (!MPlayer && (curDir > 7)) {
  4147. //--------------------------
  4148. // Jump to next path step...
  4149. newGestureStateGoal = 6;
  4150. return(false);
  4151. }
  4152. }
  4153. //MaxVelocityMag = distanceFromWayPt * worldUnitsPerMeter;
  4154. if (!goalReached) {
  4155. //---------------------------------------------
  4156. // First, rotate the mech's body (if moving)...
  4157. float relFacingToWayPt = relFacingTo(wayPt, MECH_BODY_LOCATION_LLEG);
  4158. long moveState = pilot->getMoveState();
  4159. long moveStateGoal = pilot->getMoveStateGoal();
  4160. if (moveState == MOVESTATE_FORWARD) {
  4161. if (moveStateGoal == MOVESTATE_FORWARD) {
  4162. //----------------------
  4163. // Keep going forward...
  4164. if (legStatus == LEG_STATUS_IMPAIRED_LEFT) {
  4165. newGestureStateGoal = MECH_STATE_LIMPING_LEFT;
  4166. newThrottleSetting = 100;
  4167. }
  4168. else if (legStatus == LEG_STATUS_IMPAIRED_RIGHT) {
  4169. newGestureStateGoal = MECH_STATE_LIMPING_RIGHT;
  4170. newThrottleSetting = 100;
  4171. }
  4172. else if (allowedToRun) {
  4173. newThrottleSetting = 100;
  4174. newGestureStateGoal = MECH_STATE_RUNNING;
  4175. }
  4176. else
  4177. newGestureStateGoal = MECH_STATE_WALKING;
  4178. if ((relFacingToWayPt < -5.0) || (relFacingToWayPt > 5.0)) {
  4179. //-----------------------------------------------
  4180. // We can and will shift facing to destination...
  4181. // Don't know that we need to force walk to turn!!
  4182. // -fs
  4183. newRotate = -relFacingToWayPt;
  4184. float maxRate = tonnageTurnRate[long(tonnage)] * frameLength;
  4185. if (fabs(newRotate) > maxRate) {
  4186. if (newRotate > 0.0)
  4187. newRotate = maxRate;
  4188. else
  4189. newRotate = -maxRate;
  4190. }
  4191. else {
  4192. if (newGestureStateGoal == MECH_STATE_WALKING) {
  4193. //------------------------------------
  4194. // Try to attain current goal speed...
  4195. newThrottleSetting = pilot->calcMoveSpeedThrottle(getBodyState(), control.settings.mech.throttle);
  4196. }
  4197. }
  4198. }
  4199. }
  4200. else if (moveStateGoal == MOVESTATE_REVERSE) {
  4201. //---------------------------------------------------
  4202. // Stop, and pivot fully reverse to next path step...
  4203. //((MechActor*)appearance)->forceStop();
  4204. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  4205. newMoveState = MOVESTATE_PIVOT_REVERSE;
  4206. }
  4207. else if (moveStateGoal == MOVESTATE_PIVOT_FORWARD) {
  4208. //---------------------------------------------------
  4209. // Stop, and pivot fully forward to next path step...
  4210. //((MechActor*)appearance)->forceStop();
  4211. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  4212. newMoveState = MOVESTATE_PIVOT_FORWARD;
  4213. }
  4214. else if (moveStateGoal == MOVESTATE_PIVOT_REVERSE) {
  4215. //---------------------------------------------------
  4216. // Stop, and pivot fully reverse to next path step...
  4217. //((MechActor*)appearance)->forceStop();
  4218. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  4219. newMoveState = MOVESTATE_PIVOT_REVERSE;
  4220. }
  4221. else {
  4222. //--------
  4223. // Stop...
  4224. //((MechActor*)appearance)->forceStop();
  4225. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  4226. newMoveState = MOVESTATE_FORWARD /*MOVESTATE_STAND*/;
  4227. }
  4228. }
  4229. else if (moveState == MOVESTATE_REVERSE) {
  4230. if (moveStateGoal == MOVESTATE_FORWARD) {
  4231. //---------------------------------------------------
  4232. // Stop, and pivot fully forward to next path step...
  4233. //((MechActor*)appearance)->forceStop();
  4234. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  4235. newMoveState = MOVESTATE_PIVOT_FORWARD;
  4236. }
  4237. else if (moveStateGoal == MOVESTATE_REVERSE) {
  4238. newGestureStateGoal = MECH_STATE_REVERSE;
  4239. //--------------------------
  4240. // Keep moving in reverse...
  4241. /*
  4242. if ((relFacingToWayPt < -5.0) || (relFacingToWayPt > 5.0))
  4243. {
  4244. //-----------------------------------------------
  4245. // We can and will shift facing to destination...
  4246. float maxRate = dyn->maxMechYawRate;
  4247. if (relFacingToWayPt < 0.0)
  4248. newTurnRate = maxRate*frameLength;
  4249. else
  4250. newTurnRate = -maxRate*frameLength;
  4251. relFacingToWayPt = -(relFacingToWayPt + 180.0);
  4252. if (relFacingToWayPt > 0.0)
  4253. relFacingToWayPt = -(relFacingToWayPt - 180.0);
  4254. if ((newTurnRate > 0.0) && (newTurnRate > relFacingToWayPt))
  4255. newTurnRate = relFacingToWayPt;
  4256. else if ((newTurnRate > 0.0) && (newTurnRate < relFacingToWayPt))
  4257. newTurnRate = relFacingToWayPt;
  4258. else
  4259. {
  4260. if (newGestureStateGoal == MECH_STATE_WALKING) {
  4261. //------------------------------------
  4262. // Try to attain current goal speed...
  4263. newThrottleSetting = pilot->calcMoveSpeedThrottle(getBodyState(), data->throttleSetting);
  4264. }
  4265. }
  4266. newMechYaw = newTurnRate;
  4267. }
  4268. */
  4269. if (relFacingToWayPt < 0)
  4270. newRotate = -(relFacingToWayPt + 180.0);
  4271. else
  4272. newRotate = -(relFacingToWayPt - 180.0);
  4273. float maxRate = tonnageTurnRate[long(tonnage)] * frameLength;
  4274. if (fabs(newRotate) > maxRate) {
  4275. if (newRotate > 0.0)
  4276. newRotate = maxRate;
  4277. else
  4278. newRotate = -maxRate;
  4279. newThrottleSetting = control.settings.mech.throttle - 10;
  4280. }
  4281. else {
  4282. //------------------------------------
  4283. // Try to attain current goal speed...
  4284. newThrottleSetting = pilot->calcMoveSpeedThrottle(getBodyState(), control.settings.mech.throttle);
  4285. //newThrottleSetting = data->throttleSetting + 10;
  4286. }
  4287. }
  4288. else if (moveStateGoal == MOVESTATE_PIVOT_FORWARD) {
  4289. //---------------------------------------------------
  4290. // Stop, and pivot fully forward to next path step...
  4291. //((MechActor*)appearance)->forceStop();
  4292. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  4293. newMoveState = MOVESTATE_PIVOT_FORWARD;
  4294. }
  4295. else if (moveStateGoal == MOVESTATE_PIVOT_REVERSE) {
  4296. //---------------------------------------------------
  4297. // Stop, and pivot fully reverse to next path step...
  4298. //((MechActor*)appearance)->forceStop();
  4299. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  4300. newMoveState = MOVESTATE_PIVOT_REVERSE;
  4301. }
  4302. else {
  4303. //--------
  4304. // Stop...
  4305. //((MechActor*)appearance)->forceStop();
  4306. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  4307. newMoveState = MOVESTATE_FORWARD /*MOVESTATE_STAND*/;
  4308. }
  4309. }
  4310. else {
  4311. //--------------------------
  4312. // Not moving--should we be?
  4313. if ((moveStateGoal == MOVESTATE_FORWARD) || (moveStateGoal == MOVESTATE_PIVOT_FORWARD)) {
  4314. //((MechActor*)appearance)->forceStop();
  4315. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  4316. newMoveState = MOVESTATE_PIVOT_FORWARD;
  4317. }
  4318. else if ((moveStateGoal == MOVESTATE_REVERSE) || (moveStateGoal == MOVESTATE_PIVOT_REVERSE)) {
  4319. //((MechActor*)appearance)->forceStop();
  4320. pilot->pausePath(); //pilot->getMovePath()->numSteps = 0;
  4321. newMoveState = MOVESTATE_PIVOT_REVERSE;
  4322. }
  4323. }
  4324. }
  4325. }
  4326. }
  4327. else {
  4328. //-------------------------------------------
  4329. // We better not be walking or running, then!
  4330. newGestureStateGoal = MECH_STATE_STANDING;
  4331. }
  4332. }
  4333. else {
  4334. //---------------------
  4335. // Cannot move, period!
  4336. newGestureStateGoal = MECH_STATE_STANDING;
  4337. }
  4338. return(goalReached);
  4339. }
  4340. //---------------------------------------------------------------------------
  4341. void BattleMech::netUpdateMovement (void) {
  4342. long minThrottle = 35;
  4343. long maxThrottle = 100;
  4344. long bodyState = getBodyState();
  4345. MovePathPtr path = pilot->getMovePath();
  4346. bool atEndOfPath = (path->curStep == (path->numSteps - 1)); //was >=
  4347. Stuff::Vector3D wayPt;
  4348. float distanceFromWayPt = 1000000.0;
  4349. if ((path->curStep > -1) && (path->curStep < path->numSteps)) {
  4350. wayPt = path->stepList[path->curStep].destination;
  4351. distanceFromWayPt = distanceFrom(wayPt);
  4352. }
  4353. if (moveChunk.moving && /*(path->numStepsWhenNotPaused > 0) &&*/ (bodyState == MECH_STATUSCHUNK_BODYSTATE_PARKED))
  4354. startUpThisFrame = true;
  4355. // MECH_STATUSCHUNK_BODYSTATE_NORMAL,
  4356. // MECH_STATUSCHUNK_BODYSTATE_STANDING,
  4357. // MECH_STATUSCHUNK_BODYSTATE_PARKED,
  4358. // MECH_STATUSCHUNK_BODYSTATE_POWERING_UP,
  4359. // MECH_STATUSCHUNK_BODYSTATE_POWERING_DOWN,
  4360. // MECH_STATUSCHUNK_BODYSTATE_FALLEN_BACKWARD,
  4361. // MECH_STATUSCHUNK_BODYSTATE_FALLEN_FORWARD
  4362. if (atEndOfPath && (distanceFromWayPt < Mover::marginOfError[1])) {
  4363. startUpThisFrame = false;
  4364. switch (statusChunk.bodyState) {
  4365. case MECH_STATUSCHUNK_BODYSTATE_FALLEN_FORWARD:
  4366. if (!isDisabled()) {
  4367. setStatus(OBJECT_STATUS_NORMAL);
  4368. sensorSystem->setShutdown(false);
  4369. }
  4370. if (bodyState != MECH_STATUSCHUNK_BODYSTATE_FALLEN_FORWARD) {
  4371. pilot->clearMoveOrders();
  4372. appearance->setGestureGoal(MECH_STATE_FALLEN_FORWARD);
  4373. control.settings.mech.throttle = maxThrottle;
  4374. return;
  4375. }
  4376. break;
  4377. case MECH_STATUSCHUNK_BODYSTATE_FALLEN_BACKWARD:
  4378. if (!isDisabled()) {
  4379. setStatus(OBJECT_STATUS_NORMAL);
  4380. sensorSystem->setShutdown(false);
  4381. }
  4382. if (bodyState != MECH_STATUSCHUNK_BODYSTATE_FALLEN_BACKWARD) {
  4383. pilot->clearMoveOrders();
  4384. appearance->setGestureGoal(MECH_STATE_FALLEN_BACKWARD);
  4385. control.settings.mech.throttle = maxThrottle;
  4386. return;
  4387. }
  4388. break;
  4389. case MECH_STATUSCHUNK_BODYSTATE_PARKED:
  4390. if (!isDisabled()) {
  4391. setStatus(OBJECT_STATUS_SHUTDOWN);
  4392. sensorSystem->setShutdown(true);
  4393. }
  4394. if (bodyState != MECH_STATUSCHUNK_BODYSTATE_PARKED) {
  4395. soundSystem->playDigitalSample(POWERDOWN_SFX,getPosition());
  4396. pilot->clearMoveOrders();
  4397. appearance->setGestureGoal(MECH_STATE_PARKED);
  4398. control.settings.mech.throttle = maxThrottle;
  4399. return;
  4400. }
  4401. break;
  4402. case MECH_STATUSCHUNK_BODYSTATE_STANDING:
  4403. if (!isDisabled()) {
  4404. setStatus(OBJECT_STATUS_NORMAL);
  4405. sensorSystem->setShutdown(false);
  4406. }
  4407. if (bodyState != MECH_STATUSCHUNK_BODYSTATE_STANDING) {
  4408. if (bodyState == MECH_STATUSCHUNK_BODYSTATE_PARKED)
  4409. soundSystem->playDigitalSample(POWERUP_SFX,getPosition());
  4410. pilot->clearMoveOrders();
  4411. appearance->setGestureGoal(MECH_STATE_STANDING);
  4412. control.settings.mech.throttle = maxThrottle;
  4413. return;
  4414. }
  4415. break;
  4416. }
  4417. }
  4418. if (disableThisFrame) {
  4419. long fallGesture = RandomNumber(2) ? MECH_STATE_FALLEN_FORWARD : MECH_STATE_FALLEN_BACKWARD;
  4420. if (hitFromBehindThisFrame)
  4421. fallGesture = MECH_STATE_FALLEN_FORWARD;
  4422. else if (hitFromFrontThisFrame)
  4423. fallGesture = MECH_STATE_FALLEN_BACKWARD;
  4424. appearance->setGestureGoal(fallGesture);
  4425. disableThisFrame = false;
  4426. shutDownThisFrame = false;
  4427. startUpThisFrame = false;
  4428. hitFromFrontThisFrame = false;
  4429. hitFromBehindThisFrame = false;
  4430. control.settings.mech.throttle = maxThrottle;
  4431. return;
  4432. }
  4433. if (shutDownThisFrame) {
  4434. appearance->setGestureGoal(MECH_STATE_PARKED);
  4435. shutDownThisFrame = false;
  4436. startUpThisFrame = false;
  4437. setStatus(OBJECT_STATUS_SHUTDOWN);
  4438. control.settings.mech.throttle = maxThrottle;
  4439. return;
  4440. }
  4441. if (startUpThisFrame) {
  4442. appearance->setGestureGoal(MECH_STATE_STANDING);
  4443. startUpThisFrame = false;
  4444. shutDownThisFrame = false;
  4445. setStatus(OBJECT_STATUS_NORMAL);
  4446. control.settings.mech.throttle = maxThrottle;
  4447. return;
  4448. }
  4449. if ((status == OBJECT_STATUS_SHUTTING_DOWN) ||
  4450. (status == OBJECT_STATUS_SHUTDOWN) ||
  4451. (status == OBJECT_STATUS_DISABLED))
  4452. return;
  4453. if (isCaptured())
  4454. return;
  4455. if (engineBlowTime > -1.0)
  4456. return;
  4457. if (updateJump())
  4458. return;
  4459. if (pivotTo())
  4460. return;
  4461. float newRotate = 0.0;
  4462. long newGestureStateGoal = -1;
  4463. long newMoveState = -1;
  4464. char newThrottleSetting = -1;
  4465. bool goalReached = false;
  4466. goalReached = netUpdateMovePath(newRotate, newThrottleSetting, newGestureStateGoal, newMoveState, minThrottle, maxThrottle);
  4467. if (newMoveState != -1)
  4468. pilot->setMoveState(newMoveState);
  4469. setControlSettings(newRotate, newThrottleSetting, newGestureStateGoal, minThrottle, maxThrottle,newRotate);
  4470. //updateTorso(newRotate);
  4471. updateMoveStateGoal();
  4472. NewRotation = newRotate;
  4473. }
  4474. //----------------------------------------------------------------------------------
  4475. // END OF MOVEMENT UPDATE ROUTINES
  4476. //----------------------------------------------------------------------------------
  4477. Stuff::Vector3D BattleMech::getPositionFromHS (long nodeId)
  4478. {
  4479. //-----------------------------------------------
  4480. return(appearance->getWeaponNodePosition(nodeId));
  4481. }
  4482. //----------------------------------------------------------------------------------
  4483. #ifdef PROFILE
  4484. extern long srCtrlUpd;
  4485. extern long srApprUpd;
  4486. extern long srDyneUpd;
  4487. extern long srWeapUpd;
  4488. extern long srObjtUpd;
  4489. #endif
  4490. //L_INTEGER startCk;
  4491. //L_INTEGER endCk;
  4492. #define JUMP_FX 454
  4493. //---------------------------------------------------------------------------
  4494. void BattleMech::createJumpFX (void) {
  4495. #ifdef USE_JETS
  4496. if (!jumpJets[0] && !jumpJets[1])
  4497. {
  4498. jumpJets[0] = (JetPtr)createObject(JUMP_FX);
  4499. jumpJets[0]->setOwner(this);
  4500. jumpJets[1] = (JetPtr)createObject(JUMP_FX);
  4501. jumpJets[1]->setOwner(this);
  4502. craterManager->addCrater(SCORCHMARKS,position,0);
  4503. }
  4504. #endif
  4505. }
  4506. //---------------------------------------------------------------------------
  4507. void BattleMech::endJumpFX (void) {
  4508. #ifdef USE_JETS
  4509. if (jumpJets[0] || jumpJets[1])
  4510. {
  4511. delete jumpJets[0];
  4512. jumpJets[0] = NULL;
  4513. delete jumpJets[1];
  4514. jumpJets[1] = NULL;
  4515. }
  4516. #endif
  4517. }
  4518. //---------------------------------------------------------------------------
  4519. Stuff::Vector3D BattleMech::getJumpPosition (void)
  4520. {
  4521. Stuff::Vector3D result;
  4522. result.x = result.y = result.z = 0.0f;
  4523. return result;
  4524. }
  4525. //---------------------------------------------------------------------------
  4526. bool BattleMech::crashAvoidanceSystem (void) {
  4527. if (MPlayer && !MPlayer->isServer())
  4528. return(false);
  4529. MovePathPtr path = pilot->getMovePath();
  4530. if (path->numStepsWhenNotPaused == 0)
  4531. return(false);
  4532. if (pilot->getMoveWaitForPointTime() > 999990.0)
  4533. return(false);
  4534. //float velMag = getSpeed(); //((MechActor*)appearance)->getVelocityMagnitude();
  4535. Stuff::Vector3D velocity = getVelocity();
  4536. velocity.z = 0.0;
  4537. Stuff::Vector3D relVelocity = velocity;
  4538. relVelocity *= frameLength;
  4539. relVelocity *= worldUnitsPerMeter;
  4540. Stuff::Vector3D newPosition;
  4541. newPosition.Add(position, relVelocity);
  4542. //---------------------------------------------------------------------
  4543. // Is this new position in a pathlocked area? If so, put on the brakes!
  4544. long cellR, cellC;
  4545. land->worldToCell(newPosition, cellR, cellC);
  4546. bool reachedEnd;
  4547. bool blockReachedEnd;
  4548. //-------------------------
  4549. // To avoid corner stops...
  4550. bool clippingCorner = false;
  4551. long dir = path->getDirection(path->curStep);
  4552. if ((dir == 1) || (dir == 3) || (dir == 5) || (dir == 7)) {
  4553. bool firstCornerClipped = getAdjacentCellPathLocked((moveLevel == 2), cellPositionRow, cellPositionCol, adjClippedCell[dir][0]);
  4554. bool secondCornerClipped = getAdjacentCellPathLocked((moveLevel == 2), cellPositionRow, cellPositionCol, adjClippedCell[dir][1]);
  4555. clippingCorner = (firstCornerClipped && secondCornerClipped);
  4556. }
  4557. //bool stepOnMover = getPathLocked(tileR, tileC, cellR, cellC, crashAvoidSelf);
  4558. bool nearingMover = getPathRangeLock(crashAvoidPath, &reachedEnd);
  4559. bool pathBlocked = getPathRangeBlocked(crashAvoidPath, &blockReachedEnd);
  4560. bool pathLocked = /*stepOnMover ||*/ nearingMover;
  4561. long stepIntoGate = (path->crossesClosedGate(-1, 2) > 0);
  4562. if (pilot->isYielding()) {
  4563. if (pathLocked || pathBlocked || clippingCorner || stepIntoGate) {
  4564. pilot->pausePath(); //path->numSteps = 0; //in theory, this should already be zero, yet is sometimes not. WHY?!
  4565. return(true);
  4566. }
  4567. else {
  4568. //-------------------
  4569. // It's clear, now...
  4570. pilot->resumePath();
  4571. pilot->setMoveYieldTime(-1.0);
  4572. }
  4573. }
  4574. else {
  4575. if (pathLocked || pathBlocked || clippingCorner || stepIntoGate) {
  4576. //-------------------------------------------------------------------
  4577. // What exactly is wrong here? Is our goal currently occupied? If so,
  4578. // and it's our final goal, then stop!
  4579. if (reachedEnd || blockReachedEnd) {
  4580. //-----------------------------------------------------------------------
  4581. // Since we're practically there, let's just kill the current move orders
  4582. // and let the pilot's movementDecision update decide whether a new
  4583. // one should be set...
  4584. /*
  4585. pilot->setMoveWayPath(ORDER_CURRENT, NULL, 0);
  4586. for (long i = 0; i < 2; i++)
  4587. pilot->clearMovePath(ORDER_CURRENT, i);
  4588. pilot->setMoveGlobalPath(ORDER_CURRENT, NULL, 0);
  4589. */
  4590. //pilot->clearMoveOrders(ORDER_CURRENT);
  4591. pilot->rethinkPath(0);
  4592. //pilot->pausePath();
  4593. //pilot->setMoveYieldTime(scenarioTime + crashYieldTime);
  4594. control.brake();
  4595. }
  4596. else {
  4597. pilot->pausePath();
  4598. pilot->setMoveYieldTime(scenarioTime + crashYieldTime);
  4599. control.brake();
  4600. }
  4601. return(true);
  4602. }
  4603. }
  4604. return(false);
  4605. }
  4606. //---------------------------------------------------------------------------
  4607. void BattleMech::updateAIControl (void) {
  4608. control.reset();
  4609. if (getAwake()) {
  4610. updateDamageTakenRate();
  4611. if (!isDisabled() && pilot->alive() && !pilot->hasEjected()) {
  4612. if (getTeamId() > -1)
  4613. pilot->mainDecisionTree();
  4614. updateMovement();
  4615. }
  4616. else if (shutDownThisFrame || disableThisFrame)
  4617. updateMovement();
  4618. }
  4619. }
  4620. //---------------------------------------------------------------------------
  4621. void BattleMech::updateNetworkControl (void) {
  4622. control.reset();
  4623. if (getAwake()) {
  4624. //-----------------------------------------
  4625. // Update any weaponfire chunks received...
  4626. updateWeaponFireChunks(CHUNK_RECEIVE);
  4627. updateCriticalHitChunks(CHUNK_RECEIVE);
  4628. updateRadioChunks(CHUNK_RECEIVE);
  4629. if (!isDisabled() && pilot->alive() && !pilot->hasEjected()) {
  4630. pilot->checkAlarms();
  4631. netUpdateMovement();
  4632. }
  4633. else if (shutDownThisFrame || disableThisFrame) {
  4634. netUpdateMovement();
  4635. }
  4636. }
  4637. }
  4638. //---------------------------------------------------------------------------
  4639. void BattleMech::updatePlayerControl (void) {
  4640. control.reset();
  4641. //-----------------------------------------------------------------
  4642. // Poll the joystick and keyboards here so player can control mech.
  4643. if (userInput->getKeyDown(KEY_T))
  4644. control.settings.mech.rotate = tonnageTurnRate[long(tonnage)] / 4.0 * frameLength;
  4645. if (userInput->getKeyDown(KEY_Y))
  4646. control.settings.mech.rotate = -tonnageTurnRate[long(tonnage)] / 4.0 * frameLength;
  4647. if (userInput->getKeyDown(KEY_DIVIDE))
  4648. control.settings.mech.rotateTorso = dynamics.max.mech.torsoYawRate / 4.0 * frameLength;
  4649. if (userInput->getKeyDown(KEY_MULTIPLY))
  4650. control.settings.mech.rotateTorso = -dynamics.max.mech.torsoYawRate / 4.0 * frameLength;
  4651. if (userInput->getKeyDown(KEY_NEXT))
  4652. {
  4653. appearance->setNextFrame();
  4654. }
  4655. if (userInput->getKeyDown(KEY_PRIOR))
  4656. {
  4657. appearance->setPrevFrame();
  4658. }
  4659. if (userInput->getKeyDown(KEY_END))
  4660. {
  4661. appearance->setSingleStepMode();
  4662. }
  4663. if (userInput->getKeyDown(KEY_U))
  4664. control.settings.mech.rotateLeftArm = tonnageTurnRate[long(tonnage)] / 4.0 * frameLength;
  4665. if (userInput->getKeyDown(KEY_I))
  4666. control.settings.mech.rotateLeftArm = -tonnageTurnRate[long(tonnage)] / 4.0 * frameLength;
  4667. if (userInput->getKeyDown(KEY_O))
  4668. control.settings.mech.rotateRightArm = tonnageTurnRate[long(tonnage)] / 4.0 * frameLength;
  4669. if (userInput->getKeyDown(KEY_P))
  4670. control.settings.mech.rotateRightArm = -tonnageTurnRate[long(tonnage)] / 4.0 * frameLength;
  4671. if (userInput->getKeyDown(KEY_1))
  4672. appearance->setGestureGoal(0);
  4673. if (userInput->getKeyDown(KEY_2))
  4674. appearance->setGestureGoal(1); //Stand
  4675. if (userInput->getKeyDown(KEY_3))
  4676. appearance->setGestureGoal(2); //Walk
  4677. if (userInput->getKeyDown(KEY_4))
  4678. appearance->setGestureGoal(3); //Run
  4679. if (userInput->getKeyDown(KEY_R))
  4680. appearance->setGestureGoal(4); //Reverse
  4681. if (userInput->getKeyDown(KEY_5))
  4682. appearance->setGestureGoal(5); //Limp LEFT!
  4683. if (userInput->getKeyDown(KEY_9))
  4684. appearance->setGestureGoal(9); //Limp RIGHT!
  4685. if (userInput->getKeyDown(KEY_6))
  4686. appearance->setGestureGoal(7); //Fall Forward
  4687. if (userInput->getKeyDown(KEY_7))
  4688. appearance->setGestureGoal(8); //Fall Backward
  4689. if (userInput->getKeyDown(KEY_8))
  4690. appearance->hitFront();
  4691. if (userInput->getKeyDown(KEY_B))
  4692. appearance->hitBack();
  4693. if (userInput->getKeyDown(KEY_N))
  4694. appearance->hitRight();
  4695. if (userInput->getKeyDown(KEY_M))
  4696. appearance->hitLeft();
  4697. if (userInput->getKeyDown(KEY_Z))
  4698. ObjectManager->getObjectType(typeHandle)->handleDestruction(this, NULL); //Blow self up!!
  4699. if (userInput->getKeyDown(KEY_X))
  4700. control.settings.mech.blowLeftArm = true;
  4701. if (userInput->getKeyDown(KEY_J))
  4702. {
  4703. Stuff::Vector3D jumpDest = getRotationVector();
  4704. jumpDest *= 150.0;
  4705. jumpDest += position;
  4706. appearance->setJumpParameters(jumpDest);
  4707. appearance->setGestureGoal(6); //Jump
  4708. }
  4709. if (userInput->getKeyDown(KEY_G))
  4710. appearance->setCombatMode(1);
  4711. if (userInput->getKeyDown(KEY_F))
  4712. appearance->setCombatMode(0);
  4713. if (userInput->getKeyDown(KEY_C))
  4714. control.settings.mech.blowRightArm = true;
  4715. }
  4716. //---------------------------------------------------------------------------
  4717. void BattleMech::updateDynamics (void) {
  4718. float yawRate = control.settings.mech.rotate;
  4719. float facingYawRate = control.settings.mech.facingRotate;
  4720. float torsoYawRate = control.settings.mech.rotateTorso;
  4721. float rightArmYawRate = control.settings.mech.rotateRightArm;
  4722. float leftArmYawRate = control.settings.mech.rotateLeftArm;
  4723. //----------------------------------------------------------------
  4724. // The gesture is how we control speed. So, at this point, check
  4725. // the mechControlData->gestureGoal and see if we need to change goals
  4726. bool bottomNotAllowedToYaw = false;
  4727. bool topNotAllowedToYaw = false;
  4728. if (appearance)
  4729. {
  4730. if ((control.settings.mech.gestureGoal != -1) ||
  4731. ((control.settings.mech.gestureGoal == 7) && (getMoveType() != MOVETYPE_AIR)) ||
  4732. ((control.settings.mech.gestureGoal == 8) && (getMoveType() != MOVETYPE_AIR)))
  4733. appearance->setGestureGoal(control.settings.mech.gestureGoal);
  4734. }
  4735. //--------------------------------------------------------------------
  4736. // Rotate torso by torso yaw rate, making sure we don't turn too far.
  4737. if ((torsoYawRate != 0.0) && !topNotAllowedToYaw) {
  4738. float newTorsoRotation = torsoRotation;
  4739. if (newTorsoRotation > dynamics.max.mech.torsoYaw) {
  4740. newTorsoRotation = dynamics.max.mech.torsoYaw;
  4741. torsoYawRate = 0.0;
  4742. }
  4743. if (newTorsoRotation < -dynamics.max.mech.torsoYaw) {
  4744. newTorsoRotation = -dynamics.max.mech.torsoYaw;
  4745. torsoYawRate = 0.0;
  4746. }
  4747. if ((newTorsoRotation + torsoYawRate) > dynamics.max.mech.torsoYaw)
  4748. torsoYawRate = dynamics.max.mech.torsoYaw - newTorsoRotation;
  4749. if ((newTorsoRotation + torsoYawRate) < -dynamics.max.mech.torsoYaw)
  4750. torsoYawRate = -dynamics.max.mech.torsoYaw - newTorsoRotation;
  4751. newTorsoRotation += torsoYawRate;
  4752. torsoRotation = newTorsoRotation;
  4753. }
  4754. //--------------------------------------------------------------------------
  4755. // Rotate rightArm by rightArm yaw rate, making sure we don't turn too far.
  4756. if ((rightArmYawRate != 0.0) && !topNotAllowedToYaw) {
  4757. float newRightArmRotation = rightArmRotation;
  4758. if (newRightArmRotation > tonnageTurnRate[long(tonnage)]) {
  4759. newRightArmRotation = tonnageTurnRate[long(tonnage)];
  4760. rightArmYawRate = 0.0;
  4761. }
  4762. if (newRightArmRotation < -tonnageTurnRate[long(tonnage)]) {
  4763. newRightArmRotation = -tonnageTurnRate[long(tonnage)];
  4764. rightArmYawRate = 0.0;
  4765. }
  4766. if ((newRightArmRotation + rightArmYawRate) > tonnageTurnRate[long(tonnage)]) {
  4767. newRightArmRotation = tonnageTurnRate[long(tonnage)];
  4768. rightArmYawRate = 0.0;
  4769. }
  4770. if ((newRightArmRotation + rightArmYawRate) < -tonnageTurnRate[long(tonnage)]) {
  4771. newRightArmRotation = -tonnageTurnRate[long(tonnage)];
  4772. rightArmYawRate = 0.0;
  4773. }
  4774. newRightArmRotation += rightArmYawRate;
  4775. rightArmRotation = newRightArmRotation;
  4776. }
  4777. //--------------------------------------------------------------------------
  4778. // Rotate rightArm by rightArm yaw rate, making sure we don't turn too far.
  4779. if ((leftArmYawRate != 0.0) && !topNotAllowedToYaw) {
  4780. float newLeftArmRotation = leftArmRotation;
  4781. if (newLeftArmRotation < -tonnageTurnRate[long(tonnage)]) {
  4782. newLeftArmRotation = -tonnageTurnRate[long(tonnage)];
  4783. leftArmYawRate = 0.0;
  4784. }
  4785. if (newLeftArmRotation > tonnageTurnRate[long(tonnage)]) {
  4786. newLeftArmRotation = tonnageTurnRate[long(tonnage)];
  4787. leftArmYawRate = 0.0;
  4788. }
  4789. if ((newLeftArmRotation + leftArmYawRate) < -tonnageTurnRate[long(tonnage)]) {
  4790. newLeftArmRotation = -tonnageTurnRate[long(tonnage)];
  4791. leftArmYawRate = 0.0;
  4792. }
  4793. if ((newLeftArmRotation + leftArmYawRate) > tonnageTurnRate[long(tonnage)]) {
  4794. newLeftArmRotation = tonnageTurnRate[long(tonnage)];
  4795. leftArmYawRate = 0.0;
  4796. }
  4797. newLeftArmRotation += leftArmYawRate;
  4798. leftArmRotation = newLeftArmRotation;
  4799. }
  4800. if (!bottomNotAllowedToYaw)
  4801. rotate(yawRate,facingYawRate);
  4802. }
  4803. //---------------------------------------------------------------------------
  4804. extern GameObjectPtr DebugGameObject[3];
  4805. long BattleMech::update (void)
  4806. {
  4807. positionNormal = land->getTerrainNormal(position);
  4808. getPilot()->getIndex();
  4809. //Reset every frame to avoid multiples
  4810. playedCriticalHit = false;
  4811. if ( getTeam() == Team::home )
  4812. {
  4813. ((ObjectAppearance*)appearance)->pilotNameID = getPilot()->descID;
  4814. ((ObjectAppearance*)appearance)->pilotName[0] = 0;
  4815. appearance->setMechName( variantName );
  4816. }
  4817. else if ( MPlayer )
  4818. {
  4819. strcpy( ((ObjectAppearance*)appearance)->pilotName, (commanderId > -1) ? MPlayer->playerInfo[commanderId].name : " " );
  4820. }
  4821. else
  4822. ((ObjectAppearance*)appearance)->pilotNameID = -1;
  4823. if (isDestroyed() || isDisabled())
  4824. setTangible(false);
  4825. if (withdrawing && (pilot->getStatus() == WARRIOR_STATUS_WITHDRAWN)) {
  4826. setTangible(false);
  4827. return(1); //This guy is gone.
  4828. }
  4829. //----------------------------------------------------------------------
  4830. //Blow off the arms if we need to.
  4831. // MUST be here so that they get blown off regardless of mech status
  4832. if (leftArmBlownThisFrame) {
  4833. leftArmBlownThisFrame = false;
  4834. //-------------------------------------------
  4835. // Frank says, blow the right one anyway --gd
  4836. control.settings.mech.blowRightArm = true;
  4837. }
  4838. if (rightArmBlownThisFrame) {
  4839. rightArmBlownThisFrame = false;
  4840. //------------------------------------------
  4841. // Frank says, blow the left one anyway --gd
  4842. control.settings.mech.blowLeftArm = true;
  4843. }
  4844. if (control.settings.mech.blowLeftArm)
  4845. {
  4846. appearance->blowLeftArm();
  4847. soundSystem->playDigitalSample(CRITICAL_HIT_SFX,getPosition(),true);
  4848. control.settings.mech.blowLeftArm = false;
  4849. }
  4850. if (control.settings.mech.blowRightArm)
  4851. {
  4852. appearance->blowRightArm();
  4853. soundSystem->playDigitalSample(CRITICAL_HIT_SFX,getPosition(),true);
  4854. control.settings.mech.blowRightArm = false;
  4855. }
  4856. //----------------------------------------------------------------------
  4857. if (!isDestroyed() && !isDisabled())
  4858. {
  4859. #ifdef MC_PROFILE
  4860. QueryPerformanceCounter(startCk);
  4861. #endif
  4862. //Be damned sure our legs are marked correctly!!
  4863. calcLegStatus();
  4864. updatePathLock(false);
  4865. //Check if we are SHUTDOWN and NOT onGui.
  4866. // If we are both, we probably are waiting to be linked up with.
  4867. // See if anything on our side is close enough to link up with us.
  4868. // If it is close enough, powerup and ourselves to the GUI!
  4869. if ((status == OBJECT_STATUS_SHUTDOWN) && !isOnGUI())
  4870. {
  4871. //Check if anyone on our side is within range.
  4872. // Until otherwise noted, if I have LOS to them, thats enough.
  4873. // Powerup, add ourselves to the GUI and select ourselves
  4874. // Maybe we should send a Radio Message saying "hi"?
  4875. if (Team::home->teamLineOfSight(position,getAppearRadius()))
  4876. {
  4877. mission->missionInterface->addMover(this);
  4878. setSelected(1);
  4879. pilot->corePower(true);
  4880. setOnGUI(true);
  4881. sensorSystem->broken = false;
  4882. }
  4883. else
  4884. {
  4885. sensorSystem->broken = true;
  4886. }
  4887. }
  4888. if ((status == OBJECT_STATUS_SHUTDOWN) || (status == OBJECT_STATUS_SHUTTING_DOWN))
  4889. appearance->setGestureGoal(MECH_STATE_PARKED);
  4890. if (getAwake() && !isDisabled() && getTeam() && !godMode)
  4891. {
  4892. BattleMechTypePtr mechType = (BattleMechTypePtr)ObjectManager->getObjectType(typeHandle);
  4893. getTeam()->markSeen(position,mechType->LOSFactor);
  4894. markDistanceMoved = 0.0;
  4895. }
  4896. if (timeToClearSelection != 0.0 && scenarioTime > timeToClearSelection)
  4897. {
  4898. timeToClearSelection = 0.0;
  4899. setSelected(false);
  4900. setTargeted(false);
  4901. }
  4902. control.update(this);
  4903. if (!getAwake()) {
  4904. appearance->setGestureGoal(MECH_STATE_PARKED);
  4905. shutDownThisFrame = false;
  4906. }
  4907. #ifdef MC_PROFILE
  4908. QueryPerformanceCounter(endCk);
  4909. srCtrlUpd += (endCk.LowPart - startCk.LowPart);
  4910. #endif
  4911. #ifdef MC_PROFILE
  4912. QueryPerformanceCounter(startCk);
  4913. #endif
  4914. //updateDynamics();
  4915. bool emergencyStop = false;
  4916. if (!isDisabled()) {
  4917. MoverPtr ramTarget = NULL;
  4918. if ((getPilot()->getCurTacOrder()->code == TACTICAL_ORDER_ATTACK_OBJECT) && (getPilot()->getCurTacOrder()->attackParams.method == ATTACKMETHOD_RAMMING))
  4919. ramTarget = (MoverPtr)getPilot()->getCurTacOrder()->getRamTarget();
  4920. if (ramTarget)
  4921. ramTarget->updatePathLock(false);
  4922. emergencyStop = crashAvoidanceSystem();
  4923. if (ramTarget)
  4924. ramTarget->updatePathLock(true);
  4925. }
  4926. #ifdef MC_PROFILE
  4927. QueryPerformanceCounter(endCk);
  4928. srDyneUpd += (endCk.LowPart - startCk.LowPart);
  4929. #endif
  4930. //--------------------------------------------------------------------
  4931. // At this point, the other updates have completed, its time to
  4932. // apply the velocity and rotations to the mech.
  4933. // NOTE:
  4934. // All positions in the game are in World Units. All velocities
  4935. // are in Meters/sec. This is to provide easy data entry for designers
  4936. // We can't store positions as meters because terrain tiles are fixed
  4937. // pixel(world unit) sizes which would require a boatload of math
  4938. // with its crazy floating point inconsistencies. This will mess up
  4939. // the terrain. So, whenever you want a position derived from
  4940. // a velocity, multiply velocity by worldUnitsPerMeter.
  4941. #ifdef MC_PROFILE
  4942. QueryPerformanceCounter(startCk);
  4943. #endif
  4944. if (teleportPosition.x > -999990.0) {
  4945. setPosition(teleportPosition);
  4946. teleportPosition.x = -999990.0;
  4947. teleportPosition.y = -999990.0;
  4948. teleportPosition.z = -999990.0;
  4949. }
  4950. //-----------------------------------------------------------
  4951. // Find magnitude of current velocity. Store this in dynamics
  4952. // Adjust position based on mech Velocity which is based on gesture
  4953. Stuff::Vector3D newPosition;
  4954. Stuff::Vector3D vel = getRotationVector();
  4955. if (!appearance->isJumpAirborne())
  4956. {
  4957. float velMag = appearance->getVelocityMagnitude();
  4958. if (emergencyStop)
  4959. velMag = 0.0;
  4960. velMag *= 0.01f * control.settings.mech.throttle;
  4961. float velFactor = 1.0;
  4962. //if (moveLevel == 0) {
  4963. float velAngle = land->getTerrainAngle(position);
  4964. velAngle *= DEGREES_TO_RADS;
  4965. velFactor = cos(velAngle);
  4966. //}
  4967. //--------------------------------------------
  4968. float velMult = velMag * velFactor * frameLength;
  4969. if (velMult > DistanceToWaypoint)
  4970. velMult = DistanceToWaypoint;
  4971. vel *= velMult * worldUnitsPerMeter;
  4972. setVelocity(vel);
  4973. newPosition.Add(position, vel);
  4974. newPosition.z = land->getTerrainElevation(newPosition);
  4975. if ((getMoveType() == MOVETYPE_AIR) &&
  4976. (newPosition.z < MapData::waterDepth))
  4977. newPosition.z = MapData::waterDepth;
  4978. }
  4979. else
  4980. {
  4981. //Just move mech in direction of jump.
  4982. vel = appearance->getVelocity();
  4983. vel *= frameLength;
  4984. setVelocity(vel);
  4985. newPosition.Add(position, vel);
  4986. newPosition.z = land->getTerrainElevation(newPosition);
  4987. }
  4988. if (newMoveChunk) {
  4989. if (!statusChunk.jumpOrder) {
  4990. //------------------------------------------------------------
  4991. // If we're too far from where we should be, perhaps we should
  4992. // just warp to it...
  4993. Stuff::Vector3D correctPos;
  4994. land->cellToWorld(moveChunk.stepPos[0][0], moveChunk.stepPos[0][1], correctPos);
  4995. correctPos.z = 0.0;
  4996. Stuff::Vector3D curPos = position;
  4997. curPos.z = 0.0;
  4998. curPos.Subtract(curPos, correctPos);
  4999. float posDelta = curPos.GetLength();
  5000. if (posDelta > MPlayer->warpFactor)
  5001. newPosition = correctPos;
  5002. if (!GameMap->inBounds(moveChunk.stepPos[0][0], moveChunk.stepPos[0][1]))
  5003. Fatal(0, " mech.update: newMoveChunk stepPos not on map! ");
  5004. }
  5005. newMoveChunk = false;
  5006. }
  5007. setPosition(newPosition);
  5008. updateTorso(NewRotation);
  5009. //Don't let them move if they are shutdown!!
  5010. if (status != OBJECT_STATUS_SHUTDOWN)
  5011. updateDynamics();
  5012. markDistanceMoved += vel.GetLength();
  5013. if (!isDisabled())
  5014. updatePathLock(true);
  5015. mineCheck();
  5016. float zPos = land->getTerrainElevation(position);
  5017. position.z = zPos;
  5018. if ((getMoveType() == MOVETYPE_AIR) &&
  5019. (zPos < MapData::waterDepth))
  5020. position.z = MapData::waterDepth;
  5021. //float inverseAngle = 180.0;
  5022. #ifdef MC_PROFILE
  5023. QueryPerformanceCounter(endCk);
  5024. srObjtUpd += (endCk.LowPart - startCk.LowPart);
  5025. #endif
  5026. #ifdef MC_PROFILE
  5027. QueryPerformanceCounter(startCk);
  5028. #endif
  5029. bool inView = appearance->recalcBounds();
  5030. if (inView)
  5031. windowsVisible = turn;
  5032. if (withdrawing && !inView && (pilot->getStatus() != WARRIOR_STATUS_WITHDRAWN))
  5033. ObjectManager->getObjectType(typeHandle)->handleDestruction(this, NULL);
  5034. if (appearance) {
  5035. MovePathPtr path = pilot->getMovePath();
  5036. bool brake = true;
  5037. if (path && path->numSteps && (path->curStep < path->numSteps))
  5038. brake = false;
  5039. appearance->setBrake(brake);
  5040. if ((pilot->getCurrentTarget()) || (pilot->getCurTacOrder()->code == TACTICAL_ORDER_ATTACK_OBJECT) || (pilot->getCurTacOrder()->code == TACTICAL_ORDER_ATTACK_POINT))
  5041. appearance->setCombatMode(true);
  5042. else
  5043. appearance->setCombatMode(false);
  5044. if (isJumping())
  5045. setTangible(false);
  5046. else if (!isDestroyed() && !isDisabled())
  5047. setTangible(true);
  5048. }
  5049. #ifdef MC_PROFILE
  5050. QueryPerformanceCounter(endCk);
  5051. srApprUpd += (endCk.LowPart - startCk.LowPart);
  5052. #endif
  5053. #ifdef MC_PROFILE
  5054. QueryPerformanceCounter(endCk);
  5055. srObjtUpd += (endCk.LowPart - startCk.LowPart);
  5056. #endif
  5057. if (getDebugFlag(OBJECT_DFLAG_DISABLE))
  5058. disable(DEBUGGER_DEATH);
  5059. }
  5060. else if (isDisabled() && !isDestroyed())
  5061. {
  5062. updatePathLock(false);
  5063. ((ObjectAppearance*)appearance)->pilotNameID = IDS_NOPILOT;
  5064. //--------------------------------------------------------
  5065. //We are disabled now. Stop trying to animate, dammit!
  5066. control.settings.mech.gestureGoal = -1;
  5067. updateDynamics();
  5068. //-----------------------------------------------------------
  5069. // Find magnitude of current velocity. Store this in dynamics
  5070. float velMag = appearance->getVelocityMagnitude();
  5071. //---------------------------
  5072. // Create vector for velocity
  5073. Stuff::Vector3D vel = getRotationVector();
  5074. vel *= velMag * worldUnitsPerMeter;
  5075. vel *= frameLength;
  5076. setVelocity(vel);
  5077. Stuff::Vector3D newPosition;
  5078. newPosition.Add(position, vel);
  5079. newPosition.z = land->getTerrainElevation(newPosition);
  5080. setPosition(newPosition);
  5081. bool inView = appearance->recalcBounds();
  5082. if (inView)
  5083. windowsVisible = turn;
  5084. if (appearance)
  5085. {
  5086. appearance->setInView(inView);
  5087. appearance->setCombatMode(false);
  5088. }
  5089. if (!fallen)
  5090. {
  5091. fallen = appearance->haveFallen();
  5092. }
  5093. if (!startDisabled)
  5094. {
  5095. timeLeft -= frameLength;
  5096. if ((timeLeft < 1.0f) && !exploding)
  5097. {
  5098. //-------------------------------------------------------
  5099. // Disable just plays an eject effect now.
  5100. // NO crater or it will look dumb.
  5101. //
  5102. // DO NOT play disable effect if pilot is dead!!
  5103. if (getPilot()->alive())
  5104. {
  5105. Stuff::Vector3D cockpitPos = appearance->getNodeNamePosition("cockpit");
  5106. ObjectManager->createExplosion(MECH_DISABLE_EXPLOSION_ID,NULL,cockpitPos,0.0f,0.0f);
  5107. }
  5108. appearance->startSmoking(-1);
  5109. exploding = true;
  5110. }
  5111. }
  5112. if (getMoveType() == MOVETYPE_AIR)
  5113. {
  5114. setStatus(OBJECT_STATUS_DESTROYED);
  5115. timeLeft = 0.0f;
  5116. }
  5117. }
  5118. else
  5119. {
  5120. //--------------------------------------------------------
  5121. //We are destroyed now. Stop trying to animate, dammit!
  5122. control.settings.mech.gestureGoal = -1;
  5123. updateDynamics();
  5124. //-----------------------------------------------------------
  5125. // Find magnitude of current velocity. Store this in dynamics
  5126. float velMag = appearance->getVelocityMagnitude();
  5127. //---------------------------
  5128. // Create vector for velocity
  5129. Stuff::Vector3D vel = getRotationVector();
  5130. vel *= velMag * worldUnitsPerMeter;
  5131. vel *= frameLength;
  5132. setVelocity(vel);
  5133. Stuff::Vector3D newPosition;
  5134. newPosition.Add(position, vel);
  5135. newPosition.z = land->getTerrainElevation(newPosition);
  5136. setPosition(newPosition);
  5137. if (!playedHeloDestruct)
  5138. {
  5139. soundSystem->playDigitalSample(HELICOPTER_DEATH,getPosition());
  5140. playedHeloDestruct = true;
  5141. }
  5142. bool inView = appearance->recalcBounds();
  5143. if (inView)
  5144. windowsVisible = turn;
  5145. if (appearance)
  5146. {
  5147. appearance->setGestureGoal(GestureGoalFallenBackward);
  5148. appearance->setInView(inView);
  5149. appearance->setCombatMode(false);
  5150. }
  5151. if (!fallen)
  5152. {
  5153. fallen = appearance->haveFallen();
  5154. timeLeft = 1.0f;
  5155. }
  5156. if (fallen)
  5157. {
  5158. timeLeft -= frameLength;
  5159. if ((timeLeft < 0.4) && !exploding)
  5160. {
  5161. //-------------------------------------------------------
  5162. // Blow the Mech and leave a crater.
  5163. Stuff::Vector3D cockpitPos = appearance->getNodeNamePosition("cockpit");
  5164. if (getMoveType() != MOVETYPE_AIR)
  5165. ObjectManager->createExplosion(MECH_EXPLOSION_ID,NULL,cockpitPos,((BattleMechTypePtr)getObjectType())->explDmg,((BattleMechTypePtr)getObjectType())->explRad);
  5166. else
  5167. ObjectManager->createExplosion(VEHICLE_EXPLOSION_ID,NULL,cockpitPos,0.0f,0.0f);
  5168. craterManager->addCrater(CRATER_4,position,RandomNumber(180));
  5169. exploding = true;
  5170. }
  5171. else if (((timeLeft < -2.5f) && !mechRemoved && (getMoveType() != MOVETYPE_AIR)) ||
  5172. ((timeLeft < -1.5f) && !mechRemoved && (getMoveType() == MOVETYPE_AIR)))
  5173. {
  5174. mechRemoved = true;
  5175. }
  5176. else if (mechRemoved)
  5177. appearance->setObjStatus(getStatus());
  5178. }
  5179. }
  5180. // TEMP BLOCK OUT FOR MC2 port...
  5181. #if 0
  5182. //-------------------------------------------------------------------------------
  5183. // Let the ObjectManager know which block the Mech is in for Collision Purposes
  5184. float xCoord = position.x - Terrain::mapTopLeft3d100.x;
  5185. float yCoord = Terrain::mapTopLeft3d100.y + position.y ;
  5186. float divisor = (Terrain::verticesBlockSide * Terrain::metersPerVertex);
  5187. xCoord /= divisor;
  5188. yCoord /= divisor;
  5189. long blockNumber = agfloor(xCoord) + (agfloor(yCoord) * Terrain::blocksMapSide);
  5190. addMoverToList(blockNumber);
  5191. #endif
  5192. //---------------------------------------------------------------------------------
  5193. // Setup the Render stuff here. Must do in Update to avoid texture lock in render!
  5194. long relationship = 0;
  5195. if (getTeamId() == Team::home->getId())
  5196. {
  5197. //Two Possibilities. Either we have the same commander or we don't.
  5198. // If we do, we are on the same "team", if not we are ALLIES!!!
  5199. if (getCommanderId() != Commander::home->getId())
  5200. {
  5201. relationship = 1;
  5202. }
  5203. }
  5204. else
  5205. {
  5206. relationship = 2;
  5207. }
  5208. long homeRelations = 2;
  5209. if (getTeam() == Team::home) {
  5210. if (getCommander() == Commander::home)
  5211. homeRelations = 0;
  5212. else
  5213. homeRelations = 1;
  5214. }
  5215. appearance->setObjectParameters(position, rotation, drawFlags, getTeamId(), homeRelations);
  5216. if (getMoveType() == MOVETYPE_AIR)
  5217. appearance->setMoverParameters(torsoRotation,0.0f,0.0f,true);
  5218. else
  5219. appearance->setMoverParameters(torsoRotation);
  5220. if (!mechRemoved && !isDestroyed())
  5221. appearance->setObjStatus(getStatus());
  5222. if (control.getType() == CONTROL_PLAYER)
  5223. appearance->setDebugMoveMode();
  5224. appearance->setVisibility(true,true);
  5225. //Start and stop the water wakes here.
  5226. long watercellR, watercellC;
  5227. land->worldToCell(position,watercellR, watercellC);
  5228. if (GameMap->getDeepWater(watercellR, watercellC) ||
  5229. GameMap->getShallowWater(watercellR, watercellC))
  5230. {
  5231. appearance->startWaterWake();
  5232. }
  5233. else
  5234. {
  5235. appearance->stopWaterWake();
  5236. }
  5237. //-----------------------------------------------------
  5238. //Must save sensor data HERE now so fades happen OK.
  5239. if (getTeamId() != Team::home->getId())
  5240. {
  5241. //---------------------------------------------------------------
  5242. conStat = getContactStatus(Team::home->getId(), true);
  5243. if ((conStat == CONTACT_VISUAL) || isDestroyed() || isDisabled() || ShowMovers || (MPlayer && MPlayer->allUnitsDestroyed[MPlayer->commanderID]))
  5244. {
  5245. if (alphaValue != 0xff)
  5246. {
  5247. fadeTime += frameLength;
  5248. if (fadeTime > ContactFadeTime)
  5249. {
  5250. fadeTime = ContactFadeTime;
  5251. alphaValue = 0xff;
  5252. }
  5253. else
  5254. {
  5255. float fadeValue = fadeTime / ContactFadeTime * 255.0f;
  5256. alphaValue = fadeValue;
  5257. }
  5258. }
  5259. appearance->setAlphaValue(alphaValue);
  5260. appearance->setSensorLevel(0);
  5261. }
  5262. else //Pretty much anything else is fading out.
  5263. {
  5264. if (alphaValue != 0x0)
  5265. {
  5266. //We are fading. Move it down.
  5267. fadeTime -= frameLength;
  5268. if (fadeTime < 0.0f)
  5269. {
  5270. fadeTime = 0.0f;
  5271. alphaValue = 0x0;
  5272. }
  5273. else
  5274. {
  5275. float fadeValue = fadeTime / ContactFadeTime * 255.0f;
  5276. alphaValue = fadeValue;
  5277. }
  5278. }
  5279. appearance->setAlphaValue(alphaValue);
  5280. if (conStat == CONTACT_SENSOR_QUALITY_1)
  5281. {
  5282. appearance->setSensorLevel(1);
  5283. }
  5284. else if (conStat == CONTACT_SENSOR_QUALITY_2)
  5285. {
  5286. appearance->setSensorLevel(2);
  5287. }
  5288. else if (conStat == CONTACT_SENSOR_QUALITY_3)
  5289. {
  5290. appearance->setSensorLevel(3);
  5291. }
  5292. else if (conStat == CONTACT_SENSOR_QUALITY_4)
  5293. {
  5294. appearance->setSensorLevel(4);
  5295. }
  5296. }
  5297. }
  5298. else
  5299. {
  5300. if (isOnGui)
  5301. {
  5302. alphaValue = 0xff;
  5303. appearance->setSensorLevel(5);
  5304. appearance->setAlphaValue(alphaValue);
  5305. }
  5306. }
  5307. appearance->update();
  5308. appearance->updateFootprints();
  5309. float barStatus = getTotalEffectiveness();
  5310. DWORD color = 0xff7f7f7f;
  5311. if ((teamId > -1) && (teamId < 8)) {
  5312. if (getTeam()->isFriendly(Team::home))
  5313. color = SB_GREEN;
  5314. else if (getTeam()->isEnemy(Team::home))
  5315. color = SB_RED;
  5316. else
  5317. color = SB_BLUE;
  5318. }
  5319. appearance->setBarColor(color);
  5320. appearance->setBarStatus(barStatus);
  5321. //Must make room for holdFireIcons on HUD if this mech might need one!
  5322. if (isOnGui && !mechRemoved && (attackRange == FIRERANGE_CURRENT) && !isDisabled() )
  5323. {
  5324. mcTextureManager->addTriangle(holdFireIconHandle,MC2_ISHUDLMNT);
  5325. mcTextureManager->addTriangle(holdFireIconHandle,MC2_ISHUDLMNT);
  5326. }
  5327. //---------------------------------------------------------------------------------
  5328. return(1); //Mech is still around, false means whack this mech from list.
  5329. }
  5330. //---------------------------------------------------------------------------
  5331. void BattleMech::render (void)
  5332. {
  5333. if (Terrain::IsGameSelectTerrainPosition(position))
  5334. {
  5335. if (getTeamId() != Team::home->getId())
  5336. {
  5337. //---------------------------------------------------------------
  5338. // Sensor contact is now same as during update.
  5339. long cStat = conStat;
  5340. if ((cStat == CONTACT_VISUAL) || isDestroyed() || isDisabled() || ShowMovers || (MPlayer && MPlayer->allUnitsDestroyed[MPlayer->commanderID]))
  5341. {
  5342. float barStatus = getTotalEffectiveness();
  5343. DWORD color = 0xff7f7f7f;
  5344. if ((teamId > -1) && (teamId < 8)) {
  5345. if (getTeam()->isFriendly(Team::home))
  5346. color = SB_GREEN;
  5347. else if (getTeam()->isEnemy(Team::home))
  5348. color = SB_RED;
  5349. else
  5350. color = SB_BLUE;
  5351. }
  5352. appearance->setBarColor(color);
  5353. appearance->setBarStatus(barStatus);
  5354. appearance->setObjectNameId(descID);
  5355. appearance->setVisibility(true,true);
  5356. appearance->render();
  5357. }
  5358. else if (cStat == CONTACT_SENSOR_QUALITY_1)
  5359. {
  5360. appearance->setBarColor(SB_RED);
  5361. appearance->setVisibility(true,true);
  5362. appearance->render();
  5363. //No more text help for this level
  5364. }
  5365. else if (cStat == CONTACT_SENSOR_QUALITY_2)
  5366. {
  5367. appearance->setBarColor(SB_RED);
  5368. appearance->setVisibility(true,true);
  5369. appearance->render();
  5370. //No more text help for this level
  5371. }
  5372. else if (cStat == CONTACT_SENSOR_QUALITY_3)
  5373. {
  5374. appearance->setBarColor(SB_RED);
  5375. appearance->setVisibility(true,true);
  5376. appearance->render();
  5377. if ( appearance->canBeSeen() )
  5378. {
  5379. if (tonnage < 40)
  5380. drawSensorTextHelp (appearance->getScreenPos().x, appearance->getScreenPos().y+20.0f, IDS_SENSOR_LIGHT_MECH,SD_RED,false);
  5381. else if (tonnage < 65)
  5382. drawSensorTextHelp (appearance->getScreenPos().x, appearance->getScreenPos().y+20.0f, IDS_SENSOR_MEDIUM_MECH,SD_RED,false);
  5383. else if (tonnage < 80)
  5384. drawSensorTextHelp (appearance->getScreenPos().x, appearance->getScreenPos().y+20.0f, IDS_SENSOR_HEAVY_MECH,SD_RED,false);
  5385. else
  5386. drawSensorTextHelp (appearance->getScreenPos().x, appearance->getScreenPos().y+20.0f, IDS_SENSOR_ASSAULT_MECH,SD_RED,false);
  5387. }
  5388. }
  5389. else if (cStat == CONTACT_SENSOR_QUALITY_4)
  5390. {
  5391. appearance->setBarColor(SB_RED);
  5392. appearance->setVisibility(true,true);
  5393. appearance->render();
  5394. if ( appearance->canBeSeen() )
  5395. drawSensorTextHelp (appearance->getScreenPos().x, appearance->getScreenPos().y+20.0f,descID,SD_RED,false);
  5396. }
  5397. }
  5398. else
  5399. {
  5400. if (isOnGui)
  5401. {
  5402. float barStatus = getTotalEffectiveness();
  5403. DWORD color = 0x0000ff00;
  5404. if (getTeamId() == Team::home->getId())
  5405. {
  5406. //Two Possibilities. Either we have the same commander or we don't.
  5407. // If we do, we are on the same "team", if not we are ALLIES!!!
  5408. if (getCommanderId() != Commander::home->getId())
  5409. {
  5410. color = 0x000000ff;
  5411. }
  5412. }
  5413. else
  5414. {
  5415. color = 0x00ff0000;
  5416. }
  5417. appearance->setBarColor(color);
  5418. appearance->setBarStatus(barStatus);
  5419. appearance->setObjectNameId(descID);
  5420. appearance->setVisibility(true,true);
  5421. appearance->setSensorLevel(0);
  5422. appearance->render();
  5423. if ( attackRange == FIRERANGE_CURRENT && !isDisabled() && appearance->canBeSeen() )
  5424. appearance->drawIcon( holdFireIconHandle, 5, 5, color | 0xff000000 );
  5425. }
  5426. }
  5427. }
  5428. if (drawTerrainGrid)
  5429. {
  5430. MovePathPtr path = pilot->getMovePath();
  5431. gosASSERT(path != NULL);
  5432. if (path->numSteps)
  5433. {
  5434. Stuff::Vector4D lineStart, lineEnd;
  5435. for (long i=0;i<path->numSteps;i++)
  5436. {
  5437. if (i != (path->numSteps-1))
  5438. {
  5439. Stuff::Vector3D startPos = path->stepList[i].destination;
  5440. Stuff::Vector3D endPos = path->stepList[i+1].destination;
  5441. startPos.z = land->getTerrainElevation(startPos);
  5442. endPos.z = land->getTerrainElevation(endPos);
  5443. eye->projectZ(startPos,lineStart);
  5444. eye->projectZ(endPos,lineEnd);
  5445. lineStart.z = lineEnd.z = HUD_DEPTH;
  5446. LineElement newElement(lineStart,lineEnd,SD_BLUE,NULL,-1);
  5447. newElement.draw();
  5448. }
  5449. }
  5450. }
  5451. }
  5452. damageThisFrame = 0.0f; //always reset here for the next frame.
  5453. }
  5454. //----------------------------------------------------------------------------------
  5455. void BattleMech::renderShadows (void)
  5456. {
  5457. if (Terrain::IsGameSelectTerrainPosition(position))
  5458. {
  5459. if ((appearance->getCurrentGestureId() == 14) ||
  5460. (appearance->getCurrentGestureId() == 15) ||
  5461. (appearance->getCurrentGestureId() >= 21))
  5462. {
  5463. return; //No shadows on a fall!
  5464. }
  5465. if (getTeamId() != Team::home->getId())
  5466. {
  5467. //---------------------------------------------------------------
  5468. // DO Sensor contact stuff here. GLENN, Update with new whatevers when done and let me know!
  5469. // -fs
  5470. long cStat = conStat;
  5471. if ((cStat == CONTACT_VISUAL) && (alphaValue == 0xff))
  5472. {
  5473. appearance->renderShadows();
  5474. }
  5475. }
  5476. else //We are Home Team and we always see ourselves. Unless we haven't linked up yet!
  5477. {
  5478. if (isOnGui && (alphaValue == 0xff))
  5479. {
  5480. appearance->renderShadows();
  5481. }
  5482. }
  5483. }
  5484. }
  5485. //----------------------------------------------------------------------------------
  5486. float BattleMech::relFacingTo (Stuff::Vector3D goal, long bodyLocation) {
  5487. float relFacing = Mover::relFacingTo(goal);
  5488. switch (bodyLocation) {
  5489. case MECH_BODY_LOCATION_HEAD:
  5490. case MECH_BODY_LOCATION_CTORSO:
  5491. case MECH_BODY_LOCATION_LTORSO:
  5492. case MECH_BODY_LOCATION_RTORSO:
  5493. relFacing += torsoRotation;
  5494. break;
  5495. case MECH_ARMOR_LOCATION_RCTORSO:
  5496. case MECH_ARMOR_LOCATION_RLTORSO:
  5497. case MECH_ARMOR_LOCATION_RRTORSO:
  5498. relFacing += (torsoRotation /* + 180.0*/);
  5499. break;
  5500. case MECH_BODY_LOCATION_LARM:
  5501. relFacing += (torsoRotation + leftArmRotation);
  5502. break;
  5503. case MECH_BODY_LOCATION_RARM:
  5504. relFacing += (torsoRotation + rightArmRotation);
  5505. break;
  5506. case MECH_BODY_LOCATION_RLEG:
  5507. case MECH_BODY_LOCATION_LLEG:
  5508. break;
  5509. default:
  5510. //--------------------------------------------------------------------
  5511. // Facing for a mech is ALWAYS based on Torso Rotation by default!!!
  5512. //relFacing += torsoRotation;
  5513. break;
  5514. }
  5515. //if (relFacing < -180.0)
  5516. // relFacing += 360.0;
  5517. //else if (relFacing > 180)
  5518. // relFacing -= 360.0;
  5519. return(relFacing);
  5520. }
  5521. //---------------------------------------------------------------------------
  5522. // COMBAT routines
  5523. //---------------------------------------------------------------------------
  5524. long BattleMech::getBodyState (void) {
  5525. long gID = appearance->getCurrentGestureId();
  5526. return(MechStateByGesture[gID]);
  5527. }
  5528. //---------------------------------------------------------------------------
  5529. bool BattleMech::isWeaponReady (long weaponIndex) {
  5530. // long bodyLocation = inventory[weaponIndex].bodyLocation;
  5531. // if ((bodyLocation == MECH_BODY_LOCATION_LARM) && inventory[actuator[ACTUATOR_LSHOULDER]].disabled)
  5532. // return(false);
  5533. // else if ((bodyLocation == MECH_BODY_LOCATION_RARM) && inventory[actuator[ACTUATOR_RSHOULDER]].disabled)
  5534. // return(false);
  5535. // else
  5536. if (inventory[weaponIndex].disabled || !(inventory[weaponIndex].health))
  5537. return(false);
  5538. else if (inventory[weaponIndex].readyTime > scenarioTime)
  5539. return(false);
  5540. return(true);
  5541. }
  5542. //---------------------------------------------------------------------------
  5543. float BattleMech::calcAttackChance (GameObjectPtr target, long aimLocation, float targetTime, long weaponIndex, float modifiers, long* range, Stuff::Vector3D* targetPoint) {
  5544. if ((weaponIndex < numOther) || (weaponIndex >= numOther + numWeapons))
  5545. return(-1000.0);
  5546. // if (pilot)
  5547. // modifiers += RankVersusChassisCombatModifier[pilot->getRank()][chassisClass];
  5548. float attackChance = Mover::calcAttackChance(target, aimLocation, targetTime, weaponIndex, modifiers, range, targetPoint);
  5549. return(attackChance);
  5550. }
  5551. //---------------------------------------------------------------------------
  5552. long BattleMech::calcHitLocation (GameObjectPtr attacker, long weaponIndex, long attackSource, long attackType) {
  5553. //---------------------------------------------------------------------
  5554. // Need to use the Line-of-fire params to calc section and arc of hit.
  5555. // For now, just use the arc of entry to the target, and select section
  5556. // without using obstructions...
  5557. long armorLocation = -1;
  5558. //-----------------------------------------
  5559. // Section depends upon source of attack...
  5560. long section = MechHitSectionTable[attackSource];
  5561. //------------
  5562. // Find arc...
  5563. float entryAngle = 0.0;
  5564. if (attacker)
  5565. entryAngle = relFacingTo(attacker->getPosition());
  5566. else
  5567. entryAngle = RandomNumber(360) - 180;
  5568. long arc;
  5569. if ((entryAngle >= -45.0) && (entryAngle <= 45.0))
  5570. arc = MECH_HIT_ARC_FRONT;
  5571. else if ((entryAngle > -135.0) && (entryAngle < -45.0))
  5572. arc = MECH_HIT_ARC_LEFT;
  5573. else if ((entryAngle > 45.0) && (entryAngle < 135))
  5574. arc = MECH_HIT_ARC_RIGHT;
  5575. else
  5576. arc = MECH_HIT_ARC_REAR;
  5577. if (attackSource == ATTACKSOURCE_MINE) // if this came from a mine
  5578. {
  5579. if (getAppearance()->getOldGestureGoal() == MECH_STATE_FALLEN_FORWARD)
  5580. {
  5581. arc = MECH_HIT_ARC_FRONT;
  5582. section = MECH_HIT_SECTION_MIDDLE;
  5583. }
  5584. if (getAppearance()->getOldGestureGoal() == MECH_STATE_FALLEN_BACKWARD)
  5585. {
  5586. arc = MECH_HIT_ARC_REAR;
  5587. section = MECH_HIT_SECTION_MIDDLE;
  5588. }
  5589. }
  5590. //-------------------------------
  5591. // Roll, and see where it hits...
  5592. long locationRoll = RandomNumber(100);
  5593. long startEntry = section * (NUM_MECH_ARMOR_LOCATIONS * NUM_MECH_HIT_ARCS) + (arc * NUM_MECH_ARMOR_LOCATIONS);
  5594. for (armorLocation = 0; armorLocation < NUM_MECH_ARMOR_LOCATIONS; armorLocation++) {
  5595. if (locationRoll < MechHitLocationTable[startEntry + armorLocation])
  5596. break;
  5597. locationRoll -= MechHitLocationTable[startEntry + armorLocation];
  5598. }
  5599. return(armorLocation);
  5600. }
  5601. //---------------------------------------------------------------------------
  5602. long BattleMech::transferHitLocation (long hitLocation) {
  5603. Assert((hitLocation >= 0) && (hitLocation < NUM_MECH_BODY_LOCATIONS), hitLocation, " BattleMech.transferHitLocation: bad hitLocation ");
  5604. return(MechTransferHitTable[hitLocation]);
  5605. }
  5606. //---------------------------------------------------------------------------
  5607. bool BattleMech::isJumping (Stuff::Vector3D* goal) {
  5608. if (goal)
  5609. *goal = jumpGoal;
  5610. return(inJump);
  5611. }
  5612. //---------------------------------------------------------------------------
  5613. float BattleMech::getJumpRange (long* numOffsets, long* jumpCost) {
  5614. //static long jetsToOffsets[7] = {8, 16, 40, 56, 72, 88, 104};
  5615. static long jetsToOffsets[6] = {8, 32, 56, 80, 104, 128};
  5616. long numJets = numJumpJets;
  5617. if (getPilot()->isLongJump())
  5618. numJets++;
  5619. if (numOffsets) {
  5620. if (numJets > 5)
  5621. *numOffsets = jetsToOffsets[5];
  5622. else
  5623. *numOffsets = jetsToOffsets[numJets];
  5624. }
  5625. if (jumpCost) {
  5626. if (numJets > 0)
  5627. *jumpCost = DefaultMechJumpCost;
  5628. else
  5629. *jumpCost = 0;
  5630. }
  5631. return((float)numJets * Terrain::worldUnitsPerVertex);
  5632. }
  5633. //---------------------------------------------------------------------------
  5634. bool BattleMech::handleFall (bool forward) {
  5635. return(false);
  5636. }
  5637. //---------------------------------------------------------------------------
  5638. bool BattleMech::handleEjection (void) {
  5639. //-------------------------------------------------------
  5640. // Let's let the unit know we're gone if we're a point...
  5641. // Don't do this!!! if we loose the point, we have no point! Simple, no?
  5642. // if (getPoint() == this) {
  5643. // MoverPtr newPointVehicle = getGroup()->selectPoint(true);
  5644. //--------------------------------------------------------
  5645. // If there is no new point, all units must be blown away.
  5646. // How do we want to handle this?
  5647. // }
  5648. if (pilot && ((pilot->getStatus() == WARRIOR_STATUS_NORMAL) || (pilot->getStatus() == WARRIOR_STATUS_WITHDRAWING))) {
  5649. //----------------
  5650. // First, eject...
  5651. getPilot()->eject();
  5652. ejectOrderGiven = true;
  5653. //------------------
  5654. // The head blows...
  5655. destroyBodyLocation(MECH_BODY_LOCATION_HEAD);
  5656. //---------------------
  5657. // Create the Eject FX
  5658. // WHEN READY -fs
  5659. if (CombatLog)
  5660. {
  5661. char s[1024];
  5662. sprintf(s, "[%.2f] mech.Ejected HE: [%05d]%s", scenarioTime, getPartId(), getName());
  5663. CombatLog->write(s);
  5664. CombatLog->write(" ");
  5665. }
  5666. //---------------------------------------------
  5667. // If we aren't already disabled, we are now...
  5668. disable(EJECTION_DEATH);
  5669. #ifdef USE_IFACE
  5670. //------------------------------------------------------
  5671. // The interface needs to know I'm not around anymore...
  5672. theInterface->RemoveMech(getPartId());
  5673. #endif
  5674. #ifdef USE_MOODMUSIC
  5675. //------------------------------------
  5676. // What heroic music should be played?
  5677. if (alignment == homeTeam->getAlignment())
  5678. friendlyDestroyed = true;
  5679. else
  5680. enemyDestroyed = true;
  5681. #endif
  5682. }
  5683. return(true);
  5684. }
  5685. //---------------------------------------------------------------------------
  5686. bool BattleMech::hitInventoryItem (long itemIndex, bool setupOnly) {
  5687. //HOW ABOUT...
  5688. // BEFORE we go Trapsing thrugh memory, we assure ourselves
  5689. // that this itemIndex is in the mech?
  5690. if ((itemIndex < 0) || (itemIndex >= (numOther + numWeapons + numAmmos)))
  5691. return false;
  5692. (inventory[itemIndex].health)--;
  5693. bool itemDisabled = false;
  5694. long masterID = inventory[itemIndex].masterID;
  5695. long bodyLocation = inventory[itemIndex].bodyLocation;
  5696. //---------------------------------------------------------------------------
  5697. // First, apply any effects caused whenever this component is hit (regardless
  5698. // of whether it's been disabled or destroyed with this hit)...
  5699. switch (MasterComponent::masterList[masterID].getForm()) {
  5700. case COMPONENT_FORM_SIMPLE:
  5701. break;
  5702. case COMPONENT_FORM_COCKPIT:
  5703. break;
  5704. case COMPONENT_FORM_SENSOR:
  5705. break;
  5706. case COMPONENT_FORM_ACTUATOR:
  5707. if ((bodyLocation == MECH_BODY_LOCATION_LLEG) || (MECH_BODY_LOCATION_RLEG))
  5708. pilotingCheck(0); //pilotCheckModifier += PilotCheckModifierTable[0];
  5709. break;
  5710. case COMPONENT_FORM_ENGINE:
  5711. break;
  5712. case COMPONENT_FORM_HEATSINK:
  5713. case COMPONENT_FORM_WEAPON:
  5714. case COMPONENT_FORM_WEAPON_ENERGY:
  5715. case COMPONENT_FORM_WEAPON_BALLISTIC:
  5716. case COMPONENT_FORM_WEAPON_MISSILE:
  5717. break;
  5718. case COMPONENT_FORM_AMMO:
  5719. break;
  5720. case COMPONENT_FORM_JUMPJET:
  5721. break;
  5722. case COMPONENT_FORM_CASE:
  5723. break;
  5724. case COMPONENT_FORM_LIFESUPPORT:
  5725. break;
  5726. case COMPONENT_FORM_GYROSCOPE:
  5727. pilotingCheck(0); //pilotCheckModifier += PilotCheckModifierTable[1];
  5728. break;
  5729. case COMPONENT_FORM_POWER_AMPLIFIER:
  5730. case COMPONENT_FORM_BULK:
  5731. break;
  5732. }
  5733. if (getInventoryDamage(itemIndex) >= MasterComponent::masterList[masterID].getDisableLevel()) {
  5734. //---------------------------------------
  5735. // Component is disabled with this hit...
  5736. inventory[itemIndex].disabled = true;
  5737. itemDisabled = true;
  5738. long damageHotSpot = 1;
  5739. //---------------------------------------------------------------------
  5740. // Now, we need to apply any special effects caused by this component's
  5741. // disabling blow...
  5742. switch (MasterComponent::masterList[masterID].getForm()) {
  5743. case COMPONENT_FORM_SIMPLE:
  5744. case COMPONENT_FORM_COCKPIT:
  5745. damageHotSpot = 2;
  5746. break;
  5747. case COMPONENT_FORM_SENSOR:
  5748. //Sensors CANNOT be destroyed anymore. Non-Sensor mechs lose all line of sight then.
  5749. // If you want to destroy the sensor mech, blow it up!
  5750. // if (sensorSystem)
  5751. // sensorSystem->broken = true;
  5752. break;
  5753. case COMPONENT_FORM_ECM:
  5754. #if 0
  5755. Team::teams[teamId]->removeECM(teamEcmTracker);
  5756. teamEcmTracker = NULL;
  5757. #endif
  5758. break;
  5759. case COMPONENT_FORM_JAMMER:
  5760. #if 0
  5761. Team::teams[teamId]->removeJammer(teamJammerTracker);
  5762. teamJammerTracker = NULL;
  5763. #endif
  5764. break;
  5765. case COMPONENT_FORM_ACTUATOR:
  5766. damageHotSpot = 0;
  5767. break;
  5768. case COMPONENT_FORM_ENGINE:
  5769. engineBlowTime = scenarioTime + 5.0;
  5770. damageHotSpot = 1;
  5771. disable(ENGINE_DEATH);
  5772. break;
  5773. case COMPONENT_FORM_HEATSINK:
  5774. #ifdef USEHEAT
  5775. if ((inventory[itemIndex].bodyLocation == MECH_BODY_LOCATION_LLEG) || (inventory[itemIndex].bodyLocation == MECH_BODY_LOCATION_RLEG))
  5776. curLegHeatSinks--;
  5777. disabledHeatSinks++;
  5778. heatDissipation = calcHeatDissipation();
  5779. damageHotSpot = 1;
  5780. #endif
  5781. break;
  5782. case COMPONENT_FORM_WEAPON:
  5783. case COMPONENT_FORM_WEAPON_ENERGY:
  5784. case COMPONENT_FORM_WEAPON_BALLISTIC:
  5785. case COMPONENT_FORM_WEAPON_MISSILE:
  5786. calcWeaponEffectiveness(false);
  5787. calcFireRanges();
  5788. damageHotSpot = 0;
  5789. pilot->radioMessage(RADIO_WEAPON_DOWN);
  5790. break;
  5791. case COMPONENT_FORM_AMMO:
  5792. break;
  5793. case COMPONENT_FORM_JUMPJET:
  5794. //numJumpJets--;
  5795. break;
  5796. case COMPONENT_FORM_CASE:
  5797. body[inventory[itemIndex].bodyLocation].CASE = false;
  5798. break;
  5799. case COMPONENT_FORM_LIFESUPPORT:
  5800. case COMPONENT_FORM_GYROSCOPE:
  5801. break;
  5802. case COMPONENT_FORM_POWER_AMPLIFIER:
  5803. case COMPONENT_FORM_BULK:
  5804. damageHotSpot = 1;
  5805. break;
  5806. }
  5807. }
  5808. if (inventory[itemIndex].health == 0)
  5809. {
  5810. switch (MasterComponent::masterList[masterID].getForm())
  5811. {
  5812. case COMPONENT_FORM_SIMPLE:
  5813. break;
  5814. case COMPONENT_FORM_COCKPIT:
  5815. //------------------
  5816. // Kill the pilot...
  5817. pilot->injure(6, false);
  5818. break;
  5819. case COMPONENT_FORM_SENSOR:
  5820. break;
  5821. case COMPONENT_FORM_ACTUATOR:
  5822. if ((bodyLocation == MECH_BODY_LOCATION_LLEG) || (bodyLocation == MECH_BODY_LOCATION_RLEG))
  5823. pilotingCheck(PILOTCHECK_SITUATION_NONE, 100.0); //pilotCheckModifier += 1000;
  5824. break;
  5825. case COMPONENT_FORM_ENGINE:
  5826. break;
  5827. case COMPONENT_FORM_HEATSINK:
  5828. case COMPONENT_FORM_WEAPON:
  5829. case COMPONENT_FORM_WEAPON_ENERGY:
  5830. case COMPONENT_FORM_WEAPON_BALLISTIC:
  5831. case COMPONENT_FORM_WEAPON_MISSILE:
  5832. break;
  5833. case COMPONENT_FORM_AMMO:
  5834. ammoExplosion(itemIndex);
  5835. break;
  5836. case COMPONENT_FORM_JUMPJET:
  5837. case COMPONENT_FORM_CASE:
  5838. case COMPONENT_FORM_LIFESUPPORT:
  5839. break;
  5840. case COMPONENT_FORM_GYROSCOPE:
  5841. //shutDown();
  5842. break;
  5843. case COMPONENT_FORM_POWER_AMPLIFIER:
  5844. case COMPONENT_FORM_BULK:
  5845. break;
  5846. }
  5847. if (!setupOnly && !playedCriticalHit)
  5848. {
  5849. //----------------------------------------------
  5850. // Play critical Hit effect here.
  5851. Stuff::Vector3D smokePos = appearance->getNodePosition(0);
  5852. ObjectManager->createExplosion(MECH_CRITICAL_HIT_ID,NULL,smokePos);
  5853. appearance->startSmoking(1);
  5854. playedCriticalHit = true;
  5855. }
  5856. }
  5857. return(false);
  5858. }
  5859. //---------------------------------------------------------------------------
  5860. void BattleMech::destroyBodyLocation (long bodyLocation) {
  5861. if (body[bodyLocation].damageState == IS_DAMAGE_DESTROYED)
  5862. return;
  5863. // char report[50];
  5864. // sprintf(report, "body location %d destroyed.", bodyLocation);
  5865. // pilot->postReport(REPORTCODE_DEBUGGING, report);
  5866. //----------------------------------------------------------------------
  5867. // Effectively wipe out all critical spaces in the destroyed location...
  5868. body[bodyLocation].curInternalStructure = 0;
  5869. body[bodyLocation].damageState = IS_DAMAGE_DESTROYED;
  5870. armor[bodyLocation].curArmor = 0;
  5871. if ((bodyLocation == MECH_BODY_LOCATION_LLEG) || (bodyLocation == MECH_BODY_LOCATION_RLEG)) {
  5872. calcLegStatus();
  5873. //----------------
  5874. // Force a fall...
  5875. pilotingCheck(PILOTCHECK_SITUATION_NONE, 100.0); //pilotCheckModifier += 1000;
  5876. }
  5877. else if (bodyLocation == MECH_BODY_LOCATION_CTORSO)
  5878. calcTorsoStatus();
  5879. for (long curSpace = 0; curSpace < NumLocationCriticalSpaces[bodyLocation]; curSpace++) {
  5880. if (!body[bodyLocation].criticalSpaces[curSpace].hit)
  5881. if (body[bodyLocation].criticalSpaces[curSpace].inventoryID != 255) {
  5882. //long form = MasterComponent::masterList[inventory[body[bodyLocation].criticalSpaces[curSpace].inventoryID].masterID].getForm();
  5883. //if ((form != COMPONENT_FORM_BULK) && (form != COMPONENT_FORM_CASE)) {
  5884. body[bodyLocation].criticalSpaces[curSpace].hit = true;
  5885. hitInventoryItem(body[bodyLocation].criticalSpaces[curSpace].inventoryID);
  5886. //}
  5887. }
  5888. }
  5889. //----------------------------------------------------------------------
  5890. // If the location is a side torso, destroy the attached arm, as well...
  5891. if (bodyLocation == MECH_BODY_LOCATION_CTORSO) {
  5892. //----------------------------------------------------------------
  5893. // Mech essentially destroyed. Does it explode or simply shutdown?
  5894. // For now, it's always exploding...
  5895. if ((scenarioTime <= centerTorsoBlowTime) || ((engineBlowTime > -1.0) && (scenarioTime <= engineBlowTime))) {
  5896. //------------------
  5897. // Should explode...
  5898. pilot->handleAlarm(PILOT_ALARM_VEHICLE_INCAPACITATED, 0);
  5899. ObjectManager->getObjectType(typeHandle)->handleDestruction(this, NULL);
  5900. }
  5901. else {
  5902. //-------------------
  5903. // Should shutdown...
  5904. disable(ENGINE_DEATH);
  5905. }
  5906. }
  5907. else if (bodyLocation == MECH_BODY_LOCATION_RTORSO)
  5908. destroyBodyLocation(MECH_BODY_LOCATION_RARM);
  5909. else if (bodyLocation == MECH_BODY_LOCATION_LTORSO)
  5910. destroyBodyLocation(MECH_BODY_LOCATION_LARM);
  5911. else if (bodyLocation == MECH_BODY_LOCATION_LARM)
  5912. leftArmBlownThisFrame = true;
  5913. else if (bodyLocation == MECH_BODY_LOCATION_RARM)
  5914. rightArmBlownThisFrame = true;
  5915. }
  5916. //---------------------------------------------------------------------------
  5917. void BattleMech::calcCriticalHit (long hitLocation) {
  5918. //----------------------------------------------------------
  5919. // If we're playing multiplayer and we're not the server,
  5920. // exit--wait for the critical hit chunks from the server...
  5921. if (MPlayer && !MPlayer->isServer())
  5922. return;
  5923. //----------------------------------------------
  5924. // Cannot critically hit nothing.!!
  5925. if (body[hitLocation].totalSpaces == 0)
  5926. return;
  5927. long numCriticalHits = 0;
  5928. long bodyLocation = MechArmorToBodyLocation[hitLocation];
  5929. long numBodySpaces = NumLocationCriticalSpaces[bodyLocation];
  5930. long criticalRoll = RandomNumber(100);
  5931. if (criticalRoll < CriticalHitTable[0])
  5932. return;
  5933. else if (criticalRoll < CriticalHitTable[1])
  5934. numCriticalHits = 1;
  5935. else if (criticalRoll < CriticalHitTable[2])
  5936. numCriticalHits = 2;
  5937. else if (isTorso(bodyLocation))
  5938. numCriticalHits = 3;
  5939. if (numCriticalHits > 0)
  5940. {
  5941. for (long curHit = 0; curHit < numCriticalHits; curHit++)
  5942. {
  5943. long critHitRoll = RandomNumber(body[bodyLocation].totalSpaces);
  5944. long hitSpace = 0;
  5945. long numSpaces = 0;
  5946. for (hitSpace = 0; hitSpace < numBodySpaces; hitSpace++)
  5947. {
  5948. numSpaces = 0;
  5949. if (body[bodyLocation].criticalSpaces[hitSpace].inventoryID < 255)
  5950. numSpaces = MasterComponent::masterList[inventory[body[bodyLocation].criticalSpaces[hitSpace].inventoryID].masterID].getSize();
  5951. if (critHitRoll < numSpaces)
  5952. break;
  5953. else
  5954. critHitRoll -= numSpaces;
  5955. }
  5956. //If we are out of range, no critical hit!
  5957. if (bodyLocation < 0 || bodyLocation > 7)
  5958. return;
  5959. // STOP(("Bad bodyLocation in CriticalHit %d",bodyLocation));
  5960. if (hitSpace < 0 || hitSpace >= NumLocationCriticalSpaces[bodyLocation])
  5961. return;
  5962. // STOP(("Bad Critical Hit Space %d",hitSpace));
  5963. body[bodyLocation].criticalSpaces[hitSpace].hit = 1;
  5964. hitInventoryItem(body[bodyLocation].criticalSpaces[hitSpace].inventoryID);
  5965. if (MPlayer)
  5966. addCriticalHitChunk(CHUNK_SEND, bodyLocation, hitSpace);
  5967. }
  5968. }
  5969. else
  5970. {
  5971. destroyBodyLocation(bodyLocation);
  5972. if (MPlayer)
  5973. addCriticalHitChunk(CHUNK_SEND, bodyLocation, 15);
  5974. }
  5975. }
  5976. //---------------------------------------------------------------------------
  5977. void BattleMech::handleCriticalHit (long bodyLocation, long criticalSpace) {
  5978. if (criticalSpace == 15)
  5979. destroyBodyLocation(bodyLocation);
  5980. else
  5981. hitInventoryItem(body[bodyLocation].criticalSpaces[criticalSpace].inventoryID);
  5982. }
  5983. //---------------------------------------------------------------------------
  5984. long BattleMech::updateCriticalHitChunks (long which) {
  5985. for (long i = 0; i < numCriticalHitChunks[which]; i++) {
  5986. unsigned char chunkData = criticalHitChunks[which][i];
  5987. long criticalSpace = chunkData & 0x0F;
  5988. long bodyLocation = (chunkData >> 4);
  5989. handleCriticalHit(bodyLocation, criticalSpace);
  5990. }
  5991. numCriticalHitChunks[which] = 0;
  5992. return(NO_ERR);
  5993. }
  5994. //---------------------------------------------------------------------------
  5995. long BattleMech::buildStatusChunk (void) {
  5996. //-----------------------------------------------------------------------
  5997. // For now, we'll just track a failed piloting check for 3 status updates.
  5998. // If all three updates are never received, then the clients won't know
  5999. // to fall! This should be adequate. If it proves otherwise, we can
  6000. // change this...
  6001. statusChunk.init();
  6002. //--------
  6003. // hack...
  6004. // if (appearance->getCurrentGestureId() == 1)
  6005. // bodyState = MECH_STATE_PARKED;
  6006. if (isDestroyed())
  6007. statusChunk.bodyState = MECH_STATUSCHUNK_BODYSTATE_DESTROYED;
  6008. else
  6009. statusChunk.bodyState = getBodyState();
  6010. if (pilot) {
  6011. if (inJump) {
  6012. statusChunk.jumpOrder = true;
  6013. long cellRC[2];
  6014. land->worldToCell(jumpGoal, cellRC[0], cellRC[1]);
  6015. statusChunk.targetCellRC[0] = cellRC[0];
  6016. statusChunk.targetCellRC[1] = cellRC[1];
  6017. }
  6018. else {
  6019. GameObjectPtr curTarget = pilot->getLastTarget();
  6020. if (curTarget) {
  6021. if (curTarget->isMover()) {
  6022. statusChunk.targetType = STATUSCHUNK_TARGET_MOVER;
  6023. statusChunk.targetId = ((MoverPtr)curTarget)->getNetRosterIndex();
  6024. }
  6025. else if (curTarget->isTerrainObject()) {
  6026. statusChunk.targetType = STATUSCHUNK_TARGET_TERRAIN;
  6027. statusChunk.targetId = curTarget->getPartId();
  6028. }
  6029. else
  6030. Fatal(curTarget->getObjectClass(), " BattleMech.buildStatusChunk: bad target type ");
  6031. }
  6032. }
  6033. }
  6034. statusChunk.ejectOrderGiven = ejectOrderGiven;
  6035. statusChunk.pack(this);
  6036. #ifdef DEBUG_CHUNKS
  6037. StatusChunk chunk2;
  6038. chunk2.data = statusChunk.data;
  6039. chunk2.unpack(this);
  6040. if (!statusChunk.equalTo(&chunk2))
  6041. Fatal(0, " BAD status chunk in mech: save stchunk.dbg file! ");
  6042. #endif
  6043. return(NO_ERR);
  6044. }
  6045. //---------------------------------------------------------------------------
  6046. long BattleMech::handleStatusChunk (long updateAge, unsigned long chunk) {
  6047. statusChunk.init();
  6048. statusChunk.data = chunk;
  6049. statusChunk.unpack(this);
  6050. //------------------------------------------------------------
  6051. // HACK!!!!!!!!!!!!!! If bad packet, no statuschunk for you...
  6052. if (StatusChunkUnpackErr != 0)
  6053. return(NO_ERR); //Assert(0, " BAD PACKET! ");
  6054. long lastTargetId = 0;
  6055. if (!statusChunk.jumpOrder) {
  6056. if (statusChunk.targetType > STATUSCHUNK_TARGET_NONE) {
  6057. switch (statusChunk.targetType) {
  6058. case STATUSCHUNK_TARGET_MOVER:
  6059. if (MPlayer->moverRoster[statusChunk.targetId])
  6060. lastTargetId = MPlayer->moverRoster[statusChunk.targetId]->getPartId();
  6061. break;
  6062. case STATUSCHUNK_TARGET_TERRAIN:
  6063. case STATUSCHUNK_TARGET_SPECIAL:
  6064. lastTargetId = statusChunk.targetId;
  6065. break;
  6066. }
  6067. }
  6068. }
  6069. if (pilot) {
  6070. if (lastTargetId == 0)
  6071. pilot->setLastTarget(NULL);
  6072. else {
  6073. GameObjectPtr curTarget = pilot->getLastTarget();
  6074. if (!curTarget || (curTarget->getPartId() != lastTargetId)) {
  6075. curTarget = ObjectManager->findByPartId(lastTargetId);
  6076. pilot->setLastTarget(curTarget);
  6077. }
  6078. }
  6079. if (!ejectOrderGiven && statusChunk.ejectOrderGiven) {
  6080. //--------------------------
  6081. // Just given eject order...
  6082. ejectOrderGiven = true;
  6083. handleEjection();
  6084. }
  6085. }
  6086. if (statusChunk.bodyState == MECH_STATUSCHUNK_BODYSTATE_DESTROYED)
  6087. setStatus(OBJECT_STATUS_DESTROYED);
  6088. return(NO_ERR);
  6089. }
  6090. //---------------------------------------------------------------------------
  6091. #pragma optimize("",off)
  6092. long BattleMech::buildMoveChunk (void) {
  6093. moveChunk.init();
  6094. if (pilot) {
  6095. //--------------------------------------------
  6096. // First, make sure we have the latest path...
  6097. pilot->getMovePath();
  6098. //--------------------------------------------------
  6099. // Now, use it (and any queued one, if available)...
  6100. moveChunk.build(this, pilot->getMovePath(0), pilot->getMovePath(1));
  6101. }
  6102. moveChunk.pack(this);
  6103. #ifdef DEBUG_CHUNKS
  6104. MoveChunk chunk2;
  6105. chunk2.data = moveChunk.data;
  6106. chunk2.unpack(this);
  6107. //----------------------------------------------------------
  6108. // HACK!!!!!!!!!!!!!! If bad packet, no movechunk for you...
  6109. if (MoveChunk::err != 0) {
  6110. moveChunk.init();
  6111. moveChunk.build(this, NULL, NULL);
  6112. moveChunk.pack(this);
  6113. return(NO_ERR); //Assert(0, " BAD PACKET! ");
  6114. }
  6115. if (!moveChunk.equalTo(this, &chunk2))
  6116. Fatal(0, " Bad mech movechunk: save mvchunk.dbg file! ");
  6117. #endif
  6118. return(NO_ERR);
  6119. }
  6120. //---------------------------------------------------------------------------
  6121. long BattleMech::handleMoveChunk (unsigned long chunk) {
  6122. moveChunk.init();
  6123. moveChunk.data = chunk;
  6124. moveChunk.unpack(this);
  6125. //----------------------------------------------------------
  6126. // HACK!!!!!!!!!!!!!! If bad packet, no movechunk for you...
  6127. if (MoveChunk::err != 0)
  6128. return(NO_ERR); //Assert(0, " BAD PACKET! ");
  6129. MovePathPtr path = getPilot()->getMovePath();
  6130. setMoveChunk(path, &moveChunk);
  6131. //-------------------------------------------------------------
  6132. // Now, let's determine which opening step we're closest to so
  6133. // we don't loop back to the first step everytime we get a new
  6134. // chunk of the path...
  6135. if (path->numStepsWhenNotPaused > 1) {
  6136. long i = 0;
  6137. for (i = path->numStepsWhenNotPaused - 1; i > 0; i--) {
  6138. float distanceFromPt = distanceFrom(path->stepList[i].destination);
  6139. if (distanceFromPt <= MapCellDiagonal)
  6140. break;
  6141. }
  6142. path->setCurStep(i);
  6143. }
  6144. newMoveChunk = true;
  6145. return(NO_ERR);
  6146. }
  6147. #pragma optimize("",on)
  6148. //---------------------------------------------------------------------------
  6149. bool BattleMech::injureBodyLocation (long bodyLocation, float damage) {
  6150. BodyLocationPtr location = &body[bodyLocation];
  6151. if ((bodyLocation == MECH_BODY_LOCATION_CTORSO) && (centerTorsoBlowTime < 0.0))
  6152. centerTorsoBlowTime = scenarioTime;
  6153. if (damage > location->curInternalStructure)
  6154. location->curInternalStructure = 0;
  6155. else
  6156. location->curInternalStructure -= damage;
  6157. if (location->curInternalStructure > 0) {
  6158. float damageLevel = (float)body[bodyLocation].curInternalStructure / body[bodyLocation].maxInternalStructure;
  6159. if (damageLevel <= 0.5)
  6160. body[bodyLocation].damageState = IS_DAMAGE_PARTIAL;
  6161. else
  6162. body[bodyLocation].damageState = IS_DAMAGE_NONE;
  6163. if ((bodyLocation == MECH_BODY_LOCATION_LLEG) || (bodyLocation == MECH_BODY_LOCATION_RLEG))
  6164. calcLegStatus();
  6165. else if (bodyLocation == MECH_BODY_LOCATION_CTORSO)
  6166. calcTorsoStatus();
  6167. calcCriticalHit(bodyLocation);
  6168. }
  6169. else {
  6170. destroyBodyLocation(bodyLocation);
  6171. return(true);
  6172. }
  6173. //-----------------------------------------------
  6174. // Location was not destroyed, so return false...
  6175. return(false);
  6176. }
  6177. //---------------------------------------------------------------------------
  6178. float BattleMech::weaponLocked (long weaponIndex, Stuff::Vector3D targetPosition) {
  6179. return(relFacingTo(targetPosition, inventory[weaponIndex].bodyLocation));
  6180. }
  6181. //---------------------------------------------------------------------------
  6182. #if 0
  6183. // UNDER CONSTRUCTION :)
  6184. bool weaponsLockedWithApproach (vector_3d goalPos, vector_3d targetPos, bool forwardApproached) {
  6185. GameObjectPtr target = pilot->getCurrentTarget();
  6186. if (!target)
  6187. return(-2);
  6188. vector_3d targetPosition = target->getPosition();
  6189. long numLocked = 0;
  6190. float fireArc = getFireArc();
  6191. if (listSize == -1)
  6192. for (long item = numOther; item < (numOther + numWeapons); item++) {
  6193. float relAngle = weaponLocked(item, targetPosition);
  6194. if ((relAngle >= -fireArc) && (relAngle <= fireArc))
  6195. list[numLocked++] = item;
  6196. }
  6197. else
  6198. for (long item = 0; item < listSize; item++) {
  6199. float relAngle = weaponLocked(list[item], targetPosition);
  6200. if ((relAngle >= -fireArc) && (relAngle <= fireArc))
  6201. list[numLocked++] = list[item];
  6202. }
  6203. return(numLocked);
  6204. }
  6205. #endif
  6206. //---------------------------------------------------------------------------
  6207. long BattleMech::handleWeaponHit (WeaponShotInfoPtr shotInfo, bool addMultiplayChunk)
  6208. {
  6209. bool localInvulnerable = false;
  6210. if (invulnerableON && Team::home == getTeam())
  6211. localInvulnerable = true;
  6212. if (!shotInfo)
  6213. return(NO_ERR);
  6214. printHandleWeaponHitDebugInfo(shotInfo);
  6215. if ((getTeam() && Team::noPain[getTeamId()]) || localInvulnerable)
  6216. return(NO_ERR);
  6217. if (!MPlayer && CantTouchThis && pilot->onHomeTeam())
  6218. return(NO_ERR);
  6219. //-----------------
  6220. // FOR DEBUGGING...
  6221. GameObjectPtr attacker = ObjectManager->getByWatchID(shotInfo->attackerWID);
  6222. BadGuy = attacker;
  6223. //----------------------------------
  6224. // Is this possible? Just in case...
  6225. if ((shotInfo->damage <= 0) || (shotInfo->hitLocation == -1))
  6226. return(NO_ERR);
  6227. //-------------------------------------------------------------------
  6228. // This may not be possible, but just in case. Possibly someone nails
  6229. // a mech after it's been destroyed, but before it's deleted from
  6230. // the object list...
  6231. if (isDestroyed())
  6232. return(NO_ERR);
  6233. numWeaponHitsHandled++;
  6234. if (addMultiplayChunk)
  6235. MPlayer->addWeaponHitChunk(this, shotInfo);
  6236. if (isDisabled() && fallen)
  6237. {
  6238. if (getMoveType() == MOVETYPE_GROUND)
  6239. {
  6240. damageAfterDisabled += shotInfo->damage;
  6241. if (damageAfterDisabled > ((BattleMechTypePtr)getObjectType())->destructDamage)
  6242. {
  6243. //Once the server does this, the status chunk will update the clients!!
  6244. if (!MPlayer || (MPlayer && MPlayer->isServer()))
  6245. {
  6246. timeLeft = 1.0f;
  6247. setStatus(OBJECT_STATUS_DESTROYED);
  6248. exploding = false;
  6249. for (long i=0;i<numBodyLocations;i++) //Blow all of the components. NO SALVAGE!!
  6250. destroyBodyLocation(i);
  6251. if (CombatLog) {
  6252. char s[1024];
  6253. sprintf(s, "[%.2f] mech.destroyed HWH: [%05d]%s", scenarioTime, getPartId(), getName());
  6254. CombatLog->write(s);
  6255. CombatLog->write(" ");
  6256. }
  6257. }
  6258. }
  6259. }
  6260. else
  6261. {
  6262. //Its a helicopter. Blow it up. No salvage
  6263. setStatus(OBJECT_STATUS_DESTROYED);
  6264. exploding = false;
  6265. for (long i=0;i<numBodyLocations;i++) //Blow all of the components. NO SALVAGE!!
  6266. destroyBodyLocation(i);
  6267. #ifdef USE_MOODMUSIC
  6268. //------------------------------------
  6269. // What heroic music should be played?
  6270. if (collidee->getAlignment() == Team::home->getAlignment())
  6271. friendlyDestroyed = true;
  6272. else
  6273. enemyDestroyed = true;
  6274. #endif
  6275. if (CombatLog) {
  6276. char s[1024];
  6277. sprintf(s, "[%.2f] helicopter.destroyed: [%05d]%s", scenarioTime, getPartId(), getName());
  6278. CombatLog->write(s);
  6279. CombatLog->write(" ");
  6280. }
  6281. }
  6282. return(NO_ERR);
  6283. }
  6284. //------------------------------------------------------------
  6285. // Since Multiplayer still needs this, preserve it and restore
  6286. // at the end of this function!
  6287. WeaponShotInfo startShotInfo = *shotInfo;
  6288. bool alreadyDisabled = isDisabled();
  6289. bool isAmmoExplosion = false;
  6290. isAmmoExplosion = (shotInfo->masterId == -4);
  6291. if (shotInfo->masterId > 0)
  6292. isAmmoExplosion = (MasterComponent::masterList[shotInfo->masterId].getForm() == COMPONENT_FORM_AMMO);
  6293. //pilotCheckModifier += (shotInfo->damage * PilotingCheckFactor);
  6294. //---------------------------------------------------
  6295. // Tally the damage for rate check and pilot check...
  6296. damageRateTally += shotInfo->damage;
  6297. pilotCheckDamageTally += shotInfo->damage;
  6298. //---------------------------------
  6299. // Did the hit cause us to stumble?
  6300. float torsoEntryAngle = shotInfo->entryAngle + torsoRotation;
  6301. if ((torsoEntryAngle >= -90.0/*-45.0*/) && (torsoEntryAngle <= 90.0/*45.0*/))
  6302. hitFromFrontThisFrame = true;
  6303. else if ((torsoEntryAngle <= -91.0/*-135.0*/) || (torsoEntryAngle >= 91.0/*135.0*/))
  6304. hitFromBehindThisFrame = true;
  6305. //-----------------------------------
  6306. // First, what type of hit is this...
  6307. damageThisFrame += shotInfo->damage;
  6308. long totalHitType = 0;
  6309. if (damageThisFrame < hitLevel[0])
  6310. totalHitType = HIT_TYPE_WEAK;
  6311. else if (damageThisFrame < hitLevel[1])
  6312. totalHitType = HIT_TYPE_MODERATE;
  6313. else
  6314. totalHitType = HIT_TYPE_HEAVY;
  6315. long hitType = 0;
  6316. if (shotInfo->damage < hitLevel[0])
  6317. hitType = HIT_TYPE_WEAK;
  6318. else if (shotInfo->damage < hitLevel[1])
  6319. hitType = HIT_TYPE_MODERATE;
  6320. else
  6321. hitType = HIT_TYPE_HEAVY;
  6322. //------------------------------------------------
  6323. // If this was a heavy hit, play the hit gesture.
  6324. if (!MPlayer && (totalHitType == HIT_TYPE_MODERATE) && (getCommanderId() != Commander::home->getId()))
  6325. {
  6326. if ((torsoEntryAngle >= -45.0) && (torsoEntryAngle <= 45.0))
  6327. appearance->hitFront();
  6328. else if ((torsoEntryAngle <= -45.0) && (torsoEntryAngle >= -135.0))
  6329. appearance->hitLeft();
  6330. else if ((torsoEntryAngle >= 45.0) && (torsoEntryAngle <= 135.0))
  6331. appearance->hitRight();
  6332. else if ((torsoEntryAngle <= -135.0) || (torsoEntryAngle >= 135.0))
  6333. appearance->hitBack();
  6334. }
  6335. //-------------------------------------------------------
  6336. // Note that the hitLocation is the ARMOR hit location...
  6337. long bodyLocation = MechArmorToBodyLocation[shotInfo->hitLocation];
  6338. //----------------------------------------
  6339. // Check for any special pilot injuries...
  6340. if ((bodyLocation == MECH_BODY_LOCATION_HEAD) && (shotInfo->damage >= 2))
  6341. pilot->injure(1);
  6342. bool armorHoled = false;
  6343. if ((armor[shotInfo->hitLocation].curArmor > 0) && !isAmmoExplosion)
  6344. {
  6345. if (shotInfo->damage > armor[shotInfo->hitLocation].curArmor)
  6346. {
  6347. shotInfo->setDamage(shotInfo->damage - armor[shotInfo->hitLocation].curArmor);
  6348. armor[shotInfo->hitLocation].curArmor = 0;
  6349. if (!armorHoled)
  6350. pilot->radioMessage(RADIO_ARMORHOLE);
  6351. armorHoled = true;
  6352. //Check for Tutorials here.
  6353. // IN the tutorial missions, your mechs can only have armor damaged. NO INTERNALS ALLOWED!!
  6354. // ONLY the tutorials should set this flag through ABL!!!
  6355. if (!localInvulnerable)
  6356. {
  6357. if (shotInfo->damage >= body[bodyLocation].curInternalStructure)
  6358. {
  6359. shotInfo->setDamage(shotInfo->damage - body[bodyLocation].curInternalStructure);
  6360. injureBodyLocation(bodyLocation, body[bodyLocation].curInternalStructure);
  6361. if (shotInfo->damage > 0)
  6362. {
  6363. if ((bodyLocation == MECH_BODY_LOCATION_CTORSO) || (bodyLocation == MECH_BODY_LOCATION_HEAD))
  6364. {
  6365. //----------------------------------------------------------------------
  6366. // If hit in the center torso, no where else to go...
  6367. // If hit in the head, it is disabled. What that means at this point...?
  6368. // We'll probably want to put a disabled check in there, somewhere :)
  6369. // Most likely, the mech will have been blown up and/or destroyed before
  6370. // it's "disabled"...
  6371. }
  6372. else
  6373. {
  6374. WeaponShotInfo newShotInfo = *shotInfo;
  6375. newShotInfo.hitLocation = transferHitLocation(bodyLocation/*shotInfo->hitLocation*/);
  6376. if (MPlayer)
  6377. {
  6378. if (MPlayer->isServer())
  6379. {
  6380. if (CombatLog)
  6381. CombatLog->write(" HIT TRANSFER 1...");
  6382. handleWeaponHit(&newShotInfo, true);
  6383. }
  6384. }
  6385. else
  6386. {
  6387. if (CombatLog)
  6388. CombatLog->write(" HIT TRANSFER 1...");
  6389. handleWeaponHit(&newShotInfo);
  6390. }
  6391. }
  6392. }
  6393. }
  6394. else
  6395. {
  6396. injureBodyLocation(bodyLocation, shotInfo->damage);
  6397. }
  6398. }
  6399. }
  6400. else
  6401. {
  6402. armor[shotInfo->hitLocation].curArmor -= shotInfo->damage;
  6403. }
  6404. }
  6405. else if (!localInvulnerable) //Again, for tutorials. See above check.
  6406. {
  6407. if (body[bodyLocation].curInternalStructure > 0)
  6408. {
  6409. if (shotInfo->damage >= body[bodyLocation].curInternalStructure)
  6410. {
  6411. shotInfo->setDamage(shotInfo->damage - body[bodyLocation].curInternalStructure);
  6412. injureBodyLocation(bodyLocation, body[bodyLocation].curInternalStructure);
  6413. if (shotInfo->damage > 0)
  6414. {
  6415. if (isAmmoExplosion && body[bodyLocation].CASE)
  6416. {
  6417. //---------------------------------------------
  6418. // Have CASE here, so vent the excess damage...
  6419. long armorLocation = MECH_ARMOR_LOCATION_RCTORSO;
  6420. switch (bodyLocation)
  6421. {
  6422. case MECH_BODY_LOCATION_LTORSO:
  6423. case MECH_BODY_LOCATION_LARM:
  6424. case MECH_BODY_LOCATION_LLEG:
  6425. armorLocation = MECH_ARMOR_LOCATION_RLTORSO;
  6426. break;
  6427. case MECH_BODY_LOCATION_RTORSO:
  6428. case MECH_BODY_LOCATION_RARM:
  6429. case MECH_BODY_LOCATION_RLEG:
  6430. armorLocation = MECH_ARMOR_LOCATION_RRTORSO;
  6431. break;
  6432. }
  6433. if (shotInfo->damage > armor[armorLocation].curArmor)
  6434. {
  6435. armor[armorLocation].curArmor = 0;
  6436. armorHoled = true;
  6437. }
  6438. else
  6439. armor[armorLocation].curArmor -= shotInfo->damage;
  6440. shotInfo->setDamage(0);
  6441. }
  6442. else
  6443. {
  6444. if ((bodyLocation == MECH_BODY_LOCATION_CTORSO) || (bodyLocation == MECH_BODY_LOCATION_HEAD))
  6445. {
  6446. //------------------------------
  6447. // Hit center torso, already, or
  6448. // Head wiped out... what to do?
  6449. }
  6450. else
  6451. {
  6452. WeaponShotInfo newShotInfo = *shotInfo;
  6453. newShotInfo.hitLocation = transferHitLocation(bodyLocation/*shotInfo->hitLocation*/);
  6454. if (MPlayer)
  6455. {
  6456. if (MPlayer->isServer())
  6457. {
  6458. if (CombatLog)
  6459. CombatLog->write(" HIT TRANSFER 2...");
  6460. handleWeaponHit(&newShotInfo, true);
  6461. }
  6462. }
  6463. else
  6464. {
  6465. if (CombatLog)
  6466. CombatLog->write(" HIT TRANSFER 2...");
  6467. handleWeaponHit(&newShotInfo);
  6468. }
  6469. }
  6470. }
  6471. }
  6472. }
  6473. else
  6474. {
  6475. injureBodyLocation(bodyLocation, shotInfo->damage);
  6476. }
  6477. }
  6478. else
  6479. {
  6480. if (isAmmoExplosion && body[bodyLocation].CASE)
  6481. {
  6482. //---------------------------------------------
  6483. // Have CASE here, so vent the excess damage...
  6484. long armorLocation = MECH_ARMOR_LOCATION_RCTORSO;
  6485. switch (bodyLocation)
  6486. {
  6487. case MECH_BODY_LOCATION_LTORSO:
  6488. case MECH_BODY_LOCATION_LARM:
  6489. case MECH_BODY_LOCATION_LLEG:
  6490. armorLocation = MECH_ARMOR_LOCATION_RLTORSO;
  6491. break;
  6492. case MECH_BODY_LOCATION_RTORSO:
  6493. case MECH_BODY_LOCATION_RARM:
  6494. case MECH_BODY_LOCATION_RLEG:
  6495. armorLocation = MECH_ARMOR_LOCATION_RRTORSO;
  6496. break;
  6497. }
  6498. if (shotInfo->damage > armor[armorLocation].curArmor)
  6499. {
  6500. armor[armorLocation].curArmor = 0;
  6501. armorHoled = true;
  6502. }
  6503. else
  6504. armor[armorLocation].curArmor -= shotInfo->damage;
  6505. shotInfo->setDamage(0);
  6506. }
  6507. else
  6508. {
  6509. if ((bodyLocation == MECH_BODY_LOCATION_CTORSO) || (bodyLocation == MECH_BODY_LOCATION_HEAD))
  6510. {
  6511. //------------------------------
  6512. // Already in center torso, or
  6513. // Head wiped out... what to do?
  6514. }
  6515. else
  6516. {
  6517. WeaponShotInfo newShotInfo = *shotInfo;
  6518. newShotInfo.hitLocation = transferHitLocation(bodyLocation/*shotInfo->hitLocation*/);
  6519. if (MPlayer)
  6520. {
  6521. if (MPlayer->isServer())
  6522. {
  6523. if (CombatLog)
  6524. CombatLog->write(" HIT TRANSFER 3...");
  6525. handleWeaponHit(&newShotInfo, true);
  6526. }
  6527. }
  6528. else
  6529. {
  6530. if (CombatLog)
  6531. CombatLog->write(" HIT TRANSFER 3...");
  6532. handleWeaponHit(&newShotInfo);
  6533. }
  6534. }
  6535. }
  6536. }
  6537. }
  6538. //------------------------------------------------------
  6539. // Now, let's apply any remaining effects that should be
  6540. // applied as a result of this hit...
  6541. if (inventory[gyro].disabled)
  6542. {
  6543. switch (hitType)
  6544. {
  6545. case HIT_TYPE_WEAK:
  6546. //-----------------------------------------
  6547. // Torso twists are caused by the impact...
  6548. break;
  6549. case HIT_TYPE_MODERATE:
  6550. //-------------------------------------------------------------
  6551. // A piloting roll should be made to check for possible fall...
  6552. break;
  6553. }
  6554. }
  6555. //---------------------------------------------
  6556. // Let anyone who should know that I was hit...
  6557. //--------------------------------
  6558. // Trigger the WEAPON HIT event...
  6559. if (attacker)
  6560. {
  6561. if (shotInfo->masterId > -1)
  6562. pilot->triggerAlarm(PILOT_ALARM_HIT_BY_WEAPONFIRE, attacker->getWatchID());
  6563. else if (shotInfo->masterId == -4)
  6564. pilot->triggerAlarm(PILOT_ALARM_HIT_BY_WEAPONFIRE, attacker->getWatchID());
  6565. else
  6566. pilot->triggerAlarm(PILOT_ALARM_COLLISION, attacker->getWatchID());
  6567. }
  6568. else
  6569. {
  6570. if (shotInfo->masterId == -4)
  6571. pilot->triggerAlarm(PILOT_ALARM_HIT_BY_WEAPONFIRE, 0);
  6572. else if (shotInfo->masterId < 0) {
  6573. //------------------------------------------------------------
  6574. // If no attacker and a negative weapon masterId, then it must
  6575. // be a mine or artillery...
  6576. pilot->triggerAlarm(PILOT_ALARM_HIT_BY_WEAPONFIRE, shotInfo->masterId);
  6577. }
  6578. else
  6579. pilot->triggerAlarm(PILOT_ALARM_HIT_BY_WEAPONFIRE, 0);
  6580. }
  6581. //--------------------------------------------
  6582. // Calc current CV, after this damage taken...
  6583. curCV = calcCV(false);
  6584. if (isDisabled())
  6585. setThreatRating(1);
  6586. else
  6587. setThreatRating(-1);
  6588. //-----------------------------------------------------
  6589. // If this mech was destroyed, let the attacker know...
  6590. if (!alreadyDisabled && isDisabled()) {
  6591. if (attacker && attacker->isMover())
  6592. {
  6593. ((MoverPtr)attacker)->getPilot()->triggerAlarm(PILOT_ALARM_KILLED_TARGET, getWatchID());
  6594. if (!killed && MPlayer && MPlayer->isServer())
  6595. {
  6596. if (moveType != MOVETYPE_AIR) {
  6597. if (MPlayer->missionSettings.resourceForMechs)
  6598. if (attacker->getCommanderId() != getCommanderId())
  6599. MPlayer->sendReinforcement(getResourcePointValue(), 0, "noname", attacker->getCommanderId(), attacker->getPosition(), 6);
  6600. //MPlayer->playerInfo[attacker->getCommanderId()].resourcePoints += getResourcePointValue();
  6601. if (MPlayer->missionSettings.missionType == MISSION_TYPE_ELIMINATION)
  6602. {
  6603. if (attacker->getCommanderId() != getCommanderId())
  6604. MPlayer->addTeamScore(MPlayer->playerInfo[attacker->getCommanderId()].team, cBills / 100);
  6605. }
  6606. }
  6607. long attackerCID = attacker->getCommanderId();
  6608. if (attackerCID == -1)
  6609. attackerCID = ((MoverPtr)attacker)->prevCommanderId;
  6610. if ((attackerCID == -1) || (attackerCID == getCommanderId()))
  6611. attackerCID = MAX_MC_PLAYERS;
  6612. MPlayer->addKillLossChunk(attackerCID, !lost ? getCommanderId() : MAX_MC_PLAYERS);
  6613. lost = true;
  6614. killed = true;
  6615. }
  6616. }
  6617. else if (attacker && (attacker->getObjectClass() == ARTILLERY))
  6618. {
  6619. if (!killed && MPlayer && MPlayer->isServer())
  6620. {
  6621. if (moveType != MOVETYPE_AIR) {
  6622. if (MPlayer->missionSettings.resourceForMechs)
  6623. if (attacker->getCommanderId() != getCommanderId())
  6624. MPlayer->sendReinforcement(getResourcePointValue(), 0, "noname", attacker->getCommanderId(), attacker->getPosition(), 6);
  6625. //MPlayer->playerInfo[attacker->getCommanderId()].resourcePoints += getResourcePointValue();
  6626. if (MPlayer->missionSettings.missionType == MISSION_TYPE_ELIMINATION)
  6627. {
  6628. if (attacker->getCommanderId() != getCommanderId())
  6629. MPlayer->addTeamScore(MPlayer->playerInfo[attacker->getCommanderId()].team, cBills / 100);
  6630. }
  6631. }
  6632. long attackerCID = attacker->getCommanderId();
  6633. if (attackerCID == -1)
  6634. attackerCID = ((MoverPtr)attacker)->prevCommanderId;
  6635. if ((attackerCID == -1) || (attackerCID == getCommanderId()))
  6636. attackerCID = MAX_MC_PLAYERS;
  6637. MPlayer->addKillLossChunk(attackerCID, !lost ? getCommanderId() : MAX_MC_PLAYERS);
  6638. lost = true;
  6639. killed = true;
  6640. }
  6641. }
  6642. }
  6643. *shotInfo = startShotInfo;
  6644. return(NO_ERR);
  6645. }
  6646. //---------------------------------------------------------------------------
  6647. long BattleMech::fireWeapon (GameObjectPtr target, float targetTime, long weaponIndex, long attackType, long aimLocation, Stuff::Vector3D* targetPoint, float &dmgDone) {
  6648. // if (getTeam() != Team::home)
  6649. // return(1);
  6650. if ((status == OBJECT_STATUS_SHUTDOWN) ||
  6651. (status == OBJECT_STATUS_SHUTTING_DOWN) ||
  6652. (status == OBJECT_STATUS_DISABLED) ||
  6653. (status == OBJECT_STATUS_DESTROYED))
  6654. return(1);
  6655. if ((getBodyState() == MECH_STATUSCHUNK_BODYSTATE_PARKED) ||
  6656. (getBodyState() == MECH_STATUSCHUNK_BODYSTATE_FALLEN_FORWARD) ||
  6657. (getBodyState() == MECH_STATUSCHUNK_BODYSTATE_FALLEN_BACKWARD))
  6658. return(1);
  6659. if (!isWeaponReady(weaponIndex))
  6660. return(3);
  6661. if (!Terrain::IsGameSelectTerrainPosition(getPosition()))
  6662. return (1);
  6663. float distanceToTarget = 0.0;
  6664. if (target)
  6665. {
  6666. if (target->isDestroyed())
  6667. return(4);
  6668. //We did this in calcWeaponsStatus. Do we really need to do it again??!
  6669. // I have decided NO as of now!
  6670. /*
  6671. if (getWeaponIndirectFire(weaponIndex))
  6672. {
  6673. if (!getTeam()->teamLineOfSight(target->getPosition()))
  6674. return(4);
  6675. }
  6676. else
  6677. {
  6678. if (!lineOfSight(target))
  6679. return(4);
  6680. }
  6681. */
  6682. distanceToTarget = distanceFrom(target->getPosition());
  6683. }
  6684. else if (targetPoint)
  6685. {
  6686. //We did this in calcWeaponsStatus. Do we really need to do it again??!
  6687. // I have decided NO as of now!
  6688. /*
  6689. if (getWeaponIndirectFire(weaponIndex))
  6690. {
  6691. if (!getTeam()->teamLineOfSight(*targetPoint))
  6692. return(4);
  6693. }
  6694. else
  6695. {
  6696. if (!lineOfSight(*targetPoint))
  6697. return(4);
  6698. }
  6699. */
  6700. distanceToTarget = distanceFrom(*targetPoint);
  6701. }
  6702. else
  6703. return(4);
  6704. bool inRange = weaponInRange(weaponIndex, distanceToTarget, MapCellDiagonal);
  6705. //-----------------------------------------
  6706. // Let's make sure the target's in range...
  6707. if (MPlayer)
  6708. {
  6709. if (MPlayer->isServer() && !inRange)
  6710. return(4);
  6711. }
  6712. else if (!inRange)
  6713. return(4);
  6714. long numShots = getWeaponShots(weaponIndex);
  6715. if (numShots == 0)
  6716. return(4);
  6717. //------------------------------------------
  6718. // As of 4/9/97, missiles cannot be aimed...
  6719. // As of 4/30/98, they can be again... -fs
  6720. //if ((aimLocation != -1) && (MasterComponent::masterList[inventory[weaponIndex].masterID].getForm() == COMPONENT_FORM_WEAPON_MISSILE))
  6721. // return(4);
  6722. //-------------------------------------------
  6723. // Ripple Fire
  6724. // Figure out what weapon Node on the Mech we are going to use
  6725. // And see if its recycle time is Green. If not, just return, we'll shoot again!
  6726. long sourceHotSpot;
  6727. if (MasterComponent::masterList[inventory[weaponIndex].masterID].getForm() == COMPONENT_FORM_WEAPON_MISSILE)
  6728. sourceHotSpot = MECH3D_WEAPONTYPE_MISSILE;
  6729. else if (MasterComponent::masterList[inventory[weaponIndex].masterID].getForm() == COMPONENT_FORM_WEAPON_BALLISTIC)
  6730. sourceHotSpot = MECH3D_WEAPONTYPE_BALLISTIC;
  6731. else
  6732. sourceHotSpot = MECH3D_WEAPONTYPE_ENERGY;
  6733. sourceHotSpot = inventory[weaponIndex].facing;
  6734. if (appearance->getRightArmOff() && (sourceHotSpot == 1))
  6735. sourceHotSpot = 3; //Force into right torso. Arm is gone.
  6736. if (appearance->getLeftArmOff() && (sourceHotSpot == 2))
  6737. sourceHotSpot = 5; //Force into left torso. Arm is gone.
  6738. float recycleTime = appearance->getWeaponNodeRecycle(sourceHotSpot);
  6739. if (recycleTime > 0.0f)
  6740. return (3);
  6741. //Set the hotspot for the target
  6742. long targetHotSpot = 0;
  6743. if (target && target->getAppearance())
  6744. {
  6745. targetHotSpot = target->getAppearance()->getWeaponNode(MECH3D_WEAPONTYPE_ANY);
  6746. }
  6747. //-------------------------------------------
  6748. float entryAngle = 0.0;
  6749. if (target)
  6750. entryAngle = target->relFacingTo(position);
  6751. //long weaponType = MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponType();
  6752. bool isStreakMissile = MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponStreak();
  6753. long range;
  6754. long attackChance = (long)calcAttackChance(target, aimLocation, targetTime, weaponIndex, 0.0, &range, targetPoint);
  6755. long hitRoll = RandomNumber(100);
  6756. if (target)
  6757. {
  6758. if (target->getTeamId() == TEAM2) {
  6759. pilot->incNumSkillUses(COMBAT_STAT_MISSION, MWS_GUNNERY);
  6760. pilot->skillPoints[MWS_GUNNERY] += SkillTry[MWS_GUNNERY];
  6761. }
  6762. else
  6763. pilot->skillPoints[MWS_GUNNERY] += SkillTry[MWS_GUNNERY] / 10;
  6764. }
  6765. //---------------------------------------------------------------
  6766. // HACK: If aiming a shot and moving, make chance to hit equal to
  6767. // zero, yet still take shot (denny request: 4/22/98)
  6768. //if ((aimLocation != -1) && (getSpeed() > 0.0))
  6769. // attackChance = 0;
  6770. long hitLocation = -2;
  6771. if (target && (hitRoll < attackChance)) {
  6772. if (target->getTeamId() == TEAM2)
  6773. {
  6774. pilot->incNumSkillSuccesses(COMBAT_STAT_MISSION, MWS_GUNNERY);
  6775. pilot->skillPoints[MWS_GUNNERY] += SkillSuccess[MWS_GUNNERY];
  6776. }
  6777. else
  6778. pilot->skillPoints[MWS_GUNNERY] += SkillSuccess[MWS_GUNNERY] / 10;
  6779. //------------------------------------------------------------------
  6780. // If it's an aimed shot, we need to calc whether we hit the desired
  6781. // location on the target...
  6782. if (aimLocation != -1)
  6783. hitLocation = aimLocation;
  6784. }
  6785. MechWarriorPtr targetPilot = NULL;
  6786. if (target && target->isMover()) {
  6787. targetPilot = ((MoverPtr)target)->getPilot();
  6788. targetPilot->updateAttackerStatus(getWatchID(), scenarioTime);
  6789. }
  6790. //-----------------------
  6791. // Weapon must recycle...
  6792. startWeaponRecycle(weaponIndex);
  6793. WeaponBoltPtr weaponFX = NULL;
  6794. if (hitRoll < attackChance) {
  6795. if (numShots != UNLIMITED_SHOTS) {
  6796. //-------------------------------------------------------
  6797. // We're taking the shot, so reduce our ammo inventory...
  6798. deductWeaponShot(weaponIndex);
  6799. }
  6800. //------------
  6801. // Attack hit.
  6802. if (MasterComponent::masterList[inventory[weaponIndex].masterID].getForm() == COMPONENT_FORM_WEAPON_MISSILE) {
  6803. //---------------------------------------------------------
  6804. // It's a missile weapon. We need to determine how many hit
  6805. // (and missed) the target, and in how many clusters...
  6806. long missileAmount = MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponAmmoAmount();
  6807. long numMissiles = 0;
  6808. if (isStreakMissile)
  6809. numMissiles = missileAmount;
  6810. else {
  6811. numMissiles = (long)(missileAmount / 2.0 + 0.5);
  6812. if (numMissiles < 1)
  6813. numMissiles = 1;
  6814. if (numMissiles > missileAmount)
  6815. numMissiles = missileAmount;
  6816. }
  6817. //--------------------------------------------------------
  6818. // a MissileGen Object is ALL missiles--clusters no more:)
  6819. unsigned char effectType = MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponSpecialEffect();
  6820. //--------------------------------------------------
  6821. // Need to know which hotspot this comes from.
  6822. // Also need to know which hotspot this is going to.
  6823. if (target)
  6824. {
  6825. if (aimLocation == -1)
  6826. hitLocation = target->calcHitLocation(this, weaponIndex, ATTACKSOURCE_WEAPONFIRE, attackType);
  6827. }
  6828. else
  6829. hitLocation = -1;
  6830. Assert(hitLocation != -2, 0, " Mech.FireWeapon: Bad Hit Location ");
  6831. //--------------------------------------
  6832. // For now, always use a bullet effect...
  6833. WeaponShotInfo curShotInfo;
  6834. curShotInfo.init(getWatchID(),
  6835. inventory[weaponIndex].masterID,
  6836. numMissiles * MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponDamage(),
  6837. hitLocation,
  6838. entryAngle);
  6839. Assert(((float)((long)(curShotInfo.damage / 0.25)) * 0.25) == curShotInfo.damage, 0, " WeaponHitChunk.build: damage round error ");
  6840. dmgDone = curShotInfo.damage;
  6841. //-------------------------------------------------------------------------
  6842. // If I'm in a multiplayer game and I'm the server, record this weapon fire
  6843. // so it may be broadcast to all clients...
  6844. if (MPlayer && MPlayer->isServer()) {
  6845. WeaponFireChunk chunk;
  6846. chunk.init();
  6847. if (target) {
  6848. if (target->isMover())
  6849. chunk.buildMoverTarget(target,
  6850. weaponIndex - numOther,
  6851. true,
  6852. entryAngle,
  6853. numMissiles,
  6854. hitLocation);
  6855. else if (target->getObjectClass() == CAMERADRONE)
  6856. chunk.buildCameraDroneTarget(target,
  6857. weaponIndex - numOther,
  6858. true,
  6859. entryAngle,
  6860. numMissiles);
  6861. else
  6862. chunk.buildTerrainTarget(target,
  6863. weaponIndex - numOther,
  6864. true,
  6865. numMissiles);
  6866. }
  6867. else
  6868. chunk.buildLocationTarget(*targetPoint, weaponIndex - numOther, true, numMissiles);
  6869. chunk.pack(this);
  6870. WeaponFireChunk chunk2;
  6871. chunk2.init();
  6872. chunk2.data = chunk.data;
  6873. chunk2.unpack(this);
  6874. if (!chunk.equalTo(&chunk2))
  6875. Fatal(0, " Mech.fireWeapon: Bad WeaponFireChunk (save wfchunk.dbg file now) ");
  6876. addWeaponFireChunk(CHUNK_SEND, &chunk);
  6877. LogWeaponFireChunk(&chunk, this, target);
  6878. }
  6879. //-------------------------------------------------------------------
  6880. // This code will mess up if the object is not a BULLET!!!!!!!!!!!
  6881. weaponFX = ObjectManager->createWeaponBolt(effectType);
  6882. if (!weaponFX) {
  6883. if (targetPoint)
  6884. {
  6885. //-----------------------------------------
  6886. // Check for Mine hit and MOVE ON!!!
  6887. long cellRow, cellCol;
  6888. land->worldToCell(*targetPoint, cellRow, cellCol);
  6889. if (GameMap->getMine(cellRow, cellCol) == 1)
  6890. {
  6891. ObjectManager->createExplosion(MINE_EXPLOSION_ID, NULL, *targetPoint, MineSplashDamage, MineSplashRange * worldUnitsPerMeter);
  6892. GameMap->setMine(cellRow, cellCol, 2);
  6893. }
  6894. }
  6895. }
  6896. else {
  6897. if (target)
  6898. weaponFX->connect(this, target, &curShotInfo, sourceHotSpot, targetHotSpot);
  6899. else {
  6900. weaponFX->connect(this, *targetPoint, &curShotInfo, sourceHotSpot);
  6901. //pilot->clearCurTacOrder();
  6902. }
  6903. printFireWeaponDebugInfo(target, targetPoint, attackChance, aimLocation, hitRoll, &curShotInfo);
  6904. }
  6905. }
  6906. else {
  6907. //----------------------------------------------------
  6908. // Non-missile weapon, so just one weapon hit spawn...
  6909. // For now, always use a laser effect...
  6910. if (target) {
  6911. if (aimLocation == -1)
  6912. hitLocation = target->calcHitLocation(this, weaponIndex, ATTACKSOURCE_WEAPONFIRE, attackType);
  6913. }
  6914. else
  6915. hitLocation = -1;
  6916. Assert(hitLocation != -2, 1, " Mech.FireWeapon: Bad Hit Location ");
  6917. WeaponShotInfo shotInfo;
  6918. shotInfo.init(getWatchID(),
  6919. inventory[weaponIndex].masterID,
  6920. MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponDamage(),
  6921. hitLocation,
  6922. entryAngle);
  6923. dmgDone = shotInfo.damage;
  6924. //-------------------------------------------------------------------------
  6925. // If I'm in a multiplayer game and I'm the server, record this weapon fire
  6926. // so it may be broadcast to all clients...
  6927. if (MPlayer && MPlayer->isServer()) {
  6928. WeaponFireChunk chunk;
  6929. chunk.init();
  6930. if (target) {
  6931. if (target->isMover())
  6932. chunk.buildMoverTarget(target,
  6933. weaponIndex - numOther,
  6934. true,
  6935. entryAngle,
  6936. 0,
  6937. hitLocation);
  6938. else
  6939. chunk.buildTerrainTarget(target,
  6940. weaponIndex - numOther,
  6941. true,
  6942. 0);
  6943. }
  6944. else
  6945. {
  6946. chunk.buildLocationTarget(*targetPoint, weaponIndex - numOther, true, 0);
  6947. }
  6948. chunk.pack(this);
  6949. WeaponFireChunk chunk2;
  6950. chunk2.init();
  6951. chunk2.data = chunk.data;
  6952. chunk2.unpack(this);
  6953. if (!chunk.equalTo(&chunk2))
  6954. Fatal(0, " Mech.fireWeapon: Bad WeaponFireChunk (save wfchunk.dbg file now) ");
  6955. addWeaponFireChunk(CHUNK_SEND, &chunk);
  6956. LogWeaponFireChunk(&chunk, this, target);
  6957. }
  6958. unsigned char effectType = MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponSpecialEffect();
  6959. weaponFX = ObjectManager->createWeaponBolt(effectType);
  6960. if (!weaponFX)
  6961. {
  6962. if (targetPoint)
  6963. {
  6964. //-----------------------------------------
  6965. // Check for Mine hit and MOVE ON!!!
  6966. long cellRow, cellCol;
  6967. land->worldToCell(*targetPoint, cellRow, cellCol);
  6968. if (GameMap->getMine(cellRow, cellCol) == 1)
  6969. {
  6970. ObjectManager->createExplosion(MINE_EXPLOSION_ID, NULL, *targetPoint, MineSplashDamage, MineSplashRange * worldUnitsPerMeter);
  6971. GameMap->setMine(cellRow, cellCol, 2);
  6972. }
  6973. }
  6974. }
  6975. else
  6976. {
  6977. if (target)
  6978. {
  6979. weaponFX->connect(this, target, &shotInfo, sourceHotSpot, targetHotSpot);
  6980. }
  6981. else
  6982. {
  6983. //--------------------------------
  6984. // Hit the target point/terrain...
  6985. weaponFX->connect(this, *targetPoint, &shotInfo, sourceHotSpot);
  6986. }
  6987. printFireWeaponDebugInfo(target, targetPoint, attackChance, aimLocation, hitRoll, &shotInfo);
  6988. }
  6989. if (!target) {
  6990. //-----------------------------
  6991. // Now, cancel the tac order...
  6992. //pilot->clearCurTacOrder();
  6993. }
  6994. }
  6995. }
  6996. else
  6997. {
  6998. //if ((aimLocation != -1) && (RandomNumber(100) < AimedFireAbort))
  6999. // return(NO_ERR);
  7000. if (!isStreakMissile) {
  7001. if (numShots != UNLIMITED_SHOTS) {
  7002. //-------------------------------------------------------
  7003. // We're taking the shot, so reduce our ammo inventory...
  7004. deductWeaponShot(weaponIndex);
  7005. }
  7006. //----------------------------------------------------
  7007. // Miss, so check for possible miss resolution here...
  7008. if (MasterComponent::masterList[inventory[weaponIndex].masterID].getForm() == COMPONENT_FORM_WEAPON_MISSILE)
  7009. {
  7010. //---------------------------------------------------------
  7011. // It's a missile weapon. We need to determine how many hit
  7012. // (and missed) the target, and in how many clusters...
  7013. long missileAmount = MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponAmmoAmount();
  7014. long numMissiles = ((float)missileAmount / 2.0) + 0.5;
  7015. if (numMissiles < 1)
  7016. numMissiles = 1;
  7017. if (numMissiles > missileAmount)
  7018. numMissiles = missileAmount;
  7019. if (numMissiles > 0) {
  7020. //-----------------------------------------------
  7021. // No more clusters!
  7022. WeaponShotInfo curShotInfo;
  7023. curShotInfo.init(getWatchID(),
  7024. inventory[weaponIndex].masterID,
  7025. numMissiles * MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponDamage(),
  7026. -1,
  7027. entryAngle);
  7028. Assert(((float)((long)(curShotInfo.damage / 0.25)) * 0.25) == curShotInfo.damage, 0, " WeaponHitChunk.build: damage round error ");
  7029. //-------------------------------------------------------------------------------------------
  7030. // If we missed, pick sights away from the target and check LOS to each one. If all are
  7031. // invisible, just hit the target with zero points of damage.
  7032. float missRadius = target ? 25.0 : 5.0;
  7033. Stuff::Vector3D positionOffset;
  7034. if (target)
  7035. positionOffset = target->getPosition();
  7036. else if (targetPoint)
  7037. positionOffset = *targetPoint;
  7038. positionOffset.x += missRadius;
  7039. positionOffset.z = land->getTerrainElevation(positionOffset);
  7040. bool canSeeHit = lineOfSight(positionOffset,true);
  7041. if (!canSeeHit)
  7042. {
  7043. positionOffset.x -= (missRadius * 2.0f);
  7044. positionOffset.z = land->getTerrainElevation(positionOffset);
  7045. canSeeHit = lineOfSight(positionOffset,true);
  7046. if (!canSeeHit)
  7047. {
  7048. positionOffset.x += missRadius;
  7049. positionOffset.y += missRadius;
  7050. positionOffset.z = land->getTerrainElevation(positionOffset);
  7051. canSeeHit = lineOfSight(positionOffset,true);
  7052. if (!canSeeHit)
  7053. {
  7054. positionOffset.y -= (missRadius * 2.0f);
  7055. positionOffset.z = land->getTerrainElevation(positionOffset);
  7056. canSeeHit = lineOfSight(positionOffset,true);
  7057. if (!canSeeHit)
  7058. {
  7059. //OK, no miss location is visible. Hit the target with ZERO damage!!
  7060. curShotInfo.init(getWatchID(),
  7061. inventory[weaponIndex].masterID,
  7062. 0.0f,
  7063. -1,
  7064. entryAngle);
  7065. }
  7066. }
  7067. }
  7068. }
  7069. //-------------------------------------------------------------------------
  7070. // If I'm in a multiplayer game and I'm the server, record this weapon fire
  7071. // so it may be broadcast to all clients...
  7072. if (MPlayer && MPlayer->isServer()) {
  7073. WeaponFireChunk chunk;
  7074. chunk.init();
  7075. chunk.buildLocationTarget(positionOffset, weaponIndex - numOther, false, numMissiles);
  7076. chunk.pack(this);
  7077. WeaponFireChunk chunk2;
  7078. chunk2.init();
  7079. chunk2.data = chunk.data;
  7080. chunk2.unpack(this);
  7081. if (!chunk.equalTo(&chunk2))
  7082. Fatal(0, " Mech.fireWeapon: Bad WeaponFireChunk (save wfchunk.dbg file now) ");
  7083. addWeaponFireChunk(CHUNK_SEND, &chunk);
  7084. LogWeaponFireChunk(&chunk, this, target);
  7085. }
  7086. //-------------------------------------------------------------------
  7087. unsigned char effectType = MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponSpecialEffect();
  7088. weaponFX = ObjectManager->createWeaponBolt(effectType);
  7089. if (!weaponFX)
  7090. {
  7091. //-----------------------------------------
  7092. // Check for Mine hit and MOVE ON!!!
  7093. long cellRow, cellCol;
  7094. land->worldToCell(positionOffset, cellRow, cellCol);
  7095. if (GameMap->getMine(cellRow, cellCol) == 1)
  7096. {
  7097. ObjectManager->createExplosion(MINE_EXPLOSION_ID, NULL, positionOffset, MineSplashDamage, MineSplashRange * worldUnitsPerMeter);
  7098. GameMap->setMine(cellRow, cellCol, 2);
  7099. }
  7100. }
  7101. else
  7102. {
  7103. if (canSeeHit) //miss location is in LOS. Hit the ground
  7104. weaponFX->connect(this,positionOffset,&curShotInfo,sourceHotSpot);
  7105. else if (target) //Miss location is NOT in LOS. Hit Target with ZERO damage!!!
  7106. weaponFX->connect(this,target,&curShotInfo,sourceHotSpot);
  7107. //OTHERWISE, we tried to hit the ground but we can't see the location we shot at.
  7108. // DRAW NO WEAPON EFFECT!!!!
  7109. printFireWeaponDebugInfo(target, &positionOffset, attackChance, aimLocation, hitRoll, &curShotInfo);
  7110. }
  7111. }
  7112. }
  7113. else
  7114. {
  7115. //----------------------------------------------------
  7116. // Non-missile weapon, so just one weapon hit spawn...
  7117. // For now, always use a laser effect...
  7118. WeaponShotInfo shotInfo;
  7119. shotInfo.init(getWatchID(),
  7120. inventory[weaponIndex].masterID,
  7121. MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponDamage(),
  7122. -1,
  7123. entryAngle);
  7124. //-------------------------------------------------------------------------------------------
  7125. // If we missed, pick sights away from the target and check LOS to each one. If all are
  7126. // invisible, just hit the target with zero points of damage.
  7127. float missRadius = target ? 25.0 : 5.0;
  7128. Stuff::Vector3D positionOffset;
  7129. if (target)
  7130. positionOffset = target->getPosition();
  7131. else if (targetPoint)
  7132. positionOffset = *targetPoint;
  7133. positionOffset.x += missRadius;
  7134. positionOffset.z = land->getTerrainElevation(positionOffset);
  7135. bool canSeeHit = lineOfSight(positionOffset,true);
  7136. if (!canSeeHit)
  7137. {
  7138. positionOffset.x -= (missRadius * 2.0f);
  7139. positionOffset.z = land->getTerrainElevation(positionOffset);
  7140. canSeeHit = lineOfSight(positionOffset,true);
  7141. if (!canSeeHit)
  7142. {
  7143. positionOffset.x += missRadius;
  7144. positionOffset.y += missRadius;
  7145. positionOffset.z = land->getTerrainElevation(positionOffset);
  7146. canSeeHit = lineOfSight(positionOffset,true);
  7147. if (!canSeeHit)
  7148. {
  7149. positionOffset.y -= (missRadius * 2.0f);
  7150. positionOffset.z = land->getTerrainElevation(positionOffset);
  7151. canSeeHit = lineOfSight(positionOffset,true);
  7152. if (!canSeeHit)
  7153. {
  7154. //OK, no miss location is visible. Hit the target with ZERO damage!!
  7155. shotInfo.init(getWatchID(),
  7156. inventory[weaponIndex].masterID,
  7157. 0.0f,
  7158. -1,
  7159. entryAngle);
  7160. }
  7161. }
  7162. }
  7163. }
  7164. //-------------------------------------------------------------------------
  7165. // If I'm in a multiplayer game and I'm the server, record this weapon fire
  7166. // so it may be broadcast to all clients...
  7167. if (MPlayer && MPlayer->isServer()) {
  7168. WeaponFireChunk chunk;
  7169. chunk.init();
  7170. chunk.buildLocationTarget(positionOffset, weaponIndex - numOther, false, 0);
  7171. chunk.pack(this);
  7172. WeaponFireChunk chunk2;
  7173. chunk2.init();
  7174. chunk2.data = chunk.data;
  7175. chunk2.unpack(this);
  7176. if (!chunk.equalTo(&chunk2))
  7177. Fatal(0, " Mech.fireWeapon: Bad WeaponFireChunk (save wfchunk.dbg file now) ");
  7178. addWeaponFireChunk(CHUNK_SEND, &chunk);
  7179. LogWeaponFireChunk(&chunk, this, target);
  7180. }
  7181. unsigned char effectType = MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponSpecialEffect();
  7182. weaponFX = ObjectManager->createWeaponBolt(effectType);
  7183. if (!weaponFX)
  7184. {
  7185. //-----------------------------------------
  7186. // Check for Mine hit and MOVE ON!!!
  7187. long cellRow, cellCol;
  7188. land->worldToCell(positionOffset, cellRow, cellCol);
  7189. if (GameMap->getMine(cellRow, cellCol) == 1)
  7190. {
  7191. ObjectManager->createExplosion(MINE_EXPLOSION_ID, NULL, positionOffset, MineSplashDamage, MineSplashRange * worldUnitsPerMeter);
  7192. GameMap->setMine(cellRow, cellCol, 2);
  7193. }
  7194. }
  7195. else
  7196. {
  7197. if (canSeeHit) //miss location is in LOS. Hit the ground
  7198. weaponFX->connect(this,positionOffset,&shotInfo,sourceHotSpot);
  7199. else if (target) //Miss location is NOT in LOS. Hit Target with ZERO damage!!!
  7200. weaponFX->connect(this,target,&shotInfo,sourceHotSpot);
  7201. printFireWeaponDebugInfo(target, &positionOffset, attackChance, aimLocation, hitRoll, &shotInfo);
  7202. }
  7203. }
  7204. }
  7205. }
  7206. //-------------------------------------------------------------------
  7207. // Trigger the WEAPON TARGET event. For now, this assumes the target
  7208. // KNOWS we were targeting him. Of course, the target wouldn't always
  7209. // be aware of this, would they?
  7210. pilot->triggerAlarm(PILOT_ALARM_FIRED_WEAPON, target ? target->getWatchID() : 0);
  7211. if (targetPilot)
  7212. targetPilot->triggerAlarm(PILOT_ALARM_TARGET_OF_WEAPONFIRE, getWatchID());
  7213. timeSinceFiredLast = 0.0f;
  7214. if (getGroup())
  7215. getGroup()->handleMateFiredWeapon(getWatchID());
  7216. return(NO_ERR);
  7217. }
  7218. #define MAX_WEAPON_FX 200
  7219. //---------------------------------------------------------------------------
  7220. long BattleMech::handleWeaponFire (long weaponIndex,
  7221. GameObjectPtr target,
  7222. Stuff::Vector3D* targetPoint,
  7223. bool hit,
  7224. float entryAngle,
  7225. long numMissiles,
  7226. long hitLocation) {
  7227. //--------------------------------------------------------
  7228. // If it's already been fired, assume the ammo is there...
  7229. long numShots = getWeaponShots(weaponIndex);
  7230. //Assert(numShots > 0, numShots, " handleWeaponFire: numShots is negative! ");
  7231. //-----------------------
  7232. // Weapon must recycle...
  7233. startWeaponRecycle(weaponIndex);
  7234. bool isStreakMissile = MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponStreak();
  7235. WeaponBoltPtr weaponFX = NULL;
  7236. //----------------------------------------------------
  7237. // Need to know which hotspot this comes from.
  7238. // Also need to know which hotspot this is going to.
  7239. long sourceHotSpot;
  7240. if (MasterComponent::masterList[inventory[weaponIndex].masterID].getForm() == COMPONENT_FORM_WEAPON_MISSILE)
  7241. sourceHotSpot = MECH3D_WEAPONTYPE_MISSILE;
  7242. else if (MasterComponent::masterList[inventory[weaponIndex].masterID].getForm() == COMPONENT_FORM_WEAPON_BALLISTIC)
  7243. sourceHotSpot = MECH3D_WEAPONTYPE_BALLISTIC;
  7244. else
  7245. sourceHotSpot = MECH3D_WEAPONTYPE_ENERGY;
  7246. sourceHotSpot = appearance->getWeaponNode(sourceHotSpot);
  7247. //No Ripple fire in MPLayer. Must just fire the weapon when we get the packet.
  7248. appearance->setWeaponNodeUsed(sourceHotSpot);
  7249. //Set the hotspot for the target
  7250. long targetHotSpot = 0;
  7251. if (target && target->getAppearance())
  7252. {
  7253. targetHotSpot = target->getAppearance()->getWeaponNode(MECH3D_WEAPONTYPE_ANY);
  7254. }
  7255. if (hit) {
  7256. //------------
  7257. // Attack hit.
  7258. if (numShots != UNLIMITED_SHOTS) {
  7259. //-------------------------------------------------------
  7260. // We're taking the shot, so reduce our ammo inventory...
  7261. deductWeaponShot(weaponIndex);
  7262. }
  7263. if (MasterComponent::masterList[inventory[weaponIndex].masterID].getForm() == COMPONENT_FORM_WEAPON_MISSILE) {
  7264. //---------------------------------------------------------
  7265. // It's a missile weapon. We need to determine how many hit
  7266. // (and missed) the target, and in how many clusters...
  7267. //------------------
  7268. // Clusters no more!
  7269. unsigned char effectType = MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponSpecialEffect();
  7270. if (numMissiles > 0) {
  7271. //-------------------------------------------------------------------
  7272. // This code will mess up if the object is not a BULLET!!!!!!!!!!!
  7273. weaponFX = ObjectManager->createWeaponBolt(effectType);
  7274. if (!weaponFX)
  7275. {
  7276. if (targetPoint)
  7277. {
  7278. //-----------------------------------------
  7279. // Check for Mine hit and MOVE ON!!!
  7280. long cellRow, cellCol;
  7281. land->worldToCell(*targetPoint, cellRow, cellCol);
  7282. if (GameMap->getMine(cellRow, cellCol) == 1)
  7283. {
  7284. ObjectManager->createExplosion(MINE_EXPLOSION_ID, NULL, *targetPoint, MineSplashDamage, MineSplashRange * worldUnitsPerMeter);
  7285. GameMap->setMine(cellRow, cellCol, 2);
  7286. }
  7287. }
  7288. }
  7289. else
  7290. {
  7291. Assert(hitLocation != -2, TargetRolo, " Mech.handleWeaponFire: Bad Hit Location ");
  7292. //--------------------------------------
  7293. // For now, always use a bullet effect...
  7294. WeaponShotInfo curShotInfo;
  7295. curShotInfo.init(getWatchID(),
  7296. inventory[weaponIndex].masterID,
  7297. numMissiles * MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponDamage(),
  7298. hitLocation,
  7299. entryAngle);
  7300. Assert(((float)((long)(curShotInfo.damage / 0.25)) * 0.25) == curShotInfo.damage, 0, " WeaponHitChunk.build: damage round error ");
  7301. if (target)
  7302. weaponFX->connect(this, target, &curShotInfo, sourceHotSpot, targetHotSpot);
  7303. else {
  7304. weaponFX->connect(this, *targetPoint, &curShotInfo, sourceHotSpot);
  7305. //-----------------------------
  7306. // Now, cancel the tac order...
  7307. //pilot->clearCurTacOrder();
  7308. }
  7309. }
  7310. }
  7311. }
  7312. else {
  7313. //----------------------------------------------------
  7314. // Non-missile weapon, so just one weapon hit spawn...
  7315. // For now, always use a laser effect...
  7316. WeaponShotInfo shotInfo;
  7317. shotInfo.init(getWatchID(),
  7318. inventory[weaponIndex].masterID,
  7319. MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponDamage(),
  7320. hitLocation,
  7321. entryAngle);
  7322. unsigned char effectType = MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponSpecialEffect();
  7323. weaponFX = ObjectManager->createWeaponBolt(effectType);
  7324. if (!weaponFX)
  7325. {
  7326. if (targetPoint)
  7327. {
  7328. //-----------------------------------------
  7329. // Check for Mine hit and MOVE ON!!!
  7330. long cellRow, cellCol;
  7331. land->worldToCell(*targetPoint, cellRow, cellCol);
  7332. if (GameMap->getMine(cellRow, cellCol) == 1)
  7333. {
  7334. ObjectManager->createExplosion(MINE_EXPLOSION_ID, NULL, *targetPoint, MineSplashDamage, MineSplashRange * worldUnitsPerMeter);
  7335. GameMap->setMine(cellRow, cellCol, 2);
  7336. }
  7337. }
  7338. }
  7339. else {
  7340. if (target)
  7341. weaponFX->connect(this, target, &shotInfo, sourceHotSpot, targetHotSpot);
  7342. else {
  7343. weaponFX->connect(this, *targetPoint, &shotInfo, sourceHotSpot);
  7344. //-----------------------------
  7345. // Now, cancel the tac order...
  7346. //pilot->clearCurTacOrder();
  7347. }
  7348. }
  7349. }
  7350. }
  7351. else {
  7352. Assert(target == NULL, 0, " Mech.handleWeaponFire: target should be NULL with network miss! ");
  7353. Assert(targetPoint != NULL, 0, " Mech.handleWeaponFire: MUST have targetpoint with network miss! ");
  7354. if (isStreakMissile) {
  7355. CurMoverWeaponFireChunk.unpack(this);
  7356. DebugWeaponFireChunk(&CurMoverWeaponFireChunk, NULL, this);
  7357. Assert(false, 0, " Mech.handleWeaponFire: streaks shouldn't miss! (save wfchunk.dbg file) ");
  7358. }
  7359. if (numShots != UNLIMITED_SHOTS) {
  7360. //-------------------------------------------------------
  7361. // We're taking the shot, so reduce our ammo inventory...
  7362. deductWeaponShot(weaponIndex);
  7363. }
  7364. //----------------------------------------------------
  7365. // Miss, so check for possible miss resolution here...
  7366. if (MasterComponent::masterList[inventory[weaponIndex].masterID].getForm() == COMPONENT_FORM_WEAPON_MISSILE) {
  7367. if (numMissiles) {
  7368. //------------------
  7369. // Clusters no more!
  7370. unsigned char effectType = MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponSpecialEffect();
  7371. weaponFX = ObjectManager->createWeaponBolt(effectType);
  7372. if (!weaponFX)
  7373. {
  7374. if (targetPoint)
  7375. {
  7376. //-----------------------------------------
  7377. // Check for Mine hit and MOVE ON!!!
  7378. long cellRow, cellCol;
  7379. land->worldToCell(*targetPoint, cellRow, cellCol);
  7380. if (GameMap->getMine(cellRow, cellCol) == 1)
  7381. {
  7382. ObjectManager->createExplosion(MINE_EXPLOSION_ID, NULL, *targetPoint, MineSplashDamage, MineSplashRange * worldUnitsPerMeter);
  7383. GameMap->setMine(cellRow, cellCol, 2);
  7384. }
  7385. }
  7386. }
  7387. else {
  7388. WeaponShotInfo curShotInfo;
  7389. curShotInfo.init(getWatchID(),
  7390. inventory[weaponIndex].masterID,
  7391. numMissiles * MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponDamage(),
  7392. -1,
  7393. entryAngle);
  7394. Assert(((float)((long)(curShotInfo.damage / 0.25)) * 0.25) == curShotInfo.damage, 0, " WeaponHitChunk.build: damage round error ");
  7395. weaponFX->connect(this, *targetPoint, &curShotInfo, sourceHotSpot);
  7396. }
  7397. }
  7398. }
  7399. else {
  7400. //----------------------------------------------------
  7401. // Non-missile weapon, so just one weapon hit spawn...
  7402. // For now, always use a laser effect...
  7403. WeaponShotInfo shotInfo;
  7404. shotInfo.init(getWatchID(),
  7405. inventory[weaponIndex].masterID,
  7406. MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponDamage(),
  7407. -1,
  7408. entryAngle);
  7409. unsigned char effectType = MasterComponent::masterList[inventory[weaponIndex].masterID].getWeaponSpecialEffect();
  7410. weaponFX = ObjectManager->createWeaponBolt(effectType);
  7411. if (!weaponFX)
  7412. {
  7413. if (targetPoint)
  7414. {
  7415. //-----------------------------------------
  7416. // Check for Mine hit and MOVE ON!!!
  7417. long cellRow, cellCol;
  7418. land->worldToCell(*targetPoint, cellRow, cellCol);
  7419. if (GameMap->getMine(cellRow, cellCol) == 1)
  7420. {
  7421. ObjectManager->createExplosion(MINE_EXPLOSION_ID, NULL, *targetPoint, MineSplashDamage, MineSplashRange * worldUnitsPerMeter);
  7422. GameMap->setMine(cellRow, cellCol, 2);
  7423. }
  7424. }
  7425. }
  7426. else {
  7427. weaponFX->connect(this, *targetPoint, &shotInfo, sourceHotSpot);
  7428. }
  7429. }
  7430. }
  7431. //-------------------------------------------------------------------
  7432. // Trigger the WEAPON TARGET event. For now, this assumes the target
  7433. // KNOWS we were targeting him. Of course, the target wouldn't always
  7434. // be aware of this, would they?
  7435. MechWarriorPtr targetPilot = NULL;
  7436. if (target && target->isMover()) {
  7437. targetPilot = ((MoverPtr)target)->getPilot();
  7438. targetPilot->updateAttackerStatus(getWatchID(), scenarioTime);
  7439. targetPilot->triggerAlarm(PILOT_ALARM_TARGET_OF_WEAPONFIRE, getWatchID());
  7440. }
  7441. if (getGroup())
  7442. getGroup()->handleMateFiredWeapon(getWatchID());
  7443. return(NO_ERR);
  7444. }
  7445. //---------------------------------------------------------------------------
  7446. float BattleMech::calcMaxSpeed (void) {
  7447. if (canRun())
  7448. return(appearance->getVelocityOfGesture(GestureRun));
  7449. else if (canWalk())
  7450. return(appearance->getVelocityOfGesture(GestureWalk));
  7451. else if (canLimp())
  7452. return(appearance->getVelocityOfGesture(GestureLimpLeft));
  7453. return(0.0);
  7454. }
  7455. //---------------------------------------------------------------------------
  7456. float BattleMech::calcSlowSpeed (void) {
  7457. if (canWalk())
  7458. return(maxMoveSpeed * 0.25);
  7459. else if (canLimp())
  7460. return(maxMoveSpeed * 0.2);
  7461. return(0.0);
  7462. }
  7463. //---------------------------------------------------------------------------
  7464. float BattleMech::calcModerateSpeed (void) {
  7465. if (canWalk())
  7466. return(maxMoveSpeed * 0.4);
  7467. else if (canLimp())
  7468. return(maxMoveSpeed * 0.3);
  7469. return(0.0);
  7470. }
  7471. //---------------------------------------------------------------------------
  7472. long BattleMech::calcSpriteSpeed (float speed, unsigned long flags, long& state, long& throttle) {
  7473. state = MECH_STATE_RUNNING;
  7474. throttle = 100;
  7475. //------------------------------------------------------------------------
  7476. // If the speed we want falls between the max walk speed and the run speed
  7477. // of the mech, we use the run speed (we'd rather have them stop and wait
  7478. // for others to catch up than always fall behind). If the speed is
  7479. // greater than the mech's fastest speed, we select the run state, but
  7480. // also return an error code...
  7481. long errCode = 0;
  7482. float maxWalkSpeed = appearance->getVelocityOfGesture(GestureWalk);
  7483. float minWalkSpeed = maxWalkSpeed / 2.0;
  7484. float runSpeed = appearance->getVelocityOfGesture(GestureRun);
  7485. if (speed == 0.0)
  7486. state = MECH_STATE_STANDING;
  7487. else if (speed < minWalkSpeed) {
  7488. state = MECH_STATE_WALKING;
  7489. throttle = 50;
  7490. errCode = 1;
  7491. }
  7492. else if (speed <= maxWalkSpeed) {
  7493. state = MECH_STATE_WALKING;
  7494. throttle = (long)(speed / maxWalkSpeed * 100.0);
  7495. }
  7496. else if (speed < runSpeed) {
  7497. if (flags & MECH_SPRITESPEED_FLAG_GO_SLOW) {
  7498. state = MECH_STATE_WALKING;
  7499. throttle = (long)(speed / maxWalkSpeed * 100.0);
  7500. }
  7501. else
  7502. state = MECH_STATE_RUNNING;
  7503. errCode = 2;
  7504. }
  7505. else if (speed > runSpeed) {
  7506. state = MECH_STATE_RUNNING;
  7507. errCode = 3;
  7508. }
  7509. return(errCode);
  7510. }
  7511. //---------------------------------------------------------------------------
  7512. bool BattleMech::isCaptureable (long capturingTeamID) {
  7513. // The following seems wrong, but we've opted to leave it so we don't upset the
  7514. // BETA gods. This function should never get called anyway, we think...hehe...3/20/01
  7515. return(getFlag(OBJECT_FLAG_CAPTURABLE) && (getTeam() == Team::home) && !isDestroyed());
  7516. }
  7517. //---------------------------------------------------------------------------
  7518. float BattleMech::calcMaxTargetDamage(void)
  7519. {
  7520. float damage = 0;
  7521. for (long curWeapon = numOther; curWeapon < numWeapons + numOther; curWeapon++)
  7522. {
  7523. long numClusters, clusterSize;
  7524. float thisDamage;
  7525. numClusters = clusterSize = 1;
  7526. if (MasterComponent::masterList[inventory[curWeapon].masterID].getForm() == COMPONENT_FORM_WEAPON_MISSILE)
  7527. {
  7528. //---------------------------------------------------------
  7529. // It's a missile weapon. We need to determine how many hit
  7530. // (and missed) the target, and in how many clusters...
  7531. long numMissiles = MasterComponent::masterList[inventory[curWeapon].masterID].getWeaponAmmoAmount() / 2;
  7532. switch (MasterComponent::masterList[inventory[curWeapon].masterID].getWeaponAmmoType())
  7533. {
  7534. case WEAPON_AMMO_SRM:
  7535. numClusters = numMissiles / ClusterSizeSRM;
  7536. if (numMissiles % ClusterSizeSRM)
  7537. numClusters++;
  7538. clusterSize = ClusterSizeSRM;
  7539. break;
  7540. case WEAPON_AMMO_LRM:
  7541. numClusters = numMissiles / ClusterSizeLRM;
  7542. if (numMissiles % ClusterSizeLRM)
  7543. numClusters++;
  7544. clusterSize = ClusterSizeLRM;
  7545. break;
  7546. };
  7547. }
  7548. thisDamage = clusterSize * numClusters * MasterComponent::masterList[inventory[curWeapon].masterID].getWeaponDamage() * 10;
  7549. thisDamage /= MasterComponent::masterList[inventory[curWeapon].masterID].getWeaponRecycleTime();
  7550. thisDamage *= 100; // 100% chance to hit
  7551. if (thisDamage > 0)
  7552. damage += thisDamage;
  7553. }
  7554. maxWeaponDamage = damage;
  7555. return damage;
  7556. }
  7557. //---------------------------------------------------------------------------
  7558. bool BattleMech::isWeaponWorking (long weaponIndex)
  7559. {
  7560. //long bodyLocation = inventory[weaponIndex].bodyLocation;
  7561. // if ((bodyLocation == MECH_BODY_LOCATION_LARM) && inventory[actuator[ACTUATOR_LSHOULDER]].disabled)
  7562. // return(false);
  7563. // else if ((bodyLocation == MECH_BODY_LOCATION_RARM) && inventory[actuator[ACTUATOR_RSHOULDER]].disabled)
  7564. // return(false);
  7565. // else
  7566. if (inventory[weaponIndex].disabled)
  7567. return(false);
  7568. else if (getWeaponShots(weaponIndex) == 0)
  7569. return (false);
  7570. return(true);
  7571. }
  7572. //---------------------------------------------------------------------------
  7573. float BattleMech::getTotalEffectiveness(void)
  7574. {
  7575. float weaponEffect, result;
  7576. float curCTorso, maxCTorso, armorCTorso;
  7577. float maxHead, curHead, armorHead, armorEffect, curArm, maxArm, armorArm, curLeg, maxLeg, armorLeg;
  7578. float curTorso, maxTorso, armorTorso, pilotEffect;
  7579. //-------------------------------------------------------------------------
  7580. // calculate Weapon effectiveness
  7581. if (0.0 == maxWeaponEffectiveness)
  7582. {
  7583. gosASSERT(false);
  7584. maxWeaponEffectiveness = 1.0;
  7585. }
  7586. if (weaponEffectiveness > maxWeaponEffectiveness)
  7587. maxWeaponEffectiveness = weaponEffectiveness;
  7588. weaponEffect = weaponEffectiveness / maxWeaponEffectiveness;
  7589. //---------------------------------------------------------------
  7590. // Calculate armor effectiveness.
  7591. // DO NOT CHANGE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  7592. // COmpiler does funky things if we just return 0.0!
  7593. if (isDestroyed() || isDisabled())
  7594. {
  7595. armorEffect = 0.0;
  7596. }
  7597. else
  7598. {
  7599. maxHead = armor[MECH_ARMOR_LOCATION_HEAD].maxArmor;
  7600. curHead = armor[MECH_ARMOR_LOCATION_HEAD].curArmor;
  7601. armorHead = curHead / maxHead * 0.6 + (0.4);
  7602. curCTorso = armor[MECH_ARMOR_LOCATION_CTORSO].curArmor;
  7603. maxCTorso = armor[MECH_ARMOR_LOCATION_CTORSO].maxArmor;
  7604. if (curCTorso > armor[MECH_ARMOR_LOCATION_RCTORSO].curArmor)
  7605. {
  7606. curCTorso = armor[MECH_ARMOR_LOCATION_RCTORSO].curArmor;
  7607. maxCTorso = armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor;
  7608. }
  7609. armorCTorso = curCTorso / maxCTorso * 0.5 + (0.5);
  7610. curTorso = armor[MECH_ARMOR_LOCATION_RLTORSO].curArmor +
  7611. armor[MECH_ARMOR_LOCATION_LTORSO].curArmor +
  7612. armor[MECH_ARMOR_LOCATION_RRTORSO].curArmor +
  7613. armor[MECH_ARMOR_LOCATION_RTORSO].curArmor;
  7614. maxTorso = armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor +
  7615. armor[MECH_ARMOR_LOCATION_LTORSO].maxArmor+
  7616. armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor +
  7617. armor[MECH_ARMOR_LOCATION_RTORSO].maxArmor;
  7618. armorTorso = curTorso / maxTorso * 0.25 + (0.75);
  7619. curArm = armor[MECH_ARMOR_LOCATION_LARM].curArmor + armor[MECH_ARMOR_LOCATION_RARM].curArmor;
  7620. maxArm = armor[MECH_ARMOR_LOCATION_LARM].maxArmor + armor[MECH_ARMOR_LOCATION_RARM].maxArmor;
  7621. armorArm = curArm / maxArm * 0.25 + (0.75);
  7622. curLeg = armor[MECH_ARMOR_LOCATION_LLEG].curArmor + armor[MECH_ARMOR_LOCATION_RLEG].curArmor;
  7623. maxLeg = armor[MECH_ARMOR_LOCATION_LLEG].maxArmor + armor[MECH_ARMOR_LOCATION_RLEG].maxArmor;
  7624. armorLeg = curArm / maxArm * 0.4 + (0.6);
  7625. armorEffect = armorHead * armorCTorso * armorTorso * armorArm * armorLeg;
  7626. }
  7627. float pilotWoundTable[7] =
  7628. {
  7629. 1.0,0.95f,0.85f,0.75f,0.50f,0.30f,0.00
  7630. };
  7631. unsigned long pilotWounds = float2long(getPilot()->getWounds());
  7632. if (pilotWounds > 6)
  7633. pilotWounds = 6;
  7634. pilotEffect = pilotWoundTable[pilotWounds];
  7635. result = weaponEffect * armorEffect * pilotEffect;
  7636. return result;
  7637. }
  7638. //---------------------------------------------------------------------------
  7639. void BattleMech::damageLoadedComponents (void)
  7640. {
  7641. for (long curLocation = 0; curLocation < NUM_MECH_BODY_LOCATIONS; curLocation++)
  7642. {
  7643. long numSpaces = NumLocationCriticalSpaces[curLocation];
  7644. for (long curSpace = 0; curSpace < numSpaces; curSpace++)
  7645. {
  7646. if (body[curLocation].criticalSpaces[curSpace].hit)
  7647. hitInventoryItem(body[curLocation].criticalSpaces[curSpace].inventoryID, true);
  7648. }
  7649. }
  7650. }
  7651. //***************************************************************************
  7652. void BattleMech::Save (PacketFilePtr file, long packetNum)
  7653. {
  7654. MechData data;
  7655. CopyTo(&data);
  7656. //PacketNum incremented in ObjectManager!!
  7657. file->writePacket(packetNum,(MemoryPtr)&data,sizeof(MechData),STORAGE_TYPE_ZLIB);
  7658. }
  7659. //***************************************************************************
  7660. void BattleMech::CopyTo (MechData *data)
  7661. {
  7662. data->chassisClass = chassisClass;
  7663. data->chassisBR = chassisBR;
  7664. data->variantID = variantID;
  7665. memcpy(data->variantName,variantName,sizeof(char) * 64);
  7666. data->legStatus = legStatus;
  7667. data->torsoStatus = torsoStatus;
  7668. memcpy(data->actuator,actuator, sizeof(unsigned char) * NUM_ACTUATORS);
  7669. data->gyro = gyro;
  7670. if (sensorSystem)
  7671. data->sensorOK = !sensorSystem->broken;
  7672. else
  7673. data->sensorOK = false;
  7674. data->numJumpJets = numJumpJets;
  7675. data->lastJumpTime = lastJumpTime;
  7676. data->inJump = inJump;
  7677. data->jumpGoal = jumpGoal;
  7678. data->centerTorsoBlowTime = centerTorsoBlowTime;
  7679. data->hitFromBehindThisFrame = hitFromBehindThisFrame;
  7680. data->hitFromFrontThisFrame = hitFromFrontThisFrame;
  7681. data->leftArmBlownThisFrame = leftArmBlownThisFrame;
  7682. data->rightArmBlownThisFrame = rightArmBlownThisFrame;
  7683. data->torsoRotation = torsoRotation;
  7684. data->rightArmRotation = rightArmRotation;
  7685. data->leftArmRotation = leftArmRotation;
  7686. data->fallen = fallen;
  7687. data->mechRemoved = mechRemoved;
  7688. data->pivotTurnRate = pivotTurnRate;
  7689. data->playedJumpSFX = playedJumpSFX;
  7690. data->playedCriticalHit = playedCriticalHit;
  7691. data->maxWeaponDamage = maxWeaponDamage;
  7692. memcpy(data->longName,longName,sizeof(char) * MAXLEN_MECH_LONGNAME);
  7693. data->pilotNum = pilotNum;
  7694. data->captureable = captureable;
  7695. data->notMineYet = notMineYet;
  7696. data->descID = descID;
  7697. data->damageThisFrame = damageThisFrame;
  7698. data->sentCrippledMsg = sentCrippledMsg;
  7699. memcpy(data->rotateValues,rotateValues, sizeof(float) * 6);
  7700. memcpy(data->ItemLocationToInvLocation,ItemLocationToInvLocation, sizeof(long) * MAX_MOVER_INVENTORY_ITEMS);
  7701. data->damageAfterDisabled = damageAfterDisabled;
  7702. data->numArmorComponents = numArmorComponents;
  7703. data->cBills = cBills;
  7704. if (appearance)
  7705. static_cast<Mech3DAppearance *>(appearance)->copyTo(&(data->apData));
  7706. Mover::CopyTo(dynamic_cast<MoverData *>(data));
  7707. }
  7708. //---------------------------------------------------------------------------
  7709. void BattleMech::Load (MechData *data)
  7710. {
  7711. Mover::Load(dynamic_cast<MoverData *>(data));
  7712. chassisClass = data->chassisClass;
  7713. chassisBR = data->chassisBR;
  7714. variantID = data->variantID;
  7715. memcpy(variantName,data->variantName,sizeof(char) * 64);
  7716. legStatus = data->legStatus;
  7717. torsoStatus = data->torsoStatus;
  7718. memcpy(actuator,data->actuator, sizeof(unsigned char) * NUM_ACTUATORS);
  7719. gyro = data->gyro;
  7720. numJumpJets = data->numJumpJets;
  7721. lastJumpTime = data->lastJumpTime;
  7722. inJump = data->inJump;
  7723. jumpGoal = data->jumpGoal;
  7724. centerTorsoBlowTime = data->centerTorsoBlowTime;
  7725. hitFromBehindThisFrame = data->hitFromBehindThisFrame;
  7726. hitFromFrontThisFrame = data->hitFromFrontThisFrame;
  7727. leftArmBlownThisFrame = data->leftArmBlownThisFrame;
  7728. rightArmBlownThisFrame = data->rightArmBlownThisFrame;
  7729. torsoRotation = data->torsoRotation;
  7730. rightArmRotation = data->rightArmRotation;
  7731. leftArmRotation = data->leftArmRotation;
  7732. fallen = data->fallen;
  7733. mechRemoved = data->mechRemoved;
  7734. pivotTurnRate = data->pivotTurnRate;
  7735. playedJumpSFX = data->playedJumpSFX;
  7736. playedCriticalHit = data->playedCriticalHit;
  7737. maxWeaponDamage = data->maxWeaponDamage;
  7738. memcpy(longName,data->longName,sizeof(char) * MAXLEN_MECH_LONGNAME);
  7739. pilotNum = data->pilotNum;
  7740. captureable = data->captureable;
  7741. notMineYet = data->notMineYet;
  7742. descID = data->descID;
  7743. damageThisFrame = data->damageThisFrame;
  7744. sentCrippledMsg = data->sentCrippledMsg;
  7745. memcpy(rotateValues,data->rotateValues, sizeof(float) * 6);
  7746. memcpy(ItemLocationToInvLocation,data->ItemLocationToInvLocation, sizeof(long) * MAX_MOVER_INVENTORY_ITEMS);
  7747. damageAfterDisabled = data->damageAfterDisabled;
  7748. numArmorComponents = data->numArmorComponents;
  7749. cBills = data->cBills;
  7750. if (appearance)
  7751. static_cast<Mech3DAppearance *>(appearance)->copyFrom(&(data->apData));
  7752. sensorSystem = SensorManager->newSensor();
  7753. sensorSystem->setOwner(this);
  7754. sensorSystem->setRange(MasterComponent::masterList[inventory[sensor].masterID].getSensorRange());
  7755. SensorManager->addTeamSensor(teamId, sensorSystem);
  7756. if (!data->sensorOK)
  7757. sensorSystem->broken = true;
  7758. }
  7759. //***************************************************************************
  7760. void BattleMech::repairAll (void)
  7761. {
  7762. armor[MECH_ARMOR_LOCATION_HEAD].curArmor = armor[MECH_ARMOR_LOCATION_HEAD].maxArmor;
  7763. armor[MECH_ARMOR_LOCATION_CTORSO].curArmor = armor[MECH_ARMOR_LOCATION_CTORSO].maxArmor;
  7764. armor[MECH_ARMOR_LOCATION_LTORSO].curArmor = armor[MECH_ARMOR_LOCATION_LTORSO].maxArmor;
  7765. armor[MECH_ARMOR_LOCATION_RTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RTORSO].maxArmor;
  7766. armor[MECH_ARMOR_LOCATION_LARM].curArmor = armor[MECH_ARMOR_LOCATION_LARM].maxArmor;
  7767. armor[MECH_ARMOR_LOCATION_RARM].curArmor = armor[MECH_ARMOR_LOCATION_RARM].maxArmor;
  7768. armor[MECH_ARMOR_LOCATION_LLEG].curArmor = armor[MECH_ARMOR_LOCATION_LLEG].maxArmor;
  7769. armor[MECH_ARMOR_LOCATION_RLEG].curArmor = armor[MECH_ARMOR_LOCATION_RLEG].maxArmor;
  7770. armor[MECH_ARMOR_LOCATION_RCTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor;
  7771. armor[MECH_ARMOR_LOCATION_RLTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor;
  7772. armor[MECH_ARMOR_LOCATION_RRTORSO].curArmor = armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor;
  7773. //------------------------------------------------------------
  7774. // Now, read in the component layout for each body location...
  7775. for (long curLocation = 0; curLocation < NUM_MECH_BODY_LOCATIONS; curLocation++)
  7776. {
  7777. body[curLocation].curInternalStructure = body[curLocation].maxInternalStructure;
  7778. body[curLocation].damageState = IS_DAMAGE_NONE;
  7779. long numSpaces = NumLocationCriticalSpaces[curLocation];
  7780. for (long curSpace = 0; curSpace < numSpaces; curSpace++)
  7781. {
  7782. body[curLocation].criticalSpaces[curSpace].hit = false;
  7783. }
  7784. }
  7785. for (long curItem = 0;curItem < MAX_MOVER_INVENTORY_ITEMS;curItem++)
  7786. {
  7787. inventory[curItem].health = 255;
  7788. inventory[curItem].disabled = false;
  7789. }
  7790. calcAmmoTotals();
  7791. //---------------------------------------------------------------------------
  7792. // We need to set the status states for legs and torso based upon our current
  7793. // condition...
  7794. calcLegStatus();
  7795. calcTorsoStatus();
  7796. calcFireRanges();
  7797. maxCV = calcCV(true);
  7798. curCV = calcCV(false);
  7799. setThreatRating(-1);
  7800. maxWeaponDamage = calcMaxTargetDamage();
  7801. sensorSystem->broken = false;
  7802. }
  7803. //***************************************************************************