WinTrek.cpp 316 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341
  1. #include "pch.h"
  2. #include <shellapi.h>
  3. #include "cmdview.h"
  4. //#include "console.h"
  5. #include "trekctrls.h"
  6. #include "gamesite.h"
  7. #include "badwords.h"
  8. #include "slideshow.h"
  9. #include "Training.h"
  10. #include "CommandAcknowledgedCondition.h"
  11. #include <Delayimp.h> // For error handling & advanced features
  12. #include "..\\icqapi\\ICQAPIInterface.h"
  13. class QuickChatNode : public IMDLObject {};
  14. #include "quickchat.h"
  15. // Tell the linker that my DLL should be delay loaded
  16. #pragma comment(linker, "/DelayLoad:icqmapi.dll")
  17. const float AnyViewMinRenderScreenSize = 1.0f;
  18. const float c_dtFlashOn = 0.25f;
  19. const float c_dtFlashOff = 0.25f;
  20. const float c_dtFlashingDuration = 2.0f;
  21. const int c_nCountdownMax = 1000000; // just a big number
  22. const int c_nMinGain = -60;
  23. //////////////////////////////////////////////////////////////////////////////
  24. //
  25. // Stuff that was moved out of this file
  26. //
  27. //////////////////////////////////////////////////////////////////////////////
  28. namespace SoundInit {
  29. void InitializeSoundTemplates(
  30. Modeler* pmodeler,
  31. TVector<TRef<ISoundTemplate> >& vSoundMap
  32. );
  33. void AddMembers(INameSpace* pns);
  34. }
  35. //////////////////////////////////////////////////////////////////////////////
  36. //
  37. // Global Variables
  38. //
  39. //////////////////////////////////////////////////////////////////////////////
  40. TRef<ZWriteFile> g_pzfFrameDump = NULL;
  41. FrameDumpInfo g_fdInfo;
  42. const float s_fCommandViewDistanceMax = 20000.0f;
  43. const float s_fCommandViewDistanceMin = 50.0f;
  44. const float s_fCommandViewDistanceDefault = 6000.0f;
  45. const float c_fCommandGridRadius = 7500.0f;
  46. const float s_fCommandViewDisplacementMax = 10000.0f;
  47. const float s_fExternalViewDistanceMax = 6000.0f;
  48. const float s_fExternalViewDistanceMin = 100.0f;
  49. const float s_fExteralViewDistanceDefault = 500.0f;
  50. const float c_dtRejectQueuedCommand = 15.0f;
  51. const float c_fVolumeDelta = 1;
  52. const float g_hudBright = 0.85f;
  53. const float g_fJoystickDeadZoneSmall = 0.1f;
  54. const float g_fJoystickDeadZoneLarge = 0.3f;
  55. float g_fJoystickDeadZone = g_fJoystickDeadZoneSmall;
  56. float g_fInverseJoystickDeadZone = g_fJoystickDeadZone - 1.0f;
  57. //////////////////////////////////////////////////////////////////////////////
  58. //
  59. // Joystick Helpers
  60. //
  61. //////////////////////////////////////////////////////////////////////////////
  62. static const unsigned char buttonDown = 0x01;
  63. static const unsigned char buttonChanged = 0x80;
  64. struct JoystickResults
  65. {
  66. ControlData controls;
  67. unsigned char button1;
  68. unsigned char button2;
  69. unsigned char button3;
  70. unsigned char button4;
  71. unsigned char button5;
  72. unsigned char button6;
  73. float hat; // low 7 bits: 0=center, 1-8=direction, high bit: 1=hat position changed
  74. };
  75. float GetThrottle(ImodelIGC* pmodel)
  76. {
  77. assert (pmodel);
  78. if (trekClient.GetShip()->GetParentShip() == NULL)
  79. {
  80. float speed = pmodel->GetVelocity().Length();
  81. float myMaxSpeed = trekClient.GetShip()->GetHullType()->GetMaxSpeed();
  82. return (speed >= myMaxSpeed)
  83. ? 1.0f
  84. : ((2.0f * speed / myMaxSpeed) - 1.0f);
  85. }
  86. else
  87. return 0.0f;
  88. }
  89. //////////////////////////////////////////////////////////////////////////////
  90. //
  91. // Misc Helpers
  92. //
  93. //////////////////////////////////////////////////////////////////////////////
  94. TRef<IMessageBox> CreateMessageBox(
  95. const ZString& str,
  96. ButtonPane* pbuttonIn,
  97. bool fAddDefaultButton,
  98. bool fAddCancelButton,
  99. float paintDelay
  100. ) {
  101. TRef<ButtonPane> pbutton = pbuttonIn;
  102. debugf("Creating message box with text \"%s\"\n", (const char*)str);
  103. if (fAddDefaultButton) {
  104. assert(pbutton == NULL);
  105. TRef<Surface> psurfaceButton = GetModeler()->LoadImage("btnokbmp", true)->GetSurface();
  106. pbutton =
  107. CreateTrekButton(
  108. CreateButtonFacePane(psurfaceButton, ButtonNormal, 0, psurfaceButton->GetSize().X()),
  109. false,
  110. positiveButtonClickSound
  111. );
  112. }
  113. TRef<ButtonPane> pbuttonCancel;
  114. if (fAddCancelButton) {
  115. TRef<Surface> psurfaceButton = GetModeler()->LoadImage("btnabortbmp", true)->GetSurface();
  116. pbuttonCancel =
  117. CreateTrekButton(
  118. CreateButtonFacePane(psurfaceButton, ButtonNormal, 0, psurfaceButton->GetSize().X()),
  119. false,
  120. negativeButtonClickSound
  121. );
  122. }
  123. return CreateMessageBox(GetWindow(), GetModeler(), str, pbutton, false, pbuttonCancel, paintDelay);
  124. }
  125. ImodelIGC* GetCurrentTarget(void)
  126. {
  127. ImodelIGC* pmodelTarget = trekClient.GetShip()->GetCommandTarget(c_cmdCurrent);
  128. if (pmodelTarget != NULL)
  129. {
  130. if (pmodelTarget->GetObjectType() == OT_ship)
  131. pmodelTarget = ((IshipIGC*)pmodelTarget)->GetSourceShip();
  132. if ((pmodelTarget == trekClient.GetShip()->GetSourceShip()) ||
  133. (pmodelTarget->GetHitTest() == NULL) ||
  134. (pmodelTarget->GetCluster() != trekClient.GetCluster()) ||
  135. !trekClient.GetShip()->CanSee(pmodelTarget))
  136. {
  137. pmodelTarget = NULL;
  138. }
  139. }
  140. return pmodelTarget;
  141. }
  142. int GetSimilarTargetMask(ImodelIGC* pmodel)
  143. {
  144. assert (pmodel);
  145. ObjectType type = pmodel->GetObjectType();
  146. int tt = GetTypebits(type);
  147. if ((type == OT_ship) || (type == OT_station) || (type == OT_probe))
  148. tt |= (trekClient.GetShip()->GetSide() == pmodel->GetSide())
  149. ? c_ttFriendly
  150. : c_ttEnemy;
  151. else
  152. tt |= c_ttAllSides;
  153. return tt;
  154. }
  155. //This class wraps all the functionality for controlling a camera'a position, orientation, field of view & orientation
  156. class CameraControl
  157. {
  158. public:
  159. CameraControl(void)
  160. :
  161. m_dtAnimate(0.0f),
  162. m_jiggle(0.0f),
  163. m_fov(s_fDefaultFOV),
  164. m_oldHeadYaw(0.0f)
  165. {
  166. m_orientationHead.Reset();
  167. }
  168. ~CameraControl(void)
  169. {
  170. }
  171. void SetHeadOrientation(float yaw)
  172. {
  173. if (yaw != m_oldHeadYaw)
  174. {
  175. m_oldHeadYaw = yaw;
  176. m_orientationHead.Reset();
  177. m_orientationHead.Yaw(-yaw);
  178. }
  179. }
  180. const Orientation& GetHeadOrientation(void) const
  181. {
  182. return m_orientationHead;
  183. }
  184. void SetCameras(Camera* pcamera, Camera* pcameraPosters/*, Camera* pcameraTurret*/)
  185. {
  186. m_pcamera = pcamera;
  187. m_pcameraPosters = pcameraPosters;
  188. //m_pcameraTurret = pcameraTurret;
  189. SetZClip(5.0f, 10000.0f);
  190. m_pcameraPosters->SetZClip(10, 10000);
  191. //m_pcameraTurret->SetZClip(0.5, 10000);
  192. m_pcameraTarget->SetZClip(1, 20);
  193. m_pcamera->SetFOV(s_fDefaultFOV);
  194. m_pcameraTarget->SetPosition(Vector(0, 0, 8.0f));
  195. }
  196. void SetZClip(float zMin, float zMax)
  197. {
  198. m_pcamera->SetZClip(zMin, zMax);
  199. }
  200. bool Apply(float dt, bool bJiggle, bool bTarget)
  201. {
  202. bool animatingF = false;
  203. if (m_dtAnimate > 0.0f)
  204. {
  205. float tNext = m_tnowAnimate + dt;
  206. if (tNext >= m_dtAnimate)
  207. {
  208. //but the animation has finished
  209. if (m_bAnimatePosition)
  210. m_position = m_position2;
  211. m_orientation = m_quaternion2;
  212. m_fov = m_fov2;
  213. m_dtAnimate = 0.0f;
  214. }
  215. else
  216. {
  217. float interpolate = 0.5f - 0.5f * cos(pi * (tNext / m_dtAnimate));
  218. if (m_bAnimatePosition)
  219. m_position = (m_position1 * (1.0f - interpolate)) +
  220. (m_position2 * interpolate);
  221. m_orientation = Slerp(m_quaternion1, m_quaternion2, interpolate);
  222. m_fov = (m_fov1 * (1.0f - interpolate)) +
  223. (m_fov2 * interpolate);
  224. m_tnowAnimate = tNext;
  225. animatingF = true;
  226. }
  227. }
  228. m_pcamera->SetPosition(m_position);
  229. //
  230. // Jiggle the camera orientation based on the amount of afterburner and any residual effects
  231. //
  232. const double jiggleHalfLife = 0.25f;
  233. m_jiggle *= (float)pow(jiggleHalfLife, (double)dt);
  234. float fov = m_fov;
  235. Orientation orientation;
  236. const Orientation* porientation = &m_orientation;
  237. if (bJiggle)
  238. {
  239. IafterburnerIGC* afterburner = (IafterburnerIGC*)(trekClient.GetShip()->GetSourceShip()->GetMountedPart(ET_Afterburner, 0));
  240. if (afterburner || m_jiggle > 1.0)
  241. {
  242. float power = m_jiggle + (afterburner ? afterburner->GetPower() : 0);
  243. if (power != 0.0f)
  244. {
  245. float amount = RadiansFromDegrees(0.5) * power;
  246. orientation = m_orientation;
  247. orientation.Yaw(random(-amount, amount));
  248. orientation.Pitch(random(-amount, amount));
  249. porientation = &orientation;
  250. }
  251. }
  252. //Hack alert ... find the closest aleph and use it to provide an override for the fov
  253. IshipIGC* pshipSource = trekClient.GetShip()->GetSourceShip();
  254. ImodelIGC* pmodelAleph = FindTarget(pshipSource, c_ttWarp | c_ttNearest | c_ttAllSides);
  255. if (pmodelAleph)
  256. {
  257. float range = (pmodelAleph->GetPosition() - pshipSource->GetPosition()).Length() -
  258. trekClient.GetShip()->GetRadius();
  259. float radius = pmodelAleph->GetRadius();
  260. if (range < radius)
  261. {
  262. fov = (range / radius) * s_fDefaultFOV;
  263. if (fov < 0.1f)
  264. fov = 0.1f;
  265. else if (fov > m_fov)
  266. fov = m_fov;
  267. }
  268. }
  269. }
  270. Orientation viewOrientation = m_orientationHead * *porientation;
  271. m_pcamera->SetOrientation(viewOrientation);
  272. m_pcameraPosters->SetOrientation(viewOrientation);
  273. if (bTarget)
  274. {
  275. ImodelIGC* pmodelTarget = GetCurrentTarget();
  276. if (pmodelTarget != NULL)
  277. {
  278. Orientation orientTarget = *porientation;
  279. Vector dp = pmodelTarget->GetPosition() - m_position;
  280. static const Vector c_dpDefault(0.0f, 1.0f, 5.0f);
  281. orientTarget.TurnTo(dp.LengthSquared() < 1.0f ? c_dpDefault : dp);
  282. orientTarget.Invert();
  283. m_porientTransformTarget->SetValue(Matrix(orientTarget, Vector(0, 0, 0), 1));
  284. m_pwrapGeoTarget->SetGeo(m_pgeoTarget);
  285. }
  286. else
  287. {
  288. m_pwrapGeoTarget->SetGeo(Geo::GetEmpty());
  289. }
  290. }
  291. m_pcamera->SetFOV(fov);
  292. m_pcameraPosters->SetFOV(fov);
  293. //m_pcameraTurret->SetFOV(m_fov);
  294. m_pcamera->Update();
  295. m_pcameraPosters->Update();
  296. //m_pcameraTurret->Update();
  297. return animatingF;
  298. }
  299. void SetAnimation(float t)
  300. {
  301. if (t > 0.0f)
  302. {
  303. //Start a new animation
  304. m_position1 = m_position;
  305. m_quaternion1 = m_orientation;
  306. m_fov1 = m_fov;
  307. if (m_dtAnimate == 0.0f)
  308. {
  309. //We were not animating ... so set default destinations for the things that animate
  310. m_position2 = m_position1;
  311. m_quaternion2 = m_quaternion1;
  312. m_fov2 = m_fov1;
  313. }
  314. m_tnowAnimate = 0.0f;
  315. m_dtAnimate = t;
  316. m_bAnimatePosition = true; //by default
  317. }
  318. else if ((t == 0.0f) && (m_dtAnimate != 0.0f))
  319. {
  320. //Turn animations off
  321. m_dtAnimate = 0.0f;
  322. m_position = m_position2;
  323. m_quaternion = m_quaternion2;
  324. m_fov = m_fov2;
  325. }
  326. }
  327. float GetAnimation(void) const
  328. {
  329. return m_dtAnimate;
  330. }
  331. void SetJiggle(float jiggle)
  332. {
  333. ZAssert(jiggle >= 0.0f);
  334. m_jiggle = jiggle;
  335. }
  336. void SetToModel(ImodelIGC* pmodel)
  337. {
  338. assert (pmodel);
  339. SetPosition(pmodel->GetPosition());
  340. SetOrientation(pmodel->GetOrientation());
  341. }
  342. void SetFOV(float fov)
  343. {
  344. if (m_dtAnimate <= 0.0f)
  345. {
  346. //Snap to a position instantly
  347. m_fov = fov;
  348. }
  349. else
  350. {
  351. //Modify the endpoint of an existing animation
  352. m_fov2 = fov;
  353. }
  354. }
  355. void SetPosition(const Vector& position)
  356. {
  357. if ((m_dtAnimate <= 0.0f) || !m_bAnimatePosition)
  358. {
  359. //Snap to a position instantly
  360. m_position = position;
  361. }
  362. else
  363. {
  364. //Modify the endpoint of an existing animation
  365. m_position2 = position;
  366. }
  367. }
  368. void SetOrientation(const Orientation& orientation)
  369. {
  370. if (m_dtAnimate <= 0.0f)
  371. {
  372. m_orientation = orientation;
  373. }
  374. else
  375. {
  376. m_quaternion2 = orientation;
  377. }
  378. }
  379. float GetFOV(void) const
  380. {
  381. return m_fov;
  382. }
  383. const Vector& GetPosition(void) const
  384. {
  385. return m_position;
  386. }
  387. const Orientation& GetOrientation(void) const
  388. {
  389. return m_orientation;
  390. }
  391. const Vector& GetCameraPosition(void) const
  392. {
  393. if (m_pcamera)
  394. {
  395. return m_pcamera->GetPosition();
  396. }
  397. else
  398. {
  399. return m_position;
  400. }
  401. }
  402. const Orientation& GetCameraOrientation(void) const
  403. {
  404. if (m_pcamera)
  405. {
  406. return m_pcamera->GetOrientation();
  407. }
  408. else
  409. {
  410. return m_orientation;
  411. }
  412. }
  413. void SetAnimatePosition(bool bAnimatePosition)
  414. {
  415. m_bAnimatePosition = bAnimatePosition;
  416. }
  417. private:
  418. TRef<Camera> m_pcamera;
  419. TRef<Camera> m_pcameraPosters;
  420. //TRef<Camera> m_pcameraTurret;
  421. Orientation m_orientationHead;
  422. Vector m_position;
  423. Orientation m_orientation;
  424. Quaternion m_quaternion;
  425. float m_fov;
  426. float m_dtAnimate;
  427. float m_tnowAnimate;
  428. float m_jiggle;
  429. Vector m_position1;
  430. Vector m_position2;
  431. Quaternion m_quaternion1;
  432. Quaternion m_quaternion2;
  433. float m_fov1;
  434. float m_fov2;
  435. float m_oldHeadYaw;
  436. bool m_bAnimatePosition;
  437. public:
  438. // some members are public
  439. //
  440. // Target HUD
  441. //
  442. TRef<Camera> m_pcameraTarget;
  443. TRef<WrapGeo> m_pwrapGeoTarget;
  444. TRef<Geo> m_pgeoTarget;
  445. TRef<MatrixTransform> m_porientTransformTarget;
  446. };
  447. // this class wraps the logic for tracking the listener's head position based
  448. // on camera position
  449. class CameraListener : public ISoundListener
  450. {
  451. private:
  452. // the camera to which this coresponds
  453. const CameraControl& m_camera;
  454. public:
  455. // constructor
  456. CameraListener(CameraControl& camera) :
  457. m_camera(camera)
  458. {
  459. }
  460. //
  461. // ISoundListener
  462. //
  463. // get the "up" vector for the listener
  464. HRESULT GetUpDirection(Vector& vectUp)
  465. {
  466. vectUp = m_camera.GetCameraOrientation().GetUp();
  467. return S_OK;
  468. }
  469. //
  470. // ISoundPositionSource
  471. //
  472. // Gets the position of the sound in space
  473. HRESULT GetPosition(Vector& vectPosition)
  474. {
  475. vectPosition = m_camera.GetCameraPosition();
  476. return S_OK;
  477. }
  478. // Gets the velocity of the sound in space
  479. HRESULT GetVelocity(Vector& vectVelocity)
  480. {
  481. // REVIEW: the camera's velocity is not the same as the ships!
  482. vectVelocity = trekClient.GetShip()->GetCluster() ?
  483. trekClient.GetShip()->GetVelocity() : Vector(0,0,0);
  484. return S_OK;
  485. }
  486. // Gets the orientation of the sound in space, used for sound cones.
  487. HRESULT GetOrientation(Vector& vectOrientation)
  488. {
  489. vectOrientation = m_camera.GetCameraOrientation().GetForward();
  490. return S_OK;
  491. }
  492. // Returns S_OK if the position, velocity and orientation reported are
  493. // relative to the listener, S_FALSE otherwise.
  494. HRESULT IsListenerRelative()
  495. {
  496. return S_FALSE; // Of course
  497. }
  498. // Returns S_OK if this source is still playing the sound, S_FALSE
  499. // otherwise. This might be false if a sound emitter is destroyed, for
  500. // example, in which case the sound might fade out. Once it returns
  501. // S_FALSE once, it should never return S_OK again.
  502. HRESULT IsPlaying()
  503. {
  504. return S_OK;
  505. }
  506. };
  507. //////////////////////////////////////////////////////////////////////////////
  508. //
  509. // Main Trek Window
  510. //
  511. //////////////////////////////////////////////////////////////////////////////
  512. TRef<TrekWindow> g_ptrekWindow;
  513. TrekWindow* GetWindow() { return g_ptrekWindow; }
  514. Engine* GetEngine() { return g_ptrekWindow->GetEngine(); }
  515. Modeler* GetModeler() { return g_ptrekWindow->GetModeler(); }
  516. /*
  517. * DelayLoadDllExceptionFilter
  518. *
  519. Purpose: Determine whether we need to halt if ICQ dll isn't found
  520. Side Effects: Handle exception if it's just ICQ not found, otherwise pass exception along
  521. */
  522. LONG WINAPI DelayLoadDllExceptionFilter(PEXCEPTION_POINTERS pep)
  523. {
  524. // Assume we recognize this exception
  525. LONG lDisposition = EXCEPTION_EXECUTE_HANDLER;
  526. // If this is a Delay-load problem, ExceptionInformation[0] points
  527. // to a DelayLoadInfo structure that has detailed error info
  528. PDelayLoadInfo pdli = PDelayLoadInfo(pep->ExceptionRecord->ExceptionInformation[0]);
  529. // we're not going to do anything if the dll isn't loaded, just make sure to pass on any error that's not ours.
  530. switch (pep->ExceptionRecord->ExceptionCode)
  531. {
  532. case VcppException(ERROR_SEVERITY_ERROR, ERROR_MOD_NOT_FOUND):
  533. // The DLL module was not found at runtime
  534. case VcppException(ERROR_SEVERITY_ERROR, ERROR_PROC_NOT_FOUND):
  535. // The DLL module was found but it doesn?t contain the function
  536. break;
  537. default:
  538. lDisposition = EXCEPTION_CONTINUE_SEARCH; // We don?t recognize this exception
  539. break;
  540. }
  541. return lDisposition;
  542. }
  543. class TrekWindowImpl :
  544. public TrekWindow,
  545. public IIntegerEventSink,
  546. public ISubmenuEventSink,
  547. public IMenuCommandSink,
  548. public IClientEventSink,
  549. public ModelerSite,
  550. public TrekInputSite
  551. {
  552. public:
  553. const char* m_pszCursor;
  554. //////////////////////////////////////////////////////////////////////////////
  555. //
  556. // SuperKeyboardInputFilter
  557. //
  558. //////////////////////////////////////////////////////////////////////////////
  559. class SuperKeyboardInputFilter : public IKeyboardInput {
  560. private:
  561. TrekWindowImpl* m_pwindow;
  562. public:
  563. SuperKeyboardInputFilter(TrekWindowImpl* pwindow) :
  564. m_pwindow(pwindow)
  565. {
  566. }
  567. bool OnChar(IInputProvider* pprovider, const KeyState& ks)
  568. {
  569. return false;
  570. }
  571. bool OnKey(IInputProvider* pprovider, const KeyState& ks, bool& fForceTranslate)
  572. {
  573. return m_pwindow->OnSuperKeyFilter(pprovider, ks, fForceTranslate);
  574. }
  575. void SetFocusState(bool bFocus)
  576. {
  577. }
  578. };
  579. bool OnSuperKeyFilter(IInputProvider* pprovider, const KeyState& ks, bool& fForceTranslate)
  580. {
  581. if (
  582. ks.bDown
  583. && m_pmenuQuickChat
  584. && ks.vk == VK_TAB
  585. && m_pconsoleImage != NULL
  586. ) {
  587. //
  588. // Grab the tab so we can change the chat target
  589. //
  590. m_pconsoleImage->CycleChatTarget();
  591. return true;
  592. }
  593. return false;
  594. }
  595. TRef<SuperKeyboardInputFilter> m_psuperKeyboardInputFilter;
  596. //////////////////////////////////////////////////////////////////////////////
  597. //
  598. // KeyboardInputFilter
  599. //
  600. //////////////////////////////////////////////////////////////////////////////
  601. class KeyboardInputFilter : public IKeyboardInput {
  602. private:
  603. TrekWindowImpl* m_pwindow;
  604. public:
  605. KeyboardInputFilter(TrekWindowImpl* pwindow) :
  606. m_pwindow(pwindow)
  607. {
  608. }
  609. bool OnChar(IInputProvider* pprovider, const KeyState& ks)
  610. {
  611. return false;
  612. }
  613. bool OnKey(IInputProvider* pprovider, const KeyState& ks, bool& fForceTranslate)
  614. {
  615. return m_pwindow->OnKeyFilter(pprovider, ks, fForceTranslate);
  616. }
  617. void SetFocusState(bool bFocus)
  618. {
  619. }
  620. };
  621. bool OnKeyFilter(IInputProvider* pprovider, const KeyState& ks, bool& fForceTranslate)
  622. {
  623. if (ks.bDown) {
  624. TrekKey tk = m_ptrekInput->TranslateKeyMessage(ks);
  625. if (TK_NoKeyMapping != tk) {
  626. return OnTrekKeyFilter(tk);
  627. /*!!!
  628. // hook to send this keypress to training missions
  629. if (Training::RecordKeyPress (tk))
  630. {
  631. OnTrekKey(tk);
  632. return true;
  633. }
  634. */
  635. }
  636. }
  637. return false;
  638. }
  639. TRef<KeyboardInputFilter> m_pkeyboardInputFilter;
  640. //////////////////////////////////////////////////////////////////////////////
  641. //
  642. // Quick Chat
  643. //
  644. //////////////////////////////////////////////////////////////////////////////
  645. class QuickChatMenuCommandSink :
  646. public IMenuCommandSink,
  647. public ISubmenuEventSink
  648. {
  649. private:
  650. TrekWindowImpl* m_pwindow;
  651. TRef<QuickChatMenu> m_pqcmenu;
  652. public:
  653. QuickChatMenuCommandSink(TrekWindowImpl* pwindow, QuickChatMenu* pqcmenu) :
  654. m_pwindow(pwindow),
  655. m_pqcmenu(pqcmenu)
  656. {
  657. }
  658. void OnMenuCommand(IMenuItem* pitem)
  659. {
  660. m_pwindow->OnQuickChatMenuCommand(m_pqcmenu, pitem);
  661. }
  662. void OnMenuSelect(IMenuItem* pitem)
  663. {
  664. }
  665. void OnMenuClose(IMenu* pmenu)
  666. {
  667. m_pwindow->OnQuickChatMenuClose(pmenu);
  668. }
  669. TRef<IPopup> GetSubMenu(IMenuItem* pitem)
  670. {
  671. return m_pwindow->OnQuickChatMenuCommand(m_pqcmenu, pitem);
  672. }
  673. };
  674. friend class QuickChatMenuCommandSink;
  675. TVector<TRef<SonicChat> > m_vsonicChats;
  676. TRef<IMenu> m_pmenuQuickChat;
  677. TRef<QuickChatMenu> m_pqcmenuMain;
  678. TRef<MDLType> m_pmdlTypeMenu;
  679. ChatTarget m_ctLobbyChat;
  680. bool m_bQuitComposing;
  681. void OnQuickChatMenuClose(IMenu* pmenu)
  682. {
  683. if (pmenu == m_pmenuQuickChat) {
  684. m_pmenuQuickChat = NULL;
  685. if (m_pconsoleImage && m_bQuitComposing)
  686. m_pconsoleImage->QuitComposing();
  687. }
  688. }
  689. TRef<IPopup> OnQuickChatMenuCommand(QuickChatMenu* pqcmenu, IMenuItem* pmenuItem)
  690. {
  691. //
  692. // Find the QuickChatMenuItem
  693. //
  694. TRef<IObjectList> plist = pqcmenu->GetItems();
  695. QuickChatMenuItem* pitem = (QuickChatMenuItem*)plist->GetNth(pmenuItem->GetID());
  696. //
  697. // Handle the Node
  698. //
  699. QuickChatNode* pnode = pitem->GetNode();
  700. if (pnode->GetType()->IsTypeOf(m_pmdlTypeMenu)) {
  701. //
  702. // It's a menu
  703. //
  704. return CreateQuickChatMenu((QuickChatMenu*)pnode);
  705. } else {
  706. //
  707. // It's a command
  708. //
  709. QuickChatCommand* pqcc = (QuickChatCommand*)pnode;
  710. Training::CommandAcknowledgedCondition::SetCommandAcknowledged (static_cast<char> (pqcc->GetCommandID ()));
  711. if (m_pconsoleImage)
  712. {
  713. m_pconsoleImage->SendQuickChat(
  714. pqcc->GetSonicChat()->GetIndex(),
  715. (int)pqcc->GetTargetType(),
  716. (char)pqcc->GetCommandID(),
  717. (short)pqcc->GetAbilityMask()
  718. );
  719. }
  720. else
  721. {
  722. // if the console is not around, send it to the lobby chat recipient.
  723. trekClient.SendChat(trekClient.GetShip(), m_ctLobbyChat,
  724. NA, pqcc->GetSonicChat()->GetIndex(), NULL);
  725. }
  726. m_pmenuQuickChat = NULL;
  727. //
  728. // Close the current menu
  729. //
  730. GetPopupContainer()->ClosePopup(m_pmenuQuickChat);
  731. return NULL;
  732. }
  733. }
  734. void OpenMainQuickChatMenu()
  735. {
  736. if (m_pconsoleImage)
  737. m_pconsoleImage->StartQuickChat(CHAT_NOSELECTION, NA, NULL);
  738. OpenQuickChatMenu(m_pqcmenuMain);
  739. }
  740. TRef<IMenu> CreateQuickChatMenu(QuickChatMenu* pqcmenu)
  741. {
  742. TRef<QuickChatMenuCommandSink> pmenuCommandSinkQuickChat = new QuickChatMenuCommandSink(this, pqcmenu);
  743. TRef<IMenu> pmenu =
  744. CreateMenu(
  745. GetModeler(),
  746. TrekResources::SmallFont(),
  747. pmenuCommandSinkQuickChat
  748. );
  749. TRef<IObjectList> plist = pqcmenu->GetItems();
  750. plist->GetFirst();
  751. int index = 0;
  752. while (plist->GetCurrent() != NULL) {
  753. QuickChatMenuItem* pitem = (QuickChatMenuItem*)plist->GetCurrent();
  754. QuickChatNode* pnode = pitem->GetNode();
  755. if (pnode->GetType()->IsTypeOf(m_pmdlTypeMenu)) {
  756. pmenu->AddMenuItem(
  757. index,
  758. pitem->GetString(),
  759. (char)pitem->GetChar(),
  760. pmenuCommandSinkQuickChat
  761. );
  762. } else {
  763. pmenu->AddMenuItem(index, pitem->GetString(), (char)pitem->GetChar());
  764. }
  765. index++;
  766. plist->GetNext();
  767. }
  768. return pmenu;
  769. }
  770. void OpenQuickChatMenu(QuickChatMenu* pqcmenu)
  771. {
  772. m_pmenuQuickChat = CreateQuickChatMenu(pqcmenu);
  773. OpenPopup(m_pmenuQuickChat, Point(10, 180));
  774. }
  775. void CloseQuickChatMenu()
  776. {
  777. if (m_pmenuQuickChat) {
  778. GetPopupContainer()->ClosePopup(m_pmenuQuickChat);
  779. m_pmenuQuickChat = NULL;
  780. }
  781. }
  782. void InitializeQuickChatMenu()
  783. {
  784. TRef<INameSpace> pnsQuickChat = GetModeler()->GetNameSpace("quickchat");
  785. TRef<IObjectList> plist; CastTo(plist, pnsQuickChat->FindMember("sonicChats"));
  786. TLookup<SonicChat, DoSetIndex<SonicChat> >::Parse(plist, 0, m_vsonicChats);
  787. m_pqcmenuMain = (QuickChatMenu*)pnsQuickChat->FindMember("mainMenu");
  788. m_pmdlTypeMenu = pnsQuickChat->FindType("QuickChatMenu");
  789. }
  790. //////////////////////////////////////////////////////////////////////////////
  791. //
  792. // Sonic Chats
  793. //
  794. //////////////////////////////////////////////////////////////////////////////
  795. void PlaySonicChat(int id, int voice)
  796. {
  797. if ((id >= 0) && (id < m_vsonicChats.GetCount()))
  798. {
  799. SonicChat* psonicChat = m_vsonicChats[id];
  800. if (psonicChat)
  801. {
  802. TRef<IObjectList> plistVoices = psonicChat->GetVoices();
  803. if (plistVoices)
  804. {
  805. TRef<SonicChatVoice> pvoice = (SonicChatVoice*)(plistVoices->GetNth(voice));
  806. if (pvoice)
  807. StartSound((ISoundTemplate*)(IObject*)pvoice->GetSound());
  808. else
  809. trekClient.PlaySoundEffect(id);
  810. }
  811. }
  812. }
  813. }
  814. ZString GetSonicChatText(int id, int voice)
  815. {
  816. if ((id >= 0) && (id < m_vsonicChats.GetCount()))
  817. {
  818. SonicChat* psonicChat = m_vsonicChats[id];
  819. if (psonicChat)
  820. {
  821. TRef<IObjectList> plistVoices = psonicChat->GetVoices();
  822. if (plistVoices)
  823. {
  824. TRef<SonicChatVoice> pvoice = (SonicChatVoice*)(plistVoices->GetNth(voice));
  825. if (pvoice)
  826. return pvoice->GetString();
  827. }
  828. }
  829. }
  830. static ZString unknown("Unknown chat");
  831. return unknown;
  832. }
  833. //////////////////////////////////////////////////////////////////////////////
  834. //
  835. // member variables
  836. //
  837. //////////////////////////////////////////////////////////////////////////////
  838. unsigned long m_frameID;
  839. Time m_timeLastFrame;
  840. Time m_timeLastDamage;
  841. float m_fDeltaTime;
  842. //
  843. // Rendering Toggles
  844. //
  845. bool m_bShowMeteors;
  846. bool m_bShowStations;
  847. bool m_bShowProjectiles;
  848. bool m_bShowAlephs;
  849. bool m_bShowShips;
  850. bool m_bBidirectionalLighting;
  851. TRef<ModifiableBoolean> m_pboolChatHistoryHUD;
  852. TRef<ModifiableBoolean> m_pboolCenterHUD;
  853. TRef<ModifiableBoolean> m_pboolTargetHUD;
  854. TRef<ModifiableNumber> m_pnumberStyleHUD;
  855. TRef<ModifiableNumber> m_pnumberIsGhost;
  856. TRef<ModifiableNumber> m_pnumberFlash;
  857. TRef<ModifiableNumber> m_pnumberTeamPaneCollapsed;
  858. TRef<WrapNumber> m_pwrapNumberStyleHUD;
  859. //
  860. // exports
  861. //
  862. TRef<ModifiableNumber> m_pplayerThrottle;
  863. TRef<ModifiableColorValue> m_pcolorHUD;
  864. TRef<ModifiableColorValue> m_pcolorHUDshadows;
  865. TRef<ModifiableColorValue> m_pcolorTargetHUD;
  866. TRef<ModifiableNumber> m_pnumSFXGain;
  867. TRef<ModifiableNumber> m_pnumMusicGain;
  868. TRef<ModifiableNumber> m_pnumVoiceOverGain;
  869. //
  870. // Screens
  871. //
  872. TRef<Image> m_pimageScreen;
  873. TRef<Screen> m_pscreen;
  874. ScreenID m_screen;
  875. TRef<Screen> m_pscreenBackdrop;
  876. TRef<TranslateImage> m_pimageBackdrop;
  877. WinPoint m_sizeCombat;
  878. WinPoint m_sizeCombatFullscreen;
  879. bool m_bCombatSize;
  880. //
  881. // Lighting
  882. //
  883. Color m_color;
  884. Color m_colorAlt;
  885. float m_ambientLevel;
  886. float m_ambientLevelBidirectional;
  887. //
  888. // The scene
  889. //
  890. TRef<Camera> m_pcamera;
  891. TRef<Camera> m_pcameraPosters;
  892. //TRef<Camera> m_pcameraTurret;
  893. TRef<Viewport> m_pviewport;
  894. TRef<Viewport> m_pviewportPosters;
  895. //TRef<Viewport> m_pviewportTurret;
  896. CameraControl m_cameraControl;
  897. TRef<JoystickImage> m_pjoystickImage;
  898. TRef<Geo> m_pgeoDebris;
  899. TRef<WrapGeo> m_pwrapGeoDebris;
  900. //TRef<Geo> m_pgeoTurret;
  901. //TRef<MatrixTransform> m_pmtTurret;
  902. TRef<WrapGeo> m_pgeoScene;
  903. TRef<GeoImage> m_pimageScene;
  904. TRef<StarImage> m_pimageStars;
  905. TRef<GeoImage> m_pimageEnvironment;
  906. //TRef<GeoImage> m_pimageTurret;
  907. TRef<LensFlareImage> m_pimageLensFlare;
  908. TRef<Image> m_pimageBlack;
  909. TRef<WrapImage> m_pwrapImageStars;
  910. TRef<WrapImage> m_pwrapImageLensFlare;
  911. TRef<WrapImage> m_pwrapImageScene;
  912. TRef<WrapImage> m_pwrapImagePosters;
  913. TRef<WrapImage> m_pwrapImageEnvironment;
  914. //TRef<WrapImage> m_pwrapImageTurret;
  915. TRef<WrapImage> m_pwrapImagePostersInside;
  916. TRef<WrapImage> m_pwrapImageHudGroup;
  917. TRef<WrapImage> m_pwrapImageComm;
  918. TRef<WrapImage> m_pwrapImageRadar;
  919. TRef<WrapImage> m_pwrapImageConsole;
  920. TRef<WrapImage> m_pwrapImageHelp;
  921. TRef<WrapImage> m_pwrapImageTop;
  922. TRef<ConsoleImage> m_pconsoleImage;
  923. TRef<RadarImage> m_pradarImage;
  924. TRef<MuzzleFlareImage> m_pmuzzleFlareImage;
  925. TRef<WrapImage> m_pwrapImageBackdrop;
  926. TRef<GroupImage> m_pgroupImage;
  927. TRef<GroupImage> m_pgroupImage3D;
  928. TRef<GroupImage> m_pgroupImageGame;
  929. TRef<GroupImage> m_pgroupImageHUD;
  930. //
  931. // camera stuff
  932. //
  933. CameraMode m_cm;
  934. CameraMode m_cmOld;
  935. CameraMode m_cmPreviousCommand;
  936. bool m_bPreferChaseView;
  937. Time m_timeOverrideStop;
  938. Time m_timeRejectQueuedCommand;
  939. //Time m_timeAutopilotWarning;
  940. bool m_bUseOverridePosition;
  941. Vector m_positionOverrideTarget;
  942. Vector m_positionCommandView;
  943. Vector m_displacementCommandView;
  944. TRef<ImissileIGC> m_pmissileLast;
  945. Orientation m_orientationExternalCamera;
  946. float m_distanceExternalCamera;
  947. float m_distanceCommandCamera;
  948. float m_rollCommandCamera;
  949. bool m_bEnableDisplacementCommandView;
  950. int m_suicideCount;
  951. Time m_suicideTime;
  952. bool m_bCommandGrid;
  953. bool m_bTrackCommandView;
  954. int m_radarCockpit;
  955. int m_radarCommand;
  956. //
  957. // Pane stuff
  958. //
  959. ViewMode m_viewmode;
  960. OverlayMask m_voverlaymask[c_cViewModes];
  961. bool m_bOverlaysChanged;
  962. //
  963. // chase view stuff
  964. //
  965. #define ARRAY_OF_SAMPLES_SIZE 128
  966. struct TurnRateSample
  967. {
  968. float fTurnRate[3];
  969. Time time;
  970. };
  971. TurnRateSample m_turnRateSamples[ARRAY_OF_SAMPLES_SIZE];
  972. int m_turnRateSampleIndex;
  973. //
  974. // LOD
  975. //
  976. TRef<ScrollPane> m_pscrollPane;
  977. TRef<IIntegerEventSource> m_peventLOD;
  978. TRef<Image> m_pimageLOD;
  979. TRef<WrapImage> m_pwrapImageLOD;
  980. //
  981. // Menus
  982. //
  983. TRef<IMenu> m_pmenu;
  984. TRef<IMenuCommandSink> m_pmenuCommandSink;
  985. TRef<ISubmenuEventSink> m_psubmenuEventSink;
  986. TRef<IIntegerEventSink> m_pintegerEventSink;
  987. TRef<IKeyboardInput> m_pkeyboardInput;
  988. TRef<IClientEventSink> m_pClientEventSink;
  989. TRef<IClientEventSource> m_pClientEventSource;
  990. TRef<IMenuItem> m_pitemTogglePosters;
  991. TRef<IMenuItem> m_pitemToggleDebris;
  992. TRef<IMenuItem> m_pitemToggleStars;
  993. TRef<IMenuItem> m_pitemToggleEnvironment;
  994. TRef<IMenuItem> m_pitemToggleRoundRadar;
  995. TRef<IMenuItem> m_pitemToggleLinearControls;
  996. TRef<IMenuItem> m_pitemToggleLargeDeadZone;
  997. TRef<IMenuItem> m_pitemToggleVirtualJoystick;
  998. TRef<IMenuItem> m_pitemToggleFlipY;
  999. TRef<IMenuItem> m_pitemToggleEnableFeedback;
  1000. TRef<IMenuItem> m_pitemToggleStrobes;
  1001. TRef<IMenuItem> m_pitemToggleTrails;
  1002. TRef<IMenuItem> m_pitemToggleBounds;
  1003. TRef<IMenuItem> m_pitemToggleTransparentObjects;
  1004. TRef<IMenuItem> m_pitemToggleSmoke;
  1005. TRef<IMenuItem> m_pitemToggleLensFlare;
  1006. TRef<IMenuItem> m_pitemToggleBidirectionalLighting;
  1007. TRef<IMenuItem> m_pitemToggleChatHistoryHUD;
  1008. TRef<IMenuItem> m_pitemToggleCenterHUD;
  1009. TRef<IMenuItem> m_pitemToggleTargetHUD;
  1010. TRef<IMenuItem> m_pitemStyleHUD;
  1011. TRef<IMenuItem> m_pitemToggleCensorChats;
  1012. TRef<IMenuItem> m_pitemToggleStickyChase;
  1013. TRef<IMenuItem> m_pitemFilterChatsToAll;
  1014. TRef<IMenuItem> m_pitemFilterQuickComms;
  1015. TRef<IMenuItem> m_pitemFilterLobbyChats;
  1016. TRef<IMenuItem> m_pitemSoundQuality;
  1017. TRef<IMenuItem> m_pitemToggleSoundHardware;
  1018. TRef<IMenuItem> m_pitemToggleMusic;
  1019. TRef<IMenuItem> m_pitemMusicVolumeUp;
  1020. TRef<IMenuItem> m_pitemMusicVolumeDown;
  1021. TRef<IMenuItem> m_pitemSFXVolumeUp;
  1022. TRef<IMenuItem> m_pitemSFXVolumeDown;
  1023. TRef<IMenuItem> m_pitemVoiceOverVolumeUp;
  1024. TRef<IMenuItem> m_pitemVoiceOverVolumeDown;
  1025. bool m_bLensFlare;
  1026. bool m_bMusic;
  1027. bool m_bRoundRadar;
  1028. bool m_bLinearControls;
  1029. //
  1030. // CommandView
  1031. //
  1032. TRef<CommandGeo> m_pCommandGeo;
  1033. TRef<VisibleGeo> m_pCommandVisibleGeo;
  1034. //
  1035. // UI stuff
  1036. //
  1037. int m_nLastCountdown;
  1038. TRef<IMessageBox> m_pmessageBoxLockdown;
  1039. //
  1040. // Music
  1041. //
  1042. SoundID m_musicId;
  1043. TRef<ISoundInstance> m_psoundMusic;
  1044. //
  1045. // Sound support
  1046. //
  1047. TRef<ISoundEngine> m_pSoundEngine;
  1048. TVector<TRef<ISoundTemplate> > m_vSoundMap;
  1049. ISoundEngine::Quality m_soundquality;
  1050. bool m_bEnableSoundHardware;
  1051. TRef<IDiskPlayer> m_pDiskPlayer;
  1052. TRef<ISoundMutex> m_psoundmutexSal;
  1053. TRef<ISoundMutex> m_psoundmutexVO;
  1054. //
  1055. // VT members.
  1056. //
  1057. DWORD m_cVTVersion;
  1058. HWND m_hwndVTEdit;
  1059. //
  1060. // Input
  1061. //
  1062. TRef<TrekInput> m_ptrekInput;
  1063. bool m_bEnableVirtualJoystick;
  1064. bool m_bFlipY;
  1065. bool m_bEnableFeedback;
  1066. AsteroidAbilityBitMask m_aabmInvest;
  1067. AsteroidAbilityBitMask m_aabmCommand;
  1068. public:
  1069. //////////////////////////////////////////////////////////////////////////////
  1070. //
  1071. // Animated Image cache
  1072. //
  1073. //////////////////////////////////////////////////////////////////////////////
  1074. protected:
  1075. TMap<ZString, TRef<AnimatedImage> > m_mapAnimatedImages;
  1076. public:
  1077. TRef<AnimatedImage> LoadAnimatedImage(Number* ptime, const ZString& str)
  1078. {
  1079. TRef<AnimatedImage> pimage;
  1080. if (m_mapAnimatedImages.Find(str, pimage)) {
  1081. return new AnimatedImage(ptime, pimage);
  1082. } else {
  1083. TRef<Surface> psurface = GetModeler()->LoadSurface(str, true);
  1084. if (psurface == NULL) {
  1085. return NULL;
  1086. }
  1087. pimage = new AnimatedImage(ptime, psurface);
  1088. m_mapAnimatedImages.Set(str, pimage);
  1089. return pimage;
  1090. }
  1091. }
  1092. //////////////////////////////////////////////////////////////////////////////
  1093. //
  1094. //
  1095. //
  1096. //////////////////////////////////////////////////////////////////////////////
  1097. class GameStateCloseSink : public IEventSink {
  1098. public:
  1099. TrekWindowImpl* m_pwindow;
  1100. TRef<IEventSource> m_pevent;
  1101. GameStateCloseSink(TrekWindowImpl* pwindow, IEventSource* pevent) :
  1102. m_pwindow(pwindow),
  1103. m_pevent(pevent)
  1104. {
  1105. m_pevent->AddSink(this);
  1106. }
  1107. void Terminate()
  1108. {
  1109. m_pevent->RemoveSink(this);
  1110. }
  1111. bool OnEvent(IEventSource* pevent)
  1112. {
  1113. m_pwindow->OnGameStateClose();
  1114. return true;
  1115. }
  1116. };
  1117. TRef<GameStateContainer> m_pgsc;
  1118. TRef<GameStateCloseSink> m_pgameStateCloseSink;
  1119. TRef<StringPane> m_pstringPaneConquest;
  1120. TRef<StringPane> m_pstringPaneTerritory;
  1121. TRef<StringPane> m_pstringPaneDeathMatch;
  1122. TRef<StringPane> m_pstringPaneCountdown;
  1123. TRef<StringPane> m_pstringPaneProsperity;
  1124. TRef<StringPane> m_pstringPaneArtifacts;
  1125. TRef<StringPane> m_pstringPaneFlags;
  1126. TRef<StringGridImage> m_pstringGridImageConquest;
  1127. TRef<StringGridImage> m_pstringGridImageTerritory;
  1128. TRef<StringGridImage> m_pstringGridImageDeathMatch;
  1129. TRef<StringGridImage> m_pstringGridImageProsperity;
  1130. TRef<StringGridImage> m_pstringGridImageArtifacts;
  1131. TRef<StringGridImage> m_pstringGridImageFlags;
  1132. void OnGameStateClose()
  1133. {
  1134. TurnOffOverlayFlags(ofGameState);
  1135. }
  1136. void InitializeGameStateContainer()
  1137. {
  1138. m_pgsc = m_pconsoleImage->GetGameStateContainer();
  1139. m_pgameStateCloseSink =
  1140. new GameStateCloseSink(
  1141. this,
  1142. m_pgsc->GetCloseEvent()
  1143. );
  1144. //
  1145. // Add a game state tile for each winning condition
  1146. // artifacts, deathmatch, prosperity, countdown
  1147. //
  1148. //
  1149. // Conquest grid
  1150. //
  1151. const MissionParams* pmp = trekClient.m_pCoreIGC->GetMissionParams();
  1152. if (pmp->IsConquestGame()) {
  1153. m_pstringGridImageConquest = CreateStringGridImage(3, 2, m_pgsc->GetFont());
  1154. TRef<Pane> ppaneGrid = new AnimatedImagePane(m_pstringGridImageConquest);
  1155. m_pstringPaneConquest = m_pgsc->AddGameStateTile("wctitleconquestbmp", ppaneGrid);
  1156. m_pstringPaneConquest->SetFont(TrekResources::SmallFont());
  1157. m_pstringPaneConquest->SetTextColor(Color::White());
  1158. if (pmp->GetConquestPercentage() == 100) {
  1159. m_pstringPaneConquest->SetString("1st team to own all of the starbases wins");
  1160. } else {
  1161. m_pstringPaneConquest->SetString(
  1162. "1st team to own " + ZString(pmp->GetConquestPercentage()) + "% of the starbases wins"
  1163. );
  1164. }
  1165. } else {
  1166. m_pstringGridImageConquest = NULL;
  1167. }
  1168. if (pmp->IsTerritoryGame()) {
  1169. m_pstringGridImageTerritory = CreateStringGridImage(3, 2, m_pgsc->GetFont());
  1170. TRef<Pane> ppaneGrid = new AnimatedImagePane(m_pstringGridImageTerritory);
  1171. m_pstringPaneTerritory = m_pgsc->AddGameStateTile("wctitleterritorybmp", ppaneGrid); //NYI need new artwork
  1172. m_pstringPaneTerritory->SetFont(TrekResources::SmallFont());
  1173. m_pstringPaneTerritory->SetTextColor(Color::White());
  1174. m_pstringPaneTerritory->SetString(
  1175. "1st team to own " + ZString((50 + trekClient.m_pCoreIGC->GetClusters()->n() *
  1176. pmp->GetTerritoryPercentage()) / 100) + " sectors wins"
  1177. );
  1178. } else {
  1179. m_pstringGridImageTerritory = NULL;
  1180. }
  1181. if (pmp->IsProsperityGame()) {
  1182. m_pstringGridImageProsperity = CreateStringGridImage(3, 2, m_pgsc->GetFont());
  1183. TRef<Pane> ppaneGrid = new AnimatedImagePane(m_pstringGridImageProsperity);
  1184. m_pstringPaneProsperity = m_pgsc->AddGameStateTile("wctitleprosperitybmp", ppaneGrid);
  1185. m_pstringPaneProsperity->SetFont(TrekResources::SmallFont());
  1186. m_pstringPaneProsperity->SetTextColor(Color::White());
  1187. m_pstringPaneProsperity->SetString(
  1188. "First team to purchase reinforcements wins"
  1189. );
  1190. } else {
  1191. m_pstringGridImageProsperity = NULL;
  1192. }
  1193. if (pmp->IsArtifactsGame()) {
  1194. m_pstringGridImageArtifacts = CreateStringGridImage(3, 2, m_pgsc->GetFont());
  1195. TRef<Pane> ppaneGrid = new AnimatedImagePane(m_pstringGridImageArtifacts);
  1196. m_pstringPaneArtifacts = m_pgsc->AddGameStateTile("wctitleartifactsbmp", ppaneGrid);
  1197. m_pstringPaneArtifacts->SetFont(TrekResources::SmallFont());
  1198. m_pstringPaneArtifacts->SetTextColor(Color::White());
  1199. m_pstringPaneArtifacts->SetString(
  1200. "First team to own " + ZString(pmp->nGoalArtifactsCount) + " artifacts wins"
  1201. );
  1202. } else {
  1203. m_pstringGridImageArtifacts = NULL;
  1204. }
  1205. if (pmp->IsFlagsGame()) {
  1206. m_pstringGridImageFlags = CreateStringGridImage(3, 2, m_pgsc->GetFont());
  1207. TRef<Pane> ppaneGrid = new AnimatedImagePane(m_pstringGridImageFlags);
  1208. m_pstringPaneFlags = m_pgsc->AddGameStateTile("wctitlecapturebmp", ppaneGrid);
  1209. m_pstringPaneFlags->SetFont(TrekResources::SmallFont());
  1210. m_pstringPaneFlags->SetTextColor(Color::White());
  1211. m_pstringPaneFlags->SetString(
  1212. "First team to capture " + ZString(pmp->nGoalFlagsCount) + " flags wins"
  1213. );
  1214. } else {
  1215. m_pstringGridImageFlags = NULL;
  1216. }
  1217. {
  1218. m_pstringGridImageDeathMatch = CreateStringGridImage(5, 4, m_pgsc->GetFont());
  1219. TRef<Pane> ppaneGrid = new AnimatedImagePane(m_pstringGridImageDeathMatch);
  1220. m_pstringPaneDeathMatch = m_pgsc->AddGameStateTile(pmp->IsDeathMatchGame()
  1221. ? "wctitledeathmatchbmp"
  1222. : "wctitledeathsbmp",
  1223. ppaneGrid);
  1224. m_pstringPaneDeathMatch->SetFont(TrekResources::SmallFont());
  1225. m_pstringPaneDeathMatch->SetTextColor(Color::White());
  1226. m_pstringPaneDeathMatch->SetString(pmp->IsDeathMatchGame()
  1227. ? "1st team to kill " + ZString(pmp->GetDeathMatchKillLimit()) + " ships wins"
  1228. : "");
  1229. }
  1230. UpdateGameStateContainer();
  1231. }
  1232. void TerminateGameStateContainer()
  1233. {
  1234. m_pgsc = NULL;
  1235. if (m_pgameStateCloseSink) {
  1236. m_pgameStateCloseSink->Terminate();
  1237. m_pgameStateCloseSink = NULL;
  1238. }
  1239. m_pstringPaneConquest = NULL;
  1240. m_pstringPaneTerritory = NULL;
  1241. m_pstringPaneDeathMatch = NULL;
  1242. m_pstringPaneCountdown = NULL;
  1243. m_pstringPaneProsperity = NULL;
  1244. m_pstringPaneArtifacts = NULL;
  1245. m_pstringPaneFlags = NULL;
  1246. m_pstringGridImageConquest = NULL;
  1247. m_pstringGridImageTerritory = NULL;
  1248. m_pstringGridImageDeathMatch = NULL;
  1249. m_pstringGridImageProsperity = NULL;
  1250. m_pstringGridImageArtifacts = NULL;
  1251. m_pstringGridImageFlags = NULL;
  1252. }
  1253. //////////////////////////////////////////////////////////////////////////////
  1254. //
  1255. //
  1256. //
  1257. //////////////////////////////////////////////////////////////////////////////
  1258. class WinConditionInfo {
  1259. public:
  1260. virtual void FillLine(StringGridImage* pgrid, int row, IsideIGC* pside) = 0;
  1261. virtual void ClearLine(StringGridImage* pgrid, int row) = 0;
  1262. virtual bool Greater(IsideIGC* pside1, IsideIGC* pside2) = 0;
  1263. };
  1264. class WinConditionInfo3 : public WinConditionInfo {
  1265. public:
  1266. void ClearLine(StringGridImage* pgrid, int row)
  1267. {
  1268. pgrid->SetString(row, 2, ZString());
  1269. }
  1270. };
  1271. class WinConditionInfo4 : public WinConditionInfo {
  1272. public:
  1273. void ClearLine(StringGridImage* pgrid, int row)
  1274. {
  1275. pgrid->SetString(row, 2, ZString());
  1276. pgrid->SetString(row, 3, ZString());
  1277. }
  1278. };
  1279. //////////////////////////////////////////////////////////////////////////////
  1280. //
  1281. //
  1282. //
  1283. //////////////////////////////////////////////////////////////////////////////
  1284. class ShipWinConditionInfo {
  1285. public:
  1286. virtual void FillLine(StringGridImage* pgrid, int row, IshipIGC* pship) {}
  1287. virtual bool Greater(IshipIGC* pship1, IshipIGC* pship2) { return false; }
  1288. virtual bool AnyInfo() { return false; }
  1289. virtual void ClearLine(StringGridImage* pgrid, int row) {}
  1290. };
  1291. static ShipWinConditionInfo s_shipWinConditionInfo;
  1292. //////////////////////////////////////////////////////////////////////////////
  1293. //
  1294. //
  1295. //
  1296. //////////////////////////////////////////////////////////////////////////////
  1297. class ConquestWinConditionInfo : public WinConditionInfo3 {
  1298. public:
  1299. void FillLine(StringGridImage* pgrid, int row, IsideIGC* pside)
  1300. {
  1301. pgrid->SetString(
  1302. row,
  1303. 2,
  1304. ZString(pside->GetConquestPercent()) + "% owned"
  1305. );
  1306. }
  1307. bool Greater(IsideIGC* pside1, IsideIGC* pside2)
  1308. {
  1309. return pside1->GetConquestPercent() > pside2->GetConquestPercent();
  1310. }
  1311. };
  1312. static ConquestWinConditionInfo s_conquestWinConditionInfo;
  1313. //////////////////////////////////////////////////////////////////////////////
  1314. //
  1315. //
  1316. //
  1317. //////////////////////////////////////////////////////////////////////////////
  1318. class TerritoryWinConditionInfo : public WinConditionInfo3 {
  1319. public:
  1320. void FillLine(StringGridImage* pgrid, int row, IsideIGC* pside)
  1321. {
  1322. unsigned char c = pside->GetTerritoryCount();
  1323. pgrid->SetString(
  1324. row,
  1325. 2,
  1326. ZString(c) + ((c == 1) ? " sector owned" : " sectors owned")
  1327. );
  1328. }
  1329. bool Greater(IsideIGC* pside1, IsideIGC* pside2)
  1330. {
  1331. return pside1->GetTerritoryCount() > pside2->GetTerritoryCount();
  1332. }
  1333. };
  1334. static TerritoryWinConditionInfo s_territoryWinConditionInfo;
  1335. //////////////////////////////////////////////////////////////////////////////
  1336. //
  1337. //
  1338. //
  1339. //////////////////////////////////////////////////////////////////////////////
  1340. class DeathMatchWinConditionInfo : public WinConditionInfo4 {
  1341. public:
  1342. void FillLine(StringGridImage* pgrid, int row, IsideIGC* pside)
  1343. {
  1344. pgrid->SetString(row, 2, ZString(pside->GetKills() ) + " kills" );
  1345. pgrid->SetString(row, 3, ZString(pside->GetEjections()) + " ejects");
  1346. pgrid->SetString(row, 4, ZString(pside->GetDeaths()) + " deaths");
  1347. }
  1348. bool Greater(IsideIGC* pside1, IsideIGC* pside2)
  1349. {
  1350. if (pside1->GetKills() == pside2->GetKills()) {
  1351. return pside1->GetDeaths() < pside2->GetDeaths();
  1352. } else {
  1353. return pside1->GetKills() > pside2->GetKills();
  1354. }
  1355. }
  1356. };
  1357. class DeathMatchShipWinConditionInfo : public ShipWinConditionInfo {
  1358. public:
  1359. void FillLine(StringGridImage* pgrid, int row, IshipIGC* pship)
  1360. {
  1361. pgrid->SetString(row, 2, ZString(pship->GetKills() ) + " kills" );
  1362. pgrid->SetString(row, 3, ZString(pship->GetEjections()) + " ejects");
  1363. pgrid->SetString(row, 4, ZString(pship->GetDeaths()) + " deaths");
  1364. }
  1365. virtual void ClearLine(StringGridImage* pgrid, int row)
  1366. {
  1367. pgrid->SetString(row, 2, ZString());
  1368. pgrid->SetString(row, 3, ZString());
  1369. pgrid->SetString(row, 4, ZString());
  1370. }
  1371. bool Greater(IshipIGC* pship1, IshipIGC* pship2)
  1372. {
  1373. if (pship1->GetKills() == pship2->GetKills()) {
  1374. return pship1->GetDeaths() < pship2->GetDeaths();
  1375. } else {
  1376. return pship1->GetKills() > pship2->GetKills();
  1377. }
  1378. }
  1379. bool AnyInfo() { return true; }
  1380. };
  1381. static DeathMatchWinConditionInfo s_deathMatchWinConditionInfo;
  1382. static DeathMatchShipWinConditionInfo s_deathMatchShipWinConditionInfo;
  1383. //////////////////////////////////////////////////////////////////////////////
  1384. //
  1385. //
  1386. //
  1387. //////////////////////////////////////////////////////////////////////////////
  1388. class ProsperityWinConditionInfo : public WinConditionInfo3 {
  1389. public:
  1390. void FillLine(StringGridImage* pgrid, int row, IsideIGC* pside)
  1391. {
  1392. int prosperity = 0; //Actually get from the status of the prosperity project
  1393. BucketLinkIGC* pbl = pside->GetBuckets()->last();
  1394. if (pbl)
  1395. {
  1396. IbuyableIGC* pbuyable = pbl->data()->GetBuyable();
  1397. if ((pbuyable->GetObjectType() == OT_development) &&
  1398. (pbuyable->GetObjectID() == c_didTeamMoney))
  1399. {
  1400. prosperity = pbl->data()->GetPercentComplete();
  1401. }
  1402. }
  1403. pgrid->SetString(
  1404. row,
  1405. 2,
  1406. ZString(prosperity) + "% invested"
  1407. );
  1408. }
  1409. bool Greater(IsideIGC* pside1, IsideIGC* pside2)
  1410. {
  1411. return false;
  1412. //return pside1->GetProsperityPercent() > pside2->GetProsperityPercent();
  1413. }
  1414. };
  1415. static ProsperityWinConditionInfo s_prosperityWinConditionInfo;
  1416. //////////////////////////////////////////////////////////////////////////////
  1417. //
  1418. //
  1419. //
  1420. //////////////////////////////////////////////////////////////////////////////
  1421. class ArtifactsWinConditionInfo : public WinConditionInfo3 {
  1422. public:
  1423. void FillLine(StringGridImage* pgrid, int row, IsideIGC* pside)
  1424. {
  1425. pgrid->SetString(
  1426. row,
  1427. 2,
  1428. ZString(pside->GetArtifacts()) + " owned"
  1429. );
  1430. }
  1431. bool Greater(IsideIGC* pside1, IsideIGC* pside2)
  1432. {
  1433. return pside1->GetArtifacts() > pside2->GetArtifacts();
  1434. }
  1435. };
  1436. static ArtifactsWinConditionInfo s_artifactsWinConditionInfo;
  1437. //////////////////////////////////////////////////////////////////////////////
  1438. //
  1439. //
  1440. //
  1441. //////////////////////////////////////////////////////////////////////////////
  1442. class FlagsWinConditionInfo : public WinConditionInfo3 {
  1443. public:
  1444. void FillLine(StringGridImage* pgrid, int row, IsideIGC* pside)
  1445. {
  1446. pgrid->SetString(
  1447. row,
  1448. 2,
  1449. ZString(pside->GetFlags()) + " captured"
  1450. );
  1451. }
  1452. bool Greater(IsideIGC* pside1, IsideIGC* pside2)
  1453. {
  1454. return pside1->GetFlags() > pside2->GetFlags();
  1455. }
  1456. };
  1457. static FlagsWinConditionInfo s_flagsWinConditionInfo;
  1458. //////////////////////////////////////////////////////////////////////////////
  1459. //
  1460. //
  1461. //
  1462. //////////////////////////////////////////////////////////////////////////////
  1463. void FillWinCondition(
  1464. WinConditionInfo& info,
  1465. ShipWinConditionInfo& shipInfo,
  1466. StringGridImage* pgrid
  1467. ) {
  1468. // top team
  1469. // my team
  1470. // top player
  1471. // me
  1472. static const ZString c_rank[c_cSidesMax] = { "#1", "#2", "#3", "#4", "#5", "#6" };
  1473. static const ZString c_pound("#");
  1474. IsideIGC* psideMe = trekClient.GetSide();
  1475. IshipIGC* pshipMe = trekClient.GetShip();
  1476. //
  1477. // Figure out the top side and my rank
  1478. //
  1479. {
  1480. IsideIGC* psideTop = NULL;
  1481. int myRank = 1;
  1482. for (SideLinkIGC* psl = trekClient.m_pCoreIGC->GetSides()->first();
  1483. (psl != NULL);
  1484. psl = psl->next())
  1485. {
  1486. IsideIGC* pside = psl->data();
  1487. if (pside != psideMe)
  1488. {
  1489. if ((psideTop == NULL) || info.Greater(pside, psideTop))
  1490. psideTop = pside;
  1491. if (info.Greater(pside, psideMe))
  1492. myRank++;
  1493. }
  1494. }
  1495. assert (psideTop != NULL);
  1496. if (myRank == 1)
  1497. {
  1498. //Player side is the top rank
  1499. pgrid->SetString(0, 0, c_rank[0]);
  1500. pgrid->SetString(0, 1, CensorBadWords(psideMe->GetName()));
  1501. pgrid->SetColor(0, psideMe->GetColor());
  1502. info.FillLine(pgrid, 0, psideMe);
  1503. pgrid->SetString(1, 0, c_rank[1]);
  1504. pgrid->SetString(1, 1, CensorBadWords(psideTop->GetName()));
  1505. pgrid->SetColor(1, psideTop->GetColor());
  1506. info.FillLine(pgrid, 1, psideTop);
  1507. }
  1508. else
  1509. {
  1510. //Another side is the top rank
  1511. pgrid->SetString(0, 0, c_rank[0]);
  1512. pgrid->SetString(0, 1, CensorBadWords(psideTop->GetName()));
  1513. pgrid->SetColor(0, psideTop->GetColor());
  1514. info.FillLine(pgrid, 0, psideTop);
  1515. pgrid->SetString(1, 0, c_rank[myRank - 1]);
  1516. pgrid->SetString(1, 1, CensorBadWords(psideMe->GetName()));
  1517. pgrid->SetColor(1, psideMe->GetColor());
  1518. info.FillLine(pgrid, 1, psideMe);
  1519. }
  1520. }
  1521. //
  1522. // Figure out the top ship and my rank
  1523. //
  1524. if (shipInfo.AnyInfo())
  1525. {
  1526. IshipIGC* pshipTop = NULL;
  1527. int myRank = 1;
  1528. for (ShipLinkIGC* psl = trekClient.m_pCoreIGC->GetShips()->first();
  1529. (psl != NULL);
  1530. psl = psl->next())
  1531. {
  1532. IshipIGC* pship = psl->data();
  1533. if ((pship != pshipMe) && (pship->GetPilotType() >= c_ptPlayer))
  1534. {
  1535. if ((pshipTop == NULL) || shipInfo.Greater(pship, pshipTop))
  1536. pshipTop = pship;
  1537. if (shipInfo.Greater(pship, pshipMe))
  1538. myRank++;
  1539. }
  1540. }
  1541. if (myRank == 1)
  1542. {
  1543. //Player side is the top rank
  1544. pgrid->SetString(2, 0, c_rank[0]);
  1545. pgrid->SetString(2, 1, pshipMe->GetName());
  1546. pgrid->SetColor(2, psideMe->GetColor());
  1547. shipInfo.FillLine(pgrid, 2, pshipMe);
  1548. if (pshipTop)
  1549. {
  1550. pgrid->SetString(3, 0, c_rank[1]);
  1551. pgrid->SetString(3, 1, pshipTop->GetName());
  1552. pgrid->SetColor(3, pshipTop->GetSide()->GetColor());
  1553. shipInfo.FillLine(pgrid, 3, pshipTop);
  1554. }
  1555. else
  1556. {
  1557. pgrid->SetString(3, 0, ZString());
  1558. pgrid->SetString(3, 1, ZString());
  1559. shipInfo.ClearLine(pgrid, 3);
  1560. }
  1561. }
  1562. else
  1563. {
  1564. assert (pshipTop);
  1565. //Another side is the top rank
  1566. pgrid->SetString(2, 0, c_rank[0]);
  1567. pgrid->SetString(2, 1, pshipTop->GetName());
  1568. pgrid->SetColor(2, pshipTop->GetSide()->GetColor());
  1569. shipInfo.FillLine(pgrid, 2, pshipTop);
  1570. pgrid->SetString(3, 0, c_pound + ZString(myRank));
  1571. pgrid->SetString(3, 1, pshipMe->GetName());
  1572. pgrid->SetColor(3, psideMe->GetColor());
  1573. shipInfo.FillLine(pgrid, 3, pshipMe);
  1574. }
  1575. }
  1576. }
  1577. //////////////////////////////////////////////////////////////////////////////
  1578. //
  1579. //
  1580. //
  1581. //////////////////////////////////////////////////////////////////////////////
  1582. void UpdateGameStateContainer()
  1583. {
  1584. if (m_pgsc) {
  1585. if (m_pstringGridImageConquest) {
  1586. FillWinCondition(
  1587. s_conquestWinConditionInfo,
  1588. s_shipWinConditionInfo,
  1589. m_pstringGridImageConquest
  1590. );
  1591. }
  1592. if (m_pstringGridImageTerritory) {
  1593. FillWinCondition(
  1594. s_territoryWinConditionInfo,
  1595. s_shipWinConditionInfo,
  1596. m_pstringGridImageTerritory
  1597. );
  1598. }
  1599. if (m_pstringGridImageDeathMatch) {
  1600. FillWinCondition(
  1601. s_deathMatchWinConditionInfo,
  1602. s_deathMatchShipWinConditionInfo,
  1603. m_pstringGridImageDeathMatch
  1604. );
  1605. }
  1606. if (m_pstringGridImageProsperity) {
  1607. FillWinCondition(
  1608. s_prosperityWinConditionInfo,
  1609. s_shipWinConditionInfo,
  1610. m_pstringGridImageProsperity
  1611. );
  1612. }
  1613. if (m_pstringGridImageArtifacts) {
  1614. FillWinCondition(
  1615. s_artifactsWinConditionInfo,
  1616. s_shipWinConditionInfo,
  1617. m_pstringGridImageArtifacts
  1618. );
  1619. }
  1620. if (m_pstringGridImageFlags) {
  1621. FillWinCondition(
  1622. s_flagsWinConditionInfo,
  1623. s_shipWinConditionInfo,
  1624. m_pstringGridImageFlags
  1625. );
  1626. }
  1627. }
  1628. }
  1629. //////////////////////////////////////////////////////////////////////////////
  1630. //
  1631. //
  1632. //
  1633. //////////////////////////////////////////////////////////////////////////////
  1634. void InitializeSoundTemplates()
  1635. {
  1636. SoundInit::InitializeSoundTemplates(GetModeler(), m_vSoundMap);
  1637. }
  1638. //////////////////////////////////////////////////////////////////////////////
  1639. //
  1640. //
  1641. //
  1642. //////////////////////////////////////////////////////////////////////////////
  1643. bool GetUI()
  1644. {
  1645. return m_screen != ScreenIDCombat;
  1646. }
  1647. void SetScreen(Screen* pscreen)
  1648. {
  1649. m_pimageScreen = pscreen->GetImage();
  1650. if (m_pimageScreen == NULL) {
  1651. TRef<Pane> ppane = pscreen->GetPane();
  1652. //
  1653. // Add a caption
  1654. //
  1655. SetCaption(CreateCaption(GetModeler(), ppane, this));
  1656. //
  1657. // Create the UI Window
  1658. //
  1659. m_pimageScreen = CreatePaneImage(GetEngine(), SurfaceType3D(), false, pscreen->GetPane());
  1660. }
  1661. m_pwrapImageTop->SetImage(m_pimageScreen);
  1662. SetWindowedSize(pscreen->GetSize());
  1663. SetFullscreenSize(pscreen->GetSize());
  1664. SetSizeable(false);
  1665. //
  1666. // keep a reference to the screen to keep it alive
  1667. //
  1668. m_pscreen = pscreen;
  1669. }
  1670. ScreenID screen(void) const
  1671. {
  1672. return m_screen;
  1673. }
  1674. // review: this gets messy because it can be recursively called by a screen's
  1675. // constructor.
  1676. void screen(ScreenID s)
  1677. {
  1678. screen(s, -1);
  1679. }
  1680. void screen(ScreenID s, int idPlayer, const char * szPlayerName = NULL, const char * szOther = NULL)
  1681. {
  1682. static bool bSwitchingScreens = false;
  1683. static ScreenID sNextScreen;
  1684. ZString strPlayerName = szPlayerName ? szPlayerName : ""; // make copy of player name cause previous screen is going to be destroyed
  1685. ZString strOther = szOther ? szOther : "";
  1686. sNextScreen = s;
  1687. // let the switch be handled later
  1688. if (bSwitchingScreens)
  1689. return;
  1690. bSwitchingScreens = true;
  1691. debugf("Switched to screen %d\n", s);
  1692. if (s != m_screen)
  1693. {
  1694. //
  1695. // Save the screen size if we are switching away from combat
  1696. //
  1697. if (m_screen == ScreenIDCombat) {
  1698. Set3DAccelerationImportant(false);
  1699. SaveCombatSize();
  1700. GetConsoleImage()->OnSwitchViewMode();
  1701. }
  1702. SetHideCursorTimer(s == ScreenIDCombat);
  1703. // destroy the old windows
  1704. if (m_pimageScreen != NULL) {
  1705. m_pwrapImageTop->SetImage(m_pgroupImageGame);
  1706. m_pimageScreen = NULL;
  1707. m_pscreen = NULL;
  1708. SetCaption(NULL);
  1709. }
  1710. if (s != ScreenIDCombat)
  1711. {
  1712. if (GetViewMode() == vmOverride)
  1713. EndOverrideCamera();
  1714. else
  1715. SetCameraMode(cmCockpit);
  1716. m_pwrapImageConsole->SetImage(Image::GetEmpty());
  1717. m_pconsoleImage = NULL;
  1718. TerminateGameStateContainer();
  1719. trekClient.RequestViewCluster(NULL);
  1720. m_pscreenBackdrop = NULL;
  1721. m_pimageBackdrop = NULL;
  1722. m_viewmode = vmUI;
  1723. }
  1724. m_ptrekInput->SetFocus(s != ScreenIDCombat);
  1725. RestoreCursor();
  1726. // destroy any open popups
  1727. if (!GetPopupContainer()->IsEmpty())
  1728. GetPopupContainer()->ClosePopup(NULL);
  1729. m_pmessageBox = NULL;
  1730. m_pmessageBoxLockdown = NULL;
  1731. // kill any capture
  1732. m_pwrapImageTop->RemoveCapture();
  1733. // create the new screen
  1734. switch (s) {
  1735. case ScreenIDCombat:
  1736. {
  1737. //
  1738. // Switch to combat resolution
  1739. //
  1740. SetFocus();
  1741. m_frameID = 0;
  1742. m_pconsoleImage = ConsoleImage::Create(GetEngine(), m_pviewport);
  1743. {
  1744. IsideIGC* pside = trekClient.GetShip()->GetSide();
  1745. assert (pside);
  1746. assert (pside->GetObjectID() >= 0);
  1747. m_pconsoleImage->SetDisplayMDL(pside->GetCivilization()->GetHUDName());
  1748. }
  1749. m_pwrapImageConsole->SetImage(m_pconsoleImage);
  1750. ResetOverlayMask();
  1751. SetViewMode(trekClient.GetShip()->GetStation()
  1752. ? (trekClient.GetShip()->IsGhost() ? vmCommand : vmHangar)
  1753. : vmCombat, true);
  1754. PositionCommandView(NULL, 0.0f);
  1755. VTSetText("Screen=%d", ScreenIDCombat);
  1756. //
  1757. // Fill in the game state dialog
  1758. //
  1759. InitializeGameStateContainer();
  1760. //
  1761. // Bring up the game state pane by default
  1762. //
  1763. TurnOnOverlayFlags(ofGameState);
  1764. break;
  1765. }
  1766. case ScreenIDTeamScreen:
  1767. SetScreen(CreateTeamScreen(GetModeler()));
  1768. break;
  1769. case ScreenIDGameScreen:
  1770. SetScreen(CreateGameScreen(GetModeler()));
  1771. break;
  1772. case ScreenIDGameOverScreen:
  1773. SetScreen(CreateGameOverScreen(GetModeler()));
  1774. break;
  1775. case ScreenIDCreateMission:
  1776. SetScreen(CreateNewGameScreen(GetModeler()));
  1777. break;
  1778. case ScreenIDIntroScreen:
  1779. SetScreen(CreateIntroScreen(GetModeler()));
  1780. break;
  1781. case ScreenIDSplashScreen:
  1782. SetScreen(CreateVideoScreen(GetModeler(), true));
  1783. SetCursorImage(Image::GetEmpty());
  1784. break;
  1785. case ScreenIDTrainScreen:
  1786. SetScreen(CreateTrainingScreen(GetModeler()));
  1787. break;
  1788. case ScreenIDZoneClubScreen:
  1789. SetScreen(CreateZoneClubScreen(GetModeler(), GetTime()));
  1790. break;
  1791. case ScreenIDSquadsScreen:
  1792. SetScreen(CreateSquadsScreen(GetModeler(), szPlayerName ? PCC(strPlayerName) : NULL, idPlayer, szOther ? PCC(strOther) : NULL));
  1793. break;
  1794. case ScreenIDGameStarting:
  1795. SetScreen(CreateGameStartingScreen(GetModeler()));
  1796. break;
  1797. case ScreenIDCharInfo:
  1798. if(idPlayer==-1)
  1799. idPlayer = trekClient.GetZoneClubID();
  1800. SetScreen(CreateCharInfoScreen(GetModeler(), idPlayer));
  1801. break;
  1802. case ScreenIDTrainSlideshow:
  1803. {
  1804. extern TRef<ModifiableNumber> g_pnumberMissionNumber;
  1805. int iMission = static_cast<int> (g_pnumberMissionNumber->GetValue ());
  1806. ZAssert ((iMission >= 1) && (iMission <= 6));
  1807. char* strNamespace[] =
  1808. {
  1809. "",
  1810. "",
  1811. "tm_2_basic_flight",
  1812. "tm_3_basic_weaponry",
  1813. "tm_4_enemy_engagement",
  1814. "tm_5_command_view",
  1815. "tm_6_practice_arena",
  1816. };
  1817. SetScreen (CreateTrainingSlideshow (GetModeler (), strNamespace[iMission], iMission));
  1818. break;
  1819. }
  1820. case ScreenIDPostTrainSlideshow:
  1821. {
  1822. extern TRef<ModifiableNumber> g_pnumberMissionNumber;
  1823. int iMission = static_cast<int> (g_pnumberMissionNumber->GetValue ());
  1824. ZAssert ((iMission >= 1) && (iMission <= 6));
  1825. char* strNamespace[] =
  1826. {
  1827. "",
  1828. "tm_1_introduction",
  1829. "tm_2_basic_flight_post",
  1830. "tm_3_basic_weaponry_post",
  1831. "tm_4_enemy_engagement_post",
  1832. "tm_5_command_view_post",
  1833. "tm_6_practice_arena_post",
  1834. };
  1835. SetScreen (CreatePostTrainingSlideshow (GetModeler (), strNamespace[iMission]));
  1836. break;
  1837. }
  1838. case ScreenIDZoneEvents:
  1839. SetScreen(CreateZoneEventsScreen(GetModeler()));
  1840. break;
  1841. case ScreenIDLeaderBoard:
  1842. SetScreen(CreateLeaderBoardScreen(GetModeler(), strPlayerName));
  1843. break;
  1844. default:
  1845. ZError("Bad screen id");
  1846. break;
  1847. }
  1848. m_screen = s;
  1849. UpdateMusic();
  1850. }
  1851. bSwitchingScreens = false;
  1852. if (s != sNextScreen)
  1853. screen(sNextScreen, NULL);
  1854. }
  1855. void CharInfoScreenForPlayer(int idZone)
  1856. {
  1857. screen(ScreenIDCharInfo, idZone);
  1858. }
  1859. void SquadScreenForPlayer(const char * szName, int idZone, const char * szSquad)
  1860. {
  1861. screen(ScreenIDSquadsScreen, idZone, szName, szSquad);
  1862. }
  1863. void LeaderBoardScreenForPlayer(const ZString & strCharacter)
  1864. {
  1865. screen(ScreenIDLeaderBoard, -1, PCC(strCharacter));
  1866. }
  1867. void OpenPopup(IPopup* ppopup, const Point& point)
  1868. {
  1869. GetPopupContainer()->OpenPopup(ppopup, point);
  1870. m_ptrekInput->SetFocus(false);
  1871. }
  1872. bool IsProbablyNotForChat (int vk)
  1873. {
  1874. switch (vk)
  1875. {
  1876. case VK_PRIOR:
  1877. case VK_NEXT:
  1878. case VK_END:
  1879. case VK_HOME:
  1880. case VK_LEFT:
  1881. case VK_UP:
  1882. case VK_RIGHT:
  1883. case VK_DOWN:
  1884. case VK_SELECT:
  1885. case VK_PRINT:
  1886. case VK_EXECUTE:
  1887. case VK_SNAPSHOT:
  1888. case VK_INSERT:
  1889. case VK_DELETE:
  1890. case VK_NUMPAD0:
  1891. case VK_NUMPAD1:
  1892. case VK_NUMPAD2:
  1893. case VK_NUMPAD3:
  1894. case VK_NUMPAD4:
  1895. case VK_NUMPAD5:
  1896. case VK_NUMPAD6:
  1897. case VK_NUMPAD7:
  1898. case VK_NUMPAD8:
  1899. case VK_NUMPAD9:
  1900. case VK_MULTIPLY:
  1901. case VK_ADD:
  1902. case VK_SEPARATOR:
  1903. case VK_SUBTRACT:
  1904. case VK_DECIMAL:
  1905. case VK_DIVIDE:
  1906. case VK_F1:
  1907. case VK_F2:
  1908. case VK_F3:
  1909. case VK_F4:
  1910. case VK_F5:
  1911. case VK_F6:
  1912. case VK_F7:
  1913. case VK_F8:
  1914. case VK_F9:
  1915. case VK_F10:
  1916. case VK_F11:
  1917. case VK_F12:
  1918. case VK_F13:
  1919. case VK_F14:
  1920. case VK_F15:
  1921. case VK_F16:
  1922. case VK_F17:
  1923. case VK_F18:
  1924. case VK_F19:
  1925. case VK_F20:
  1926. case VK_F21:
  1927. case VK_F22:
  1928. case VK_F23:
  1929. case VK_F24:
  1930. case VK_NUMLOCK:
  1931. case VK_SCROLL:
  1932. return true;
  1933. default:
  1934. return false;
  1935. }
  1936. }
  1937. bool IsInputEnabled(int vk)
  1938. {
  1939. return (m_screen != ScreenIDCombat) || IsProbablyNotForChat (vk) || !m_pconsoleImage->IsComposing ();
  1940. }
  1941. TrekWindowImpl(
  1942. EffectApp* papp,
  1943. const ZString& strCommandLine,
  1944. bool bMovies,
  1945. bool bSoftware,
  1946. bool bHardware,
  1947. bool bPrimary,
  1948. bool bSecondary
  1949. ) :
  1950. TrekWindow(
  1951. papp,
  1952. strCommandLine,
  1953. true,
  1954. WinRect(0, 0, 800, 600),
  1955. WinPoint(640, 480)
  1956. ),
  1957. m_screen(ScreenIDSplashScreen),
  1958. m_bShowMeteors(true),
  1959. m_bShowStations(true),
  1960. m_bShowProjectiles(true),
  1961. m_bShowAlephs(true),
  1962. m_bShowShips(true),
  1963. m_bBidirectionalLighting(true),
  1964. m_color(Color::White()),
  1965. m_colorAlt(Color::White()),
  1966. m_ambientLevel(0),
  1967. m_ambientLevelBidirectional(0),
  1968. m_frameID(0),
  1969. m_timeLastFrame(Time::Now()),
  1970. m_timeLastDamage(Time::Now()),
  1971. m_cm(cmCockpit),
  1972. m_cmOld(cmCockpit),
  1973. m_timeRejectQueuedCommand(0),
  1974. m_cmPreviousCommand(cmExternalCommandView34),
  1975. m_bPreferChaseView (false),
  1976. m_distanceExternalCamera(s_fExteralViewDistanceDefault),
  1977. m_distanceCommandCamera(s_fCommandViewDistanceDefault),
  1978. m_rollCommandCamera(0.0f),
  1979. m_bEnableDisplacementCommandView (true),
  1980. m_suicideCount(0),
  1981. m_bLensFlare(true),
  1982. m_bRoundRadar(false),
  1983. m_bLinearControls (true),
  1984. m_bMusic(false),
  1985. m_bCommandGrid(false),
  1986. m_radarCockpit(RadarImage::c_rlDefault),
  1987. m_radarCommand(RadarImage::c_rlAll),
  1988. m_musicId(NA),
  1989. m_viewmode(vmUI),
  1990. m_bOverlaysChanged(false),
  1991. m_pszCursor(AWF_CURSOR_DEFAULT),
  1992. m_nLastCountdown(c_nCountdownMax),
  1993. m_ctLobbyChat(CHAT_EVERYONE),
  1994. m_bTrackCommandView(false),
  1995. m_bQuitComposing(true),
  1996. m_bEnableVirtualJoystick(false),
  1997. m_bFlipY(false),
  1998. m_bEnableFeedback(true),
  1999. m_aabmInvest(0),
  2000. m_aabmCommand(0)
  2001. {
  2002. HRESULT hr;
  2003. if (!IsValid()) {
  2004. return;
  2005. }
  2006. SetEffectWindow(this);
  2007. GetModeler()->SetSite(this);
  2008. // , global pointer to the one and only window
  2009. // should eventually be able to get rid of this
  2010. ZAssert(g_ptrekWindow == NULL);
  2011. g_ptrekWindow = this;
  2012. //
  2013. // App Icon
  2014. //
  2015. //SetIcon(LoadIcon(NULL, MAKEINTRESOURCE(0)));
  2016. LPCTSTR pszRes = MAKEINTRESOURCE(10);
  2017. HICON hIcon = (HICON)::LoadImage(GetModuleHandle(NULL), pszRes, IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
  2018. SendMessage(WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon);
  2019. HICON hIconSmall = (HICON)::LoadImage(GetModuleHandle(NULL), pszRes, IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
  2020. SendMessage(WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIconSmall);
  2021. //
  2022. // Event sink delegates
  2023. //
  2024. m_pClientEventSink = IClientEventSink::CreateDelegate(this);
  2025. m_pintegerEventSink = IIntegerEventSink::CreateDelegate(this);
  2026. m_pmenuCommandSink = IMenuCommandSink::CreateDelegate(this);
  2027. m_psubmenuEventSink = ISubmenuEventSink::CreateDelegate(this);
  2028. //
  2029. // advise us of client notifications
  2030. //
  2031. m_pClientEventSource = trekClient.GetClientEventSource();
  2032. m_pClientEventSource->AddSink(m_pClientEventSink);
  2033. //
  2034. // Initialize redbook audio
  2035. //
  2036. hr = CreateDiskPlayer(m_pDiskPlayer, LoadPreference("AudioCD", "Allegiance"));
  2037. if (FAILED(hr))
  2038. CreateDummyDiskPlayer(m_pDiskPlayer);
  2039. //
  2040. // Initialize some of the basic sound stuff
  2041. //
  2042. ZSucceeded(CreateSoundMutex(m_psoundmutexSal));
  2043. ZSucceeded(CreateSoundMutex(m_psoundmutexVO));
  2044. //
  2045. // Load our custom controls for .MDL screens
  2046. //
  2047. TRef<INameSpace> pnsSound = CreateSoundNameSpace(GetModeler(), GetModeler()->GetNameSpace("effect"));
  2048. TRef<INameSpace> pnsGamePanes =
  2049. GetModeler()->CreateNameSpace(
  2050. "gamepanes",
  2051. pnsSound
  2052. );
  2053. ::ExportPaneFactories(pnsGamePanes);
  2054. pnsGamePanes->AddMember("ShowChatHistoryHUD", m_pboolChatHistoryHUD = new ModifiableBoolean(true));
  2055. pnsGamePanes->AddMember("ShowCenterHUD", m_pboolCenterHUD = new ModifiableBoolean(true));
  2056. pnsGamePanes->AddMember("ShowTargetHUD", m_pboolTargetHUD = new ModifiableBoolean(true));
  2057. pnsGamePanes->AddMember(
  2058. "StyleHUD",
  2059. m_pwrapNumberStyleHUD = new WrapNumber(
  2060. m_pnumberStyleHUD = new ModifiableNumber(0)
  2061. )
  2062. );
  2063. pnsGamePanes->AddMember("Flash", m_pnumberFlash = new ModifiableNumber(0));
  2064. pnsGamePanes->AddMember("TeamPaneCollapsed", m_pnumberTeamPaneCollapsed = new ModifiableNumber(0));
  2065. pnsGamePanes->AddMember("IsGhost", m_pnumberIsGhost = new ModifiableNumber(0));
  2066. pnsGamePanes->AddMember("playerThrottle", m_pplayerThrottle = new ModifiableNumber(0));
  2067. pnsGamePanes->AddMember("hudColor", m_pcolorHUD = new ModifiableColorValue(Color::Black()));
  2068. pnsGamePanes->AddMember("hudColorshadows",m_pcolorHUDshadows = new ModifiableColorValue(Color::Black()));
  2069. pnsGamePanes->AddMember("targetHudColor", m_pcolorTargetHUD = new ModifiableColorValue(Color::Black()));
  2070. pnsGamePanes->AddMember("SFXGain", m_pnumSFXGain =
  2071. new ModifiableNumber(-(float)LoadPreference("SFXGain", 5)));
  2072. pnsGamePanes->AddMember("MusicGain", m_pnumMusicGain =
  2073. new ModifiableNumber(-(float)LoadPreference("MusicGain", 30)));
  2074. pnsGamePanes->AddMember("VoiceOverGain", m_pnumVoiceOverGain =
  2075. new ModifiableNumber(-(float)LoadPreference("VoiceOverGain", 3)));
  2076. pnsGamePanes->AddMember("AllegianceCD", m_pDiskPlayer);
  2077. pnsGamePanes->AddMember("MutexSal", m_psoundmutexSal);
  2078. pnsGamePanes->AddMember("MutexVO", m_psoundmutexVO);
  2079. m_pDiskPlayer->SetGain(m_pnumMusicGain->GetValue());
  2080. SoundInit::AddMembers(pnsGamePanes);
  2081. //
  2082. // Target Image
  2083. //
  2084. m_cameraControl.m_pcameraTarget = new Camera();
  2085. m_cameraControl.m_pgeoTarget = Geo::GetEmpty();
  2086. m_cameraControl.m_pwrapGeoTarget = new WrapGeo(m_cameraControl.m_pgeoTarget),
  2087. m_cameraControl.m_porientTransformTarget = new MatrixTransform(Matrix::GetIdentity());
  2088. // initialize for chase view
  2089. m_turnRateSampleIndex = 0;
  2090. pnsGamePanes->AddMember(
  2091. "targetGeo",
  2092. new TransformGeo(
  2093. m_cameraControl.m_pwrapGeoTarget,
  2094. m_cameraControl.m_porientTransformTarget
  2095. )
  2096. );
  2097. pnsGamePanes->AddMember("targetCamera", m_cameraControl.m_pcameraTarget);
  2098. //
  2099. // Keyboard input
  2100. //
  2101. m_psuperKeyboardInputFilter = new SuperKeyboardInputFilter(this);
  2102. AddKeyboardInputFilter(m_psuperKeyboardInputFilter);
  2103. //
  2104. // Popup keyboard input
  2105. //
  2106. AddKeyboardInputFilter(GetPopupContainer());
  2107. m_pkeyboardInput = IKeyboardInput::CreateDelegate(this);
  2108. SetFocus(m_pkeyboardInput);
  2109. //
  2110. // Filter the keyboard input
  2111. //
  2112. m_pkeyboardInputFilter = new KeyboardInputFilter(this);
  2113. AddKeyboardInputFilter(m_pkeyboardInputFilter);
  2114. //
  2115. // Create the virtual joystick image
  2116. //
  2117. m_pjoystickImage = CreateJoystickImage(1.0f / 512.0f);
  2118. //
  2119. // Initialize what's needed to show the splash screen
  2120. //
  2121. InitializeImages();
  2122. //
  2123. // initialize the sound engine (for the intro music if nothing else)
  2124. //
  2125. DWORD dwSoundInitStartTime = timeGetTime();
  2126. if (g_bEnableSound) {
  2127. assert (m_pSoundEngine == NULL);
  2128. hr = CreateSoundEngine(m_pSoundEngine, GetHWND());
  2129. }
  2130. if (FAILED(hr) || !g_bEnableSound)
  2131. {
  2132. hr = CreateDummySoundEngine(m_pSoundEngine);
  2133. ZAssert(SUCCEEDED(hr));
  2134. }
  2135. m_soundquality = (ISoundEngine::Quality)LoadPreference("SoundQuality",
  2136. ISoundEngine::midQuality);
  2137. ZSucceeded(m_pSoundEngine->SetQuality(m_soundquality));
  2138. m_bEnableSoundHardware = LoadPreference("SoundHardwareAcceleration", false) != FALSE;
  2139. ZSucceeded(m_pSoundEngine->EnableHardware(m_bEnableSoundHardware));
  2140. ZSucceeded(m_pSoundEngine->SetListener(new CameraListener(m_cameraControl)));
  2141. InitializeSoundTemplates();
  2142. //
  2143. // Load the Quick Chat Info
  2144. //
  2145. InitializeQuickChatMenu();
  2146. debugf("Time initializing sound: %d ms\n", timeGetTime() - dwSoundInitStartTime);
  2147. //
  2148. // Load Input toggles
  2149. //
  2150. m_bEnableVirtualJoystick = (LoadPreference("EnableVirtualJoystick", 0) != 0);
  2151. m_bFlipY = (LoadPreference("FlipY", 0) != 0);
  2152. m_bEnableFeedback = (LoadPreference("EnableFeedback", 1) != 0);
  2153. //
  2154. // Initial screen size
  2155. //
  2156. m_bCombatSize = false;
  2157. m_sizeCombat =
  2158. WinPoint(
  2159. int(LoadPreference("CombatXSize", 800)),
  2160. int(LoadPreference("CombatYSize", 600))
  2161. );
  2162. m_sizeCombatFullscreen =
  2163. WinPoint(
  2164. int(LoadPreference("CombatFullscreenXSize", 800)),
  2165. int(LoadPreference("CombatFullscreenYSize", 600))
  2166. );
  2167. //
  2168. // Music toggle
  2169. //
  2170. if (LoadPreference("Music", TRUE)) {
  2171. ToggleMusic();
  2172. }
  2173. //
  2174. // Create the combat camera
  2175. //
  2176. m_pcamera = new Camera();
  2177. m_pcameraPosters = new Camera();
  2178. //m_pcameraTurret = new Camera();
  2179. m_cameraControl.SetCameras(
  2180. m_pcamera,
  2181. m_pcameraPosters/*,
  2182. m_pcameraTurret*/
  2183. );
  2184. m_orientationExternalCamera.Reset();
  2185. //
  2186. // The viewports
  2187. //
  2188. m_pviewport = new Viewport(m_pcamera, GetRenderRectValue());
  2189. m_pviewportPosters = new Viewport(m_pcameraPosters, GetRenderRectValue());
  2190. //m_pviewportTurret = new Viewport(m_pcameraTurret, GetRenderRectValue());
  2191. //
  2192. // put some Debris into the scene
  2193. //
  2194. m_pgeoDebris = CreateDebrisGeo(GetModeler(), GetTime(), m_pviewport);
  2195. //
  2196. // Command View
  2197. //
  2198. m_pCommandVisibleGeo = new VisibleGeo(m_pCommandGeo = new CommandGeo(c_fCommandGridRadius, 0.0f, 40));
  2199. m_pCommandVisibleGeo->SetVisible(false);
  2200. //
  2201. // The 3D Scene
  2202. //
  2203. m_pgeoScene = new WrapGeo(Geo::GetEmpty());
  2204. m_pimageScene =
  2205. new GeoImage(
  2206. GroupGeo::Create(
  2207. m_pwrapGeoDebris = new WrapGeo(m_pgeoDebris),
  2208. m_pgeoScene,
  2209. m_pCommandVisibleGeo
  2210. ),
  2211. m_pviewport,
  2212. true
  2213. );
  2214. UpdateBidirectionalLighting();
  2215. //
  2216. // The environment sphere
  2217. //
  2218. m_pimageEnvironment = new GeoImage(Geo::GetEmpty(), m_pviewportPosters, false);
  2219. //
  2220. // A solid black image
  2221. //
  2222. m_pimageBlack = CreateColorImage(new ColorValue(Color::Black()));
  2223. //
  2224. // Turret
  2225. //
  2226. //m_pgeoTurret = Geo::GetEmpty();
  2227. //m_pmtTurret = new MatrixTransform(Matrix::GetIdentity());
  2228. //m_pimageTurret = new GeoImage(m_pgeoTurret, m_pviewportTurret, false);
  2229. //
  2230. // The background stars
  2231. //
  2232. m_pimageStars = StarImage::Create(m_pviewportPosters, 500);
  2233. //
  2234. // The Lens Flare
  2235. //
  2236. m_pimageLensFlare = CreateLensFlareImage(GetModeler(), m_pviewportPosters);
  2237. //
  2238. // The muzzle flare
  2239. //
  2240. m_pmuzzleFlareImage = CreateMuzzleFlareImage(GetModeler(), GetTime());
  2241. //
  2242. // The HUD
  2243. //
  2244. m_pradarImage = RadarImage::Create(GetModeler(), m_pviewport);
  2245. m_pgroupImageHUD = new GroupImage();
  2246. m_pgroupImageHUD->AddImage(CreateIndicatorImage(GetModeler(), m_pviewport, GetTime()));
  2247. m_pgroupImageHUD->AddImage(m_pwrapImageRadar = new WrapImage(m_pradarImage));
  2248. //m_pgroupImageHUD->AddImage(m_pwrapImageTurret = new WrapImage(Image::GetEmpty()));
  2249. //
  2250. // Create an LODScrollBar
  2251. //
  2252. TRef<Pane> ppane = CreateScrollPane(WinPoint(128, 10), 100, 10, 1, 90, m_pscrollPane, m_peventLOD);
  2253. m_peventLOD->AddSink(m_pintegerEventSink);
  2254. m_pimageLOD =
  2255. CreatePaneImage(
  2256. GetEngine(),
  2257. SurfaceType2D(),
  2258. false,
  2259. ppane
  2260. );
  2261. //
  2262. // Wrap up the images that can be toggled
  2263. //
  2264. m_pwrapImageHudGroup = new WrapImage(m_pgroupImageHUD);
  2265. m_pwrapImageLensFlare = new WrapImage(m_pimageLensFlare);
  2266. m_pwrapImageScene = new WrapImage(m_pimageScene);
  2267. m_pwrapImageStars = new WrapImage(m_pimageStars);
  2268. m_pwrapImageEnvironment = new WrapImage(m_pimageEnvironment);
  2269. m_pwrapImagePosters =
  2270. new WrapImage(
  2271. m_pwrapImagePostersInside = new WrapImage(
  2272. Image::GetEmpty()
  2273. )
  2274. );
  2275. //
  2276. // Group all of the image layers together, starting from the front.
  2277. //
  2278. m_pgroupImage3D = new GroupImage();
  2279. m_pgroupImage3D->AddImage(m_pwrapImageHudGroup );
  2280. m_pgroupImage3D->AddImage(m_pmuzzleFlareImage );
  2281. m_pgroupImage3D->AddImage(m_pwrapImageLensFlare );
  2282. m_pgroupImage3D->AddImage(m_pwrapImageScene );
  2283. m_pgroupImage3D->AddImage(m_pwrapImagePosters );
  2284. m_pgroupImage3D->AddImage(m_pwrapImageStars );
  2285. m_pgroupImage3D->AddImage(m_pwrapImageEnvironment);
  2286. m_pwrapImageConsole = new WrapImage(Image::GetEmpty());
  2287. m_pwrapImageBackdrop = new WrapImage(m_pgroupImage3D);
  2288. m_pgroupImageGame = new GroupImage();
  2289. m_pgroupImageGame->AddImage(m_pwrapImageConsole);
  2290. m_pgroupImageGame->AddImage(m_pwrapImageBackdrop);
  2291. m_pgroupImageGame->AddImage(m_pimageBlack );
  2292. //
  2293. // Initialize IGC
  2294. //
  2295. trekClient.Initialize(Time::Now());
  2296. //
  2297. // Load the sounds
  2298. //
  2299. m_ptrekInput = CreateTrekInput(GetModuleHandle(NULL), GetHWND(), GetInputEngine(), m_pjoystickImage);
  2300. //
  2301. // Initialize VT.
  2302. //
  2303. m_cVTVersion = 0;
  2304. m_hwndVTEdit = ::CreateWindow(TEXT("EDIT"),
  2305. TEXT("VTEdit"),
  2306. 0,
  2307. 0,
  2308. 0,
  2309. 0,
  2310. 0,
  2311. TrekWindow::GetHWND(),
  2312. NULL,
  2313. GetModuleHandle(NULL),
  2314. NULL);
  2315. //
  2316. // Load saved settings
  2317. //
  2318. if (LoadPreference("RoundRadarScreen", FALSE))
  2319. ToggleRoundRadar();
  2320. if (!LoadPreference("CensorChats", TRUE))
  2321. ToggleCensorChats();
  2322. if (LoadPreference ("PreferChaseView", FALSE))
  2323. ToggleStickyChase ();
  2324. if (!LoadPreference("FilterChatsToAll", TRUE))
  2325. ToggleFilterChatsToAll();
  2326. if (!LoadPreference("FilterQuickComms", TRUE))
  2327. ToggleFilterQuickComms();
  2328. if (!LoadPreference("FilterLobbyChats", TRUE))
  2329. ToggleFilterLobbyChats();
  2330. if (!LoadPreference("LinearControlResponse", TRUE))
  2331. ToggleLinearControls();
  2332. if (!LoadPreference("Environment", TRUE))
  2333. ToggleEnvironment();
  2334. if (!LoadPreference("Posters", TRUE))
  2335. TogglePosters();
  2336. if (!LoadPreference("Debris", TRUE))
  2337. ToggleDebris();
  2338. if (!LoadPreference("Stars", TRUE))
  2339. ToggleStars();
  2340. if (!LoadPreference("Strobes", TRUE))
  2341. ToggleStrobes();
  2342. if (!LoadPreference("Trails", TRUE))
  2343. ToggleTrails();
  2344. if (!LoadPreference("Bounds", TRUE))
  2345. ToggleBounds();
  2346. if (!LoadPreference("TransparentObjects", TRUE))
  2347. ToggleTransparentObjects();
  2348. SetSmoke (LoadPreference ("SmokeEffects", 3));
  2349. if (!LoadPreference("Lens Flare", TRUE))
  2350. ToggleLensFlare();
  2351. if (!LoadPreference("BidirectionalLighting", TRUE))
  2352. ToggleBidirectionalLighting();
  2353. if (!LoadPreference("ChatHistory", TRUE))
  2354. ToggleChatHistoryHUD();
  2355. if (!LoadPreference("CenterHUD", TRUE))
  2356. ToggleCenterHUD();
  2357. if (!LoadPreference("TargetHUD", TRUE))
  2358. ToggleTargetHUD();
  2359. if (LoadPreference("SoftwareHUD", FALSE)) //All we need with two styles
  2360. CycleStyleHUD();
  2361. if (LoadPreference("LargeDeadZone", FALSE))
  2362. ToggleLargeDeadZone();
  2363. bool bAllow3DAcceleration;
  2364. if (bSoftware || bHardware) {
  2365. bAllow3DAcceleration = bHardware;
  2366. SavePreference("Allow3DAcceleration", bAllow3DAcceleration);
  2367. } else {
  2368. bAllow3DAcceleration = LoadPreference("Allow3DAcceleration", TRUE) != 0;
  2369. }
  2370. GetEngine()->SetAllow3DAcceleration(bAllow3DAcceleration);
  2371. bool bAllowSecondary;
  2372. if (bSecondary || bPrimary) {
  2373. bAllowSecondary = bSecondary;
  2374. SavePreference("AllowSecondary", bAllowSecondary);
  2375. } else {
  2376. bAllowSecondary = LoadPreference("AllowSecondary" , TRUE) != 0;
  2377. }
  2378. GetEngine()->SetAllowSecondary(bAllowSecondary);
  2379. //
  2380. // Help
  2381. //
  2382. InitializeHelp();
  2383. // initialize the bad words filters
  2384. LoadBadWords ();
  2385. m_pmissileLast = 0;
  2386. //
  2387. // Show the intro videos
  2388. //
  2389. if (!g_bQuickstart && bMovies && !g_bReloaded) {
  2390. SetScreen(CreateVideoScreen(GetModeler(), false));
  2391. } else {
  2392. SetScreen(CreateIntroScreen(GetModeler()));
  2393. m_screen = ScreenIDIntroScreen;
  2394. RestoreCursor();
  2395. }
  2396. }
  2397. void InitializeImages()
  2398. {
  2399. m_pwrapImageTop = new WrapImage(Image::GetEmpty());
  2400. m_pwrapImageLOD = new WrapImage(Image::GetEmpty());
  2401. m_pgroupImage = new GroupImage();
  2402. m_pgroupImage->AddImage(m_pjoystickImage);
  2403. m_pgroupImage->AddImage(m_pwrapImageLOD);
  2404. m_pgroupImage->AddImage(GetPopupContainer()->GetImage());
  2405. m_pgroupImage->AddImage(m_pwrapImageHelp = new WrapImage(Image::GetEmpty()));
  2406. m_pgroupImage->AddImage(m_pwrapImageTop);
  2407. SetImage(m_pgroupImage);
  2408. }
  2409. void SetCursor(const char* pszCursor)
  2410. {
  2411. if (m_pszCursor != pszCursor) //Assume they are all static strings that are combined so pointers are all we need
  2412. {
  2413. m_pszCursor = pszCursor;
  2414. if (GetCursorImage() != Image::GetEmpty())
  2415. RestoreCursor();
  2416. }
  2417. }
  2418. void RestoreCursor()
  2419. {
  2420. TRef<Image> pimageCursor;
  2421. CastTo(pimageCursor, (Value*)GetModeler()->GetNameSpace("cursor")->FindMember(m_pszCursor));
  2422. assert(pimageCursor);
  2423. SetCursorImage(pimageCursor);
  2424. }
  2425. void SetWaitCursor()
  2426. {
  2427. TRef<Image> pimageCursor;
  2428. CastTo(pimageCursor, (Value*)GetModeler()->GetNameSpace("cursor")->FindMember(AWF_CURSOR_WAIT));
  2429. assert(pimageCursor);
  2430. SetCursorImage(pimageCursor);
  2431. }
  2432. void SavePreference(const ZString& szName, DWORD dwValue)
  2433. {
  2434. HKEY hKey;
  2435. if (ERROR_SUCCESS == ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, ALLEGIANCE_REGISTRY_KEY_ROOT,
  2436. 0, "", REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL))
  2437. {
  2438. ::RegSetValueEx(hKey, szName, NULL, REG_DWORD, (const BYTE*)&dwValue, sizeof(dwValue));
  2439. ::RegCloseKey(hKey);
  2440. }
  2441. }
  2442. DWORD LoadPreference(const ZString& szName, DWORD dwDefault)
  2443. {
  2444. HKEY hKey;
  2445. DWORD dwResult = dwDefault;
  2446. if (ERROR_SUCCESS == ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, ALLEGIANCE_REGISTRY_KEY_ROOT,
  2447. 0, "", REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hKey, NULL))
  2448. {
  2449. DWORD dwSize = sizeof(dwResult);
  2450. DWORD dwType = REG_DWORD;
  2451. ::RegQueryValueEx(hKey, szName, NULL, &dwType, (BYTE*)&dwResult, &dwSize);
  2452. ::RegCloseKey(hKey);
  2453. if (dwType != REG_DWORD)
  2454. dwResult = dwDefault;
  2455. }
  2456. return dwResult;
  2457. }
  2458. void SavePreference(const ZString& szName, const ZString& strValue)
  2459. {
  2460. HKEY hKey;
  2461. if (ERROR_SUCCESS == ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, ALLEGIANCE_REGISTRY_KEY_ROOT,
  2462. 0, "", REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL))
  2463. {
  2464. ::RegSetValueEx(hKey, szName, NULL, REG_SZ,
  2465. (const unsigned char*)(const char*)strValue, strValue.GetLength() + 1);
  2466. ::RegCloseKey(hKey);
  2467. }
  2468. }
  2469. ZString LoadPreference(const ZString& szName, const ZString& strDefault)
  2470. {
  2471. HKEY hKey;
  2472. ZString strResult = strDefault;
  2473. if (ERROR_SUCCESS == ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, ALLEGIANCE_REGISTRY_KEY_ROOT,
  2474. 0, "", REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hKey, NULL))
  2475. {
  2476. const int nMaxStrLen = 2048;
  2477. DWORD dwSize = nMaxStrLen;
  2478. DWORD dwType = REG_SZ;
  2479. unsigned char cbValue[nMaxStrLen + 1];
  2480. ::RegQueryValueEx(hKey, szName, NULL, &dwType, cbValue, &dwSize);
  2481. ::RegCloseKey(hKey);
  2482. cbValue[nMaxStrLen] = '\0';
  2483. if (dwType == REG_SZ)
  2484. strResult = (const char*)cbValue;
  2485. }
  2486. return strResult;
  2487. }
  2488. void Terminate()
  2489. {
  2490. //
  2491. // Save the screen resolution
  2492. //
  2493. SaveCombatSize();
  2494. SavePreference("CombatXSize", m_sizeCombat.X());
  2495. SavePreference("CombatYSize", m_sizeCombat.Y());
  2496. SavePreference("CombatFullscreenXSize", m_sizeCombatFullscreen.X());
  2497. SavePreference("CombatFullscreenYSize", m_sizeCombatFullscreen.Y());
  2498. SavePreference("Allow3DAcceleration", GetEngine()->GetAllow3DAcceleration());
  2499. SavePreference("AllowSecondary" , GetEngine()->GetAllowSecondary ());
  2500. //
  2501. // Terminate VT.
  2502. //
  2503. if (NULL != m_hwndVTEdit)
  2504. {
  2505. if (TRUE == ::DestroyWindow(m_hwndVTEdit))
  2506. m_hwndVTEdit = NULL;
  2507. }
  2508. // close all popups (a potential circular reference)
  2509. if (!GetPopupContainer()->IsEmpty())
  2510. GetPopupContainer()->ClosePopup(NULL);
  2511. m_pmessageBox = NULL;
  2512. m_pmessageBoxLockdown= NULL;
  2513. m_pClientEventSource->RemoveSink(m_pClientEventSink);
  2514. RemoveKeyboardInputFilter(GetPopupContainer());
  2515. RemoveKeyboardInputFilter(m_pkeyboardInputFilter);
  2516. trekClient.Terminate();
  2517. // clean up after the training mission if we need to
  2518. extern void KillTrainingStandaloneGame (void);
  2519. KillTrainingStandaloneGame ();
  2520. m_mapAnimatedImages.SetEmpty();
  2521. TerminateGameStateContainer();
  2522. m_pimageBackdrop = NULL;
  2523. m_pimageScreen = NULL;
  2524. m_pscreen = NULL;
  2525. m_pscreenBackdrop = NULL;
  2526. SetCaption(NULL);
  2527. SetImage(Image::GetEmpty());
  2528. m_pwrapImageConsole->SetImage(Image::GetEmpty());
  2529. m_pwrapImageTop->SetImage(Image::GetEmpty());
  2530. m_pgeoScene = NULL;
  2531. m_pcamera = NULL;
  2532. m_pcameraPosters = NULL;
  2533. //m_pcameraTurret = NULL;
  2534. m_pimageScene = NULL;
  2535. m_pgeoDebris = NULL;
  2536. m_pimageStars = NULL;
  2537. m_pimageEnvironment = NULL;
  2538. m_pimageBlack = NULL;
  2539. //m_pimageTurret = NULL;
  2540. m_pimageLensFlare = NULL;
  2541. m_pwrapImageHudGroup = NULL;
  2542. m_pwrapImageComm = NULL;
  2543. m_pwrapImageRadar = NULL;
  2544. m_pwrapImageConsole = NULL;
  2545. m_pgroupImageHUD = NULL;
  2546. m_pconsoleImage = NULL;
  2547. m_pradarImage = NULL;
  2548. m_pgroupImage = NULL;
  2549. m_pgroupImage3D = NULL;
  2550. m_pconsoleImage = NULL;
  2551. m_psoundMusic = NULL;
  2552. m_vSoundMap.SetEmpty();
  2553. m_vsonicChats.SetEmpty();
  2554. m_pqcmenuMain = NULL;
  2555. m_psoundmutexSal->Reset();
  2556. m_psoundmutexVO->Reset();
  2557. m_pSoundEngine = NULL;
  2558. m_ptrekInput = NULL;
  2559. }
  2560. void OnClose()
  2561. {
  2562. Terminate();
  2563. EngineWindow::OnClose();
  2564. }
  2565. void CloseMessageBox ()
  2566. {
  2567. m_pmessageBox = NULL;
  2568. }
  2569. void DoClose()
  2570. {
  2571. PostMessage(WM_CLOSE);
  2572. }
  2573. class CloseSink : public IIntegerEventSink {
  2574. public:
  2575. TrekWindowImpl* m_pwindow;
  2576. CloseSink(TrekWindowImpl* pwindow) :
  2577. m_pwindow(pwindow)
  2578. {
  2579. }
  2580. bool OnEvent(IIntegerEventSource* pevent, int value)
  2581. {
  2582. if (value == IDOK)
  2583. m_pwindow->DoClose();
  2584. else
  2585. m_pwindow->CloseMessageBox ();
  2586. return false;
  2587. }
  2588. };
  2589. TRef<IMessageBox> m_pmessageBox;
  2590. void StartClose()
  2591. {
  2592. if (m_pmessageBox == NULL) {
  2593. m_pmessageBox = CreateMessageBox("Quit Allegiance?", NULL, true, true);
  2594. m_pmessageBox->GetEventSource()->AddSink(new CloseSink(this));
  2595. GetPopupContainer()->OpenPopup(m_pmessageBox, false);
  2596. m_ptrekInput->SetFocus(false);
  2597. }
  2598. //
  2599. // Make sure the window isn't minimized
  2600. //
  2601. if (!GetFullscreen()) {
  2602. OnCaptionRestore();
  2603. }
  2604. }
  2605. bool OnEvent(IIntegerEventSource* pevent, int value)
  2606. {
  2607. if (pevent == m_peventLOD) {
  2608. ThingGeo::SetLODBias(((float)value) / 100);
  2609. }
  2610. return true;
  2611. }
  2612. void DoQuitMission()
  2613. {
  2614. if (Training::IsTraining ())
  2615. {
  2616. Training::EndMission ();
  2617. Training::SetSkipPostSlideshow ();
  2618. }
  2619. else if (Slideshow::IsInSlideShow ())
  2620. {
  2621. screen (ScreenIDTrainScreen);
  2622. }
  2623. else
  2624. {
  2625. trekClient.QuitMission();
  2626. SetWaitCursor();
  2627. TRef<IMessageBox> pmsgBox = CreateMessageBox("Quitting team...", NULL, false, false, 1.0f);
  2628. GetPopupContainer()->OpenPopup(pmsgBox, false);
  2629. }
  2630. }
  2631. class QuitMissionSink : public IIntegerEventSink {
  2632. public:
  2633. TrekWindowImpl* m_pwindow;
  2634. QuitMissionSink(TrekWindowImpl* pwindow) :
  2635. m_pwindow(pwindow)
  2636. {
  2637. }
  2638. bool OnEvent(IIntegerEventSource* pevent, int value)
  2639. {
  2640. if (value == IDOK) {
  2641. m_pwindow->DoQuitMission();
  2642. }
  2643. return false;
  2644. }
  2645. };
  2646. void StartQuitMission()
  2647. {
  2648. TRef<IMessageBox> pmessageBox;
  2649. if (Training::IsTraining () || Slideshow::IsInSlideShow ())
  2650. pmessageBox = CreateMessageBox("Quit the Current Training Mission?", NULL, true, true);
  2651. else
  2652. pmessageBox = CreateMessageBox("Quit the Current Game?", NULL, true, true);
  2653. pmessageBox->GetEventSource()->AddSink(new QuitMissionSink(this));
  2654. GetPopupContainer()->OpenPopup(pmessageBox, false);
  2655. }
  2656. TrekInput* GetInput (void)
  2657. {
  2658. return m_ptrekInput;
  2659. }
  2660. void SetLightDirection(const Vector& direction)
  2661. {
  2662. m_pimageLensFlare->SetLightDirection(direction);
  2663. m_pimageScene->SetLightDirection(direction);
  2664. }
  2665. void SetCluster(IclusterIGC* pcluster)
  2666. {
  2667. if (pcluster)
  2668. {
  2669. m_pCommandGeo->SetCluster(pcluster);
  2670. m_pgeoScene->SetGeo(pcluster->GetClusterSite()->GetGroupScene());
  2671. m_pwrapImagePostersInside->SetImage(pcluster->GetClusterSite()->GetPosterImage());
  2672. m_pimageEnvironment->SetGeo(
  2673. CreateCopyModeGeo(
  2674. pcluster->GetClusterSite()->GetEnvironmentGeo()
  2675. )
  2676. );
  2677. m_pimageStars->SetCount(pcluster->GetStarSeed(), pcluster->GetNstars());
  2678. m_color = pcluster->GetLightColor();
  2679. m_colorAlt = pcluster->GetLightColorAlt();
  2680. m_ambientLevel = pcluster->GetAmbientLevel();
  2681. m_ambientLevelBidirectional = pcluster->GetBidirectionalAmbientLevel();
  2682. SetLightDirection(pcluster->GetLightDirection());
  2683. UpdateBidirectionalLighting();
  2684. // show the 3D view
  2685. m_pwrapImageBackdrop->SetImage(m_pgroupImage3D);
  2686. m_pscreenBackdrop = NULL;
  2687. m_pimageBackdrop = NULL;
  2688. // if they switched away from command view before the cluster could be displayed...
  2689. if (trekClient.GetViewCluster() && (m_viewmode == vmHangar || m_viewmode == vmLoadout))
  2690. {
  2691. // put them back in command mode
  2692. SetViewMode(vmCommand);
  2693. }
  2694. }
  2695. m_pnumberIsGhost->SetValue(trekClient.GetShip()->IsGhost() ? 1.0f : 0.0f);
  2696. UpdateMusic();
  2697. }
  2698. void UpdateBackdropCentering()
  2699. {
  2700. if (m_pimageBackdrop)
  2701. {
  2702. // center the pane on the screen
  2703. const Rect& rectScreen = GetScreenRectValue()->GetValue();
  2704. const WinPoint& sizePane = m_pscreenBackdrop->GetPane()->GetSize();
  2705. Point
  2706. pntOffset(
  2707. (rectScreen.XSize() - sizePane.X()) / 2,
  2708. (rectScreen.YSize() - sizePane.Y()) / 2
  2709. );
  2710. m_pimageBackdrop->SetTranslation(
  2711. pntOffset
  2712. );
  2713. }
  2714. }
  2715. //////////////////////////////////////////////////////////////////////////////
  2716. //
  2717. // ModelerSite
  2718. //
  2719. //////////////////////////////////////////////////////////////////////////////
  2720. void Error(const ZString& str)
  2721. {
  2722. SetFullscreen(false);
  2723. MessageBox(str, "Error", MB_OK);
  2724. }
  2725. //////////////////////////////////////////////////////////////////////////////
  2726. //
  2727. //
  2728. //
  2729. //////////////////////////////////////////////////////////////////////////////
  2730. Camera* GetCamera() { return m_pcamera; }
  2731. Orientation GetCameraOrientation() { return m_cameraControl.GetHeadOrientation() * m_cameraControl.GetOrientation(); }
  2732. void ResetCameraFOV() { m_cameraControl.SetFOV(s_fDefaultFOV); }
  2733. Camera* GetCameraPosters() { return m_pcameraPosters; }
  2734. ConsoleImage* GetConsoleImage() { return m_pconsoleImage; }
  2735. Viewport* GetViewport() { return m_pviewport; }
  2736. Viewport* GetPosterViewport() { return m_pviewportPosters; }
  2737. int GetRadarMode(void) const { return int(m_pradarImage->GetRadarLOD()); }
  2738. void SetRadarMode(int radarMode)
  2739. {
  2740. m_pradarImage->SetRadarLOD (static_cast<RadarImage::RadarLOD> (radarMode));
  2741. m_radarCockpit = radarMode;
  2742. }
  2743. AsteroidAbilityBitMask GetInvestAsteroid(void) const { return m_aabmInvest; }
  2744. void SetInvestAsteroid(AsteroidAbilityBitMask aabm) { m_aabmInvest = aabm; }
  2745. AsteroidAbilityBitMask GetCommandAsteroid(void) const { return m_aabmCommand; }
  2746. void SetCommandAsteroid(AsteroidAbilityBitMask aabm) { m_aabmCommand = aabm; }
  2747. bool GetRoundRadarMode(void) const { return m_bRoundRadar; }
  2748. CameraMode GetCameraMode(void) const { return m_cm; }
  2749. /*
  2750. void TurretChange(void)
  2751. {
  2752. Mount turret = trekClient.GetShip()->GetTurretID();
  2753. if (turret == NA)
  2754. {
  2755. m_pwrapImageTurret->SetImage(Image::GetEmpty());
  2756. m_pgeoTurret = Geo::GetEmpty();
  2757. }
  2758. else
  2759. {
  2760. IshipIGC* pshipParent = trekClient.GetShip()->GetParentShip();
  2761. assert (pshipParent);
  2762. float minDot = pshipParent->GetHullType()->GetHardpointData(turret).minDot;
  2763. if (minDot < -0.75f)
  2764. {
  2765. m_pwrapImageTurret->SetImage(Image::GetEmpty());
  2766. m_pgeoTurret = Geo::GetEmpty();
  2767. }
  2768. else
  2769. {
  2770. m_pgeoTurret = CreateWireSphereGeo(pshipParent->GetHullType()->GetHardpointData(turret).minDot, 32);
  2771. }
  2772. }
  2773. m_pimageTurret =
  2774. new GeoImage(new TransformGeo(m_pgeoTurret, m_pmtTurret),
  2775. m_pviewportTurret, false);
  2776. }
  2777. */
  2778. bool IsValid()
  2779. {
  2780. return EngineWindow::IsValid();
  2781. }
  2782. void ShowWebPage(const char* szURL)
  2783. {
  2784. if (szURL[0] == '\0')
  2785. szURL = "http://www.zone.com/allegiance";
  2786. if (!IsWindows9x()) {
  2787. /*
  2788. if (GetFullscreen()) {
  2789. SetFullscreen(false);
  2790. }
  2791. */
  2792. }
  2793. ShellExecute(NULL, NULL, szURL, NULL, NULL, SW_SHOWNORMAL);
  2794. }
  2795. #define idmConfigure 3
  2796. #define idmView 5
  2797. #define idmOptions 6
  2798. #define idmHelp 7
  2799. #define idmExitGame 8
  2800. #define idmEngineOptions 9
  2801. #define idmSoundOptions 10
  2802. #define idmGameOptions 11
  2803. #define idmExitApp 12
  2804. #define idmGameDetails 13
  2805. #define idmChannelN 101
  2806. #define idmChannelShow 102
  2807. #define idmChannelHide 103
  2808. #define idmChannelRename 104
  2809. #define idmCommSend 201
  2810. #define idmCommMuzzle 202
  2811. #define idmCommUnMuzzle 203
  2812. #define idmEquipmentN 301
  2813. #define idmEquipmentMount 302
  2814. #define idmEquipmentDismount 303
  2815. #define idmEquipmentDrop 304
  2816. #define idmWeaponN 401
  2817. #define idmWeaponMount 402
  2818. #define idmWeaponDismount 403
  2819. #define idmWeaponDrop 404
  2820. #define idmCMGameState 501
  2821. #define idmCMCombat 502
  2822. #define idmCMCommand 503
  2823. #define idmCMSector 504
  2824. #define idmCMLoadout 505
  2825. #define idmCMTeamPane 506
  2826. #define idmSound 601
  2827. #define idmTogglePosters 602
  2828. #define idmToggleDebris 603
  2829. #define idmToggleStars 604
  2830. #define idmToggleStrobes 605
  2831. #define idmToggleLensFlare 606
  2832. #define idmToggleTrails 609
  2833. #define idmToggleEnvironment 611
  2834. #define idmToggleBidirectionalLighting 612
  2835. #define idmToggleChatHistoryHUD 614
  2836. #define idmToggleCenterHUD 615
  2837. #define idmToggleTargetHUD 616
  2838. #define idmToggleRoundRadar 617
  2839. #define idmStyleHUD 618
  2840. #define idmToggleCensorChats 619
  2841. #define idmToggleLinearControls 620
  2842. #define idmToggleSmoke 621
  2843. #define idmToggleBounds 622
  2844. #define idmToggleTransparentObjects 623
  2845. #define idmFilterChatsToAll 624
  2846. #define idmFilterQuickComms 625
  2847. #define idmFilterLobbyChats 626
  2848. #define idmToggleLargeDeadZone 627
  2849. #define idmToggleVirtualJoystick 628
  2850. #define idmToggleFlipY 629
  2851. #define idmToggleStickyChase 630
  2852. #define idmToggleEnableFeedback 631
  2853. #define idmResetSound 701
  2854. #define idmSoundQuality 702
  2855. #define idmSoundHardware 703
  2856. #define idmToggleMusic 704
  2857. #define idmMusicVolumeUp 705
  2858. #define idmMusicVolumeDown 706
  2859. #define idmSFXVolumeUp 707
  2860. #define idmSFXVolumeDown 708
  2861. #define idmVoiceOverVolumeUp 709
  2862. #define idmVoiceOverVolumeDown 710
  2863. void ShowMainMenu()
  2864. {
  2865. m_pmenu =
  2866. CreateMenu(
  2867. GetModeler(),
  2868. TrekResources::SmallFont(),
  2869. m_pmenuCommandSink
  2870. );
  2871. m_pmenu->AddMenuItem(idmEngineOptions, "Graphics Device" , 'D', m_psubmenuEventSink);
  2872. m_pmenu->AddMenuItem(idmOptions , "Graphics Options", 'O', m_psubmenuEventSink);
  2873. m_pmenu->AddMenuItem(idmSoundOptions , "Sound Options" , 'S', m_psubmenuEventSink);
  2874. m_pmenu->AddMenuItem(idmGameOptions , "Game Options", 'G', m_psubmenuEventSink);
  2875. if (trekClient.MyMission() != NULL) {
  2876. m_pmenu->AddMenuItem(idmGameDetails , "Game Details", 'I');
  2877. }
  2878. m_pmenu->AddMenuItem(idmHelp , "Help" , 'H' );
  2879. if ((trekClient.MyMission() != NULL) || Slideshow::IsInSlideShow ())
  2880. m_pmenu->AddMenuItem(idmExitGame , "Quit Mission" , 'Q' );
  2881. m_pmenu->AddMenuItem(idmExitApp , "Exit Allegiance" , 'X' );
  2882. OpenPopup(m_pmenu, Point(10, 10));
  2883. }
  2884. void ShowOptionsMenu()
  2885. {
  2886. m_pmenu =
  2887. CreateMenu(
  2888. GetModeler(),
  2889. TrekResources::SmallFont(),
  2890. m_pmenuCommandSink
  2891. );
  2892. m_pmenu->AddMenuItem(idmEngineOptions, "Graphics Device" , 'D', m_psubmenuEventSink);
  2893. m_pmenu->AddMenuItem(idmOptions , "Graphics Options", 'O', m_psubmenuEventSink);
  2894. m_pmenu->AddMenuItem(idmSoundOptions , "Sound Options" , 'S', m_psubmenuEventSink);
  2895. m_pmenu->AddMenuItem(idmGameOptions , "Game Options" , 'G', m_psubmenuEventSink);
  2896. OpenPopup(m_pmenu, Point(10, 10));
  2897. }
  2898. TRef<IPopup> GetSubMenu(IMenuItem* pitem)
  2899. {
  2900. TRef<IMenu> pmenu =
  2901. CreateMenu(
  2902. GetModeler(),
  2903. TrekResources::SmallFont(),
  2904. m_pmenuCommandSink
  2905. );
  2906. switch (pitem->GetID()) {
  2907. case idmEngineOptions:
  2908. return GetEngineMenu(TrekResources::SmallFont());
  2909. case idmOptions:
  2910. m_pitemToggleEnvironment = pmenu->AddMenuItem(idmToggleEnvironment, GetEnvironmentMenuString() , 'E');
  2911. m_pitemTogglePosters = pmenu->AddMenuItem(idmTogglePosters, GetPostersMenuString() , 'P');
  2912. m_pitemToggleDebris = pmenu->AddMenuItem(idmToggleDebris, GetDebrisMenuString() , 'D');
  2913. m_pitemToggleStars = pmenu->AddMenuItem(idmToggleStars, GetStarsMenuString() , 'S');
  2914. m_pitemToggleStrobes = pmenu->AddMenuItem(idmToggleStrobes, GetStrobesMenuString() , 'R');
  2915. m_pitemToggleTrails = pmenu->AddMenuItem(idmToggleTrails, GetTrailsMenuString() , 'T');
  2916. #ifdef _DEBUG
  2917. m_pitemToggleBounds = pmenu->AddMenuItem(idmToggleBounds, GetBoundsMenuString() , 'N');
  2918. m_pitemToggleTransparentObjects = pmenu->AddMenuItem(idmToggleTransparentObjects, GetTransparentObjectsMenuString() , 'O');
  2919. #endif
  2920. m_pitemToggleSmoke = pmenu->AddMenuItem(idmToggleSmoke, GetSmokeMenuString() , 'A');
  2921. m_pitemToggleLensFlare = pmenu->AddMenuItem(idmToggleLensFlare, GetLensFlareMenuString() , 'F');
  2922. m_pitemToggleBidirectionalLighting = pmenu->AddMenuItem(idmToggleBidirectionalLighting, GetBidirectionalLightingMenuString(), 'B');
  2923. m_pitemStyleHUD = pmenu->AddMenuItem(idmStyleHUD, GetStyleHUDMenuString() , 'H');
  2924. break;
  2925. case idmGameOptions:
  2926. m_pitemToggleCensorChats = pmenu->AddMenuItem(idmToggleCensorChats, GetCensorChatsMenuString(), 'S');
  2927. m_pitemToggleStickyChase = pmenu->AddMenuItem(idmToggleStickyChase, GetStickyChaseMenuString (), 'K');
  2928. m_pitemFilterChatsToAll = pmenu->AddMenuItem(idmFilterChatsToAll, GetFilterChatsToAllMenuString(), 'A');
  2929. m_pitemFilterQuickComms = pmenu->AddMenuItem(idmFilterQuickComms, GetFilterQuickCommsMenuString(), 'Q');
  2930. m_pitemFilterLobbyChats = pmenu->AddMenuItem(idmFilterLobbyChats, GetFilterLobbyChatsMenuString(), 'F');
  2931. m_pitemToggleLinearControls = pmenu->AddMenuItem(idmToggleLinearControls, GetLinearControlsMenuString(), 'L');
  2932. m_pitemToggleLargeDeadZone = pmenu->AddMenuItem(idmToggleLargeDeadZone, GetLargeDeadZoneMenuString(), 'Z');
  2933. m_pitemToggleVirtualJoystick = pmenu->AddMenuItem(idmToggleVirtualJoystick, GetVirtualJoystickMenuString(), 'J');
  2934. m_pitemToggleFlipY = pmenu->AddMenuItem(idmToggleFlipY, GetFlipYMenuString(), 'Y');
  2935. m_pitemToggleEnableFeedback = pmenu->AddMenuItem(idmToggleEnableFeedback, GetEnableFeedbackMenuString(), 'E');
  2936. pmenu->AddMenuItem(idmConfigure , "Map Keys and Controls" , 'C');
  2937. break;
  2938. case idmSoundOptions:
  2939. #ifdef _DEBUG
  2940. pmenu->AddMenuItem(idmResetSound, "Reset Sound", 'R');
  2941. #endif
  2942. m_pitemSoundQuality = pmenu->AddMenuItem(idmSoundQuality, GetSoundQualityMenuString());
  2943. m_pitemToggleSoundHardware = pmenu->AddMenuItem(idmSoundHardware, GetSoundHardwareMenuString());
  2944. m_pitemToggleMusic = pmenu->AddMenuItem(idmToggleMusic, GetMusicMenuString());
  2945. m_pitemMusicVolumeUp = pmenu->AddMenuItem(idmMusicVolumeUp,
  2946. GetGainMenuString("Music", m_pnumMusicGain->GetValue(), c_fVolumeDelta), 'M');
  2947. m_pitemMusicVolumeDown = pmenu->AddMenuItem(idmMusicVolumeDown,
  2948. GetGainMenuString("Music", m_pnumMusicGain->GetValue(), -c_fVolumeDelta), 'N');
  2949. m_pitemSFXVolumeUp = pmenu->AddMenuItem(idmSFXVolumeUp,
  2950. GetGainMenuString("Sound Effect", m_pnumSFXGain->GetValue(), c_fVolumeDelta), 'S');
  2951. m_pitemSFXVolumeDown = pmenu->AddMenuItem(idmSFXVolumeDown,
  2952. GetGainMenuString("Sound Effect", m_pnumSFXGain->GetValue(), -c_fVolumeDelta), 'A');
  2953. m_pitemVoiceOverVolumeUp = pmenu->AddMenuItem(idmVoiceOverVolumeUp,
  2954. GetGainMenuString("Voice Over", m_pnumVoiceOverGain->GetValue(), c_fVolumeDelta), 'V');
  2955. m_pitemVoiceOverVolumeDown = pmenu->AddMenuItem(idmVoiceOverVolumeDown,
  2956. GetGainMenuString("Voice Over", m_pnumVoiceOverGain->GetValue(), -c_fVolumeDelta), 'C');
  2957. break;
  2958. }
  2959. return pmenu;
  2960. }
  2961. void ToggleDebris()
  2962. {
  2963. if (m_pwrapGeoDebris->GetGeo() == Geo::GetEmpty()) {
  2964. m_pwrapGeoDebris->SetGeo(m_pgeoDebris);
  2965. SavePreference("Debris", TRUE);
  2966. } else {
  2967. m_pwrapGeoDebris->SetGeo(Geo::GetEmpty());
  2968. SavePreference("Debris", FALSE);
  2969. }
  2970. if (m_pitemToggleDebris != NULL) {
  2971. m_pitemToggleDebris->SetString(GetDebrisMenuString());
  2972. }
  2973. }
  2974. void ToggleEnvironment()
  2975. {
  2976. if (m_pwrapImageEnvironment->GetImage() == m_pimageEnvironment) {
  2977. m_pwrapImageEnvironment->SetImage(Image::GetEmpty());
  2978. SavePreference("Environment", FALSE);
  2979. } else {
  2980. m_pwrapImageEnvironment->SetImage(m_pimageEnvironment);
  2981. SavePreference("Environment", TRUE);
  2982. }
  2983. if (m_pitemToggleEnvironment != NULL) {
  2984. m_pitemToggleEnvironment->SetString(GetEnvironmentMenuString());
  2985. }
  2986. }
  2987. void ToggleRoundRadar()
  2988. {
  2989. if (m_bRoundRadar)
  2990. {
  2991. m_bRoundRadar = false;
  2992. SavePreference("RoundRadarScreen", FALSE);
  2993. }
  2994. else
  2995. {
  2996. m_bRoundRadar = true;
  2997. SavePreference("RoundRadarScreen", TRUE);
  2998. }
  2999. if (m_pitemToggleRoundRadar != NULL) {
  3000. m_pitemToggleRoundRadar->SetString(GetRoundRadarMenuString());
  3001. }
  3002. }
  3003. void ToggleCensorChats()
  3004. {
  3005. if (CensorDisplay ())
  3006. SavePreference("CensorChats", FALSE);
  3007. else
  3008. SavePreference("CensorChats", TRUE);
  3009. ToggleCensorDisplay ();
  3010. if (m_pitemToggleCensorChats != NULL) {
  3011. m_pitemToggleCensorChats->SetString(GetCensorChatsMenuString());
  3012. }
  3013. }
  3014. void ToggleStickyChase ()
  3015. {
  3016. if (m_bPreferChaseView)
  3017. {
  3018. m_bPreferChaseView = false;
  3019. SavePreference("PreferChaseView", FALSE);
  3020. }
  3021. else
  3022. {
  3023. m_bPreferChaseView = true;
  3024. SavePreference ("PreferChaseView", TRUE);
  3025. }
  3026. if (m_pitemToggleStickyChase != NULL)
  3027. m_pitemToggleStickyChase->SetString (GetStickyChaseMenuString ());
  3028. }
  3029. void ToggleFilterChatsToAll()
  3030. {
  3031. if (trekClient.FilterChatsToAll())
  3032. {
  3033. trekClient.FilterChatsToAll(false);
  3034. SavePreference("FilterChatsToAll", FALSE);
  3035. }
  3036. else
  3037. {
  3038. trekClient.FilterChatsToAll(true);
  3039. SavePreference("FilterChatsToAll", TRUE);
  3040. }
  3041. if (m_pitemFilterChatsToAll != NULL) {
  3042. m_pitemFilterChatsToAll->SetString(GetFilterChatsToAllMenuString());
  3043. }
  3044. }
  3045. void ToggleFilterQuickComms()
  3046. {
  3047. if (trekClient.FilterQuickComms())
  3048. {
  3049. trekClient.FilterQuickComms(false);
  3050. SavePreference("FilterQuickComms", FALSE);
  3051. }
  3052. else
  3053. {
  3054. trekClient.FilterQuickComms(true);
  3055. SavePreference("FilterQuickComms", TRUE);
  3056. }
  3057. if (m_pitemFilterQuickComms != NULL) {
  3058. m_pitemFilterQuickComms->SetString(GetFilterQuickCommsMenuString());
  3059. }
  3060. }
  3061. void ToggleFilterLobbyChats()
  3062. {
  3063. if (trekClient.FilterLobbyChats())
  3064. {
  3065. trekClient.FilterLobbyChats(false);
  3066. SavePreference("FilterLobbyChats", FALSE);
  3067. }
  3068. else
  3069. {
  3070. trekClient.FilterLobbyChats(true);
  3071. SavePreference("FilterLobbyChats", TRUE);
  3072. }
  3073. if (m_pitemFilterLobbyChats != NULL) {
  3074. m_pitemFilterLobbyChats->SetString(GetFilterLobbyChatsMenuString());
  3075. }
  3076. }
  3077. void ToggleLinearControls()
  3078. {
  3079. if (m_bLinearControls)
  3080. {
  3081. m_bLinearControls = false;
  3082. SavePreference("LinearControlResponse", FALSE);
  3083. }
  3084. else
  3085. {
  3086. m_bLinearControls = true;
  3087. SavePreference("LinearControlResponse", TRUE);
  3088. }
  3089. if (m_pitemToggleLinearControls != NULL) {
  3090. m_pitemToggleLinearControls->SetString(GetLinearControlsMenuString());
  3091. }
  3092. }
  3093. void ToggleStars()
  3094. {
  3095. if (m_pwrapImageStars->GetImage() == Image::GetEmpty()) {
  3096. m_pwrapImageStars->SetImage(m_pimageStars);
  3097. SavePreference("Stars", TRUE);
  3098. } else {
  3099. m_pwrapImageStars->SetImage(Image::GetEmpty());
  3100. SavePreference("Stars", FALSE);
  3101. }
  3102. if (m_pitemToggleStars != NULL) {
  3103. m_pitemToggleStars->SetString(GetStarsMenuString());
  3104. }
  3105. }
  3106. void TogglePosters()
  3107. {
  3108. if (m_pwrapImagePosters->GetImage() == Image::GetEmpty()) {
  3109. m_pwrapImagePosters->SetImage(m_pwrapImagePostersInside);
  3110. SavePreference("Posters", TRUE);
  3111. } else {
  3112. m_pwrapImagePosters->SetImage(Image::GetEmpty());
  3113. SavePreference("Posters", FALSE);
  3114. }
  3115. if (m_pitemTogglePosters != NULL) {
  3116. m_pitemTogglePosters->SetString(GetPostersMenuString());
  3117. }
  3118. }
  3119. void ToggleLensFlare()
  3120. {
  3121. m_bLensFlare = !m_bLensFlare;
  3122. SavePreference("Lens Flare", (DWORD)m_bLensFlare);
  3123. if (!CommandCamera(m_cm)) {
  3124. if (m_bLensFlare) {
  3125. m_pwrapImageLensFlare->SetImage(m_pimageLensFlare);
  3126. } else {
  3127. m_pwrapImageLensFlare->SetImage(Image::GetEmpty());
  3128. }
  3129. }
  3130. if (m_pitemToggleLensFlare != NULL) {
  3131. m_pitemToggleLensFlare->SetString(GetLensFlareMenuString());
  3132. }
  3133. }
  3134. void UpdateBidirectionalLighting()
  3135. {
  3136. if (m_bBidirectionalLighting) {
  3137. m_pimageScene->SetLight(m_color, m_colorAlt);
  3138. m_pimageScene->SetAmbientLevel(m_ambientLevelBidirectional);
  3139. } else {
  3140. m_pimageScene->SetLight(m_color);
  3141. m_pimageScene->SetAmbientLevel(m_ambientLevel);
  3142. }
  3143. }
  3144. void ToggleBidirectionalLighting()
  3145. {
  3146. m_bBidirectionalLighting = !m_bBidirectionalLighting;
  3147. SavePreference("BidirectionalLighting", (DWORD)m_bBidirectionalLighting);
  3148. UpdateBidirectionalLighting();
  3149. if (m_pitemToggleBidirectionalLighting != NULL) {
  3150. m_pitemToggleBidirectionalLighting->SetString(GetBidirectionalLightingMenuString());
  3151. }
  3152. }
  3153. SoundID GetFlightMusic()
  3154. {
  3155. int nGrooveLevel = trekClient.GetGrooveLevel();
  3156. static SoundID idLastFlightMusic = (random(0, 1) > 0.5)
  3157. ? flightMusic1ASound : flightMusic2ASound;
  3158. SoundID idNextFlightAMusic = (idLastFlightMusic < flightMusic2ASound)
  3159. ? flightMusic2ASound : flightMusic1ASound;
  3160. SoundID musicIdNew;
  3161. if (idLastFlightMusic < flightMusic2ASound)
  3162. idNextFlightAMusic = flightMusic2ASound;
  3163. else if (idLastFlightMusic < flightMusic3ASound)
  3164. idNextFlightAMusic = flightMusic3ASound;
  3165. else
  3166. idNextFlightAMusic = flightMusic1ASound;
  3167. ZAssert(nGrooveLevel >= 0 && nGrooveLevel <= 2);
  3168. switch (m_musicId)
  3169. {
  3170. case flightMusic1CSound:
  3171. case flightMusic2CSound:
  3172. case flightMusic3CSound:
  3173. if (nGrooveLevel == 2)
  3174. {
  3175. if (m_psoundMusic && m_psoundMusic->IsPlaying() == S_OK)
  3176. musicIdNew = m_musicId;
  3177. else
  3178. musicIdNew = idNextFlightAMusic + 2;
  3179. }
  3180. else if (nGrooveLevel == 1)
  3181. musicIdNew = m_musicId - 1;
  3182. else
  3183. musicIdNew = idNextFlightAMusic;
  3184. break;
  3185. case flightMusic1BSound:
  3186. case flightMusic2BSound:
  3187. case flightMusic3BSound:
  3188. if (nGrooveLevel == 2)
  3189. musicIdNew = m_musicId + 1;
  3190. else if (nGrooveLevel == 1)
  3191. {
  3192. if (m_psoundMusic && m_psoundMusic->IsPlaying() == S_OK)
  3193. musicIdNew = m_musicId;
  3194. else
  3195. musicIdNew = idNextFlightAMusic + 1;
  3196. }
  3197. else
  3198. musicIdNew = idNextFlightAMusic;
  3199. break;
  3200. case flightMusic1ASound:
  3201. case flightMusic2ASound:
  3202. case flightMusic3ASound:
  3203. if (nGrooveLevel == 2)
  3204. musicIdNew = m_musicId + 2;
  3205. else if (nGrooveLevel == 1)
  3206. musicIdNew = m_musicId + 1;
  3207. else
  3208. {
  3209. if (m_psoundMusic && m_psoundMusic->IsPlaying() == S_OK)
  3210. musicIdNew = m_musicId;
  3211. else
  3212. musicIdNew = idNextFlightAMusic;
  3213. }
  3214. break;
  3215. case deathMusicSound:
  3216. if (m_psoundMusic && m_psoundMusic && m_psoundMusic->IsPlaying() == S_OK)
  3217. return deathMusicSound;
  3218. else
  3219. musicIdNew = nGrooveLevel + idNextFlightAMusic;
  3220. break;
  3221. default:
  3222. musicIdNew = nGrooveLevel + idNextFlightAMusic;
  3223. break;
  3224. }
  3225. idLastFlightMusic = musicIdNew;
  3226. return musicIdNew;
  3227. }
  3228. void UpdateMusic()
  3229. {
  3230. SoundID newMusicSound = NA;
  3231. if (m_bMusic)
  3232. {
  3233. switch (m_screen)
  3234. {
  3235. case ScreenIDCombat:
  3236. newMusicSound = GetFlightMusic();
  3237. break;
  3238. case ScreenIDSplashScreen:
  3239. newMusicSound = NA;
  3240. break;
  3241. default:
  3242. if ((m_musicId == gameOverWonMusicSound
  3243. || m_musicId == gameOverLostMusicSound)
  3244. && m_psoundMusic && m_psoundMusic->IsPlaying() == S_OK)
  3245. {
  3246. newMusicSound = m_musicId;
  3247. }
  3248. else
  3249. newMusicSound = gameScreenMusicSound;
  3250. break;
  3251. }
  3252. }
  3253. TriggerMusic(newMusicSound);
  3254. }
  3255. void TriggerMusic(SoundID newMusicSound)
  3256. {
  3257. if (newMusicSound != m_musicId || m_psoundMusic == NULL || m_psoundMusic->IsPlaying() == S_FALSE)
  3258. {
  3259. if (m_psoundMusic != NULL)
  3260. m_psoundMusic->Stop(true);
  3261. if (newMusicSound != NA)
  3262. m_psoundMusic = StartSound(newMusicSound);
  3263. else
  3264. m_psoundMusic = NULL;
  3265. m_musicId = newMusicSound;
  3266. }
  3267. }
  3268. bool GetMusicIsOn (void)
  3269. {
  3270. return m_bMusic;
  3271. }
  3272. void SetMusicOn (bool bMusicOn)
  3273. {
  3274. m_bMusic = bMusicOn;
  3275. UpdateMusic ();
  3276. }
  3277. void ToggleStrobes()
  3278. {
  3279. ThingGeo::SetShowLights(!ThingGeo::GetShowLights());
  3280. SavePreference("Strobes", (DWORD)ThingGeo::GetShowLights());
  3281. if (m_pitemToggleStrobes != NULL) {
  3282. m_pitemToggleStrobes->SetString(GetStrobesMenuString());
  3283. }
  3284. }
  3285. void ToggleTrails()
  3286. {
  3287. ThingGeo::SetShowTrails(!ThingGeo::GetShowTrails());
  3288. SavePreference("Trails", (DWORD)ThingGeo::GetShowTrails());
  3289. if (m_pitemToggleTrails != NULL) {
  3290. m_pitemToggleTrails->SetString(GetTrailsMenuString());
  3291. }
  3292. }
  3293. void ToggleBounds()
  3294. {
  3295. ThingGeo::SetShowBounds(!ThingGeo::GetShowBounds());
  3296. SavePreference("Bounds", (DWORD)ThingGeo::GetShowBounds());
  3297. if (m_pitemToggleBounds != NULL) {
  3298. m_pitemToggleBounds->SetString(GetBoundsMenuString());
  3299. }
  3300. }
  3301. void ToggleTransparentObjects()
  3302. {
  3303. ThingGeo::SetTransparentObjects(!ThingGeo::GetTransparentObjects());
  3304. SavePreference("TransparentObjects", (DWORD)ThingGeo::GetTransparentObjects());
  3305. if (m_pitemToggleTransparentObjects != NULL) {
  3306. m_pitemToggleTransparentObjects->SetString(GetTransparentObjectsMenuString());
  3307. }
  3308. }
  3309. void SetSmoke (DWORD value)
  3310. {
  3311. ThingGeo::SetShowSmoke (int (value));
  3312. }
  3313. void ToggleSmoke()
  3314. {
  3315. int iSmoke = ThingGeo::GetShowSmoke();
  3316. switch (iSmoke)
  3317. {
  3318. case 0:
  3319. iSmoke = 1;
  3320. break;
  3321. case 1:
  3322. iSmoke = 3;
  3323. break;
  3324. case 3:
  3325. iSmoke = 5;
  3326. break;
  3327. default:
  3328. iSmoke = 0;
  3329. }
  3330. ThingGeo::SetShowSmoke(iSmoke);
  3331. SavePreference("SmokeEffects", (DWORD) iSmoke);
  3332. if (m_pitemToggleSmoke != NULL) {
  3333. m_pitemToggleSmoke->SetString(GetSmokeMenuString());
  3334. }
  3335. }
  3336. void ToggleChatHistoryHUD()
  3337. {
  3338. m_pboolChatHistoryHUD->SetValue(!m_pboolChatHistoryHUD->GetValue());
  3339. //SavePreference("ChatHistory", (DWORD)m_pboolChatHistoryHUD->GetValue());
  3340. if (m_pitemToggleChatHistoryHUD != NULL)
  3341. m_pitemToggleChatHistoryHUD->SetString(GetChatHistoryHUDMenuString());
  3342. }
  3343. void ToggleCenterHUD()
  3344. {
  3345. m_pboolCenterHUD->SetValue(!m_pboolCenterHUD->GetValue());
  3346. SavePreference("CenterHUD", (DWORD)m_pboolCenterHUD->GetValue());
  3347. if (m_pitemToggleCenterHUD != NULL)
  3348. m_pitemToggleCenterHUD->SetString(GetCenterHUDMenuString());
  3349. }
  3350. void ToggleTargetHUD()
  3351. {
  3352. m_pboolTargetHUD->SetValue(!m_pboolTargetHUD->GetValue());
  3353. SavePreference("TargetHUD", (DWORD)m_pboolTargetHUD->GetValue());
  3354. if (m_pitemToggleTargetHUD != NULL)
  3355. m_pitemToggleTargetHUD->SetString(GetTargetHUDMenuString());
  3356. }
  3357. //Something of a misnomer since there are only two styles but this may change
  3358. void CycleStyleHUD()
  3359. {
  3360. int style = (int(m_pnumberStyleHUD->GetValue()) + 1) % 2;
  3361. m_pnumberStyleHUD->SetValue(float(style));
  3362. SavePreference("SoftwareHUD", (DWORD)style);
  3363. if (m_pitemStyleHUD != NULL)
  3364. m_pitemStyleHUD->SetString(GetStyleHUDMenuString());
  3365. }
  3366. void ToggleLargeDeadZone(void)
  3367. {
  3368. g_fJoystickDeadZone = g_fJoystickDeadZoneSmall + g_fJoystickDeadZoneLarge - g_fJoystickDeadZone;
  3369. g_fInverseJoystickDeadZone = g_fJoystickDeadZone - 1.0f;
  3370. SavePreference("LargeDeadZone", g_fJoystickDeadZone > (g_fJoystickDeadZoneSmall + g_fJoystickDeadZoneLarge)/2.0f);
  3371. if (m_pitemToggleLargeDeadZone != NULL)
  3372. m_pitemToggleLargeDeadZone->SetString(GetLargeDeadZoneMenuString());
  3373. }
  3374. void ToggleVirtualJoystick()
  3375. {
  3376. m_bEnableVirtualJoystick = !m_bEnableVirtualJoystick;
  3377. SavePreference("VirtualJoystick", m_bEnableVirtualJoystick);
  3378. if (m_pitemToggleVirtualJoystick != NULL) {
  3379. m_pitemToggleVirtualJoystick->SetString(GetVirtualJoystickMenuString());
  3380. }
  3381. }
  3382. void ToggleFlipY()
  3383. {
  3384. m_bFlipY = !m_bFlipY;
  3385. SavePreference("FlipY", m_bFlipY);
  3386. if (m_pitemToggleFlipY != NULL) {
  3387. m_pitemToggleFlipY->SetString(GetFlipYMenuString());
  3388. }
  3389. }
  3390. void ToggleEnableFeedback()
  3391. {
  3392. m_bEnableFeedback = !m_bEnableFeedback;
  3393. SavePreference("EnableFeedback", m_bEnableFeedback);
  3394. if (m_pitemToggleEnableFeedback != NULL) {
  3395. m_pitemToggleEnableFeedback->SetString(GetEnableFeedbackMenuString());
  3396. }
  3397. }
  3398. void RenderSizeChanged(bool bSmaller)
  3399. {
  3400. if (bSmaller && GetFullscreen()) {
  3401. m_pwrapNumberStyleHUD->SetWrappedValue(new Number(1.0f));
  3402. } else {
  3403. m_pwrapNumberStyleHUD->SetWrappedValue(m_pnumberStyleHUD);
  3404. }
  3405. }
  3406. // Reloads the sound mdls.
  3407. // this is a hack added to make art's life easier
  3408. void ResetSound()
  3409. {
  3410. // reload the sound-related MDLs
  3411. GetModeler()->UnloadNameSpace("quickchat");
  3412. GetModeler()->UnloadNameSpace("sounddef");
  3413. InitializeQuickChatMenu();
  3414. InitializeSoundTemplates();
  3415. // reset the music
  3416. m_musicId = NA;
  3417. // reset the SFX
  3418. trekClient.ResetSound();
  3419. }
  3420. void SwitchSoundQuality()
  3421. {
  3422. switch (m_soundquality)
  3423. {
  3424. case ISoundEngine::minQuality:
  3425. m_soundquality = ISoundEngine::midQuality;
  3426. break;
  3427. case ISoundEngine::midQuality:
  3428. m_soundquality = ISoundEngine::maxQuality;
  3429. break;
  3430. case ISoundEngine::maxQuality:
  3431. m_soundquality = ISoundEngine::minQuality;
  3432. break;
  3433. default:
  3434. ZAssert(false);
  3435. m_soundquality = ISoundEngine::minQuality;
  3436. break;
  3437. }
  3438. ZSucceeded(m_pSoundEngine->SetQuality(m_soundquality));
  3439. SavePreference("SoundQuality", (DWORD)m_soundquality);
  3440. if (m_pitemSoundQuality != NULL)
  3441. m_pitemSoundQuality->SetString(GetSoundQualityMenuString());
  3442. };
  3443. void ToggleSoundHardware()
  3444. {
  3445. m_bEnableSoundHardware = !m_bEnableSoundHardware;
  3446. SavePreference("SoundHardwareAcceleration", (DWORD)m_bEnableSoundHardware);
  3447. ZSucceeded(m_pSoundEngine->EnableHardware(m_bEnableSoundHardware));
  3448. if (m_pitemToggleSoundHardware != NULL)
  3449. m_pitemToggleSoundHardware->SetString(GetSoundHardwareMenuString());
  3450. }
  3451. void ToggleMusic()
  3452. {
  3453. m_bMusic = !m_bMusic;
  3454. SavePreference("Music", (DWORD)m_bMusic);
  3455. UpdateMusic();
  3456. if (m_pitemToggleMusic != NULL)
  3457. m_pitemToggleMusic->SetString(GetMusicMenuString());
  3458. }
  3459. void AdjustMusicVolume(float fDelta)
  3460. {
  3461. float fNewValue = min(0, max(c_nMinGain, m_pnumMusicGain->GetValue() + fDelta));
  3462. m_pnumMusicGain->SetValue(fNewValue);
  3463. SavePreference("MusicGain", (DWORD)-fNewValue);
  3464. if (m_pitemMusicVolumeUp != NULL)
  3465. {
  3466. m_pitemMusicVolumeUp->SetString(
  3467. GetGainMenuString("Music", m_pnumMusicGain->GetValue(), c_fVolumeDelta));
  3468. }
  3469. if (m_pitemMusicVolumeDown != NULL)
  3470. {
  3471. m_pitemMusicVolumeDown->SetString(
  3472. GetGainMenuString("Music", m_pnumMusicGain->GetValue(), -c_fVolumeDelta));
  3473. }
  3474. m_pDiskPlayer->SetGain(fNewValue);
  3475. }
  3476. void AdjustSFXVolume(float fDelta)
  3477. {
  3478. float fNewValue = min(0, max(c_nMinGain, m_pnumSFXGain->GetValue() + fDelta));
  3479. m_pnumSFXGain->SetValue(fNewValue);
  3480. SavePreference("SFXGain", (DWORD)-fNewValue);
  3481. if (m_pitemSFXVolumeUp != NULL)
  3482. {
  3483. m_pitemSFXVolumeUp->SetString(
  3484. GetGainMenuString("Sound Effect", m_pnumSFXGain->GetValue(), c_fVolumeDelta));
  3485. }
  3486. if (m_pitemSFXVolumeDown != NULL)
  3487. {
  3488. m_pitemSFXVolumeDown->SetString(
  3489. GetGainMenuString("Sound Effect", m_pnumSFXGain->GetValue(), -c_fVolumeDelta));
  3490. }
  3491. }
  3492. void AdjustVoiceOverVolume(float fDelta)
  3493. {
  3494. float fNewValue = min(0, max(c_nMinGain, m_pnumVoiceOverGain->GetValue() + fDelta));
  3495. m_pnumVoiceOverGain->SetValue(fNewValue);
  3496. SavePreference("VoiceOverGain", (DWORD)-fNewValue);
  3497. if (m_pitemVoiceOverVolumeUp != NULL)
  3498. {
  3499. m_pitemVoiceOverVolumeUp->SetString(
  3500. GetGainMenuString("Voice Over", m_pnumVoiceOverGain->GetValue(), c_fVolumeDelta));
  3501. }
  3502. if (m_pitemVoiceOverVolumeDown != NULL)
  3503. {
  3504. m_pitemVoiceOverVolumeDown->SetString(
  3505. GetGainMenuString("Voice Over", m_pnumVoiceOverGain->GetValue(), -c_fVolumeDelta));
  3506. }
  3507. }
  3508. ZString GetPostersMenuString()
  3509. {
  3510. return (m_pwrapImagePosters->GetImage() != Image::GetEmpty()) ? "Posters On " : "Posters Off ";
  3511. }
  3512. ZString GetDebrisMenuString()
  3513. {
  3514. return (m_pwrapGeoDebris->GetGeo() != Geo::GetEmpty()) ? "Debris On " : "Debris Off ";
  3515. }
  3516. ZString GetEnvironmentMenuString()
  3517. {
  3518. return (m_pwrapImageEnvironment->GetImage() == m_pimageEnvironment) ? "Environment On " : "Environment Off ";
  3519. }
  3520. ZString GetRoundRadarMenuString()
  3521. {
  3522. return (m_bRoundRadar) ? "Round Radar" : "Square Radar";
  3523. }
  3524. ZString GetCensorChatsMenuString()
  3525. {
  3526. return (CensorDisplay ()) ? "Censor Display" : "Don't Censor Display";
  3527. }
  3528. ZString GetStickyChaseMenuString ()
  3529. {
  3530. return m_bPreferChaseView ? "Default To Chase View" : "Default To Cockpit View";
  3531. }
  3532. ZString GetFilterChatsToAllMenuString()
  3533. {
  3534. return trekClient.FilterChatsToAll() ? "Filter Chats Sent To All" : "Don't Filter Chats Sent To All";
  3535. }
  3536. ZString GetFilterQuickCommsMenuString()
  3537. {
  3538. return trekClient.FilterQuickComms() ? "Filter Voice Commands" : "Don't Filter Voice Commands";
  3539. }
  3540. ZString GetFilterLobbyChatsMenuString()
  3541. {
  3542. return trekClient.FilterLobbyChats() ? "Filter Chats Sent From Lobby" : "Don't Filter Chats Sent From Lobby";
  3543. }
  3544. ZString GetLinearControlsMenuString()
  3545. {
  3546. return (m_bLinearControls) ? "Linear Control Response" : "Quadratic Control Response";
  3547. }
  3548. ZString GetStarsMenuString()
  3549. {
  3550. return (m_pwrapImageStars->GetImage() != Image::GetEmpty()) ? "Stars On " : "Stars Off ";
  3551. }
  3552. ZString GetStrobesMenuString()
  3553. {
  3554. return ThingGeo::GetShowLights() ? "Strobes On " : "Strobes Off ";
  3555. }
  3556. ZString GetTrailsMenuString()
  3557. {
  3558. return ThingGeo::GetShowTrails() ? "Trails On " : "Trails Off ";
  3559. }
  3560. ZString GetBoundsMenuString()
  3561. {
  3562. return ThingGeo::GetShowBounds() ? "Bounds On " : "Bounds Off ";
  3563. }
  3564. ZString GetTransparentObjectsMenuString()
  3565. {
  3566. return ThingGeo::GetTransparentObjects() ? "TransparentObjects On " : "TransparentObjects Off ";
  3567. }
  3568. ZString GetLensFlareMenuString()
  3569. {
  3570. return (m_bLensFlare) ? "Lens Flare On " : "Lens Flare Off ";
  3571. }
  3572. ZString GetSmokeMenuString()
  3573. {
  3574. switch (ThingGeo::GetShowSmoke())
  3575. {
  3576. case 0:
  3577. return ZString ("Particles Off");
  3578. break;
  3579. case 1:
  3580. return ZString ("Particles On - Low Quality");
  3581. break;
  3582. case 3:
  3583. return ZString ("Particles On - Medium Quality");
  3584. break;
  3585. default:
  3586. return ZString ("Particles On - High Quality");
  3587. break;
  3588. }
  3589. }
  3590. ZString GetSoundQualityMenuString()
  3591. {
  3592. switch (m_soundquality)
  3593. {
  3594. case ISoundEngine::minQuality:
  3595. return "Sound Quality: Low";
  3596. case ISoundEngine::midQuality:
  3597. return "Sound Quality: Default";
  3598. case ISoundEngine::maxQuality:
  3599. return "Sound Quality: High";
  3600. default:
  3601. ZAssert(false);
  3602. return "<bug>";
  3603. }
  3604. }
  3605. ZString GetSoundHardwareMenuString()
  3606. {
  3607. return m_bEnableSoundHardware ? "Sound Card Acceleration On" : "Sound Card Acceleration Off";
  3608. }
  3609. ZString GetMusicMenuString()
  3610. {
  3611. return (m_bMusic) ? "Music On " : "Music Off ";
  3612. }
  3613. ZString GetBidirectionalLightingMenuString()
  3614. {
  3615. return (m_bBidirectionalLighting) ? "Bidirectional Lighting On " : "Bidirectional Lighting Off ";
  3616. }
  3617. ZString GetChatHistoryHUDMenuString()
  3618. {
  3619. return (m_pboolChatHistoryHUD->GetValue()) ? "Chat History On " : "Chat History Off ";
  3620. }
  3621. ZString GetCenterHUDMenuString()
  3622. {
  3623. return (m_pboolCenterHUD->GetValue()) ? "Center HUD On " : "Center HUD Off ";
  3624. }
  3625. ZString GetTargetHUDMenuString()
  3626. {
  3627. return (m_pboolTargetHUD->GetValue()) ? "Target HUD On " : "Target HUD Off ";
  3628. }
  3629. const ZString& GetStyleHUDMenuString()
  3630. {
  3631. static const ZString c_strNormal("Style: Normal");
  3632. static const ZString c_strSoftware("Style: Software");
  3633. return (m_pnumberStyleHUD->GetValue()) ? c_strSoftware : c_strNormal;
  3634. }
  3635. const ZString& GetLargeDeadZoneMenuString()
  3636. {
  3637. static const ZString c_strNormal("Normal dead zone");
  3638. static const ZString c_strLarge("Large dead zone");
  3639. return (g_fJoystickDeadZone > (g_fJoystickDeadZoneSmall + g_fJoystickDeadZoneLarge)/2.0f) ? c_strLarge : c_strNormal;
  3640. }
  3641. ZString GetVirtualJoystickMenuString()
  3642. {
  3643. return (m_bEnableVirtualJoystick ? "Virtual Joystick On " : "Virtual Joystick Off ");
  3644. }
  3645. ZString GetFlipYMenuString()
  3646. {
  3647. return (m_bFlipY ? "Y Axis Flipped " : "Y Axis Not Flipped ");
  3648. }
  3649. ZString GetEnableFeedbackMenuString()
  3650. {
  3651. return (m_bEnableFeedback ? "Force Feedback Enabled " : "Force Feedback Disabled ");
  3652. }
  3653. ZString GetGainMenuString(const ZString& strSoundType, float fCurrentGain, float fDelta)
  3654. {
  3655. ZString strResult = ((fDelta > 0) ? "Raise " : "Lower ") + strSoundType + " Volume ";
  3656. if (fCurrentGain >= 0 && fDelta > 0)
  3657. {
  3658. strResult += "(maxed)";
  3659. }
  3660. else if (fCurrentGain <= c_nMinGain && fDelta < 0)
  3661. {
  3662. strResult += "(off)";
  3663. }
  3664. else
  3665. {
  3666. strResult += "to " + ZString(min(0, max(c_nMinGain, fCurrentGain + fDelta))) + " dB";
  3667. }
  3668. return strResult;
  3669. }
  3670. void DoInputConfigure()
  3671. {
  3672. CloseMenu();
  3673. TRef<IPopup> ppopup =
  3674. m_ptrekInput->CreateInputMapPopup(
  3675. GetModeler(),
  3676. TrekResources::SmallFont(),
  3677. GetTime()
  3678. );
  3679. GetPopupContainer()->OpenPopup(ppopup);
  3680. }
  3681. void CloseMenu()
  3682. {
  3683. GetPopupContainer()->ClosePopup(m_pmenu);
  3684. m_pmenu = NULL;
  3685. }
  3686. void OnGameState()
  3687. {
  3688. GetPopupContainer()->OpenPopup(
  3689. CreateMissionParametersPopup(GetModeler())
  3690. );
  3691. }
  3692. void OnMenuCommand(IMenuItem* pitem)
  3693. {
  3694. switch (pitem->GetID()) {
  3695. case idmConfigure:
  3696. DoInputConfigure();
  3697. break;
  3698. case idmHelp:
  3699. CloseMenu();
  3700. OnHelp(true);
  3701. break;
  3702. case idmGameDetails:
  3703. CloseMenu();
  3704. OnGameState();
  3705. break;
  3706. case idmExitGame:
  3707. CloseMenu();
  3708. StartQuitMission();
  3709. break;
  3710. case idmExitApp:
  3711. CloseMenu();
  3712. StartClose();
  3713. break;
  3714. case idmTogglePosters:
  3715. TogglePosters();
  3716. break;
  3717. case idmToggleDebris:
  3718. ToggleDebris();
  3719. break;
  3720. case idmToggleStars:
  3721. ToggleStars();
  3722. break;
  3723. case idmToggleEnvironment:
  3724. ToggleEnvironment();
  3725. break;
  3726. case idmToggleRoundRadar:
  3727. ToggleRoundRadar ();
  3728. break;
  3729. case idmToggleCensorChats:
  3730. ToggleCensorChats ();
  3731. break;
  3732. case idmToggleStickyChase:
  3733. ToggleStickyChase ();
  3734. break;
  3735. case idmFilterChatsToAll:
  3736. ToggleFilterChatsToAll();
  3737. break;
  3738. case idmFilterQuickComms:
  3739. ToggleFilterQuickComms();
  3740. break;
  3741. case idmFilterLobbyChats:
  3742. ToggleFilterLobbyChats();
  3743. break;
  3744. case idmToggleLinearControls:
  3745. ToggleLinearControls ();
  3746. break;
  3747. case idmToggleLargeDeadZone:
  3748. ToggleLargeDeadZone();
  3749. break;
  3750. case idmToggleVirtualJoystick:
  3751. ToggleVirtualJoystick();
  3752. break;
  3753. case idmToggleFlipY:
  3754. ToggleFlipY();
  3755. break;
  3756. case idmToggleEnableFeedback:
  3757. ToggleEnableFeedback();
  3758. break;
  3759. case idmToggleStrobes:
  3760. ToggleStrobes();
  3761. break;
  3762. case idmToggleTrails:
  3763. ToggleTrails();
  3764. break;
  3765. case idmToggleBounds:
  3766. ToggleBounds();
  3767. break;
  3768. case idmToggleTransparentObjects:
  3769. ToggleTransparentObjects();
  3770. break;
  3771. case idmToggleSmoke:
  3772. ToggleSmoke();
  3773. break;
  3774. case idmToggleLensFlare:
  3775. ToggleLensFlare();
  3776. break;
  3777. case idmToggleBidirectionalLighting:
  3778. ToggleBidirectionalLighting();
  3779. break;
  3780. case idmToggleChatHistoryHUD:
  3781. ToggleChatHistoryHUD(); //Not persisted
  3782. break;
  3783. case idmToggleCenterHUD:
  3784. ToggleCenterHUD();
  3785. break;
  3786. case idmToggleTargetHUD:
  3787. ToggleTargetHUD();
  3788. break;
  3789. case idmStyleHUD:
  3790. CycleStyleHUD();
  3791. break;
  3792. case idmResetSound:
  3793. ResetSound();
  3794. break;
  3795. case idmSoundQuality:
  3796. SwitchSoundQuality();
  3797. break;
  3798. case idmSoundHardware:
  3799. ToggleSoundHardware();
  3800. break;
  3801. case idmToggleMusic:
  3802. ToggleMusic();
  3803. break;
  3804. case idmMusicVolumeUp:
  3805. AdjustMusicVolume(c_fVolumeDelta);
  3806. break;
  3807. case idmMusicVolumeDown:
  3808. AdjustMusicVolume(-c_fVolumeDelta);
  3809. break;
  3810. case idmSFXVolumeUp:
  3811. AdjustSFXVolume(c_fVolumeDelta);
  3812. break;
  3813. case idmSFXVolumeDown:
  3814. AdjustSFXVolume(-c_fVolumeDelta);
  3815. break;
  3816. case idmVoiceOverVolumeUp:
  3817. AdjustVoiceOverVolume(c_fVolumeDelta);
  3818. break;
  3819. case idmVoiceOverVolumeDown:
  3820. AdjustVoiceOverVolume(-c_fVolumeDelta);
  3821. break;
  3822. }
  3823. }
  3824. void SetJiggle(float jiggle)
  3825. {
  3826. m_cameraControl.SetJiggle(jiggle);
  3827. }
  3828. void OverrideCamera(Time now, ImodelIGC* pmodelTarget, bool bOverridePosition)
  3829. {
  3830. m_viewmode = vmOverride;
  3831. m_pwrapImageBackdrop->SetImage(trekClient.GetCluster() ? m_pgroupImage3D : Image::GetEmpty());
  3832. m_pscreenBackdrop = NULL;
  3833. m_pimageBackdrop = NULL;
  3834. AdjustCombatSize(vmOverride);
  3835. SetCameraMode(cmExternalOverride);
  3836. m_cameraControl.SetAnimatePosition(false);
  3837. m_cameraControl.SetAnimation(0.0f);
  3838. m_cameraControl.SetFOV(s_fDefaultFOV);
  3839. // always use the upright coordinate system as a starting point here
  3840. //m_cameraControl.SetOrientation (trekClient.GetShip()->GetSourceShip()->GetOrientation());
  3841. Orientation orthogonal (Vector (1.0f, 0.0f, 0.0f), Vector (0.0f, 0.0f, 1.0f));
  3842. m_cameraControl.SetOrientation (orthogonal);
  3843. m_timeOverrideStop = now + (bOverridePosition ? 5.0f : 3.0f);
  3844. m_bUseOverridePosition = bOverridePosition;
  3845. if (bOverridePosition)
  3846. {
  3847. IshipIGC* pshipSource = trekClient.GetShip()->GetSourceShip();
  3848. IclusterIGC* pcluster = pshipSource->GetCluster();
  3849. float offset = pshipSource->GetRadius() * 2.0f;
  3850. const Vector* pPositionTarget;
  3851. if (pmodelTarget && (pmodelTarget->GetCluster() == pcluster))
  3852. {
  3853. pPositionTarget = &(pmodelTarget->GetPosition());
  3854. if (pmodelTarget->GetObjectType() == OT_ship)
  3855. SetTarget(pmodelTarget, c_cidNone);
  3856. }
  3857. else
  3858. {
  3859. static Vector positionBfr;
  3860. positionBfr = pshipSource->GetPosition() + pshipSource->GetOrientation().GetBackward() * offset;
  3861. pPositionTarget = &positionBfr;
  3862. }
  3863. trekClient.GetShip()->SetCluster(NULL);
  3864. trekClient.SetViewCluster(pcluster);
  3865. TrackCamera(pshipSource->GetPosition(), *pPositionTarget,
  3866. offset * 3.0f);
  3867. }
  3868. else
  3869. {
  3870. m_positionOverrideTarget = pmodelTarget->GetPosition();
  3871. }
  3872. UpdateOverlayFlags();
  3873. }
  3874. void EndOverrideCamera(void)
  3875. {
  3876. if (m_bUseOverridePosition)
  3877. SetTarget(NULL, c_cidNone);
  3878. // end the overide camera's special status
  3879. m_cm = cmExternal;
  3880. if (trekClient.flyingF())
  3881. {
  3882. SetViewMode(vmCombat);
  3883. }
  3884. else if (screen() == ScreenIDCombat)
  3885. {
  3886. if (Training::IsTraining ())
  3887. {
  3888. // training missions will usually just put the ship back where
  3889. // it was and proceed. However, this call can signal us that
  3890. // the mission doesn't want to resume for some reason, so
  3891. // we stay in override mode if that happens. The mission *should*
  3892. // terminate when this happens, so it shouldn't last forever.
  3893. if (!Training::RestoreShip ())
  3894. {
  3895. m_cm = cmExternalOverride;
  3896. m_timeOverrideStop = m_timeOverrideStop + 10.0f;
  3897. }
  3898. }
  3899. else
  3900. {
  3901. SetViewMode(trekClient.GetShip()->IsGhost() ? vmCommand : vmHangar);
  3902. PositionCommandView(NULL, 0.0f);
  3903. StartSound(personalJumpSound);
  3904. assert (trekClient.GetShip()->IsGhost() || trekClient.GetViewCluster() == NULL);
  3905. }
  3906. }
  3907. }
  3908. void SetCameraMode(CameraMode cm)
  3909. {
  3910. // Ignore the set display mode.
  3911. if (m_cm == cmExternalOverride)
  3912. return;
  3913. // allow us to use the external chase as our default instead of the
  3914. // cockpit. This keeps you from having to hit F11 every time you
  3915. // launch or switch to another view. It's not fully tested, so I
  3916. // added a registry key switch. Set "PreferChaseView" in the registry
  3917. // to enable this feature.
  3918. if ((cm == cmCockpit) && m_bPreferChaseView)
  3919. cm = cmExternalChase;
  3920. if (m_cm != cm)
  3921. {
  3922. m_cmOld = m_cm;
  3923. m_cm = cm;
  3924. if (!CommandCamera(cm))
  3925. {
  3926. m_cameraControl.SetAnimation (InternalCamera(cm) ? 1.0f : 2.0f);
  3927. if (m_bLensFlare)
  3928. m_pwrapImageLensFlare->SetImage(m_pimageLensFlare);
  3929. }
  3930. // Any camera change restores the FOV
  3931. m_cameraControl.SetFOV(s_fDefaultFOV);
  3932. // adjust the display of damage effects for the camera view
  3933. ThingSitePrivate* pSite; CastTo(pSite, trekClient.GetShip ()->GetSourceShip()->GetThingSite());
  3934. TRef<ThingGeo> pThing = pSite ? pSite->GetThingGeo() : NULL;
  3935. // turn things on or off based on internal or external camera modes
  3936. if (InternalCamera(cm))
  3937. {
  3938. if (InternalCamera(m_cmOld))
  3939. {
  3940. // going from internal view to internal view
  3941. //Never animate the change in position
  3942. m_cameraControl.SetAnimatePosition(false);
  3943. }
  3944. if (pThing)
  3945. pThing->SetShowDamage (false);
  3946. }
  3947. else if (ExternalCamera (cm))
  3948. {
  3949. if (pThing)
  3950. pThing->SetShowDamage (true);
  3951. }
  3952. UpdateOverlayFlags();
  3953. // REVIEW: why not expose this in MDL?
  3954. if (GetOverlayFlags() & (ofInCockpit | ofInChase))
  3955. m_pradarImage->SetRadarLOD((RadarImage::RadarLOD)m_radarCockpit);
  3956. else if (GetOverlayFlags() & (ofInFlightCommand | ofInStationCommand))
  3957. m_pradarImage->SetRadarLOD((RadarImage::RadarLOD)m_radarCommand);
  3958. else
  3959. m_pradarImage->SetRadarLOD(RadarImage::c_rlNone);
  3960. }
  3961. }
  3962. ViewMode GetViewMode(void) const
  3963. {
  3964. return m_viewmode;
  3965. }
  3966. void SaveCombatSize()
  3967. {
  3968. if (m_bCombatSize) {
  3969. m_sizeCombat = GetWindowedSize();
  3970. m_sizeCombatFullscreen = GetFullscreenSize();
  3971. m_bCombatSize = false;
  3972. }
  3973. }
  3974. void AdjustCombatSize(ViewMode vm)
  3975. {
  3976. SaveCombatSize();
  3977. if (vm == vmLoadout) {
  3978. ZDebugOutput("SetViewMode : 800x600\n");
  3979. //
  3980. // Hangar or loadout switch to 8x6
  3981. //
  3982. Set3DAccelerationImportant(false);
  3983. SetWindowedSize(WinPoint(800, 600));
  3984. SetFullscreenSize(WinPoint(800, 600));
  3985. SetSizeable(false);
  3986. } else {
  3987. ZDebugOutput("SetViewMode : combat size\n");
  3988. //
  3989. // a 3D mode switch to the combat resolution
  3990. //
  3991. SetWindowedSize(m_sizeCombat);
  3992. SetFullscreenSize(m_sizeCombatFullscreen);
  3993. Set3DAccelerationImportant(true);
  3994. SetSizeable(true);
  3995. m_bCombatSize = true;
  3996. }
  3997. }
  3998. void SetViewMode(ViewMode vm, bool bForce = false)
  3999. {
  4000. ZDebugOutput("SetViewMode(" + ZString((int)vm) + ")\n");
  4001. //
  4002. // Ignore the set display mode.
  4003. //
  4004. if (m_cm == cmExternalOverride)
  4005. return;
  4006. //
  4007. // Adjust the window properties
  4008. //
  4009. if (bForce || vm != m_viewmode) {
  4010. AdjustCombatSize(vm);
  4011. }
  4012. //
  4013. // Switch the image
  4014. //
  4015. if (vm != m_viewmode)
  4016. {
  4017. debugf("Changing view mode from %d to %d\n", m_viewmode, vm);
  4018. m_viewmode = vm;
  4019. GetConsoleImage()->OnSwitchViewMode();
  4020. // destroy any open popups
  4021. if (!GetPopupContainer()->IsEmpty())
  4022. GetPopupContainer()->ClosePopup(NULL);
  4023. m_pmessageBox = NULL;
  4024. m_pmessageBoxLockdown = NULL;
  4025. GetWindow()->RestoreCursor();
  4026. // kill any mouse capture
  4027. m_pwrapImageTop->RemoveCapture();
  4028. switch (vm)
  4029. {
  4030. case vmHangar:
  4031. m_pscreenBackdrop = CreateHangarScreen(GetModeler(), "hangar");
  4032. {
  4033. m_pimageBackdrop =
  4034. new TranslateImage(
  4035. CreatePaneImage(
  4036. GetEngine(),
  4037. SurfaceType2D(),
  4038. false,
  4039. m_pscreenBackdrop->GetPane()
  4040. ),
  4041. Point(0,0)
  4042. );
  4043. }
  4044. if (m_pwrapImageBackdrop->GetImage() != m_pimageBackdrop)
  4045. {
  4046. trekClient.RequestViewCluster(NULL);
  4047. m_pwrapImageBackdrop->SetImage(m_pimageBackdrop);
  4048. m_pscreenBackdrop->GetPane()->UpdateLayout();
  4049. DoHitTest();
  4050. }
  4051. UpdateOverlayFlags();
  4052. SetCameraMode(cmCockpit);
  4053. m_pradarImage->SetRadarLOD(RadarImage::c_rlNone);
  4054. break;
  4055. case vmLoadout:
  4056. m_pscreenBackdrop = CreateLoadout(GetModeler(), GetWindow()->GetTime());
  4057. {
  4058. m_pimageBackdrop =
  4059. new TranslateImage(
  4060. CreatePaneImage(
  4061. GetEngine(),
  4062. SurfaceType3D() | SurfaceTypeZBuffer(),
  4063. false,
  4064. m_pscreenBackdrop->GetPane()
  4065. ),
  4066. Point(0,0)
  4067. );
  4068. }
  4069. if (m_pwrapImageBackdrop->GetImage() != m_pimageBackdrop)
  4070. {
  4071. trekClient.RequestViewCluster(NULL);
  4072. m_pwrapImageBackdrop->SetImage(m_pimageBackdrop);
  4073. m_pscreenBackdrop->GetPane()->UpdateLayout();
  4074. DoHitTest();
  4075. }
  4076. UpdateOverlayFlags();
  4077. SetCameraMode(cmCockpit);
  4078. m_pradarImage->SetRadarLOD(RadarImage::c_rlNone);
  4079. break;
  4080. case vmCommand:
  4081. SetCameraMode(m_cmPreviousCommand);
  4082. m_pwrapImageBackdrop->SetImage(trekClient.GetCluster() ? m_pgroupImage3D : Image::GetEmpty());
  4083. m_pscreenBackdrop = NULL;
  4084. m_pimageBackdrop = NULL;
  4085. break;
  4086. case vmCombat:
  4087. assert (trekClient.GetViewCluster() == NULL);
  4088. SetCameraMode(cmCockpit);
  4089. m_pwrapImageBackdrop->SetImage(trekClient.GetCluster() ? m_pgroupImage3D : Image::GetEmpty());
  4090. m_pscreenBackdrop = NULL;
  4091. m_pimageBackdrop = NULL;
  4092. break;
  4093. case vmOverride:
  4094. assert(false); // must call OverrideCamera()
  4095. break;
  4096. case vmUI:
  4097. assert(false); // must call screen()
  4098. break;
  4099. default:
  4100. assert(false);
  4101. break;
  4102. }
  4103. TurnOffOverlayFlags(c_omBanishablePanes);
  4104. UpdateOverlayFlags();
  4105. //
  4106. // if we are transitioning from the override camera or UI stuff,
  4107. // we may be locked down but not displaying the message box.
  4108. //
  4109. if (trekClient.IsLockedDown())
  4110. StartLockDown(trekClient.GetLockDownReason());
  4111. }
  4112. }
  4113. void EnableDisplacementCommandView(bool bEnable)
  4114. {
  4115. m_bEnableDisplacementCommandView = bEnable;
  4116. }
  4117. OverlayMask GetOverlayFlags() const
  4118. {
  4119. return m_voverlaymask[m_viewmode];
  4120. }
  4121. void SetOverlayFlags(OverlayMask om)
  4122. {
  4123. m_voverlaymask[m_viewmode] = om;
  4124. if (m_pconsoleImage)
  4125. m_pconsoleImage->SetOverlayFlags(om);
  4126. if (om & ofTeam)
  4127. m_pnumberTeamPaneCollapsed->SetValue(1.0f);
  4128. else if (om & ofExpandedTeam)
  4129. m_pnumberTeamPaneCollapsed->SetValue(0.0f);
  4130. if ((om & ofInvestment) == 0)
  4131. SetInvestAsteroid(0);
  4132. m_bOverlaysChanged = true;
  4133. }
  4134. // the normal set & clear were ambiguous
  4135. void TurnOnOverlayFlags(OverlayMask om)
  4136. {
  4137. SetOverlayFlags(m_voverlaymask[m_viewmode] | om);
  4138. }
  4139. void TurnOffOverlayFlags(OverlayMask om)
  4140. {
  4141. SetOverlayFlags(m_voverlaymask[m_viewmode] & ~om);
  4142. }
  4143. void ToggleOverlayFlags(OverlayMask om)
  4144. {
  4145. SetOverlayFlags(m_voverlaymask[m_viewmode] ^ om);
  4146. }
  4147. void ResetOverlayMask()
  4148. {
  4149. for (int i = 0; i < c_cViewModes; i++)
  4150. {
  4151. m_voverlaymask[i] = 0;
  4152. }
  4153. m_voverlaymask[vmCombat] = ofSectorPane;
  4154. m_voverlaymask[vmCommand] = ofSectorPane;
  4155. }
  4156. void CopyOverlayFlags(OverlayMask om, bool bSet)
  4157. {
  4158. if (bSet)
  4159. TurnOnOverlayFlags(om);
  4160. else
  4161. TurnOffOverlayFlags(om);
  4162. }
  4163. void UpdateOverlayFlags()
  4164. {
  4165. bool bInCommand = GetViewMode() == vmCommand;
  4166. bool bInFlight = trekClient.GetShip()->GetCluster() != NULL;
  4167. CopyOverlayFlags(ofInHangar, GetViewMode() == vmHangar);
  4168. CopyOverlayFlags(ofInLoadout, GetViewMode() == vmLoadout);
  4169. CopyOverlayFlags(ofInFlightCommand, bInFlight && bInCommand);
  4170. CopyOverlayFlags(ofInStationCommand, !bInFlight && bInCommand);
  4171. CopyOverlayFlags(ofInFlight, bInFlight);
  4172. CopyOverlayFlags(ofInCockpit, bInFlight && GetCameraMode() == cmCockpit);
  4173. CopyOverlayFlags(ofInChase, bInFlight && ((GetCameraMode() == cmExternalChase) || ((GetCameraMode() == cmExternalMissile) && (m_pmissileLast == 0))));
  4174. CopyOverlayFlags(ofCommandPane, bInCommand && !(GetOverlayFlags() & c_omBanishablePanes));
  4175. CopyOverlayFlags(ofGloatCam, GetCameraMode() == cmExternalOverride);
  4176. }
  4177. void TrackCamera(const Vector& position1,
  4178. const Vector& position2,
  4179. float length)
  4180. {
  4181. assert ((position2 - position1).LengthSquared() > 0.0f);
  4182. Vector axis = (position2 - position1).Normalize();
  4183. // GetOrthogonalVector does not return consistent results, which
  4184. // causes an unsightly jump when tracking the camera. I replaced it with
  4185. // some code that is biased toward the camera orientation when building a
  4186. // coordinate system. In an animation, this should choose an initial
  4187. // condition, then use that as a start point for the next frame. That
  4188. // should always give smooth results. BSW 2/2/2000
  4189. //Vector side = axis.GetOrthogonalVector();
  4190. Orientation orientation = m_cameraControl.GetOrientation();
  4191. Vector up = orientation.GetUp ();
  4192. float dot_product = up * axis;
  4193. if (fabsf (dot_product) > 0.95f)
  4194. {
  4195. up = orientation.GetRight ();
  4196. dot_product = up * axis;
  4197. if (fabsf (dot_product) > 0.95f)
  4198. up = orientation.GetRight ();
  4199. assert (up * axis < 0.95f);
  4200. }
  4201. Vector side = CrossProduct (axis, up);
  4202. m_cameraControl.SetPosition(position1 - axis * (length * 2.0f) + side * (length * 0.25f));
  4203. orientation.TurnTo(axis);
  4204. m_cameraControl.SetOrientation(orientation);
  4205. }
  4206. void ComputeExternalChase (IshipIGC* pShip, Orientation& orientationBfr, Vector& positionBfr, float& offset)
  4207. {
  4208. // get the ship orientation and position
  4209. const Orientation& shipOrientation = pShip->GetOrientation ();
  4210. const Vector& shipPosition = pShip->GetPosition();
  4211. // This part is for dealing with the zoomable camera
  4212. float fZoomDelta = s_fExternalViewDistanceMax - s_fExternalViewDistanceMin;
  4213. offset = (offset - s_fExternalViewDistanceMin) / (fZoomDelta * 0.01); // maps this into the range 0.0 ... 100.0
  4214. float fDelayTime = 0.05f + (offset * 0.00333);
  4215. // find the sample index to interpolate
  4216. int iSampleIndex = ((m_turnRateSampleIndex - 1) + ARRAY_OF_SAMPLES_SIZE) % ARRAY_OF_SAMPLES_SIZE;
  4217. while ((m_turnRateSamples[iSampleIndex].time + fDelayTime) > m_turnRateSamples[m_turnRateSampleIndex].time)
  4218. iSampleIndex = ((iSampleIndex - 1) + ARRAY_OF_SAMPLES_SIZE) % ARRAY_OF_SAMPLES_SIZE;
  4219. // find the amount to interpolate
  4220. float fDeltaTime = m_turnRateSamples[m_turnRateSampleIndex].time - (m_turnRateSamples[iSampleIndex].time + fDelayTime);
  4221. int iNextSampleIndex = (iSampleIndex + 1) % ARRAY_OF_SAMPLES_SIZE;
  4222. float fIntervalSize = m_turnRateSamples[iNextSampleIndex].time - m_turnRateSamples[iSampleIndex].time;
  4223. float fInterpolant = 1.0f - (fDeltaTime / fIntervalSize);
  4224. // compute the angular displacements
  4225. float fYawDisplacement = 0.0f;
  4226. float fPitchDisplacement = 0.0f;
  4227. float fRollDisplacement = 0.0f;
  4228. float fPreviousYawRate = Interpolate (m_turnRateSamples[iNextSampleIndex].fTurnRate[c_axisYaw], m_turnRateSamples[iSampleIndex].fTurnRate[c_axisYaw], fInterpolant);
  4229. float fPreviousPitchRate = Interpolate (m_turnRateSamples[iNextSampleIndex].fTurnRate[c_axisPitch], m_turnRateSamples[iSampleIndex].fTurnRate[c_axisPitch], fInterpolant);
  4230. float fPreviousRollRate = Interpolate (m_turnRateSamples[iNextSampleIndex].fTurnRate[c_axisRoll], m_turnRateSamples[iSampleIndex].fTurnRate[c_axisRoll], fInterpolant);
  4231. float fTimeInterval = fInterpolant * fIntervalSize * 0.5f;
  4232. while (iNextSampleIndex != m_turnRateSampleIndex)
  4233. {
  4234. fYawDisplacement += (fPreviousYawRate + m_turnRateSamples[iNextSampleIndex].fTurnRate[c_axisYaw]) * fTimeInterval;
  4235. fPreviousYawRate = m_turnRateSamples[iNextSampleIndex].fTurnRate[c_axisYaw];
  4236. fPitchDisplacement += (fPreviousPitchRate + m_turnRateSamples[iNextSampleIndex].fTurnRate[c_axisPitch]) * fTimeInterval;
  4237. fPreviousPitchRate = m_turnRateSamples[iNextSampleIndex].fTurnRate[c_axisPitch];
  4238. fRollDisplacement += (fPreviousRollRate + m_turnRateSamples[iNextSampleIndex].fTurnRate[c_axisRoll]) * fTimeInterval;
  4239. fPreviousRollRate = m_turnRateSamples[iNextSampleIndex].fTurnRate[c_axisRoll];
  4240. Time oldTime = m_turnRateSamples[iNextSampleIndex].time;
  4241. iNextSampleIndex = (iNextSampleIndex + 1) % ARRAY_OF_SAMPLES_SIZE;
  4242. fTimeInterval = (m_turnRateSamples[iNextSampleIndex].time - oldTime) * 0.5f;
  4243. }
  4244. fYawDisplacement += (fPreviousYawRate + m_turnRateSamples[iNextSampleIndex].fTurnRate[c_axisYaw]) * fTimeInterval;
  4245. fPitchDisplacement += (fPreviousPitchRate + m_turnRateSamples[iNextSampleIndex].fTurnRate[c_axisPitch]) * fTimeInterval;
  4246. fRollDisplacement += (fPreviousRollRate + m_turnRateSamples[iNextSampleIndex].fTurnRate[c_axisRoll]) * fTimeInterval;
  4247. // Compute orientation matrix from angular displacements
  4248. orientationBfr = shipOrientation;
  4249. orientationBfr.Roll (-fRollDisplacement);
  4250. orientationBfr.Pitch (fPitchDisplacement); // not negated, because it is already backwards for some reason
  4251. orientationBfr.Yaw (-fYawDisplacement);
  4252. // compute vector scaling quantities
  4253. float fRadius = pShip->GetHullType()->GetLength();
  4254. float fMaxVelocity = pShip->GetHullType()->GetMaxSpeed ();
  4255. Vector velocityVector = pShip->GetVelocity ();
  4256. float fVelocity = velocityVector.Length ();
  4257. float fFractionMaxVelocity = fVelocity / fMaxVelocity;
  4258. if (fVelocity > 0.0f)
  4259. {
  4260. // this computes a proper multiplier for the scalar regardless of what
  4261. // direction the ship is travelling with respect to its orientation
  4262. velocityVector /= fVelocity;
  4263. float fVelocityScalar = velocityVector * shipOrientation.GetForward ();
  4264. fVelocity *= (fVelocityScalar < 0.0f) ? (fVelocityScalar * 0.5f) : fVelocityScalar;
  4265. }
  4266. float fFractionMaxForwardVelocity = fVelocity / fMaxVelocity; // range 0..1
  4267. // compute vector offset quantities
  4268. float fCurrentVelocityOffset = fRadius * -0.5f * fFractionMaxVelocity; // half the radius times the fraction of max velocity
  4269. float fOldForwardVelocityOffset = fRadius * fFractionMaxForwardVelocity; // range of the radius * (0 .. 1)
  4270. float fOldUpOffset = fRadius * 0.3333f; // one quarter of the radius
  4271. float fCurrentOrientationOffset = offset * 0.5f; // range 0 .. 50
  4272. float fOldOrientationOffset = (offset + 100.0f) * 0.5f; // range 50 .. 100
  4273. // compute orientations taking into account the POV (the joystick hat control)
  4274. const Orientation& headOrientation = m_cameraControl.GetHeadOrientation();
  4275. Orientation currentLookOrientation = headOrientation * shipOrientation;
  4276. Orientation oldLookOrientation = headOrientation * orientationBfr;
  4277. // We compute a new location for the camera by combining an offset
  4278. // along the old forward vector, an offset along the new forward
  4279. // vector, an offset along the actual velocity vector, and a bit
  4280. // of up offset so you can see what's on the other side of the ship.
  4281. positionBfr = shipPosition
  4282. + (orientationBfr.GetUp () * fOldUpOffset)
  4283. + (orientationBfr.GetBackward () * fOldForwardVelocityOffset)
  4284. + (velocityVector * fCurrentVelocityOffset)
  4285. + (currentLookOrientation.GetBackward () * fCurrentOrientationOffset)
  4286. + (oldLookOrientation.GetBackward () * fOldOrientationOffset)
  4287. ;
  4288. // don't let the camera mode add an additional offset later
  4289. offset = 0.0f;
  4290. }
  4291. void UpdateCamera(float dt)
  4292. {
  4293. if (trekClient.GetCluster())
  4294. {
  4295. bool bJiggle = false;
  4296. assert (trekClient.GetShip()->GetBaseHullType() || trekClient.GetShip()->GetParentShip());
  4297. IshipIGC* pshipSource = trekClient.GetShip()->GetSourceShip();
  4298. const Orientation& shipOrientation = pshipSource->GetOrientation();
  4299. const Orientation* pMyOrientation;
  4300. //Orientation orientationBfr;
  4301. float myRadius = pshipSource->GetRadius();
  4302. const Vector& myPosition = pshipSource->GetPosition();
  4303. // fill in samples for chase view
  4304. m_turnRateSampleIndex = (m_turnRateSampleIndex + 1) % ARRAY_OF_SAMPLES_SIZE;
  4305. m_turnRateSamples[m_turnRateSampleIndex].fTurnRate[c_axisYaw] = pshipSource->GetCurrentTurnRate (c_axisYaw);
  4306. m_turnRateSamples[m_turnRateSampleIndex].fTurnRate[c_axisPitch] = pshipSource->GetCurrentTurnRate (c_axisPitch);
  4307. m_turnRateSamples[m_turnRateSampleIndex].fTurnRate[c_axisRoll] = pshipSource->GetCurrentTurnRate (c_axisRoll);
  4308. m_turnRateSamples[m_turnRateSampleIndex].time = trekClient.GetCore()->GetLastUpdate ();
  4309. if (InternalCamera(m_cm))
  4310. {
  4311. bJiggle = true;
  4312. const Vector* poffset;
  4313. if (pshipSource != trekClient.GetShip())
  4314. {
  4315. assert (trekClient.GetShip()->GetParentShip() != NULL);
  4316. Mount turretID = trekClient.GetShip()->GetTurretID();
  4317. if (turretID != NA)
  4318. {
  4319. //Turret orientation always mirrors the orientation of the source ship
  4320. const Orientation& clientOrientation = trekClient.GetShip()->GetOrientation();
  4321. /*
  4322. if (m_cameraControl.GetAnimation() == 0.0f)
  4323. {
  4324. Orientation oTurret = pshipSource->GetHullType()->GetWeaponOrientation(turretID) *
  4325. shipOrientation;
  4326. m_pmtTurret->SetValue(Matrix(oTurret, Vector::GetZero(), 1.0f));
  4327. //m_pwrapImageTurret->SetImage(m_pimageTurret);
  4328. //m_pcameraTurret->SetOrientation(m_cameraControl.GetHeadOrientation() * clientOrientation);
  4329. }
  4330. else
  4331. {
  4332. //m_pwrapImageTurret->SetImage(Image::GetEmpty());
  4333. }
  4334. */
  4335. /* NYI gun orientation depends on parent ship orientation
  4336. Orientation oTurret = pshipSource->GetHullType()->GetWeaponOrientation(turretID) *
  4337. shipOrientation;
  4338. orientationBfr = clientOrientation * oTurret;
  4339. pMyOrientation = &orientationBfr;
  4340. */
  4341. pMyOrientation = &clientOrientation;
  4342. poffset = &(pshipSource->GetHullType()->GetWeaponPosition(turretID));
  4343. }
  4344. else
  4345. {
  4346. pMyOrientation = &shipOrientation;
  4347. poffset = &(pshipSource->GetHullType()->GetCockpit());
  4348. }
  4349. }
  4350. else
  4351. {
  4352. pMyOrientation = &shipOrientation;
  4353. poffset = &(pshipSource->GetHullType()->GetCockpit());
  4354. /*if (m_cameraControl.GetAnimation() == 0.0f)
  4355. {
  4356. m_pcameraTurret->SetOrientation(m_cameraControl.GetHeadOrientation());
  4357. }
  4358. */
  4359. }
  4360. Vector p = myPosition + *poffset * shipOrientation;
  4361. m_cameraControl.SetPosition(p); //Do not override the existing animation
  4362. m_cameraControl.SetOrientation(*pMyOrientation);
  4363. }
  4364. else
  4365. {
  4366. //m_pwrapImageTurret->SetImage(Image::GetEmpty());
  4367. if (CommandCamera(m_cm))
  4368. {
  4369. UpdateCommandView();
  4370. }
  4371. else
  4372. {
  4373. assert (ExternalCamera(m_cm));
  4374. Orientation orientationBfr;
  4375. Vector positionBfr;
  4376. const Orientation* pOrientation;
  4377. const Vector* pPosition;
  4378. float offset = m_distanceExternalCamera;
  4379. switch (m_cm)
  4380. {
  4381. case cmExternalTarget:
  4382. {
  4383. ImodelIGC* pmodelTarget = GetCurrentTarget();
  4384. if (pmodelTarget)
  4385. {
  4386. {
  4387. float fMin = 5.0f + 2.0f * pmodelTarget->GetRadius();
  4388. if (offset < fMin)
  4389. offset = m_distanceExternalCamera = fMin;
  4390. }
  4391. pPosition = &(pmodelTarget->GetPosition());
  4392. pOrientation = &m_orientationExternalCamera;
  4393. break;
  4394. }
  4395. }
  4396. //No break
  4397. case cmExternal:
  4398. {
  4399. {
  4400. float fMin = 5.0f + 2.0f * pshipSource->GetRadius();
  4401. if (offset < fMin)
  4402. offset = m_distanceExternalCamera = fMin;
  4403. }
  4404. pPosition = &myPosition;
  4405. pOrientation = &m_orientationExternalCamera;
  4406. }
  4407. break;
  4408. case cmExternalChase:
  4409. {
  4410. ComputeExternalChase (pshipSource, orientationBfr, positionBfr, offset);
  4411. pOrientation = &orientationBfr;
  4412. pPosition = &(positionBfr);
  4413. }
  4414. break;
  4415. case cmExternalFlyBy:
  4416. {
  4417. //Position the camera so that both the target and the player are in view
  4418. //Basic algorithm:
  4419. //Aim the camera at the midpoint, back far enough so both are in view
  4420. ImodelIGC* pmodelTarget = GetCurrentTarget();
  4421. if (pmodelTarget != NULL)
  4422. {
  4423. const Vector& targetPosition = pmodelTarget->GetPosition();
  4424. pPosition = &positionBfr;
  4425. pOrientation = &m_orientationExternalCamera;
  4426. positionBfr = (0.5f * (targetPosition + myPosition));
  4427. const Vector& backward = pOrientation->GetBackward();
  4428. //Now how far back to we have to move the camera to get both in view
  4429. float dTarget;
  4430. {
  4431. Vector delta = targetPosition - positionBfr;
  4432. //Find the distance the target is along the forward vector
  4433. float dBackward = delta * backward;
  4434. //Find the distance the target is perpendicular to the forward vector
  4435. float dSide = (float)sqrt(delta.LengthSquared() + dBackward * dBackward);
  4436. dTarget = dSide * 3.0f + dBackward; //5.0 == fudge factor based on field of view
  4437. }
  4438. float dMe;
  4439. {
  4440. Vector delta = myPosition - positionBfr;
  4441. float dBackward = delta * backward;
  4442. float dSide = (float)sqrt(delta.LengthSquared() + dBackward * dBackward);
  4443. dMe = dSide * 3.0f + dBackward;
  4444. }
  4445. offset = (1.25f * ((dTarget > dMe) ? dTarget : dMe));
  4446. }
  4447. else
  4448. {
  4449. //Degenerate case ... treat as external chase
  4450. pPosition = &myPosition;
  4451. pOrientation = &m_orientationExternalCamera;
  4452. }
  4453. }
  4454. break;
  4455. case cmExternalOrbit:
  4456. {
  4457. m_orientationExternalCamera.Pitch(dt * 0.35f);
  4458. m_orientationExternalCamera.Yaw(dt * 0.2f);
  4459. m_orientationExternalCamera.Roll(dt * 0.5f);
  4460. pPosition = &myPosition;
  4461. pOrientation = &m_orientationExternalCamera;
  4462. offset = 5.0f + 2.5f * pshipSource->GetHullType()->GetLength();
  4463. }
  4464. break;
  4465. case cmExternalOverride:
  4466. {
  4467. if (!m_bUseOverridePosition)
  4468. TrackCamera(myPosition, m_positionOverrideTarget,
  4469. pshipSource->GetRadius() * 3.0f);
  4470. offset = -1.0f;
  4471. }
  4472. break;
  4473. case cmExternalStation:
  4474. {
  4475. ImodelIGC* myTarget = GetCurrentTarget();
  4476. if ((myTarget != NULL) &&
  4477. (myTarget != pshipSource) &&
  4478. (pshipSource->GetCluster() == myTarget->GetCluster()) &&
  4479. (myTarget->GetHitTest() != NULL) &&
  4480. pshipSource->CanSee(myTarget))
  4481. {
  4482. pPosition = &myPosition;
  4483. pOrientation = &m_orientationExternalCamera;
  4484. offset = 5.0f + pshipSource->GetRadius() * 2.5f;
  4485. TrackCamera (myPosition, myTarget->GetPosition(), offset);
  4486. offset = -1.0f;
  4487. }
  4488. else
  4489. {
  4490. // no target, or it wasn't visible...
  4491. // so use external chase view
  4492. ComputeExternalChase (pshipSource, orientationBfr, positionBfr, offset);
  4493. pOrientation = &orientationBfr;
  4494. pPosition = &(positionBfr);
  4495. // and should we switch back to cockpit?
  4496. }
  4497. }
  4498. break;
  4499. case cmExternalMissile:
  4500. {
  4501. ImissileIGC* pmissile = pshipSource->GetLastMissileFired();
  4502. if (pmissile != m_pmissileLast)
  4503. {
  4504. m_cmOld = cmExternalMissile; //Hack: prevent anything weird on the animated transition to the missile
  4505. m_cameraControl.SetOrientation (pshipSource->GetOrientation ());
  4506. m_cameraControl.SetAnimation(1.0f); //Force an animation to the new missile/ship position
  4507. m_pmissileLast = pmissile;
  4508. UpdateOverlayFlags ();
  4509. }
  4510. if (pmissile)
  4511. {
  4512. ImodelIGC* pTarget = pmissile->GetTarget ();
  4513. if (pTarget && pTarget->GetMission ())
  4514. // if the missile has a valid target, we use the tracking camera
  4515. TrackCamera (pmissile->GetPosition (), pTarget->GetPosition(), pmissile->GetRadius () * 3.0f);
  4516. else
  4517. // otherwise track the missile and the ship it was fired from
  4518. TrackCamera (pmissile->GetPosition (), pshipSource->GetPosition(), pmissile->GetRadius () * 3.0f);
  4519. offset = -1.0f;
  4520. }
  4521. else
  4522. {
  4523. // No missile ... treat as a chase view
  4524. ComputeExternalChase (pshipSource, orientationBfr, positionBfr, offset);
  4525. pOrientation = &orientationBfr;
  4526. pPosition = &(positionBfr);
  4527. // and check to see if we are out of missiles, just for the heck of it
  4528. // and switch back to cockpit mode if we are?
  4529. }
  4530. }
  4531. break;
  4532. default:
  4533. {
  4534. //Some unsupprted mode ... treat as external
  4535. pPosition = &myPosition;
  4536. pOrientation = &m_orientationExternalCamera;
  4537. }
  4538. }
  4539. if (offset >= 0.0f)
  4540. {
  4541. m_cameraControl.SetPosition(offset == 0.0f
  4542. ? *pPosition
  4543. : (*pPosition + offset * pOrientation->GetBackward()));
  4544. m_cameraControl.SetOrientation(*pOrientation);
  4545. }
  4546. }
  4547. }
  4548. bool bAnimating = m_cameraControl.Apply(dt, bJiggle, m_pboolTargetHUD->GetValue());
  4549. m_pCommandVisibleGeo->SetVisible(m_bCommandGrid || CommandCamera(m_cm) ||
  4550. (bAnimating && CommandCamera(m_cmOld)));
  4551. {
  4552. bool v = !(InternalCamera(m_cm) &&
  4553. ((!bAnimating) || InternalCamera(m_cmOld)));
  4554. pshipSource->SetVisibleF(v);
  4555. }
  4556. m_pmuzzleFlareImage->SetVisible(!bAnimating);
  4557. }
  4558. }
  4559. void AddMuzzleFlare(const Vector& vecDirection, float duration)
  4560. {
  4561. /* , doesn't work
  4562. if (vecDirection.LengthSquared() != 0) {
  4563. Point pointNDC;
  4564. if (m_pcamera->TransformEyeToNDC(vecDirection, pointNDC)) {
  4565. m_pmuzzleFlareImage->AddFlare(pointNDC, duration);
  4566. }
  4567. }
  4568. */
  4569. }
  4570. //////////////////////////////////////////////////////////////////////////////
  4571. //
  4572. //
  4573. //
  4574. //////////////////////////////////////////////////////////////////////////////
  4575. ZString GetFPSString(float fps, float mspf, Context* pcontext)
  4576. {
  4577. ZString strPosition;
  4578. if (g_pzfFrameDump && g_pzfFrameDump->IsValid())
  4579. {
  4580. ZString str = ZString((int)mspf) + "," + ZString((int)fps) + ",";
  4581. int i;
  4582. for (i=0; i<7; i++)
  4583. str += ZString(g_fdInfo.objects_drawn[i]) + ",";
  4584. for (i=0; i<7; i++)
  4585. str += ZString(g_fdInfo.objects_insector[i]) + ",";
  4586. str += ZString(pcontext->GetPerformanceCounter(CounterTriangles)) + ",";
  4587. str += ZString(pcontext->GetPerformanceCounter(CounterDrawStrings)) + ",";
  4588. str += ZString(pcontext->GetPerformanceCounter(CounterDrawStringChars)) + "\n";
  4589. g_pzfFrameDump->Write(str);
  4590. }
  4591. if (trekClient.flyingF()) {
  4592. const Vector& myPosition = trekClient.GetShip()->GetPosition();
  4593. strPosition =
  4594. " pos("
  4595. + ZString((int)myPosition.X()) + ","
  4596. + ZString((int)myPosition.Y()) + ","
  4597. + ZString((int)myPosition.Z()) + ")";
  4598. } else {
  4599. strPosition = " pos: (Dead)";
  4600. }
  4601. /*
  4602. ZString str;
  4603. str += (m_pwrapGeoDebris->GetGeo() != Geo::GetEmpty()) ? "D" : "d";
  4604. str += (m_pwrapImageStars->GetImage() != Image::GetEmpty()) ? "S" : "s";
  4605. str += (m_pwrapImagePosters->GetImage() != Image::GetEmpty()) ? "N" : "n";
  4606. str += (m_pwrapImageScene->GetImage() != Image::GetEmpty()) ? "3" : "*";
  4607. str += (m_pwrapImageHudGroup->GetImage() != Image::GetEmpty()) ? "H" : "h";
  4608. str += m_bShowMeteors ? "M" : "m";
  4609. str += m_bShowStations ? "S" : "s";
  4610. str += m_bShowProjectiles ? "P" : "p";
  4611. str += m_bShowAlephs ? "A" : "a";
  4612. str += m_bShowShips ? "F" : "f";
  4613. str += " ";
  4614. str += ThingGeo::GetShowLights() ? "S" : "s";
  4615. str += (m_pwrapImageLensFlare->GetImage() != Image::GetEmpty()) ? "F" : "f";
  4616. str += ThingGeo::GetShowTrails() ? "T" : "t";
  4617. str += (m_pwrapImageEnvironment->GetImage() != Image::GetEmpty()) ? "E" : "s";
  4618. */
  4619. int nNumPlayingSoundBuffers;
  4620. ZSucceeded(m_pSoundEngine->GetNumPlayingVirtualBuffers(nNumPlayingSoundBuffers));
  4621. char szRemoteAddress [16];
  4622. if (trekClient.m_fm.IsConnected())
  4623. trekClient.m_fm.GetIPAddress(*trekClient.m_fm.GetServerConnection(), szRemoteAddress);
  4624. else
  4625. lstrcpy(szRemoteAddress, "N/A");
  4626. return
  4627. "TC:" + ZString(ThingGeo::GetTrashCount())
  4628. + " CC:" + ZString(ThingGeo::GetCrashCount())
  4629. + " Server: " + ZString(szRemoteAddress)
  4630. + " fov: " + ((m_pcamera != NULL) ? ZString(DegreesFromRadians(m_pcamera->GetFOV())) : ZString())
  4631. + strPosition
  4632. + " lag: " + ZString((long) trekClient.m_serverLag)
  4633. + " ping: " + ZString(Time::Now() - trekClient.m_timeLastPing)
  4634. + " sync: " + ZString(int(100.0f * trekClient.m_sync))
  4635. + " snds: " + ZString(nNumPlayingSoundBuffers);
  4636. //return m_ptrekInput->GetFPSString();
  4637. }
  4638. void StartTraining (int iMissionIndex)
  4639. {
  4640. if (Training::StartMission (iMissionIndex))
  4641. {
  4642. screen(ScreenIDCombat);
  4643. if (m_cm == cmExternalOverride)
  4644. EndOverrideCamera();
  4645. Training::SetupShipAndCamera ();
  4646. m_cameraControl.SetAnimatePosition(false);
  4647. m_cameraControl.SetAnimation(0.0f);
  4648. // set the ship status
  4649. ShipStatus status;
  4650. status.SetHullID (static_cast<HullID> (trekClient.GetShip ()->GetHullType ()->GetObjectID ()));
  4651. status.SetSectorID (Training::GetStartSectorID ());
  4652. status.SetState (c_ssFlying);
  4653. status.SetDetected (false);
  4654. trekClient.GetPlayerInfo ()->SetShipStatus (status);
  4655. }
  4656. }
  4657. void OrientCommandView(void)
  4658. {
  4659. assert (CommandCamera(m_cm));
  4660. Orientation o;
  4661. if (m_cm == cmExternalCommandView34)
  4662. {
  4663. static const Vector forward(0.0f, sqrt2 / 2.0f, -sqrt2 / 2.0f); //Remember negated in set
  4664. static const Vector up(0.0f, sqrt2 / 2.0f, sqrt2 / 2.0f);
  4665. o.Set(forward, up);
  4666. }
  4667. else
  4668. {
  4669. assert (m_cm == cmExternalCommandViewTD);
  4670. o.Reset();
  4671. }
  4672. o.PostRoll(m_rollCommandCamera);
  4673. m_cameraControl.SetOrientation(o);
  4674. }
  4675. static void GetDefaultPosition(Vector* pposition, float* pradiusMin)
  4676. {
  4677. IstationIGC* pstation = trekClient.GetShip()->GetStation();
  4678. if (pstation)
  4679. {
  4680. if (pstation->GetCluster() == trekClient.GetCluster())
  4681. {
  4682. *pposition = pstation->GetPosition();
  4683. *pradiusMin = pstation->GetRadius() * 2.0f;
  4684. }
  4685. else
  4686. *pposition = Vector::GetZero();
  4687. }
  4688. else
  4689. {
  4690. IshipIGC* pship = trekClient.GetShip()->GetSourceShip();
  4691. assert (pship);
  4692. *pposition = pship->GetPosition();
  4693. *pradiusMin = 5.0f + pship->GetRadius() * 2.0f;
  4694. }
  4695. }
  4696. void PositionCommandView(const Vector* pposition, float dt)
  4697. {
  4698. if (CommandCamera(m_cm))
  4699. {
  4700. m_cameraControl.SetHeadOrientation(0.0f);
  4701. m_cameraControl.SetAnimation(dt);
  4702. OrientCommandView();
  4703. m_displacementCommandView = Vector::GetZero();
  4704. if (pposition)
  4705. {
  4706. m_positionCommandView = *pposition;
  4707. m_distanceCommandCamera = s_fCommandViewDistanceMax / 2.0f;
  4708. }
  4709. else
  4710. {
  4711. float fMin;
  4712. GetDefaultPosition(&m_positionCommandView, &fMin);
  4713. if (m_distanceCommandCamera < fMin)
  4714. m_distanceCommandCamera = fMin;
  4715. }
  4716. }
  4717. }
  4718. virtual UpdateCommandView(void)
  4719. {
  4720. assert (CommandCamera(m_cm));
  4721. IclusterIGC* pcluster = trekClient.GetCluster();
  4722. assert (pcluster);
  4723. if (!m_pconsoleImage->DrawSelectionBox())
  4724. {
  4725. float fMin = s_fCommandViewDistanceMin;
  4726. Vector positionTarget;
  4727. ImodelIGC* pmodelTarget = trekClient.GetShip()->GetCommandTarget(c_cmdCurrent);
  4728. if (pmodelTarget != NULL)
  4729. {
  4730. if (m_bTrackCommandView)
  4731. {
  4732. if (pmodelTarget->GetObjectType() == OT_ship)
  4733. pmodelTarget = ((IshipIGC*)pmodelTarget)->GetSourceShip();
  4734. if ((pmodelTarget->GetCluster() == pcluster) &&
  4735. trekClient.GetShip()->CanSee(pmodelTarget))
  4736. {
  4737. positionTarget = pmodelTarget->GetPosition();
  4738. fMin = 5.0f + pmodelTarget->GetRadius() * 2.0f;
  4739. if (m_distanceCommandCamera < fMin)
  4740. m_distanceCommandCamera = fMin;
  4741. m_positionCommandView = positionTarget +
  4742. m_displacementCommandView;
  4743. }
  4744. }
  4745. }
  4746. /*
  4747. else
  4748. {
  4749. GetDefaultPosition(&positionTarget, &fMin);
  4750. if (m_distanceCommandCamera < fMin)
  4751. m_distanceCommandCamera = fMin;
  4752. m_positionCommandView = positionTarget +
  4753. m_displacementCommandView;
  4754. }
  4755. */
  4756. {
  4757. //No matter what ... never allow displacement over twice the normal max
  4758. float l2 = m_positionCommandView.LengthSquared();
  4759. if (l2 > 4.0f * s_fCommandViewDisplacementMax * s_fCommandViewDisplacementMax)
  4760. m_positionCommandView *= 2.0f * s_fCommandViewDisplacementMax / float(sqrt(l2));
  4761. }
  4762. }
  4763. const Orientation& myOrientation = m_cameraControl.GetOrientation();
  4764. m_cameraControl.SetPosition(m_positionCommandView + (myOrientation.GetBackward() * m_distanceCommandCamera));
  4765. }
  4766. virtual void ChangeChatMessage(void)
  4767. {
  4768. }
  4769. /*
  4770. void OnLoadoutChanged(IpartIGC* ppart, LoadoutChange lc)
  4771. {
  4772. if (lc == c_lcHullChange)
  4773. {
  4774. IshipIGC* pship = trekClient.GetShip()->GetSourceShip();
  4775. if (pship->GetCluster() != NULL)
  4776. {
  4777. // Change in flight ... update the display mdl
  4778. // NYI assume we'll only get this when being placed in a life pod
  4779. if (m_pconsoleImage)
  4780. m_pconsoleImage->SetDisplayMDL(pship->GetHullType()->GetPilotHUDName());
  4781. }
  4782. }
  4783. else if (lc == c_lcTurretChange)
  4784. {
  4785. //player switched positions
  4786. IhullTypeIGC* pht = trekClient.GetShip()->GetSourceShip()->GetBaseHullType();
  4787. const char* pszDisplayMDL;
  4788. Mount turretID = trekClient.GetShip()->GetTurretID();
  4789. if (turretID == NA)
  4790. {
  4791. pszDisplayMDL = pht->GetObserverHUDName();
  4792. }
  4793. else
  4794. {
  4795. pszDisplayMDL = pht->GetHardpointData(turretID).hudName;
  4796. }
  4797. m_pconsoleImage->SetDisplayMDL(pszDisplayMDL);
  4798. }
  4799. }
  4800. */
  4801. void OnPaint(HDC hdc, const WinRect& rect)
  4802. {
  4803. }
  4804. float GetDeltaTime (void) const
  4805. {
  4806. return m_fDeltaTime;
  4807. }
  4808. void EvaluateFrame(Time time)
  4809. {
  4810. static bool bFirstFrame = true;
  4811. if (bFirstFrame)
  4812. {
  4813. // allow the splash screen to draw itself before we do
  4814. // any other initialization
  4815. bFirstFrame = false;
  4816. if (m_screen != ScreenIDCombat)
  4817. return;
  4818. }
  4819. float dtime = m_fDeltaTime = (float)(time - m_timeLastFrame);
  4820. ZAssert(dtime >= 0);
  4821. //
  4822. // Turn on the virtual joystick if the right conditions are met
  4823. //
  4824. {
  4825. bool bEnable =
  4826. m_bEnableVirtualJoystick
  4827. && GetFullscreen()
  4828. && GetPopupContainer()->IsEmpty()
  4829. && trekClient.flyingF()
  4830. && m_viewmode == vmCombat
  4831. && ((m_voverlaymask[m_viewmode] & c_omBanishablePanes) == 0);
  4832. m_pjoystickImage->SetEnabled(bEnable, bEnable);
  4833. SetMoveOnHide(!bEnable);
  4834. ShowCursor(!bEnable);
  4835. }
  4836. //
  4837. // Give the current screen a chance to do something on a per frame basis
  4838. //
  4839. if (m_pscreen) {
  4840. m_pscreen->OnFrame();
  4841. }
  4842. if (m_pscreenBackdrop) {
  4843. m_pscreenBackdrop->OnFrame();
  4844. }
  4845. CheckCountdownSound();
  4846. // Handle AutoDownload as needed, if we're not downloading, do nothing
  4847. if (trekClient.m_pAutoDownload)
  4848. {
  4849. if(GetWindow()->GetFullscreen())
  4850. trekClient.HandleAutoDownload(50); // give smaller time slice to allow for mouse to update
  4851. else
  4852. trekClient.HandleAutoDownload(500); // since the mouse is hardware in not full screen, the graphics engine doesn't need much CPU
  4853. }
  4854. // receive network messages
  4855. trekClient.m_lastUpdate = m_timeLastFrame;
  4856. trekClient.m_now = time;
  4857. if (FAILED(trekClient.ReceiveMessages()))
  4858. return; //bug out
  4859. // (CRC) Too much spew: ShouldBe ((!trekClient.m_serverOffsetValidF) || (fabs(Time::Now() - trekClient.m_timeLastPing) < 30.0f));
  4860. // Update the world
  4861. DoTrekUpdate(m_timeLastFrame, time, dtime, (m_frameID > 1));
  4862. // Update sounds
  4863. m_pSoundEngine->Update();
  4864. trekClient.UpdateAmbientSounds(DWORD(dtime * 1000));
  4865. UpdateMusic();
  4866. // Update the HUD Graphics
  4867. if ((m_cm == cmExternalOverride) && (m_timeOverrideStop < time))
  4868. {
  4869. // Back to a normal camera mode
  4870. EndOverrideCamera();
  4871. }
  4872. if (m_pconsoleImage != NULL && m_bOverlaysChanged)
  4873. {
  4874. UpdateOverlayFlags();
  4875. m_bOverlaysChanged = false;
  4876. }
  4877. // if this is not a training mission, the commands time out
  4878. if (m_timeRejectQueuedCommand < time)
  4879. RejectQueuedCommand(false);
  4880. IclusterIGC* pcluster = trekClient.GetCluster();
  4881. if (pcluster && m_screen == ScreenIDCombat)
  4882. {
  4883. assert (m_screen == ScreenIDCombat);
  4884. m_frameID++;
  4885. Rect rectImage = m_pviewport->GetViewRect()->GetValue();
  4886. //
  4887. // Move the camera
  4888. //
  4889. UpdateCamera(dtime);
  4890. //
  4891. // Update the screen positions and thrust values for all of the ships
  4892. // (and, while we are here, see if we can see it)
  4893. //
  4894. const ModelListIGC* models = pcluster->GetPickableModels();
  4895. assert (models);
  4896. double angleToPixels = double(rectImage.Size().X()) / double(m_cameraControl.GetFOV());
  4897. {
  4898. Point pointCenter = rectImage.Center();
  4899. rectImage.Offset(-pointCenter);
  4900. rectImage.Expand(-c_flBorderSide);
  4901. }
  4902. for (int i=0; i<7; i++)
  4903. {
  4904. g_fdInfo.objects_drawn[i] = 0;
  4905. g_fdInfo.objects_insector[i] = 0;
  4906. }
  4907. const Vector& positionCamera = m_cameraControl.GetPosition();
  4908. IshipIGC* pshipParent = trekClient.GetShip()->GetParentShip();
  4909. IshipIGC* pshipSource = pshipParent ? pshipParent : trekClient.GetShip();
  4910. // store the screen size for later use
  4911. #if 1
  4912. float fScreenSize = (rectImage.YMax() - rectImage.YMin()) * 0.48f; //NYI same constant as in radarimage.cpp
  4913. #else
  4914. float fScreenXSize = rectImage.XMax() - rectImage.XMin(),
  4915. fScreenYSize = rectImage.YMax() - rectImage.YMin(),
  4916. fScreenSize = sqrtf ((fScreenXSize * fScreenXSize) + (fScreenYSize * fScreenYSize)) * 0.5f;
  4917. #endif
  4918. ImodelIGC* pmodelTarget = trekClient.GetShip()->GetCommandTarget(c_cmdCurrent);
  4919. //
  4920. // Update the target geo
  4921. //
  4922. {
  4923. SetTargetGeo(pmodelTarget);
  4924. assert (m_pconsoleImage);
  4925. m_pconsoleImage->GetConsoleData()->SetTarget(pmodelTarget);
  4926. }
  4927. IsideIGC* psideMe;
  4928. bool bAnyEnemyShips;
  4929. if (pmodelTarget)
  4930. bAnyEnemyShips = true;
  4931. else
  4932. {
  4933. bAnyEnemyShips = false;
  4934. psideMe = trekClient.GetSide();
  4935. }
  4936. float zMin;
  4937. float zMax;
  4938. const Vector* pcameraPosition;
  4939. const Vector* pcameraBackward;
  4940. if (CommandCamera(m_cm))
  4941. {
  4942. pcameraPosition = &(m_cameraControl.GetPosition());
  4943. pcameraBackward = &(m_cameraControl.GetOrientation().GetBackward());
  4944. //Set the initial zMin & Max to whatever is needed to contain the command grid
  4945. //the grid is a disk of radius r in the XY plane
  4946. //Phi is the angle between the z-axis and the camera vector
  4947. double sinPhi = pcameraBackward->z; //Convenient
  4948. double cosTheta2 = 1.0 - sinPhi * sinPhi;
  4949. float r = cosTheta2 > 0.0f ? float(c_fCommandGridRadius * sqrt(cosTheta2)) : 0.0f;
  4950. float d = (*pcameraPosition * *pcameraBackward);
  4951. zMin = d-r;
  4952. zMax = d+r;
  4953. }
  4954. for (ModelLinkIGC* l = models->first(); (l != NULL); l = l->next())
  4955. {
  4956. ImodelIGC* pmodel = l->data();
  4957. // check to see if this is a ship
  4958. if (pmodel->GetObjectType () == OT_ship)
  4959. {
  4960. // it is a ship, let's check to see if it is approaching an aleph
  4961. IshipIGC* pship; CastTo(pship, pmodel);
  4962. ImodelIGC* pmodelAleph = FindTarget (pship, c_ttWarp | c_ttNearest | c_ttAllSides);
  4963. if (pmodelAleph)
  4964. {
  4965. Vector vecDelta = pmodelAleph->GetPosition() - pship->GetPosition();
  4966. float fRange = vecDelta.Length ();
  4967. float fRelativeVelocity = pship->GetVelocity () * (vecDelta / fRange);
  4968. if (fRelativeVelocity > 0.0f)
  4969. pship->GetThingSite ()->SetTimeUntilAleph (fRange / fRelativeVelocity);
  4970. else
  4971. pship->GetThingSite ()->SetTimeUntilAleph (-1.0f);
  4972. }
  4973. }
  4974. // do all other stuff
  4975. if (((pmodel != trekClient.GetShip()) &&
  4976. (pmodel != pshipParent)) || pmodel->GetVisibleF())
  4977. {
  4978. ObjectType type = pmodel->GetObjectType();
  4979. if ((type != OT_ship) || (((IshipIGC*)pmodel)->GetParentShip() == NULL))
  4980. {
  4981. ThingSitePrivate* psite; CastTo(psite, pmodel->GetThingSite());
  4982. unsigned char renderMask = c_ucRenderAll;
  4983. //
  4984. // Update screen positions for ships
  4985. //
  4986. {
  4987. float fScreenRadius;
  4988. float distanceToEdge;
  4989. Point pointScreenPosition;
  4990. unsigned char ucRadarState;
  4991. const Vector& positionModel = pmodel->GetPosition();
  4992. float radius = pmodel->GetRadius();
  4993. if (CommandCamera(m_cm))
  4994. {
  4995. float d = (*pcameraPosition - positionModel) * *pcameraBackward;
  4996. float z1 = d - radius;
  4997. if (z1 < zMin)
  4998. zMin = z1;
  4999. float z2 = d + radius;
  5000. if (z2 > zMax)
  5001. zMax = z2;
  5002. }
  5003. {
  5004. if (m_pcamera->TransformLocalToImage(positionModel, pointScreenPosition))
  5005. {
  5006. pointScreenPosition = rectImage.TransformNDCToImage(pointScreenPosition);
  5007. //
  5008. // Blip is in front of ship
  5009. //
  5010. if (m_bRoundRadar)
  5011. {
  5012. // lock the blip to a circle inscribed in the view rectangle
  5013. float fDistanceSquared = (pointScreenPosition.X () * pointScreenPosition.X ()) + (pointScreenPosition.Y () * pointScreenPosition.Y ());
  5014. if (fDistanceSquared >= (fScreenSize * fScreenSize))
  5015. {
  5016. ucRadarState = c_ucRadarOffScreen;
  5017. }
  5018. else
  5019. {
  5020. ucRadarState = c_ucRadarOnScreenLarge;
  5021. //Calculate this here, since we have it in a convenient form
  5022. distanceToEdge = fScreenSize - sqrtf(fDistanceSquared);
  5023. }
  5024. }
  5025. else
  5026. {
  5027. // lock the blip to the screen rectangle
  5028. ucRadarState = rectImage.Inside(pointScreenPosition) ? c_ucRadarOnScreenLarge : c_ucRadarOffScreen;
  5029. }
  5030. }
  5031. else
  5032. ucRadarState = c_ucRadarOffScreen;
  5033. }
  5034. if (ucRadarState == c_ucRadarOffScreen)
  5035. {
  5036. fScreenRadius = CmdViewMaxIconScreenSize;
  5037. distanceToEdge = 0.0f;
  5038. // Direction from eye to object
  5039. Vector vecDirection = m_pcamera->TransformLocalToEye(positionModel);
  5040. if (m_bRoundRadar)
  5041. {
  5042. //No gutter for now ... icons are pinned to the circle
  5043. float fLength = sqrtf(vecDirection.X() * vecDirection.X() +
  5044. vecDirection.Y() * vecDirection.Y());
  5045. float f = fScreenSize / fLength;
  5046. pointScreenPosition.SetX(vecDirection.X() * f);
  5047. pointScreenPosition.SetY(vecDirection.Y() * f);
  5048. }
  5049. else
  5050. {
  5051. //
  5052. // Get the components
  5053. //
  5054. float x = vecDirection.X();
  5055. float y = vecDirection.Y();
  5056. if (x == 0.0f)
  5057. {
  5058. y = (y <= 0.0f) ? rectImage.YMin() : rectImage.YMax();
  5059. }
  5060. else if (y == 0.0f)
  5061. {
  5062. x = (x <= 0.0f) ? rectImage.XMin() : rectImage.XMax();
  5063. }
  5064. else
  5065. {
  5066. float tX = ((x > 0.0f) ? rectImage.XMax() : rectImage.XMin()) / x;
  5067. float tY = ((y > 0.0f) ? rectImage.YMax() : rectImage.YMin()) / y;
  5068. float tMin = (tX < tY) ? tX : tY;
  5069. x *= tMin;
  5070. y *= tMin;
  5071. }
  5072. //No gutter for now ... icons are pinned to the edge of the screen
  5073. pointScreenPosition.SetX(x);
  5074. pointScreenPosition.SetY(y);
  5075. }
  5076. }
  5077. else
  5078. {
  5079. double sinAlpha = radius / (positionModel - positionCamera).Length();
  5080. fScreenRadius = (sinAlpha < 1.0)
  5081. ? float(angleToPixels * asin(sinAlpha)) //hack ... 480/(50*pi/180) * 2asin(r/d)
  5082. : 640.0f;
  5083. if (fScreenRadius < CmdViewMaxIconScreenSize)
  5084. {
  5085. if ((fScreenRadius < AnyViewMinRenderScreenSize) ||
  5086. CommandCamera(m_cm))
  5087. {
  5088. ucRadarState = c_ucRadarOnScreenSmall;
  5089. renderMask = c_ucRenderTrail;
  5090. }
  5091. fScreenRadius = CmdViewMaxIconScreenSize;
  5092. }
  5093. //distanceToEdge is calculated above for round radars
  5094. if (!m_bRoundRadar)
  5095. {
  5096. distanceToEdge = (pointScreenPosition.X() >= 0.0f)
  5097. ? (rectImage.XMax() - pointScreenPosition.X())
  5098. : (pointScreenPosition.X() - rectImage.XMin());
  5099. {
  5100. float d = (pointScreenPosition.Y() >= 0.0f)
  5101. ? (rectImage.YMax() - pointScreenPosition.Y())
  5102. : (pointScreenPosition.Y() - rectImage.YMin());
  5103. if (d < distanceToEdge)
  5104. distanceToEdge = d;
  5105. }
  5106. }
  5107. assert (distanceToEdge >= 0.0f);
  5108. }
  5109. g_fdInfo.objects_insector[type]++;
  5110. psite->UpdateScreenPosition(
  5111. pointScreenPosition,
  5112. fScreenRadius,
  5113. distanceToEdge,
  5114. ucRadarState
  5115. );
  5116. }
  5117. bool visibleF = pshipSource->CanSee(pmodel);
  5118. bool bSetVisible;
  5119. if (type == OT_ship)
  5120. {
  5121. IshipIGC* pship; CastTo(pship, pmodel);
  5122. int stateM = pship->GetStateM();
  5123. if (stateM & miningMaskIGC)
  5124. {
  5125. ImodelIGC* pmodel = pship->GetCommandTarget(c_cmdAccepted);
  5126. if (pmodel && (pmodel->GetObjectType() == OT_asteroid))
  5127. {
  5128. float minedOre = dtime * pship->GetSide()->GetGlobalAttributeSet().GetAttribute(c_gaMiningRate);
  5129. ((IasteroidIGC*)pmodel)->MineOre(minedOre);
  5130. }
  5131. }
  5132. if (!bAnyEnemyShips)
  5133. {
  5134. //We haven't spotted any enemy ships yet ... see if this is one.
  5135. bAnyEnemyShips = pship->GetSide() != psideMe;
  5136. }
  5137. bSetVisible = (pmodel != trekClient.GetShip()) &&
  5138. (pmodel != pshipParent);
  5139. TRef<ThingGeo> pthing = psite->GetThingGeo();
  5140. if (visibleF && pthing)
  5141. {
  5142. IafterburnerIGC* afterburner = (IafterburnerIGC*)(pship->GetMountedPart(ET_Afterburner, 0));
  5143. if (afterburner)
  5144. pthing->SetAfterburnerThrust(pship->GetOrientation().GetBackward(),
  5145. afterburner->GetPower());
  5146. else
  5147. pthing->SetAfterburnerThrust(Vector::GetZero(),
  5148. 0.0f);
  5149. pthing->SetThrust(0.5f * (pship->GetControls().jsValues[3] + 1));
  5150. if (stateM & miningMaskIGC)
  5151. psite->ActivateBolt();
  5152. else
  5153. psite->DeactivateBolt();
  5154. }
  5155. else
  5156. pthing->SetAfterburnerThrust(Vector::GetZero(), 0.0f);
  5157. }
  5158. else
  5159. bSetVisible = true;
  5160. //Is the model visible?
  5161. if (bSetVisible)
  5162. {
  5163. switch (type)
  5164. {
  5165. case OT_asteroid:
  5166. visibleF &= m_bShowMeteors;
  5167. break;
  5168. case OT_station:
  5169. visibleF &= m_bShowStations;
  5170. break;
  5171. case OT_projectile:
  5172. visibleF &= m_bShowProjectiles;
  5173. break;
  5174. case OT_warp:
  5175. visibleF &= m_bShowAlephs;
  5176. break;
  5177. case OT_ship:
  5178. visibleF &= m_bShowShips;
  5179. }
  5180. pmodel->SetVisibleF(visibleF);
  5181. }
  5182. pmodel->SetRender(renderMask);
  5183. }
  5184. }
  5185. else
  5186. {
  5187. //Player's ship in a first person view
  5188. IshipIGC* pship; CastTo(pship, pmodel);
  5189. ThingSitePrivate* psite; CastTo(psite, pmodel->GetThingSite());
  5190. TRef<ThingGeo> pthing = psite->GetThingGeo();
  5191. if (pthing)
  5192. {
  5193. IafterburnerIGC* afterburner = (IafterburnerIGC*)(pship->GetMountedPart(ET_Afterburner, 0));
  5194. if (afterburner)
  5195. pthing->SetAfterburnerThrust(pship->GetOrientation().GetBackward(),
  5196. afterburner->GetPower());
  5197. else
  5198. pthing->SetAfterburnerThrust(Vector::GetZero(),
  5199. 0.0f);
  5200. }
  5201. }
  5202. }
  5203. if (CommandCamera(m_cm))
  5204. m_cameraControl.SetZClip(zMin < 5.0f ? 5.0f : zMin,
  5205. zMax);
  5206. else
  5207. m_cameraControl.SetZClip(5.0f, 10000.0f);
  5208. if ((pmodelTarget == NULL) && bAnyEnemyShips && (!Training::IsTraining ()))
  5209. {
  5210. //We have no target and there are enemy ships ... select an appropriate ship
  5211. const Vector& position = pshipSource->GetPosition();
  5212. ImodelIGC* m = FindTarget(pshipSource,
  5213. (c_ttShip | c_ttEnemy | c_ttNearest),
  5214. NULL,
  5215. pcluster,
  5216. &position, NULL, c_habmRescue);
  5217. if (m == NULL)
  5218. {
  5219. m = FindTarget(pshipSource,
  5220. (c_ttShip | c_ttEnemy | c_ttNearest),
  5221. NULL,
  5222. pcluster,
  5223. &position, NULL, c_habmMiner | c_habmBuilder);
  5224. if (m == NULL)
  5225. m = FindTarget(pshipSource,
  5226. (c_ttShip | c_ttEnemy | c_ttNearest),
  5227. NULL,
  5228. pcluster,
  5229. &position);
  5230. }
  5231. if (m)
  5232. SetTarget(m, c_cidDefault);
  5233. }
  5234. m_pnumberFlash->SetValue(GetFlash(time) ? 1.0f : 0.0f);
  5235. }
  5236. if (m_pconsoleImage)
  5237. m_pconsoleImage->Update(time);
  5238. m_timeLastFrame = time;
  5239. //
  5240. // Center the hangar bitmap if we are in the hangar
  5241. //
  5242. UpdateBackdropCentering();
  5243. //
  5244. // Update the countdown timer
  5245. //
  5246. UpdateGameStateContainer();
  5247. if (m_pgsc)
  5248. {
  5249. const MissionParams* pmp = trekClient.m_pCoreIGC->GetMissionParams();
  5250. float dt = time - pmp->timeStart;
  5251. if (pmp->IsCountdownGame())
  5252. {
  5253. //Countdown timer
  5254. m_pgsc->SetTimeRemaining(int(pmp->GetCountDownTime() - dt));
  5255. }
  5256. else
  5257. {
  5258. //Countup timer
  5259. m_pgsc->SetTimeElapsed(int(dt));
  5260. }
  5261. }
  5262. }
  5263. void OnEnterMission (void)
  5264. {
  5265. if (!(Training::IsTraining () || (Training::GetTrainingMissionID () == Training::c_TM_7_Live)))
  5266. {
  5267. Training::StartMission (0);
  5268. SetCluster(trekClient.GetShip()->GetCluster());
  5269. screen(ScreenIDCombat);
  5270. IstationIGC* pstation = trekClient.GetShip()->GetStation();
  5271. if (pstation)
  5272. trekClient.ReplaceLoadout(pstation);
  5273. }
  5274. }
  5275. void PlayFFEffect(ForceEffectID effectID, LONG lDirection = 0)
  5276. {
  5277. if (m_bEnableFeedback) {
  5278. m_ptrekInput->PlayFFEffect(effectID, lDirection);
  5279. }
  5280. }
  5281. void DoTrekUpdate(Time lastUpdate,
  5282. Time now,
  5283. float dt,
  5284. bool activeControlsF)
  5285. {
  5286. if (trekClient.GetCluster() && GetWindow()->screen() == ScreenIDCombat)
  5287. {
  5288. //For now, leave joystick specific code here.
  5289. //Only process joystick if we have focus
  5290. if (GetFocus())
  5291. {
  5292. bool bAllowKeyboardMovement = !m_pconsoleImage->IsComposing() && GetPopupContainer()->IsEmpty();
  5293. bool bNoCameraControl = NoCameraControl(m_cm);
  5294. if (trekClient.flyingF())
  5295. {
  5296. //
  5297. // Handle any joystick button commands
  5298. //
  5299. m_ptrekInput->GetButtonTrekKeys(this);
  5300. //Process joystick input for the player
  5301. //Carry over persistent bits
  5302. int buttonsM = trekClient.GetShip()->GetStateM() & (coastButtonIGC | cloakActiveIGC);
  5303. //Controls default to what the ship has now
  5304. JoystickResults js;
  5305. js.controls.jsValues[c_axisYaw] = js.controls.jsValues[c_axisPitch] = js.controls.jsValues[c_axisRoll] = 0.0f;
  5306. js.controls.jsValues[c_axisThrottle] = trekClient.GetShip()->GetControls().jsValues[c_axisThrottle];
  5307. bool fAutoPilot = trekClient.autoPilot();
  5308. if (!GetUI() && activeControlsF)
  5309. {
  5310. bool bControlsInUse = SenseJoystick(&js, bNoCameraControl, bAllowKeyboardMovement);
  5311. int oldButtonsM = buttonsM;
  5312. if (m_ptrekInput->IsTrekKeyDown(TK_ThrustLeft, bAllowKeyboardMovement))
  5313. buttonsM |= leftButtonIGC;
  5314. if (m_ptrekInput->IsTrekKeyDown(TK_ThrustRight, bAllowKeyboardMovement))
  5315. buttonsM |= rightButtonIGC;
  5316. if (m_ptrekInput->IsTrekKeyDown(TK_ThrustUp, bAllowKeyboardMovement))
  5317. buttonsM |= upButtonIGC;
  5318. if (m_ptrekInput->IsTrekKeyDown(TK_ThrustDown, bAllowKeyboardMovement))
  5319. buttonsM |= downButtonIGC;
  5320. if (m_ptrekInput->IsTrekKeyDown(TK_ThrustForward, bAllowKeyboardMovement))
  5321. buttonsM |= forwardButtonIGC;
  5322. if (m_ptrekInput->IsTrekKeyDown(TK_ThrustBackward, bAllowKeyboardMovement))
  5323. buttonsM |= backwardButtonIGC;
  5324. if (m_ptrekInput->IsTrekKeyDown(TK_FireBooster, bAllowKeyboardMovement))
  5325. buttonsM |= afterburnerButtonIGC;
  5326. if (fAutoPilot)
  5327. {
  5328. if (oldButtonsM != buttonsM)
  5329. bControlsInUse = true;
  5330. else
  5331. {
  5332. bControlsInUse = bControlsInUse ||
  5333. js.button1 || js.button2 || js.button3 || js.button4 || js.button5 || js.button6;
  5334. }
  5335. if (trekClient.bInitTrekJoyStick)
  5336. {
  5337. trekClient.trekJoyStick[0] = js.controls.jsValues[0];
  5338. trekClient.trekJoyStick[1] = js.controls.jsValues[1];
  5339. trekClient.trekJoyStick[2] = js.controls.jsValues[2];
  5340. trekClient.bInitTrekJoyStick = false;
  5341. }
  5342. else
  5343. {
  5344. const float c_fAutopilotDisengage = g_fJoystickDeadZone * 2.0f;
  5345. bControlsInUse = bControlsInUse ||
  5346. (js.controls.jsValues[c_axisYaw] - trekClient.trekJoyStick[c_axisYaw] < -c_fAutopilotDisengage) ||
  5347. (js.controls.jsValues[c_axisYaw] - trekClient.trekJoyStick[c_axisYaw] > c_fAutopilotDisengage) ||
  5348. (js.controls.jsValues[c_axisPitch] - trekClient.trekJoyStick[c_axisPitch] < -c_fAutopilotDisengage) ||
  5349. (js.controls.jsValues[c_axisPitch] - trekClient.trekJoyStick[c_axisPitch] > c_fAutopilotDisengage) ||
  5350. (js.controls.jsValues[c_axisRoll] - trekClient.trekJoyStick[c_axisRoll] < -c_fAutopilotDisengage) ||
  5351. (js.controls.jsValues[c_axisRoll] - trekClient.trekJoyStick[c_axisRoll] > c_fAutopilotDisengage);
  5352. }
  5353. if (bControlsInUse)
  5354. {
  5355. /*
  5356. if (now >= m_timeAutopilotWarning)
  5357. {
  5358. m_timeAutopilotWarning = now + 5.0f;
  5359. trekClient.PostText(true, "Hit P to disengage the autopilot");
  5360. }
  5361. */
  5362. trekClient.SetAutoPilot(false);
  5363. SwitchToJoyThrottle();
  5364. fAutoPilot = false;
  5365. trekClient.PlaySoundEffect(salAutopilotDisengageSound);
  5366. }
  5367. }
  5368. }
  5369. else
  5370. {
  5371. js.controls.Reset();
  5372. js.hat = 0;
  5373. js.button1 = js.button2 = js.button3 = js.button4 = js.button5 = js.button6 = 0x00;
  5374. }
  5375. IshipIGC* pshipParent = trekClient.GetShip()->GetParentShip();
  5376. if (fAutoPilot && (pshipParent == NULL))
  5377. {
  5378. js.controls = trekClient.GetShip()->GetControls();
  5379. // use the controls decided by autoPilot.Update()
  5380. buttonsM = trekClient.GetShip()->GetStateM();
  5381. // we want to poll the joystick, and ignore everything but the hat.
  5382. }
  5383. else // autoPilot doesn't need these
  5384. {
  5385. // Pay attention to the joystick buttons.
  5386. buttonsM |= (trekClient.m_selectedWeapon << selectedWeaponShiftIGC);
  5387. if (js.button1 & buttonDown)
  5388. buttonsM |= trekClient.fGroupFire
  5389. ? allWeaponsIGC
  5390. : oneWeaponIGC;
  5391. if (js.button2 & buttonDown)
  5392. buttonsM |= missileFireIGC;
  5393. if (js.button3 & buttonDown)
  5394. buttonsM |= afterburnerButtonIGC;
  5395. }
  5396. if (m_ptrekInput->IsTrekKeyDown(TK_DropMine, bAllowKeyboardMovement))
  5397. buttonsM |= mineFireIGC;
  5398. else
  5399. buttonsM &= ~mineFireIGC;
  5400. if (m_ptrekInput->IsTrekKeyDown(TK_DropChaff, bAllowKeyboardMovement))
  5401. buttonsM |= chaffFireIGC;
  5402. else
  5403. buttonsM &= ~chaffFireIGC;
  5404. // training mission hook
  5405. Training::ApproveControls (js.controls);
  5406. buttonsM = Training::ApproveActions (buttonsM);
  5407. // end training mission hook
  5408. if (m_cm == cmCockpit)
  5409. {
  5410. if (trekClient.GetShip()->GetTurretID() != NA)
  5411. {
  5412. float fov = (s_fMinFOV + 0.5f * (s_fMaxFOV - s_fMinFOV)) +
  5413. (0.5f * (s_fMaxFOV - s_fMinFOV)) * js.controls.jsValues[c_axisThrottle];
  5414. m_cameraControl.SetFOV(fov);
  5415. }
  5416. else
  5417. {
  5418. float fov = m_cameraControl.GetFOV();
  5419. if (m_ptrekInput->IsTrekKeyDown(TK_ZoomIn, true))
  5420. {
  5421. fov -= dt;
  5422. if (fov < s_fMinFOV)
  5423. fov = s_fMinFOV;
  5424. m_cameraControl.SetFOV(fov);
  5425. }
  5426. else if (m_ptrekInput->IsTrekKeyDown(TK_ZoomOut, true))
  5427. {
  5428. fov += dt;
  5429. if (fov > s_fMaxFOV)
  5430. fov = s_fMaxFOV;
  5431. m_cameraControl.SetFOV(fov);
  5432. }
  5433. if (trekClient.GetShip()->GetBaseHullType() != NULL)
  5434. {
  5435. //What is the maximum desired rate of turn for this field of view?
  5436. //Use the same calculation as for turrets.
  5437. //Keep in sync with wintrek.cpp's FOV by throttle
  5438. static const float c_minRate = RadiansFromDegrees(7.5f);
  5439. static const float c_maxRate = RadiansFromDegrees(75.0f);
  5440. float maxSlewRate = c_minRate +
  5441. (c_maxRate - c_minRate) * fov / s_fMaxFOV;
  5442. const IhullTypeIGC* pht = trekClient.GetShip()->GetHullType();
  5443. {
  5444. float pitch = pht->GetMaxTurnRate(c_axisPitch);
  5445. if (pitch > maxSlewRate)
  5446. js.controls.jsValues[c_axisPitch] *= maxSlewRate / pitch;
  5447. }
  5448. {
  5449. float yaw = pht->GetMaxTurnRate(c_axisYaw);
  5450. if (yaw > maxSlewRate)
  5451. js.controls.jsValues[c_axisYaw] *= maxSlewRate / yaw;
  5452. }
  5453. }
  5454. }
  5455. }
  5456. trekClient.GetShip()->SetControls(js.controls);
  5457. trekClient.GetShip()->SetStateBits(buttonsMaskIGC | weaponsMaskIGC | selectedWeaponMaskIGC |
  5458. missileFireIGC | mineFireIGC | chaffFireIGC, buttonsM);
  5459. if ((m_cm == cmCockpit) || (m_cm == cmExternalChase))
  5460. m_cameraControl.SetHeadOrientation(js.hat);
  5461. else
  5462. m_cameraControl.SetHeadOrientation(0.0f);
  5463. m_pplayerThrottle->SetValue(pshipParent
  5464. ? 0.0f
  5465. : ((buttonsM & (leftButtonIGC | rightButtonIGC | upButtonIGC | downButtonIGC |
  5466. forwardButtonIGC | backwardButtonIGC | afterburnerButtonIGC))
  5467. ? 1.0f
  5468. : (js.controls.jsValues[c_axisThrottle] * 0.5f + 0.5f)));
  5469. }
  5470. if (CommandCamera(m_cm) && m_bEnableDisplacementCommandView && !m_pconsoleImage->DrawSelectionBox())
  5471. {
  5472. float delta = dt * m_distanceCommandCamera;
  5473. float dRight = 0.0f;
  5474. float dUp = 0.0f;
  5475. Point point;
  5476. bool bInside;
  5477. Rect rectImage = GetScreenRectValue()->GetValue();
  5478. if (GetEngine()->IsFullscreen()) {
  5479. point = GetMousePosition();
  5480. point.SetY(GetScreenRectValue()->GetValue().YMax() - 1 - point.Y());
  5481. bInside = rectImage.Inside(point);
  5482. point = point - rectImage.Min();
  5483. } else {
  5484. WinPoint xy;
  5485. bInside = false;
  5486. if (GetCursorPos(&xy)) {
  5487. point = Point::Cast(ScreenToClient(xy));
  5488. bInside = rectImage.Inside(point);
  5489. point = point - rectImage.Min();
  5490. }
  5491. }
  5492. if (bInside) {
  5493. static const float gutter = 8.0f;
  5494. static const float maxGutter = 12.0f;
  5495. if (point.X() < gutter) {
  5496. dRight = delta * (point.X() - gutter) / maxGutter;
  5497. } else {
  5498. float x = rectImage.XSize() - point.X();
  5499. if (x < gutter) {
  5500. dRight = delta * (gutter - x) / maxGutter;
  5501. }
  5502. }
  5503. if (point.Y() < gutter) {
  5504. dUp = delta * (point.Y() - gutter) / maxGutter;
  5505. } else {
  5506. float y = rectImage.YSize() - point.Y();
  5507. if (y < gutter) {
  5508. dUp = delta * (gutter - y) / maxGutter;
  5509. }
  5510. }
  5511. }
  5512. // Cheat ... horizontal is always parallel to the plane
  5513. if (m_ptrekInput->IsTrekKeyDown(TK_YawLeft, bAllowKeyboardMovement))
  5514. {
  5515. dRight -= delta;
  5516. }
  5517. else if (m_ptrekInput->IsTrekKeyDown(TK_YawRight, bAllowKeyboardMovement))
  5518. {
  5519. dRight += delta;
  5520. }
  5521. if (m_ptrekInput->IsTrekKeyDown(TK_PitchUp, bAllowKeyboardMovement))
  5522. {
  5523. dUp -= delta;
  5524. }
  5525. else if (m_ptrekInput->IsTrekKeyDown(TK_PitchDown, bAllowKeyboardMovement))
  5526. {
  5527. dUp += delta;
  5528. }
  5529. if (m_ptrekInput->IsTrekKeyDown(TK_ZoomOut, bAllowKeyboardMovement))
  5530. {
  5531. m_distanceCommandCamera += delta * 2.0f;
  5532. if (m_distanceCommandCamera > s_fCommandViewDistanceMax)
  5533. m_distanceCommandCamera = s_fCommandViewDistanceMax;
  5534. }
  5535. else if (m_ptrekInput->IsTrekKeyDown(TK_ZoomIn, bAllowKeyboardMovement))
  5536. {
  5537. m_distanceCommandCamera -= delta * 2.0f;
  5538. if (m_distanceCommandCamera < s_fCommandViewDistanceMin)
  5539. m_distanceCommandCamera = s_fCommandViewDistanceMin;
  5540. }
  5541. if (m_ptrekInput->IsTrekKeyDown(TK_RollRight, bAllowKeyboardMovement))
  5542. {
  5543. m_rollCommandCamera += dt;
  5544. if (m_rollCommandCamera >= 2.0f * pi)
  5545. m_rollCommandCamera -= 2.0f * pi;
  5546. OrientCommandView();
  5547. }
  5548. else if (m_ptrekInput->IsTrekKeyDown(TK_RollLeft, bAllowKeyboardMovement))
  5549. {
  5550. m_rollCommandCamera -= dt;
  5551. if (m_distanceCommandCamera < 0.0f)
  5552. m_distanceCommandCamera += 2.0f * pi;
  5553. OrientCommandView();
  5554. }
  5555. if (dRight)
  5556. {
  5557. Vector v = m_cameraControl.GetOrientation().GetRight() * dRight;
  5558. m_displacementCommandView += v;
  5559. m_positionCommandView += v;
  5560. }
  5561. if (dUp)
  5562. {
  5563. Vector up = m_cameraControl.GetOrientation().GetUp();
  5564. up.z = 0.0f;
  5565. float l = (float)sqrt(up.x * up.x + up.y * up.y);
  5566. assert (l != 0.0f);
  5567. Vector v = up * (dUp / l);
  5568. m_displacementCommandView -= v;
  5569. m_positionCommandView -= v;
  5570. }
  5571. }
  5572. else if (!bNoCameraControl)
  5573. {
  5574. if (m_ptrekInput->IsTrekKeyDown(TK_PitchUp, bAllowKeyboardMovement))
  5575. m_orientationExternalCamera.Pitch(dt);
  5576. else if (m_ptrekInput->IsTrekKeyDown(TK_PitchDown, bAllowKeyboardMovement))
  5577. m_orientationExternalCamera.Pitch(-dt);
  5578. if (m_ptrekInput->IsTrekKeyDown(TK_YawLeft, bAllowKeyboardMovement))
  5579. m_orientationExternalCamera.Yaw(dt);
  5580. else if (m_ptrekInput->IsTrekKeyDown(TK_YawRight, bAllowKeyboardMovement))
  5581. m_orientationExternalCamera.Yaw(-dt);
  5582. if (m_ptrekInput->IsTrekKeyDown(TK_RollLeft, bAllowKeyboardMovement))
  5583. m_orientationExternalCamera.Roll(dt);
  5584. else if (m_ptrekInput->IsTrekKeyDown(TK_RollRight, bAllowKeyboardMovement))
  5585. m_orientationExternalCamera.Roll(-dt);
  5586. if (m_ptrekInput->IsTrekKeyDown(TK_ZoomOut, bAllowKeyboardMovement))
  5587. {
  5588. m_distanceExternalCamera += dt * m_distanceExternalCamera;
  5589. if (m_distanceExternalCamera > s_fExternalViewDistanceMax)
  5590. m_distanceExternalCamera = s_fExternalViewDistanceMax;
  5591. }
  5592. else if (m_ptrekInput->IsTrekKeyDown(TK_ZoomIn, bAllowKeyboardMovement))
  5593. {
  5594. m_distanceExternalCamera -= dt * m_distanceExternalCamera;
  5595. if (m_distanceExternalCamera < s_fExternalViewDistanceMin)
  5596. m_distanceExternalCamera = s_fExternalViewDistanceMin;
  5597. }
  5598. }
  5599. else if (m_cm == cmExternalChase)
  5600. {
  5601. if (m_ptrekInput->IsTrekKeyDown(TK_ZoomOut, bAllowKeyboardMovement))
  5602. {
  5603. m_distanceExternalCamera += dt * m_distanceExternalCamera;
  5604. if (m_distanceExternalCamera > s_fExternalViewDistanceMax)
  5605. m_distanceExternalCamera = s_fExternalViewDistanceMax;
  5606. }
  5607. else if (m_ptrekInput->IsTrekKeyDown(TK_ZoomIn, bAllowKeyboardMovement))
  5608. {
  5609. m_distanceExternalCamera -= dt * m_distanceExternalCamera;
  5610. if (m_distanceExternalCamera < s_fExternalViewDistanceMin)
  5611. m_distanceExternalCamera = s_fExternalViewDistanceMin;
  5612. }
  5613. }
  5614. }
  5615. trekClient.SendUpdate(lastUpdate);
  5616. IshipIGC* pshipSource = trekClient.GetShip()->GetSourceShip();
  5617. //Change sounds for warning state as appropriate
  5618. {
  5619. WarningMask wm = trekClient.GetShip()->GetWarningMask();
  5620. if (trekClient.wmOld != wm)
  5621. {
  5622. if ((wm & c_wmOutOfBounds) && ((trekClient.wmOld & c_wmOutOfBounds) == 0))
  5623. {
  5624. trekClient.PlaySoundEffect(salBoundryExceededSound);
  5625. }
  5626. if ((wm & c_wmCrowdedSector) && ((trekClient.wmOld & c_wmCrowdedSector) == 0))
  5627. {
  5628. trekClient.PlaySoundEffect(salSectorCrowdedSound);
  5629. }
  5630. trekClient.wmOld = wm;
  5631. }
  5632. }
  5633. //NYI this should only be done once or on a side change
  5634. const float alpha = 0.75f;
  5635. IsideIGC* pside = trekClient.GetShip()->GetSide();
  5636. assert (pside);
  5637. Color colorHUD = pside->GetColor();
  5638. colorHUD = colorHUD * g_hudBright;
  5639. colorHUD.SetAlpha(alpha);
  5640. m_pcolorHUD->SetValue(colorHUD);
  5641. const float alphaless = 0.55f;
  5642. Color colorHUDshadows = Color(45, 36, 59);
  5643. colorHUDshadows = colorHUDshadows * 0.65f;
  5644. colorHUDshadows.SetAlpha(alphaless);
  5645. m_pcolorHUDshadows->SetValue(colorHUDshadows);
  5646. //------------------------------------------------------------------------------
  5647. // Interception point for handling training missions
  5648. // =================================================
  5649. // This call is to be made when we are running a training mission to check to
  5650. // see if mission goals have been accomplished, and prevent the player from
  5651. // running off into space wherever appropriate. The function called will
  5652. // maintain the state, and provide guidance and restrictions as applicable.
  5653. //------------------------------------------------------------------------------
  5654. Training::HandleMission ();
  5655. //------------------------------------------------------------------------------
  5656. // End interception for training missions
  5657. //------------------------------------------------------------------------------
  5658. }
  5659. //
  5660. // Handle sending network messages
  5661. //
  5662. trekClient.CheckServerLag(Time::Now());
  5663. if (trekClient.m_fm.IsConnected())
  5664. trekClient.SendMessages();
  5665. trekClient.m_pCoreIGC->Update(now);
  5666. /*
  5667. //
  5668. // check for the clock bug.
  5669. //
  5670. static bool bWarnedAboutClockBug = false;
  5671. if (!bWarnedAboutClockBug && trekClient.m_sync < 0.30)
  5672. {
  5673. bWarnedAboutClockBug = true;
  5674. TRef<IMessageBox> pmsgBox = CreateMessageBox("You are experiencing the clock bug.");
  5675. OpenPopup(pmsgBox);
  5676. }
  5677. */
  5678. }
  5679. bool OnKey(IInputProvider* pprovider, const KeyState& ks, bool& bForceTranslate)
  5680. {
  5681. if (IsInputEnabled (ks.vk)) {
  5682. m_ptrekInput->SetFocus(true);
  5683. TrekKey tk = m_ptrekInput->HandleKeyMessage(ks);
  5684. if (TK_NoKeyMapping != tk) {
  5685. if (ks.bDown) {
  5686. // hook to send this keypress to training missions
  5687. if (Training::RecordKeyPress (tk))
  5688. {
  5689. if (
  5690. trekClient.IsInGame()
  5691. && ((GetViewMode() != vmOverride) || (tk == TK_StartChat))
  5692. && !trekClient.IsLockedDown()
  5693. ) {
  5694. OnTrekKey(tk);
  5695. }
  5696. return true;
  5697. }
  5698. }
  5699. }
  5700. }
  5701. return false;
  5702. }
  5703. bool OnChar(IInputProvider* pprovider, const KeyState& ks)
  5704. {
  5705. if (!GetUI()) {
  5706. return m_pconsoleImage->OnChar(ks);
  5707. } else {
  5708. return false;
  5709. }
  5710. }
  5711. void SetTargetGeo(ImodelIGC* pmodel)
  5712. {
  5713. const float alpha = 0.5f;
  5714. Color colorTargetHUD(alpha, alpha, alpha, alpha);
  5715. m_cameraControl.m_pgeoTarget = Geo::GetEmpty();
  5716. if (pmodel != NULL)
  5717. {
  5718. if (pmodel->GetObjectType() == OT_ship)
  5719. pmodel = ((IshipIGC*)pmodel)->GetSourceShip();
  5720. if ((pmodel != trekClient.GetShip()->GetSourceShip()) &&
  5721. (pmodel->GetHitTest() != NULL) &&
  5722. (pmodel->GetCluster() == trekClient.GetCluster()) &&
  5723. trekClient.GetShip()->CanSee(pmodel))
  5724. {
  5725. ThingSite* pthingSite = pmodel->GetThingSite();
  5726. if (pthingSite)
  5727. {
  5728. TRef<ThingGeo> pthing;
  5729. CastTo(pthing, pthingSite->GetThingGeo());
  5730. if (pthing)
  5731. m_cameraControl.m_pgeoTarget = pthing->GetTargetGeo();
  5732. }
  5733. }
  5734. IsideIGC* pside = pmodel->GetSide();
  5735. if (pside)
  5736. {
  5737. colorTargetHUD = pside->GetColor();
  5738. colorTargetHUD = colorTargetHUD * g_hudBright;
  5739. colorTargetHUD.SetAlpha(alpha);
  5740. }
  5741. }
  5742. m_pcolorTargetHUD->SetValue(colorTargetHUD);
  5743. }
  5744. void SetTarget(ImodelIGC* pmodel, CommandID cid)
  5745. {
  5746. if (pmodel && trekClient.GetShip()->GetCommandTarget(c_cmdCurrent) != pmodel)
  5747. {
  5748. StartSound(newTargetSound);
  5749. }
  5750. if (cid == c_cidDefault)
  5751. cid = pmodel ? trekClient.GetShip()->GetDefaultOrder(pmodel) : c_cidNone;
  5752. trekClient.GetShip()->SetCommand(c_cmdCurrent, pmodel, cid);
  5753. if (trekClient.m_fm.IsConnected())
  5754. {
  5755. trekClient.SetMessageType(BaseClient::c_mtGuaranteed);
  5756. BEGIN_PFM_CREATE(trekClient.m_fm, pfmOC, CS, ORDER_CHANGE)
  5757. END_PFM_CREATE
  5758. //Don't bother to set ship ID
  5759. pfmOC->command = c_cmdCurrent;
  5760. pfmOC->commandID = cid;
  5761. if (pmodel)
  5762. {
  5763. pfmOC->objectType = pmodel->GetObjectType();
  5764. pfmOC->objectID = pmodel->GetObjectID();
  5765. }
  5766. else
  5767. {
  5768. pfmOC->objectType = OT_invalid;
  5769. pfmOC->objectID = NA;
  5770. }
  5771. }
  5772. if (CommandCamera(m_cm))
  5773. {
  5774. if (m_cameraControl.GetAnimation() < 1.0f)
  5775. m_cameraControl.SetAnimation(1.0f);
  5776. if (pmodel && !m_bTrackCommandView)
  5777. {
  5778. if (pmodel->GetObjectType() == OT_ship)
  5779. pmodel = ((IshipIGC*)pmodel)->GetSourceShip();
  5780. if ((pmodel->GetCluster() == trekClient.GetCluster()) &&
  5781. trekClient.GetShip()->CanSee(pmodel))
  5782. {
  5783. m_positionCommandView = pmodel->GetPosition();
  5784. }
  5785. }
  5786. m_displacementCommandView = Vector::GetZero();
  5787. }
  5788. }
  5789. void SetAccepted(ImodelIGC* pmodel, CommandID cid)
  5790. {
  5791. if ((cid != c_cidNone) && m_pconsoleImage)
  5792. {
  5793. trekClient.PostText(false, "Command accepted.");
  5794. trekClient.PostText(true, "");
  5795. }
  5796. trekClient.GetShip()->SetCommand(c_cmdAccepted, pmodel, cid);
  5797. /*
  5798. if (trekClient.autoPilot())
  5799. {
  5800. if (pmodel)
  5801. SetTarget(pmodel, cid);
  5802. else
  5803. {
  5804. trekClient.SetAutoPilot(false);
  5805. SwitchToJoyThrottle();
  5806. trekClient.PlaySoundEffect(salAutopilotDisengageSound);
  5807. }
  5808. }
  5809. */
  5810. if (trekClient.m_fm.IsConnected())
  5811. {
  5812. trekClient.SetMessageType(BaseClient::c_mtGuaranteed);
  5813. BEGIN_PFM_CREATE(trekClient.m_fm, pfmOC, CS, ORDER_CHANGE)
  5814. END_PFM_CREATE
  5815. //Don't bother to set ship ID
  5816. pfmOC->command = c_cmdAccepted;
  5817. pfmOC->commandID = cid;
  5818. if (pmodel)
  5819. {
  5820. pfmOC->objectType = pmodel->GetObjectType();
  5821. pfmOC->objectID = pmodel->GetObjectID();
  5822. }
  5823. else
  5824. {
  5825. pfmOC->objectType = OT_invalid;
  5826. pfmOC->objectID = NA;
  5827. }
  5828. }
  5829. }
  5830. void SetTimeDamaged(Time now)
  5831. {
  5832. if (now <= m_timeLastDamage + c_dtFlashingDuration)
  5833. {
  5834. //We were already hit and flashing. Fudge the time hit to the most recent boundary between
  5835. //on and off
  5836. float dt = now - m_timeLastDamage;
  5837. float n = float(floor(dt / (c_dtFlashOn + c_dtFlashOff)));
  5838. m_timeLastDamage += n * (c_dtFlashOn + c_dtFlashOff);
  5839. }
  5840. else
  5841. m_timeLastDamage = now; //Start flashing now
  5842. }
  5843. bool GetFlash(Time now)
  5844. {
  5845. bool bFlash;
  5846. if (now <= m_timeLastDamage + c_dtFlashingDuration)
  5847. {
  5848. //We were already hit and flashing. Fudge the time hit to the most recent boundary between
  5849. //on and off
  5850. float dt = now - m_timeLastDamage;
  5851. float n = float(floor(dt / (c_dtFlashOn + c_dtFlashOff)));
  5852. Time timeStartFlash = m_timeLastDamage + n * (c_dtFlashOn + c_dtFlashOff);
  5853. bFlash = (now <= (timeStartFlash + c_dtFlashOn));
  5854. }
  5855. else
  5856. bFlash = false;
  5857. return bFlash;
  5858. }
  5859. void TrekFindTarget(int ttMask,
  5860. TrekKey tk,
  5861. TrekKey tkNearest,
  5862. TrekKey tkPrevious,
  5863. AbilityBitMask abm = 0)
  5864. {
  5865. assert ((ttMask & c_ttFront) == 0);
  5866. if (tk == tkNearest)
  5867. ttMask |= c_ttNearest;
  5868. else if (tk == tkPrevious)
  5869. ttMask |= c_ttPrevious;
  5870. const Vector* pposition;
  5871. if (trekClient.GetViewCluster())
  5872. {
  5873. IstationIGC* pstation = trekClient.GetShip()->GetStation();
  5874. if (pstation && (pstation->GetCluster() == trekClient.GetViewCluster()))
  5875. pposition = &(pstation->GetPosition());
  5876. else
  5877. pposition = &(Vector::GetZero());
  5878. }
  5879. else
  5880. pposition = &(trekClient.GetShip()->GetPosition());
  5881. ImodelIGC* m = FindTarget(trekClient.GetShip()->GetSourceShip(),
  5882. ttMask,
  5883. trekClient.GetShip()->GetCommandTarget(c_cmdCurrent),
  5884. trekClient.GetCluster(),
  5885. pposition, NULL, abm);
  5886. SetTarget(m, c_cidDefault);
  5887. }
  5888. void ToggleWeapon(Mount mount)
  5889. {
  5890. IshipIGC* pship = trekClient.GetShip();
  5891. if (pship->GetParentShip() == NULL)
  5892. {
  5893. Mount nHardpoints = pship->GetHullType()->GetMaxFixedWeapons();
  5894. IweaponIGC* pweapon = (IweaponIGC*)pship->GetMountedPart(ET_Weapon, mount);
  5895. if (pweapon && mount < nHardpoints)
  5896. {
  5897. int stateM = trekClient.GetShip()->GetStateM();
  5898. Mount mountSelected = (stateM & selectedWeaponMaskIGC) >> selectedWeaponShiftIGC;
  5899. if (trekClient.fGroupFire
  5900. || pweapon->GetMountID() != mountSelected)
  5901. {
  5902. // set the client to single fire with this weapon
  5903. trekClient.SetSelectedWeapon(mount);
  5904. trekClient.fGroupFire = false;
  5905. trekClient.PlaySoundEffect(ungroupWeaponsSound, trekClient.GetShip());
  5906. }
  5907. else
  5908. {
  5909. // set the client back to group fire
  5910. trekClient.fGroupFire = true;
  5911. trekClient.PlaySoundEffect(groupWeaponsSound, trekClient.GetShip());
  5912. }
  5913. }
  5914. }
  5915. }
  5916. int FindPartIndex(IpartIGC* ppart)
  5917. {
  5918. const PartLinkIGC* ppartLink = trekClient.GetShip()->GetParts()->first();
  5919. int index = 0;
  5920. while (ppartLink->data() != ppart)
  5921. {
  5922. index++;
  5923. ppartLink = ppartLink->next();
  5924. assert (ppartLink);
  5925. }
  5926. return index;
  5927. }
  5928. void SwapPart(EquipmentType et, Mount mount)
  5929. {
  5930. IshipIGC* pship = trekClient.GetShip();
  5931. if ((pship->GetParentShip() == NULL) && trekClient.flyingF())
  5932. {
  5933. PartMask maxPartMask = pship->GetHullType()->GetPartMask(et, mount);
  5934. IpartIGC* ppartOld = pship->GetMountedPart(et, mount);
  5935. if (trekClient.SelectCargoPartOfType(et, maxPartMask, ppartOld ? ppartOld->GetPartType() : NULL))
  5936. {
  5937. Mount mountNew = trekClient.GetSelectedCargoMount();
  5938. IpartIGC* ppartNew = pship->GetMountedPart(et, mountNew);
  5939. if (ppartOld || ppartNew)
  5940. {
  5941. if (ppartOld)
  5942. trekClient.SwapPart(ppartOld, mountNew);
  5943. else if (ppartNew)
  5944. trekClient.SwapPart(ppartNew, mount);
  5945. if (ppartNew)
  5946. {
  5947. trekClient.PlaySoundEffect(mountSound, trekClient.GetShip());
  5948. }
  5949. else if (ppartOld)
  5950. {
  5951. trekClient.PlaySoundEffect(unmountSound, trekClient.GetShip());
  5952. }
  5953. // set the inventory slot to the next item of that type
  5954. trekClient.NextCargoPart();
  5955. trekClient.SelectCargoPartOfType(et, maxPartMask, ppartNew ? ppartNew->GetPartType() : NULL);
  5956. trekClient.GetCore()->GetIgcSite()->LoadoutChangeEvent(pship, trekClient.GetCargoPart(), c_lcCargoSelectionChanged);
  5957. }
  5958. }
  5959. else
  5960. {
  5961. trekClient.PlaySoundEffect(salCargoFullSound, trekClient.GetShip());
  5962. }
  5963. }
  5964. }
  5965. void SwapWeapon(Mount mount)
  5966. {
  5967. IshipIGC* pship = trekClient.GetShip();
  5968. if ((pship->GetParentShip() == NULL) && trekClient.flyingF())
  5969. {
  5970. Mount nHardpoints = pship->GetHullType()->GetMaxFixedWeapons();
  5971. if (mount < nHardpoints)
  5972. {
  5973. SwapPart(ET_Weapon, mount);
  5974. }
  5975. }
  5976. }
  5977. void SwapTurret(int id)
  5978. {
  5979. ZAssert(id >= 0);
  5980. IshipIGC* pship = trekClient.GetShip();
  5981. if ((pship->GetParentShip() == NULL) && trekClient.flyingF())
  5982. {
  5983. Mount nFixedHardpoints = pship->GetHullType()->GetMaxFixedWeapons();
  5984. int nTurrets = pship->GetHullType()->GetMaxWeapons() - nFixedHardpoints;
  5985. if (id < nTurrets)
  5986. {
  5987. SwapPart(ET_Weapon, id + nFixedHardpoints);
  5988. }
  5989. }
  5990. }
  5991. //////////////////////////////////////////////////////////////////////////////
  5992. //
  5993. // HUD Style exposure
  5994. //
  5995. //////////////////////////////////////////////////////////////////////////////
  5996. float GetHUDStyle (void) const
  5997. {
  5998. return m_pnumberStyleHUD->GetValue ();
  5999. }
  6000. void SetHUDStyle (float newStyle)
  6001. {
  6002. m_pnumberStyleHUD->SetValue (newStyle);
  6003. }
  6004. //////////////////////////////////////////////////////////////////////////////
  6005. //
  6006. // Help stuff
  6007. //
  6008. //////////////////////////////////////////////////////////////////////////////
  6009. class HelpPosition :
  6010. public PointValue,
  6011. public IEventSink
  6012. {
  6013. private:
  6014. bool m_bOn;
  6015. float m_timeStart;
  6016. float m_valueStart;
  6017. float m_value;
  6018. Point m_positionOff;
  6019. Point m_positionOn;
  6020. float GetTime() { return Number::Cast(GetChild(0))->GetValue() * 2.0f; }
  6021. public:
  6022. HelpPosition(Number* ptime, IEventSource* peventSource) :
  6023. PointValue(ptime),
  6024. m_bOn(false),
  6025. m_timeStart(ptime->GetValue()),
  6026. m_valueStart(0),
  6027. m_value(0),
  6028. m_positionOn(10, 10),
  6029. m_positionOff(-527, 10)
  6030. {
  6031. peventSource->AddSink(this);
  6032. }
  6033. bool OnEvent(IEventSource* pevent)
  6034. {
  6035. m_bOn = false;
  6036. m_timeStart = GetTime();
  6037. m_valueStart = m_value;
  6038. return true;
  6039. }
  6040. void Toggle(bool bOn)
  6041. {
  6042. m_bOn = bOn || !m_bOn;
  6043. m_timeStart = GetTime();
  6044. m_valueStart = m_value;
  6045. }
  6046. void Evaluate()
  6047. {
  6048. if (m_bOn) {
  6049. m_value = min(1, m_valueStart + (GetTime() - m_timeStart));
  6050. } else {
  6051. m_value = max(0, m_valueStart - (GetTime() - m_timeStart));
  6052. }
  6053. GetValueInternal() = Interpolate(m_positionOff, m_positionOn, m_value);
  6054. }
  6055. };
  6056. TRef<HelpPane> m_phelp;
  6057. TRef<HelpPosition> m_phelpPosition;
  6058. class PagePaneIncluderImpl : public PagePaneIncluder {
  6059. public:
  6060. TRef<ZFile> Include(const ZString& str)
  6061. {
  6062. HKEY hKey;
  6063. if (ERROR_SUCCESS != ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, ALLEGIANCE_REGISTRY_KEY_ROOT, 0, "", REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hKey, NULL)
  6064. ) {
  6065. return NULL;
  6066. }
  6067. char buf[128];
  6068. DWORD dwSize = sizeof(buf);
  6069. DWORD dwType = REG_SZ;
  6070. ::RegQueryValueEx(hKey, str, NULL, &dwType, (BYTE*)buf, &dwSize);
  6071. ::RegCloseKey(hKey);
  6072. if (dwType != REG_SZ) {
  6073. return NULL;
  6074. }
  6075. TRef<ZFile> pfile = GetWindow()->GetModeler()->LoadFile(ZString(buf), "mml", false);
  6076. if (pfile) {
  6077. return pfile;
  6078. }
  6079. return NULL;
  6080. }
  6081. };
  6082. ZString GetProductID()
  6083. {
  6084. HKEY hKey;
  6085. if (ERROR_SUCCESS == ::RegCreateKeyEx(HKEY_LOCAL_MACHINE, ALLEGIANCE_REGISTRY_KEY_ROOT,
  6086. 0, "", REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hKey, NULL)) {
  6087. char buf[128];
  6088. DWORD dwSize = sizeof(buf);
  6089. DWORD dwType = REG_SZ;
  6090. ::RegQueryValueEx(hKey, "PID", NULL, &dwType, (BYTE*)buf, &dwSize);
  6091. ::RegCloseKey(hKey);
  6092. if (dwType == REG_SZ) {
  6093. return ZString(buf);
  6094. }
  6095. }
  6096. return ZString("<unknown pid>");
  6097. }
  6098. ZString GetVersionString()
  6099. {
  6100. }
  6101. void InitializeHelp()
  6102. {
  6103. m_phelp = CreateHelpPane(GetModeler(), "hlpblank", new PagePaneIncluderImpl());
  6104. m_phelp->SetString("pid", GetProductID());
  6105. m_phelp->SetString("ver", ZVersionInfo().GetProductVersionString());
  6106. m_phelpPosition = new HelpPosition(GetTime(), m_phelp->GetEventSourceClose());
  6107. m_pwrapImageHelp->SetImage(
  6108. new TransformImage(
  6109. CreatePaneImage(
  6110. GetEngine(),
  6111. SurfaceType2D() | SurfaceType3D(),
  6112. true,
  6113. m_phelp
  6114. ),
  6115. new TranslateTransform2(m_phelpPosition)
  6116. )
  6117. );
  6118. }
  6119. void OnHelp(bool bOn)
  6120. {
  6121. trekClient.PlaySoundEffect(positiveButtonClickSound);
  6122. m_phelpPosition->Toggle(bOn);
  6123. }
  6124. //////////////////////////////////////////////////////////////////////////////
  6125. //
  6126. //
  6127. //
  6128. //////////////////////////////////////////////////////////////////////////////
  6129. bool OnTrekKeyFilter(TrekKey tk)
  6130. {
  6131. if (m_screen != ScreenIDSplashScreen) {
  6132. switch(tk) {
  6133. case TK_Help:
  6134. OnHelp(false);
  6135. return true;
  6136. case TK_MainMenu:
  6137. if (
  6138. (
  6139. !trekClient.IsInGame()
  6140. || (GetViewMode() != vmOverride)
  6141. )
  6142. && !trekClient.IsLockedDown()
  6143. && (
  6144. m_pconsoleImage == NULL
  6145. || !m_pconsoleImage->IsComposing()
  6146. )
  6147. ) {
  6148. ShowMainMenu();
  6149. return true;
  6150. }
  6151. return false;
  6152. case TK_ChatPageUp:
  6153. if (m_pchatListPane != NULL) {
  6154. m_pchatListPane->PageUp();
  6155. }
  6156. return true;
  6157. case TK_ChatPageDown:
  6158. if (m_pchatListPane != NULL) {
  6159. m_pchatListPane->PageDown();
  6160. }
  6161. return true;
  6162. case TK_QuickChatMenu:
  6163. if (
  6164. trekClient.MyMission()
  6165. && (!trekClient.IsInGame() || (GetViewMode() != vmOverride))
  6166. && !trekClient.IsLockedDown()
  6167. && (m_screen == ScreenIDGameOverScreen
  6168. || m_screen == ScreenIDTeamScreen
  6169. || m_screen == ScreenIDCombat)
  6170. ) {
  6171. OpenMainQuickChatMenu();
  6172. }
  6173. return true;
  6174. }
  6175. }
  6176. return false;
  6177. };
  6178. //////////////////////////////////////////////////////////////////////////////
  6179. //
  6180. //
  6181. //
  6182. //////////////////////////////////////////////////////////////////////////////
  6183. void SetViewToCombatMode (CameraMode newCameraMode)
  6184. {
  6185. // turn off command view overlays
  6186. TurnOffOverlayFlags(c_omBanishablePanes);
  6187. if (GetViewMode () == vmCombat)
  6188. {
  6189. // if we aren't already facing ahead, face ahead
  6190. m_cameraControl.SetHeadOrientation(0.0f);
  6191. // set the desired camera mode
  6192. SetCameraMode (newCameraMode);
  6193. }
  6194. else if (trekClient.flyingF())
  6195. {
  6196. // set the mode to combat
  6197. SetViewMode (vmCombat);
  6198. // set the desired camera mode
  6199. SetCameraMode (newCameraMode);
  6200. }
  6201. else
  6202. {
  6203. // switch to the hangar mode
  6204. SetViewMode(trekClient.GetShip()->IsGhost() ? vmCommand : vmHangar);
  6205. }
  6206. }
  6207. //////////////////////////////////////////////////////////////////////////////
  6208. //
  6209. //
  6210. //
  6211. //////////////////////////////////////////////////////////////////////////////
  6212. void OnTrekKey(TrekKey tk)
  6213. {
  6214. bool suicideF = false;
  6215. switch(tk)
  6216. {
  6217. /*
  6218. case TK_ChatPageUp:
  6219. if (m_pchatListPane != NULL) {
  6220. m_pchatListPane->PageUp();
  6221. }
  6222. break;
  6223. case TK_ChatPageDown:
  6224. if (m_pchatListPane != NULL) {
  6225. m_pchatListPane->PageDown();
  6226. }
  6227. break;
  6228. case TK_QuickChatMenu:
  6229. if (
  6230. trekClient.MyMission()
  6231. && (!trekClient.IsInGame() || (GetViewMode() != vmOverride))
  6232. && !trekClient.IsLockedDown()
  6233. ) {
  6234. OpenMainQuickChatMenu();
  6235. }
  6236. break;
  6237. */
  6238. case TK_ToggleMouse:
  6239. {
  6240. m_bEnableVirtualJoystick = !m_bEnableVirtualJoystick;
  6241. }
  6242. break;
  6243. case TK_TrackCommandView:
  6244. {
  6245. m_bTrackCommandView = !m_bTrackCommandView;
  6246. trekClient.PostText(false, m_bTrackCommandView ? "Command view tracking enabled" : "Command view tracking disabled");
  6247. }
  6248. break;
  6249. case TK_StartChat:
  6250. {
  6251. m_pconsoleImage->StartChat();
  6252. m_ptrekInput->SetFocus(false);
  6253. }
  6254. break;
  6255. case TK_ToggleLODSlider:
  6256. {
  6257. if (m_pwrapImageLOD->GetImage() == Image::GetEmpty()) {
  6258. m_pwrapImageLOD->SetImage(m_pimageLOD);
  6259. } else {
  6260. m_pwrapImageLOD->SetImage(Image::GetEmpty());
  6261. }
  6262. }
  6263. break;
  6264. case TK_LockVector:
  6265. {
  6266. if (trekClient.GetShip()->GetParentShip() == NULL)
  6267. {
  6268. trekClient.GetShip()->SetStateBits(coastButtonIGC, Training::ApproveActions (trekClient.GetShip()->GetStateM() ^ coastButtonIGC));
  6269. trekClient.PlaySoundEffect(vectorLockSound);
  6270. }
  6271. }
  6272. break;
  6273. case TK_ToggleCloak:
  6274. {
  6275. if (trekClient.GetShip()->GetParentShip() == NULL)
  6276. trekClient.GetShip()->SetStateBits(cloakActiveIGC, Training::ApproveActions (trekClient.GetShip()->GetStateM() ^ cloakActiveIGC));
  6277. }
  6278. break;
  6279. case TK_Ripcord:
  6280. {
  6281. if (!Training::IsTraining ())
  6282. {
  6283. if ((trekClient.GetShip()->GetParentShip() == NULL) &&
  6284. trekClient.GetShip()->GetCluster())
  6285. {
  6286. if ((trekClient.GetShip()->GetFlag() != NA) ||
  6287. trekClient.GetShip()->GetBaseHullType()->HasCapability(c_habmNoRipcord))
  6288. {
  6289. trekClient.PlayNotificationSound(salShipCantRipcordSound, trekClient.GetShip());
  6290. }
  6291. else
  6292. {
  6293. IclusterIGC* pcluster = NULL;
  6294. if (!trekClient.GetShip()->fRipcordActive())
  6295. {
  6296. ImodelIGC* pmodel = trekClient.GetShip()->GetCommandTarget(c_cmdCurrent);
  6297. if (!pmodel)
  6298. pmodel = trekClient.GetShip()->GetCommandTarget(c_cmdAccepted);
  6299. if (pmodel)
  6300. pcluster = trekClient.GetCluster(trekClient.GetShip(), pmodel);
  6301. if (!pcluster)
  6302. pcluster = trekClient.GetShip()->GetCluster();
  6303. assert (pcluster);
  6304. }
  6305. trekClient.RequestRipcord(trekClient.GetShip(), pcluster);
  6306. }
  6307. }
  6308. }
  6309. }
  6310. break;
  6311. case TK_PrevWeapon:
  6312. {
  6313. if (trekClient.GetShip()->GetParentShip() == NULL)
  6314. trekClient.PreviousWeapon();
  6315. }
  6316. break;
  6317. case TK_NextWeapon:
  6318. {
  6319. if (trekClient.GetShip()->GetParentShip() == NULL)
  6320. trekClient.NextWeapon();
  6321. }
  6322. break;
  6323. case TK_ToggleGroupFire:
  6324. {
  6325. if (trekClient.GetShip()->GetParentShip() == NULL)
  6326. trekClient.fGroupFire = !trekClient.fGroupFire;
  6327. if (trekClient.fGroupFire)
  6328. trekClient.PlaySoundEffect(groupWeaponsSound, trekClient.GetShip());
  6329. else
  6330. trekClient.PlaySoundEffect(ungroupWeaponsSound, trekClient.GetShip());
  6331. }
  6332. break;
  6333. case TK_SwapWeapon1:
  6334. {
  6335. SwapWeapon(0);
  6336. }
  6337. break;
  6338. case TK_SwapWeapon2:
  6339. {
  6340. SwapWeapon(1);
  6341. }
  6342. break;
  6343. case TK_SwapWeapon3:
  6344. {
  6345. SwapWeapon(2);
  6346. }
  6347. break;
  6348. case TK_SwapWeapon4:
  6349. {
  6350. SwapWeapon(3);
  6351. }
  6352. break;
  6353. case TK_SwapTurret1:
  6354. {
  6355. SwapTurret(0);
  6356. }
  6357. break;
  6358. case TK_SwapTurret2:
  6359. {
  6360. SwapTurret(1);
  6361. }
  6362. break;
  6363. case TK_SwapTurret3:
  6364. {
  6365. SwapTurret(2);
  6366. }
  6367. break;
  6368. case TK_SwapTurret4:
  6369. {
  6370. SwapTurret(3);
  6371. }
  6372. break;
  6373. case TK_PromoteTurret1:
  6374. case TK_PromoteTurret2:
  6375. case TK_PromoteTurret3:
  6376. case TK_PromoteTurret4:
  6377. {
  6378. IhullTypeIGC* pht = trekClient.GetShip()->GetBaseHullType();
  6379. if (pht)
  6380. {
  6381. Mount turret = Mount(tk - TK_PromoteTurret1) + pht->GetMaxFixedWeapons();
  6382. if (turret < pht->GetMaxWeapons())
  6383. {
  6384. trekClient.SetMessageType(BaseClient::c_mtGuaranteed);
  6385. BEGIN_PFM_CREATE(trekClient.m_fm, pfmPromote, C, PROMOTE)
  6386. END_PFM_CREATE;
  6387. pfmPromote->mountidPromoted = turret;
  6388. }
  6389. }
  6390. }
  6391. break;
  6392. case TK_SwapMissile:
  6393. {
  6394. SwapPart(ET_Magazine, 0);
  6395. }
  6396. break;
  6397. case TK_SwapChaff:
  6398. {
  6399. SwapPart(ET_ChaffLauncher, 0);
  6400. }
  6401. break;
  6402. case TK_SwapShield:
  6403. {
  6404. SwapPart(ET_Shield, 0);
  6405. }
  6406. break;
  6407. case TK_SwapCloak:
  6408. {
  6409. SwapPart(ET_Cloak, 0);
  6410. }
  6411. break;
  6412. case TK_SwapAfterburner:
  6413. {
  6414. SwapPart(ET_Afterburner, 0);
  6415. }
  6416. break;
  6417. case TK_SwapMine:
  6418. {
  6419. SwapPart(ET_Dispenser, 0);
  6420. }
  6421. break;
  6422. case TK_NextCargo:
  6423. {
  6424. if (trekClient.GetShip()->GetParentShip() == NULL)
  6425. {
  6426. trekClient.NextCargoPart();
  6427. trekClient.GetCore()->GetIgcSite()->LoadoutChangeEvent(trekClient.GetShip(), trekClient.GetCargoPart(), c_lcCargoSelectionChanged);
  6428. }
  6429. }
  6430. break;
  6431. case TK_ToggleWeapon1:
  6432. {
  6433. ToggleWeapon(0);
  6434. }
  6435. break;
  6436. case TK_ToggleWeapon2:
  6437. {
  6438. ToggleWeapon(1);
  6439. }
  6440. break;
  6441. case TK_ToggleWeapon3:
  6442. {
  6443. ToggleWeapon(2);
  6444. }
  6445. break;
  6446. case TK_ToggleWeapon4:
  6447. {
  6448. ToggleWeapon(3);
  6449. }
  6450. break;
  6451. case TK_Reload:
  6452. {
  6453. if (trekClient.GetShip()->GetParentShip() == NULL)
  6454. {
  6455. int stateM = trekClient.GetShip()->GetStateM();
  6456. if ((stateM & (oneWeaponIGC | allWeaponsIGC)) == 0)
  6457. trekClient.Reload(trekClient.GetShip(), NULL, ET_Weapon);
  6458. if ((stateM & afterburnerButtonIGC) == 0)
  6459. trekClient.Reload(trekClient.GetShip(), NULL, ET_Afterburner);
  6460. if ((stateM & missileFireIGC) == 0)
  6461. trekClient.Reload(trekClient.GetShip(), (IlauncherIGC*)(trekClient.GetShip()->GetMountedPart(ET_Magazine, 0)), ET_Magazine);
  6462. if ((stateM & mineFireIGC) == 0)
  6463. trekClient.Reload(trekClient.GetShip(), (IlauncherIGC*)(trekClient.GetShip()->GetMountedPart(ET_Dispenser, 0)), ET_Dispenser);
  6464. if ((stateM & chaffFireIGC) == 0)
  6465. trekClient.Reload(trekClient.GetShip(), (IlauncherIGC*)(trekClient.GetShip()->GetMountedPart(ET_ChaffLauncher, 0)), ET_ChaffLauncher);
  6466. trekClient.PlayNotificationSound(salReloadingSound, trekClient.GetShip());
  6467. }
  6468. }
  6469. break;
  6470. case TK_DropCargo:
  6471. {
  6472. if (trekClient.flyingF() && (trekClient.GetShip()->GetParentShip() == NULL))
  6473. {
  6474. IpartIGC* ppart = trekClient.GetCargoPart();
  6475. if (ppart)
  6476. {
  6477. // to keep from changing the order of things in the
  6478. // inventory pane, always drop the last instance of
  6479. // this part type.
  6480. IpartTypeIGC *ppartType = ppart->GetPartType();
  6481. for (Mount mount = -c_maxCargo; mount < 0; ++mount)
  6482. {
  6483. IpartIGC *ppartPrev = trekClient.GetShip()->GetMountedPart(NA, mount);
  6484. IpartTypeIGC *ppartTypePrev = ppartPrev ? ppartPrev->GetPartType() : NULL;
  6485. if (ppartType == ppartTypePrev)
  6486. {
  6487. trekClient.DropPart(ppartPrev);
  6488. trekClient.PlaySoundEffect(dropSound, trekClient.GetShip());
  6489. break;
  6490. }
  6491. }
  6492. }
  6493. else
  6494. {
  6495. trekClient.NextCargoPart();
  6496. }
  6497. trekClient.GetCore()->GetIgcSite()->LoadoutChangeEvent(trekClient.GetShip(), trekClient.GetCargoPart(), c_lcCargoSelectionChanged);
  6498. }
  6499. }
  6500. break;
  6501. case TK_ViewRearLeft:
  6502. {
  6503. if ((m_cm == cmCockpit) || (m_cm == cmExternalChase))
  6504. {
  6505. m_cameraControl.SetHeadOrientation(pi * 1.25f);
  6506. }
  6507. }
  6508. break;
  6509. case TK_ViewRearRight:
  6510. {
  6511. if ((m_cm == cmCockpit) || (m_cm == cmExternalChase))
  6512. {
  6513. m_cameraControl.SetHeadOrientation(pi * 0.75f);
  6514. }
  6515. }
  6516. break;
  6517. case TK_ViewFrontLeft:
  6518. {
  6519. if ((m_cm == cmCockpit) || (m_cm == cmExternalChase))
  6520. {
  6521. m_cameraControl.SetHeadOrientation(pi * 1.75f);
  6522. }
  6523. }
  6524. break;
  6525. case TK_ViewFrontRight:
  6526. {
  6527. if ((m_cm == cmCockpit) || (m_cm == cmExternalChase))
  6528. {
  6529. m_cameraControl.SetHeadOrientation(pi * 0.25f);
  6530. }
  6531. }
  6532. break;
  6533. case TK_ViewRear:
  6534. {
  6535. if ((m_cm == cmCockpit) || (m_cm == cmExternalChase))
  6536. {
  6537. m_cameraControl.SetHeadOrientation(pi);
  6538. }
  6539. }
  6540. break;
  6541. case TK_ViewLeft:
  6542. {
  6543. if ((m_cm == cmCockpit) || (m_cm == cmExternalChase))
  6544. {
  6545. m_cameraControl.SetHeadOrientation(pi * 1.5f);
  6546. }
  6547. }
  6548. break;
  6549. case TK_ViewRight:
  6550. {
  6551. if ((m_cm == cmCockpit) || (m_cm == cmExternalChase))
  6552. {
  6553. m_cameraControl.SetHeadOrientation(pi * 0.5f);
  6554. }
  6555. }
  6556. break;
  6557. case TK_ViewExternal:
  6558. {
  6559. SetViewToCombatMode ((GetCameraMode () != cmExternal) ? cmExternal : cmCockpit);
  6560. }
  6561. break;
  6562. case TK_ViewExternalOrbit:
  6563. {
  6564. SetViewToCombatMode ((GetCameraMode () != cmExternalOrbit) ? cmExternalOrbit : cmCockpit);
  6565. }
  6566. break;
  6567. case TK_ViewExternalStation:
  6568. {
  6569. SetViewToCombatMode ((GetCameraMode () != cmExternalStation) ? cmExternalStation : cmCockpit);
  6570. }
  6571. break;
  6572. case TK_ViewFlyby:
  6573. {
  6574. SetViewToCombatMode ((GetCameraMode () != cmExternalFlyBy) ? cmExternalFlyBy : cmCockpit);
  6575. }
  6576. break;
  6577. case TK_ViewMissile:
  6578. {
  6579. SetViewToCombatMode ((GetCameraMode () != cmExternalMissile) ? cmExternalMissile : cmCockpit);
  6580. }
  6581. break;
  6582. case TK_ViewTarget:
  6583. {
  6584. if (trekClient.flyingF())
  6585. {
  6586. if (GetCameraMode() != cmExternalTarget)
  6587. SetCameraMode(cmExternalTarget);
  6588. else
  6589. SetCameraMode(cmCockpit);
  6590. }
  6591. }
  6592. break;
  6593. case TK_ViewChase:
  6594. {
  6595. SetViewToCombatMode((GetCameraMode() != cmExternalChase) ? cmExternalChase : cmCockpit);
  6596. /*
  6597. if (m_bUsePreferChaseView)
  6598. {
  6599. // here we want to treat this as a sticky key press, not a toggle
  6600. m_bPreferChaseView = true;
  6601. SetViewToCombatMode (cmExternalChase);
  6602. }
  6603. else
  6604. {
  6605. // here we just toggle the views
  6606. SetViewToCombatMode ((GetCameraMode () != cmExternalChase) ? cmExternalChase : cmCockpit);
  6607. }
  6608. */
  6609. }
  6610. break;
  6611. /*
  6612. // This camera mode is not actually handled by the viewing code
  6613. case TK_ViewTurret:
  6614. {
  6615. SetViewToCombatMode ((GetCameraMode () != cmExternalTurret) ? cmExternalTurret : cmCockpit);
  6616. }
  6617. break;
  6618. */
  6619. case TK_ViewBase:
  6620. {
  6621. SetViewToCombatMode ((GetCameraMode () != cmExternalBase) ? cmExternalBase : cmCockpit);
  6622. }
  6623. break;
  6624. case TK_ConModeGameState:
  6625. {
  6626. if (GetViewMode() != vmOverride && trekClient.m_fm.IsConnected())
  6627. {
  6628. TurnOffOverlayFlags(c_omBanishablePanes & ~ofGameState);
  6629. ToggleOverlayFlags(ofGameState);
  6630. }
  6631. }
  6632. break;
  6633. case TK_ConModeNav:
  6634. case TK_ViewSector:
  6635. {
  6636. if (GetViewMode() != vmOverride) {
  6637. ToggleOverlayFlags(ofSectorPane);
  6638. }
  6639. }
  6640. break;
  6641. case TK_ViewCommand:
  6642. case TK_ConModeCommand:
  6643. {
  6644. if (CommandCamera(m_cm))
  6645. {
  6646. if (GetOverlayFlags() & c_omBanishablePanes) {
  6647. TurnOffOverlayFlags(c_omBanishablePanes);
  6648. } else if (!trekClient.GetShip()->IsGhost()) {
  6649. if (trekClient.flyingF()) {
  6650. SetViewMode(vmCombat);
  6651. } else {
  6652. SetViewMode(vmHangar);
  6653. }
  6654. }
  6655. }
  6656. else
  6657. {
  6658. if ((trekClient.GetViewCluster() == NULL) && !trekClient.flyingF())
  6659. {
  6660. IstationIGC* pstation = trekClient.GetShip()->GetStation();
  6661. assert (pstation);
  6662. IclusterIGC* pcluster = pstation->GetCluster();
  6663. assert (pcluster);
  6664. trekClient.RequestViewCluster(pcluster);
  6665. SetViewMode(vmCommand);
  6666. }
  6667. else
  6668. {
  6669. SetViewMode(vmCommand);
  6670. PositionCommandView(NULL, 2.0f);
  6671. }
  6672. }
  6673. }
  6674. break;
  6675. case TK_ToggleCommand:
  6676. {
  6677. if (m_cmPreviousCommand == cmExternalCommandViewTD)
  6678. {
  6679. m_cmPreviousCommand = cmExternalCommandView34;
  6680. }
  6681. else if (m_cmPreviousCommand == cmExternalCommandView34)
  6682. {
  6683. m_cmPreviousCommand = cmExternalCommandViewTD;
  6684. }
  6685. if (CommandCamera(m_cm))
  6686. {
  6687. SetCameraMode(m_cmPreviousCommand);
  6688. PositionCommandView(NULL, 2.0f);
  6689. }
  6690. }
  6691. break;
  6692. case TK_CycleRadar:
  6693. {
  6694. extern const char* c_szRadarLODs[];
  6695. if (m_cm == cmCockpit && GetViewMode() == vmCombat)
  6696. {
  6697. m_radarCockpit = (m_radarCockpit + 1) % (int(RadarImage::c_rlMax) + 1);
  6698. m_pradarImage->SetRadarLOD((RadarImage::RadarLOD)m_radarCockpit);
  6699. trekClient.PostText(false, "%s", c_szRadarLODs[m_radarCockpit]);
  6700. }
  6701. else if (GetViewMode() == vmCommand)
  6702. {
  6703. m_radarCommand = (m_radarCommand + 1) % (int(RadarImage::c_rlMax) + 1);
  6704. m_pradarImage->SetRadarLOD((RadarImage::RadarLOD)m_radarCommand);
  6705. trekClient.PostText(false, "%s", c_szRadarLODs[m_radarCommand]);
  6706. }
  6707. }
  6708. break;
  6709. case TK_ConModeCombat:
  6710. {
  6711. if (GetCameraMode() != cmCockpit)
  6712. {
  6713. // save the old default state
  6714. bool bOldPreference = m_bPreferChaseView;
  6715. // if we are using the prefer chase view option, then make
  6716. // chase view unsticky
  6717. m_bPreferChaseView = false;
  6718. // always set the view mode to cockpit
  6719. SetViewToCombatMode (cmCockpit);
  6720. // restore the old default state
  6721. m_bPreferChaseView = bOldPreference;
  6722. }
  6723. else
  6724. {
  6725. SetViewToCombatMode(cmCockpit);
  6726. }
  6727. }
  6728. break;
  6729. case TK_ConModeInventory:
  6730. {
  6731. if (GetViewMode() == vmOverride) {
  6732. // do nothing
  6733. } else if (trekClient.GetShip()->IsGhost()) {
  6734. TurnOffOverlayFlags(c_omBanishablePanes);
  6735. } else if (trekClient.GetShip()->GetStation() != NULL) {
  6736. if (GetViewMode() != vmLoadout)
  6737. SetViewMode(vmLoadout);
  6738. else if (GetOverlayFlags() & c_omBanishablePanes)
  6739. TurnOffOverlayFlags(c_omBanishablePanes);
  6740. else
  6741. SetViewMode(vmHangar);
  6742. }
  6743. else
  6744. ToggleOverlayFlags(ofInventory);
  6745. }
  6746. break;
  6747. case TK_ConModeInvest:
  6748. {
  6749. if (GetViewMode() != vmOverride && trekClient.m_fm.IsConnected()
  6750. && trekClient.MyMission()->AllowDevelopments())
  6751. {
  6752. TurnOffOverlayFlags(c_omBanishablePanes & ~ofInvestment);
  6753. ToggleOverlayFlags(ofInvestment);
  6754. }
  6755. }
  6756. break;
  6757. case TK_ConModeTeam:
  6758. {
  6759. TurnOffOverlayFlags(c_omBanishablePanes & ~(ofTeam | ofExpandedTeam));
  6760. if (GetViewMode() != vmOverride)
  6761. {
  6762. if (GetOverlayFlags() & ofTeam)
  6763. {
  6764. TurnOnOverlayFlags(ofExpandedTeam);
  6765. TurnOffOverlayFlags(ofTeam);
  6766. }
  6767. else if (GetOverlayFlags() & ofExpandedTeam)
  6768. {
  6769. TurnOffOverlayFlags(ofExpandedTeam);
  6770. }
  6771. else
  6772. {
  6773. TurnOnOverlayFlags(ofExpandedTeam);
  6774. }
  6775. }
  6776. }
  6777. break;
  6778. case TK_ConModeMiniTeam:
  6779. {
  6780. TurnOffOverlayFlags(c_omBanishablePanes & ~(ofTeam | ofExpandedTeam));
  6781. if ((GetViewMode() != vmOverride) && trekClient.m_fm.IsConnected())
  6782. {
  6783. if (GetOverlayFlags() & ofTeam)
  6784. {
  6785. TurnOffOverlayFlags(ofTeam);
  6786. }
  6787. else if (GetOverlayFlags() & ofExpandedTeam)
  6788. {
  6789. TurnOnOverlayFlags(ofTeam);
  6790. TurnOffOverlayFlags(ofExpandedTeam);
  6791. }
  6792. else
  6793. {
  6794. TurnOnOverlayFlags(ofTeam);
  6795. }
  6796. UpdateOverlayFlags();
  6797. }
  6798. }
  6799. break;
  6800. case TK_ConModeTeleport:
  6801. {
  6802. TurnOffOverlayFlags(c_omBanishablePanes & ~ofTeleportPane);
  6803. if (trekClient.GetShip()->GetStation() && !trekClient.GetShip()->IsGhost())
  6804. {
  6805. SetViewMode(vmHangar);
  6806. if (GetOverlayFlags() & ofTeleportPane)
  6807. TurnOffOverlayFlags(ofTeleportPane);
  6808. else
  6809. TurnOnOverlayFlags(ofTeleportPane);
  6810. }
  6811. }
  6812. break;
  6813. case TK_TargetHostile: // target the thing that has done the most damage to me recently
  6814. {
  6815. DamageTrack* pdt = trekClient.GetShip()->GetDamageTrack();
  6816. assert (pdt);
  6817. int n = pdt->GetDamageBuckets()->n();
  6818. if (n > 0)
  6819. {
  6820. DamageBucketLink* pdbl = pdt->GetDamageBuckets()->first();
  6821. assert (pdbl);
  6822. ImodelIGC* pmodel = pdbl->data()->model();
  6823. if ((n > 1) && (trekClient.GetShip()->GetCommandTarget(c_cmdCurrent) == pmodel))
  6824. {
  6825. assert (pdbl->next());
  6826. pmodel = pdbl->next()->data()->model();
  6827. }
  6828. SetTarget(pmodel, c_cidDefault);
  6829. }
  6830. else
  6831. {
  6832. TrekFindTarget((c_ttShip | c_ttEnemy | c_ttNearest), tk, TK_TargetEnemyNearest, TK_TargetEnemyPrev, c_habmRescue | c_habmMiner | c_habmBuilder);
  6833. }
  6834. }
  6835. break;
  6836. case TK_TargetCenter: // target the ship closest to the reticle
  6837. {
  6838. if (trekClient.flyingF())
  6839. {
  6840. const Orientation* porientation = &(trekClient.GetShip()->GetOrientation());
  6841. IshipIGC* pship = trekClient.GetShip()->GetParentShip();
  6842. if (pship)
  6843. {
  6844. Mount turretID = trekClient.GetShip()->GetTurretID();
  6845. if (turretID == NA)
  6846. porientation = &(pship->GetOrientation());
  6847. }
  6848. else
  6849. pship = trekClient.GetShip();
  6850. ImodelIGC* m = FindTarget(pship,
  6851. (c_ttFront | c_ttAllTypes | c_ttAllSides),
  6852. trekClient.GetShip()->GetCommandTarget(c_cmdCurrent),
  6853. NULL, NULL,
  6854. porientation);
  6855. SetTarget(m, c_cidDefault);
  6856. }
  6857. }
  6858. break;
  6859. case TK_TargetEnemy:
  6860. case TK_TargetEnemyNearest:
  6861. case TK_TargetEnemyPrev:
  6862. {
  6863. TrekFindTarget((c_ttShip | c_ttEnemy), tk, TK_TargetEnemyNearest, TK_TargetEnemyPrev, c_habmRescue | c_habmMiner | c_habmBuilder);
  6864. }
  6865. break;
  6866. case TK_TargetEnemyBomber:
  6867. case TK_TargetEnemyBomberNearest:
  6868. case TK_TargetEnemyBomberPrev:
  6869. {
  6870. TrekFindTarget((c_ttShip | c_ttEnemy), tk, TK_TargetEnemyBomberNearest, TK_TargetEnemyBomberPrev, c_habmThreatToStation);
  6871. }
  6872. break;
  6873. case TK_TargetEnemyFighter:
  6874. case TK_TargetEnemyFighterNearest:
  6875. case TK_TargetEnemyFighterPrev:
  6876. {
  6877. TrekFindTarget((c_ttShip | c_ttEnemy), tk, TK_TargetEnemyFighterNearest, TK_TargetEnemyFighterPrev, c_habmFighter);
  6878. }
  6879. break;
  6880. case TK_TargetEnemyMiner:
  6881. case TK_TargetEnemyMinerNearest:
  6882. case TK_TargetEnemyMinerPrev:
  6883. {
  6884. TrekFindTarget((c_ttShip | c_ttEnemy), tk, TK_TargetEnemyMinerNearest, TK_TargetEnemyMinerPrev, c_habmMiner);
  6885. }
  6886. break;
  6887. case TK_TargetEnemyConstructor:
  6888. case TK_TargetEnemyConstructorNearest:
  6889. case TK_TargetEnemyConstructorPrev:
  6890. {
  6891. TrekFindTarget((c_ttShip | c_ttEnemy), tk, TK_TargetEnemyConstructorNearest, TK_TargetEnemyConstructorPrev, c_habmBuilder);
  6892. }
  6893. break;
  6894. case TK_TargetEnemyBase:
  6895. case TK_TargetEnemyBaseNearest:
  6896. case TK_TargetEnemyBasePrev:
  6897. {
  6898. TrekFindTarget((c_ttStation | c_ttEnemy | c_ttAnyCluster), tk, TK_TargetEnemyBaseNearest, TK_TargetEnemyBasePrev, ~c_sabmPedestal);
  6899. }
  6900. break;
  6901. case TK_TargetEnemyMajorBase:
  6902. case TK_TargetEnemyMajorBaseNearest:
  6903. case TK_TargetEnemyMajorBasePrev:
  6904. {
  6905. TrekFindTarget((c_ttStation | c_ttEnemy | c_ttAnyCluster), tk, TK_TargetEnemyMajorBaseNearest, TK_TargetEnemyMajorBasePrev, c_sabmFlag);
  6906. }
  6907. break;
  6908. case TK_TargetFriendlyBase:
  6909. case TK_TargetFriendlyBaseNearest:
  6910. case TK_TargetFriendlyBasePrev:
  6911. {
  6912. int ttMask = (c_ttStation | c_ttFriendly | c_ttAnyCluster);
  6913. AbilityBitMask abm = c_sabmLand;
  6914. {
  6915. IhullTypeIGC* pht = trekClient.GetShip()->GetSourceShip()->GetBaseHullType();
  6916. if (pht)
  6917. {
  6918. HullAbilityBitMask habm = pht->GetCapabilities();
  6919. if (habm & c_habmLifepod)
  6920. {
  6921. abm = c_sabmRescue | c_sabmRescueAny | c_sabmLand;
  6922. ttMask |= c_ttProbe;
  6923. }
  6924. else if ((habm & c_habmFighter) == 0)
  6925. abm = c_sabmCapLand;
  6926. }
  6927. }
  6928. TrekFindTarget(ttMask, tk, TK_TargetFriendlyBaseNearest, TK_TargetFriendlyBasePrev,
  6929. abm);
  6930. }
  6931. break;
  6932. case TK_TargetFriendlyMajorBase:
  6933. case TK_TargetFriendlyMajorBaseNearest:
  6934. case TK_TargetFriendlyMajorBasePrev:
  6935. {
  6936. TrekFindTarget((c_ttStation | c_ttFriendly | c_ttAnyCluster), tk, TK_TargetFriendlyMajorBaseNearest, TK_TargetFriendlyMajorBasePrev, c_sabmFlag);
  6937. }
  6938. break;
  6939. case TK_Target:
  6940. case TK_TargetNearest:
  6941. case TK_TargetPrev:
  6942. {
  6943. ImodelIGC* pmodel = trekClient.GetShip()->GetCommandTarget(c_cmdCurrent);
  6944. TrekFindTarget(pmodel && (pmodel != trekClient.GetShip())
  6945. ? GetSimilarTargetMask(pmodel)
  6946. : (c_ttShipTypes | c_ttEnemy),
  6947. tk, TK_TargetNearest, TK_TargetPrev);
  6948. }
  6949. break;
  6950. case TK_TargetFriendly:
  6951. case TK_TargetFriendlyNearest:
  6952. case TK_TargetFriendlyPrev:
  6953. {
  6954. TrekFindTarget((c_ttShip | c_ttFriendly), tk, TK_TargetFriendlyNearest, TK_TargetFriendlyPrev);
  6955. }
  6956. break;
  6957. case TK_TargetFriendlyBomber:
  6958. case TK_TargetFriendlyBomberNearest:
  6959. case TK_TargetFriendlyBomberPrev:
  6960. {
  6961. TrekFindTarget((c_ttShip | c_ttFriendly), tk, TK_TargetFriendlyBomberNearest, TK_TargetFriendlyBomberPrev, c_habmThreatToStation);
  6962. }
  6963. break;
  6964. case TK_TargetFriendlyFighter:
  6965. case TK_TargetFriendlyFighterNearest:
  6966. case TK_TargetFriendlyFighterPrev:
  6967. {
  6968. TrekFindTarget((c_ttShip | c_ttFriendly), tk, TK_TargetFriendlyFighterNearest, TK_TargetFriendlyFighterPrev, c_habmFighter);
  6969. }
  6970. break;
  6971. case TK_TargetFriendlyMiner:
  6972. case TK_TargetFriendlyMinerNearest:
  6973. case TK_TargetFriendlyMinerPrev:
  6974. {
  6975. TrekFindTarget((c_ttShip | c_ttFriendly), tk, TK_TargetFriendlyMinerNearest, TK_TargetFriendlyMinerPrev, c_habmMiner);
  6976. }
  6977. break;
  6978. case TK_TargetFriendlyConstructor:
  6979. case TK_TargetFriendlyConstructorNearest:
  6980. case TK_TargetFriendlyConstructorPrev:
  6981. {
  6982. TrekFindTarget((c_ttShip | c_ttFriendly), tk, TK_TargetFriendlyConstructorNearest, TK_TargetFriendlyConstructorPrev, c_habmBuilder);
  6983. }
  6984. break;
  6985. case TK_TargetFriendlyLifepod:
  6986. case TK_TargetFriendlyLifepodNearest:
  6987. case TK_TargetFriendlyLifepodPrev:
  6988. {
  6989. TrekFindTarget((c_ttShip | c_ttFriendly), tk, TK_TargetFriendlyLifepodNearest, TK_TargetFriendlyLifepodPrev, c_habmLifepod);
  6990. }
  6991. break;
  6992. case TK_TargetArtifact:
  6993. case TK_TargetArtifactNearest:
  6994. case TK_TargetArtifactPrev:
  6995. {
  6996. TrekFindTarget((c_ttTreasure | c_ttNeutral), tk, TK_TargetArtifactNearest, TK_TargetArtifactPrev, 1);
  6997. }
  6998. break;
  6999. case TK_TargetFlag:
  7000. case TK_TargetFlagNearest:
  7001. case TK_TargetFlagPrev:
  7002. {
  7003. TrekFindTarget((c_ttTreasure | c_ttEnemy), tk, TK_TargetFlagNearest, TK_TargetFlagPrev, 1);
  7004. }
  7005. break;
  7006. case TK_TargetWarp:
  7007. case TK_TargetWarpNearest:
  7008. case TK_TargetWarpPrev:
  7009. {
  7010. TrekFindTarget((c_ttWarp | c_ttNeutral), tk, TK_TargetWarpNearest, TK_TargetWarpPrev);
  7011. }
  7012. break;
  7013. case TK_ToggleAutoPilot:
  7014. {
  7015. if (trekClient.autoPilot())
  7016. {
  7017. trekClient.SetAutoPilot(false);
  7018. SwitchToJoyThrottle();
  7019. trekClient.PlaySoundEffect(salAutopilotDisengageSound);
  7020. }
  7021. else if ((trekClient.GetShip()->GetParentShip() == NULL) && (trekClient.GetShip()->GetStation() == NULL))
  7022. {
  7023. //m_timeAutopilotWarning = Time::Now();
  7024. trekClient.SetAutoPilot(true);
  7025. trekClient.bInitTrekJoyStick = true;
  7026. trekClient.PlaySoundEffect(salAutopilotEngageSound);
  7027. }
  7028. }
  7029. break;
  7030. case TK_VoteYes:
  7031. {
  7032. trekClient.Vote(true);
  7033. }
  7034. break;
  7035. case TK_VoteNo:
  7036. {
  7037. trekClient.Vote(false);
  7038. }
  7039. break;
  7040. case TK_ExecuteCommand:
  7041. case TK_AcceptCommand: // queued command becomes accepted command
  7042. {
  7043. AcceptQueuedCommand(tk == TK_ExecuteCommand);
  7044. }
  7045. break;
  7046. case TK_RejectCommand:
  7047. {
  7048. RejectQueuedCommand(true, true);
  7049. }
  7050. break;
  7051. case TK_ClearCommand: // clear accepted command
  7052. {
  7053. SetAccepted(NULL, c_cidNone);
  7054. }
  7055. break;
  7056. case TK_TargetCommand:
  7057. {
  7058. SetTarget(trekClient.GetShip()->GetCommandTarget(c_cmdAccepted),
  7059. trekClient.GetShip()->GetCommandID(c_cmdAccepted));
  7060. }
  7061. break;
  7062. case TK_LODUp:
  7063. {
  7064. m_pscrollPane->PageUp();
  7065. }
  7066. break;
  7067. case TK_LODDown:
  7068. {
  7069. m_pscrollPane->PageDown();
  7070. }
  7071. break;
  7072. case TK_Suicide:
  7073. {
  7074. suicideF = true;
  7075. }
  7076. break;
  7077. case TK_ToggleGrid:
  7078. {
  7079. m_bCommandGrid = !m_bCommandGrid;
  7080. }
  7081. break;
  7082. case TK_TargetSelf:
  7083. {
  7084. SetTarget(trekClient.GetShip(), c_cidNone);
  7085. }
  7086. break;
  7087. case TK_TargetNothing:
  7088. {
  7089. SetTarget(NULL, c_cidNone);
  7090. }
  7091. break;
  7092. case TK_OccupyNextTurret:
  7093. {
  7094. IshipIGC* pship = trekClient.GetShip()->GetParentShip();
  7095. if (pship)
  7096. {
  7097. trekClient.SetMessageType(BaseClient::c_mtGuaranteed);
  7098. BEGIN_PFM_CREATE(trekClient.m_fm, pfmBoardShip, C, BOARD_SHIP)
  7099. END_PFM_CREATE;
  7100. pfmBoardShip->sidParent = pship->GetObjectID();
  7101. }
  7102. }
  7103. break;
  7104. case TK_DebugTest1:
  7105. case TK_DebugTest2:
  7106. case TK_DebugTest3:
  7107. case TK_DebugTest4:
  7108. case TK_DebugTest5:
  7109. case TK_DebugTest6:
  7110. case TK_DebugTest7:
  7111. case TK_DebugTest8:
  7112. case TK_DebugTest9:
  7113. {
  7114. // do nothing
  7115. }
  7116. break;
  7117. default:
  7118. return;
  7119. }
  7120. if (suicideF)
  7121. {
  7122. // 3 seconds to hit the sequence of keys
  7123. if (m_suicideCount++ == 0)
  7124. m_suicideTime = Time::Now();
  7125. else if (Time::Now().clock() - m_suicideTime.clock() > 3000)
  7126. {
  7127. assert (m_suicideCount != 0);
  7128. m_suicideCount = 0;
  7129. }
  7130. else if (m_suicideCount == 3)
  7131. {
  7132. m_suicideCount = 0;
  7133. if (trekClient.m_fm.IsConnected())
  7134. {
  7135. trekClient.SetMessageType(BaseClient::c_mtGuaranteed);
  7136. BEGIN_PFM_CREATE(trekClient.m_fm, pfm, C, SUICIDE)
  7137. END_PFM_CREATE
  7138. }
  7139. else
  7140. trekClient.KillShipEvent(Time::Now(), trekClient.GetShip(), NULL, 1.0f, trekClient.GetShip()->GetPosition(), Vector::GetZero());
  7141. }
  7142. }
  7143. else
  7144. {
  7145. m_suicideCount = 0;
  7146. }
  7147. }
  7148. void RejectQueuedCommand(bool bClear = true, bool bNegative = false)
  7149. {
  7150. if (trekClient.GetLastMoneyRequest() != 0)
  7151. {
  7152. trekClient.SetLastMoneyRequest(0);
  7153. IshipIGC* pshipSender = trekClient.GetLastSender();
  7154. if (pshipSender)
  7155. {
  7156. if (bNegative)
  7157. {
  7158. if (pshipSender != trekClient.GetShip())
  7159. {
  7160. trekClient.SendChat(trekClient.GetShip(), CHAT_INDIVIDUAL, pshipSender->GetObjectID(),
  7161. voNegativeSound, "Negative.");
  7162. }
  7163. }
  7164. trekClient.SetLastSender(NULL);
  7165. }
  7166. }
  7167. else if (trekClient.GetShip()->GetCommandID(c_cmdQueued) != c_cidNone)
  7168. {
  7169. if (bClear)
  7170. trekClient.GetShip()->SetCommand(c_cmdQueued, NULL, c_cidNone);
  7171. IshipIGC* pshipSender = trekClient.GetLastSender();
  7172. if (pshipSender)
  7173. {
  7174. if (bNegative)
  7175. {
  7176. if (pshipSender != trekClient.GetShip())
  7177. {
  7178. trekClient.SendChat(trekClient.GetShip(), CHAT_INDIVIDUAL, pshipSender->GetObjectID(),
  7179. voNegativeSound, "Negative.");
  7180. }
  7181. }
  7182. trekClient.SetLastSender(NULL);
  7183. }
  7184. }
  7185. m_timeRejectQueuedCommand = trekClient.m_now + (3600.0f * 24.0f * 20.0f); //20 days in the future
  7186. }
  7187. void AcceptQueuedCommand(bool bExecute)
  7188. {
  7189. IshipIGC* pshipSender = trekClient.GetLastSender();
  7190. Money request = trekClient.GetLastMoneyRequest();
  7191. if (request != 0)
  7192. {
  7193. if (pshipSender && (pshipSender != trekClient.GetShip()))
  7194. {
  7195. Money m = trekClient.GetMoney();
  7196. if (request > m)
  7197. request = m;
  7198. if (request > 0)
  7199. {
  7200. PlayerInfo* pplayerSender = trekClient.FindPlayer(pshipSender->GetObjectID());
  7201. if (pplayerSender)
  7202. trekClient.DonateMoney(pplayerSender, request);
  7203. }
  7204. trekClient.SetLastMoneyRequest(0);
  7205. }
  7206. }
  7207. else
  7208. {
  7209. CommandID cid = trekClient.GetShip()->GetCommandID(c_cmdQueued);
  7210. if (cid != c_cidNone)
  7211. {
  7212. ImodelIGC* pmodel = trekClient.GetShip()->GetCommandTarget(c_cmdQueued);
  7213. if (pmodel && trekClient.GetShip()->LegalCommand(cid, pmodel))
  7214. {
  7215. trekClient.PlaySoundEffect(acceptCommandSound);
  7216. if (cid == c_cidJoin)
  7217. {
  7218. if (pmodel->GetObjectType() == OT_ship)
  7219. trekClient.SetWing(((IshipIGC*)pmodel)->GetWingID());
  7220. }
  7221. else
  7222. {
  7223. if ((cid == c_cidPickup) &&
  7224. (pmodel->GetObjectType() == OT_ship) &&
  7225. trekClient.GetShip()->GetBaseHullType()->HasCapability(c_habmRescue))
  7226. {
  7227. //Tell the other person to pick me up as well
  7228. trekClient.SendChat(trekClient.GetShip(),
  7229. CHAT_INDIVIDUAL,
  7230. pmodel->GetObjectID(),
  7231. NA,
  7232. NULL,
  7233. c_cidPickup,
  7234. OT_ship,
  7235. trekClient.GetShipID(),
  7236. trekClient.GetShip());
  7237. }
  7238. SetTarget(pmodel, cid);
  7239. SetAccepted(pmodel, cid);
  7240. if (bExecute &&
  7241. (trekClient.GetShip()->GetStation() == NULL) &&
  7242. (trekClient.GetShip()->GetParentShip() == NULL) &&
  7243. trekClient.GetCluster(trekClient.GetShip(), pmodel))
  7244. {
  7245. trekClient.SetAutoPilot(true);
  7246. trekClient.bInitTrekJoyStick = true;
  7247. trekClient.PlaySoundEffect(salAutopilotEngageSound);
  7248. }
  7249. }
  7250. trekClient.GetShip()->SetCommand(c_cmdQueued, NULL, c_cidNone);
  7251. }
  7252. }
  7253. }
  7254. if (pshipSender)
  7255. {
  7256. if (pshipSender != trekClient.GetShip())
  7257. trekClient.SendChat(trekClient.GetShip(), CHAT_INDIVIDUAL, pshipSender->GetObjectID(),
  7258. voAffirmativeSound, "Affirmative.");
  7259. trekClient.SetLastSender(NULL);
  7260. }
  7261. m_timeRejectQueuedCommand = trekClient.m_now + (3600.0f * 24.0f * 20.0f); //20 days in the future
  7262. }
  7263. void SetQueuedCommand(IshipIGC* pshipSender,
  7264. CommandID cid,
  7265. ImodelIGC* pmodelTarget)
  7266. {
  7267. if (pshipSender != trekClient.GetLastSender())
  7268. RejectQueuedCommand();
  7269. if (!Training::IsTraining ())
  7270. m_timeRejectQueuedCommand = trekClient.m_now + c_dtRejectQueuedCommand;
  7271. trekClient.SetLastSender(pshipSender);
  7272. trekClient.SetLastMoneyRequest(0);
  7273. trekClient.GetShip()->SetCommand(c_cmdQueued, pmodelTarget, cid);
  7274. }
  7275. void SetQueuedCommand(IshipIGC* pshipSender,
  7276. Money money,
  7277. HullID hid)
  7278. {
  7279. if (pshipSender != trekClient.GetLastSender())
  7280. RejectQueuedCommand();
  7281. m_timeRejectQueuedCommand = trekClient.m_now + c_dtRejectQueuedCommand;
  7282. trekClient.SetLastSender(pshipSender);
  7283. trekClient.SetLastMoneyRequest(money);
  7284. trekClient.GetShip()->SetCommand(c_cmdQueued, NULL, c_cidNone);
  7285. if ((pshipSender != trekClient.GetShip()) && GetWindow()->GetConsoleImage())
  7286. {
  7287. static const ZString c_str1(" has requested $");
  7288. static const ZString c_str2(" to buy a ");
  7289. static const ZString c_str3(" Press the [Insert] key to approve it.");
  7290. assert (pshipSender);
  7291. IhullTypeIGC* pht = trekClient.m_pCoreIGC->GetHullType(hid);
  7292. assert (pht);
  7293. trekClient.PostText(true, "%s",
  7294. (const char*)((pshipSender->GetName() + c_str1) +
  7295. (ZString(money) + c_str2) +
  7296. (pht->GetName() + c_str3)));
  7297. }
  7298. }
  7299. TRef<ChatListPane> m_pchatListPane;
  7300. void SetChatListPane(ChatListPane* pchatListPane)
  7301. {
  7302. m_pchatListPane = pchatListPane;
  7303. }
  7304. void SetLobbyChatTarget(ChatTarget ct)
  7305. {
  7306. m_ctLobbyChat = ct;
  7307. }
  7308. ChatTarget GetLobbyChatTarget()
  7309. {
  7310. return m_ctLobbyChat;
  7311. }
  7312. float MapJoystick(float value)
  7313. {
  7314. if (value > g_fJoystickDeadZone)
  7315. value = (value - g_fJoystickDeadZone) / g_fInverseJoystickDeadZone;
  7316. else if (value < -g_fJoystickDeadZone)
  7317. value = (value + g_fJoystickDeadZone) / g_fInverseJoystickDeadZone;
  7318. else
  7319. value = 0.0f;
  7320. if (!m_bLinearControls)
  7321. value *= fabsf (value);
  7322. return value;
  7323. }
  7324. void SwitchToJoyThrottle(void)
  7325. {
  7326. if (m_ptrekInput->IsAxisValid(3))
  7327. {
  7328. trekClient.joyThrottle = true;
  7329. }
  7330. else
  7331. {
  7332. trekClient.trekThrottle = GetThrottle(trekClient.GetShip());
  7333. }
  7334. }
  7335. bool SenseJoystick(JoystickResults* js, bool bInternalCamera, bool bReadKeyboard)
  7336. {
  7337. bool bThrottleChange = false;
  7338. //
  7339. // Read the joystick
  7340. //
  7341. if (m_pjoystickImage->GetJoystickEnabled()) {
  7342. js->controls.jsValues[c_axisYaw ] = m_pjoystickImage->GetValue(0)->GetValue();
  7343. js->controls.jsValues[c_axisPitch] = m_pjoystickImage->GetValue(1)->GetValue();
  7344. js->controls.jsValues[c_axisRoll ] = 0;
  7345. } else {
  7346. if (m_ptrekInput->IsTrekKeyDown(TK_RollModifier, bReadKeyboard)) {
  7347. js->controls.jsValues[c_axisYaw ] = 0;
  7348. js->controls.jsValues[c_axisRoll] = MapJoystick(m_ptrekInput->GetAxis(0));
  7349. } else {
  7350. js->controls.jsValues[c_axisYaw ] = MapJoystick(m_ptrekInput->GetAxis(0));
  7351. js->controls.jsValues[c_axisRoll] = MapJoystick(m_ptrekInput->GetAxis(2));
  7352. }
  7353. js->controls.jsValues[c_axisPitch ] = MapJoystick(m_ptrekInput->GetAxis(1));
  7354. }
  7355. js->controls.jsValues[c_axisThrottle] = -m_ptrekInput->GetAxis(3);
  7356. js->hat = m_ptrekInput->GetAxis(4) * pi;
  7357. //
  7358. // Flip the y axis if requested
  7359. //
  7360. if (m_bFlipY) {
  7361. js->controls.jsValues[c_axisPitch] = -js->controls.jsValues[c_axisPitch];
  7362. }
  7363. //
  7364. // If the throttle system needs to be initialized, we do that. Otherwise, if the joystick
  7365. // throttle has changed significantly, then we start using the joystick throttle.
  7366. //
  7367. if (trekClient.bInitTrekThrottle)
  7368. {
  7369. // see Training::StartMission for initialization of trekClient.trekThrottle
  7370. // it is 1.0f for on-line play, and -1.0f for off-line.
  7371. trekClient.joyThrottle = false;
  7372. trekClient.fOldJoyThrottle = js->controls.jsValues[c_axisThrottle];
  7373. trekClient.bInitTrekThrottle = false;
  7374. }
  7375. else if (fabs(js->controls.jsValues[c_axisThrottle] - trekClient.fOldJoyThrottle) > g_fJoystickDeadZone)
  7376. {
  7377. bThrottleChange = true;
  7378. trekClient.joyThrottle = true;
  7379. }
  7380. //
  7381. // Read buttons and keyboard
  7382. //
  7383. bool newButton1 = m_ptrekInput->IsTrekKeyDown(TK_FireWeapon , bReadKeyboard);
  7384. bool newButton2 = m_ptrekInput->IsTrekKeyDown(TK_FireMissile, bReadKeyboard);
  7385. bool newButton3 = m_ptrekInput->IsTrekKeyDown(TK_FireBooster, bReadKeyboard);
  7386. //bool newButton4 = m_ptrekInput->GetButton(3); // !!! was next weapon
  7387. //bool newButton5 = m_ptrekInput->GetButton(4); // !!! was vector lock
  7388. bool newButton6 = m_ptrekInput->IsTrekKeyDown(TK_MatchSpeed , bReadKeyboard);
  7389. if (bInternalCamera)
  7390. {
  7391. // roll left/right
  7392. if (m_ptrekInput->IsTrekKeyDown(TK_RollRight, bReadKeyboard)) {
  7393. js->controls.jsValues[c_axisRoll] = -1.0f;
  7394. } else if (m_ptrekInput->IsTrekKeyDown(TK_RollLeft, bReadKeyboard)) {
  7395. js->controls.jsValues[c_axisRoll] = 1.0f;
  7396. }
  7397. // yaw left/right
  7398. if (m_ptrekInput->IsTrekKeyDown(TK_RollModifier, bReadKeyboard)) {
  7399. if (m_ptrekInput->IsTrekKeyDown(TK_YawRight, bReadKeyboard)) {
  7400. js->controls.jsValues[c_axisRoll] = -1.0f;
  7401. } else if (m_ptrekInput->IsTrekKeyDown(TK_YawLeft, bReadKeyboard)) {
  7402. js->controls.jsValues[c_axisRoll] = 1.0f;
  7403. }
  7404. } else {
  7405. if (m_ptrekInput->IsTrekKeyDown(TK_YawRight, bReadKeyboard)) {
  7406. js->controls.jsValues[c_axisYaw] = -1.0f;
  7407. } else if (m_ptrekInput->IsTrekKeyDown(TK_YawLeft, bReadKeyboard)) {
  7408. js->controls.jsValues[c_axisYaw] = 1.0f;
  7409. }
  7410. }
  7411. // up/down == pitch
  7412. if (m_ptrekInput->IsTrekKeyDown(TK_PitchDown, bReadKeyboard)) {
  7413. js->controls.jsValues[c_axisPitch] = -1.0f;
  7414. } else if (m_ptrekInput->IsTrekKeyDown(TK_PitchUp, bReadKeyboard)) {
  7415. js->controls.jsValues[c_axisPitch] = 1.0f;
  7416. }
  7417. if (m_ptrekInput->IsTrekKeyDown(TK_ThrottleUp, bReadKeyboard))
  7418. {
  7419. trekClient.trekThrottle =
  7420. (trekClient.trekThrottle < 0.8f)
  7421. ? (trekClient.trekThrottle + 0.2f)
  7422. : 1.0f;
  7423. trekClient.joyThrottle = false;
  7424. bThrottleChange = true;
  7425. }
  7426. else if (m_ptrekInput->IsTrekKeyDown(TK_ThrottleDown, bReadKeyboard))
  7427. {
  7428. trekClient.trekThrottle =
  7429. (trekClient.trekThrottle > -0.8f)
  7430. ? (trekClient.trekThrottle - 0.2f)
  7431. : -1.0f;
  7432. trekClient.joyThrottle = false;
  7433. bThrottleChange = true;
  7434. }
  7435. }
  7436. if (m_ptrekInput->IsTrekKeyDown(TK_ThrottleZero, bReadKeyboard))
  7437. {
  7438. trekClient.trekThrottle = -1.0f;
  7439. trekClient.joyThrottle = false;
  7440. bThrottleChange = true;
  7441. }
  7442. else if (m_ptrekInput->IsTrekKeyDown(TK_Throttle33, bReadKeyboard))
  7443. {
  7444. trekClient.trekThrottle = -0.3f;
  7445. trekClient.joyThrottle = false;
  7446. bThrottleChange = true;
  7447. }
  7448. else if (m_ptrekInput->IsTrekKeyDown(TK_Throttle66, bReadKeyboard))
  7449. {
  7450. trekClient.trekThrottle = 0.3f;
  7451. trekClient.joyThrottle = false;
  7452. bThrottleChange = true;
  7453. }
  7454. else if (m_ptrekInput->IsTrekKeyDown(TK_ThrottleFull, bReadKeyboard))
  7455. {
  7456. trekClient.trekThrottle = 1.0f;
  7457. trekClient.joyThrottle = false;
  7458. bThrottleChange = true;
  7459. }
  7460. //
  7461. // Handle match speed
  7462. //
  7463. if (newButton6)
  7464. {
  7465. ImodelIGC* pmodel = GetCurrentTarget();
  7466. if (pmodel)
  7467. {
  7468. trekClient.trekThrottle = GetThrottle(pmodel);
  7469. trekClient.joyThrottle = false;
  7470. bThrottleChange = true;
  7471. }
  7472. }
  7473. if (trekClient.joyThrottle)
  7474. {
  7475. trekClient.fOldJoyThrottle = js->controls.jsValues[c_axisThrottle];
  7476. }
  7477. else
  7478. {
  7479. js->controls.jsValues[c_axisThrottle] = trekClient.trekThrottle;
  7480. }
  7481. // Process joystick buttons, keeping track of whether the button has changed
  7482. // since the last poll.
  7483. static bool oldButton1 = false;
  7484. static bool oldButton2 = false;
  7485. static bool oldButton3 = false;
  7486. //static bool oldButton4 = false;
  7487. //static bool oldButton5 = false;
  7488. static bool oldButton6 = false;
  7489. js->button1 = (newButton1 ? buttonDown : 0x00) | (newButton1 != oldButton1 ? buttonChanged : 0x00);
  7490. js->button2 = (newButton2 ? buttonDown : 0x00) | (newButton2 != oldButton2 ? buttonChanged : 0x00);
  7491. js->button3 = (newButton3 ? buttonDown : 0x00) | (newButton3 != oldButton3 ? buttonChanged : 0x00);
  7492. //!!!js->button4 = (newButton4 ? buttonDown : 0x00) | (newButton4 != oldButton4 ? buttonChanged : 0x00);
  7493. //!!!js->button5 = (newButton5 ? buttonDown : 0x00) | (newButton5 != oldButton5 ? buttonChanged : 0x00);
  7494. js->button4 = 0;
  7495. js->button5 = 0;
  7496. js->button6 = (newButton6 ? buttonDown : 0x00) | (newButton6 != oldButton6 ? buttonChanged : 0x00);
  7497. oldButton1 = newButton1;
  7498. oldButton2 = newButton2;
  7499. oldButton3 = newButton3;
  7500. //oldButton4 = newButton4;
  7501. //oldButton5 = newButton5;
  7502. oldButton6 = newButton6;
  7503. return bThrottleChange;
  7504. }
  7505. HRESULT HandleMsg(FEDMESSAGE* pfm, Time lastUpdate, Time now)
  7506. {
  7507. HRESULT hr = S_OK; //handled by default
  7508. switch(pfm->fmid)
  7509. {
  7510. case FM_S_LOGONACK:
  7511. {
  7512. CASTPFM(pfmLogonAck, S, LOGONACK, pfm);
  7513. if (!pfmLogonAck->fValidated)
  7514. hr = S_FALSE; // don't do anything mission control will handle
  7515. }
  7516. break;
  7517. case FM_S_GAME_OVER:
  7518. {
  7519. CASTPFM(pfmGameOver, S, GAME_OVER, pfm);
  7520. TriggerMusic(pfmGameOver->iSideWinner == trekClient.GetSide()->GetObjectID()
  7521. ? gameOverWonMusicSound
  7522. : gameOverLostMusicSound);
  7523. trekClient.SetGameoverInfo(pfmGameOver);
  7524. if (trekClient.GetSideID() != SIDE_TEAMLOBBY)
  7525. screen(ScreenIDGameOverScreen);
  7526. }
  7527. break;
  7528. case FM_S_GAME_OVER_PLAYERS:
  7529. {
  7530. CASTPFM(pfmGameoverPlayers, S, GAME_OVER_PLAYERS, pfm);
  7531. int nCount = pfmGameoverPlayers->cbrgPlayerInfo / sizeof(PlayerEndgameInfo);
  7532. PlayerEndgameInfo* vPlayerEndgameInfo
  7533. = (PlayerEndgameInfo*)FM_VAR_REF(pfmGameoverPlayers, rgPlayerInfo);
  7534. trekClient.AddGameoverPlayers(vPlayerEndgameInfo, nCount);
  7535. }
  7536. break;
  7537. case FM_S_ICQ_CHAT_ACK:
  7538. {
  7539. CASTPFM(pfmICQChat, S, ICQ_CHAT_ACK, pfm);
  7540. __try
  7541. {
  7542. static bool fICQInit = false;
  7543. if (!fICQInit)
  7544. {
  7545. ICQAPICall_SetLicenseKey("Microsoft", "hankukkk", "EDB699A39FE5BAE8");
  7546. fICQInit = true;
  7547. }
  7548. ICQAPICall_SendMessage(pfmICQChat->icqid, FM_VAR_REF(pfmICQChat, Message));
  7549. //ICQAPICall_SendExternal(pfmICQChat->icqid, "", FM_VAR_REF(pfmICQChat, Message), true);
  7550. }
  7551. __except(DelayLoadDllExceptionFilter(GetExceptionInformation()))
  7552. {
  7553. // nothing to do here
  7554. }
  7555. }
  7556. break;
  7557. case FM_S_TREASURE_SETS:
  7558. {
  7559. // NYI
  7560. }
  7561. break;
  7562. default:
  7563. {
  7564. hr = S_FALSE;
  7565. }
  7566. }
  7567. return hr;
  7568. }
  7569. void TerminateModelEvent(ImodelIGC* model)
  7570. {
  7571. ObjectType type = model->GetObjectType();
  7572. if (type == OT_ship)
  7573. {
  7574. //A ship died ... do we need to do anything special?
  7575. if (model == trekClient.GetShip())
  7576. {
  7577. //m_pconsoleImage->SetConsoleMode(c_cmNone);
  7578. }
  7579. }
  7580. }
  7581. void OnDelPlayer(MissionInfo* pMissionInfo, SideID sideID, PlayerInfo* pPlayerInfo, QuitSideReason reason, const char* szMessageParam)
  7582. {
  7583. if (pPlayerInfo->ShipID() == trekClient.GetShipID() && trekClient.GetSideID() == SIDE_TEAMLOBBY)
  7584. {
  7585. m_nLastCountdown = c_nCountdownMax;
  7586. }
  7587. }
  7588. virtual void OnMissionCountdown(MissionInfo* pMissionDef)
  7589. {
  7590. m_nLastCountdown = c_nCountdownMax;
  7591. trekClient.PlaySoundEffect(countdownStartingSound);
  7592. }
  7593. void CheckCountdownSound()
  7594. {
  7595. if (trekClient.MyMission()
  7596. && (trekClient.MyMission()->GetStage() == STAGE_STARTING
  7597. || (trekClient.MyMission()->GetStage() == STAGE_STARTED
  7598. && trekClient.MyMission()->GetMissionParams().IsCountdownGame())))
  7599. {
  7600. // note: have the timer lag by 1 second to give users the familiar countdown feel
  7601. int nTimeLeft;
  7602. if (trekClient.MyMission()->GetStage() == STAGE_STARTING)
  7603. nTimeLeft = max(0, int(trekClient.MyMission()->GetMissionParams().timeStart - Time::Now()) + 1);
  7604. else
  7605. nTimeLeft = max(0, int(
  7606. trekClient.MyMission()->GetMissionParams().GetCountDownTime()
  7607. - (Time::Now() - trekClient.MyMission()->GetMissionParams().timeStart) + 1));
  7608. if (nTimeLeft != m_nLastCountdown)
  7609. {
  7610. m_nLastCountdown = nTimeLeft;
  7611. switch (m_nLastCountdown)
  7612. {
  7613. case 10 * 60:
  7614. trekClient.PlaySoundEffect(countdown10minSound);
  7615. break;
  7616. case 5 * 60:
  7617. trekClient.PlaySoundEffect(countdown5minSound);
  7618. break;
  7619. case 1 * 60:
  7620. trekClient.PlaySoundEffect(countdown1minSound);
  7621. break;
  7622. case 30:
  7623. trekClient.PlaySoundEffect(countdown30Sound);
  7624. break;
  7625. case 10:
  7626. trekClient.PlaySoundEffect(countdown10Sound);
  7627. break;
  7628. case 9:
  7629. trekClient.PlaySoundEffect(countdown9Sound);
  7630. break;
  7631. case 8:
  7632. trekClient.PlaySoundEffect(countdown8Sound);
  7633. break;
  7634. case 7:
  7635. trekClient.PlaySoundEffect(countdown7Sound);
  7636. break;
  7637. case 6:
  7638. trekClient.PlaySoundEffect(countdown6Sound);
  7639. break;
  7640. case 5:
  7641. trekClient.PlaySoundEffect(countdown5Sound);
  7642. break;
  7643. case 4:
  7644. trekClient.PlaySoundEffect(countdown4Sound);
  7645. break;
  7646. case 3:
  7647. trekClient.PlaySoundEffect(countdown3Sound);
  7648. break;
  7649. case 2:
  7650. trekClient.PlaySoundEffect(countdown2Sound);
  7651. break;
  7652. case 1:
  7653. trekClient.PlaySoundEffect(countdown1Sound);
  7654. break;
  7655. }
  7656. }
  7657. }
  7658. }
  7659. void OnChatMessageChange()
  7660. {
  7661. this->ChangeChatMessage();
  7662. }
  7663. virtual bool OnOK(int result)
  7664. {
  7665. assert(result == IDOK);
  7666. return false;
  7667. }
  7668. //
  7669. // VT functions.
  7670. //
  7671. VOID VTSetText(LPSTR szFormat, ...)
  7672. {
  7673. TCHAR szText[1024];
  7674. va_list vaList;
  7675. INT cchText;
  7676. if (NULL != m_hwndVTEdit)
  7677. {
  7678. cchText = sprintf(szText, "Version=%d,", ++m_cVTVersion);
  7679. va_start(vaList, szFormat);
  7680. vsprintf(szText + cchText, szFormat, vaList);
  7681. va_end(vaList);
  7682. ::SetWindowText(m_hwndVTEdit, szText);
  7683. }
  7684. }
  7685. void SoundEngineUpdate (void)
  7686. {
  7687. ZSucceeded(m_pSoundEngine->Update ());
  7688. }
  7689. TRef<ISoundInstance> StartSound(ISoundTemplate* ptemplate, ISoundPositionSource* psource = NULL)
  7690. {
  7691. if (ptemplate)
  7692. {
  7693. TRef<ISoundInstance> pSoundInstance;
  7694. if (ZSucceeded(ptemplate->CreateSound(pSoundInstance, m_pSoundEngine->GetBufferSource(), psource)))
  7695. {
  7696. return pSoundInstance;
  7697. }
  7698. }
  7699. {
  7700. // may avoid some art crashes in retail builds
  7701. return NULL;
  7702. }
  7703. };
  7704. TRef<ISoundInstance> StartSound(SoundID soundId, ISoundPositionSource* psource = NULL)
  7705. {
  7706. if (soundId < 0 || soundId > m_vSoundMap.GetCount())
  7707. {
  7708. // may avoid some art crashes in retail builds
  7709. ZAssert(false);
  7710. return NULL;
  7711. }
  7712. return StartSound(m_vSoundMap[soundId], psource);
  7713. };
  7714. void StartLockDown(const ZString& strReason)
  7715. {
  7716. ZAssert(m_pmessageBoxLockdown == NULL || trekClient.IsLockedDown());
  7717. if (m_pmessageBoxLockdown)
  7718. GetPopupContainer()->ClosePopup(m_pmessageBoxLockdown);
  7719. if ((GetViewMode() != vmOverride) && (GetViewMode() != vmUI))
  7720. {
  7721. m_pmessageBoxLockdown = CreateMessageBox(strReason, NULL, false, false, 1.0f);
  7722. GetWindow()->SetWaitCursor();
  7723. GetPopupContainer()->OpenPopup(m_pmessageBoxLockdown, false);
  7724. }
  7725. }
  7726. void EndLockDown()
  7727. {
  7728. if (!trekClient.IsLockedDown())
  7729. {
  7730. GetPopupContainer()->ClosePopup(m_pmessageBoxLockdown);
  7731. GetWindow()->RestoreCursor();
  7732. m_pmessageBoxLockdown = NULL;
  7733. }
  7734. }
  7735. };
  7736. TrekWindowImpl::ShipWinConditionInfo TrekWindowImpl::s_shipWinConditionInfo;
  7737. TrekWindowImpl::DeathMatchWinConditionInfo TrekWindowImpl::s_deathMatchWinConditionInfo;
  7738. TrekWindowImpl::DeathMatchShipWinConditionInfo TrekWindowImpl::s_deathMatchShipWinConditionInfo;
  7739. TrekWindowImpl::ConquestWinConditionInfo TrekWindowImpl::s_conquestWinConditionInfo;
  7740. TrekWindowImpl::TerritoryWinConditionInfo TrekWindowImpl::s_territoryWinConditionInfo;
  7741. TrekWindowImpl::ProsperityWinConditionInfo TrekWindowImpl::s_prosperityWinConditionInfo;
  7742. TrekWindowImpl::ArtifactsWinConditionInfo TrekWindowImpl::s_artifactsWinConditionInfo;
  7743. TrekWindowImpl::FlagsWinConditionInfo TrekWindowImpl::s_flagsWinConditionInfo;
  7744. TRef<TrekWindow> TrekWindow::Create(
  7745. EffectApp* papp,
  7746. const ZString& strCommandLine,
  7747. bool bMovies,
  7748. bool bSoftware,
  7749. bool bHardware,
  7750. bool bPrimary,
  7751. bool bSecondary
  7752. ) {
  7753. return
  7754. new TrekWindowImpl(
  7755. papp,
  7756. strCommandLine,
  7757. bMovies,
  7758. bSoftware,
  7759. bHardware,
  7760. bPrimary,
  7761. bSecondary
  7762. );
  7763. }
  7764. // forward squad message to squad screen
  7765. void ForwardSquadMessage(FEDMESSAGE *pSquadMessage);
  7766. void WinTrekClient::ForwardSquadMessage(FEDMESSAGE * pSquadMessage)
  7767. {
  7768. ::ForwardSquadMessage(pSquadMessage);
  7769. }
  7770. // forward CharacterInfo message to CharacterInfo screen
  7771. void ForwardCharInfoMessage(FEDMESSAGE *pCharInfoMessage);
  7772. void WinTrekClient::ForwardCharInfoMessage(FEDMESSAGE * pCharInfoMessage)
  7773. {
  7774. ::ForwardCharInfoMessage(pCharInfoMessage);
  7775. }
  7776. // forward LeaderBoard message to the LeaderBoard screen
  7777. void ForwardLeaderBoardMessage(FEDMESSAGE *pCharInfoMessage);
  7778. void WinTrekClient::ForwardLeaderBoardMessage(FEDMESSAGE * pLeaderBoardMessage)
  7779. {
  7780. ::ForwardLeaderBoardMessage(pLeaderBoardMessage);
  7781. }