1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276 |
- //---------------------------------------------------------------------------
- //
- // bdactor.cpp - This file contains the code for the building and tree appearance classes
- //
- // MechCommander 2
- //
- //---------------------------------------------------------------------------//
- // Copyright (C) Microsoft Corporation. All rights reserved. //
- //===========================================================================//
- #ifndef BDACTOR_H
- #include "bdactor.h"
- #endif
- #ifndef CAMERA_H
- #include "camera.h"
- #endif
- #ifndef DBASEGUI_H
- #include "dbasegui.h"
- #endif
- #ifndef CIDENT_H
- #include "cident.h"
- #endif
- #ifndef PATHS_H
- #include "paths.h"
- #endif
- #ifndef OBJSTATUS_H
- #include "objstatus.h"
- #endif
- #ifndef UTILITIES_H
- #include "utilities.h"
- #endif
- #ifndef INIFILE_H
- #include "inifile.h"
- #endif
- #ifndef ERR_H
- #include "err.h"
- #endif
- #ifndef TXMMGR_H
- #include "txmmgr.h"
- #endif
- #ifndef TIMING_H
- #include "timing.h"
- #endif
- #ifndef CELINE_H
- #include "celine.h"
- #endif
- #ifndef MOVE_H
- #include "move.h"
- #endif
- #include "../Code/unitdesg.h" /* just for definition of MIN_TERRAIN_PART_ID and MAX_MAP_CELL_WIDTH */
- //******************************************************************************************
- extern float worldUnitsPerMeter;
- extern bool drawTerrainGrid;
- extern bool useFog;
- extern long mechRGBLookup[];
- extern long mechRGBLookup2[];
- extern long ObjectTextureSize;
- extern bool reloadBounds;
- extern float metersPerWorldUnit;
- extern bool useShadows;
- extern MidLevelRenderer::MLRClipper * theClipper;
- extern bool useNonWeaponEffects;
- extern bool useHighObjectDetail;
- extern bool MLRVertexLimitReached;
- #define SPINRATE 90.0f
- #define BASE_NODE_RECYCLE_TIME 0.25f
- #define MAX_WEAPON_NODES 4
- //-----------------------------------------------------------------------------
- // class BldgAppearanceType
- void BldgAppearanceType::init (char * fileName)
- {
- AppearanceType::init(fileName);
- //----------------------------------------------
- FullPathFileName iniName;
- iniName.init(tglPath,fileName,".ini");
- FitIniFile iniFile;
- long result = iniFile.open(iniName);
- if (result != NO_ERR)
- STOP(("Could not find building appearance INI file %s",iniName));
- result = iniFile.seekBlock("TGLData");
- if (result != NO_ERR)
- Fatal(result,"Could not find block in building appearance INI file");
- result = iniFile.readIdBoolean("SpinMe",spinMe);
- if (result != NO_ERR)
- spinMe = false;
-
- float nFrameRate = 0.0f;
- result = iniFile.readIdFloat("FrameRate",nFrameRate);
- if (result != NO_ERR)
- nFrameRate = 0.0f;
- result = iniFile.readIdBoolean("ForestClump",isForestClump);
- if (result != NO_ERR)
- isForestClump = false;
-
- DWORD hotPinkRGB, hotGreenRGB, hotYellowRGB;
- result = iniFile.readIdULong("HotPinkRGB",hotPinkRGB);
- if (result != NO_ERR)
- hotPinkRGB = 0xffff00ff;
-
- result = iniFile.readIdULong("HotGreenRGB",hotGreenRGB);
- if (result != NO_ERR)
- hotGreenRGB = 0xff00ff00;
-
- result = iniFile.readIdULong("HotYellowRGB",hotYellowRGB);
- if (result != NO_ERR)
- hotYellowRGB = 0xffffff00;
- result = iniFile.readIdULong("TerrainLightRGB",terrainLightRGB);
- if (result != NO_ERR)
- {
- terrainLightRGB = 0xffffffff;
- }
- else
- {
- result = iniFile.readIdFloat("TerrainLightIntensity",terrainLightIntensity);
- if (result != NO_ERR)
- terrainLightIntensity = 0.5f;
-
- result = iniFile.readIdFloat("TerrainLightInnerRadius",terrainLightInnerRadius);
- if (result != NO_ERR)
- terrainLightInnerRadius = 100.0f;
-
- result = iniFile.readIdFloat("TerrainLightOuterRadius",terrainLightOuterRadius);
- if (result != NO_ERR)
- terrainLightOuterRadius = 250.0f;
- }
-
- char aseFileName[512];
- result = iniFile.readIdString("FileName",aseFileName,511);
- if (result != NO_ERR)
- {
- //Check for LOD filenames instead
- for (long i=0;i<MAX_LODS;i++)
- {
- char baseName[256];
- char baseLODDist[256];
- sprintf(baseName,"FileName%d",i);
- sprintf(baseLODDist,"Distance%d",i);
-
- result = iniFile.readIdString(baseName,aseFileName,511);
- if (result == NO_ERR)
- {
- result = iniFile.readIdFloat(baseLODDist,lodDistance[i]);
- if (result != NO_ERR)
- STOP(("LOD %d has no distance value in file %s",i,fileName));
-
- //----------------------------------------------
- // Base LOD shape. In stand Pose by default.
- bldgShape[i] = new TG_TypeMultiShape;
- gosASSERT(bldgShape[i] != NULL);
-
- FullPathFileName bldgName;
- bldgName.init(tglPath,aseFileName,".ase");
-
- bldgShape[i]->LoadTGMultiShapeFromASE(bldgName);
- }
- else if (!i)
- {
- STOP(("No base LOD for shape %s",fileName));
- }
- }
- }
- else
- {
- //----------------------------------------------
- // Base shape. In stand Pose by default.
- bldgShape[0] = new TG_TypeMultiShape;
- gosASSERT(bldgShape[0] != NULL);
-
- FullPathFileName bldgName;
- bldgName.init(tglPath,aseFileName,".ase");
-
- bldgShape[0]->LoadTGMultiShapeFromASE(bldgName);
- }
- result = iniFile.readIdString("ShadowName",aseFileName,511);
- if (result == NO_ERR)
- {
- //----------------------------------------------
- // Base Shadow shape.
- bldgShadowShape = new TG_TypeMultiShape;
- gosASSERT(bldgShadowShape != NULL);
-
- FullPathFileName bldgName;
- bldgName.init(tglPath,aseFileName,".ase");
-
- bldgShadowShape->LoadTGMultiShapeFromASE(bldgName);
- }
-
- //destroyed state.
- result = iniFile.seekBlock("TGLDamage");
- if (result == NO_ERR)
- {
- result = iniFile.readIdString("FileName",aseFileName,511);
- if (result != NO_ERR)
- Fatal(result,"Could not find ASE FileName in building appearance INI file");
-
- FullPathFileName dmgName;
- dmgName.init(tglPath,aseFileName,".ase");
-
- bldgDmgShape = new TG_TypeMultiShape;
- gosASSERT(bldgDmgShape != NULL);
- bldgDmgShape->LoadTGMultiShapeFromASE(dmgName);
- if (!bldgDmgShape->GetNumShapes())
- {
- delete bldgDmgShape;
- bldgDmgShape = NULL;
- }
-
- //Shadow for destroyed state.
- result = iniFile.readIdString("ShadowName",aseFileName,511);
- if (result == NO_ERR)
- {
- //----------------------------------------------
- // Base Shadow shape.
- bldgDmgShadowShape = new TG_TypeMultiShape;
- gosASSERT(bldgDmgShadowShape != NULL);
-
- FullPathFileName bldgName;
- bldgName.init(tglPath,aseFileName,".ase");
-
- bldgDmgShadowShape->LoadTGMultiShapeFromASE(bldgName);
- if (!bldgDmgShadowShape->GetNumShapes())
- {
- delete bldgDmgShadowShape;
- bldgDmgShadowShape = NULL;
- }
- }
- }
- else
- {
- bldgDmgShape = NULL;
- bldgDmgShadowShape = NULL;
- }
- result = iniFile.seekBlock("TGLDestructEffect");
- if (result == NO_ERR)
- {
- result = iniFile.readIdString("FileName",destructEffect,59);
- if (result != NO_ERR)
- STOP(("Could not Find DestructEffectName in building appearance INI file"));
-
- }
- else
- {
- destructEffect[0] = 0;
- }
- //--------------------------------------------------------------------
- // Load Animation Information.
- // We can load up to 10 Animation States.
- for (long i=0;i<MAX_BD_ANIMATIONS;i++)
- {
- char blockId[512];
- sprintf(blockId,"Animation:%d",i);
-
- result = iniFile.seekBlock(blockId);
- if (result == NO_ERR)
- {
- char animName[512];
- result = iniFile.readIdString("AnimationName",animName,511);
- gosASSERT(result == NO_ERR);
-
- result = iniFile.readIdBoolean("LoopAnimation",bdAnimLoop[i]);
- gosASSERT(result == NO_ERR);
-
- result = iniFile.readIdBoolean("Reverse",bdReverse[i]);
- gosASSERT(result == NO_ERR);
-
- result = iniFile.readIdBoolean("Random",bdRandom[i]);
- gosASSERT(result == NO_ERR);
-
- result = iniFile.readIdLong("StartFrame",bdStartF[i]);
- if (result != NO_ERR)
- bdStartF[i] = 0;
-
- //-------------------------------
- // We have an animation to load.
- FullPathFileName animPath;
- animPath.init(tglPath,animName,".ase");
- FullPathFileName otherPath;
- otherPath.init(tglPath,animName,".agl");
- if (fileExists(animPath) || fileExists(otherPath))
- {
- bdAnimData[i] = new TG_AnimateShape;
- gosASSERT(bdAnimData[i] != NULL);
-
- //--------------------------------------------------------
- // If this animation does not exist, it is not a problem!
- // Building will simply freeze until animation is "over"
- bdAnimData[i]->LoadTGMultiShapeAnimationFromASE(animPath,bldgShape[0]);
- }
- else
- bdAnimData[i] = NULL;
- }
- else
- {
- bdAnimData[i] = NULL;
- }
- }
-
- //--------------------------------------------------------------------
- // We can also load the node to pitch and yaw for spotlights/turrets.
- result = iniFile.seekBlock("AnimationNode");
- if (result == NO_ERR)
- {
- result = iniFile.readIdString("AnimationNodeId",rotationalNodeId,24);
- gosASSERT(result == NO_ERR);
- }
- else
- {
- strcpy(rotationalNodeId,"NONE");
- }
-
- if (nFrameRate != 0.0f)
- {
- for (long i=0;i<MAX_BD_ANIMATIONS;i++)
- setFrameRate(i,nFrameRate);
- }
- //-----------------------------------------------
- // Load up the Weapon Node Data.
- numWeaponNodes = 0;
- nodeData = NULL;
- result = iniFile.seekBlock("WeaponNode");
- if (result == NO_ERR)
- {
- nodeData = (NodeData *)AppearanceTypeList::appearanceHeap->Malloc(sizeof(NodeData)*(MAX_WEAPON_NODES));
- gosASSERT(nodeData != NULL);
-
- for (i=0;i<MAX_WEAPON_NODES;i++)
- {
- char blockId[512];
- sprintf(blockId,"WeaponNodeId%d",i);
-
- char weaponName[512];
- result = iniFile.readIdString(blockId,weaponName,511);
- if (result != NO_ERR)
- {
- strcpy(weaponName,"NONE");
- }
-
- nodeData[i].nodeId = (char *)AppearanceTypeList::appearanceHeap->Malloc(strlen(weaponName)+1);
- gosASSERT(nodeData[i].nodeId != NULL);
-
- strcpy(nodeData[i].nodeId,weaponName);
- nodeData[i].weaponType = 0;
- numWeaponNodes++;
- }
- }
- for (i=0;i<MAX_LODS;i++)
- {
- if (bldgShape[i])
- bldgShape[i]->SetLightRGBs(hotPinkRGB, hotGreenRGB, hotYellowRGB);
- }
- }
- //----------------------------------------------------------------------------
- void BldgAppearanceType::destroy (void)
- {
- AppearanceType::destroy();
- for (long i=0;i<MAX_LODS;i++)
- {
- if (bldgShape[i])
- {
- delete bldgShape[i];
- bldgShape[i] = NULL;
- }
- }
- if (bldgShadowShape)
- {
- delete bldgShadowShape;
- bldgShadowShape = NULL;
- }
-
- if (bldgDmgShape)
- {
- delete bldgDmgShape;
- bldgDmgShape = NULL;
- }
-
- if (bldgDmgShadowShape)
- {
- delete bldgDmgShadowShape;
- bldgDmgShadowShape = NULL;
- }
-
- for (i=0;i<MAX_BD_ANIMATIONS;i++)
- {
- if (bdAnimData[i])
- {
- delete bdAnimData[i];
- bdAnimData[i] = NULL;
- }
- }
- }
- //-----------------------------------------------------------------------------
- void BldgAppearanceType::setAnimation (TG_MultiShapePtr shape, DWORD animationNum)
- {
- gosASSERT(shape != NULL);
- gosASSERT(animationNum != 0xffffffff);
- gosASSERT(animationNum < MAX_BD_ANIMATIONS);
- if (bdAnimData[animationNum])
- bdAnimData[animationNum]->SetAnimationState(shape);
- else
- shape->ClearAnimation();
- }
- //-----------------------------------------------------------------------------
- // class BldgAppearance
- void BldgAppearance::setWeaponNodeUsed (long weaponNode)
- {
- weaponNode -= appearType->numWeaponNodes;
- if ((weaponNode >= 0) && (weaponNode < appearType->numWeaponNodes))
- {
- nodeUsed[weaponNode]++;
- nodeRecycle[weaponNode] = BASE_NODE_RECYCLE_TIME;
- }
- }
- //-----------------------------------------------------------------------------
- Stuff::Vector3D BldgAppearance::getWeaponNodePosition (long nodeId)
- {
- Stuff::Vector3D result = position;
- if ((nodeId < 0) || (nodeId >= appearType->numWeaponNodes))
- return result;
-
- //We already know we are using this node. Do NOT increment recycle or nodeUsed!
-
- //-------------------------------------------
- // Create Matrix to conform to.
- Stuff::UnitQuaternion qRotation;
- float yaw = rotation * DEGREES_TO_RADS;
- qRotation = Stuff::EulerAngles(0.0f, yaw, 0.0f);
-
- Stuff::Point3D xlatPosition;
- xlatPosition.x = -position.x;
- xlatPosition.y = land->getTerrainElevation(position);
- xlatPosition.z = position.y;
-
- Stuff::UnitQuaternion torsoRot;
- torsoRot = Stuff::EulerAngles(0.0f,(turretYaw * DEGREES_TO_RADS),0.0f);
- if (rotationalNodeId == -1)
- {
- if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
- rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
- else
- rotationalNodeId = -2;
- }
-
- if (rotationalNodeId >= 0)
- bldgShape->SetNodeRotation(rotationalNodeId,&torsoRot);
- result = bldgShape->GetTransformedNodePosition(&xlatPosition,&qRotation,appearType->nodeData[nodeId].nodeId);
- if ((result.x == 0.0f) &&
- (result.y == 0.0f) &&
- (result.z == 0.0f))
- result = position;
-
- return result;
- }
- //-----------------------------------------------------------------------------
- Stuff::Vector3D BldgAppearance::getHitNode (void)
- {
- if (hitNodeId == -1)
- hitNodeId = bldgShape->GetNodeNameId("hitnode");
- Stuff::Vector3D result = getNodeIdPosition(hitNodeId);
- return result;
- }
- //-----------------------------------------------------------------------------
- long BldgAppearance::getWeaponNode (long weaponType)
- {
- //------------------------------------------------
- // Scan all weapon nodes and find least used one.
- long leastUsed = 999999999;
- long bestNode = -1;
- for (long i=0;i<appearType->numWeaponNodes;i++)
- {
- if (nodeUsed[i] < leastUsed)
- {
- leastUsed = nodeUsed[i];
- bestNode = i;
- }
- }
-
- if ((bestNode < 0) || (bestNode >= appearType->numWeaponNodes))
- return -1;
- return bestNode;
- }
-
- //-----------------------------------------------------------------------------
- float BldgAppearance::getWeaponNodeRecycle (long node)
- {
- if ((node >= 0) && (node < appearType->numWeaponNodes))
- return nodeRecycle[node];
-
- return 0.0f;
- }
- //-----------------------------------------------------------------------------
- void BldgAppearance::init (AppearanceTypePtr tree, GameObjectPtr obj)
- {
- Appearance::init(tree,obj);
- appearType = (BldgAppearanceType *)tree;
- shapeMin.x = shapeMin.y = -25;
- shapeMax.x = shapeMax.y = 50;
- bdAnimationState =-1;
- currentFrame = 0.0f;
- bdFrameRate = 0.0f;
- isReversed = false;
- isLooping = false;
- setFirstFrame = false;
- canTransition = true;
-
- paintScheme = -1;
- objectNameId = 30469;
- hazeFactor = 0.0f;
- rotationalNodeId = -1;
- hitNodeId = activityNodeId = activityNode1Id = -1;
- currentFlash = duration = flashDuration = 0.0f;
- flashColor = 0x00000000;
- drawFlash = false;
- pointLight = NULL;
- lightId = 0xffffffff;
- forceLightsOut = false;
-
- screenPos.x = screenPos.y = screenPos.z = screenPos.w = -999.0f;
- position.Zero();
- rotation = 0.0f;
- selected = 0;
- teamId = -1;
- homeTeamRelationship = 0;
- actualRotation = rotation;
- currentLOD = 0;
-
- turretYaw = turretPitch = 0.0f;
-
- destructFX = NULL;
- activity = NULL;
- activity1 = NULL;
- isActivitying = false;
- OBBRadius = -1.0f;
- highZ = -1.0f;
-
- nodeUsed = NULL;
- nodeRecycle = NULL;
-
- beenInView = false;
- fogLightSet = false;
- if (appearType)
- {
- bldgShape = appearType->bldgShape[0]->CreateFrom();
- //-------------------------------------------------
- // Load the texture and store its handle.
- for (long i=0;i<bldgShape->GetNumTextures();i++)
- {
- char txmName[1024];
- bldgShape->GetTextureName(i,txmName,256);
- char texturePath[1024];
- sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
-
- FullPathFileName textureName;
- textureName.init(texturePath,txmName,"");
-
- if (fileExists(textureName))
- {
- if (strnicmp(txmName,"a_",2) == 0)
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- bldgShape->SetTextureHandle(i,gosTextureHandle);
- bldgShape->SetTextureAlpha(i,true);
- }
- else
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- bldgShape->SetTextureHandle(i,gosTextureHandle);
- bldgShape->SetTextureAlpha(i,false);
- }
- }
- else
- {
- //PAUSE(("Warning: %s texture name not found",textureName));
- bldgShape->SetTextureHandle(i,0xffffffff);
- }
- }
-
- if (appearType->bldgShadowShape)
- {
- bldgShadowShape = appearType->bldgShadowShape->CreateFrom();
-
- //-------------------------------------------------
- // Load the texture and store its handle.
- for (long i=0;i<bldgShadowShape->GetNumTextures();i++)
- {
- char txmName[1024];
- bldgShadowShape->GetTextureName(i,txmName,256);
-
- char texturePath[1024];
- sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
-
- FullPathFileName textureName;
- textureName.init(texturePath,txmName,"");
-
- if (fileExists(textureName))
- {
- if (strnicmp(txmName,"a_",2) == 0)
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- bldgShadowShape->SetTextureHandle(i,gosTextureHandle);
- bldgShadowShape->SetTextureAlpha(i,true);
- }
- else
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- bldgShadowShape->SetTextureHandle(i,gosTextureHandle);
- bldgShadowShape->SetTextureAlpha(i,false);
- }
- }
- else
- {
- bldgShadowShape->SetTextureHandle(i,0xffffffff);
- }
- }
- }
- else
- {
- bldgShadowShape = NULL;
- }
-
- Stuff::Vector3D boxCoords[8];
- Stuff::Vector3D nodeCenter = bldgShape->GetRootNodeCenter();
- boxCoords[0].x = position.x + bldgShape->GetMinBox().x + nodeCenter.x;
- boxCoords[0].y = position.y + bldgShape->GetMinBox().z + nodeCenter.z;
- boxCoords[0].z = position.z + bldgShape->GetMaxBox().y + nodeCenter.y;
-
- boxCoords[1].x = position.x + bldgShape->GetMinBox().x + nodeCenter.x;
- boxCoords[1].y = position.y + bldgShape->GetMaxBox().z + nodeCenter.z;
- boxCoords[1].z = position.z + bldgShape->GetMaxBox().y + nodeCenter.y;
-
- boxCoords[2].x = position.x + bldgShape->GetMaxBox().x + nodeCenter.x;
- boxCoords[2].y = position.y + bldgShape->GetMaxBox().z + nodeCenter.z;
- boxCoords[2].z = position.z + bldgShape->GetMaxBox().y + nodeCenter.y;
-
- boxCoords[3].x = position.x + bldgShape->GetMaxBox().x + nodeCenter.x;
- boxCoords[3].y = position.y + bldgShape->GetMinBox().z + nodeCenter.z;
- boxCoords[3].z = position.z + bldgShape->GetMaxBox().y + nodeCenter.y;
-
- boxCoords[4].x = position.x + bldgShape->GetMinBox().x + nodeCenter.x;
- boxCoords[4].y = position.y + bldgShape->GetMinBox().z + nodeCenter.z;
- boxCoords[4].z = position.z + bldgShape->GetMinBox().y + nodeCenter.y;
-
- boxCoords[5].x = position.x + bldgShape->GetMaxBox().x + nodeCenter.x;
- boxCoords[5].y = position.y + bldgShape->GetMinBox().z + nodeCenter.z;
- boxCoords[5].z = position.z + bldgShape->GetMinBox().y + nodeCenter.y;
-
- boxCoords[6].x = position.x + bldgShape->GetMaxBox().x + nodeCenter.x;
- boxCoords[6].y = position.y + bldgShape->GetMaxBox().z + nodeCenter.z;
- boxCoords[6].z = position.z + bldgShape->GetMinBox().y + nodeCenter.y;
-
- boxCoords[7].x = position.x + bldgShape->GetMinBox().x + nodeCenter.x;
- boxCoords[7].y = position.y + bldgShape->GetMaxBox().z + nodeCenter.z;
- boxCoords[7].z = position.z + bldgShape->GetMinBox().y + nodeCenter.y;
-
- float testRadius = 0.0;
-
- for (i=0;i<8;i++)
- {
- testRadius = boxCoords[i].GetLength();
- if (OBBRadius < testRadius)
- OBBRadius = testRadius;
- if (boxCoords[i].z > highZ)
- highZ = boxCoords[i].z;
- }
-
- appearType->boundsUpperLeftX = (-OBBRadius * 2.0);
- appearType->boundsUpperLeftY = (-OBBRadius * 2.0);
-
- appearType->boundsLowerRightX = (OBBRadius * 2.0);
- appearType->boundsLowerRightY = (OBBRadius);
-
- if (!appearType->getDesignerTypeBounds())
- {
- Stuff::Vector3D nodeCenter = bldgShape->GetRootNodeCenter();
- appearType->typeUpperLeft.Add(bldgShape->GetMinBox(),nodeCenter);
- appearType->typeLowerRight.Add(bldgShape->GetMaxBox(),nodeCenter);
- }
-
- if (appearType->numWeaponNodes)
- {
- nodeUsed = (long *)AppearanceTypeList::appearanceHeap->Malloc(sizeof(long) * appearType->numWeaponNodes);
- gosASSERT(nodeUsed != NULL);
- memset(nodeUsed,0,sizeof(long) * appearType->numWeaponNodes);
-
- nodeRecycle = (float *)AppearanceTypeList::appearanceHeap->Malloc(sizeof(float) * appearType->numWeaponNodes);
- gosASSERT(nodeRecycle != NULL);
-
- for (long i=0;i<appearType->numWeaponNodes;i++)
- nodeRecycle[i] = 0.0f;
- }
- }
- }
- //-----------------------------------------------------------------------------
- void BldgAppearance::setObjStatus (long oStatus)
- {
- if (status != oStatus)
- {
- if ((oStatus == OBJECT_STATUS_DESTROYED) || (oStatus == OBJECT_STATUS_DISABLED))
- {
- if (appearType->bldgDmgShape)
- {
- if (bldgShape)
- {
- bldgShape->ClearAnimation();
- delete bldgShape;
- bldgShape = NULL;
- }
-
- bldgShape = appearType->bldgDmgShape->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(bldgShape,bdAnimationState);
-
- beenInView = false;
- currentLOD = 0;
- }
-
- if (appearType->bldgDmgShadowShape)
- {
- if (bldgShadowShape)
- {
- bldgShadowShape->ClearAnimation();
- delete bldgShadowShape;
- bldgShadowShape = NULL;
- }
-
- bldgShadowShape = appearType->bldgDmgShadowShape->CreateFrom();
-
- //Do shadows need to animate??
- //if (bdAnimationState != -1)
- //appearType->setAnimation(bldgShadowShape,bdAnimationState);
-
- beenInView = false;
- }
- stopActivity();
- }
-
- if (oStatus == OBJECT_STATUS_NORMAL)
- {
- if (appearType->bldgShape)
- {
- if (bldgShape)
- {
- bldgShape->ClearAnimation();
- delete bldgShape;
- bldgShape = NULL;
- }
-
- bldgShape = appearType->bldgShape[0]->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(bldgShape,bdAnimationState);
-
- beenInView = false;
- }
-
- if (appearType->bldgShadowShape)
- {
- if (bldgShadowShape)
- {
- bldgShadowShape->ClearAnimation();
- delete bldgShadowShape;
- bldgShadowShape = NULL;
- }
-
- bldgShadowShape = appearType->bldgShadowShape->CreateFrom();
-
- //Do shadows need to animate??
- // if (bdAnimationState != -1)
- //appearType->setAnimation(bldgShadowShape,bdAnimationState);
-
- beenInView = false;
- }
- }
-
- if (bldgShape)
- {
- //-------------------------------------------------
- // Load the texture and store its handle.
- for (long i=0;i<bldgShape->GetNumTextures();i++)
- {
- char txmName[1024];
- bldgShape->GetTextureName(i,txmName,256);
-
- char texturePath[1024];
- sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
-
- FullPathFileName textureName;
- textureName.init(texturePath,txmName,"");
-
- if (fileExists(textureName))
- {
- if (strnicmp(txmName,"a_",2) == 0)
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- bldgShape->SetTextureHandle(i,gosTextureHandle);
- bldgShape->SetTextureAlpha(i,true);
- }
- else
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- bldgShape->SetTextureHandle(i,gosTextureHandle);
- bldgShape->SetTextureAlpha(i,false);
- }
- }
- else
- {
- //PAUSE(("Warning: %s texture name not found",textureName));
- bldgShape->SetTextureHandle(i,0xffffffff);
- }
- }
- }
- if (bldgShadowShape)
- {
- //-------------------------------------------------
- // Load the texture for the shadow and store its handle.
- for (long i=0;i<bldgShadowShape->GetNumTextures();i++)
- {
- char txmName[1024];
- bldgShadowShape->GetTextureName(i,txmName,256);
-
- char texturePath[1024];
- sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
-
- FullPathFileName textureName;
- textureName.init(texturePath,txmName,"");
-
- if (fileExists(textureName))
- {
- if (strnicmp(txmName,"a_",2) == 0)
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- bldgShadowShape->SetTextureHandle(i,gosTextureHandle);
- bldgShadowShape->SetTextureAlpha(i,true);
- }
- else
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- bldgShadowShape->SetTextureHandle(i,gosTextureHandle);
- bldgShadowShape->SetTextureAlpha(i,false);
- }
- }
- else
- {
- bldgShadowShape->SetTextureHandle(i,0xffffffff);
- }
- }
- }
- }
-
- status = oStatus;
- }
- //-----------------------------------------------------------------------------
- Stuff::Vector3D BldgAppearance::getNodeNamePosition (char *nodeName)
- {
- Stuff::Vector3D result = position;
-
- //-------------------------------------------
- // Create Matrix to conform to.
- Stuff::UnitQuaternion qRotation;
- float yaw = rotation * DEGREES_TO_RADS;
- qRotation = Stuff::EulerAngles(0.0f, yaw, 0.0f);
-
- Stuff::Point3D xlatPosition;
- xlatPosition.x = -position.x;
- xlatPosition.y = position.z;
- xlatPosition.z = position.y;
-
- result = bldgShape->GetTransformedNodePosition(&xlatPosition,&qRotation,nodeName);
- if ((result.x == 0.0f) &&
- (result.y == 0.0f) &&
- (result.z == 0.0f))
- result = position;
-
- return result;
- }
- //-----------------------------------------------------------------------------
- Stuff::Vector3D BldgAppearance::getNodeIdPosition (long nodeId)
- {
- Stuff::Vector3D result = position;
-
- //-------------------------------------------
- // Create Matrix to conform to.
- Stuff::UnitQuaternion qRotation;
- float yaw = rotation * DEGREES_TO_RADS;
- qRotation = Stuff::EulerAngles(0.0f, yaw, 0.0f);
-
- Stuff::Point3D xlatPosition;
- xlatPosition.x = -position.x;
- xlatPosition.y = position.z;
- xlatPosition.z = position.y;
-
- result = bldgShape->GetTransformedNodePosition(&xlatPosition,&qRotation,nodeId);
- if ((result.x == 0.0f) &&
- (result.y == 0.0f) &&
- (result.z == 0.0f))
- result = position;
-
- return result;
- }
- //-----------------------------------------------------------------------------
- bool BldgAppearance::PerPolySelect (long mouseX, long mouseY)
- {
- return bldgShape->PerPolySelect(mouseX,mouseY);
- }
- //-----------------------------------------------------------------------------
- void BldgAppearance::setGesture (unsigned long gestureId)
- {
- //------------------------------------------------------------
- // Check if state is possible.
- if (gestureId >= MAX_BD_ANIMATIONS)
- return;
- //------------------------------------------------------------
- // Check if object destroyed. If so, no animation!
- if ((status == OBJECT_STATUS_DESTROYED) || (status == OBJECT_STATUS_DISABLED))
- return;
-
- if (gestureId == bdAnimationState)
- return;
- //----------------------------------------------------------------------
- // If state is OK, set animation data, set first frame, set loop and
- // reverse flag, and start it going until you hear otherwise.
- appearType->setAnimation(bldgShape,gestureId);
- bdAnimationState = gestureId;
- currentFrame = 0.0f;
- if (appearType->bdStartF[gestureId])
- currentFrame = appearType->bdStartF[gestureId];
-
- isReversed = false;
-
- if (appearType->isReversed(bdAnimationState))
- {
- currentFrame = appearType->getNumFrames(bdAnimationState)-1;
- isReversed = true;
- }
-
- if (appearType->isRandom(bdAnimationState))
- {
- currentFrame = RandomNumber(appearType->getNumFrames(bdAnimationState)-1);
- }
-
- isLooping = appearType->isLooped(bdAnimationState);
-
- bdFrameRate = appearType->getFrameRate(bdAnimationState);
-
- setFirstFrame = true;
- if (bdFrameRate > Stuff::SMALL)
- canTransition = false;
- else
- canTransition = true; //We can change immediately to another animation because we have no animation for this state!
- }
- //-----------------------------------------------------------------------------
- void BldgAppearance::setMoverParameters (float turretRot, float lArmRot, float rArmRot, bool isAirborne)
- {
- turretYaw = turretRot;
- turretPitch = lArmRot;
- }
- //-----------------------------------------------------------------------------
- void BldgAppearance::setObjectParameters (Stuff::Vector3D &pos, float Rot, long sel, long team, long homeRelations)
- {
- rotation = Rot;
- position = pos;
- selected = sel;
- actualRotation = Rot;
- teamId = team;
- homeTeamRelationship = homeRelations;
- }
- //-----------------------------------------------------------------------------
- bool BldgAppearance::isMouseOver (float px, float py)
- {
- if (inView)
- {
- if ((px <= lowerRight.x) && (py <= lowerRight.y) &&
- (px >= upperLeft.x) &&
- (py >= upperLeft.y))
- {
- return inView;
- }
- else
- {
- return FALSE;
- }
- }
-
- return(inView);
- }
- //-----------------------------------------------------------------------------
- bool BldgAppearance::recalcBounds (void)
- {
- Stuff::Vector4D tempPos;
- inView = false;
- float distanceToEye = 0.0f;
-
- if (eye)
- {
- //-------------------------------------------------------------------
- //NEW METHOD from the WAY BACK Days
- inView = true;
-
- if (eye->usePerspective)
- {
- Stuff::Vector3D cameraPos;
- cameraPos.x = -eye->getCameraOrigin().x;
- cameraPos.y = eye->getCameraOrigin().z;
- cameraPos.z = eye->getCameraOrigin().y;
- float vClipConstant = eye->verticalSphereClipConstant;
- float hClipConstant = eye->horizontalSphereClipConstant;
-
- Stuff::Vector3D objectCenter;
- objectCenter.Subtract(position,cameraPos);
- Camera::cameraFrame.trans_to_frame(objectCenter);
- distanceToEye = objectCenter.GetApproximateLength();
- float clip_distance = fabs(1.0f / objectCenter.y);
-
- //Is vertex on Screen OR close enough to screen that its triangle MAY be visible?
- // WE have removed the atans here by simply taking the tan of the angle we want above.
- float object_angle = fabs(objectCenter.z) * clip_distance;
- float extent_angle = bldgShape->GetExtentRadius() / distanceToEye;
- if (object_angle > (vClipConstant + extent_angle))
- {
- //In theory, we would return here. Object is NOT on screen.
- inView = false;
- }
- else
- {
- object_angle = fabs(objectCenter.x) * clip_distance;
- if (object_angle > (hClipConstant + extent_angle))
- {
- //In theory, we would return here. Object is NOT on screen.
- inView = false;
- }
- }
- }
-
- //Can we be seen at all?
- // If yes, check if we are behind fog plane.
- if (inView)
- {
- //ALWAYS need to do this or select is YAYA
- // But now inView is correct!!
- eye->projectZ(position,screenPos);
-
- if (eye->usePerspective)
- {
- if (distanceToEye > Camera::MaxClipDistance)
- {
- hazeFactor = 1.0f;
- inView = false;
- }
- else if (distanceToEye > Camera::MinHazeDistance)
- {
- Camera::HazeFactor = (distanceToEye - Camera::MinHazeDistance) * Camera::DistanceFactor;
- inView = true;
- }
- else
- {
- Camera::HazeFactor = 0.0f;
- inView = true;
- }
- }
- else
- {
- Camera::HazeFactor = 0.0f;
- inView = true;
- }
- }
-
- //If we were not behind fog plane, do a bunch O math we need later!!
- if (inView)
- {
- if (reloadBounds)
- appearType->reinit();
- appearType->boundsLowerRightY = (OBBRadius * eye->getTiltFactor() * 2.0f);
-
- //-------------------------------------------------------------------------
- // do a rough check if on screen. If no where near, do NOT do the below.
- // Mighty mighty slow!!!!
- // Use the original check done before all this 3D madness. Dig out sourceSafe tomorrow!
- tempPos = screenPos;
- upperLeft.x = tempPos.x;
- upperLeft.y = tempPos.y;
-
- lowerRight.x = tempPos.x;
- lowerRight.y = tempPos.y;
-
- upperLeft.x += (appearType->boundsUpperLeftX * eye->getScaleFactor());
- upperLeft.y += (appearType->boundsUpperLeftY * eye->getScaleFactor());
-
- lowerRight.x += (appearType->boundsLowerRightX * eye->getScaleFactor());
- lowerRight.y += (appearType->boundsLowerRightY * eye->getScaleFactor());
- if ((lowerRight.x >= 0) && (lowerRight.y >= 0) &&
- (upperLeft.x <= eye->getScreenResX()) &&
- (upperLeft.y <= eye->getScreenResY()))
- {
- //We are on screen. Figure out selection box.
- Stuff::Vector3D boxCoords[8];
- Stuff::Vector4D bcsp[8];
- Stuff::Vector3D boxStart;
- boxStart.x = -appearType->typeUpperLeft.x;
- boxStart.y = appearType->typeUpperLeft.z;
- boxStart.z = appearType->typeUpperLeft.y;
- Stuff::Vector3D boxEnd;
- boxEnd.x = -appearType->typeLowerRight.x;
- boxEnd.y = appearType->typeLowerRight.z;
- boxEnd.z = appearType->typeLowerRight.y;
-
- Stuff::Vector3D addCoords;
-
- addCoords.x = boxStart.x;
- addCoords.y = boxStart.y;
- addCoords.z = boxEnd.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[0].Add(position,addCoords);
-
- addCoords.x = boxStart.x;
- addCoords.y = boxEnd.y;
- addCoords.z = boxEnd.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[1].Add(position,addCoords);
-
- addCoords.x = boxEnd.x;
- addCoords.y = boxEnd.y;
- addCoords.z = boxEnd.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[2].Add(position,addCoords);
-
- addCoords.x = boxEnd.x;
- addCoords.y = boxStart.y;
- addCoords.z = boxEnd.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[3].Add(position,addCoords);
-
- addCoords.x = boxStart.x;
- addCoords.y = boxStart.y;
- addCoords.z = boxStart.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[4].Add(position,addCoords);
-
- addCoords.x = boxEnd.x;
- addCoords.y = boxStart.y;
- addCoords.z = boxStart.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[5].Add(position,addCoords);
-
- addCoords.x = boxEnd.x;
- addCoords.y = boxEnd.y;
- addCoords.z = boxStart.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[6].Add(position,addCoords);
-
- addCoords.x = boxStart.x;
- addCoords.y = boxEnd.y;
- addCoords.z = boxStart.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[7].Add(position,addCoords);
-
- float maxX = 0.0f, maxY = 0.0f;
- float minX = 0.0f, minY = 0.0f;
- for (long i=0;i<8;i++)
- {
- eye->projectZ(boxCoords[i],bcsp[i]);
- if (!i)
- {
- maxX = minX = bcsp[i].x;
- maxY = minY = bcsp[i].y;
- }
-
- if (i)
- {
- if (bcsp[i].x > maxX)
- maxX = bcsp[i].x;
-
- if (bcsp[i].x < minX)
- minX = bcsp[i].x;
-
- if (bcsp[i].y > maxY)
- maxY = bcsp[i].y;
-
- if (bcsp[i].y < minY)
- minY = bcsp[i].y;
- }
- }
-
- upperLeft.x = minX;
- upperLeft.y = minY;
- lowerRight.x = maxX;
- lowerRight.y = maxY;
-
- if ((lowerRight.x >= 0) && (lowerRight.y >= 0) &&
- (upperLeft.x <= eye->getScreenResX()) &&
- (upperLeft.y <= eye->getScreenResY()))
- {
- inView = true;
- if ((status != OBJECT_STATUS_DESTROYED) && (status != OBJECT_STATUS_DISABLED))
- {
- //-------------------------------------------------------------------------------
- //Set LOD of Model here because we have the distance and we KNOW we can see it!
- bool baseLOD = true;
- DWORD selectLOD = 0;
- if (useHighObjectDetail)
- {
- for (long i=1;i<MAX_LODS;i++)
- {
- if (appearType->bldgShape[i] && (distanceToEye > appearType->lodDistance[i]))
- {
- baseLOD = false;
- selectLOD = i;
- }
- }
- }
- else //We always want to use the lowest LOD!!
- {
- if (appearType->bldgShape[1])
- {
- baseLOD = false;
- selectLOD = 1;
- }
- }
-
- // we are at this LOD level.
- if (selectLOD != currentLOD)
- {
- currentLOD = selectLOD;
- bldgShape->ClearAnimation();
- delete bldgShape;
- bldgShape = NULL;
- bldgShape = appearType->bldgShape[currentLOD]->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(bldgShape,bdAnimationState);
- //-------------------------------------------------
- // Load the texture and store its handle.
- for (long j=0;j<bldgShape->GetNumTextures();j++)
- {
- char txmName[1024];
- bldgShape->GetTextureName(j,txmName,256);
- char texturePath[1024];
- sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
- FullPathFileName textureName;
- textureName.init(texturePath,txmName,"");
- if (fileExists(textureName))
- {
- if (strnicmp(txmName,"a_",2) == 0)
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- bldgShape->SetTextureHandle(j,gosTextureHandle);
- bldgShape->SetTextureAlpha(j,true);
- }
- else
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- bldgShape->SetTextureHandle(j,gosTextureHandle);
- bldgShape->SetTextureAlpha(j,false);
- }
- }
- else
- {
- //PAUSE(("Warning: %s texture name not found",textureName));
- bldgShape->SetTextureHandle(j,0xffffffff);
- }
- }
- }
- //ONLY change if we need
- if (currentLOD && baseLOD)
- {
- // we are at the Base LOD level.
- currentLOD = 0;
-
- bldgShape->ClearAnimation();
- delete bldgShape;
- bldgShape = NULL;
-
- bldgShape = appearType->bldgShape[currentLOD]->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(bldgShape,bdAnimationState);
-
- //-------------------------------------------------
- // Load the texture and store its handle.
- for (long i=0;i<bldgShape->GetNumTextures();i++)
- {
- char txmName[1024];
- bldgShape->GetTextureName(i,txmName,256);
-
- char texturePath[1024];
- sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
-
- FullPathFileName textureName;
- textureName.init(texturePath,txmName,"");
-
- if (fileExists(textureName))
- {
- if (strnicmp(txmName,"a_",2) == 0)
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- bldgShape->SetTextureHandle(i,gosTextureHandle);
- bldgShape->SetTextureAlpha(i,true);
- }
- else
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- bldgShape->SetTextureHandle(i,gosTextureHandle);
- bldgShape->SetTextureAlpha(i,false);
- }
- }
- else
- {
- //PAUSE(("Warning: %s texture name not found",textureName));
- bldgShape->SetTextureHandle(i,0xffffffff);
- }
- }
- }
- }
- }
- else
- {
- inView = false; //Did alot of extra work checking this, but WHY draw and insult to injury?
- }
- }
- else
- {
- inView = false;
- }
- }
- }
-
- return(inView);
- }
- //-----------------------------------------------------------------------------
- bool BldgAppearance::playDestruction (void)
- {
- //Check if there is a Destruct FX
- if (appearType->destructEffect[0])
- {
- //--------------------------------------------
- // Yes, load it on up.
- unsigned flags = gosFX::Effect::ExecuteFlag;
- Check_Object(gosFX::EffectLibrary::Instance);
- gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(appearType->destructEffect);
-
- if (gosEffectSpec)
- {
- destructFX = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
- gosASSERT(destructFX != NULL);
-
- MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
-
- Stuff::Point3D tPosition;
- Stuff::LinearMatrix4D shapeOrigin;
- Stuff::LinearMatrix4D localToWorld;
-
- //Stuff::Vector3D offsetPosition;
- //offsetPosition.x = Terrain::worldUnitsPerVertex / 3.0f;
- //offsetPosition.y = -(Terrain::worldUnitsPerVertex / 3.0f);
- //offsetPosition.z = 0.0f;
- //OppRotate(offsetPosition,rotation);
- Stuff::Vector3D actualPosition = position;
- //actualPosition.Add(position,offsetPosition);
- tPosition.x = -actualPosition.x;
- tPosition.y = actualPosition.z;
- tPosition.z = actualPosition.y;
- float yaw = (180.0f + rotation) * DEGREES_TO_RADS;
- Stuff::UnitQuaternion rot;
- rot = Stuff::EulerAngles(0.0f, yaw, 0.0f);
- shapeOrigin.BuildRotation(rot);
- shapeOrigin.BuildTranslation(tPosition);
-
- gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,NULL);
- destructFX->Start(&info);
-
- return true;
- }
-
- return false;
- }
-
- return false; //We didn't have a destruct effect. Tell the object to play its default.
- }
- //-----------------------------------------------------------------------------
- long BldgAppearance::render (long depthFixup)
- {
- if (inView)
- {
- long color = SD_BLUE;
- unsigned long highLight = 0x007f7f7f;
- if ((teamId > -1) && (teamId < 8)) {
- static unsigned long highLightTable[3] = {0x00007f00, 0x0000007f, 0x007f0000};
- static long colorTable[3] = {SB_GREEN | 0xff000000, SB_BLUE | 0xff000000, SB_RED| 0xff000000};
- color = colorTable[homeTeamRelationship];
- highLight = highLightTable[homeTeamRelationship];
- }
- if (selected & DRAW_COLORED)
- {
- bldgShape->SetARGBHighLight(highLight);
- }
- else
- {
- bldgShape->SetARGBHighLight(highlightColor);
- }
-
- if (drawFlash)
- {
- bldgShape->SetARGBHighLight(flashColor);
- }
-
- //---------------------------------------------
- // Call Multi-shape render stuff here.
- if (appearType->spinMe)
- bldgShape->Render(false,0.00001f);
- else if (!depthFixup)
- bldgShape->Render();
- else if (depthFixup > 0)
- bldgShape->Render(false,0.9999999f);
- else if (depthFixup < 0)
- bldgShape->Render(false,0.00001f);
- if (selected & DRAW_BARS)
- {
- if (!appearType->spinMe)
- {
- drawBars();
- //drawSelectBrackets(color);
- }
- }
- if ( selected & DRAW_TEXT )
- {
- if (objectNameId != -1)
- {
- char tmpString[255];
- cLoadString(objectNameId, tmpString, 254);
- drawTextHelp(tmpString, color);
- }
- }
-
- //------------------------------------------
- // Render GOS FX if necessary
- if (destructFX && destructFX->IsExecuted())
- {
- gosFX::Effect::DrawInfo drawInfo;
- drawInfo.m_clipper = theClipper;
-
- MidLevelRenderer::MLRState mlrState;
- mlrState.SetDitherOn();
- mlrState.SetTextureCorrectionOn();
- mlrState.SetZBufferCompareOn();
- mlrState.SetZBufferWriteOn();
-
- drawInfo.m_state = mlrState;
- drawInfo.m_clippingFlags = 0x0;
- Stuff::LinearMatrix4D shapeOrigin;
- Stuff::LinearMatrix4D localToWorld;
- Stuff::Point3D tPosition;
-
- //Stuff::Vector3D offsetPosition;
- //offsetPosition.x = Terrain::worldUnitsPerVertex / 3.0f;
- //offsetPosition.y = -(Terrain::worldUnitsPerVertex / 3.0f);
- //offsetPosition.z = 0.0f;
- //OppRotate(offsetPosition,rotation);
- Stuff::Vector3D actualPosition = position;
- //actualPosition.Add(position,offsetPosition);
- tPosition.x = -actualPosition.x;
- tPosition.y = actualPosition.z;
- tPosition.z = actualPosition.y;
- float yaw = (180.0f + rotation) * DEGREES_TO_RADS;
- Stuff::UnitQuaternion rot;
- rot = Stuff::EulerAngles(0.0f, yaw, 0.0f);
- shapeOrigin.BuildRotation(rot);
- shapeOrigin.BuildTranslation(tPosition);
-
- drawInfo.m_parentToWorld = &shapeOrigin;
-
- if (!MLRVertexLimitReached)
- destructFX->Draw(&drawInfo);
- }
-
- if (isActivitying)
- {
- gosFX::Effect::DrawInfo drawInfo;
- drawInfo.m_clipper = theClipper;
- MidLevelRenderer::MLRState mlrState;
- mlrState.SetDitherOn();
- mlrState.SetTextureCorrectionOn();
- mlrState.SetZBufferCompareOn();
- mlrState.SetZBufferWriteOn();
-
- drawInfo.m_state = mlrState;
- drawInfo.m_clippingFlags = 0x0;
- Stuff::LinearMatrix4D shapeOrigin;
- Stuff::LinearMatrix4D localToWorld;
- Stuff::LinearMatrix4D localResult;
- if (activityNodeId == -1)
- activityNodeId = bldgShape->GetNodeNameId("activity_node");
- Stuff::Vector3D dustPos = getNodeIdPosition(activityNodeId);
- if (rotationalNodeId == -1)
- {
- if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
- rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
- else
- rotationalNodeId = -2;
- }
- if (rotationalNodeId >= 0)
- dustPos = getNodeIdPosition(rotationalNodeId);
-
- Stuff::Point3D wakePos;
- wakePos.x = -dustPos.x;
- wakePos.y = dustPos.z;
- wakePos.z = dustPos.y;
-
- shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
- shapeOrigin.BuildTranslation(wakePos);
-
- /*
- Stuff::UnitQuaternion effectRot;
- effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
- localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
- localResult.Multiply(localToWorld,shapeOrigin);
- */
- drawInfo.m_parentToWorld = &shapeOrigin;
- if (!MLRVertexLimitReached)
- activity->Draw(&drawInfo);
-
- if (activity1)
- {
- if (activityNodeId == -1)
- activityNodeId = bldgShape->GetNodeNameId("activity_node");
- Stuff::Vector3D dustPos = getNodeIdPosition(activityNodeId);
-
- if (rotationalNodeId == -1)
- {
- if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
- rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
- else
- rotationalNodeId = -2;
- }
-
- if (rotationalNodeId >= 0)
- dustPos = getNodeIdPosition(rotationalNodeId);
-
- Stuff::Point3D wakePos;
- wakePos.x = -dustPos.x;
- wakePos.y = dustPos.z;
- wakePos.z = dustPos.y;
-
- shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
- shapeOrigin.BuildTranslation(wakePos);
-
- /*
- Stuff::UnitQuaternion effectRot;
- effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
- localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
- localResult.Multiply(localToWorld,shapeOrigin);
- */
-
- drawInfo.m_parentToWorld = &shapeOrigin;
- if (!MLRVertexLimitReached)
- activity1->Draw(&drawInfo);
- }
- }
-
- // selected = FALSE;
- //#define DRAW_BOX
- #ifdef DRAW_BOX
- //---------------------------------------------------------
- // Render the Bounding Box to see if it is OK.
- Stuff::Vector3D nodeCenter = bldgShape->GetRootNodeCenter();
- Stuff::Vector3D boxStart;
- Stuff::Vector3D boxEnd;
- boxStart.x = -(bldgShape->GetMinBox().x + nodeCenter.x);
- boxStart.z = bldgShape->GetMinBox().y + nodeCenter.y;
- boxStart.y = bldgShape->GetMinBox().z + nodeCenter.z;
-
- boxEnd.x = -(bldgShape->GetMaxBox().x + nodeCenter.x);
- boxEnd.z = bldgShape->GetMaxBox().y + nodeCenter.y;
- boxEnd.y = bldgShape->GetMaxBox().z + nodeCenter.z;
-
- Stuff::Vector3D boxCoords[8];
- Stuff::Vector3D addCoords;
-
- addCoords.x = boxStart.x;
- addCoords.y = boxStart.y;
- addCoords.z = boxEnd.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[0].Add(position,addCoords);
- addCoords.x = boxStart.x;
- addCoords.y = boxEnd.y;
- addCoords.z = boxEnd.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[1].Add(position,addCoords);
- addCoords.x = boxEnd.x;
- addCoords.y = boxEnd.y;
- addCoords.z = boxEnd.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[2].Add(position,addCoords);
-
- addCoords.x = boxEnd.x;
- addCoords.y = boxStart.y;
- addCoords.z = boxEnd.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[3].Add(position,addCoords);
-
- addCoords.x = boxStart.x;
- addCoords.y = boxStart.y;
- addCoords.z = boxStart.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[4].Add(position,addCoords);
-
- addCoords.x = boxEnd.x;
- addCoords.y = boxStart.y;
- addCoords.z = boxStart.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[5].Add(position,addCoords);
-
- addCoords.x = boxEnd.x;
- addCoords.y = boxEnd.y;
- addCoords.z = boxStart.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[6].Add(position,addCoords);
-
- addCoords.x = boxStart.x;
- addCoords.y = boxEnd.y;
- addCoords.z = boxStart.z;
- if (rotation != 0.0f)
- Rotate(addCoords,-rotation);
-
- boxCoords[7].Add(position,addCoords);
-
- Stuff::Vector4D screenPos[8];
- for (long i=0;i<8;i++)
- {
- eye->projectZ(boxCoords[i],screenPos[i]);
- }
-
- {
- LineElement newElement(screenPos[0],screenPos[1],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[0],screenPos[4],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[0],screenPos[3],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[5],screenPos[4],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[5],screenPos[6],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[5],screenPos[3],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[2],screenPos[3],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[2],screenPos[6],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[2],screenPos[1],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[7],screenPos[1],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[7],screenPos[6],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[7],screenPos[4],XP_WHITE,NULL,-1);
- newElement.draw();
- }
- #endif
- #undef DRAW_BOX
- }
- return NO_ERR;
- }
- //-----------------------------------------------------------------------------
- long BldgAppearance::renderShadows (void)
- {
- if (inView && visible && !appearType->spinMe)
- {
- //---------------------------------------------
- // Call Multi-shape render stuff here.
- if (bldgShadowShape)
- bldgShadowShape->RenderShadows();
- else
- bldgShape->RenderShadows();
- }
- return NO_ERR;
- }
- //-----------------------------------------------------------------------------
- long BldgAppearance::update (bool animate)
- {
- Stuff::Point3D xlatPosition;
- Stuff::UnitQuaternion rot;
- //----------------------------------------
- // Recycle the weapon Nodes
- if (nodeRecycle)
- {
- for (long i=0;i<appearType->numWeaponNodes;i++)
- {
- if (nodeRecycle[i] > 0.0f)
- {
- nodeRecycle[i] -= frameLength;
- if (nodeRecycle[i] < 0.0f)
- nodeRecycle[i] = 0.0f;
- }
- }
- }
- if (appearType->terrainLightRGB != 0xffffffff && (eye->nightFactor > 0.0f) && !forceLightsOut)
- {
- if (!pointLight)
- {
- pointLight = (TG_LightPtr)malloc(sizeof(TG_Light));
- pointLight->init(TG_LIGHT_TERRAIN);
- lightId = eye->addWorldLight(pointLight);
-
- pointLight->SetaRGB(appearType->terrainLightRGB);
- pointLight->SetIntensity(appearType->terrainLightIntensity);
- pointLight->SetFalloffDistances(appearType->terrainLightInnerRadius, appearType->terrainLightOuterRadius);
- }
-
- if (pointLight)
- {
- Stuff::Point3D ourPosition;
- ourPosition.x = -position.x;
- ourPosition.y = position.z;
- ourPosition.z = position.y;
-
- pointLight->direction = ourPosition;
-
- Stuff::LinearMatrix4D lightToWorldMatrix;
- lightToWorldMatrix.BuildTranslation(ourPosition);
- lightToWorldMatrix.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
- pointLight->SetLightToWorld(&lightToWorldMatrix);
- pointLight->SetPosition(&position);
- pointLight->SetIntensity(appearType->terrainLightIntensity * eye->getNightFactor());
- }
- }
- else
- {
- //Turn the lights off!
- //Need to kill the light source here too!
- if (pointLight)
- {
- eye->removeWorldLight(lightId,pointLight);
- free(pointLight);
- pointLight = NULL;
- }
- }
- if (forceLightsOut)
- bldgShape->SetLightsOut(true);
-
- //Update flashing regardless of view!!!
- if (duration > 0.0f)
- {
- duration -= frameLength;
- currentFlash -= frameLength;
- if (currentFlash < 0.0f)
- {
- drawFlash ^= true;
- currentFlash = flashDuration;
- }
- }
- else
- {
- drawFlash = false;
- }
- if (inView)
- {
- if (appearType->spinMe)
- rotation += SPINRATE * frameLength;
-
- if (rotation > 180)
- rotation -= 360;
-
- if (rotation < -180)
- rotation += 360;
-
- //-------------------------------------------
- // Does math necessary to draw Tree
- float yaw = rotation * DEGREES_TO_RADS;
- rot = Stuff::EulerAngles(0.0f, yaw, 0.0f);
-
- if (appearType->spinMe && land)
- {
- //Make sure we are above the water level
- if (position.z < Terrain::waterElevation)
- position.z = Terrain::waterElevation;
- }
- xlatPosition.x = -position.x;
- xlatPosition.y = position.z;
- xlatPosition.z = position.y;
- if (!fogLightSet)
- {
- unsigned char lightr,lightg,lightb;
- float lightIntensity = 1.0f;
- if (land)
- lightIntensity = land->getTerrainLight(position);
- lightr = eye->getLightRed(lightIntensity);
- lightg = eye->getLightGreen(lightIntensity);
- lightb = eye->getLightBlue(lightIntensity);
- lightRGB = (lightr<<16) + (lightg<<8) + lightb;
- fogRGB = 0xff<<24;
- float fogStart = eye->fogStart;
- float fogFull = eye->fogFull;
- if (xlatPosition.y < fogStart)
- {
- float fogFactor = fogStart - xlatPosition.y;
- if (fogFactor < 0.0)
- fogRGB = 0xff<<24;
- else
- {
- fogFactor /= (fogStart - fogFull);
- if (fogFactor <= 1.0)
- {
- fogFactor *= fogFactor;
- fogFactor = 1.0 - fogFactor;
- fogFactor *= 256.0;
- }
- else
- {
- fogFactor = 256.0;
- }
- unsigned char fogResult = float2long(fogFactor);
- fogRGB = fogResult << 24;
- }
- }
- else
- {
- fogRGB = 0xff<<24;
- }
- fogLightSet = true;
- }
-
- eye->setLightColor(0,lightRGB);
- eye->setLightIntensity(0,1.0);
- if (useFog)
- bldgShape->SetFogRGB(fogRGB);
- else
- bldgShape->SetFogRGB(0xffffffff);
-
- Stuff::UnitQuaternion turretRot;
- turretRot = Stuff::EulerAngles((turretPitch * DEGREES_TO_RADS),(turretYaw * DEGREES_TO_RADS),0.0f);
- if (rotationalNodeId == -1)
- rotationalNodeId = bldgShape->SetNodeRotation(appearType->rotationalNodeId,&turretRot);
-
- bldgShape->SetNodeRotation(rotationalNodeId,&turretRot);
- }
- float oldFrame = currentFrame;
- if (animate && bdFrameRate != 0.0f)
- {
- //--------------------------------------------------------
- // Make sure animation runs no faster than bdFrameRate fps.
- float frameInc = bdFrameRate * frameLength;
-
- //---------------------------------------
- // Increment Frames -- Everything else!
- if (frameInc != 0.0f)
- {
- if (!setFirstFrame) //DO NOT ANIMATE ON FIRST FRAME! Wait a bit!
- {
- if (isReversed)
- currentFrame -= frameInc;
- else
- currentFrame += frameInc;
- }
- else
- {
- setFirstFrame = false;
- }
-
- //--------------------------------------
- //Check Positive overflow of Animation
- if (currentFrame >= appearType->getNumFrames(bdAnimationState))
- {
- if (isLooping)
- currentFrame -= appearType->getNumFrames(bdAnimationState);
- else
- currentFrame = appearType->getNumFrames(bdAnimationState) - 1;
-
- canTransition = true; //Whenever we have completed one cycle or at last frame, OK to move on!
- }
-
-
- //--------------------------------------
- //Check negative overflow of gesture
- if (currentFrame < 0)
- {
- if (isLooping)
- currentFrame += appearType->getNumFrames(bdAnimationState);
- else
- currentFrame = 0.0f;
-
- canTransition = true; //Whenever we have completed one cycle or at last frame, OK to move on!
- }
- }
-
- bldgShape->SetFrameNum(currentFrame);
- }
- if (inView)
- {
- bool checkShadows = ((!beenInView) || (appearType->spinMe) || (eye->forceShadowRecalc) || (currentFrame != oldFrame));
- if (bldgShadowShape)
- bldgShape->SetUseShadow(false);
- else
- bldgShape->SetRecalcShadows(checkShadows);
-
- bldgShape->SetLightList(eye->getWorldLights(),eye->getNumLights());
- bldgShape->TransformMultiShape (&xlatPosition,&rot);
-
- if (bldgShadowShape && useShadows)
- {
- bldgShadowShape->SetRecalcShadows(checkShadows);
- bldgShadowShape->SetLightList(eye->getWorldLights(),eye->getNumLights());
- bldgShadowShape->TransformMultiShape (&xlatPosition,&rot);
- }
-
- if ((turn > 3) && useShadows)
- beenInView = true;
-
- //------------------------------------------------
- // Update GOSFX
- if (destructFX && destructFX->IsExecuted())
- {
- Stuff::LinearMatrix4D shapeOrigin;
- Stuff::LinearMatrix4D localToWorld;
- Stuff::Point3D tPosition;
-
- //Stuff::Vector3D offsetPosition;
- //offsetPosition.x = Terrain::worldUnitsPerVertex / 3.0f;
- //offsetPosition.y = -(Terrain::worldUnitsPerVertex / 3.0f);
- //offsetPosition.z = 0.0f;
- //OppRotate(offsetPosition,rotation);
- Stuff::Vector3D actualPosition = position;
- //actualPosition.Add(position,offsetPosition);
- tPosition.x = -actualPosition.x;
- tPosition.y = actualPosition.z;
- tPosition.z = actualPosition.y;
- float yaw = (180.0f + rotation) * DEGREES_TO_RADS;
- Stuff::UnitQuaternion rot;
- rot = Stuff::EulerAngles(0.0f, yaw, 0.0f);
- shapeOrigin.BuildRotation(rot);
- shapeOrigin.BuildTranslation(tPosition);
- Stuff::OBB boundingBox;
- gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,&boundingBox);
-
- bool result = destructFX->Execute(&info);
- if (!result)
- {
- destructFX->Kill();
- delete destructFX;
- destructFX = NULL;
- }
- }
-
- if (isActivitying)
- {
- Stuff::LinearMatrix4D shapeOrigin;
- Stuff::LinearMatrix4D localToWorld;
- Stuff::LinearMatrix4D localResult;
-
- if (activityNodeId == -1)
- activityNodeId = bldgShape->GetNodeNameId("activity_node");
- Stuff::Vector3D dustPos = getNodeIdPosition(activityNodeId);
- if (rotationalNodeId == -1)
- {
- if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
- rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
- else
- rotationalNodeId = -2;
- }
- if (rotationalNodeId >= 0)
- dustPos = getNodeIdPosition(rotationalNodeId);
-
- Stuff::Point3D wakePos;
- wakePos.x = -dustPos.x;
- wakePos.y = dustPos.z;
- wakePos.z = dustPos.y;
-
- shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
- shapeOrigin.BuildTranslation(wakePos);
-
- /*
- Stuff::UnitQuaternion effectRot;
- effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
- localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
- localResult.Multiply(localToWorld,shapeOrigin);
- */
-
- Stuff::OBB boundingBox;
- gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,&boundingBox);
-
- activity->Execute(&info);
-
- if (activity1)
- {
- if (activityNodeId == -1)
- activityNodeId = bldgShape->GetNodeNameId("activity_node");
- Stuff::Vector3D dustPos = getNodeIdPosition(activityNodeId);
-
- if (rotationalNodeId == -1)
- {
- if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
- rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
- else
- rotationalNodeId = -2;
- }
-
- if (rotationalNodeId >= 0)
- dustPos = getNodeIdPosition(rotationalNodeId);
-
- Stuff::Point3D wakePos;
- wakePos.x = -dustPos.x;
- wakePos.y = dustPos.z;
- wakePos.z = dustPos.y;
-
- shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
- shapeOrigin.BuildTranslation(wakePos);
-
- /*
- Stuff::UnitQuaternion effectRot;
- effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
- localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
- localResult.Multiply(localToWorld,shapeOrigin);
- */
-
- Stuff::OBB boundingBox;
- gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,&boundingBox);
-
- activity1->Execute(&info);
- }
- }
- }
-
- return TRUE;
- }
- //-----------------------------------------------------------------------------
- void BldgAppearance::startActivity (long effectId, bool loop)
- {
- //Check if we are already playing one. If not, be active!
-
- //First, check if its even loaded.
- // can easily preload this. Should we? NO. We don't know what will be passed in.
- if (!activity && useNonWeaponEffects)
- {
- if (strcmp(weaponEffects->GetEffectName(effectId),"NONE") != 0)
- {
- //--------------------------------------------
- // Yes, load it on up.
- unsigned flags = gosFX::Effect::ExecuteFlag|gosFX::Effect::LoopFlag;
- if (!loop)
- flags = gosFX::Effect::ExecuteFlag;
- Check_Object(gosFX::EffectLibrary::Instance);
- gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(effectId));
-
- if (gosEffectSpec)
- {
- activity = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
- gosASSERT(activity != NULL);
-
- Stuff::Vector3D testPos = getNodeNamePosition("activity_node1");
- if (testPos != position)
- {
- activity1 = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
- gosASSERT(activity != NULL);
- }
- MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
- }
- }
- }
-
- if (!isActivitying && activity) //Start the effect if we are not running it yet!!
- {
- Stuff::LinearMatrix4D shapeOrigin;
- Stuff::LinearMatrix4D localToWorld;
- Stuff::LinearMatrix4D localResult;
-
- if (activityNodeId == -1)
- activityNodeId = bldgShape->GetNodeNameId("activity_node");
- Stuff::Vector3D nodePos = getNodeIdPosition(activityNodeId);
- if (rotationalNodeId == -1)
- {
- if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
- rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
- else
- rotationalNodeId = -2;
- }
- if (rotationalNodeId >= 0)
- nodePos = getNodeIdPosition(rotationalNodeId);
- Stuff::Point3D wakePos;
- wakePos.x = -nodePos.x;
- wakePos.y = nodePos.z; //Wake is at Water Level!
- wakePos.z = nodePos.y;
-
- shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
- shapeOrigin.BuildTranslation(wakePos);
-
- /*
- Stuff::UnitQuaternion effectRot;
- effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
- localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
- localResult.Multiply(localToWorld,shapeOrigin);
- */
-
- gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,NULL);
- activity->Start(&info);
-
- if (activity1)
- {
- if (activityNode1Id == -1)
- activityNode1Id = bldgShape->GetNodeNameId("activity_node1");
- Stuff::Vector3D nodePos = getNodeIdPosition(activityNode1Id);
- if (rotationalNodeId == -1)
- {
- if (stricmp(appearType->rotationalNodeId,"NONE") != 0)
- rotationalNodeId = bldgShape->GetNodeNameId(appearType->rotationalNodeId);
- else
- rotationalNodeId = -2;
- }
- if (rotationalNodeId >= 0)
- nodePos = getNodeIdPosition(rotationalNodeId);
-
- Stuff::Point3D wakePos;
- wakePos.x = -nodePos.x;
- wakePos.y = nodePos.z; //Wake is at Water Level!
- wakePos.z = nodePos.y;
-
- shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
- shapeOrigin.BuildTranslation(wakePos);
-
- /*
- Stuff::UnitQuaternion effectRot;
- effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
- localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
- localResult.Multiply(localToWorld,shapeOrigin);
- */
-
- gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,NULL);
-
- activity1->Start(&info);
- }
-
- isActivitying = true;
- }
- }
- //-----------------------------------------------------------------------------
- void BldgAppearance::stopActivity (void)
- {
- if (isActivitying) //Stop the effect if we are running it!!
- {
- activity->Kill();
- if (activity1)
- activity1->Kill();
- }
-
- isActivitying = false;
- }
- //-----------------------------------------------------------------------------
- void BldgAppearance::flashBuilding (float dur, float fDuration, DWORD color)
- {
- duration = dur;
- flashDuration = fDuration;
- flashColor = color;
- drawFlash = true;
- currentFlash = flashDuration;
- }
- //-----------------------------------------------------------------------------
- void BldgAppearance::destroy (void)
- {
- if ( bldgShape )
- {
- delete bldgShape;
- bldgShape = NULL;
- }
- if (bldgShadowShape)
- {
- delete bldgShadowShape;
- bldgShadowShape = NULL;
- }
- if (destructFX)
- {
- destructFX->Kill();
- delete destructFX;
- destructFX = NULL;
- }
-
- //Turn the lights off!
- //Need to kill the light source here too!
- if (pointLight)
- {
- if (eye)
- eye->removeWorldLight(lightId,pointLight);
- free(pointLight);
- pointLight = NULL;
- }
- appearanceTypeList->removeAppearance(appearType);
- }
- #define HEIGHT_THRESHOLD 10.0f
- //-----------------------------------------------------------------------------
- long BldgAppearance::calcCellsCovered (Stuff::Vector3D& pos, short* cellList) {
- gosASSERT((Terrain::realVerticesMapSide * MAPCELL_DIM) == GameMap->width);
- long numCoords = 0;
- long maxCoords = cellList[0];
- //MUST force building to HIGHEST LOD!!! IMpassability data is only valid at this LOD!!
- // Building will reset its LOD on next draw!!
- if (currentLOD)
- {
- currentLOD = 0;
-
- bldgShape->ClearAnimation();
- delete bldgShape;
- bldgShape = NULL;
-
- bldgShape = appearType->bldgShape[currentLOD]->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(bldgShape,bdAnimationState);
- }
- //-------------------------------------------------------------
- // New way. For each vertex in each shape, translate to world
- for (long i=0;i<bldgShape->GetNumShapes();i++)
- {
- //Check if the artists meant for this piece to NOT block passability!!
- if (strnicmp(bldgShape->GetNodeId(i),"_PAB",4) != 0)
- {
- for (long j=0;j<bldgShape->GetNumVerticesInShape(i);j++)
- {
- Stuff::Vector3D vertexPos, worldPos;
- vertexPos = bldgShape->GetShapeVertexInEditor(i,j,-rotation);
- worldPos.Add(pos,vertexPos);
-
- bool recordCell = false;
- if (appearType->isForestClump)
- recordCell = (vertexPos.z <= 1.0f);
- else
- recordCell = (vertexPos.z >= 1.0f);
- if (recordCell)
- {
- long cellR, cellC;
- land->worldToCell(worldPos,cellR,cellC);
- if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR)
- || (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
- {
- //gosASSERT(false);
- continue;
- }
- // if (GameMap->inBounds(cellR, cellC)) {
- //-------------------
- // Record the cell...
- if (numCoords > (maxCoords - 2))
- Fatal(numCoords, "BldgAppearance.markMoveMap: too many coords for cellList ");
-
- cellList[numCoords++] = (short)cellR;
- cellList[numCoords++] = (short)cellC;
- // }
- }
- }
- }
- }
-
- return(numCoords);
- }
- //-----------------------------------------------------------------------------
- void BldgAppearance::markTerrain (_ScenarioMapCellInfo* pInfo, int type, int counter)
- {
- if (appearType->spinMe) //We are a marker
- return; //Do not mark impassable
-
- //MUST force building to HIGHEST LOD!!! IMpassability data is only valid at this LOD!!
- // Building will reset its LOD on next draw!!
- if (currentLOD)
- {
- currentLOD = 0;
-
- bldgShape->ClearAnimation();
- delete bldgShape;
- bldgShape = NULL;
-
- bldgShape = appearType->bldgShape[currentLOD]->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(bldgShape,bdAnimationState);
- }
- long cellR, cellC;
- land->worldToCell(position, cellR, cellC);
- if (appearType->isForestClump)
- {
- //-------------------------------------------------------------
- // New way. For each vertex in each shape, translate to world
- for (long i=0;i<bldgShape->GetNumShapes();i++)
- {
- //Check if the artists meant for this piece to NOT block passability!!
- if (strnicmp(bldgShape->GetNodeId(i),"_PAB",4) != 0)
- {
- for (long j=0;j<bldgShape->GetNumVerticesInShape(i);j++)
- {
- Stuff::Vector3D vertexPos, worldPos;
- vertexPos = bldgShape->GetShapeVertexInEditor(i,j,-rotation);
- worldPos.Add(position,vertexPos);
-
- long cellR, cellC;
- land->worldToCell(worldPos,cellR,cellC);
- if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
- (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
- {
- continue;
- }
-
- _ScenarioMapCellInfo*pTmp = &(pInfo[cellR * Terrain::realVerticesMapSide * MAPCELL_DIM + cellC]);
-
- if (vertexPos.z <= 1.0f)
- {
- pTmp->passable = true;
- pTmp->gate = false;
- pTmp->forest = true;
- //pTmp->specialType = type;
- //pTmp->specialID = counter;
- }
-
- float cellLocalHeight = vertexPos.z * metersPerWorldUnit * 0.25f;
- if (cellLocalHeight > 15.0f)
- cellLocalHeight = 15.0f;
-
- //ONLY mark LOS on cells that are impassable with forests. Maybe everything?
- if (pTmp->passable && (pTmp->lineOfSight < cellLocalHeight))
- pTmp->lineOfSight = cellLocalHeight+0.5f;
- }
- }
- }
- }
- else
- {
- if ((type == SPECIAL_GATE) || (type == SPECIAL_WALL))
- {
- if (appearType->bldgShape[0])
- {
- bldgShape->ClearAnimation();
- delete bldgShape;
- bldgShape = NULL;
-
- bldgShape = appearType->bldgShape[0]->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(bldgShape,bdAnimationState);
- }
- }
- if (type == SPECIAL_LAND_BRIDGE)
- {
- if (appearType->bldgDmgShape)
- {
- bldgShape->ClearAnimation();
- delete bldgShape;
- bldgShape = NULL;
-
- bldgShape = appearType->bldgDmgShape->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(bldgShape,bdAnimationState);
- }
- }
- //-------------------------------------------------------------
- // New way. For each vertex in each shape, translate to world
- for (long i=0;i<bldgShape->GetNumShapes();i++)
- {
- //Check if the artists meant for this piece to NOT block passability!!
- if (strnicmp(bldgShape->GetNodeId(i),"_PAB",4) != 0)
- {
- for (long j=0;j<bldgShape->GetNumVerticesInShape(i);j++)
- {
- Stuff::Vector3D vertexPos, worldPos;
- vertexPos = bldgShape->GetShapeVertexInEditor(i,j,-rotation);
- worldPos.Add(position,vertexPos);
-
- long cellR, cellC;
- land->worldToCell(worldPos,cellR,cellC);
- if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
- (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
- {
- continue;
- }
- _ScenarioMapCellInfo*pTmp = &(pInfo[cellR * Terrain::realVerticesMapSide * MAPCELL_DIM + cellC]);
-
- if (vertexPos.z >= 1.0f)
- {
- pTmp->passable = false;
-
- if (((type == SPECIAL_GATE) || (type == SPECIAL_WALL)))
- {
- pTmp->passable = true;
- pTmp->specialID = counter;
- pTmp->specialType = type;
- if (type == SPECIAL_GATE)
- pTmp->gate = true;
- }
- else if (type == SPECIAL_LAND_BRIDGE)
- {
- pTmp->passable = true;
- pTmp->specialID = counter;
- pTmp->specialType = type;
- }
- else if (type == 18)
- {
- pTmp->specialID = 0;
- pTmp->specialType = SPECIAL_NONE;
- pTmp->passable = true;
- }
- else
- {
- pTmp->specialID = 0;
- pTmp->specialType = SPECIAL_NONE;
- }
-
- if (type != 18)
- {
- float cellLocalHeight = vertexPos.z * metersPerWorldUnit * 0.25f;
- if (cellLocalHeight > 15.0f)
- cellLocalHeight = 15.0f;
-
- if (pTmp->lineOfSight < cellLocalHeight)
- pTmp->lineOfSight = cellLocalHeight+0.5f;
- }
- }
- }
- }
- }
-
- //Switch to destroyed state to mark impassable. The destroyed impassability will NEVER change!!
- // When a gate opens or a wall or gate is destroyed, we only want to mark stuff that is going
- // away passable and long range capable.
- if ((type == SPECIAL_GATE) || (type == SPECIAL_WALL))
- {
- if (appearType->bldgDmgShape)
- {
- bldgShape->ClearAnimation();
- delete bldgShape;
- bldgShape = NULL;
-
- bldgShape = appearType->bldgDmgShape->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(bldgShape,bdAnimationState);
- }
- }
- if (type == SPECIAL_LAND_BRIDGE)
- {
- if (appearType->bldgShape[0])
- {
- bldgShape->ClearAnimation();
- delete bldgShape;
- bldgShape = NULL;
-
- bldgShape = appearType->bldgShape[0]->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(bldgShape,bdAnimationState);
- }
- }
-
- //-------------------------------------------------------------
- // New way. For each vertex in each shape, translate to world
- for (i=0;i<bldgShape->GetNumShapes();i++)
- {
- //Check if the artists meant for this piece to NOT block passability!!
- if (strnicmp(bldgShape->GetNodeId(i),"_PAB",4) != 0)
- {
- for (long j=0;j<bldgShape->GetNumVerticesInShape(i);j++)
- {
- Stuff::Vector3D vertexPos, worldPos;
- vertexPos = bldgShape->GetShapeVertexInEditor(i,j,-rotation);
- worldPos.Add(position,vertexPos);
-
- long cellR, cellC;
- land->worldToCell(worldPos,cellR,cellC);
- if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
- (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
- {
- continue;
- }
- _ScenarioMapCellInfo*pTmp = &(pInfo[cellR * Terrain::realVerticesMapSide * MAPCELL_DIM + cellC]);
-
- if (vertexPos.z >= 1.0f)
- {
- if (type == 18)
- {
- pTmp->passable = true;
- pTmp->specialID = 0;
- pTmp->specialType = SPECIAL_NONE;
- }
- else
- {
- pTmp->passable = false;
- pTmp->gate = false; //Perfectly OK to mark these again, They are no longer special!!
- pTmp->specialID = 0;
- pTmp->specialType = SPECIAL_NONE;
- }
- }
- }
- }
- }
-
- if ((status != OBJECT_STATUS_DESTROYED) && appearType->bldgShape[0])
- {
- bldgShape->ClearAnimation();
- delete bldgShape;
- bldgShape = NULL;
-
- bldgShape = appearType->bldgShape[0]->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(bldgShape,bdAnimationState);
- }
- else if ((status == OBJECT_STATUS_DESTROYED) && appearType->bldgDmgShape)
- {
- bldgShape->ClearAnimation();
- delete bldgShape;
- bldgShape = NULL;
-
- bldgShape = appearType->bldgDmgShape->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(bldgShape,bdAnimationState);
- }
- }
- }
- //-----------------------------------------------------------------------------
- long BldgAppearance::markMoveMap (bool passable, long* lineOfSightRect, bool useHeight, short* cellList)
- {
- long minRow = 9999;
- long maxRow = 0;
- long minCol = 9999;
- long maxCol = 0;
- //MUST force building to HIGHEST LOD!!! IMpassability data is only valid at this LOD!!
- // Building will reset its LOD on next draw!!
- TG_MultiShapePtr tempBldgShape = bldgShape;
- if (currentLOD)
- {
- tempBldgShape = appearType->bldgShape[currentLOD]->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(tempBldgShape,bdAnimationState);
- }
- long numCoords = 0;
- if (cellList) {
- gosASSERT(!useHeight);
- //----------------------------------------------------------------------------------
- // Store the max number of coords allowed in the first cell. Can overwrite it now...
- long maxCoords = cellList[0];
- //-------------------------------------------------------------
- // New way. For each vertex in each shape, translate to world
- for (long i = 0; i < tempBldgShape->GetNumShapes(); i++)
- {
- //Check if the artists meant for this piece to NOT block passability!!
- if (strnicmp(tempBldgShape->GetNodeId(i),"_PAB",4) != 0)
- {
- for (long j=0;j<tempBldgShape->GetNumVerticesInShape(i);j++)
- {
- Stuff::Vector3D vertexPos, worldPos;
- vertexPos = tempBldgShape->GetShapeVertexInWorld(i,j,-rotation);
- worldPos.Add(position,vertexPos);
-
- long cellR, cellC;
- land->worldToCell(worldPos,cellR,cellC);
- if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
- (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
- {
- continue;
- }
-
- //----------------------------
- // Building lineOfSightRect...
- if (cellR < minRow)
- minRow = cellR;
- if (cellR > maxRow)
- maxRow = cellR;
- if (cellC < minCol)
- minCol = cellC;
- if (cellC > maxCol)
- maxCol = cellC;
-
- //-------------------
- // Record the cell...
- if (numCoords > (maxCoords - 2))
- Fatal(numCoords, "BldgAppearance.markMoveMap: too many coords for cellList ");
- cellList[numCoords++] = (short)cellR;
- cellList[numCoords++] = (short)cellC;
- }
- }
- }
- }
- else
- {
- //-------------------------------------------------------------
- // New way. For each vertex in each shape, translate to world
- for (long i=0;i<tempBldgShape->GetNumShapes();i++)
- {
- //Check if the artists meant for this piece to NOT block passability!!
- if (strnicmp(tempBldgShape->GetNodeId(i),"_PAB",4) != 0)
- {
- for (long j=0;j<tempBldgShape->GetNumVerticesInShape(i);j++)
- {
- Stuff::Vector3D vertexPos, worldPos;
- vertexPos = tempBldgShape->GetShapeVertexInWorld(i,j,-rotation);
- worldPos.Add(position,vertexPos);
-
- long cellR, cellC;
- land->worldToCell(worldPos,cellR,cellC);
- if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
- (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
- {
- continue;
- }
-
- //----------------------------
- // Building lineOfSightRect...
- if (cellR < minRow)
- minRow = cellR;
- if (cellR > maxRow)
- maxRow = cellR;
- if (cellC < minCol)
- minCol = cellC;
- if (cellC > maxCol)
- maxCol = cellC;
-
- //----------------
- // Mark the map...
- MapCellPtr curCell = GameMap->getCell(cellR, cellC);
- if (appearType->isForestClump) {
- if (vertexPos.z <= 1.0f)
- curCell->setPassable(passable);
- }
- else {
- if (vertexPos.z >= 1.0f)
- curCell->setPassable(passable);
- }
- }
- }
- }
- }
-
- if (lineOfSightRect) {
- lineOfSightRect[0] = minRow;
- lineOfSightRect[1] = minCol;
- lineOfSightRect[2] = maxRow;
- lineOfSightRect[3] = maxCol;
- }
- if (tempBldgShape != bldgShape)
- {
- tempBldgShape->ClearAnimation();
- delete tempBldgShape;
- tempBldgShape = NULL;
- }
- return(numCoords/2);
- }
- //-----------------------------------------------------------------------------
- void BldgAppearance::markLOS (bool clearIt)
- {
- //MUST force building to HIGHEST LOD!!! IMpassability data is only valid at this LOD!!
- // Building will reset its LOD on next draw!!
- TG_MultiShapePtr tempBldgShape = bldgShape;
- if (currentLOD)
- {
- tempBldgShape = appearType->bldgShape[0]->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(tempBldgShape,bdAnimationState);
- }
- //-------------------------------------------------------------
- // New way. For each vertex in each shape, translate to world
- for (long i=0;i<tempBldgShape->GetNumShapes();i++)
- {
- //Check if the artists meant for this piece to NOT block LOS!!
- // Probably should check for light cones,too!
-
- if ((strnicmp(tempBldgShape->GetNodeId(i),"LOS_",4) != 0) &&
- (strnicmp(tempBldgShape->GetNodeId(i),"SpotLight_",10) != 0))
- {
- for (long j=0;j<tempBldgShape->GetNumVerticesInShape(i);j++)
- {
- Stuff::Vector3D vertexPos, worldPos;
- vertexPos = tempBldgShape->GetShapeVertexInEditor(i,j,-rotation);
- // vertexPos = tempBldgShape->GetShapeVertexInWorld(i,j,-rotation);
- worldPos.Add(position,vertexPos);
-
- long cellR, cellC;
- land->worldToCell(worldPos,cellR,cellC);
- if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
- (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
- {
- continue;
- }
-
- //----------------
- // Mark the map...
- MapCellPtr curCell = GameMap->getCell(cellR, cellC);
- if (!clearIt)
- {
- float currentCellHeight = curCell->getLocalHeight();
-
- float cellLocalHeight = vertexPos.z * metersPerWorldUnit * 0.25f;
- if (cellLocalHeight > 15.0f)
- cellLocalHeight = 15.0f;
- if (cellLocalHeight > currentCellHeight)
- curCell->setLocalHeight(cellLocalHeight+0.5f);
- }
- else //We want to clear all LOS height INFO. We're about to change shape!!
- {
- curCell->setLocalHeight(0.0f);
- }
- }
- }
- }
- if (tempBldgShape != bldgShape)
- {
- tempBldgShape->ClearAnimation();
- delete tempBldgShape;
- tempBldgShape = NULL;
- }
- }
- //-----------------------------------------------------------------------------
- void BldgAppearance::calcAdjCell (long& row, long& col)
- {
- //MUST force building to HIGHEST LOD!!! IMpassability data is only valid at this LOD!!
- // Building will reset its LOD on next draw!!
- if (currentLOD)
- {
- currentLOD = 0;
-
- bldgShape->ClearAnimation();
- delete bldgShape;
- bldgShape = NULL;
-
- bldgShape = appearType->bldgShape[currentLOD]->CreateFrom();
- if (bdAnimationState != -1)
- appearType->setAnimation(bldgShape,bdAnimationState);
- }
- //-------------------------------------------------------------
- // New way. For each vertex in each shape, translate to world
- long numVert = 0;
- for (long i=0;i<bldgShape->GetNumShapes();i++)
- {
- for (long j=0;j<bldgShape->GetNumVerticesInShape(i);j++)
- {
- Stuff::Vector3D vertexPos, worldPos;
- vertexPos = bldgShape->GetShapeVertexInWorld(i,j,-rotation);
- worldPos.Add(position,vertexPos);
- {
- numVert++;
- long cellR, cellC;
- land->worldToCell(worldPos,cellR,cellC);
-
- //MapCellPtr curCell = GameMap->getCell(cellR, cellC);
- //curCell->setPassable(passable);
- }
- }
- }
- }
- //-----------------------------------------------------------------------------
- // class TreeAppearanceType
- void TreeAppearanceType::init (char * fileName)
- {
- AppearanceType::init(fileName);
- FullPathFileName iniName;
- iniName.init(tglPath,fileName,".ini");
- FitIniFile iniFile;
-
- long result = iniFile.open(iniName);
- if (result != NO_ERR)
- Fatal(result,"Could not find building appearance INI file");
- result = iniFile.seekBlock("TGLData");
- if (result != NO_ERR)
- Fatal(result,"Could not find block in building appearance INI file");
- result = iniFile.readIdBoolean("ForestClump",isForestClump);
- if (result != NO_ERR)
- isForestClump = false;
-
- char aseFileName[512];
- result = iniFile.readIdString("FileName",aseFileName,511);
- if (result != NO_ERR)
- {
- //Check for LOD filenames instead
- for (long i=0;i<MAX_LODS;i++)
- {
- char baseName[256];
- char baseLODDist[256];
- sprintf(baseName,"FileName%d",i);
- sprintf(baseLODDist,"Distance%d",i);
-
- result = iniFile.readIdString(baseName,aseFileName,511);
- if (result == NO_ERR)
- {
- result = iniFile.readIdFloat(baseLODDist,lodDistance[i]);
- if (result != NO_ERR)
- STOP(("LOD %d has no distance value in file %s",i,fileName));
-
- //----------------------------------------------
- // Base LOD shape. In stand Pose by default.
- treeShape[i] = new TG_TypeMultiShape;
- gosASSERT(treeShape[i] != NULL);
-
- FullPathFileName treeName;
- treeName.init(tglPath,aseFileName,".ase");
-
- treeShape[i]->LoadTGMultiShapeFromASE(treeName);
-
- //---------------------------------------------------------
- // Should only be necessary for trees. Easy to data drive
- treeShape[i]->SetAlphaTest(true);
- treeShape[i]->SetFilter(true);
- }
- else if (!i)
- {
- STOP(("No base LOD for shape %s",fileName));
- }
- }
- }
- else
- {
- //----------------------------------------------
- // Base shape. In stand Pose by default.
- treeShape[0] = new TG_TypeMultiShape;
- gosASSERT(treeShape[0] != NULL);
-
- FullPathFileName treeName;
- treeName.init(tglPath,aseFileName,".ase");
-
- treeShape[0]->LoadTGMultiShapeFromASE(treeName);
-
- //---------------------------------------------------------
- // Should only be necessary for trees. Easy to data drive
- treeShape[0]->SetAlphaTest(true);
- treeShape[0]->SetFilter(true);
- }
- result = iniFile.readIdString("ShadowName",aseFileName,511);
- if (result == NO_ERR)
- {
- //----------------------------------------------
- // Base Shadow shape.
- treeShadowShape = new TG_TypeMultiShape;
- gosASSERT(treeShadowShape != NULL);
-
- FullPathFileName treeName;
- treeName.init(tglPath,aseFileName,".ase");
-
- treeShadowShape->LoadTGMultiShapeFromASE(treeName);
-
- //---------------------------------------------------------
- // Should only be necessary for trees. Easy to data drive
- treeShadowShape->SetAlphaTest(true);
- treeShadowShape->SetFilter(true);
- }
-
- result = iniFile.seekBlock("TGLDamage");
- if (result == NO_ERR)
- {
- result = iniFile.readIdString("FileName",aseFileName,511);
- if (result != NO_ERR)
- Fatal(result,"Could not find ASE FileName in building appearance INI file");
-
- FullPathFileName dmgName;
- dmgName.init(tglPath,aseFileName,".ase");
-
- treeDmgShape = new TG_TypeMultiShape;
- gosASSERT(treeDmgShape != NULL);
- treeDmgShape->LoadTGMultiShapeFromASE(dmgName);
- if (!treeDmgShape->GetNumShapes())
- {
- delete treeDmgShape;
- treeDmgShape = NULL;
- }
-
- //Shadow for destroyed state.
- result = iniFile.readIdString("ShadowName",aseFileName,511);
- if (result == NO_ERR)
- {
- //----------------------------------------------
- // Base Shadow shape.
- treeDmgShadowShape = new TG_TypeMultiShape;
- gosASSERT(treeDmgShadowShape != NULL);
-
- FullPathFileName treeName;
- treeName.init(tglPath,aseFileName,".ase");
-
- treeDmgShadowShape->LoadTGMultiShapeFromASE(treeName);
- if (!treeDmgShadowShape->GetNumShapes())
- {
- delete treeDmgShadowShape;
- treeDmgShadowShape = NULL;
- }
- }
- }
- else
- {
- treeDmgShape = NULL;
- treeDmgShadowShape = NULL;
- }
- //No Animations at present.
- }
- //----------------------------------------------------------------------------
- void TreeAppearanceType::destroy (void)
- {
- AppearanceType::destroy();
- for (long i=0;i<MAX_LODS;i++)
- {
- if (treeShape[i])
- {
- delete treeShape[i];
- treeShape[i] = NULL;
- }
- }
- if (treeDmgShape)
- {
- delete treeDmgShape;
- treeDmgShape = NULL;
- }
-
- if (treeDmgShadowShape)
- {
- delete treeDmgShadowShape;
- treeDmgShadowShape = NULL;
- }
-
- if (treeShadowShape)
- {
- delete treeShadowShape;
- treeShadowShape = NULL;
- }
- }
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- // class TreeAppearance
- void TreeAppearance::init (AppearanceTypePtr tree, GameObjectPtr obj)
- {
- Appearance::init(tree,obj);
- appearType = (TreeAppearanceType *)tree;
- shapeMin.x = shapeMin.y = -25;
- shapeMax.x = shapeMax.y = 50;
-
- paintScheme = -1;
- objectNameId = 30862;
-
- hazeFactor = 0.0f;
- screenPos.x = screenPos.y = screenPos.z = screenPos.w = -999.0f;
- position.Zero();
- rotation = 0.0;;
- selected = 0;
- teamId = 0;
- homeTeamRelationship = 0;
- actualRotation = rotation;
- OBBRadius = -1.0f;
- currentLOD = 0;
-
- beenInView = false;
-
- fogLightSet = false;
- lightRGB = fogRGB = 0xffffffff;
- if (appearType)
- {
- treeShape = appearType->treeShape[0]->CreateFrom();
- //-------------------------------------------------
- // Load the texture and store its handle.
- for (long i=0;i<treeShape->GetNumTextures();i++)
- {
- char txmName[1024];
- treeShape->GetTextureName(i,txmName,256);
-
- char texturePath[1024];
- sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
-
- FullPathFileName textureName;
- textureName.init(texturePath,txmName,"");
-
- if (fileExists(textureName))
- {
- if (strnicmp(txmName,"a_",2) == 0)
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- treeShape->SetTextureHandle(i,gosTextureHandle);
- treeShape->SetTextureAlpha(i,true);
- }
- else
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- treeShape->SetTextureHandle(i,gosTextureHandle);
- treeShape->SetTextureAlpha(i,false);
- }
- }
- else
- {
- //PAUSE(("Warning: %s texture name not found",textureName));
- treeShape->SetTextureHandle(i,0xffffffff);
- }
- }
-
- if (appearType->treeShadowShape)
- {
- treeShadowShape = appearType->treeShadowShape->CreateFrom();
-
- //-------------------------------------------------
- // Load the texture and store its handle.
- for (long i=0;i<treeShadowShape->GetNumTextures();i++)
- {
- char txmName[1024];
- treeShadowShape->GetTextureName(i,txmName,256);
-
- char texturePath[1024];
- sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
-
- FullPathFileName textureName;
- textureName.init(texturePath,txmName,"");
-
- if (fileExists(textureName))
- {
- if (strnicmp(txmName,"a_",2) == 0)
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- treeShadowShape->SetTextureHandle(i,gosTextureHandle);
- treeShadowShape->SetTextureAlpha(i,true);
- }
- else
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- treeShadowShape->SetTextureHandle(i,gosTextureHandle);
- treeShadowShape->SetTextureAlpha(i,false);
- }
- }
- else
- {
- treeShadowShape->SetTextureHandle(i,0xffffffff);
- }
- }
- }
- else
- {
- treeShadowShape = NULL;
- }
-
- Stuff::Vector3D boxCoords[8];
- Stuff::Vector3D nodeCenter = treeShape->GetRootNodeCenter();
- boxCoords[0].x = position.x + treeShape->GetMinBox().x + nodeCenter.x;
- boxCoords[0].y = position.y + treeShape->GetMinBox().z + nodeCenter.z;
- boxCoords[0].z = position.z + treeShape->GetMaxBox().y + nodeCenter.y;
-
- boxCoords[1].x = position.x + treeShape->GetMinBox().x + nodeCenter.x;
- boxCoords[1].y = position.y + treeShape->GetMaxBox().z + nodeCenter.z;
- boxCoords[1].z = position.z + treeShape->GetMaxBox().y + nodeCenter.y;
-
- boxCoords[2].x = position.x + treeShape->GetMaxBox().x + nodeCenter.x;
- boxCoords[2].y = position.y + treeShape->GetMaxBox().z + nodeCenter.z;
- boxCoords[2].z = position.z + treeShape->GetMaxBox().y + nodeCenter.y;
-
- boxCoords[3].x = position.x + treeShape->GetMaxBox().x + nodeCenter.x;
- boxCoords[3].y = position.y + treeShape->GetMinBox().z + nodeCenter.z;
- boxCoords[3].z = position.z + treeShape->GetMaxBox().y + nodeCenter.y;
-
- boxCoords[4].x = position.x + treeShape->GetMinBox().x + nodeCenter.x;
- boxCoords[4].y = position.y + treeShape->GetMinBox().z + nodeCenter.z;
- boxCoords[4].z = position.z + treeShape->GetMinBox().y + nodeCenter.y;
-
- boxCoords[5].x = position.x + treeShape->GetMaxBox().x + nodeCenter.x;
- boxCoords[5].y = position.y + treeShape->GetMinBox().z + nodeCenter.z;
- boxCoords[5].z = position.z + treeShape->GetMinBox().y + nodeCenter.y;
-
- boxCoords[6].x = position.x + treeShape->GetMaxBox().x + nodeCenter.x;
- boxCoords[6].y = position.y + treeShape->GetMaxBox().z + nodeCenter.z;
- boxCoords[6].z = position.z + treeShape->GetMinBox().y + nodeCenter.y;
-
- boxCoords[7].x = position.x + treeShape->GetMinBox().x + nodeCenter.x;
- boxCoords[7].y = position.y + treeShape->GetMaxBox().z + nodeCenter.z;
- boxCoords[7].z = position.z + treeShape->GetMinBox().y + nodeCenter.y;
-
- float testRadius = 0.0;
-
- for (i=0;i<8;i++)
- {
- testRadius = boxCoords[i].GetLength();
- if (OBBRadius < testRadius)
- OBBRadius = testRadius;
- }
-
- appearType->boundsUpperLeftX = (-OBBRadius * 2.0);
- appearType->boundsUpperLeftY = (-OBBRadius * 2.0);
-
- appearType->boundsLowerRightX = (OBBRadius * 2.0);
- appearType->boundsLowerRightY = (OBBRadius);
-
- if (!appearType->getDesignerTypeBounds())
- {
- appearType->typeUpperLeft = treeShape->GetMinBox();
- appearType->typeLowerRight = treeShape->GetMaxBox();
- }
- }
-
- pitch = yaw = 0.0f;
- }
- //-----------------------------------------------------------------------------
- void TreeAppearance::setObjStatus (long oStatus)
- {
- if (status != oStatus)
- {
- if ((oStatus == OBJECT_STATUS_DESTROYED) || (oStatus == OBJECT_STATUS_DISABLED))
- {
- if (appearType->treeDmgShape)
- {
- if (treeShape)
- {
- treeShape->ClearAnimation();
- delete treeShape;
- treeShape = NULL;
- }
-
- treeShape = appearType->treeDmgShape->CreateFrom();
- beenInView = false;
- }
-
- if (appearType->treeDmgShadowShape)
- {
- if (treeShadowShape)
- {
- treeShadowShape->ClearAnimation();
- delete treeShadowShape;
- treeShadowShape = NULL;
- }
-
- treeShadowShape = appearType->treeDmgShadowShape->CreateFrom();
-
- beenInView = false;
- }
- }
-
- if (oStatus == OBJECT_STATUS_NORMAL)
- {
- if (appearType->treeShape)
- {
- if (treeShape)
- {
- treeShape->ClearAnimation();
- delete treeShape;
- treeShape = NULL;
- }
-
- treeShape = appearType->treeShape[0]->CreateFrom();
- beenInView = false;
- }
-
- if (appearType->treeShadowShape)
- {
- if (treeShadowShape)
- {
- treeShadowShape->ClearAnimation();
- delete treeShadowShape;
- treeShadowShape = NULL;
- }
-
- treeShadowShape = appearType->treeShadowShape->CreateFrom();
-
- beenInView = false;
- }
- }
-
- //-------------------------------------------------
- // Load the texture and store its handle.
- if (treeShape)
- {
- for (long i=0;i<treeShape->GetNumTextures();i++)
- {
- char txmName[1024];
- treeShape->GetTextureName(i,txmName,256);
-
- char texturePath[1024];
- sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
-
- FullPathFileName textureName;
- textureName.init(texturePath,txmName,"");
-
- if (fileExists(textureName))
- {
- if (strnicmp(txmName,"a_",2) == 0)
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- treeShape->SetTextureHandle(i,gosTextureHandle);
- treeShape->SetTextureAlpha(i,true);
- }
- else
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- treeShape->SetTextureHandle(i,gosTextureHandle);
- treeShape->SetTextureAlpha(i,false);
- }
- }
- else
- {
- //PAUSE(("Warning: %s texture name not found",textureName));
- treeShape->SetTextureHandle(i,0xffffffff);
- }
- }
- }
- if (treeShadowShape)
- {
- //-------------------------------------------------
- // Load the texture and store its handle.
- for (long i=0;i<treeShadowShape->GetNumTextures();i++)
- {
- char txmName[1024];
- treeShadowShape->GetTextureName(i,txmName,256);
-
- char texturePath[1024];
- sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
-
- FullPathFileName textureName;
- textureName.init(texturePath,txmName,"");
-
- if (fileExists(textureName))
- {
- if (strnicmp(txmName,"a_",2) == 0)
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- treeShadowShape->SetTextureHandle(i,gosTextureHandle);
- treeShadowShape->SetTextureAlpha(i,true);
- }
- else
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- treeShadowShape->SetTextureHandle(i,gosTextureHandle);
- treeShadowShape->SetTextureAlpha(i,false);
- }
- }
- else
- {
- //PAUSE(("Warning: %s texture name not found",textureName));
- treeShadowShape->SetTextureHandle(i,0xffffffff);
- }
- }
- }
- }
-
- status = oStatus;
- }
- //-----------------------------------------------------------------------------
- void TreeAppearance::setObjectParameters (Stuff::Vector3D &pos, float Rot, long sel, long team, long homeRelations)
- {
- rotation = Rot;
- position = pos;
- selected = sel;
- actualRotation = Rot;
- teamId = team;
- homeTeamRelationship = homeRelations;
- }
- //-----------------------------------------------------------------------------
- void TreeAppearance::setMoverParameters (float pitchAngle, float lArmRot, float rArmRot, bool isAirborne)
- {
- pitch = pitchAngle;
- }
-
- //-----------------------------------------------------------------------------
- bool TreeAppearance::isMouseOver (float px, float py)
- {
- if (inView)
- {
- if ((px <= lowerRight.x) && (py <= lowerRight.y) &&
- (px >= upperLeft.x) &&
- (py >= upperLeft.y))
- {
- return inView;
- }
- else
- {
- return FALSE;
- }
- }
-
- return(inView);
- }
- //-----------------------------------------------------------------------------
- bool TreeAppearance::recalcBounds (void)
- {
- Stuff::Vector4D tempPos;
- inView = false;
-
- float distanceToEye = 0.0f;
- if (eye)
- {
- //-------------------------------------------------------------------
- //NEW METHOD from the WAY BACK Days
- inView = true;
- if (eye->usePerspective)
- {
- Stuff::Vector3D cameraPos;
- cameraPos.x = -eye->getCameraOrigin().x;
- cameraPos.y = eye->getCameraOrigin().z;
- cameraPos.z = eye->getCameraOrigin().y;
- float vClipConstant = eye->verticalSphereClipConstant;
- float hClipConstant = eye->horizontalSphereClipConstant;
-
- Stuff::Vector3D objectCenter;
- objectCenter.Subtract(position,cameraPos);
- Camera::cameraFrame.trans_to_frame(objectCenter);
- distanceToEye = objectCenter.GetApproximateLength();
- float clip_distance = fabs(1.0f / objectCenter.y);
-
- //Is vertex on Screen OR close enough to screen that its triangle MAY be visible?
- // WE have removed the atans here by simply taking the tan of the angle we want above.
- float object_angle = fabs(objectCenter.z) * clip_distance;
- float extent_angle = treeShape->GetExtentRadius() / distanceToEye;
- if (object_angle > (vClipConstant + extent_angle))
- {
- //In theory, we would return here. Object is NOT on screen.
- inView = false;
- }
- else
- {
- object_angle = fabs(objectCenter.x) * clip_distance;
- if (object_angle > (hClipConstant + extent_angle))
- {
- //In theory, we would return here. Object is NOT on screen.
- inView = false;
- }
- }
- }
-
- //Can we be seen at all?
- // If yes, check if we are behind fog plane.
- if (inView)
- {
- //ALWAYS need to do this or select is YAYA
- // But now inView is correct.
- eye->projectZ(position,screenPos);
-
- if (eye->usePerspective)
- {
- if (distanceToEye > Camera::MaxClipDistance)
- {
- hazeFactor = 1.0f;
- inView = false;
- }
- else if (distanceToEye > Camera::MinHazeDistance)
- {
- Camera::HazeFactor = (distanceToEye - Camera::MinHazeDistance) * Camera::DistanceFactor;
- inView = true;
- }
- else
- {
- Camera::HazeFactor = 0.0f;
- inView = true;
- }
-
- }
- else
- {
- Camera::HazeFactor = 0.0f;
- inView = true;
- }
- }
-
- //If we were not behind fog plane, do a bunch O math we need later!!
- if (inView)
- {
- //We are on screen. Figure out selection box.
- Stuff::Vector3D boxCoords[8];
- Stuff::Vector4D bcsp[8];
- Stuff::Vector3D minBox;
- minBox.x = -appearType->typeUpperLeft.x;
- minBox.y = appearType->typeUpperLeft.z;
- minBox.z = appearType->typeUpperLeft.y;
- Stuff::Vector3D maxBox;
- maxBox.x = -appearType->typeLowerRight.x;
- maxBox.y = appearType->typeLowerRight.z;
- maxBox.z = appearType->typeLowerRight.y;
- if (rotation != 0.0f)
- Rotate(minBox,-rotation);
- if (rotation != 0.0f)
- Rotate(maxBox,-rotation);
- boxCoords[0].x = position.x + minBox.x;
- boxCoords[0].y = position.y + minBox.y;
- boxCoords[0].z = position.z + minBox.z;
- boxCoords[1].x = position.x + minBox.x;
- boxCoords[1].y = position.y + maxBox.y;
- boxCoords[1].z = position.z + minBox.z;
- boxCoords[2].x = position.x + maxBox.x;
- boxCoords[2].y = position.y + minBox.y;
- boxCoords[2].z = position.z + minBox.z;
- boxCoords[3].x = position.x + maxBox.x;
- boxCoords[3].y = position.y + maxBox.y;
- boxCoords[3].z = position.z + minBox.z;
- boxCoords[4].x = position.x + maxBox.x;
- boxCoords[4].y = position.y + maxBox.y;
- boxCoords[4].z = position.z + maxBox.z;
- boxCoords[5].x = position.x + maxBox.x;
- boxCoords[5].y = position.y + minBox.y;
- boxCoords[5].z = position.z + maxBox.z;
- boxCoords[6].x = position.x + minBox.x;
- boxCoords[6].y = position.y + maxBox.y;
- boxCoords[6].z = position.z + maxBox.z;
- boxCoords[7].x = position.x + minBox.x;
- boxCoords[7].y = position.y + minBox.y;
- boxCoords[7].z = position.z + maxBox.z;
- float maxX = 0.0f, maxY = 0.0f;
- float minX = 0.0f, minY = 0.0f;
- for (long i=0;i<8;i++)
- {
- eye->projectZ(boxCoords[i],bcsp[i]);
- if (!i)
- {
- maxX = minX = bcsp[i].x;
- maxY = minY = bcsp[i].y;
- }
-
- if (i)
- {
- if (bcsp[i].x > maxX)
- maxX = bcsp[i].x;
-
- if (bcsp[i].x < minX)
- minX = bcsp[i].x;
-
- if (bcsp[i].y > maxY)
- maxY = bcsp[i].y;
-
- if (bcsp[i].y < minY)
- minY = bcsp[i].y;
- }
- }
-
- upperLeft.x = minX;
- upperLeft.y = minY;
- lowerRight.x = maxX;
- lowerRight.y = maxY;
-
- if ((lowerRight.x >= 0) && (lowerRight.y >= 0) &&
- (upperLeft.x <= eye->getScreenResX()) &&
- (upperLeft.y <= eye->getScreenResY()))
- {
- inView = true;
-
- if ((status != OBJECT_STATUS_DESTROYED) && (status != OBJECT_STATUS_DISABLED))
- {
- //-------------------------------------------------------------------------------
- //Set LOD of Model here because we have the distance and we KNOW we can see it!
- bool baseLOD = true;
- DWORD selectLOD = 0;
- if (useHighObjectDetail)
- {
- for (long i=1;i<MAX_LODS;i++)
- {
- if (appearType->treeShape[i] && (distanceToEye > appearType->lodDistance[i]))
- {
- baseLOD = false;
- selectLOD = i;
- }
- }
- }
- else //We always want to use the lowest LOD!!
- {
- if (appearType->treeShape[1])
- {
- baseLOD = false;
- selectLOD = 1;
- }
- }
-
- // we are at this LOD level.
- if (selectLOD != currentLOD)
- {
- currentLOD = selectLOD;
- treeShape->ClearAnimation();
- delete treeShape;
- treeShape = NULL;
- treeShape = appearType->treeShape[currentLOD]->CreateFrom();
- //-------------------------------------------------
- // Load the texture and store its handle.
- for (long j=0;j<treeShape->GetNumTextures();j++)
- {
- char txmName[1024];
- treeShape->GetTextureName(j,txmName,256);
- char texturePath[1024];
- sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
- FullPathFileName textureName;
- textureName.init(texturePath,txmName,"");
- if (fileExists(textureName))
- {
- if (strnicmp(txmName,"a_",2) == 0)
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- treeShape->SetTextureHandle(j,gosTextureHandle);
- treeShape->SetTextureAlpha(j,true);
- }
- else
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- treeShape->SetTextureHandle(j,gosTextureHandle);
- treeShape->SetTextureAlpha(j,false);
- }
- }
- else
- {
- //PAUSE(("Warning: %s texture name not found",textureName));
- treeShape->SetTextureHandle(j,0xffffffff);
- }
- }
- }
-
- //ONLY change if we need
- if (currentLOD && baseLOD)
- {
- // we are at the Base LOD level.
- currentLOD = 0;
-
- treeShape->ClearAnimation();
- delete treeShape;
- treeShape = NULL;
-
- treeShape = appearType->treeShape[currentLOD]->CreateFrom();
-
- //-------------------------------------------------
- // Load the texture and store its handle.
- for (long i=0;i<treeShape->GetNumTextures();i++)
- {
- char txmName[1024];
- treeShape->GetTextureName(i,txmName,256);
-
- char texturePath[1024];
- sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
-
- FullPathFileName textureName;
- textureName.init(texturePath,txmName,"");
-
- if (fileExists(textureName))
- {
- if (strnicmp(txmName,"a_",2) == 0)
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- treeShape->SetTextureHandle(i,gosTextureHandle);
- treeShape->SetTextureAlpha(i,true);
- }
- else
- {
- DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
- gosASSERT(gosTextureHandle != 0xffffffff);
- treeShape->SetTextureHandle(i,gosTextureHandle);
- treeShape->SetTextureAlpha(i,false);
- }
- }
- else
- {
- //PAUSE(("Warning: %s texture name not found",textureName));
- treeShape->SetTextureHandle(i,0xffffffff);
- }
- }
- }
- }
- }
- else
- {
- inView = false; //Did alot of extra work checking this, but WHY draw and insult to injury?
- }
- }
- }
-
- return(inView);
- }
- //-----------------------------------------------------------------------------
- long TreeAppearance::render (long depthFixup)
- {
- if (inView)
- {
- long color = SD_BLUE;
- //unsigned long highLight = 0x007f7f7f;
- if ((teamId > -1) && (teamId < 8)) {
- //static unsigned long highLightTable[3] = {0x00007f00, 0x0000007f, 0x007f0000};
- static long colorTable[3] = {SB_GREEN | 0xff000000, SB_BLUE | 0xff000000, SB_RED | 0xff000000};
- color = colorTable[homeTeamRelationship];
- //highLight = highLightTable[homeTeamRelationship];
- }
- //---------------------------------------------
- // Call Multi-shape render stuff here.
- treeShape->Render();
- if (selected & DRAW_BARS)
- {
- drawBars();
- }
- if ( selected & DRAW_BRACKETS )
- {
- drawSelectBrackets(color);
- }
- if ( selected & DRAW_TEXT )
- {
- if (objectNameId != -1)
- {
- char tmpString[255];
- cLoadString(objectNameId, tmpString, 254);
- drawTextHelp(tmpString, color);
- }
- }
- // I don't want my selection reset each time I draw HKG
- // selected = FALSE;
- //---------------------------------------------------------
- // Render the Bounding Box to see if it is OK.
- #ifdef DRAW_BOX
- Stuff::Vector3D nodeCenter = treeShape->GetRootNodeCenter();
- boxCoords[0].x = position.x + treeShape->minBox.x + nodeCenter.x;
- boxCoords[0].y = position.y + treeShape->minBox.z + nodeCenter.z;
- boxCoords[0].z = position.z + treeShape->maxBox.y + nodeCenter.y;
-
- boxCoords[1].x = position.x + treeShape->minBox.x + nodeCenter.x;
- boxCoords[1].y = position.y + treeShape->maxBox.z + nodeCenter.z;
- boxCoords[1].z = position.z + treeShape->maxBox.y + nodeCenter.y;
-
- boxCoords[2].x = position.x + treeShape->maxBox.x + nodeCenter.x;
- boxCoords[2].y = position.y + treeShape->maxBox.z + nodeCenter.z;
- boxCoords[2].z = position.z + treeShape->maxBox.y + nodeCenter.y;
-
- boxCoords[3].x = position.x + treeShape->maxBox.x + nodeCenter.x;
- boxCoords[3].y = position.y + treeShape->minBox.z + nodeCenter.z;
- boxCoords[3].z = position.z + treeShape->maxBox.y + nodeCenter.y;
-
- boxCoords[4].x = position.x + treeShape->minBox.x + nodeCenter.x;
- boxCoords[4].y = position.y + treeShape->minBox.z + nodeCenter.z;
- boxCoords[4].z = position.z + treeShape->minBox.y + nodeCenter.y;
-
- boxCoords[5].x = position.x + treeShape->maxBox.x + nodeCenter.x;
- boxCoords[5].y = position.y + treeShape->minBox.z + nodeCenter.z;
- boxCoords[5].z = position.z + treeShape->minBox.y + nodeCenter.y;
-
- boxCoords[6].x = position.x + treeShape->maxBox.x + nodeCenter.x;
- boxCoords[6].y = position.y + treeShape->maxBox.z + nodeCenter.z;
- boxCoords[6].z = position.z + treeShape->minBox.y + nodeCenter.y;
-
- boxCoords[7].x = position.x + treeShape->minBox.x + nodeCenter.x;
- boxCoords[7].y = position.y + treeShape->maxBox.z + nodeCenter.z;
- boxCoords[7].z = position.z + treeShape->minBox.y + nodeCenter.y;
-
- Stuff::Vector4D screenPos[8];
- for (long i=0;i<8;i++)
- {
- eye->projectZ(boxCoords[i],screenPos[i]);
- }
-
- {
- LineElement newElement(screenPos[0],screenPos[1],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[0],screenPos[4],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[0],screenPos[3],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[5],screenPos[4],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[5],screenPos[6],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[5],screenPos[3],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[2],screenPos[3],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[2],screenPos[6],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[2],screenPos[1],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[7],screenPos[1],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[7],screenPos[6],XP_WHITE,NULL,-1);
- newElement.draw();
- }
-
- {
- LineElement newElement(screenPos[7],screenPos[4],XP_WHITE,NULL,-1);
- newElement.draw();
- }
- #endif
- }
- return NO_ERR;
- }
- //-----------------------------------------------------------------------------
- long TreeAppearance::renderShadows (void)
- {
- if (inView && visible)
- {
- //---------------------------------------------
- // Call Multi-shape render stuff here.
- if (treeShadowShape)
- treeShadowShape->RenderShadows();
- else
- treeShape->RenderShadows();
- }
-
- return NO_ERR;
- }
- //-----------------------------------------------------------------------------
- long TreeAppearance::update (bool animate)
- {
- if (rotation > 180)
- rotation -= 360;
- if (rotation < -180)
- rotation += 360;
- //-------------------------------------------
- // Does math necessary to draw Tree
- Stuff::UnitQuaternion rot;
- float yawAngle = (rotation * DEGREES_TO_RADS) + (yaw * DEGREES_TO_RADS);
- float pitchAngle = (pitch * DEGREES_TO_RADS);
- rot = Stuff::EulerAngles(pitchAngle, yawAngle, 0.0f);
- Stuff::Point3D xlatPosition;
- xlatPosition.x = -position.x;
- xlatPosition.y = position.z;
- xlatPosition.z = position.y;
- if (!fogLightSet)
- {
- unsigned char lightr,lightg,lightb;
- float lightIntensity = 1.0f;
- if (land)
- lightIntensity = land->getTerrainLight(position);
- lightr = eye->getLightRed(lightIntensity);
- lightg = eye->getLightGreen(lightIntensity);
- lightb = eye->getLightBlue(lightIntensity);
- lightRGB = (lightr<<16) + (lightg<<8) + lightb;
- fogRGB = 0xff<<24;
- float fogStart = eye->fogStart;
- float fogFull = eye->fogFull;
- if (xlatPosition.y < fogStart)
- {
- float fogFactor = fogStart - xlatPosition.y;
- if (fogFactor < 0.0)
- fogRGB = 0xff<<24;
- else
- {
- fogFactor /= (fogStart - fogFull);
- if (fogFactor <= 1.0)
- {
- fogFactor *= fogFactor;
- fogFactor = 1.0 - fogFactor;
- fogFactor *= 256.0;
- }
- else
- {
- fogFactor = 256.0;
- }
- unsigned char fogResult = float2long(fogFactor);
- fogRGB = fogResult << 24;
- }
- }
- else
- {
- fogRGB = 0xff<<24;
- }
- fogLightSet = true;
- }
- if (useFog)
- treeShape->SetFogRGB(fogRGB);
- else
- treeShape->SetFogRGB(0xffffffff);
- DWORD oldRGB = eye->getLightColor(1);
- eye->setLightColor(1,lightRGB);
- eye->setLightIntensity(1,1.0);
- if (forceLightsOut)
- treeShape->SetLightsOut(true);
- if (inView)
- {
- bool checkShadows = ((!beenInView) || (eye->forceShadowRecalc));
-
- if (treeShadowShape)
- treeShape->SetUseShadow(false);
- else
- treeShape->SetRecalcShadows(checkShadows);
-
- TG_LightPtr light = eye->getWorldLight(0);
- light->active = false;
- treeShape->SetLightList(eye->getWorldLights(),eye->getNumLights());
- treeShape->TransformMultiShape (&xlatPosition,&rot);
-
- light->active = true;
- if (treeShadowShape && useShadows)
- {
- treeShadowShape->SetRecalcShadows(checkShadows);
- treeShadowShape->SetLightList(eye->getWorldLights(),eye->getNumLights());
- treeShadowShape->TransformMultiShape (&xlatPosition,&rot);
- }
-
- if ((turn > 3) && useShadows)
- beenInView = true;
- }
-
- //Set Ambient back to normal color.
- eye->setLightColor(1,oldRGB);
- return TRUE;
- }
- //-----------------------------------------------------------------------------
- void TreeAppearance::markTerrain (_ScenarioMapCellInfo* pInfo, int type, int counter)
- {
- //MUST force tree to HIGHEST LOD!!! Impassability data is only valid at this LOD!!
- // Tree will reset its LOD on next draw!!
- if (currentLOD)
- {
- currentLOD = 0;
-
- treeShape->ClearAnimation();
- delete treeShape;
- treeShape = NULL;
-
- treeShape = appearType->treeShape[currentLOD]->CreateFrom();
- }
- //-------------------------------------------------------------
- // New way. For each vertex in each shape, translate to world
- for (long i=0;i<treeShape->GetNumShapes();i++)
- {
- //Check if the artists meant for this piece to NOT block passability!!
- if (strnicmp(treeShape->GetNodeId(i),"_PAB",4) != 0)
- {
- for (long j=0;j<treeShape->GetNumVerticesInShape(i);j++)
- {
- Stuff::Vector3D vertexPos, worldPos;
- vertexPos = treeShape->GetShapeVertexInEditor(i,j,-rotation);
- worldPos.Add(position,vertexPos);
-
- long cellR, cellC;
- land->worldToCell(worldPos,cellR,cellC);
- if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
- (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
- {
- continue;
- }
- _ScenarioMapCellInfo*pTmp = &(pInfo[cellR * Terrain::realVerticesMapSide * MAPCELL_DIM + cellC]);
- if (vertexPos.z >= 1.0f)
- {
- pTmp->forest = true;
-
- float cellLocalHeight = vertexPos.z * metersPerWorldUnit * 0.25f;
- if (cellLocalHeight > 15.0f)
- cellLocalHeight = 15.0f;
-
- if (pTmp->lineOfSight < cellLocalHeight)
- pTmp->lineOfSight = cellLocalHeight+0.5f;
- }
- }
- }
- }
- }
- //-----------------------------------------------------------------------------
- void TreeAppearance::markLOS (bool clearIt)
- {
- //MUST force building to HIGHEST LOD!!! IMpassability data is only valid at this LOD!!
- // Building will reset its LOD on next draw!!
- if (currentLOD)
- {
- currentLOD = 0;
-
- treeShape->ClearAnimation();
- delete treeShape;
- treeShape = NULL;
-
- treeShape = appearType->treeShape[currentLOD]->CreateFrom();
- }
- //-------------------------------------------------------------
- // New way. For each vertex in each shape, translate to world
- for (long i=0;i<treeShape->GetNumShapes();i++)
- {
- //Check if the artists meant for this piece to NOT block LOS!!
- // Probably should check for light cones,too!
-
- if ((strnicmp(treeShape->GetNodeId(i),"LOS_",4) != 0) &&
- (strnicmp(treeShape->GetNodeId(i),"SpotLight_",10) != 0))
- {
- for (long j=0;j<treeShape->GetNumVerticesInShape(i);j++)
- {
- Stuff::Vector3D vertexPos, worldPos;
- vertexPos = treeShape->GetShapeVertexInEditor(i,j,-rotation);
- // vertexPos = treeShape->GetShapeVertexInWorld(i,j,-rotation);
- worldPos.Add(position,vertexPos);
-
- long cellR, cellC;
- land->worldToCell(worldPos,cellR,cellC);
- if ((0 > cellR) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellR) ||
- (0 > cellC) || (Terrain::realVerticesMapSide * MAPCELL_DIM <= cellC))
- {
- continue;
- }
-
- //----------------
- // Mark the map...
- MapCellPtr curCell = GameMap->getCell(cellR, cellC);
- float currentCellHeight = curCell->getLocalHeight();
-
- float cellLocalHeight = vertexPos.z * metersPerWorldUnit * 0.25f;
- if (cellLocalHeight > 15.0f)
- cellLocalHeight = 15.0f;
-
- if (!clearIt)
- {
- if (cellLocalHeight > currentCellHeight)
- curCell->setLocalHeight(cellLocalHeight+0.5f);
- }
- else //We want to clear all LOS height INFO. We're about to change shape!!
- {
- curCell->setLocalHeight(0.0f);
- }
- }
- }
- }
- }
- //-----------------------------------------------------------------------------
- void TreeAppearance::destroy (void)
- {
- if ( treeShape )
- {
- delete treeShape;
- treeShape = NULL;
- }
- appearanceTypeList->removeAppearance(appearType);
- }
- //*****************************************************************************
|