bdactor.cpp 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276
  1. //---------------------------------------------------------------------------
  2. //
  3. // bdactor.cpp - This file contains the code for the building and tree appearance classes
  4. //
  5. // MechCommander 2
  6. //
  7. //---------------------------------------------------------------------------//
  8. // Copyright (C) Microsoft Corporation. All rights reserved. //
  9. //===========================================================================//
  10. #ifndef BDACTOR_H
  11. #include "bdactor.h"
  12. #endif
  13. #ifndef CAMERA_H
  14. #include "camera.h"
  15. #endif
  16. #ifndef DBASEGUI_H
  17. #include "dbasegui.h"
  18. #endif
  19. #ifndef CIDENT_H
  20. #include "cident.h"
  21. #endif
  22. #ifndef PATHS_H
  23. #include "paths.h"
  24. #endif
  25. #ifndef OBJSTATUS_H
  26. #include "objstatus.h"
  27. #endif
  28. #ifndef UTILITIES_H
  29. #include "utilities.h"
  30. #endif
  31. #ifndef INIFILE_H
  32. #include "inifile.h"
  33. #endif
  34. #ifndef ERR_H
  35. #include "err.h"
  36. #endif
  37. #ifndef TXMMGR_H
  38. #include "txmmgr.h"
  39. #endif
  40. #ifndef TIMING_H
  41. #include "timing.h"
  42. #endif
  43. #ifndef CELINE_H
  44. #include "celine.h"
  45. #endif
  46. #ifndef MOVE_H
  47. #include "move.h"
  48. #endif
  49. #include "../Code/unitdesg.h" /* just for definition of MIN_TERRAIN_PART_ID and MAX_MAP_CELL_WIDTH */
  50. //******************************************************************************************
  51. extern float worldUnitsPerMeter;
  52. extern bool drawTerrainGrid;
  53. extern bool useFog;
  54. extern long mechRGBLookup[];
  55. extern long mechRGBLookup2[];
  56. extern long ObjectTextureSize;
  57. extern bool reloadBounds;
  58. extern float metersPerWorldUnit;
  59. extern bool useShadows;
  60. extern MidLevelRenderer::MLRClipper * theClipper;
  61. extern bool useNonWeaponEffects;
  62. extern bool useHighObjectDetail;
  63. extern bool MLRVertexLimitReached;
  64. #define SPINRATE 90.0f
  65. #define BASE_NODE_RECYCLE_TIME 0.25f
  66. #define MAX_WEAPON_NODES 4
  67. //-----------------------------------------------------------------------------
  68. // class BldgAppearanceType
  69. void BldgAppearanceType::init (char * fileName)
  70. {
  71. AppearanceType::init(fileName);
  72. //----------------------------------------------
  73. FullPathFileName iniName;
  74. iniName.init(tglPath,fileName,".ini");
  75. FitIniFile iniFile;
  76. long result = iniFile.open(iniName);
  77. if (result != NO_ERR)
  78. STOP(("Could not find building appearance INI file %s",iniName));
  79. result = iniFile.seekBlock("TGLData");
  80. if (result != NO_ERR)
  81. Fatal(result,"Could not find block in building appearance INI file");
  82. result = iniFile.readIdBoolean("SpinMe",spinMe);
  83. if (result != NO_ERR)
  84. spinMe = false;
  85. float nFrameRate = 0.0f;
  86. result = iniFile.readIdFloat("FrameRate",nFrameRate);
  87. if (result != NO_ERR)
  88. nFrameRate = 0.0f;
  89. result = iniFile.readIdBoolean("ForestClump",isForestClump);
  90. if (result != NO_ERR)
  91. isForestClump = false;
  92. DWORD hotPinkRGB, hotGreenRGB, hotYellowRGB;
  93. result = iniFile.readIdULong("HotPinkRGB",hotPinkRGB);
  94. if (result != NO_ERR)
  95. hotPinkRGB = 0xffff00ff;
  96. result = iniFile.readIdULong("HotGreenRGB",hotGreenRGB);
  97. if (result != NO_ERR)
  98. hotGreenRGB = 0xff00ff00;
  99. result = iniFile.readIdULong("HotYellowRGB",hotYellowRGB);
  100. if (result != NO_ERR)
  101. hotYellowRGB = 0xffffff00;
  102. result = iniFile.readIdULong("TerrainLightRGB",terrainLightRGB);
  103. if (result != NO_ERR)
  104. {
  105. terrainLightRGB = 0xffffffff;
  106. }
  107. else
  108. {
  109. result = iniFile.readIdFloat("TerrainLightIntensity",terrainLightIntensity);
  110. if (result != NO_ERR)
  111. terrainLightIntensity = 0.5f;
  112. result = iniFile.readIdFloat("TerrainLightInnerRadius",terrainLightInnerRadius);
  113. if (result != NO_ERR)
  114. terrainLightInnerRadius = 100.0f;
  115. result = iniFile.readIdFloat("TerrainLightOuterRadius",terrainLightOuterRadius);
  116. if (result != NO_ERR)
  117. terrainLightOuterRadius = 250.0f;
  118. }
  119. char aseFileName[512];
  120. result = iniFile.readIdString("FileName",aseFileName,511);
  121. if (result != NO_ERR)
  122. {
  123. //Check for LOD filenames instead
  124. for (long i=0;i<MAX_LODS;i++)
  125. {
  126. char baseName[256];
  127. char baseLODDist[256];
  128. sprintf(baseName,"FileName%d",i);
  129. sprintf(baseLODDist,"Distance%d",i);
  130. result = iniFile.readIdString(baseName,aseFileName,511);
  131. if (result == NO_ERR)
  132. {
  133. result = iniFile.readIdFloat(baseLODDist,lodDistance[i]);
  134. if (result != NO_ERR)
  135. STOP(("LOD %d has no distance value in file %s",i,fileName));
  136. //----------------------------------------------
  137. // Base LOD shape. In stand Pose by default.
  138. bldgShape[i] = new TG_TypeMultiShape;
  139. gosASSERT(bldgShape[i] != NULL);
  140. FullPathFileName bldgName;
  141. bldgName.init(tglPath,aseFileName,".ase");
  142. bldgShape[i]->LoadTGMultiShapeFromASE(bldgName);
  143. }
  144. else if (!i)
  145. {
  146. STOP(("No base LOD for shape %s",fileName));
  147. }
  148. }
  149. }
  150. else
  151. {
  152. //----------------------------------------------
  153. // Base shape. In stand Pose by default.
  154. bldgShape[0] = new TG_TypeMultiShape;
  155. gosASSERT(bldgShape[0] != NULL);
  156. FullPathFileName bldgName;
  157. bldgName.init(tglPath,aseFileName,".ase");
  158. bldgShape[0]->LoadTGMultiShapeFromASE(bldgName);
  159. }
  160. result = iniFile.readIdString("ShadowName",aseFileName,511);
  161. if (result == NO_ERR)
  162. {
  163. //----------------------------------------------
  164. // Base Shadow shape.
  165. bldgShadowShape = new TG_TypeMultiShape;
  166. gosASSERT(bldgShadowShape != NULL);
  167. FullPathFileName bldgName;
  168. bldgName.init(tglPath,aseFileName,".ase");
  169. bldgShadowShape->LoadTGMultiShapeFromASE(bldgName);
  170. }
  171. //destroyed state.
  172. result = iniFile.seekBlock("TGLDamage");
  173. if (result == NO_ERR)
  174. {
  175. result = iniFile.readIdString("FileName",aseFileName,511);
  176. if (result != NO_ERR)
  177. Fatal(result,"Could not find ASE FileName in building appearance INI file");
  178. FullPathFileName dmgName;
  179. dmgName.init(tglPath,aseFileName,".ase");
  180. bldgDmgShape = new TG_TypeMultiShape;
  181. gosASSERT(bldgDmgShape != NULL);
  182. bldgDmgShape->LoadTGMultiShapeFromASE(dmgName);
  183. if (!bldgDmgShape->GetNumShapes())
  184. {
  185. delete bldgDmgShape;
  186. bldgDmgShape = NULL;
  187. }
  188. //Shadow for destroyed state.
  189. result = iniFile.readIdString("ShadowName",aseFileName,511);
  190. if (result == NO_ERR)
  191. {
  192. //----------------------------------------------
  193. // Base Shadow shape.
  194. bldgDmgShadowShape = new TG_TypeMultiShape;
  195. gosASSERT(bldgDmgShadowShape != NULL);
  196. FullPathFileName bldgName;
  197. bldgName.init(tglPath,aseFileName,".ase");
  198. bldgDmgShadowShape->LoadTGMultiShapeFromASE(bldgName);
  199. if (!bldgDmgShadowShape->GetNumShapes())
  200. {
  201. delete bldgDmgShadowShape;
  202. bldgDmgShadowShape = NULL;
  203. }
  204. }
  205. }
  206. else
  207. {
  208. bldgDmgShape = NULL;
  209. bldgDmgShadowShape = NULL;
  210. }
  211. result = iniFile.seekBlock("TGLDestructEffect");
  212. if (result == NO_ERR)
  213. {
  214. result = iniFile.readIdString("FileName",destructEffect,59);
  215. if (result != NO_ERR)
  216. STOP(("Could not Find DestructEffectName in building appearance INI file"));
  217. }
  218. else
  219. {
  220. destructEffect[0] = 0;
  221. }
  222. //--------------------------------------------------------------------
  223. // Load Animation Information.
  224. // We can load up to 10 Animation States.
  225. for (long i=0;i<MAX_BD_ANIMATIONS;i++)
  226. {
  227. char blockId[512];
  228. sprintf(blockId,"Animation:%d",i);
  229. result = iniFile.seekBlock(blockId);
  230. if (result == NO_ERR)
  231. {
  232. char animName[512];
  233. result = iniFile.readIdString("AnimationName",animName,511);
  234. gosASSERT(result == NO_ERR);
  235. result = iniFile.readIdBoolean("LoopAnimation",bdAnimLoop[i]);
  236. gosASSERT(result == NO_ERR);
  237. result = iniFile.readIdBoolean("Reverse",bdReverse[i]);
  238. gosASSERT(result == NO_ERR);
  239. result = iniFile.readIdBoolean("Random",bdRandom[i]);
  240. gosASSERT(result == NO_ERR);
  241. result = iniFile.readIdLong("StartFrame",bdStartF[i]);
  242. if (result != NO_ERR)
  243. bdStartF[i] = 0;
  244. //-------------------------------
  245. // We have an animation to load.
  246. FullPathFileName animPath;
  247. animPath.init(tglPath,animName,".ase");
  248. FullPathFileName otherPath;
  249. otherPath.init(tglPath,animName,".agl");
  250. if (fileExists(animPath) || fileExists(otherPath))
  251. {
  252. bdAnimData[i] = new TG_AnimateShape;
  253. gosASSERT(bdAnimData[i] != NULL);
  254. //--------------------------------------------------------
  255. // If this animation does not exist, it is not a problem!
  256. // Building will simply freeze until animation is "over"
  257. bdAnimData[i]->LoadTGMultiShapeAnimationFromASE(animPath,bldgShape[0]);
  258. }
  259. else
  260. bdAnimData[i] = NULL;
  261. }
  262. else
  263. {
  264. bdAnimData[i] = NULL;
  265. }
  266. }
  267. //--------------------------------------------------------------------
  268. // We can also load the node to pitch and yaw for spotlights/turrets.
  269. result = iniFile.seekBlock("AnimationNode");
  270. if (result == NO_ERR)
  271. {
  272. result = iniFile.readIdString("AnimationNodeId",rotationalNodeId,24);
  273. gosASSERT(result == NO_ERR);
  274. }
  275. else
  276. {
  277. strcpy(rotationalNodeId,"NONE");
  278. }
  279. if (nFrameRate != 0.0f)
  280. {
  281. for (long i=0;i<MAX_BD_ANIMATIONS;i++)
  282. setFrameRate(i,nFrameRate);
  283. }
  284. //-----------------------------------------------
  285. // Load up the Weapon Node Data.
  286. numWeaponNodes = 0;
  287. nodeData = NULL;
  288. result = iniFile.seekBlock("WeaponNode");
  289. if (result == NO_ERR)
  290. {
  291. nodeData = (NodeData *)AppearanceTypeList::appearanceHeap->Malloc(sizeof(NodeData)*(MAX_WEAPON_NODES));
  292. gosASSERT(nodeData != NULL);
  293. for (i=0;i<MAX_WEAPON_NODES;i++)
  294. {
  295. char blockId[512];
  296. sprintf(blockId,"WeaponNodeId%d",i);
  297. char weaponName[512];
  298. result = iniFile.readIdString(blockId,weaponName,511);
  299. if (result != NO_ERR)
  300. {
  301. strcpy(weaponName,"NONE");
  302. }
  303. nodeData[i].nodeId = (char *)AppearanceTypeList::appearanceHeap->Malloc(strlen(weaponName)+1);
  304. gosASSERT(nodeData[i].nodeId != NULL);
  305. strcpy(nodeData[i].nodeId,weaponName);
  306. nodeData[i].weaponType = 0;
  307. numWeaponNodes++;
  308. }
  309. }
  310. for (i=0;i<MAX_LODS;i++)
  311. {
  312. if (bldgShape[i])
  313. bldgShape[i]->SetLightRGBs(hotPinkRGB, hotGreenRGB, hotYellowRGB);
  314. }
  315. }
  316. //----------------------------------------------------------------------------
  317. void BldgAppearanceType::destroy (void)
  318. {
  319. AppearanceType::destroy();
  320. for (long i=0;i<MAX_LODS;i++)
  321. {
  322. if (bldgShape[i])
  323. {
  324. delete bldgShape[i];
  325. bldgShape[i] = NULL;
  326. }
  327. }
  328. if (bldgShadowShape)
  329. {
  330. delete bldgShadowShape;
  331. bldgShadowShape = NULL;
  332. }
  333. if (bldgDmgShape)
  334. {
  335. delete bldgDmgShape;
  336. bldgDmgShape = NULL;
  337. }
  338. if (bldgDmgShadowShape)
  339. {
  340. delete bldgDmgShadowShape;
  341. bldgDmgShadowShape = NULL;
  342. }
  343. for (i=0;i<MAX_BD_ANIMATIONS;i++)
  344. {
  345. if (bdAnimData[i])
  346. {
  347. delete bdAnimData[i];
  348. bdAnimData[i] = NULL;
  349. }
  350. }
  351. }
  352. //-----------------------------------------------------------------------------
  353. void BldgAppearanceType::setAnimation (TG_MultiShapePtr shape, DWORD animationNum)
  354. {
  355. gosASSERT(shape != NULL);
  356. gosASSERT(animationNum != 0xffffffff);
  357. gosASSERT(animationNum < MAX_BD_ANIMATIONS);
  358. if (bdAnimData[animationNum])
  359. bdAnimData[animationNum]->SetAnimationState(shape);
  360. else
  361. shape->ClearAnimation();
  362. }
  363. //-----------------------------------------------------------------------------
  364. // class BldgAppearance
  365. void BldgAppearance::setWeaponNodeUsed (long weaponNode)
  366. {
  367. weaponNode -= appearType->numWeaponNodes;
  368. if ((weaponNode >= 0) && (weaponNode < appearType->numWeaponNodes))
  369. {
  370. nodeUsed[weaponNode]++;
  371. nodeRecycle[weaponNode] = BASE_NODE_RECYCLE_TIME;
  372. }
  373. }
  374. //-----------------------------------------------------------------------------
  375. Stuff::Vector3D BldgAppearance::getWeaponNodePosition (long nodeId)
  376. {
  377. Stuff::Vector3D result = position;
  378. if ((nodeId < 0) || (nodeId >= appearType->numWeaponNodes))
  379. return result;
  380. //We already know we are using this node. Do NOT increment recycle or nodeUsed!
  381. //-------------------------------------------
  382. // Create Matrix to conform to.
  383. Stuff::UnitQuaternion qRotation;
  384. float yaw = rotation * DEGREES_TO_RADS;
  385. qRotation = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  386. Stuff::Point3D xlatPosition;
  387. xlatPosition.x = -position.x;
  388. xlatPosition.y = land->getTerrainElevation(position);
  389. xlatPosition.z = position.y;
  390. Stuff::UnitQuaternion torsoRot;
  391. torsoRot = Stuff::EulerAngles(0.0f,(turretYaw * DEGREES_TO_RADS),0.0f);
  392. if (rotationalNodeId == -1)
  393. {
  394. if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
  395. rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
  396. else
  397. rotationalNodeId = -2;
  398. }
  399. if (rotationalNodeId >= 0)
  400. bldgShape->SetNodeRotation(rotationalNodeId,&torsoRot);
  401. result = bldgShape->GetTransformedNodePosition(&xlatPosition,&qRotation,appearType->nodeData[nodeId].nodeId);
  402. if ((result.x == 0.0f) &&
  403. (result.y == 0.0f) &&
  404. (result.z == 0.0f))
  405. result = position;
  406. return result;
  407. }
  408. //-----------------------------------------------------------------------------
  409. Stuff::Vector3D BldgAppearance::getHitNode (void)
  410. {
  411. if (hitNodeId == -1)
  412. hitNodeId = bldgShape->GetNodeNameId("hitnode");
  413. Stuff::Vector3D result = getNodeIdPosition(hitNodeId);
  414. return result;
  415. }
  416. //-----------------------------------------------------------------------------
  417. long BldgAppearance::getWeaponNode (long weaponType)
  418. {
  419. //------------------------------------------------
  420. // Scan all weapon nodes and find least used one.
  421. long leastUsed = 999999999;
  422. long bestNode = -1;
  423. for (long i=0;i<appearType->numWeaponNodes;i++)
  424. {
  425. if (nodeUsed[i] < leastUsed)
  426. {
  427. leastUsed = nodeUsed[i];
  428. bestNode = i;
  429. }
  430. }
  431. if ((bestNode < 0) || (bestNode >= appearType->numWeaponNodes))
  432. return -1;
  433. return bestNode;
  434. }
  435. //-----------------------------------------------------------------------------
  436. float BldgAppearance::getWeaponNodeRecycle (long node)
  437. {
  438. if ((node >= 0) && (node < appearType->numWeaponNodes))
  439. return nodeRecycle[node];
  440. return 0.0f;
  441. }
  442. //-----------------------------------------------------------------------------
  443. void BldgAppearance::init (AppearanceTypePtr tree, GameObjectPtr obj)
  444. {
  445. Appearance::init(tree,obj);
  446. appearType = (BldgAppearanceType *)tree;
  447. shapeMin.x = shapeMin.y = -25;
  448. shapeMax.x = shapeMax.y = 50;
  449. bdAnimationState =-1;
  450. currentFrame = 0.0f;
  451. bdFrameRate = 0.0f;
  452. isReversed = false;
  453. isLooping = false;
  454. setFirstFrame = false;
  455. canTransition = true;
  456. paintScheme = -1;
  457. objectNameId = 30469;
  458. hazeFactor = 0.0f;
  459. rotationalNodeId = -1;
  460. hitNodeId = activityNodeId = activityNode1Id = -1;
  461. currentFlash = duration = flashDuration = 0.0f;
  462. flashColor = 0x00000000;
  463. drawFlash = false;
  464. pointLight = NULL;
  465. lightId = 0xffffffff;
  466. forceLightsOut = false;
  467. screenPos.x = screenPos.y = screenPos.z = screenPos.w = -999.0f;
  468. position.Zero();
  469. rotation = 0.0f;
  470. selected = 0;
  471. teamId = -1;
  472. homeTeamRelationship = 0;
  473. actualRotation = rotation;
  474. currentLOD = 0;
  475. turretYaw = turretPitch = 0.0f;
  476. destructFX = NULL;
  477. activity = NULL;
  478. activity1 = NULL;
  479. isActivitying = false;
  480. OBBRadius = -1.0f;
  481. highZ = -1.0f;
  482. nodeUsed = NULL;
  483. nodeRecycle = NULL;
  484. beenInView = false;
  485. fogLightSet = false;
  486. if (appearType)
  487. {
  488. bldgShape = appearType->bldgShape[0]->CreateFrom();
  489. //-------------------------------------------------
  490. // Load the texture and store its handle.
  491. for (long i=0;i<bldgShape->GetNumTextures();i++)
  492. {
  493. char txmName[1024];
  494. bldgShape->GetTextureName(i,txmName,256);
  495. char texturePath[1024];
  496. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  497. FullPathFileName textureName;
  498. textureName.init(texturePath,txmName,"");
  499. if (fileExists(textureName))
  500. {
  501. if (strnicmp(txmName,"a_",2) == 0)
  502. {
  503. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  504. gosASSERT(gosTextureHandle != 0xffffffff);
  505. bldgShape->SetTextureHandle(i,gosTextureHandle);
  506. bldgShape->SetTextureAlpha(i,true);
  507. }
  508. else
  509. {
  510. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  511. gosASSERT(gosTextureHandle != 0xffffffff);
  512. bldgShape->SetTextureHandle(i,gosTextureHandle);
  513. bldgShape->SetTextureAlpha(i,false);
  514. }
  515. }
  516. else
  517. {
  518. //PAUSE(("Warning: %s texture name not found",textureName));
  519. bldgShape->SetTextureHandle(i,0xffffffff);
  520. }
  521. }
  522. if (appearType->bldgShadowShape)
  523. {
  524. bldgShadowShape = appearType->bldgShadowShape->CreateFrom();
  525. //-------------------------------------------------
  526. // Load the texture and store its handle.
  527. for (long i=0;i<bldgShadowShape->GetNumTextures();i++)
  528. {
  529. char txmName[1024];
  530. bldgShadowShape->GetTextureName(i,txmName,256);
  531. char texturePath[1024];
  532. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  533. FullPathFileName textureName;
  534. textureName.init(texturePath,txmName,"");
  535. if (fileExists(textureName))
  536. {
  537. if (strnicmp(txmName,"a_",2) == 0)
  538. {
  539. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  540. gosASSERT(gosTextureHandle != 0xffffffff);
  541. bldgShadowShape->SetTextureHandle(i,gosTextureHandle);
  542. bldgShadowShape->SetTextureAlpha(i,true);
  543. }
  544. else
  545. {
  546. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  547. gosASSERT(gosTextureHandle != 0xffffffff);
  548. bldgShadowShape->SetTextureHandle(i,gosTextureHandle);
  549. bldgShadowShape->SetTextureAlpha(i,false);
  550. }
  551. }
  552. else
  553. {
  554. bldgShadowShape->SetTextureHandle(i,0xffffffff);
  555. }
  556. }
  557. }
  558. else
  559. {
  560. bldgShadowShape = NULL;
  561. }
  562. Stuff::Vector3D boxCoords[8];
  563. Stuff::Vector3D nodeCenter = bldgShape->GetRootNodeCenter();
  564. boxCoords[0].x = position.x + bldgShape->GetMinBox().x + nodeCenter.x;
  565. boxCoords[0].y = position.y + bldgShape->GetMinBox().z + nodeCenter.z;
  566. boxCoords[0].z = position.z + bldgShape->GetMaxBox().y + nodeCenter.y;
  567. boxCoords[1].x = position.x + bldgShape->GetMinBox().x + nodeCenter.x;
  568. boxCoords[1].y = position.y + bldgShape->GetMaxBox().z + nodeCenter.z;
  569. boxCoords[1].z = position.z + bldgShape->GetMaxBox().y + nodeCenter.y;
  570. boxCoords[2].x = position.x + bldgShape->GetMaxBox().x + nodeCenter.x;
  571. boxCoords[2].y = position.y + bldgShape->GetMaxBox().z + nodeCenter.z;
  572. boxCoords[2].z = position.z + bldgShape->GetMaxBox().y + nodeCenter.y;
  573. boxCoords[3].x = position.x + bldgShape->GetMaxBox().x + nodeCenter.x;
  574. boxCoords[3].y = position.y + bldgShape->GetMinBox().z + nodeCenter.z;
  575. boxCoords[3].z = position.z + bldgShape->GetMaxBox().y + nodeCenter.y;
  576. boxCoords[4].x = position.x + bldgShape->GetMinBox().x + nodeCenter.x;
  577. boxCoords[4].y = position.y + bldgShape->GetMinBox().z + nodeCenter.z;
  578. boxCoords[4].z = position.z + bldgShape->GetMinBox().y + nodeCenter.y;
  579. boxCoords[5].x = position.x + bldgShape->GetMaxBox().x + nodeCenter.x;
  580. boxCoords[5].y = position.y + bldgShape->GetMinBox().z + nodeCenter.z;
  581. boxCoords[5].z = position.z + bldgShape->GetMinBox().y + nodeCenter.y;
  582. boxCoords[6].x = position.x + bldgShape->GetMaxBox().x + nodeCenter.x;
  583. boxCoords[6].y = position.y + bldgShape->GetMaxBox().z + nodeCenter.z;
  584. boxCoords[6].z = position.z + bldgShape->GetMinBox().y + nodeCenter.y;
  585. boxCoords[7].x = position.x + bldgShape->GetMinBox().x + nodeCenter.x;
  586. boxCoords[7].y = position.y + bldgShape->GetMaxBox().z + nodeCenter.z;
  587. boxCoords[7].z = position.z + bldgShape->GetMinBox().y + nodeCenter.y;
  588. float testRadius = 0.0;
  589. for (i=0;i<8;i++)
  590. {
  591. testRadius = boxCoords[i].GetLength();
  592. if (OBBRadius < testRadius)
  593. OBBRadius = testRadius;
  594. if (boxCoords[i].z > highZ)
  595. highZ = boxCoords[i].z;
  596. }
  597. appearType->boundsUpperLeftX = (-OBBRadius * 2.0);
  598. appearType->boundsUpperLeftY = (-OBBRadius * 2.0);
  599. appearType->boundsLowerRightX = (OBBRadius * 2.0);
  600. appearType->boundsLowerRightY = (OBBRadius);
  601. if (!appearType->getDesignerTypeBounds())
  602. {
  603. Stuff::Vector3D nodeCenter = bldgShape->GetRootNodeCenter();
  604. appearType->typeUpperLeft.Add(bldgShape->GetMinBox(),nodeCenter);
  605. appearType->typeLowerRight.Add(bldgShape->GetMaxBox(),nodeCenter);
  606. }
  607. if (appearType->numWeaponNodes)
  608. {
  609. nodeUsed = (long *)AppearanceTypeList::appearanceHeap->Malloc(sizeof(long) * appearType->numWeaponNodes);
  610. gosASSERT(nodeUsed != NULL);
  611. memset(nodeUsed,0,sizeof(long) * appearType->numWeaponNodes);
  612. nodeRecycle = (float *)AppearanceTypeList::appearanceHeap->Malloc(sizeof(float) * appearType->numWeaponNodes);
  613. gosASSERT(nodeRecycle != NULL);
  614. for (long i=0;i<appearType->numWeaponNodes;i++)
  615. nodeRecycle[i] = 0.0f;
  616. }
  617. }
  618. }
  619. //-----------------------------------------------------------------------------
  620. void BldgAppearance::setObjStatus (long oStatus)
  621. {
  622. if (status != oStatus)
  623. {
  624. if ((oStatus == OBJECT_STATUS_DESTROYED) || (oStatus == OBJECT_STATUS_DISABLED))
  625. {
  626. if (appearType->bldgDmgShape)
  627. {
  628. if (bldgShape)
  629. {
  630. bldgShape->ClearAnimation();
  631. delete bldgShape;
  632. bldgShape = NULL;
  633. }
  634. bldgShape = appearType->bldgDmgShape->CreateFrom();
  635. if (bdAnimationState != -1)
  636. appearType->setAnimation(bldgShape,bdAnimationState);
  637. beenInView = false;
  638. currentLOD = 0;
  639. }
  640. if (appearType->bldgDmgShadowShape)
  641. {
  642. if (bldgShadowShape)
  643. {
  644. bldgShadowShape->ClearAnimation();
  645. delete bldgShadowShape;
  646. bldgShadowShape = NULL;
  647. }
  648. bldgShadowShape = appearType->bldgDmgShadowShape->CreateFrom();
  649. //Do shadows need to animate??
  650. //if (bdAnimationState != -1)
  651. //appearType->setAnimation(bldgShadowShape,bdAnimationState);
  652. beenInView = false;
  653. }
  654. stopActivity();
  655. }
  656. if (oStatus == OBJECT_STATUS_NORMAL)
  657. {
  658. if (appearType->bldgShape)
  659. {
  660. if (bldgShape)
  661. {
  662. bldgShape->ClearAnimation();
  663. delete bldgShape;
  664. bldgShape = NULL;
  665. }
  666. bldgShape = appearType->bldgShape[0]->CreateFrom();
  667. if (bdAnimationState != -1)
  668. appearType->setAnimation(bldgShape,bdAnimationState);
  669. beenInView = false;
  670. }
  671. if (appearType->bldgShadowShape)
  672. {
  673. if (bldgShadowShape)
  674. {
  675. bldgShadowShape->ClearAnimation();
  676. delete bldgShadowShape;
  677. bldgShadowShape = NULL;
  678. }
  679. bldgShadowShape = appearType->bldgShadowShape->CreateFrom();
  680. //Do shadows need to animate??
  681. // if (bdAnimationState != -1)
  682. //appearType->setAnimation(bldgShadowShape,bdAnimationState);
  683. beenInView = false;
  684. }
  685. }
  686. if (bldgShape)
  687. {
  688. //-------------------------------------------------
  689. // Load the texture and store its handle.
  690. for (long i=0;i<bldgShape->GetNumTextures();i++)
  691. {
  692. char txmName[1024];
  693. bldgShape->GetTextureName(i,txmName,256);
  694. char texturePath[1024];
  695. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  696. FullPathFileName textureName;
  697. textureName.init(texturePath,txmName,"");
  698. if (fileExists(textureName))
  699. {
  700. if (strnicmp(txmName,"a_",2) == 0)
  701. {
  702. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  703. gosASSERT(gosTextureHandle != 0xffffffff);
  704. bldgShape->SetTextureHandle(i,gosTextureHandle);
  705. bldgShape->SetTextureAlpha(i,true);
  706. }
  707. else
  708. {
  709. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  710. gosASSERT(gosTextureHandle != 0xffffffff);
  711. bldgShape->SetTextureHandle(i,gosTextureHandle);
  712. bldgShape->SetTextureAlpha(i,false);
  713. }
  714. }
  715. else
  716. {
  717. //PAUSE(("Warning: %s texture name not found",textureName));
  718. bldgShape->SetTextureHandle(i,0xffffffff);
  719. }
  720. }
  721. }
  722. if (bldgShadowShape)
  723. {
  724. //-------------------------------------------------
  725. // Load the texture for the shadow and store its handle.
  726. for (long i=0;i<bldgShadowShape->GetNumTextures();i++)
  727. {
  728. char txmName[1024];
  729. bldgShadowShape->GetTextureName(i,txmName,256);
  730. char texturePath[1024];
  731. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  732. FullPathFileName textureName;
  733. textureName.init(texturePath,txmName,"");
  734. if (fileExists(textureName))
  735. {
  736. if (strnicmp(txmName,"a_",2) == 0)
  737. {
  738. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  739. gosASSERT(gosTextureHandle != 0xffffffff);
  740. bldgShadowShape->SetTextureHandle(i,gosTextureHandle);
  741. bldgShadowShape->SetTextureAlpha(i,true);
  742. }
  743. else
  744. {
  745. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  746. gosASSERT(gosTextureHandle != 0xffffffff);
  747. bldgShadowShape->SetTextureHandle(i,gosTextureHandle);
  748. bldgShadowShape->SetTextureAlpha(i,false);
  749. }
  750. }
  751. else
  752. {
  753. bldgShadowShape->SetTextureHandle(i,0xffffffff);
  754. }
  755. }
  756. }
  757. }
  758. status = oStatus;
  759. }
  760. //-----------------------------------------------------------------------------
  761. Stuff::Vector3D BldgAppearance::getNodeNamePosition (char *nodeName)
  762. {
  763. Stuff::Vector3D result = position;
  764. //-------------------------------------------
  765. // Create Matrix to conform to.
  766. Stuff::UnitQuaternion qRotation;
  767. float yaw = rotation * DEGREES_TO_RADS;
  768. qRotation = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  769. Stuff::Point3D xlatPosition;
  770. xlatPosition.x = -position.x;
  771. xlatPosition.y = position.z;
  772. xlatPosition.z = position.y;
  773. result = bldgShape->GetTransformedNodePosition(&xlatPosition,&qRotation,nodeName);
  774. if ((result.x == 0.0f) &&
  775. (result.y == 0.0f) &&
  776. (result.z == 0.0f))
  777. result = position;
  778. return result;
  779. }
  780. //-----------------------------------------------------------------------------
  781. Stuff::Vector3D BldgAppearance::getNodeIdPosition (long nodeId)
  782. {
  783. Stuff::Vector3D result = position;
  784. //-------------------------------------------
  785. // Create Matrix to conform to.
  786. Stuff::UnitQuaternion qRotation;
  787. float yaw = rotation * DEGREES_TO_RADS;
  788. qRotation = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  789. Stuff::Point3D xlatPosition;
  790. xlatPosition.x = -position.x;
  791. xlatPosition.y = position.z;
  792. xlatPosition.z = position.y;
  793. result = bldgShape->GetTransformedNodePosition(&xlatPosition,&qRotation,nodeId);
  794. if ((result.x == 0.0f) &&
  795. (result.y == 0.0f) &&
  796. (result.z == 0.0f))
  797. result = position;
  798. return result;
  799. }
  800. //-----------------------------------------------------------------------------
  801. bool BldgAppearance::PerPolySelect (long mouseX, long mouseY)
  802. {
  803. return bldgShape->PerPolySelect(mouseX,mouseY);
  804. }
  805. //-----------------------------------------------------------------------------
  806. void BldgAppearance::setGesture (unsigned long gestureId)
  807. {
  808. //------------------------------------------------------------
  809. // Check if state is possible.
  810. if (gestureId >= MAX_BD_ANIMATIONS)
  811. return;
  812. //------------------------------------------------------------
  813. // Check if object destroyed. If so, no animation!
  814. if ((status == OBJECT_STATUS_DESTROYED) || (status == OBJECT_STATUS_DISABLED))
  815. return;
  816. if (gestureId == bdAnimationState)
  817. return;
  818. //----------------------------------------------------------------------
  819. // If state is OK, set animation data, set first frame, set loop and
  820. // reverse flag, and start it going until you hear otherwise.
  821. appearType->setAnimation(bldgShape,gestureId);
  822. bdAnimationState = gestureId;
  823. currentFrame = 0.0f;
  824. if (appearType->bdStartF[gestureId])
  825. currentFrame = appearType->bdStartF[gestureId];
  826. isReversed = false;
  827. if (appearType->isReversed(bdAnimationState))
  828. {
  829. currentFrame = appearType->getNumFrames(bdAnimationState)-1;
  830. isReversed = true;
  831. }
  832. if (appearType->isRandom(bdAnimationState))
  833. {
  834. currentFrame = RandomNumber(appearType->getNumFrames(bdAnimationState)-1);
  835. }
  836. isLooping = appearType->isLooped(bdAnimationState);
  837. bdFrameRate = appearType->getFrameRate(bdAnimationState);
  838. setFirstFrame = true;
  839. if (bdFrameRate > Stuff::SMALL)
  840. canTransition = false;
  841. else
  842. canTransition = true; //We can change immediately to another animation because we have no animation for this state!
  843. }
  844. //-----------------------------------------------------------------------------
  845. void BldgAppearance::setMoverParameters (float turretRot, float lArmRot, float rArmRot, bool isAirborne)
  846. {
  847. turretYaw = turretRot;
  848. turretPitch = lArmRot;
  849. }
  850. //-----------------------------------------------------------------------------
  851. void BldgAppearance::setObjectParameters (Stuff::Vector3D &pos, float Rot, long sel, long team, long homeRelations)
  852. {
  853. rotation = Rot;
  854. position = pos;
  855. selected = sel;
  856. actualRotation = Rot;
  857. teamId = team;
  858. homeTeamRelationship = homeRelations;
  859. }
  860. //-----------------------------------------------------------------------------
  861. bool BldgAppearance::isMouseOver (float px, float py)
  862. {
  863. if (inView)
  864. {
  865. if ((px <= lowerRight.x) && (py <= lowerRight.y) &&
  866. (px >= upperLeft.x) &&
  867. (py >= upperLeft.y))
  868. {
  869. return inView;
  870. }
  871. else
  872. {
  873. return FALSE;
  874. }
  875. }
  876. return(inView);
  877. }
  878. //-----------------------------------------------------------------------------
  879. bool BldgAppearance::recalcBounds (void)
  880. {
  881. Stuff::Vector4D tempPos;
  882. inView = false;
  883. float distanceToEye = 0.0f;
  884. if (eye)
  885. {
  886. //-------------------------------------------------------------------
  887. //NEW METHOD from the WAY BACK Days
  888. inView = true;
  889. if (eye->usePerspective)
  890. {
  891. Stuff::Vector3D cameraPos;
  892. cameraPos.x = -eye->getCameraOrigin().x;
  893. cameraPos.y = eye->getCameraOrigin().z;
  894. cameraPos.z = eye->getCameraOrigin().y;
  895. float vClipConstant = eye->verticalSphereClipConstant;
  896. float hClipConstant = eye->horizontalSphereClipConstant;
  897. Stuff::Vector3D objectCenter;
  898. objectCenter.Subtract(position,cameraPos);
  899. Camera::cameraFrame.trans_to_frame(objectCenter);
  900. distanceToEye = objectCenter.GetApproximateLength();
  901. float clip_distance = fabs(1.0f / objectCenter.y);
  902. //Is vertex on Screen OR close enough to screen that its triangle MAY be visible?
  903. // WE have removed the atans here by simply taking the tan of the angle we want above.
  904. float object_angle = fabs(objectCenter.z) * clip_distance;
  905. float extent_angle = bldgShape->GetExtentRadius() / distanceToEye;
  906. if (object_angle > (vClipConstant + extent_angle))
  907. {
  908. //In theory, we would return here. Object is NOT on screen.
  909. inView = false;
  910. }
  911. else
  912. {
  913. object_angle = fabs(objectCenter.x) * clip_distance;
  914. if (object_angle > (hClipConstant + extent_angle))
  915. {
  916. //In theory, we would return here. Object is NOT on screen.
  917. inView = false;
  918. }
  919. }
  920. }
  921. //Can we be seen at all?
  922. // If yes, check if we are behind fog plane.
  923. if (inView)
  924. {
  925. //ALWAYS need to do this or select is YAYA
  926. // But now inView is correct!!
  927. eye->projectZ(position,screenPos);
  928. if (eye->usePerspective)
  929. {
  930. if (distanceToEye > Camera::MaxClipDistance)
  931. {
  932. hazeFactor = 1.0f;
  933. inView = false;
  934. }
  935. else if (distanceToEye > Camera::MinHazeDistance)
  936. {
  937. Camera::HazeFactor = (distanceToEye - Camera::MinHazeDistance) * Camera::DistanceFactor;
  938. inView = true;
  939. }
  940. else
  941. {
  942. Camera::HazeFactor = 0.0f;
  943. inView = true;
  944. }
  945. }
  946. else
  947. {
  948. Camera::HazeFactor = 0.0f;
  949. inView = true;
  950. }
  951. }
  952. //If we were not behind fog plane, do a bunch O math we need later!!
  953. if (inView)
  954. {
  955. if (reloadBounds)
  956. appearType->reinit();
  957. appearType->boundsLowerRightY = (OBBRadius * eye->getTiltFactor() * 2.0f);
  958. //-------------------------------------------------------------------------
  959. // do a rough check if on screen. If no where near, do NOT do the below.
  960. // Mighty mighty slow!!!!
  961. // Use the original check done before all this 3D madness. Dig out sourceSafe tomorrow!
  962. tempPos = screenPos;
  963. upperLeft.x = tempPos.x;
  964. upperLeft.y = tempPos.y;
  965. lowerRight.x = tempPos.x;
  966. lowerRight.y = tempPos.y;
  967. upperLeft.x += (appearType->boundsUpperLeftX * eye->getScaleFactor());
  968. upperLeft.y += (appearType->boundsUpperLeftY * eye->getScaleFactor());
  969. lowerRight.x += (appearType->boundsLowerRightX * eye->getScaleFactor());
  970. lowerRight.y += (appearType->boundsLowerRightY * eye->getScaleFactor());
  971. if ((lowerRight.x >= 0) && (lowerRight.y >= 0) &&
  972. (upperLeft.x <= eye->getScreenResX()) &&
  973. (upperLeft.y <= eye->getScreenResY()))
  974. {
  975. //We are on screen. Figure out selection box.
  976. Stuff::Vector3D boxCoords[8];
  977. Stuff::Vector4D bcsp[8];
  978. Stuff::Vector3D boxStart;
  979. boxStart.x = -appearType->typeUpperLeft.x;
  980. boxStart.y = appearType->typeUpperLeft.z;
  981. boxStart.z = appearType->typeUpperLeft.y;
  982. Stuff::Vector3D boxEnd;
  983. boxEnd.x = -appearType->typeLowerRight.x;
  984. boxEnd.y = appearType->typeLowerRight.z;
  985. boxEnd.z = appearType->typeLowerRight.y;
  986. Stuff::Vector3D addCoords;
  987. addCoords.x = boxStart.x;
  988. addCoords.y = boxStart.y;
  989. addCoords.z = boxEnd.z;
  990. if (rotation != 0.0f)
  991. Rotate(addCoords,-rotation);
  992. boxCoords[0].Add(position,addCoords);
  993. addCoords.x = boxStart.x;
  994. addCoords.y = boxEnd.y;
  995. addCoords.z = boxEnd.z;
  996. if (rotation != 0.0f)
  997. Rotate(addCoords,-rotation);
  998. boxCoords[1].Add(position,addCoords);
  999. addCoords.x = boxEnd.x;
  1000. addCoords.y = boxEnd.y;
  1001. addCoords.z = boxEnd.z;
  1002. if (rotation != 0.0f)
  1003. Rotate(addCoords,-rotation);
  1004. boxCoords[2].Add(position,addCoords);
  1005. addCoords.x = boxEnd.x;
  1006. addCoords.y = boxStart.y;
  1007. addCoords.z = boxEnd.z;
  1008. if (rotation != 0.0f)
  1009. Rotate(addCoords,-rotation);
  1010. boxCoords[3].Add(position,addCoords);
  1011. addCoords.x = boxStart.x;
  1012. addCoords.y = boxStart.y;
  1013. addCoords.z = boxStart.z;
  1014. if (rotation != 0.0f)
  1015. Rotate(addCoords,-rotation);
  1016. boxCoords[4].Add(position,addCoords);
  1017. addCoords.x = boxEnd.x;
  1018. addCoords.y = boxStart.y;
  1019. addCoords.z = boxStart.z;
  1020. if (rotation != 0.0f)
  1021. Rotate(addCoords,-rotation);
  1022. boxCoords[5].Add(position,addCoords);
  1023. addCoords.x = boxEnd.x;
  1024. addCoords.y = boxEnd.y;
  1025. addCoords.z = boxStart.z;
  1026. if (rotation != 0.0f)
  1027. Rotate(addCoords,-rotation);
  1028. boxCoords[6].Add(position,addCoords);
  1029. addCoords.x = boxStart.x;
  1030. addCoords.y = boxEnd.y;
  1031. addCoords.z = boxStart.z;
  1032. if (rotation != 0.0f)
  1033. Rotate(addCoords,-rotation);
  1034. boxCoords[7].Add(position,addCoords);
  1035. float maxX = 0.0f, maxY = 0.0f;
  1036. float minX = 0.0f, minY = 0.0f;
  1037. for (long i=0;i<8;i++)
  1038. {
  1039. eye->projectZ(boxCoords[i],bcsp[i]);
  1040. if (!i)
  1041. {
  1042. maxX = minX = bcsp[i].x;
  1043. maxY = minY = bcsp[i].y;
  1044. }
  1045. if (i)
  1046. {
  1047. if (bcsp[i].x > maxX)
  1048. maxX = bcsp[i].x;
  1049. if (bcsp[i].x < minX)
  1050. minX = bcsp[i].x;
  1051. if (bcsp[i].y > maxY)
  1052. maxY = bcsp[i].y;
  1053. if (bcsp[i].y < minY)
  1054. minY = bcsp[i].y;
  1055. }
  1056. }
  1057. upperLeft.x = minX;
  1058. upperLeft.y = minY;
  1059. lowerRight.x = maxX;
  1060. lowerRight.y = maxY;
  1061. if ((lowerRight.x >= 0) && (lowerRight.y >= 0) &&
  1062. (upperLeft.x <= eye->getScreenResX()) &&
  1063. (upperLeft.y <= eye->getScreenResY()))
  1064. {
  1065. inView = true;
  1066. if ((status != OBJECT_STATUS_DESTROYED) && (status != OBJECT_STATUS_DISABLED))
  1067. {
  1068. //-------------------------------------------------------------------------------
  1069. //Set LOD of Model here because we have the distance and we KNOW we can see it!
  1070. bool baseLOD = true;
  1071. DWORD selectLOD = 0;
  1072. if (useHighObjectDetail)
  1073. {
  1074. for (long i=1;i<MAX_LODS;i++)
  1075. {
  1076. if (appearType->bldgShape[i] && (distanceToEye > appearType->lodDistance[i]))
  1077. {
  1078. baseLOD = false;
  1079. selectLOD = i;
  1080. }
  1081. }
  1082. }
  1083. else //We always want to use the lowest LOD!!
  1084. {
  1085. if (appearType->bldgShape[1])
  1086. {
  1087. baseLOD = false;
  1088. selectLOD = 1;
  1089. }
  1090. }
  1091. // we are at this LOD level.
  1092. if (selectLOD != currentLOD)
  1093. {
  1094. currentLOD = selectLOD;
  1095. bldgShape->ClearAnimation();
  1096. delete bldgShape;
  1097. bldgShape = NULL;
  1098. bldgShape = appearType->bldgShape[currentLOD]->CreateFrom();
  1099. if (bdAnimationState != -1)
  1100. appearType->setAnimation(bldgShape,bdAnimationState);
  1101. //-------------------------------------------------
  1102. // Load the texture and store its handle.
  1103. for (long j=0;j<bldgShape->GetNumTextures();j++)
  1104. {
  1105. char txmName[1024];
  1106. bldgShape->GetTextureName(j,txmName,256);
  1107. char texturePath[1024];
  1108. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  1109. FullPathFileName textureName;
  1110. textureName.init(texturePath,txmName,"");
  1111. if (fileExists(textureName))
  1112. {
  1113. if (strnicmp(txmName,"a_",2) == 0)
  1114. {
  1115. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  1116. gosASSERT(gosTextureHandle != 0xffffffff);
  1117. bldgShape->SetTextureHandle(j,gosTextureHandle);
  1118. bldgShape->SetTextureAlpha(j,true);
  1119. }
  1120. else
  1121. {
  1122. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  1123. gosASSERT(gosTextureHandle != 0xffffffff);
  1124. bldgShape->SetTextureHandle(j,gosTextureHandle);
  1125. bldgShape->SetTextureAlpha(j,false);
  1126. }
  1127. }
  1128. else
  1129. {
  1130. //PAUSE(("Warning: %s texture name not found",textureName));
  1131. bldgShape->SetTextureHandle(j,0xffffffff);
  1132. }
  1133. }
  1134. }
  1135. //ONLY change if we need
  1136. if (currentLOD && baseLOD)
  1137. {
  1138. // we are at the Base LOD level.
  1139. currentLOD = 0;
  1140. bldgShape->ClearAnimation();
  1141. delete bldgShape;
  1142. bldgShape = NULL;
  1143. bldgShape = appearType->bldgShape[currentLOD]->CreateFrom();
  1144. if (bdAnimationState != -1)
  1145. appearType->setAnimation(bldgShape,bdAnimationState);
  1146. //-------------------------------------------------
  1147. // Load the texture and store its handle.
  1148. for (long i=0;i<bldgShape->GetNumTextures();i++)
  1149. {
  1150. char txmName[1024];
  1151. bldgShape->GetTextureName(i,txmName,256);
  1152. char texturePath[1024];
  1153. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  1154. FullPathFileName textureName;
  1155. textureName.init(texturePath,txmName,"");
  1156. if (fileExists(textureName))
  1157. {
  1158. if (strnicmp(txmName,"a_",2) == 0)
  1159. {
  1160. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  1161. gosASSERT(gosTextureHandle != 0xffffffff);
  1162. bldgShape->SetTextureHandle(i,gosTextureHandle);
  1163. bldgShape->SetTextureAlpha(i,true);
  1164. }
  1165. else
  1166. {
  1167. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  1168. gosASSERT(gosTextureHandle != 0xffffffff);
  1169. bldgShape->SetTextureHandle(i,gosTextureHandle);
  1170. bldgShape->SetTextureAlpha(i,false);
  1171. }
  1172. }
  1173. else
  1174. {
  1175. //PAUSE(("Warning: %s texture name not found",textureName));
  1176. bldgShape->SetTextureHandle(i,0xffffffff);
  1177. }
  1178. }
  1179. }
  1180. }
  1181. }
  1182. else
  1183. {
  1184. inView = false; //Did alot of extra work checking this, but WHY draw and insult to injury?
  1185. }
  1186. }
  1187. else
  1188. {
  1189. inView = false;
  1190. }
  1191. }
  1192. }
  1193. return(inView);
  1194. }
  1195. //-----------------------------------------------------------------------------
  1196. bool BldgAppearance::playDestruction (void)
  1197. {
  1198. //Check if there is a Destruct FX
  1199. if (appearType->destructEffect[0])
  1200. {
  1201. //--------------------------------------------
  1202. // Yes, load it on up.
  1203. unsigned flags = gosFX::Effect::ExecuteFlag;
  1204. Check_Object(gosFX::EffectLibrary::Instance);
  1205. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(appearType->destructEffect);
  1206. if (gosEffectSpec)
  1207. {
  1208. destructFX = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  1209. gosASSERT(destructFX != NULL);
  1210. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  1211. Stuff::Point3D tPosition;
  1212. Stuff::LinearMatrix4D shapeOrigin;
  1213. Stuff::LinearMatrix4D localToWorld;
  1214. //Stuff::Vector3D offsetPosition;
  1215. //offsetPosition.x = Terrain::worldUnitsPerVertex / 3.0f;
  1216. //offsetPosition.y = -(Terrain::worldUnitsPerVertex / 3.0f);
  1217. //offsetPosition.z = 0.0f;
  1218. //OppRotate(offsetPosition,rotation);
  1219. Stuff::Vector3D actualPosition = position;
  1220. //actualPosition.Add(position,offsetPosition);
  1221. tPosition.x = -actualPosition.x;
  1222. tPosition.y = actualPosition.z;
  1223. tPosition.z = actualPosition.y;
  1224. float yaw = (180.0f + rotation) * DEGREES_TO_RADS;
  1225. Stuff::UnitQuaternion rot;
  1226. rot = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  1227. shapeOrigin.BuildRotation(rot);
  1228. shapeOrigin.BuildTranslation(tPosition);
  1229. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,NULL);
  1230. destructFX->Start(&info);
  1231. return true;
  1232. }
  1233. return false;
  1234. }
  1235. return false; //We didn't have a destruct effect. Tell the object to play its default.
  1236. }
  1237. //-----------------------------------------------------------------------------
  1238. long BldgAppearance::render (long depthFixup)
  1239. {
  1240. if (inView)
  1241. {
  1242. long color = SD_BLUE;
  1243. unsigned long highLight = 0x007f7f7f;
  1244. if ((teamId > -1) && (teamId < 8)) {
  1245. static unsigned long highLightTable[3] = {0x00007f00, 0x0000007f, 0x007f0000};
  1246. static long colorTable[3] = {SB_GREEN | 0xff000000, SB_BLUE | 0xff000000, SB_RED| 0xff000000};
  1247. color = colorTable[homeTeamRelationship];
  1248. highLight = highLightTable[homeTeamRelationship];
  1249. }
  1250. if (selected & DRAW_COLORED)
  1251. {
  1252. bldgShape->SetARGBHighLight(highLight);
  1253. }
  1254. else
  1255. {
  1256. bldgShape->SetARGBHighLight(highlightColor);
  1257. }
  1258. if (drawFlash)
  1259. {
  1260. bldgShape->SetARGBHighLight(flashColor);
  1261. }
  1262. //---------------------------------------------
  1263. // Call Multi-shape render stuff here.
  1264. if (appearType->spinMe)
  1265. bldgShape->Render(false,0.00001f);
  1266. else if (!depthFixup)
  1267. bldgShape->Render();
  1268. else if (depthFixup > 0)
  1269. bldgShape->Render(false,0.9999999f);
  1270. else if (depthFixup < 0)
  1271. bldgShape->Render(false,0.00001f);
  1272. if (selected & DRAW_BARS)
  1273. {
  1274. if (!appearType->spinMe)
  1275. {
  1276. drawBars();
  1277. //drawSelectBrackets(color);
  1278. }
  1279. }
  1280. if ( selected & DRAW_TEXT )
  1281. {
  1282. if (objectNameId != -1)
  1283. {
  1284. char tmpString[255];
  1285. cLoadString(objectNameId, tmpString, 254);
  1286. drawTextHelp(tmpString, color);
  1287. }
  1288. }
  1289. //------------------------------------------
  1290. // Render GOS FX if necessary
  1291. if (destructFX && destructFX->IsExecuted())
  1292. {
  1293. gosFX::Effect::DrawInfo drawInfo;
  1294. drawInfo.m_clipper = theClipper;
  1295. MidLevelRenderer::MLRState mlrState;
  1296. mlrState.SetDitherOn();
  1297. mlrState.SetTextureCorrectionOn();
  1298. mlrState.SetZBufferCompareOn();
  1299. mlrState.SetZBufferWriteOn();
  1300. drawInfo.m_state = mlrState;
  1301. drawInfo.m_clippingFlags = 0x0;
  1302. Stuff::LinearMatrix4D shapeOrigin;
  1303. Stuff::LinearMatrix4D localToWorld;
  1304. Stuff::Point3D tPosition;
  1305. //Stuff::Vector3D offsetPosition;
  1306. //offsetPosition.x = Terrain::worldUnitsPerVertex / 3.0f;
  1307. //offsetPosition.y = -(Terrain::worldUnitsPerVertex / 3.0f);
  1308. //offsetPosition.z = 0.0f;
  1309. //OppRotate(offsetPosition,rotation);
  1310. Stuff::Vector3D actualPosition = position;
  1311. //actualPosition.Add(position,offsetPosition);
  1312. tPosition.x = -actualPosition.x;
  1313. tPosition.y = actualPosition.z;
  1314. tPosition.z = actualPosition.y;
  1315. float yaw = (180.0f + rotation) * DEGREES_TO_RADS;
  1316. Stuff::UnitQuaternion rot;
  1317. rot = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  1318. shapeOrigin.BuildRotation(rot);
  1319. shapeOrigin.BuildTranslation(tPosition);
  1320. drawInfo.m_parentToWorld = &shapeOrigin;
  1321. if (!MLRVertexLimitReached)
  1322. destructFX->Draw(&drawInfo);
  1323. }
  1324. if (isActivitying)
  1325. {
  1326. gosFX::Effect::DrawInfo drawInfo;
  1327. drawInfo.m_clipper = theClipper;
  1328. MidLevelRenderer::MLRState mlrState;
  1329. mlrState.SetDitherOn();
  1330. mlrState.SetTextureCorrectionOn();
  1331. mlrState.SetZBufferCompareOn();
  1332. mlrState.SetZBufferWriteOn();
  1333. drawInfo.m_state = mlrState;
  1334. drawInfo.m_clippingFlags = 0x0;
  1335. Stuff::LinearMatrix4D shapeOrigin;
  1336. Stuff::LinearMatrix4D localToWorld;
  1337. Stuff::LinearMatrix4D localResult;
  1338. if (activityNodeId == -1)
  1339. activityNodeId = bldgShape->GetNodeNameId("activity_node");
  1340. Stuff::Vector3D dustPos = getNodeIdPosition(activityNodeId);
  1341. if (rotationalNodeId == -1)
  1342. {
  1343. if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
  1344. rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
  1345. else
  1346. rotationalNodeId = -2;
  1347. }
  1348. if (rotationalNodeId >= 0)
  1349. dustPos = getNodeIdPosition(rotationalNodeId);
  1350. Stuff::Point3D wakePos;
  1351. wakePos.x = -dustPos.x;
  1352. wakePos.y = dustPos.z;
  1353. wakePos.z = dustPos.y;
  1354. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  1355. shapeOrigin.BuildTranslation(wakePos);
  1356. /*
  1357. Stuff::UnitQuaternion effectRot;
  1358. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  1359. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  1360. localResult.Multiply(localToWorld,shapeOrigin);
  1361. */
  1362. drawInfo.m_parentToWorld = &shapeOrigin;
  1363. if (!MLRVertexLimitReached)
  1364. activity->Draw(&drawInfo);
  1365. if (activity1)
  1366. {
  1367. if (activityNodeId == -1)
  1368. activityNodeId = bldgShape->GetNodeNameId("activity_node");
  1369. Stuff::Vector3D dustPos = getNodeIdPosition(activityNodeId);
  1370. if (rotationalNodeId == -1)
  1371. {
  1372. if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
  1373. rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
  1374. else
  1375. rotationalNodeId = -2;
  1376. }
  1377. if (rotationalNodeId >= 0)
  1378. dustPos = getNodeIdPosition(rotationalNodeId);
  1379. Stuff::Point3D wakePos;
  1380. wakePos.x = -dustPos.x;
  1381. wakePos.y = dustPos.z;
  1382. wakePos.z = dustPos.y;
  1383. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  1384. shapeOrigin.BuildTranslation(wakePos);
  1385. /*
  1386. Stuff::UnitQuaternion effectRot;
  1387. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  1388. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  1389. localResult.Multiply(localToWorld,shapeOrigin);
  1390. */
  1391. drawInfo.m_parentToWorld = &shapeOrigin;
  1392. if (!MLRVertexLimitReached)
  1393. activity1->Draw(&drawInfo);
  1394. }
  1395. }
  1396. // selected = FALSE;
  1397. //#define DRAW_BOX
  1398. #ifdef DRAW_BOX
  1399. //---------------------------------------------------------
  1400. // Render the Bounding Box to see if it is OK.
  1401. Stuff::Vector3D nodeCenter = bldgShape->GetRootNodeCenter();
  1402. Stuff::Vector3D boxStart;
  1403. Stuff::Vector3D boxEnd;
  1404. boxStart.x = -(bldgShape->GetMinBox().x + nodeCenter.x);
  1405. boxStart.z = bldgShape->GetMinBox().y + nodeCenter.y;
  1406. boxStart.y = bldgShape->GetMinBox().z + nodeCenter.z;
  1407. boxEnd.x = -(bldgShape->GetMaxBox().x + nodeCenter.x);
  1408. boxEnd.z = bldgShape->GetMaxBox().y + nodeCenter.y;
  1409. boxEnd.y = bldgShape->GetMaxBox().z + nodeCenter.z;
  1410. Stuff::Vector3D boxCoords[8];
  1411. Stuff::Vector3D addCoords;
  1412. addCoords.x = boxStart.x;
  1413. addCoords.y = boxStart.y;
  1414. addCoords.z = boxEnd.z;
  1415. if (rotation != 0.0f)
  1416. Rotate(addCoords,-rotation);
  1417. boxCoords[0].Add(position,addCoords);
  1418. addCoords.x = boxStart.x;
  1419. addCoords.y = boxEnd.y;
  1420. addCoords.z = boxEnd.z;
  1421. if (rotation != 0.0f)
  1422. Rotate(addCoords,-rotation);
  1423. boxCoords[1].Add(position,addCoords);
  1424. addCoords.x = boxEnd.x;
  1425. addCoords.y = boxEnd.y;
  1426. addCoords.z = boxEnd.z;
  1427. if (rotation != 0.0f)
  1428. Rotate(addCoords,-rotation);
  1429. boxCoords[2].Add(position,addCoords);
  1430. addCoords.x = boxEnd.x;
  1431. addCoords.y = boxStart.y;
  1432. addCoords.z = boxEnd.z;
  1433. if (rotation != 0.0f)
  1434. Rotate(addCoords,-rotation);
  1435. boxCoords[3].Add(position,addCoords);
  1436. addCoords.x = boxStart.x;
  1437. addCoords.y = boxStart.y;
  1438. addCoords.z = boxStart.z;
  1439. if (rotation != 0.0f)
  1440. Rotate(addCoords,-rotation);
  1441. boxCoords[4].Add(position,addCoords);
  1442. addCoords.x = boxEnd.x;
  1443. addCoords.y = boxStart.y;
  1444. addCoords.z = boxStart.z;
  1445. if (rotation != 0.0f)
  1446. Rotate(addCoords,-rotation);
  1447. boxCoords[5].Add(position,addCoords);
  1448. addCoords.x = boxEnd.x;
  1449. addCoords.y = boxEnd.y;
  1450. addCoords.z = boxStart.z;
  1451. if (rotation != 0.0f)
  1452. Rotate(addCoords,-rotation);
  1453. boxCoords[6].Add(position,addCoords);
  1454. addCoords.x = boxStart.x;
  1455. addCoords.y = boxEnd.y;
  1456. addCoords.z = boxStart.z;
  1457. if (rotation != 0.0f)
  1458. Rotate(addCoords,-rotation);
  1459. boxCoords[7].Add(position,addCoords);
  1460. Stuff::Vector4D screenPos[8];
  1461. for (long i=0;i<8;i++)
  1462. {
  1463. eye->projectZ(boxCoords[i],screenPos[i]);
  1464. }
  1465. {
  1466. LineElement newElement(screenPos[0],screenPos[1],XP_WHITE,NULL,-1);
  1467. newElement.draw();
  1468. }
  1469. {
  1470. LineElement newElement(screenPos[0],screenPos[4],XP_WHITE,NULL,-1);
  1471. newElement.draw();
  1472. }
  1473. {
  1474. LineElement newElement(screenPos[0],screenPos[3],XP_WHITE,NULL,-1);
  1475. newElement.draw();
  1476. }
  1477. {
  1478. LineElement newElement(screenPos[5],screenPos[4],XP_WHITE,NULL,-1);
  1479. newElement.draw();
  1480. }
  1481. {
  1482. LineElement newElement(screenPos[5],screenPos[6],XP_WHITE,NULL,-1);
  1483. newElement.draw();
  1484. }
  1485. {
  1486. LineElement newElement(screenPos[5],screenPos[3],XP_WHITE,NULL,-1);
  1487. newElement.draw();
  1488. }
  1489. {
  1490. LineElement newElement(screenPos[2],screenPos[3],XP_WHITE,NULL,-1);
  1491. newElement.draw();
  1492. }
  1493. {
  1494. LineElement newElement(screenPos[2],screenPos[6],XP_WHITE,NULL,-1);
  1495. newElement.draw();
  1496. }
  1497. {
  1498. LineElement newElement(screenPos[2],screenPos[1],XP_WHITE,NULL,-1);
  1499. newElement.draw();
  1500. }
  1501. {
  1502. LineElement newElement(screenPos[7],screenPos[1],XP_WHITE,NULL,-1);
  1503. newElement.draw();
  1504. }
  1505. {
  1506. LineElement newElement(screenPos[7],screenPos[6],XP_WHITE,NULL,-1);
  1507. newElement.draw();
  1508. }
  1509. {
  1510. LineElement newElement(screenPos[7],screenPos[4],XP_WHITE,NULL,-1);
  1511. newElement.draw();
  1512. }
  1513. #endif
  1514. #undef DRAW_BOX
  1515. }
  1516. return NO_ERR;
  1517. }
  1518. //-----------------------------------------------------------------------------
  1519. long BldgAppearance::renderShadows (void)
  1520. {
  1521. if (inView && visible && !appearType->spinMe)
  1522. {
  1523. //---------------------------------------------
  1524. // Call Multi-shape render stuff here.
  1525. if (bldgShadowShape)
  1526. bldgShadowShape->RenderShadows();
  1527. else
  1528. bldgShape->RenderShadows();
  1529. }
  1530. return NO_ERR;
  1531. }
  1532. //-----------------------------------------------------------------------------
  1533. long BldgAppearance::update (bool animate)
  1534. {
  1535. Stuff::Point3D xlatPosition;
  1536. Stuff::UnitQuaternion rot;
  1537. //----------------------------------------
  1538. // Recycle the weapon Nodes
  1539. if (nodeRecycle)
  1540. {
  1541. for (long i=0;i<appearType->numWeaponNodes;i++)
  1542. {
  1543. if (nodeRecycle[i] > 0.0f)
  1544. {
  1545. nodeRecycle[i] -= frameLength;
  1546. if (nodeRecycle[i] < 0.0f)
  1547. nodeRecycle[i] = 0.0f;
  1548. }
  1549. }
  1550. }
  1551. if (appearType->terrainLightRGB != 0xffffffff && (eye->nightFactor > 0.0f) && !forceLightsOut)
  1552. {
  1553. if (!pointLight)
  1554. {
  1555. pointLight = (TG_LightPtr)malloc(sizeof(TG_Light));
  1556. pointLight->init(TG_LIGHT_TERRAIN);
  1557. lightId = eye->addWorldLight(pointLight);
  1558. pointLight->SetaRGB(appearType->terrainLightRGB);
  1559. pointLight->SetIntensity(appearType->terrainLightIntensity);
  1560. pointLight->SetFalloffDistances(appearType->terrainLightInnerRadius, appearType->terrainLightOuterRadius);
  1561. }
  1562. if (pointLight)
  1563. {
  1564. Stuff::Point3D ourPosition;
  1565. ourPosition.x = -position.x;
  1566. ourPosition.y = position.z;
  1567. ourPosition.z = position.y;
  1568. pointLight->direction = ourPosition;
  1569. Stuff::LinearMatrix4D lightToWorldMatrix;
  1570. lightToWorldMatrix.BuildTranslation(ourPosition);
  1571. lightToWorldMatrix.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  1572. pointLight->SetLightToWorld(&lightToWorldMatrix);
  1573. pointLight->SetPosition(&position);
  1574. pointLight->SetIntensity(appearType->terrainLightIntensity * eye->getNightFactor());
  1575. }
  1576. }
  1577. else
  1578. {
  1579. //Turn the lights off!
  1580. //Need to kill the light source here too!
  1581. if (pointLight)
  1582. {
  1583. eye->removeWorldLight(lightId,pointLight);
  1584. free(pointLight);
  1585. pointLight = NULL;
  1586. }
  1587. }
  1588. if (forceLightsOut)
  1589. bldgShape->SetLightsOut(true);
  1590. //Update flashing regardless of view!!!
  1591. if (duration > 0.0f)
  1592. {
  1593. duration -= frameLength;
  1594. currentFlash -= frameLength;
  1595. if (currentFlash < 0.0f)
  1596. {
  1597. drawFlash ^= true;
  1598. currentFlash = flashDuration;
  1599. }
  1600. }
  1601. else
  1602. {
  1603. drawFlash = false;
  1604. }
  1605. if (inView)
  1606. {
  1607. if (appearType->spinMe)
  1608. rotation += SPINRATE * frameLength;
  1609. if (rotation > 180)
  1610. rotation -= 360;
  1611. if (rotation < -180)
  1612. rotation += 360;
  1613. //-------------------------------------------
  1614. // Does math necessary to draw Tree
  1615. float yaw = rotation * DEGREES_TO_RADS;
  1616. rot = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  1617. if (appearType->spinMe && land)
  1618. {
  1619. //Make sure we are above the water level
  1620. if (position.z < Terrain::waterElevation)
  1621. position.z = Terrain::waterElevation;
  1622. }
  1623. xlatPosition.x = -position.x;
  1624. xlatPosition.y = position.z;
  1625. xlatPosition.z = position.y;
  1626. if (!fogLightSet)
  1627. {
  1628. unsigned char lightr,lightg,lightb;
  1629. float lightIntensity = 1.0f;
  1630. if (land)
  1631. lightIntensity = land->getTerrainLight(position);
  1632. lightr = eye->getLightRed(lightIntensity);
  1633. lightg = eye->getLightGreen(lightIntensity);
  1634. lightb = eye->getLightBlue(lightIntensity);
  1635. lightRGB = (lightr<<16) + (lightg<<8) + lightb;
  1636. fogRGB = 0xff<<24;
  1637. float fogStart = eye->fogStart;
  1638. float fogFull = eye->fogFull;
  1639. if (xlatPosition.y < fogStart)
  1640. {
  1641. float fogFactor = fogStart - xlatPosition.y;
  1642. if (fogFactor < 0.0)
  1643. fogRGB = 0xff<<24;
  1644. else
  1645. {
  1646. fogFactor /= (fogStart - fogFull);
  1647. if (fogFactor <= 1.0)
  1648. {
  1649. fogFactor *= fogFactor;
  1650. fogFactor = 1.0 - fogFactor;
  1651. fogFactor *= 256.0;
  1652. }
  1653. else
  1654. {
  1655. fogFactor = 256.0;
  1656. }
  1657. unsigned char fogResult = float2long(fogFactor);
  1658. fogRGB = fogResult << 24;
  1659. }
  1660. }
  1661. else
  1662. {
  1663. fogRGB = 0xff<<24;
  1664. }
  1665. fogLightSet = true;
  1666. }
  1667. eye->setLightColor(0,lightRGB);
  1668. eye->setLightIntensity(0,1.0);
  1669. if (useFog)
  1670. bldgShape->SetFogRGB(fogRGB);
  1671. else
  1672. bldgShape->SetFogRGB(0xffffffff);
  1673. Stuff::UnitQuaternion turretRot;
  1674. turretRot = Stuff::EulerAngles((turretPitch * DEGREES_TO_RADS),(turretYaw * DEGREES_TO_RADS),0.0f);
  1675. if (rotationalNodeId == -1)
  1676. rotationalNodeId = bldgShape->SetNodeRotation(appearType->rotationalNodeId,&turretRot);
  1677. bldgShape->SetNodeRotation(rotationalNodeId,&turretRot);
  1678. }
  1679. float oldFrame = currentFrame;
  1680. if (animate && bdFrameRate != 0.0f)
  1681. {
  1682. //--------------------------------------------------------
  1683. // Make sure animation runs no faster than bdFrameRate fps.
  1684. float frameInc = bdFrameRate * frameLength;
  1685. //---------------------------------------
  1686. // Increment Frames -- Everything else!
  1687. if (frameInc != 0.0f)
  1688. {
  1689. if (!setFirstFrame) //DO NOT ANIMATE ON FIRST FRAME! Wait a bit!
  1690. {
  1691. if (isReversed)
  1692. currentFrame -= frameInc;
  1693. else
  1694. currentFrame += frameInc;
  1695. }
  1696. else
  1697. {
  1698. setFirstFrame = false;
  1699. }
  1700. //--------------------------------------
  1701. //Check Positive overflow of Animation
  1702. if (currentFrame >= appearType->getNumFrames(bdAnimationState))
  1703. {
  1704. if (isLooping)
  1705. currentFrame -= appearType->getNumFrames(bdAnimationState);
  1706. else
  1707. currentFrame = appearType->getNumFrames(bdAnimationState) - 1;
  1708. canTransition = true; //Whenever we have completed one cycle or at last frame, OK to move on!
  1709. }
  1710. //--------------------------------------
  1711. //Check negative overflow of gesture
  1712. if (currentFrame < 0)
  1713. {
  1714. if (isLooping)
  1715. currentFrame += appearType->getNumFrames(bdAnimationState);
  1716. else
  1717. currentFrame = 0.0f;
  1718. canTransition = true; //Whenever we have completed one cycle or at last frame, OK to move on!
  1719. }
  1720. }
  1721. bldgShape->SetFrameNum(currentFrame);
  1722. }
  1723. if (inView)
  1724. {
  1725. bool checkShadows = ((!beenInView) || (appearType->spinMe) || (eye->forceShadowRecalc) || (currentFrame != oldFrame));
  1726. if (bldgShadowShape)
  1727. bldgShape->SetUseShadow(false);
  1728. else
  1729. bldgShape->SetRecalcShadows(checkShadows);
  1730. bldgShape->SetLightList(eye->getWorldLights(),eye->getNumLights());
  1731. bldgShape->TransformMultiShape (&xlatPosition,&rot);
  1732. if (bldgShadowShape && useShadows)
  1733. {
  1734. bldgShadowShape->SetRecalcShadows(checkShadows);
  1735. bldgShadowShape->SetLightList(eye->getWorldLights(),eye->getNumLights());
  1736. bldgShadowShape->TransformMultiShape (&xlatPosition,&rot);
  1737. }
  1738. if ((turn > 3) && useShadows)
  1739. beenInView = true;
  1740. //------------------------------------------------
  1741. // Update GOSFX
  1742. if (destructFX && destructFX->IsExecuted())
  1743. {
  1744. Stuff::LinearMatrix4D shapeOrigin;
  1745. Stuff::LinearMatrix4D localToWorld;
  1746. Stuff::Point3D tPosition;
  1747. //Stuff::Vector3D offsetPosition;
  1748. //offsetPosition.x = Terrain::worldUnitsPerVertex / 3.0f;
  1749. //offsetPosition.y = -(Terrain::worldUnitsPerVertex / 3.0f);
  1750. //offsetPosition.z = 0.0f;
  1751. //OppRotate(offsetPosition,rotation);
  1752. Stuff::Vector3D actualPosition = position;
  1753. //actualPosition.Add(position,offsetPosition);
  1754. tPosition.x = -actualPosition.x;
  1755. tPosition.y = actualPosition.z;
  1756. tPosition.z = actualPosition.y;
  1757. float yaw = (180.0f + rotation) * DEGREES_TO_RADS;
  1758. Stuff::UnitQuaternion rot;
  1759. rot = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  1760. shapeOrigin.BuildRotation(rot);
  1761. shapeOrigin.BuildTranslation(tPosition);
  1762. Stuff::OBB boundingBox;
  1763. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,&boundingBox);
  1764. bool result = destructFX->Execute(&info);
  1765. if (!result)
  1766. {
  1767. destructFX->Kill();
  1768. delete destructFX;
  1769. destructFX = NULL;
  1770. }
  1771. }
  1772. if (isActivitying)
  1773. {
  1774. Stuff::LinearMatrix4D shapeOrigin;
  1775. Stuff::LinearMatrix4D localToWorld;
  1776. Stuff::LinearMatrix4D localResult;
  1777. if (activityNodeId == -1)
  1778. activityNodeId = bldgShape->GetNodeNameId("activity_node");
  1779. Stuff::Vector3D dustPos = getNodeIdPosition(activityNodeId);
  1780. if (rotationalNodeId == -1)
  1781. {
  1782. if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
  1783. rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
  1784. else
  1785. rotationalNodeId = -2;
  1786. }
  1787. if (rotationalNodeId >= 0)
  1788. dustPos = getNodeIdPosition(rotationalNodeId);
  1789. Stuff::Point3D wakePos;
  1790. wakePos.x = -dustPos.x;
  1791. wakePos.y = dustPos.z;
  1792. wakePos.z = dustPos.y;
  1793. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  1794. shapeOrigin.BuildTranslation(wakePos);
  1795. /*
  1796. Stuff::UnitQuaternion effectRot;
  1797. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  1798. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  1799. localResult.Multiply(localToWorld,shapeOrigin);
  1800. */
  1801. Stuff::OBB boundingBox;
  1802. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,&boundingBox);
  1803. activity->Execute(&info);
  1804. if (activity1)
  1805. {
  1806. if (activityNodeId == -1)
  1807. activityNodeId = bldgShape->GetNodeNameId("activity_node");
  1808. Stuff::Vector3D dustPos = getNodeIdPosition(activityNodeId);
  1809. if (rotationalNodeId == -1)
  1810. {
  1811. if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
  1812. rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
  1813. else
  1814. rotationalNodeId = -2;
  1815. }
  1816. if (rotationalNodeId >= 0)
  1817. dustPos = getNodeIdPosition(rotationalNodeId);
  1818. Stuff::Point3D wakePos;
  1819. wakePos.x = -dustPos.x;
  1820. wakePos.y = dustPos.z;
  1821. wakePos.z = dustPos.y;
  1822. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  1823. shapeOrigin.BuildTranslation(wakePos);
  1824. /*
  1825. Stuff::UnitQuaternion effectRot;
  1826. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  1827. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  1828. localResult.Multiply(localToWorld,shapeOrigin);
  1829. */
  1830. Stuff::OBB boundingBox;
  1831. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,&boundingBox);
  1832. activity1->Execute(&info);
  1833. }
  1834. }
  1835. }
  1836. return TRUE;
  1837. }
  1838. //-----------------------------------------------------------------------------
  1839. void BldgAppearance::startActivity (long effectId, bool loop)
  1840. {
  1841. //Check if we are already playing one. If not, be active!
  1842. //First, check if its even loaded.
  1843. // can easily preload this. Should we? NO. We don't know what will be passed in.
  1844. if (!activity && useNonWeaponEffects)
  1845. {
  1846. if (strcmp(weaponEffects->GetEffectName(effectId),"NONE") != 0)
  1847. {
  1848. //--------------------------------------------
  1849. // Yes, load it on up.
  1850. unsigned flags = gosFX::Effect::ExecuteFlag|gosFX::Effect::LoopFlag;
  1851. if (!loop)
  1852. flags = gosFX::Effect::ExecuteFlag;
  1853. Check_Object(gosFX::EffectLibrary::Instance);
  1854. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(effectId));
  1855. if (gosEffectSpec)
  1856. {
  1857. activity = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  1858. gosASSERT(activity != NULL);
  1859. Stuff::Vector3D testPos = getNodeNamePosition("activity_node1");
  1860. if (testPos != position)
  1861. {
  1862. activity1 = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  1863. gosASSERT(activity != NULL);
  1864. }
  1865. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  1866. }
  1867. }
  1868. }
  1869. if (!isActivitying && activity) //Start the effect if we are not running it yet!!
  1870. {
  1871. Stuff::LinearMatrix4D shapeOrigin;
  1872. Stuff::LinearMatrix4D localToWorld;
  1873. Stuff::LinearMatrix4D localResult;
  1874. if (activityNodeId == -1)
  1875. activityNodeId = bldgShape->GetNodeNameId("activity_node");
  1876. Stuff::Vector3D nodePos = getNodeIdPosition(activityNodeId);
  1877. if (rotationalNodeId == -1)
  1878. {
  1879. if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
  1880. rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
  1881. else
  1882. rotationalNodeId = -2;
  1883. }
  1884. if (rotationalNodeId >= 0)
  1885. nodePos = getNodeIdPosition(rotationalNodeId);
  1886. Stuff::Point3D wakePos;
  1887. wakePos.x = -nodePos.x;
  1888. wakePos.y = nodePos.z; //Wake is at Water Level!
  1889. wakePos.z = nodePos.y;
  1890. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  1891. shapeOrigin.BuildTranslation(wakePos);
  1892. /*
  1893. Stuff::UnitQuaternion effectRot;
  1894. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  1895. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  1896. localResult.Multiply(localToWorld,shapeOrigin);
  1897. */
  1898. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,NULL);
  1899. activity->Start(&info);
  1900. if (activity1)
  1901. {
  1902. if (activityNode1Id == -1)
  1903. activityNode1Id = bldgShape->GetNodeNameId("activity_node1");
  1904. Stuff::Vector3D nodePos = getNodeIdPosition(activityNode1Id);
  1905. if (rotationalNodeId == -1)
  1906. {
  1907. if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
  1908. rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
  1909. else
  1910. rotationalNodeId = -2;
  1911. }
  1912. if (rotationalNodeId >= 0)
  1913. nodePos = getNodeIdPosition(rotationalNodeId);
  1914. Stuff::Point3D wakePos;
  1915. wakePos.x = -nodePos.x;
  1916. wakePos.y = nodePos.z; //Wake is at Water Level!
  1917. wakePos.z = nodePos.y;
  1918. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  1919. shapeOrigin.BuildTranslation(wakePos);
  1920. /*
  1921. Stuff::UnitQuaternion effectRot;
  1922. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  1923. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  1924. localResult.Multiply(localToWorld,shapeOrigin);
  1925. */
  1926. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,NULL);
  1927. activity1->Start(&info);
  1928. }
  1929. isActivitying = true;
  1930. }
  1931. }
  1932. //-----------------------------------------------------------------------------
  1933. void BldgAppearance::stopActivity (void)
  1934. {
  1935. if (isActivitying) //Stop the effect if we are running it!!
  1936. {
  1937. activity->Kill();
  1938. if (activity1)
  1939. activity1->Kill();
  1940. }
  1941. isActivitying = false;
  1942. }
  1943. //-----------------------------------------------------------------------------
  1944. void BldgAppearance::flashBuilding (float dur, float fDuration, DWORD color)
  1945. {
  1946. duration = dur;
  1947. flashDuration = fDuration;
  1948. flashColor = color;
  1949. drawFlash = true;
  1950. currentFlash = flashDuration;
  1951. }
  1952. //-----------------------------------------------------------------------------
  1953. void BldgAppearance::destroy (void)
  1954. {
  1955. if ( bldgShape )
  1956. {
  1957. delete bldgShape;
  1958. bldgShape = NULL;
  1959. }
  1960. if (bldgShadowShape)
  1961. {
  1962. delete bldgShadowShape;
  1963. bldgShadowShape = NULL;
  1964. }
  1965. if (destructFX)
  1966. {
  1967. destructFX->Kill();
  1968. delete destructFX;
  1969. destructFX = NULL;
  1970. }
  1971. //Turn the lights off!
  1972. //Need to kill the light source here too!
  1973. if (pointLight)
  1974. {
  1975. if (eye)
  1976. eye->removeWorldLight(lightId,pointLight);
  1977. free(pointLight);
  1978. pointLight = NULL;
  1979. }
  1980. appearanceTypeList->removeAppearance(appearType);
  1981. }
  1982. #define HEIGHT_THRESHOLD 10.0f
  1983. //-----------------------------------------------------------------------------
  1984. long BldgAppearance::calcCellsCovered (Stuff::Vector3D& pos, short* cellList) {
  1985. gosASSERT((Terrain::realVerticesMapSide * MAPCELL_DIM) == GameMap->width);
  1986. long numCoords = 0;
  1987. long maxCoords = cellList[0];
  1988. //MUST force building to HIGHEST LOD!!! IMpassability data is only valid at this LOD!!
  1989. // Building will reset its LOD on next draw!!
  1990. if (currentLOD)
  1991. {
  1992. currentLOD = 0;
  1993. bldgShape->ClearAnimation();
  1994. delete bldgShape;
  1995. bldgShape = NULL;
  1996. bldgShape = appearType->bldgShape[currentLOD]->CreateFrom();
  1997. if (bdAnimationState != -1)
  1998. appearType->setAnimation(bldgShape,bdAnimationState);
  1999. }
  2000. //-------------------------------------------------------------
  2001. // New way. For each vertex in each shape, translate to world
  2002. for (long i=0;i<bldgShape->GetNumShapes();i++)
  2003. {
  2004. //Check if the artists meant for this piece to NOT block passability!!
  2005. if (strnicmp(bldgShape->GetNodeId(i),"_PAB",4) != 0)
  2006. {
  2007. for (long j=0;j<bldgShape->GetNumVerticesInShape(i);j++)
  2008. {
  2009. Stuff::Vector3D vertexPos, worldPos;
  2010. vertexPos = bldgShape->GetShapeVertexInEditor(i,j,-rotation);
  2011. worldPos.Add(pos,vertexPos);
  2012. bool recordCell = false;
  2013. if (appearType->isForestClump)
  2014. recordCell = (vertexPos.z <= 1.0f);
  2015. else
  2016. recordCell = (vertexPos.z >= 1.0f);
  2017. if (recordCell)
  2018. {
  2019. long cellR, cellC;
  2020. land->worldToCell(worldPos,cellR,cellC);
  2021. if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR)
  2022. || (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
  2023. {
  2024. //gosASSERT(false);
  2025. continue;
  2026. }
  2027. // if (GameMap->inBounds(cellR, cellC)) {
  2028. //-------------------
  2029. // Record the cell...
  2030. if (numCoords > (maxCoords - 2))
  2031. Fatal(numCoords, "BldgAppearance.markMoveMap: too many coords for cellList ");
  2032. cellList[numCoords++] = (short)cellR;
  2033. cellList[numCoords++] = (short)cellC;
  2034. // }
  2035. }
  2036. }
  2037. }
  2038. }
  2039. return(numCoords);
  2040. }
  2041. //-----------------------------------------------------------------------------
  2042. void BldgAppearance::markTerrain (_ScenarioMapCellInfo* pInfo, int type, int counter)
  2043. {
  2044. if (appearType->spinMe) //We are a marker
  2045. return; //Do not mark impassable
  2046. //MUST force building to HIGHEST LOD!!! IMpassability data is only valid at this LOD!!
  2047. // Building will reset its LOD on next draw!!
  2048. if (currentLOD)
  2049. {
  2050. currentLOD = 0;
  2051. bldgShape->ClearAnimation();
  2052. delete bldgShape;
  2053. bldgShape = NULL;
  2054. bldgShape = appearType->bldgShape[currentLOD]->CreateFrom();
  2055. if (bdAnimationState != -1)
  2056. appearType->setAnimation(bldgShape,bdAnimationState);
  2057. }
  2058. long cellR, cellC;
  2059. land->worldToCell(position, cellR, cellC);
  2060. if (appearType->isForestClump)
  2061. {
  2062. //-------------------------------------------------------------
  2063. // New way. For each vertex in each shape, translate to world
  2064. for (long i=0;i<bldgShape->GetNumShapes();i++)
  2065. {
  2066. //Check if the artists meant for this piece to NOT block passability!!
  2067. if (strnicmp(bldgShape->GetNodeId(i),"_PAB",4) != 0)
  2068. {
  2069. for (long j=0;j<bldgShape->GetNumVerticesInShape(i);j++)
  2070. {
  2071. Stuff::Vector3D vertexPos, worldPos;
  2072. vertexPos = bldgShape->GetShapeVertexInEditor(i,j,-rotation);
  2073. worldPos.Add(position,vertexPos);
  2074. long cellR, cellC;
  2075. land->worldToCell(worldPos,cellR,cellC);
  2076. if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
  2077. (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
  2078. {
  2079. continue;
  2080. }
  2081. _ScenarioMapCellInfo*pTmp = &(pInfo[cellR * Terrain::realVerticesMapSide * MAPCELL_DIM + cellC]);
  2082. if (vertexPos.z <= 1.0f)
  2083. {
  2084. pTmp->passable = true;
  2085. pTmp->gate = false;
  2086. pTmp->forest = true;
  2087. //pTmp->specialType = type;
  2088. //pTmp->specialID = counter;
  2089. }
  2090. float cellLocalHeight = vertexPos.z * metersPerWorldUnit * 0.25f;
  2091. if (cellLocalHeight > 15.0f)
  2092. cellLocalHeight = 15.0f;
  2093. //ONLY mark LOS on cells that are impassable with forests. Maybe everything?
  2094. if (pTmp->passable && (pTmp->lineOfSight < cellLocalHeight))
  2095. pTmp->lineOfSight = cellLocalHeight+0.5f;
  2096. }
  2097. }
  2098. }
  2099. }
  2100. else
  2101. {
  2102. if ((type == SPECIAL_GATE) || (type == SPECIAL_WALL))
  2103. {
  2104. if (appearType->bldgShape[0])
  2105. {
  2106. bldgShape->ClearAnimation();
  2107. delete bldgShape;
  2108. bldgShape = NULL;
  2109. bldgShape = appearType->bldgShape[0]->CreateFrom();
  2110. if (bdAnimationState != -1)
  2111. appearType->setAnimation(bldgShape,bdAnimationState);
  2112. }
  2113. }
  2114. if (type == SPECIAL_LAND_BRIDGE)
  2115. {
  2116. if (appearType->bldgDmgShape)
  2117. {
  2118. bldgShape->ClearAnimation();
  2119. delete bldgShape;
  2120. bldgShape = NULL;
  2121. bldgShape = appearType->bldgDmgShape->CreateFrom();
  2122. if (bdAnimationState != -1)
  2123. appearType->setAnimation(bldgShape,bdAnimationState);
  2124. }
  2125. }
  2126. //-------------------------------------------------------------
  2127. // New way. For each vertex in each shape, translate to world
  2128. for (long i=0;i<bldgShape->GetNumShapes();i++)
  2129. {
  2130. //Check if the artists meant for this piece to NOT block passability!!
  2131. if (strnicmp(bldgShape->GetNodeId(i),"_PAB",4) != 0)
  2132. {
  2133. for (long j=0;j<bldgShape->GetNumVerticesInShape(i);j++)
  2134. {
  2135. Stuff::Vector3D vertexPos, worldPos;
  2136. vertexPos = bldgShape->GetShapeVertexInEditor(i,j,-rotation);
  2137. worldPos.Add(position,vertexPos);
  2138. long cellR, cellC;
  2139. land->worldToCell(worldPos,cellR,cellC);
  2140. if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
  2141. (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
  2142. {
  2143. continue;
  2144. }
  2145. _ScenarioMapCellInfo*pTmp = &(pInfo[cellR * Terrain::realVerticesMapSide * MAPCELL_DIM + cellC]);
  2146. if (vertexPos.z >= 1.0f)
  2147. {
  2148. pTmp->passable = false;
  2149. if (((type == SPECIAL_GATE) || (type == SPECIAL_WALL)))
  2150. {
  2151. pTmp->passable = true;
  2152. pTmp->specialID = counter;
  2153. pTmp->specialType = type;
  2154. if (type == SPECIAL_GATE)
  2155. pTmp->gate = true;
  2156. }
  2157. else if (type == SPECIAL_LAND_BRIDGE)
  2158. {
  2159. pTmp->passable = true;
  2160. pTmp->specialID = counter;
  2161. pTmp->specialType = type;
  2162. }
  2163. else if (type == 18)
  2164. {
  2165. pTmp->specialID = 0;
  2166. pTmp->specialType = SPECIAL_NONE;
  2167. pTmp->passable = true;
  2168. }
  2169. else
  2170. {
  2171. pTmp->specialID = 0;
  2172. pTmp->specialType = SPECIAL_NONE;
  2173. }
  2174. if (type != 18)
  2175. {
  2176. float cellLocalHeight = vertexPos.z * metersPerWorldUnit * 0.25f;
  2177. if (cellLocalHeight > 15.0f)
  2178. cellLocalHeight = 15.0f;
  2179. if (pTmp->lineOfSight < cellLocalHeight)
  2180. pTmp->lineOfSight = cellLocalHeight+0.5f;
  2181. }
  2182. }
  2183. }
  2184. }
  2185. }
  2186. //Switch to destroyed state to mark impassable. The destroyed impassability will NEVER change!!
  2187. // When a gate opens or a wall or gate is destroyed, we only want to mark stuff that is going
  2188. // away passable and long range capable.
  2189. if ((type == SPECIAL_GATE) || (type == SPECIAL_WALL))
  2190. {
  2191. if (appearType->bldgDmgShape)
  2192. {
  2193. bldgShape->ClearAnimation();
  2194. delete bldgShape;
  2195. bldgShape = NULL;
  2196. bldgShape = appearType->bldgDmgShape->CreateFrom();
  2197. if (bdAnimationState != -1)
  2198. appearType->setAnimation(bldgShape,bdAnimationState);
  2199. }
  2200. }
  2201. if (type == SPECIAL_LAND_BRIDGE)
  2202. {
  2203. if (appearType->bldgShape[0])
  2204. {
  2205. bldgShape->ClearAnimation();
  2206. delete bldgShape;
  2207. bldgShape = NULL;
  2208. bldgShape = appearType->bldgShape[0]->CreateFrom();
  2209. if (bdAnimationState != -1)
  2210. appearType->setAnimation(bldgShape,bdAnimationState);
  2211. }
  2212. }
  2213. //-------------------------------------------------------------
  2214. // New way. For each vertex in each shape, translate to world
  2215. for (i=0;i<bldgShape->GetNumShapes();i++)
  2216. {
  2217. //Check if the artists meant for this piece to NOT block passability!!
  2218. if (strnicmp(bldgShape->GetNodeId(i),"_PAB",4) != 0)
  2219. {
  2220. for (long j=0;j<bldgShape->GetNumVerticesInShape(i);j++)
  2221. {
  2222. Stuff::Vector3D vertexPos, worldPos;
  2223. vertexPos = bldgShape->GetShapeVertexInEditor(i,j,-rotation);
  2224. worldPos.Add(position,vertexPos);
  2225. long cellR, cellC;
  2226. land->worldToCell(worldPos,cellR,cellC);
  2227. if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
  2228. (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
  2229. {
  2230. continue;
  2231. }
  2232. _ScenarioMapCellInfo*pTmp = &(pInfo[cellR * Terrain::realVerticesMapSide * MAPCELL_DIM + cellC]);
  2233. if (vertexPos.z >= 1.0f)
  2234. {
  2235. if (type == 18)
  2236. {
  2237. pTmp->passable = true;
  2238. pTmp->specialID = 0;
  2239. pTmp->specialType = SPECIAL_NONE;
  2240. }
  2241. else
  2242. {
  2243. pTmp->passable = false;
  2244. pTmp->gate = false; //Perfectly OK to mark these again, They are no longer special!!
  2245. pTmp->specialID = 0;
  2246. pTmp->specialType = SPECIAL_NONE;
  2247. }
  2248. }
  2249. }
  2250. }
  2251. }
  2252. if ((status != OBJECT_STATUS_DESTROYED) && appearType->bldgShape[0])
  2253. {
  2254. bldgShape->ClearAnimation();
  2255. delete bldgShape;
  2256. bldgShape = NULL;
  2257. bldgShape = appearType->bldgShape[0]->CreateFrom();
  2258. if (bdAnimationState != -1)
  2259. appearType->setAnimation(bldgShape,bdAnimationState);
  2260. }
  2261. else if ((status == OBJECT_STATUS_DESTROYED) && appearType->bldgDmgShape)
  2262. {
  2263. bldgShape->ClearAnimation();
  2264. delete bldgShape;
  2265. bldgShape = NULL;
  2266. bldgShape = appearType->bldgDmgShape->CreateFrom();
  2267. if (bdAnimationState != -1)
  2268. appearType->setAnimation(bldgShape,bdAnimationState);
  2269. }
  2270. }
  2271. }
  2272. //-----------------------------------------------------------------------------
  2273. long BldgAppearance::markMoveMap (bool passable, long* lineOfSightRect, bool useHeight, short* cellList)
  2274. {
  2275. long minRow = 9999;
  2276. long maxRow = 0;
  2277. long minCol = 9999;
  2278. long maxCol = 0;
  2279. //MUST force building to HIGHEST LOD!!! IMpassability data is only valid at this LOD!!
  2280. // Building will reset its LOD on next draw!!
  2281. TG_MultiShapePtr tempBldgShape = bldgShape;
  2282. if (currentLOD)
  2283. {
  2284. tempBldgShape = appearType->bldgShape[currentLOD]->CreateFrom();
  2285. if (bdAnimationState != -1)
  2286. appearType->setAnimation(tempBldgShape,bdAnimationState);
  2287. }
  2288. long numCoords = 0;
  2289. if (cellList) {
  2290. gosASSERT(!useHeight);
  2291. //----------------------------------------------------------------------------------
  2292. // Store the max number of coords allowed in the first cell. Can overwrite it now...
  2293. long maxCoords = cellList[0];
  2294. //-------------------------------------------------------------
  2295. // New way. For each vertex in each shape, translate to world
  2296. for (long i = 0; i < tempBldgShape->GetNumShapes(); i++)
  2297. {
  2298. //Check if the artists meant for this piece to NOT block passability!!
  2299. if (strnicmp(tempBldgShape->GetNodeId(i),"_PAB",4) != 0)
  2300. {
  2301. for (long j=0;j<tempBldgShape->GetNumVerticesInShape(i);j++)
  2302. {
  2303. Stuff::Vector3D vertexPos, worldPos;
  2304. vertexPos = tempBldgShape->GetShapeVertexInWorld(i,j,-rotation);
  2305. worldPos.Add(position,vertexPos);
  2306. long cellR, cellC;
  2307. land->worldToCell(worldPos,cellR,cellC);
  2308. if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
  2309. (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
  2310. {
  2311. continue;
  2312. }
  2313. //----------------------------
  2314. // Building lineOfSightRect...
  2315. if (cellR < minRow)
  2316. minRow = cellR;
  2317. if (cellR > maxRow)
  2318. maxRow = cellR;
  2319. if (cellC < minCol)
  2320. minCol = cellC;
  2321. if (cellC > maxCol)
  2322. maxCol = cellC;
  2323. //-------------------
  2324. // Record the cell...
  2325. if (numCoords > (maxCoords - 2))
  2326. Fatal(numCoords, "BldgAppearance.markMoveMap: too many coords for cellList ");
  2327. cellList[numCoords++] = (short)cellR;
  2328. cellList[numCoords++] = (short)cellC;
  2329. }
  2330. }
  2331. }
  2332. }
  2333. else
  2334. {
  2335. //-------------------------------------------------------------
  2336. // New way. For each vertex in each shape, translate to world
  2337. for (long i=0;i<tempBldgShape->GetNumShapes();i++)
  2338. {
  2339. //Check if the artists meant for this piece to NOT block passability!!
  2340. if (strnicmp(tempBldgShape->GetNodeId(i),"_PAB",4) != 0)
  2341. {
  2342. for (long j=0;j<tempBldgShape->GetNumVerticesInShape(i);j++)
  2343. {
  2344. Stuff::Vector3D vertexPos, worldPos;
  2345. vertexPos = tempBldgShape->GetShapeVertexInWorld(i,j,-rotation);
  2346. worldPos.Add(position,vertexPos);
  2347. long cellR, cellC;
  2348. land->worldToCell(worldPos,cellR,cellC);
  2349. if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
  2350. (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
  2351. {
  2352. continue;
  2353. }
  2354. //----------------------------
  2355. // Building lineOfSightRect...
  2356. if (cellR < minRow)
  2357. minRow = cellR;
  2358. if (cellR > maxRow)
  2359. maxRow = cellR;
  2360. if (cellC < minCol)
  2361. minCol = cellC;
  2362. if (cellC > maxCol)
  2363. maxCol = cellC;
  2364. //----------------
  2365. // Mark the map...
  2366. MapCellPtr curCell = GameMap->getCell(cellR, cellC);
  2367. if (appearType->isForestClump) {
  2368. if (vertexPos.z <= 1.0f)
  2369. curCell->setPassable(passable);
  2370. }
  2371. else {
  2372. if (vertexPos.z >= 1.0f)
  2373. curCell->setPassable(passable);
  2374. }
  2375. }
  2376. }
  2377. }
  2378. }
  2379. if (lineOfSightRect) {
  2380. lineOfSightRect[0] = minRow;
  2381. lineOfSightRect[1] = minCol;
  2382. lineOfSightRect[2] = maxRow;
  2383. lineOfSightRect[3] = maxCol;
  2384. }
  2385. if (tempBldgShape != bldgShape)
  2386. {
  2387. tempBldgShape->ClearAnimation();
  2388. delete tempBldgShape;
  2389. tempBldgShape = NULL;
  2390. }
  2391. return(numCoords/2);
  2392. }
  2393. //-----------------------------------------------------------------------------
  2394. void BldgAppearance::markLOS (bool clearIt)
  2395. {
  2396. //MUST force building to HIGHEST LOD!!! IMpassability data is only valid at this LOD!!
  2397. // Building will reset its LOD on next draw!!
  2398. TG_MultiShapePtr tempBldgShape = bldgShape;
  2399. if (currentLOD)
  2400. {
  2401. tempBldgShape = appearType->bldgShape[0]->CreateFrom();
  2402. if (bdAnimationState != -1)
  2403. appearType->setAnimation(tempBldgShape,bdAnimationState);
  2404. }
  2405. //-------------------------------------------------------------
  2406. // New way. For each vertex in each shape, translate to world
  2407. for (long i=0;i<tempBldgShape->GetNumShapes();i++)
  2408. {
  2409. //Check if the artists meant for this piece to NOT block LOS!!
  2410. // Probably should check for light cones,too!
  2411. if ((strnicmp(tempBldgShape->GetNodeId(i),"LOS_",4) != 0) &&
  2412. (strnicmp(tempBldgShape->GetNodeId(i),"SpotLight_",10) != 0))
  2413. {
  2414. for (long j=0;j<tempBldgShape->GetNumVerticesInShape(i);j++)
  2415. {
  2416. Stuff::Vector3D vertexPos, worldPos;
  2417. vertexPos = tempBldgShape->GetShapeVertexInEditor(i,j,-rotation);
  2418. // vertexPos = tempBldgShape->GetShapeVertexInWorld(i,j,-rotation);
  2419. worldPos.Add(position,vertexPos);
  2420. long cellR, cellC;
  2421. land->worldToCell(worldPos,cellR,cellC);
  2422. if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
  2423. (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
  2424. {
  2425. continue;
  2426. }
  2427. //----------------
  2428. // Mark the map...
  2429. MapCellPtr curCell = GameMap->getCell(cellR, cellC);
  2430. if (!clearIt)
  2431. {
  2432. float currentCellHeight = curCell->getLocalHeight();
  2433. float cellLocalHeight = vertexPos.z * metersPerWorldUnit * 0.25f;
  2434. if (cellLocalHeight > 15.0f)
  2435. cellLocalHeight = 15.0f;
  2436. if (cellLocalHeight > currentCellHeight)
  2437. curCell->setLocalHeight(cellLocalHeight+0.5f);
  2438. }
  2439. else //We want to clear all LOS height INFO. We're about to change shape!!
  2440. {
  2441. curCell->setLocalHeight(0.0f);
  2442. }
  2443. }
  2444. }
  2445. }
  2446. if (tempBldgShape != bldgShape)
  2447. {
  2448. tempBldgShape->ClearAnimation();
  2449. delete tempBldgShape;
  2450. tempBldgShape = NULL;
  2451. }
  2452. }
  2453. //-----------------------------------------------------------------------------
  2454. void BldgAppearance::calcAdjCell (long& row, long& col)
  2455. {
  2456. //MUST force building to HIGHEST LOD!!! IMpassability data is only valid at this LOD!!
  2457. // Building will reset its LOD on next draw!!
  2458. if (currentLOD)
  2459. {
  2460. currentLOD = 0;
  2461. bldgShape->ClearAnimation();
  2462. delete bldgShape;
  2463. bldgShape = NULL;
  2464. bldgShape = appearType->bldgShape[currentLOD]->CreateFrom();
  2465. if (bdAnimationState != -1)
  2466. appearType->setAnimation(bldgShape,bdAnimationState);
  2467. }
  2468. //-------------------------------------------------------------
  2469. // New way. For each vertex in each shape, translate to world
  2470. long numVert = 0;
  2471. for (long i=0;i<bldgShape->GetNumShapes();i++)
  2472. {
  2473. for (long j=0;j<bldgShape->GetNumVerticesInShape(i);j++)
  2474. {
  2475. Stuff::Vector3D vertexPos, worldPos;
  2476. vertexPos = bldgShape->GetShapeVertexInWorld(i,j,-rotation);
  2477. worldPos.Add(position,vertexPos);
  2478. {
  2479. numVert++;
  2480. long cellR, cellC;
  2481. land->worldToCell(worldPos,cellR,cellC);
  2482. //MapCellPtr curCell = GameMap->getCell(cellR, cellC);
  2483. //curCell->setPassable(passable);
  2484. }
  2485. }
  2486. }
  2487. }
  2488. //-----------------------------------------------------------------------------
  2489. // class TreeAppearanceType
  2490. void TreeAppearanceType::init (char * fileName)
  2491. {
  2492. AppearanceType::init(fileName);
  2493. FullPathFileName iniName;
  2494. iniName.init(tglPath,fileName,".ini");
  2495. FitIniFile iniFile;
  2496. long result = iniFile.open(iniName);
  2497. if (result != NO_ERR)
  2498. Fatal(result,"Could not find building appearance INI file");
  2499. result = iniFile.seekBlock("TGLData");
  2500. if (result != NO_ERR)
  2501. Fatal(result,"Could not find block in building appearance INI file");
  2502. result = iniFile.readIdBoolean("ForestClump",isForestClump);
  2503. if (result != NO_ERR)
  2504. isForestClump = false;
  2505. char aseFileName[512];
  2506. result = iniFile.readIdString("FileName",aseFileName,511);
  2507. if (result != NO_ERR)
  2508. {
  2509. //Check for LOD filenames instead
  2510. for (long i=0;i<MAX_LODS;i++)
  2511. {
  2512. char baseName[256];
  2513. char baseLODDist[256];
  2514. sprintf(baseName,"FileName%d",i);
  2515. sprintf(baseLODDist,"Distance%d",i);
  2516. result = iniFile.readIdString(baseName,aseFileName,511);
  2517. if (result == NO_ERR)
  2518. {
  2519. result = iniFile.readIdFloat(baseLODDist,lodDistance[i]);
  2520. if (result != NO_ERR)
  2521. STOP(("LOD %d has no distance value in file %s",i,fileName));
  2522. //----------------------------------------------
  2523. // Base LOD shape. In stand Pose by default.
  2524. treeShape[i] = new TG_TypeMultiShape;
  2525. gosASSERT(treeShape[i] != NULL);
  2526. FullPathFileName treeName;
  2527. treeName.init(tglPath,aseFileName,".ase");
  2528. treeShape[i]->LoadTGMultiShapeFromASE(treeName);
  2529. //---------------------------------------------------------
  2530. // Should only be necessary for trees. Easy to data drive
  2531. treeShape[i]->SetAlphaTest(true);
  2532. treeShape[i]->SetFilter(true);
  2533. }
  2534. else if (!i)
  2535. {
  2536. STOP(("No base LOD for shape %s",fileName));
  2537. }
  2538. }
  2539. }
  2540. else
  2541. {
  2542. //----------------------------------------------
  2543. // Base shape. In stand Pose by default.
  2544. treeShape[0] = new TG_TypeMultiShape;
  2545. gosASSERT(treeShape[0] != NULL);
  2546. FullPathFileName treeName;
  2547. treeName.init(tglPath,aseFileName,".ase");
  2548. treeShape[0]->LoadTGMultiShapeFromASE(treeName);
  2549. //---------------------------------------------------------
  2550. // Should only be necessary for trees. Easy to data drive
  2551. treeShape[0]->SetAlphaTest(true);
  2552. treeShape[0]->SetFilter(true);
  2553. }
  2554. result = iniFile.readIdString("ShadowName",aseFileName,511);
  2555. if (result == NO_ERR)
  2556. {
  2557. //----------------------------------------------
  2558. // Base Shadow shape.
  2559. treeShadowShape = new TG_TypeMultiShape;
  2560. gosASSERT(treeShadowShape != NULL);
  2561. FullPathFileName treeName;
  2562. treeName.init(tglPath,aseFileName,".ase");
  2563. treeShadowShape->LoadTGMultiShapeFromASE(treeName);
  2564. //---------------------------------------------------------
  2565. // Should only be necessary for trees. Easy to data drive
  2566. treeShadowShape->SetAlphaTest(true);
  2567. treeShadowShape->SetFilter(true);
  2568. }
  2569. result = iniFile.seekBlock("TGLDamage");
  2570. if (result == NO_ERR)
  2571. {
  2572. result = iniFile.readIdString("FileName",aseFileName,511);
  2573. if (result != NO_ERR)
  2574. Fatal(result,"Could not find ASE FileName in building appearance INI file");
  2575. FullPathFileName dmgName;
  2576. dmgName.init(tglPath,aseFileName,".ase");
  2577. treeDmgShape = new TG_TypeMultiShape;
  2578. gosASSERT(treeDmgShape != NULL);
  2579. treeDmgShape->LoadTGMultiShapeFromASE(dmgName);
  2580. if (!treeDmgShape->GetNumShapes())
  2581. {
  2582. delete treeDmgShape;
  2583. treeDmgShape = NULL;
  2584. }
  2585. //Shadow for destroyed state.
  2586. result = iniFile.readIdString("ShadowName",aseFileName,511);
  2587. if (result == NO_ERR)
  2588. {
  2589. //----------------------------------------------
  2590. // Base Shadow shape.
  2591. treeDmgShadowShape = new TG_TypeMultiShape;
  2592. gosASSERT(treeDmgShadowShape != NULL);
  2593. FullPathFileName treeName;
  2594. treeName.init(tglPath,aseFileName,".ase");
  2595. treeDmgShadowShape->LoadTGMultiShapeFromASE(treeName);
  2596. if (!treeDmgShadowShape->GetNumShapes())
  2597. {
  2598. delete treeDmgShadowShape;
  2599. treeDmgShadowShape = NULL;
  2600. }
  2601. }
  2602. }
  2603. else
  2604. {
  2605. treeDmgShape = NULL;
  2606. treeDmgShadowShape = NULL;
  2607. }
  2608. //No Animations at present.
  2609. }
  2610. //----------------------------------------------------------------------------
  2611. void TreeAppearanceType::destroy (void)
  2612. {
  2613. AppearanceType::destroy();
  2614. for (long i=0;i<MAX_LODS;i++)
  2615. {
  2616. if (treeShape[i])
  2617. {
  2618. delete treeShape[i];
  2619. treeShape[i] = NULL;
  2620. }
  2621. }
  2622. if (treeDmgShape)
  2623. {
  2624. delete treeDmgShape;
  2625. treeDmgShape = NULL;
  2626. }
  2627. if (treeDmgShadowShape)
  2628. {
  2629. delete treeDmgShadowShape;
  2630. treeDmgShadowShape = NULL;
  2631. }
  2632. if (treeShadowShape)
  2633. {
  2634. delete treeShadowShape;
  2635. treeShadowShape = NULL;
  2636. }
  2637. }
  2638. //-----------------------------------------------------------------------------
  2639. //-----------------------------------------------------------------------------
  2640. // class TreeAppearance
  2641. void TreeAppearance::init (AppearanceTypePtr tree, GameObjectPtr obj)
  2642. {
  2643. Appearance::init(tree,obj);
  2644. appearType = (TreeAppearanceType *)tree;
  2645. shapeMin.x = shapeMin.y = -25;
  2646. shapeMax.x = shapeMax.y = 50;
  2647. paintScheme = -1;
  2648. objectNameId = 30862;
  2649. hazeFactor = 0.0f;
  2650. screenPos.x = screenPos.y = screenPos.z = screenPos.w = -999.0f;
  2651. position.Zero();
  2652. rotation = 0.0;;
  2653. selected = 0;
  2654. teamId = 0;
  2655. homeTeamRelationship = 0;
  2656. actualRotation = rotation;
  2657. OBBRadius = -1.0f;
  2658. currentLOD = 0;
  2659. beenInView = false;
  2660. fogLightSet = false;
  2661. lightRGB = fogRGB = 0xffffffff;
  2662. if (appearType)
  2663. {
  2664. treeShape = appearType->treeShape[0]->CreateFrom();
  2665. //-------------------------------------------------
  2666. // Load the texture and store its handle.
  2667. for (long i=0;i<treeShape->GetNumTextures();i++)
  2668. {
  2669. char txmName[1024];
  2670. treeShape->GetTextureName(i,txmName,256);
  2671. char texturePath[1024];
  2672. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  2673. FullPathFileName textureName;
  2674. textureName.init(texturePath,txmName,"");
  2675. if (fileExists(textureName))
  2676. {
  2677. if (strnicmp(txmName,"a_",2) == 0)
  2678. {
  2679. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  2680. gosASSERT(gosTextureHandle != 0xffffffff);
  2681. treeShape->SetTextureHandle(i,gosTextureHandle);
  2682. treeShape->SetTextureAlpha(i,true);
  2683. }
  2684. else
  2685. {
  2686. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  2687. gosASSERT(gosTextureHandle != 0xffffffff);
  2688. treeShape->SetTextureHandle(i,gosTextureHandle);
  2689. treeShape->SetTextureAlpha(i,false);
  2690. }
  2691. }
  2692. else
  2693. {
  2694. //PAUSE(("Warning: %s texture name not found",textureName));
  2695. treeShape->SetTextureHandle(i,0xffffffff);
  2696. }
  2697. }
  2698. if (appearType->treeShadowShape)
  2699. {
  2700. treeShadowShape = appearType->treeShadowShape->CreateFrom();
  2701. //-------------------------------------------------
  2702. // Load the texture and store its handle.
  2703. for (long i=0;i<treeShadowShape->GetNumTextures();i++)
  2704. {
  2705. char txmName[1024];
  2706. treeShadowShape->GetTextureName(i,txmName,256);
  2707. char texturePath[1024];
  2708. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  2709. FullPathFileName textureName;
  2710. textureName.init(texturePath,txmName,"");
  2711. if (fileExists(textureName))
  2712. {
  2713. if (strnicmp(txmName,"a_",2) == 0)
  2714. {
  2715. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  2716. gosASSERT(gosTextureHandle != 0xffffffff);
  2717. treeShadowShape->SetTextureHandle(i,gosTextureHandle);
  2718. treeShadowShape->SetTextureAlpha(i,true);
  2719. }
  2720. else
  2721. {
  2722. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  2723. gosASSERT(gosTextureHandle != 0xffffffff);
  2724. treeShadowShape->SetTextureHandle(i,gosTextureHandle);
  2725. treeShadowShape->SetTextureAlpha(i,false);
  2726. }
  2727. }
  2728. else
  2729. {
  2730. treeShadowShape->SetTextureHandle(i,0xffffffff);
  2731. }
  2732. }
  2733. }
  2734. else
  2735. {
  2736. treeShadowShape = NULL;
  2737. }
  2738. Stuff::Vector3D boxCoords[8];
  2739. Stuff::Vector3D nodeCenter = treeShape->GetRootNodeCenter();
  2740. boxCoords[0].x = position.x + treeShape->GetMinBox().x + nodeCenter.x;
  2741. boxCoords[0].y = position.y + treeShape->GetMinBox().z + nodeCenter.z;
  2742. boxCoords[0].z = position.z + treeShape->GetMaxBox().y + nodeCenter.y;
  2743. boxCoords[1].x = position.x + treeShape->GetMinBox().x + nodeCenter.x;
  2744. boxCoords[1].y = position.y + treeShape->GetMaxBox().z + nodeCenter.z;
  2745. boxCoords[1].z = position.z + treeShape->GetMaxBox().y + nodeCenter.y;
  2746. boxCoords[2].x = position.x + treeShape->GetMaxBox().x + nodeCenter.x;
  2747. boxCoords[2].y = position.y + treeShape->GetMaxBox().z + nodeCenter.z;
  2748. boxCoords[2].z = position.z + treeShape->GetMaxBox().y + nodeCenter.y;
  2749. boxCoords[3].x = position.x + treeShape->GetMaxBox().x + nodeCenter.x;
  2750. boxCoords[3].y = position.y + treeShape->GetMinBox().z + nodeCenter.z;
  2751. boxCoords[3].z = position.z + treeShape->GetMaxBox().y + nodeCenter.y;
  2752. boxCoords[4].x = position.x + treeShape->GetMinBox().x + nodeCenter.x;
  2753. boxCoords[4].y = position.y + treeShape->GetMinBox().z + nodeCenter.z;
  2754. boxCoords[4].z = position.z + treeShape->GetMinBox().y + nodeCenter.y;
  2755. boxCoords[5].x = position.x + treeShape->GetMaxBox().x + nodeCenter.x;
  2756. boxCoords[5].y = position.y + treeShape->GetMinBox().z + nodeCenter.z;
  2757. boxCoords[5].z = position.z + treeShape->GetMinBox().y + nodeCenter.y;
  2758. boxCoords[6].x = position.x + treeShape->GetMaxBox().x + nodeCenter.x;
  2759. boxCoords[6].y = position.y + treeShape->GetMaxBox().z + nodeCenter.z;
  2760. boxCoords[6].z = position.z + treeShape->GetMinBox().y + nodeCenter.y;
  2761. boxCoords[7].x = position.x + treeShape->GetMinBox().x + nodeCenter.x;
  2762. boxCoords[7].y = position.y + treeShape->GetMaxBox().z + nodeCenter.z;
  2763. boxCoords[7].z = position.z + treeShape->GetMinBox().y + nodeCenter.y;
  2764. float testRadius = 0.0;
  2765. for (i=0;i<8;i++)
  2766. {
  2767. testRadius = boxCoords[i].GetLength();
  2768. if (OBBRadius < testRadius)
  2769. OBBRadius = testRadius;
  2770. }
  2771. appearType->boundsUpperLeftX = (-OBBRadius * 2.0);
  2772. appearType->boundsUpperLeftY = (-OBBRadius * 2.0);
  2773. appearType->boundsLowerRightX = (OBBRadius * 2.0);
  2774. appearType->boundsLowerRightY = (OBBRadius);
  2775. if (!appearType->getDesignerTypeBounds())
  2776. {
  2777. appearType->typeUpperLeft = treeShape->GetMinBox();
  2778. appearType->typeLowerRight = treeShape->GetMaxBox();
  2779. }
  2780. }
  2781. pitch = yaw = 0.0f;
  2782. }
  2783. //-----------------------------------------------------------------------------
  2784. void TreeAppearance::setObjStatus (long oStatus)
  2785. {
  2786. if (status != oStatus)
  2787. {
  2788. if ((oStatus == OBJECT_STATUS_DESTROYED) || (oStatus == OBJECT_STATUS_DISABLED))
  2789. {
  2790. if (appearType->treeDmgShape)
  2791. {
  2792. if (treeShape)
  2793. {
  2794. treeShape->ClearAnimation();
  2795. delete treeShape;
  2796. treeShape = NULL;
  2797. }
  2798. treeShape = appearType->treeDmgShape->CreateFrom();
  2799. beenInView = false;
  2800. }
  2801. if (appearType->treeDmgShadowShape)
  2802. {
  2803. if (treeShadowShape)
  2804. {
  2805. treeShadowShape->ClearAnimation();
  2806. delete treeShadowShape;
  2807. treeShadowShape = NULL;
  2808. }
  2809. treeShadowShape = appearType->treeDmgShadowShape->CreateFrom();
  2810. beenInView = false;
  2811. }
  2812. }
  2813. if (oStatus == OBJECT_STATUS_NORMAL)
  2814. {
  2815. if (appearType->treeShape)
  2816. {
  2817. if (treeShape)
  2818. {
  2819. treeShape->ClearAnimation();
  2820. delete treeShape;
  2821. treeShape = NULL;
  2822. }
  2823. treeShape = appearType->treeShape[0]->CreateFrom();
  2824. beenInView = false;
  2825. }
  2826. if (appearType->treeShadowShape)
  2827. {
  2828. if (treeShadowShape)
  2829. {
  2830. treeShadowShape->ClearAnimation();
  2831. delete treeShadowShape;
  2832. treeShadowShape = NULL;
  2833. }
  2834. treeShadowShape = appearType->treeShadowShape->CreateFrom();
  2835. beenInView = false;
  2836. }
  2837. }
  2838. //-------------------------------------------------
  2839. // Load the texture and store its handle.
  2840. if (treeShape)
  2841. {
  2842. for (long i=0;i<treeShape->GetNumTextures();i++)
  2843. {
  2844. char txmName[1024];
  2845. treeShape->GetTextureName(i,txmName,256);
  2846. char texturePath[1024];
  2847. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  2848. FullPathFileName textureName;
  2849. textureName.init(texturePath,txmName,"");
  2850. if (fileExists(textureName))
  2851. {
  2852. if (strnicmp(txmName,"a_",2) == 0)
  2853. {
  2854. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  2855. gosASSERT(gosTextureHandle != 0xffffffff);
  2856. treeShape->SetTextureHandle(i,gosTextureHandle);
  2857. treeShape->SetTextureAlpha(i,true);
  2858. }
  2859. else
  2860. {
  2861. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  2862. gosASSERT(gosTextureHandle != 0xffffffff);
  2863. treeShape->SetTextureHandle(i,gosTextureHandle);
  2864. treeShape->SetTextureAlpha(i,false);
  2865. }
  2866. }
  2867. else
  2868. {
  2869. //PAUSE(("Warning: %s texture name not found",textureName));
  2870. treeShape->SetTextureHandle(i,0xffffffff);
  2871. }
  2872. }
  2873. }
  2874. if (treeShadowShape)
  2875. {
  2876. //-------------------------------------------------
  2877. // Load the texture and store its handle.
  2878. for (long i=0;i<treeShadowShape->GetNumTextures();i++)
  2879. {
  2880. char txmName[1024];
  2881. treeShadowShape->GetTextureName(i,txmName,256);
  2882. char texturePath[1024];
  2883. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  2884. FullPathFileName textureName;
  2885. textureName.init(texturePath,txmName,"");
  2886. if (fileExists(textureName))
  2887. {
  2888. if (strnicmp(txmName,"a_",2) == 0)
  2889. {
  2890. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  2891. gosASSERT(gosTextureHandle != 0xffffffff);
  2892. treeShadowShape->SetTextureHandle(i,gosTextureHandle);
  2893. treeShadowShape->SetTextureAlpha(i,true);
  2894. }
  2895. else
  2896. {
  2897. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  2898. gosASSERT(gosTextureHandle != 0xffffffff);
  2899. treeShadowShape->SetTextureHandle(i,gosTextureHandle);
  2900. treeShadowShape->SetTextureAlpha(i,false);
  2901. }
  2902. }
  2903. else
  2904. {
  2905. //PAUSE(("Warning: %s texture name not found",textureName));
  2906. treeShadowShape->SetTextureHandle(i,0xffffffff);
  2907. }
  2908. }
  2909. }
  2910. }
  2911. status = oStatus;
  2912. }
  2913. //-----------------------------------------------------------------------------
  2914. void TreeAppearance::setObjectParameters (Stuff::Vector3D &pos, float Rot, long sel, long team, long homeRelations)
  2915. {
  2916. rotation = Rot;
  2917. position = pos;
  2918. selected = sel;
  2919. actualRotation = Rot;
  2920. teamId = team;
  2921. homeTeamRelationship = homeRelations;
  2922. }
  2923. //-----------------------------------------------------------------------------
  2924. void TreeAppearance::setMoverParameters (float pitchAngle, float lArmRot, float rArmRot, bool isAirborne)
  2925. {
  2926. pitch = pitchAngle;
  2927. }
  2928. //-----------------------------------------------------------------------------
  2929. bool TreeAppearance::isMouseOver (float px, float py)
  2930. {
  2931. if (inView)
  2932. {
  2933. if ((px <= lowerRight.x) && (py <= lowerRight.y) &&
  2934. (px >= upperLeft.x) &&
  2935. (py >= upperLeft.y))
  2936. {
  2937. return inView;
  2938. }
  2939. else
  2940. {
  2941. return FALSE;
  2942. }
  2943. }
  2944. return(inView);
  2945. }
  2946. //-----------------------------------------------------------------------------
  2947. bool TreeAppearance::recalcBounds (void)
  2948. {
  2949. Stuff::Vector4D tempPos;
  2950. inView = false;
  2951. float distanceToEye = 0.0f;
  2952. if (eye)
  2953. {
  2954. //-------------------------------------------------------------------
  2955. //NEW METHOD from the WAY BACK Days
  2956. inView = true;
  2957. if (eye->usePerspective)
  2958. {
  2959. Stuff::Vector3D cameraPos;
  2960. cameraPos.x = -eye->getCameraOrigin().x;
  2961. cameraPos.y = eye->getCameraOrigin().z;
  2962. cameraPos.z = eye->getCameraOrigin().y;
  2963. float vClipConstant = eye->verticalSphereClipConstant;
  2964. float hClipConstant = eye->horizontalSphereClipConstant;
  2965. Stuff::Vector3D objectCenter;
  2966. objectCenter.Subtract(position,cameraPos);
  2967. Camera::cameraFrame.trans_to_frame(objectCenter);
  2968. distanceToEye = objectCenter.GetApproximateLength();
  2969. float clip_distance = fabs(1.0f / objectCenter.y);
  2970. //Is vertex on Screen OR close enough to screen that its triangle MAY be visible?
  2971. // WE have removed the atans here by simply taking the tan of the angle we want above.
  2972. float object_angle = fabs(objectCenter.z) * clip_distance;
  2973. float extent_angle = treeShape->GetExtentRadius() / distanceToEye;
  2974. if (object_angle > (vClipConstant + extent_angle))
  2975. {
  2976. //In theory, we would return here. Object is NOT on screen.
  2977. inView = false;
  2978. }
  2979. else
  2980. {
  2981. object_angle = fabs(objectCenter.x) * clip_distance;
  2982. if (object_angle > (hClipConstant + extent_angle))
  2983. {
  2984. //In theory, we would return here. Object is NOT on screen.
  2985. inView = false;
  2986. }
  2987. }
  2988. }
  2989. //Can we be seen at all?
  2990. // If yes, check if we are behind fog plane.
  2991. if (inView)
  2992. {
  2993. //ALWAYS need to do this or select is YAYA
  2994. // But now inView is correct.
  2995. eye->projectZ(position,screenPos);
  2996. if (eye->usePerspective)
  2997. {
  2998. if (distanceToEye > Camera::MaxClipDistance)
  2999. {
  3000. hazeFactor = 1.0f;
  3001. inView = false;
  3002. }
  3003. else if (distanceToEye > Camera::MinHazeDistance)
  3004. {
  3005. Camera::HazeFactor = (distanceToEye - Camera::MinHazeDistance) * Camera::DistanceFactor;
  3006. inView = true;
  3007. }
  3008. else
  3009. {
  3010. Camera::HazeFactor = 0.0f;
  3011. inView = true;
  3012. }
  3013. }
  3014. else
  3015. {
  3016. Camera::HazeFactor = 0.0f;
  3017. inView = true;
  3018. }
  3019. }
  3020. //If we were not behind fog plane, do a bunch O math we need later!!
  3021. if (inView)
  3022. {
  3023. //We are on screen. Figure out selection box.
  3024. Stuff::Vector3D boxCoords[8];
  3025. Stuff::Vector4D bcsp[8];
  3026. Stuff::Vector3D minBox;
  3027. minBox.x = -appearType->typeUpperLeft.x;
  3028. minBox.y = appearType->typeUpperLeft.z;
  3029. minBox.z = appearType->typeUpperLeft.y;
  3030. Stuff::Vector3D maxBox;
  3031. maxBox.x = -appearType->typeLowerRight.x;
  3032. maxBox.y = appearType->typeLowerRight.z;
  3033. maxBox.z = appearType->typeLowerRight.y;
  3034. if (rotation != 0.0f)
  3035. Rotate(minBox,-rotation);
  3036. if (rotation != 0.0f)
  3037. Rotate(maxBox,-rotation);
  3038. boxCoords[0].x = position.x + minBox.x;
  3039. boxCoords[0].y = position.y + minBox.y;
  3040. boxCoords[0].z = position.z + minBox.z;
  3041. boxCoords[1].x = position.x + minBox.x;
  3042. boxCoords[1].y = position.y + maxBox.y;
  3043. boxCoords[1].z = position.z + minBox.z;
  3044. boxCoords[2].x = position.x + maxBox.x;
  3045. boxCoords[2].y = position.y + minBox.y;
  3046. boxCoords[2].z = position.z + minBox.z;
  3047. boxCoords[3].x = position.x + maxBox.x;
  3048. boxCoords[3].y = position.y + maxBox.y;
  3049. boxCoords[3].z = position.z + minBox.z;
  3050. boxCoords[4].x = position.x + maxBox.x;
  3051. boxCoords[4].y = position.y + maxBox.y;
  3052. boxCoords[4].z = position.z + maxBox.z;
  3053. boxCoords[5].x = position.x + maxBox.x;
  3054. boxCoords[5].y = position.y + minBox.y;
  3055. boxCoords[5].z = position.z + maxBox.z;
  3056. boxCoords[6].x = position.x + minBox.x;
  3057. boxCoords[6].y = position.y + maxBox.y;
  3058. boxCoords[6].z = position.z + maxBox.z;
  3059. boxCoords[7].x = position.x + minBox.x;
  3060. boxCoords[7].y = position.y + minBox.y;
  3061. boxCoords[7].z = position.z + maxBox.z;
  3062. float maxX = 0.0f, maxY = 0.0f;
  3063. float minX = 0.0f, minY = 0.0f;
  3064. for (long i=0;i<8;i++)
  3065. {
  3066. eye->projectZ(boxCoords[i],bcsp[i]);
  3067. if (!i)
  3068. {
  3069. maxX = minX = bcsp[i].x;
  3070. maxY = minY = bcsp[i].y;
  3071. }
  3072. if (i)
  3073. {
  3074. if (bcsp[i].x > maxX)
  3075. maxX = bcsp[i].x;
  3076. if (bcsp[i].x < minX)
  3077. minX = bcsp[i].x;
  3078. if (bcsp[i].y > maxY)
  3079. maxY = bcsp[i].y;
  3080. if (bcsp[i].y < minY)
  3081. minY = bcsp[i].y;
  3082. }
  3083. }
  3084. upperLeft.x = minX;
  3085. upperLeft.y = minY;
  3086. lowerRight.x = maxX;
  3087. lowerRight.y = maxY;
  3088. if ((lowerRight.x >= 0) && (lowerRight.y >= 0) &&
  3089. (upperLeft.x <= eye->getScreenResX()) &&
  3090. (upperLeft.y <= eye->getScreenResY()))
  3091. {
  3092. inView = true;
  3093. if ((status != OBJECT_STATUS_DESTROYED) && (status != OBJECT_STATUS_DISABLED))
  3094. {
  3095. //-------------------------------------------------------------------------------
  3096. //Set LOD of Model here because we have the distance and we KNOW we can see it!
  3097. bool baseLOD = true;
  3098. DWORD selectLOD = 0;
  3099. if (useHighObjectDetail)
  3100. {
  3101. for (long i=1;i<MAX_LODS;i++)
  3102. {
  3103. if (appearType->treeShape[i] && (distanceToEye > appearType->lodDistance[i]))
  3104. {
  3105. baseLOD = false;
  3106. selectLOD = i;
  3107. }
  3108. }
  3109. }
  3110. else //We always want to use the lowest LOD!!
  3111. {
  3112. if (appearType->treeShape[1])
  3113. {
  3114. baseLOD = false;
  3115. selectLOD = 1;
  3116. }
  3117. }
  3118. // we are at this LOD level.
  3119. if (selectLOD != currentLOD)
  3120. {
  3121. currentLOD = selectLOD;
  3122. treeShape->ClearAnimation();
  3123. delete treeShape;
  3124. treeShape = NULL;
  3125. treeShape = appearType->treeShape[currentLOD]->CreateFrom();
  3126. //-------------------------------------------------
  3127. // Load the texture and store its handle.
  3128. for (long j=0;j<treeShape->GetNumTextures();j++)
  3129. {
  3130. char txmName[1024];
  3131. treeShape->GetTextureName(j,txmName,256);
  3132. char texturePath[1024];
  3133. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  3134. FullPathFileName textureName;
  3135. textureName.init(texturePath,txmName,"");
  3136. if (fileExists(textureName))
  3137. {
  3138. if (strnicmp(txmName,"a_",2) == 0)
  3139. {
  3140. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  3141. gosASSERT(gosTextureHandle != 0xffffffff);
  3142. treeShape->SetTextureHandle(j,gosTextureHandle);
  3143. treeShape->SetTextureAlpha(j,true);
  3144. }
  3145. else
  3146. {
  3147. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  3148. gosASSERT(gosTextureHandle != 0xffffffff);
  3149. treeShape->SetTextureHandle(j,gosTextureHandle);
  3150. treeShape->SetTextureAlpha(j,false);
  3151. }
  3152. }
  3153. else
  3154. {
  3155. //PAUSE(("Warning: %s texture name not found",textureName));
  3156. treeShape->SetTextureHandle(j,0xffffffff);
  3157. }
  3158. }
  3159. }
  3160. //ONLY change if we need
  3161. if (currentLOD && baseLOD)
  3162. {
  3163. // we are at the Base LOD level.
  3164. currentLOD = 0;
  3165. treeShape->ClearAnimation();
  3166. delete treeShape;
  3167. treeShape = NULL;
  3168. treeShape = appearType->treeShape[currentLOD]->CreateFrom();
  3169. //-------------------------------------------------
  3170. // Load the texture and store its handle.
  3171. for (long i=0;i<treeShape->GetNumTextures();i++)
  3172. {
  3173. char txmName[1024];
  3174. treeShape->GetTextureName(i,txmName,256);
  3175. char texturePath[1024];
  3176. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  3177. FullPathFileName textureName;
  3178. textureName.init(texturePath,txmName,"");
  3179. if (fileExists(textureName))
  3180. {
  3181. if (strnicmp(txmName,"a_",2) == 0)
  3182. {
  3183. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  3184. gosASSERT(gosTextureHandle != 0xffffffff);
  3185. treeShape->SetTextureHandle(i,gosTextureHandle);
  3186. treeShape->SetTextureAlpha(i,true);
  3187. }
  3188. else
  3189. {
  3190. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  3191. gosASSERT(gosTextureHandle != 0xffffffff);
  3192. treeShape->SetTextureHandle(i,gosTextureHandle);
  3193. treeShape->SetTextureAlpha(i,false);
  3194. }
  3195. }
  3196. else
  3197. {
  3198. //PAUSE(("Warning: %s texture name not found",textureName));
  3199. treeShape->SetTextureHandle(i,0xffffffff);
  3200. }
  3201. }
  3202. }
  3203. }
  3204. }
  3205. else
  3206. {
  3207. inView = false; //Did alot of extra work checking this, but WHY draw and insult to injury?
  3208. }
  3209. }
  3210. }
  3211. return(inView);
  3212. }
  3213. //-----------------------------------------------------------------------------
  3214. long TreeAppearance::render (long depthFixup)
  3215. {
  3216. if (inView)
  3217. {
  3218. long color = SD_BLUE;
  3219. //unsigned long highLight = 0x007f7f7f;
  3220. if ((teamId > -1) && (teamId < 8)) {
  3221. //static unsigned long highLightTable[3] = {0x00007f00, 0x0000007f, 0x007f0000};
  3222. static long colorTable[3] = {SB_GREEN | 0xff000000, SB_BLUE | 0xff000000, SB_RED | 0xff000000};
  3223. color = colorTable[homeTeamRelationship];
  3224. //highLight = highLightTable[homeTeamRelationship];
  3225. }
  3226. //---------------------------------------------
  3227. // Call Multi-shape render stuff here.
  3228. treeShape->Render();
  3229. if (selected & DRAW_BARS)
  3230. {
  3231. drawBars();
  3232. }
  3233. if ( selected & DRAW_BRACKETS )
  3234. {
  3235. drawSelectBrackets(color);
  3236. }
  3237. if ( selected & DRAW_TEXT )
  3238. {
  3239. if (objectNameId != -1)
  3240. {
  3241. char tmpString[255];
  3242. cLoadString(objectNameId, tmpString, 254);
  3243. drawTextHelp(tmpString, color);
  3244. }
  3245. }
  3246. // I don't want my selection reset each time I draw HKG
  3247. // selected = FALSE;
  3248. //---------------------------------------------------------
  3249. // Render the Bounding Box to see if it is OK.
  3250. #ifdef DRAW_BOX
  3251. Stuff::Vector3D nodeCenter = treeShape->GetRootNodeCenter();
  3252. boxCoords[0].x = position.x + treeShape->minBox.x + nodeCenter.x;
  3253. boxCoords[0].y = position.y + treeShape->minBox.z + nodeCenter.z;
  3254. boxCoords[0].z = position.z + treeShape->maxBox.y + nodeCenter.y;
  3255. boxCoords[1].x = position.x + treeShape->minBox.x + nodeCenter.x;
  3256. boxCoords[1].y = position.y + treeShape->maxBox.z + nodeCenter.z;
  3257. boxCoords[1].z = position.z + treeShape->maxBox.y + nodeCenter.y;
  3258. boxCoords[2].x = position.x + treeShape->maxBox.x + nodeCenter.x;
  3259. boxCoords[2].y = position.y + treeShape->maxBox.z + nodeCenter.z;
  3260. boxCoords[2].z = position.z + treeShape->maxBox.y + nodeCenter.y;
  3261. boxCoords[3].x = position.x + treeShape->maxBox.x + nodeCenter.x;
  3262. boxCoords[3].y = position.y + treeShape->minBox.z + nodeCenter.z;
  3263. boxCoords[3].z = position.z + treeShape->maxBox.y + nodeCenter.y;
  3264. boxCoords[4].x = position.x + treeShape->minBox.x + nodeCenter.x;
  3265. boxCoords[4].y = position.y + treeShape->minBox.z + nodeCenter.z;
  3266. boxCoords[4].z = position.z + treeShape->minBox.y + nodeCenter.y;
  3267. boxCoords[5].x = position.x + treeShape->maxBox.x + nodeCenter.x;
  3268. boxCoords[5].y = position.y + treeShape->minBox.z + nodeCenter.z;
  3269. boxCoords[5].z = position.z + treeShape->minBox.y + nodeCenter.y;
  3270. boxCoords[6].x = position.x + treeShape->maxBox.x + nodeCenter.x;
  3271. boxCoords[6].y = position.y + treeShape->maxBox.z + nodeCenter.z;
  3272. boxCoords[6].z = position.z + treeShape->minBox.y + nodeCenter.y;
  3273. boxCoords[7].x = position.x + treeShape->minBox.x + nodeCenter.x;
  3274. boxCoords[7].y = position.y + treeShape->maxBox.z + nodeCenter.z;
  3275. boxCoords[7].z = position.z + treeShape->minBox.y + nodeCenter.y;
  3276. Stuff::Vector4D screenPos[8];
  3277. for (long i=0;i<8;i++)
  3278. {
  3279. eye->projectZ(boxCoords[i],screenPos[i]);
  3280. }
  3281. {
  3282. LineElement newElement(screenPos[0],screenPos[1],XP_WHITE,NULL,-1);
  3283. newElement.draw();
  3284. }
  3285. {
  3286. LineElement newElement(screenPos[0],screenPos[4],XP_WHITE,NULL,-1);
  3287. newElement.draw();
  3288. }
  3289. {
  3290. LineElement newElement(screenPos[0],screenPos[3],XP_WHITE,NULL,-1);
  3291. newElement.draw();
  3292. }
  3293. {
  3294. LineElement newElement(screenPos[5],screenPos[4],XP_WHITE,NULL,-1);
  3295. newElement.draw();
  3296. }
  3297. {
  3298. LineElement newElement(screenPos[5],screenPos[6],XP_WHITE,NULL,-1);
  3299. newElement.draw();
  3300. }
  3301. {
  3302. LineElement newElement(screenPos[5],screenPos[3],XP_WHITE,NULL,-1);
  3303. newElement.draw();
  3304. }
  3305. {
  3306. LineElement newElement(screenPos[2],screenPos[3],XP_WHITE,NULL,-1);
  3307. newElement.draw();
  3308. }
  3309. {
  3310. LineElement newElement(screenPos[2],screenPos[6],XP_WHITE,NULL,-1);
  3311. newElement.draw();
  3312. }
  3313. {
  3314. LineElement newElement(screenPos[2],screenPos[1],XP_WHITE,NULL,-1);
  3315. newElement.draw();
  3316. }
  3317. {
  3318. LineElement newElement(screenPos[7],screenPos[1],XP_WHITE,NULL,-1);
  3319. newElement.draw();
  3320. }
  3321. {
  3322. LineElement newElement(screenPos[7],screenPos[6],XP_WHITE,NULL,-1);
  3323. newElement.draw();
  3324. }
  3325. {
  3326. LineElement newElement(screenPos[7],screenPos[4],XP_WHITE,NULL,-1);
  3327. newElement.draw();
  3328. }
  3329. #endif
  3330. }
  3331. return NO_ERR;
  3332. }
  3333. //-----------------------------------------------------------------------------
  3334. long TreeAppearance::renderShadows (void)
  3335. {
  3336. if (inView && visible)
  3337. {
  3338. //---------------------------------------------
  3339. // Call Multi-shape render stuff here.
  3340. if (treeShadowShape)
  3341. treeShadowShape->RenderShadows();
  3342. else
  3343. treeShape->RenderShadows();
  3344. }
  3345. return NO_ERR;
  3346. }
  3347. //-----------------------------------------------------------------------------
  3348. long TreeAppearance::update (bool animate)
  3349. {
  3350. if (rotation > 180)
  3351. rotation -= 360;
  3352. if (rotation < -180)
  3353. rotation += 360;
  3354. //-------------------------------------------
  3355. // Does math necessary to draw Tree
  3356. Stuff::UnitQuaternion rot;
  3357. float yawAngle = (rotation * DEGREES_TO_RADS) + (yaw * DEGREES_TO_RADS);
  3358. float pitchAngle = (pitch * DEGREES_TO_RADS);
  3359. rot = Stuff::EulerAngles(pitchAngle, yawAngle, 0.0f);
  3360. Stuff::Point3D xlatPosition;
  3361. xlatPosition.x = -position.x;
  3362. xlatPosition.y = position.z;
  3363. xlatPosition.z = position.y;
  3364. if (!fogLightSet)
  3365. {
  3366. unsigned char lightr,lightg,lightb;
  3367. float lightIntensity = 1.0f;
  3368. if (land)
  3369. lightIntensity = land->getTerrainLight(position);
  3370. lightr = eye->getLightRed(lightIntensity);
  3371. lightg = eye->getLightGreen(lightIntensity);
  3372. lightb = eye->getLightBlue(lightIntensity);
  3373. lightRGB = (lightr<<16) + (lightg<<8) + lightb;
  3374. fogRGB = 0xff<<24;
  3375. float fogStart = eye->fogStart;
  3376. float fogFull = eye->fogFull;
  3377. if (xlatPosition.y < fogStart)
  3378. {
  3379. float fogFactor = fogStart - xlatPosition.y;
  3380. if (fogFactor < 0.0)
  3381. fogRGB = 0xff<<24;
  3382. else
  3383. {
  3384. fogFactor /= (fogStart - fogFull);
  3385. if (fogFactor <= 1.0)
  3386. {
  3387. fogFactor *= fogFactor;
  3388. fogFactor = 1.0 - fogFactor;
  3389. fogFactor *= 256.0;
  3390. }
  3391. else
  3392. {
  3393. fogFactor = 256.0;
  3394. }
  3395. unsigned char fogResult = float2long(fogFactor);
  3396. fogRGB = fogResult << 24;
  3397. }
  3398. }
  3399. else
  3400. {
  3401. fogRGB = 0xff<<24;
  3402. }
  3403. fogLightSet = true;
  3404. }
  3405. if (useFog)
  3406. treeShape->SetFogRGB(fogRGB);
  3407. else
  3408. treeShape->SetFogRGB(0xffffffff);
  3409. DWORD oldRGB = eye->getLightColor(1);
  3410. eye->setLightColor(1,lightRGB);
  3411. eye->setLightIntensity(1,1.0);
  3412. if (forceLightsOut)
  3413. treeShape->SetLightsOut(true);
  3414. if (inView)
  3415. {
  3416. bool checkShadows = ((!beenInView) || (eye->forceShadowRecalc));
  3417. if (treeShadowShape)
  3418. treeShape->SetUseShadow(false);
  3419. else
  3420. treeShape->SetRecalcShadows(checkShadows);
  3421. TG_LightPtr light = eye->getWorldLight(0);
  3422. light->active = false;
  3423. treeShape->SetLightList(eye->getWorldLights(),eye->getNumLights());
  3424. treeShape->TransformMultiShape (&xlatPosition,&rot);
  3425. light->active = true;
  3426. if (treeShadowShape && useShadows)
  3427. {
  3428. treeShadowShape->SetRecalcShadows(checkShadows);
  3429. treeShadowShape->SetLightList(eye->getWorldLights(),eye->getNumLights());
  3430. treeShadowShape->TransformMultiShape (&xlatPosition,&rot);
  3431. }
  3432. if ((turn > 3) && useShadows)
  3433. beenInView = true;
  3434. }
  3435. //Set Ambient back to normal color.
  3436. eye->setLightColor(1,oldRGB);
  3437. return TRUE;
  3438. }
  3439. //-----------------------------------------------------------------------------
  3440. void TreeAppearance::markTerrain (_ScenarioMapCellInfo* pInfo, int type, int counter)
  3441. {
  3442. //MUST force tree to HIGHEST LOD!!! Impassability data is only valid at this LOD!!
  3443. // Tree will reset its LOD on next draw!!
  3444. if (currentLOD)
  3445. {
  3446. currentLOD = 0;
  3447. treeShape->ClearAnimation();
  3448. delete treeShape;
  3449. treeShape = NULL;
  3450. treeShape = appearType->treeShape[currentLOD]->CreateFrom();
  3451. }
  3452. //-------------------------------------------------------------
  3453. // New way. For each vertex in each shape, translate to world
  3454. for (long i=0;i<treeShape->GetNumShapes();i++)
  3455. {
  3456. //Check if the artists meant for this piece to NOT block passability!!
  3457. if (strnicmp(treeShape->GetNodeId(i),"_PAB",4) != 0)
  3458. {
  3459. for (long j=0;j<treeShape->GetNumVerticesInShape(i);j++)
  3460. {
  3461. Stuff::Vector3D vertexPos, worldPos;
  3462. vertexPos = treeShape->GetShapeVertexInEditor(i,j,-rotation);
  3463. worldPos.Add(position,vertexPos);
  3464. long cellR, cellC;
  3465. land->worldToCell(worldPos,cellR,cellC);
  3466. if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
  3467. (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
  3468. {
  3469. continue;
  3470. }
  3471. _ScenarioMapCellInfo*pTmp = &(pInfo[cellR * Terrain::realVerticesMapSide * MAPCELL_DIM + cellC]);
  3472. if (vertexPos.z >= 1.0f)
  3473. {
  3474. pTmp->forest = true;
  3475. float cellLocalHeight = vertexPos.z * metersPerWorldUnit * 0.25f;
  3476. if (cellLocalHeight > 15.0f)
  3477. cellLocalHeight = 15.0f;
  3478. if (pTmp->lineOfSight < cellLocalHeight)
  3479. pTmp->lineOfSight = cellLocalHeight+0.5f;
  3480. }
  3481. }
  3482. }
  3483. }
  3484. }
  3485. //-----------------------------------------------------------------------------
  3486. void TreeAppearance::markLOS (bool clearIt)
  3487. {
  3488. //MUST force building to HIGHEST LOD!!! IMpassability data is only valid at this LOD!!
  3489. // Building will reset its LOD on next draw!!
  3490. if (currentLOD)
  3491. {
  3492. currentLOD = 0;
  3493. treeShape->ClearAnimation();
  3494. delete treeShape;
  3495. treeShape = NULL;
  3496. treeShape = appearType->treeShape[currentLOD]->CreateFrom();
  3497. }
  3498. //-------------------------------------------------------------
  3499. // New way. For each vertex in each shape, translate to world
  3500. for (long i=0;i<treeShape->GetNumShapes();i++)
  3501. {
  3502. //Check if the artists meant for this piece to NOT block LOS!!
  3503. // Probably should check for light cones,too!
  3504. if ((strnicmp(treeShape->GetNodeId(i),"LOS_",4) != 0) &&
  3505. (strnicmp(treeShape->GetNodeId(i),"SpotLight_",10) != 0))
  3506. {
  3507. for (long j=0;j<treeShape->GetNumVerticesInShape(i);j++)
  3508. {
  3509. Stuff::Vector3D vertexPos, worldPos;
  3510. vertexPos = treeShape->GetShapeVertexInEditor(i,j,-rotation);
  3511. // vertexPos = treeShape->GetShapeVertexInWorld(i,j,-rotation);
  3512. worldPos.Add(position,vertexPos);
  3513. long cellR, cellC;
  3514. land->worldToCell(worldPos,cellR,cellC);
  3515. if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
  3516. (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
  3517. {
  3518. continue;
  3519. }
  3520. //----------------
  3521. // Mark the map...
  3522. MapCellPtr curCell = GameMap->getCell(cellR, cellC);
  3523. float currentCellHeight = curCell->getLocalHeight();
  3524. float cellLocalHeight = vertexPos.z * metersPerWorldUnit * 0.25f;
  3525. if (cellLocalHeight > 15.0f)
  3526. cellLocalHeight = 15.0f;
  3527. if (!clearIt)
  3528. {
  3529. if (cellLocalHeight > currentCellHeight)
  3530. curCell->setLocalHeight(cellLocalHeight+0.5f);
  3531. }
  3532. else //We want to clear all LOS height INFO. We're about to change shape!!
  3533. {
  3534. curCell->setLocalHeight(0.0f);
  3535. }
  3536. }
  3537. }
  3538. }
  3539. }
  3540. //-----------------------------------------------------------------------------
  3541. void TreeAppearance::destroy (void)
  3542. {
  3543. if ( treeShape )
  3544. {
  3545. delete treeShape;
  3546. treeShape = NULL;
  3547. }
  3548. appearanceTypeList->removeAppearance(appearType);
  3549. }
  3550. //*****************************************************************************