MechIcon.cpp 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649
  1. #define MECHICON_CPP
  2. /*************************************************************************************************\
  3. MechIcon.cpp : Implementation of the MechIcon component.
  4. //---------------------------------------------------------------------------//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "MechIcon.h"
  9. #include "Mover.h"
  10. #include "Utilities.h"
  11. #include "Mech.h"
  12. #include "gvehicl.h"
  13. #include "GameCam.h"
  14. #include "controlgui.h"
  15. #include "gamesound.h"
  16. #include <windows.h>
  17. #ifndef MISSION_H
  18. #include "mission.h"
  19. #endif
  20. #ifndef MULTPLYR_H
  21. #include "multplyr.h"
  22. #endif
  23. TGAFileHeader *MechIcon::s_MechTextures = NULL;
  24. TGAFileHeader *VehicleIcon::s_VehicleTextures = NULL;
  25. TGAFileHeader* ForceGroupIcon::s_textureMemory = 0;
  26. StaticInfo* ForceGroupIcon::jumpJetIcon = NULL;
  27. MC2MoviePtr ForceGroupIcon::bMovie = NULL;
  28. unsigned long ForceGroupIcon::pilotVideoTexture = 0;
  29. MechWarrior* ForceGroupIcon::pilotVideoPilot = NULL;
  30. #define HEALTH_BAROFFSET 12.0f * Environment.screenHeight/600.f
  31. #define HEALTH_BARLENGTH 31.0f * Environment.screenWidth/600.f
  32. #define HEALTH_BARHEIGHT 2.0f * Environment.screenHeight/600.f
  33. #define TEXT_HEIGHT 8.0f * Environment.screenHeight/480.f
  34. float MechIcon::unitIconX = 32;
  35. float MechIcon::unitIconY = 38;
  36. float PilotIcon::pilotIconX = 25;
  37. float PilotIcon::pilotIconY = 36;
  38. const long PilotIcon::DEAD_PILOT_INDEX = 27;
  39. unsigned long PilotIcon::s_pilotTextureHandle = 0;
  40. unsigned long PilotIcon::s_pilotTextureWidth = 0;
  41. long ForceGroupIcon::pilotTextTop[17] = {0};
  42. long MechIcon::damageColors[4][3] =
  43. { 194 << 16 | 229 << 8 | 255 | 0xff << 24, 92 << 16 | 150 << 8 | 194 | 0xff << 24, 0 << 16 | 83 << 8 | 146 | 0xff << 24,
  44. 248 << 16 | 241 << 8 | 193 | 0xff << 24, 248 << 16 | 206 << 8 | 31 | 0xff << 24, 139 << 16 | 114 << 8 | 0 | 0xff << 24,
  45. 248 << 16 | 193 << 8 | 193 | 0xff << 24, 248 << 16 | 31 << 8 | 31 | 0xff << 24, 139 << 16 | 0 << 8 | 0 | 0xff << 24,
  46. 94 << 16 | 101 << 8 | 101 | 0xff << 24, 56 << 16 | 64 << 8 | 64 | 0xff << 24, 26 << 16 | 33 << 8 | 33 | 0xff << 24
  47. };
  48. long MechIcon::ForceGroupColors[11] = {
  49. 0xff005392,
  50. 0xffC66600,
  51. 0xff6E7C00,
  52. 0xffB70000,
  53. 0xff620053,
  54. 0xffD8AD00,
  55. 0xff8B00BE,
  56. 0xffFF0000,
  57. 0xffFF8A00,
  58. 0xff0091FF,
  59. 0xff505050
  60. };
  61. ForceGroupIcon::AnimationInfo ForceGroupIcon::animationInfos[NUM_DEATH_INFOS] =
  62. {
  63. 0.f, 0,
  64. 2.5f, 0,
  65. 5.0f, 0x7fff0000,
  66. 5.35f, 0x7fff0000,
  67. 6.0f, 0xff000000,
  68. 6.5f, 0xff000000
  69. };
  70. unsigned long ForceGroupIcon::s_textureHandle[5] = { -1, -1, -1, -1, -1 };
  71. bool ForceGroupIcon::s_slotUsed[240] = { 0 };
  72. gos_VERTEX ForceGroupIcon:: bmpLocation[17][5] = {0}; // in screen coords
  73. GUI_RECT ForceGroupIcon:: textArea[17] = {0};
  74. GUI_RECT ForceGroupIcon:: pilotRect[17] = {0};
  75. GUI_RECT ForceGroupIcon:: selectionRect[17] = {0};
  76. GUI_RECT ForceGroupIcon:: healthBar[17] = {0};
  77. float ForceGroupIcon:: pilotLocation[17][4] = {0};
  78. aFont* ForceGroupIcon::gosFontHandle = 0;
  79. int ForceGroupIcon::curScreenWidth = 800;
  80. #define ICON_REALSIZE 256
  81. ForceGroupIcon::ForceGroupIcon( )
  82. {
  83. unit = NULL;
  84. bDrawBack = 0;
  85. backDamageIndex = -1;
  86. damageIconIndex = 0;
  87. locationIndex = 0;
  88. if ( s_textureHandle[0] == -1 )
  89. {
  90. // this is the textures that all icons are using
  91. long size = ( 256 * 256 * sizeof( long ) + sizeof( TGAFileHeader ) );
  92. s_textureMemory = (TGAFileHeader*)new char[size];
  93. memset( s_textureMemory, 0, size );
  94. s_textureMemory->height = 256;
  95. s_textureMemory->width = 256;
  96. s_textureMemory->pixel_depth = 32;
  97. s_textureMemory->image_type = UNC_PAL;
  98. if ( s_textureHandle[0] == -1 )
  99. s_textureHandle[0] = gos_NewTextureFromMemory( gos_Texture_Alpha, ".tga", (unsigned char*)s_textureMemory, size, 0 );
  100. memset( s_slotUsed, 0, 240 * sizeof( bool ) );
  101. }
  102. bool bFound = 0;
  103. for ( int index = 0; index < 240; index++ )
  104. {
  105. if ( !s_slotUsed[ index ] )
  106. {
  107. damageIconIndex = index;
  108. s_slotUsed[index] = 1;
  109. bFound = 1;
  110. break;
  111. }
  112. }
  113. Assert( bFound, bFound, "out of space for icon textures" );
  114. deathAnimationTime = 0.0;
  115. msgPlayTime = 0.0f;
  116. }
  117. void ForceGroupIcon::resetResolution(bool bForce)
  118. {
  119. if ( curScreenWidth != Environment.screenWidth || bForce )
  120. {
  121. delete [] MechIcon::s_MechTextures;
  122. MechIcon::s_MechTextures = 0;
  123. delete [] VehicleIcon::s_VehicleTextures;
  124. VehicleIcon::s_VehicleTextures = 0;
  125. setIconVariables();
  126. PilotIcon::swapResolutions();
  127. }
  128. curScreenWidth = Environment.screenWidth;
  129. }
  130. void ForceGroupIcon::swapResolutions( bool bForce )
  131. {
  132. resetResolution(bForce);
  133. init( unit );
  134. }
  135. ForceGroupIcon::~ForceGroupIcon()
  136. {
  137. if (pilotVideoPilot && pilotVideoPilot == unit->getPilot() )
  138. {
  139. if ( bMovie )
  140. {
  141. delete bMovie;
  142. bMovie = NULL;
  143. pilotVideoTexture = 0;
  144. }
  145. pilotVideoPilot = NULL;
  146. }
  147. s_slotUsed[damageIconIndex] = 0;
  148. if ( backDamageIndex != -1 )
  149. s_slotUsed[ backDamageIndex ] = 0;
  150. }
  151. void ForceGroupIcon::init( FitIniFile& file, int which )
  152. {
  153. char buffer[256];
  154. sprintf( buffer, "MechIcon%ld", which );
  155. if ( NO_ERR != file.seekBlock( buffer ) )
  156. Assert( 0, 0, "couldn't find the icon" );
  157. if ( !gosFontHandle )
  158. gosFontHandle = new aFont();
  159. file.readIdLong( "TextAReaLeft", textArea[which].left );
  160. file.readIdLong( "TextAreaRight", textArea[which].right );
  161. file.readIdLong( "TextAReaTop", textArea[which].top );
  162. file.readIdLong( "TextAreaBottom", textArea[which].bottom );
  163. textArea[which].left += ControlGui::hiResOffsetX;
  164. textArea[which].right += ControlGui::hiResOffsetX;
  165. textArea[which].top += ControlGui::hiResOffsetY;
  166. textArea[which].bottom += ControlGui::hiResOffsetY;
  167. file.readIdLong( "PilotTextTop", pilotTextTop[which] );
  168. pilotTextTop[which] += ControlGui::hiResOffsetY;
  169. long left, right, top, bottom;
  170. file.readIdLong( "MechIconAreaLeft", left );
  171. file.readIdLong( "MechIconArearight", right );
  172. file.readIdLong( "MechIconAreaTop", top );
  173. file.readIdLong( "MechIconAreaBottom", bottom );
  174. left += ControlGui::hiResOffsetX;
  175. right += ControlGui::hiResOffsetX;
  176. top += ControlGui::hiResOffsetY;
  177. bottom += ControlGui::hiResOffsetY;
  178. for ( int i = 0; i < 4; i++ )
  179. {
  180. bmpLocation[which][i].x = left;
  181. bmpLocation[which][i].y = top;
  182. bmpLocation[which][i].argb = 0xffffffff;
  183. bmpLocation[which][i].rhw = 0.5;
  184. }
  185. bmpLocation[which][2].x = bmpLocation[which][3].x = right;
  186. bmpLocation[which][1].y = bmpLocation[which][2].y = bottom;
  187. bmpLocation[which][4] = bmpLocation[which][0];
  188. file.readIdLong( "PilotAreaLeft", left );
  189. file.readIdLong( "PilotAreaRight", right );
  190. file.readIdLong( "PilotAreaTop", top );
  191. file.readIdLong( "PilotAreaBottom", bottom );
  192. left += ControlGui::hiResOffsetX;
  193. right += ControlGui::hiResOffsetX;
  194. top += ControlGui::hiResOffsetY;
  195. bottom += ControlGui::hiResOffsetY;
  196. pilotLocation[which][0] = left;
  197. pilotLocation[which][1] = top;
  198. pilotLocation[which][2] = right;
  199. pilotLocation[which][3] = bottom;
  200. file.readIdLong( "PilotRectLeft", pilotRect[which].left );
  201. file.readIdLong( "PilotRectRight", pilotRect[which].right );
  202. file.readIdLong( "PilotRectTop", pilotRect[which].top );
  203. file.readIdLong( "PilotRectBottom", pilotRect[which].bottom );
  204. pilotRect[which].left += ControlGui::hiResOffsetX;
  205. pilotRect[which].right += ControlGui::hiResOffsetX;
  206. pilotRect[which].top += ControlGui::hiResOffsetY;
  207. pilotRect[which].bottom += ControlGui::hiResOffsetY;
  208. file.readIdLong( "SelectionRectLeft", selectionRect[which].left );
  209. file.readIdLong( "SelectionRectRight", selectionRect[which].right );
  210. file.readIdLong( "SelectionRectTop", selectionRect[which].top );
  211. file.readIdLong( "SelectionRectBottom", selectionRect[which].bottom );
  212. selectionRect[which].left += ControlGui::hiResOffsetX;
  213. selectionRect[which].right += ControlGui::hiResOffsetX;
  214. selectionRect[which].top += ControlGui::hiResOffsetY;
  215. selectionRect[which].bottom += ControlGui::hiResOffsetY;
  216. file.readIdLong( "HealthBarLeft", healthBar[which].left );
  217. file.readIdLong( "HealthBarRight", healthBar[which].right );
  218. file.readIdLong( "HealthBarTop", healthBar[which].top );
  219. file.readIdLong( "HealthBarBottom", healthBar[which].bottom );
  220. healthBar[which].left += ControlGui::hiResOffsetX;
  221. healthBar[which].right += ControlGui::hiResOffsetX;
  222. healthBar[which].top += ControlGui::hiResOffsetY;
  223. healthBar[which].bottom += ControlGui::hiResOffsetY;
  224. if ( !jumpJetIcon )
  225. jumpJetIcon = new StaticInfo;
  226. jumpJetIcon->init( file, "JumpJetIcon", 0, 0 );
  227. }
  228. void MechIcon::setDrawBack( bool bSet)
  229. {
  230. bDrawBack = bSet;
  231. bool bFound = 0;
  232. for ( int index = 0; index < 240; index++ )
  233. {
  234. if ( !s_slotUsed[ index ] )
  235. {
  236. backDamageIndex = index;
  237. s_slotUsed[index] = 1;
  238. bFound = 1;
  239. break;
  240. }
  241. }
  242. int iconsPerLine = ((int)s_textureMemory->width/(int)unitIconX);
  243. int iconsPerPage = ((int)s_textureMemory->width/(int)unitIconY);
  244. long textureIndex = 0;
  245. long row = (backDamageIndex/iconsPerLine);
  246. if ( row >= iconsPerPage )
  247. {
  248. textureIndex = row/iconsPerPage;
  249. row = row % iconsPerPage;
  250. }
  251. long column = (backDamageIndex % iconsPerLine);
  252. long offsetY = row * unitIconY;
  253. long offsetX = column * unitIconX;
  254. Assert( bFound, bFound, "out of space for icon textures" );
  255. if ( s_textureHandle[textureIndex] == -1 )
  256. {
  257. long size = ( 256 * 256 * sizeof( long ) + sizeof( TGAFileHeader ) );
  258. s_textureHandle[textureIndex] = gos_NewTextureFromMemory( gos_Texture_Alpha, ".tga", (unsigned char*)s_textureMemory, size, 0 );
  259. }
  260. // now need to make a copy of the data
  261. TEXTUREPTR textureData;
  262. gos_LockTexture( s_textureHandle[textureIndex], 0, 0, &textureData );
  263. unsigned long* pDestData, *pDestRow = textureData.pTexture + offsetY * textureData.Width + offsetX;
  264. char* pTmp = (char*)s_MechTextures + sizeof ( TGAFileHeader );
  265. unsigned long* pSrcRow = (unsigned long*)pTmp;
  266. long whichMech = unit->getIconPictureIndex();
  267. offsetY = unitIconY;
  268. offsetX = whichMech * unitIconX;
  269. long tmpOffset = ((s_MechTextures->width) * (offsetY ) + offsetX);
  270. pSrcRow += tmpOffset;
  271. unsigned long* pSrcData = pSrcRow;
  272. for( int j = 0; j < unitIconY; ++j )
  273. {
  274. pDestData = pDestRow;
  275. pSrcData = pSrcRow;
  276. for ( int i = 0; i < unitIconX; ++i ) // do four icons per row
  277. {
  278. bool bDraw = 0;
  279. // compare colors, only draw back ones which are 4, 5, 6, and 7
  280. for ( int i = 0; i < 3; i++ )
  281. {
  282. long compColor = damageColors[0][i];
  283. long srcColor = *pSrcData;
  284. long compMin = compColor >> 16;
  285. compMin += 4;
  286. long compMax = compMin + 3;
  287. if ( srcColor >> 16 >= compMin && srcColor >> 16 <= compMax )
  288. {
  289. bDraw = 1;
  290. }
  291. }
  292. if ( *pSrcData == 0xff505050 )
  293. bDraw = 1;
  294. if ( bDraw )
  295. *pDestData++ = *pSrcData;
  296. else
  297. *pDestData++ = 0;
  298. pSrcData++;
  299. }
  300. pSrcRow += s_MechTextures->width;
  301. pDestRow += textureData.Width;
  302. }
  303. gos_UnLockTexture( s_textureHandle[textureIndex] );
  304. }
  305. bool ForceGroupIcon::inRegion( int x, int y )
  306. {
  307. return ( x >= selectionRect[locationIndex].left && x <= selectionRect[locationIndex].right &&
  308. y >= selectionRect[locationIndex].top && y <= selectionRect[locationIndex].bottom );
  309. }
  310. void ForceGroupIcon::rightClick()
  311. {
  312. ((GameCamera*)eye)->setTarget( unit );
  313. }
  314. void ForceGroupIcon::click( bool shiftDn )
  315. {
  316. if ( shiftDn && !unit->isSelected() )
  317. {
  318. unit->setSelected( true );
  319. }
  320. else if ( !shiftDn )
  321. {
  322. unit->setSelected( true );
  323. }
  324. else
  325. {
  326. unit->setSelected( false );
  327. }
  328. soundSystem->playDigitalSample( LOG_SELECT );
  329. }
  330. void ForceGroupIcon::init( )
  331. {
  332. }
  333. bool MechIcon::initTextures()
  334. {
  335. if ( !s_MechTextures )
  336. {
  337. File file;
  338. char path[256];
  339. strcpy( path, artPath );
  340. if ( Environment.screenWidth == 800 )
  341. strcat( path, "mcui_med4.tga" );
  342. else if ( Environment.screenWidth == 640 )
  343. strcat( path, "mcui_low4.tga" );
  344. else
  345. strcat( path, "mcui_high7.tga" );
  346. _strlwr( path );
  347. if ( NO_ERR != file.open( path ) )
  348. {
  349. Assert( 0, 0, "Couldn't open the mech parts" );
  350. return false;
  351. }
  352. setIconVariables();
  353. int size = file.getLength();
  354. s_MechTextures = (TGAFileHeader*)new char[size];
  355. file.read( (BYTE*)s_MechTextures, size );
  356. BYTE* pTmp = (BYTE*)(s_MechTextures + 1);
  357. flipTopToBottom (pTmp, s_MechTextures->pixel_depth, s_MechTextures->width, s_MechTextures->height );
  358. }
  359. return true;
  360. }
  361. bool MechIcon::init( Mover* pMover )
  362. {
  363. ForceGroupIcon::init();
  364. if ( !pMover )
  365. return 0;
  366. long whichMech = pMover->getIconPictureIndex();
  367. bool bRetVal = init( whichMech );
  368. unit = pMover;
  369. pilotIcon.setPilot( pMover->getPilot() );
  370. return bRetVal;
  371. }
  372. bool MechIcon::init( long whichIndex )
  373. {
  374. initTextures();
  375. int pixelDepth = s_MechTextures->pixel_depth/8;
  376. if ( pixelDepth != 4 )
  377. PAUSE(("Texture for MechIcon not 32-bit"));
  378. int iconsPerLine = ((int)s_textureMemory->width/(int)unitIconX);
  379. int iconsPerPage = ((int)s_textureMemory->width/(int)unitIconY);
  380. long textureIndex = 0;
  381. long row = (damageIconIndex/iconsPerLine);
  382. if ( row >= iconsPerPage )
  383. {
  384. textureIndex = row/iconsPerPage;
  385. row = row % iconsPerPage;
  386. }
  387. long column = (damageIconIndex % iconsPerLine);
  388. long offsetY = (row) * unitIconY;
  389. long offsetX = (column) * unitIconX;
  390. if ( s_textureHandle[textureIndex] == -1 )
  391. {
  392. long size = ( 256 * 256 * sizeof( long ) + sizeof( TGAFileHeader ) );
  393. s_textureHandle[textureIndex] = gos_NewTextureFromMemory( gos_Texture_Alpha, ".tga", (unsigned char*)s_textureMemory, size, 0 );
  394. }
  395. // now need to make a copy of the data
  396. TEXTUREPTR textureData;
  397. gos_LockTexture( s_textureHandle[textureIndex], 0, 0, &textureData );
  398. unsigned long* pDestData, *pDestRow = textureData.pTexture + offsetY * textureData.Width + offsetX;
  399. char* pTmp = (char*)s_MechTextures + sizeof ( TGAFileHeader );
  400. unsigned long* pSrcRow = (unsigned long*)pTmp;
  401. offsetY = 0;
  402. offsetX = whichIndex * unitIconX;
  403. long tmpOffset = ((s_MechTextures->width) * (offsetY ) + offsetX);
  404. pSrcRow += tmpOffset;
  405. unsigned long* pSrcData = pSrcRow;
  406. for( int j = 0; j < unitIconY; ++j )
  407. {
  408. pDestData = pDestRow;
  409. pSrcData = pSrcRow;
  410. for ( int i = 0; i < unitIconX; ++i ) // do four icons per row
  411. {
  412. *pDestData++ = *pSrcData++;
  413. }
  414. pSrcRow += s_MechTextures->width;
  415. pDestRow += textureData.Width;
  416. }
  417. gos_UnLockTexture( s_textureHandle[textureIndex] );
  418. for ( int i = 0; i < 5; ++i )
  419. {
  420. bmpLocation[locationIndex][i].argb = 0xffffffff;
  421. bmpLocation[locationIndex][i].frgb = 0;
  422. bmpLocation[locationIndex][i].rhw = .5;
  423. bmpLocation[locationIndex][i].u = 0.;
  424. bmpLocation[locationIndex][i].v = 0.;
  425. bmpLocation[locationIndex][i].z = 0.;
  426. }
  427. memset( damage, 0, 8 );
  428. memset( backDamage, 0, 8 );
  429. return true;
  430. }
  431. void MechIcon::update()
  432. {
  433. // need to check object's status here
  434. char newDamage[8];
  435. char rearDamage[8];
  436. memset( newDamage, 0, 8 );
  437. memset( rearDamage, 0, 8 );
  438. // do check against armor location
  439. ArmorLocation armor = unit->armor[MECH_ARMOR_LOCATION_HEAD];
  440. float tmp = armor.curArmor/(float)armor.maxArmor;
  441. if (unit->body[MECH_BODY_LOCATION_HEAD].damageState == IS_DAMAGE_DESTROYED)
  442. tmp = -1.0f;
  443. float backTmp = 0;
  444. if ( tmp < .0 )
  445. newDamage[7] = 3;
  446. else if ( tmp < .3 )
  447. newDamage[7] = 2;
  448. else if ( tmp < .6 )
  449. newDamage[7] = 1;
  450. tmp = unit->armor[MECH_ARMOR_LOCATION_CTORSO].curArmor/(float)unit->armor[MECH_ARMOR_LOCATION_CTORSO].maxArmor;
  451. if ( !bDrawBack )
  452. {
  453. if ( (float)unit->armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor )
  454. tmp += unit->armor[MECH_ARMOR_LOCATION_RCTORSO].curArmor/(float)unit->armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor;
  455. tmp/= 2.f;
  456. }
  457. else
  458. {
  459. backTmp = unit->armor[MECH_ARMOR_LOCATION_RCTORSO].curArmor/(float)unit->armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor;
  460. }
  461. if (unit->body[MECH_BODY_LOCATION_CTORSO].damageState == IS_DAMAGE_DESTROYED)
  462. {
  463. tmp = -1.0f;
  464. backTmp = -1.0f;
  465. }
  466. if ( tmp < .0 )
  467. newDamage[6] = 3;
  468. else if ( tmp < .3 )
  469. newDamage[6] = 2;
  470. else if ( tmp < .6 )
  471. newDamage[6] = 1;
  472. if ( backTmp < .0 )
  473. rearDamage[6] = 3;
  474. else if ( backTmp < .3 )
  475. rearDamage[6] = 2;
  476. else if ( backTmp < .6 )
  477. rearDamage[6] = 1;
  478. tmp = unit->armor[MECH_ARMOR_LOCATION_LTORSO].curArmor/(float)unit->armor[MECH_ARMOR_LOCATION_LTORSO].maxArmor;
  479. if ( !bDrawBack )
  480. {
  481. if ( (float)unit->armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor )
  482. tmp += unit->armor[MECH_ARMOR_LOCATION_RLTORSO].curArmor/(float)unit->armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor;
  483. tmp/= 2.f;
  484. }
  485. else
  486. {
  487. backTmp = unit->armor[MECH_ARMOR_LOCATION_RLTORSO].curArmor/(float)unit->armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor;
  488. }
  489. if (bMovie)
  490. {
  491. bool result = bMovie->update();
  492. if (result)
  493. {
  494. delete bMovie;
  495. bMovie = NULL;
  496. }
  497. }
  498. if (unit->body[MECH_BODY_LOCATION_LTORSO].damageState == IS_DAMAGE_DESTROYED)
  499. {
  500. tmp = -1.0f;
  501. backTmp = -1.0f;
  502. }
  503. if ( tmp < .0 )
  504. newDamage[5] = 3;
  505. else if ( tmp < .3 )
  506. newDamage[5] = 2;
  507. else if ( tmp < .6 )
  508. newDamage[5] = 1;
  509. if ( backTmp < .0 )
  510. rearDamage[5] = 3;
  511. else if ( backTmp < .3 )
  512. rearDamage[5] = 2;
  513. else if ( backTmp < .5 )
  514. rearDamage[5] = 1;
  515. tmp = unit->armor[MECH_ARMOR_LOCATION_RTORSO].curArmor/(float)unit->armor[MECH_ARMOR_LOCATION_RTORSO].maxArmor;
  516. if ( !bDrawBack )
  517. {
  518. if ( (float)unit->armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor )
  519. tmp += unit->armor[MECH_ARMOR_LOCATION_RRTORSO].curArmor/(float)unit->armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor;
  520. tmp/= 2.f;
  521. }
  522. else
  523. {
  524. backTmp = unit->armor[MECH_ARMOR_LOCATION_RRTORSO].curArmor/(float)unit->armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor;
  525. }
  526. if (unit->body[MECH_BODY_LOCATION_RTORSO].damageState == IS_DAMAGE_DESTROYED)
  527. {
  528. tmp = -1.0f;
  529. backTmp = -1.0f;
  530. }
  531. if ( tmp < .0 )
  532. newDamage[4] = 3;
  533. else if ( tmp < .3 )
  534. newDamage[4] = 2;
  535. else if ( tmp < .6 )
  536. newDamage[4] = 1;
  537. if ( backTmp < .0 )
  538. rearDamage[4] = 3;
  539. else if ( backTmp < .3 )
  540. rearDamage[4] = 2;
  541. else if ( backTmp < .4 )
  542. rearDamage[4] = 1;
  543. armor = unit->armor[MECH_ARMOR_LOCATION_LLEG];
  544. tmp = armor.curArmor/(float)armor.maxArmor;
  545. if (unit->body[MECH_BODY_LOCATION_LLEG].damageState == IS_DAMAGE_DESTROYED)
  546. {
  547. tmp = -1.0f;
  548. }
  549. if ( tmp < .0 )
  550. newDamage[0] = 3;
  551. else if ( tmp < .3 )
  552. newDamage[0] = 2;
  553. else if ( tmp < .6 )
  554. newDamage[0] = 1;
  555. armor = unit->armor[MECH_ARMOR_LOCATION_RLEG];
  556. tmp = armor.curArmor/(float)armor.maxArmor;
  557. if (unit->body[MECH_BODY_LOCATION_RLEG].damageState == IS_DAMAGE_DESTROYED)
  558. {
  559. tmp = -1.0f;
  560. }
  561. if ( tmp < .0 )
  562. newDamage[1] = 3;
  563. else if ( tmp < .3 )
  564. newDamage[1] = 2;
  565. else if ( tmp < .6 )
  566. newDamage[1] = 1;
  567. armor = unit->armor[MECH_ARMOR_LOCATION_LARM];
  568. tmp = armor.curArmor/(float)armor.maxArmor;
  569. if (unit->body[MECH_BODY_LOCATION_LARM].damageState == IS_DAMAGE_DESTROYED)
  570. {
  571. tmp = -1.0f;
  572. }
  573. if ( tmp < .0 )
  574. newDamage[2] = 3;
  575. else if ( tmp < .3 )
  576. newDamage[2] = 2;
  577. else if ( tmp < .6 )
  578. newDamage[2] = 1;
  579. armor = unit->armor[MECH_ARMOR_LOCATION_RARM];
  580. tmp = armor.curArmor/(float)armor.maxArmor;
  581. if (unit->body[MECH_BODY_LOCATION_RARM].damageState == IS_DAMAGE_DESTROYED)
  582. {
  583. tmp = -1.0f;
  584. backTmp = -1.0f;
  585. }
  586. if ( tmp < .0 )
  587. newDamage[3] = 3;
  588. else if ( tmp < .3 )
  589. newDamage[3] = 2;
  590. else if ( tmp < .6 )
  591. newDamage[3] = 1;
  592. doDraw( newDamage, damage, -1, damageIconIndex );
  593. if ( bDrawBack )
  594. {
  595. float lratio = 1.f;
  596. float rratio = 1.f;
  597. if ( (float)unit->armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor )
  598. {
  599. lratio = (float)unit->armor[MECH_ARMOR_LOCATION_RLTORSO].maxArmor/(float)unit->armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor;
  600. rratio = (float)unit->armor[MECH_ARMOR_LOCATION_RRTORSO].maxArmor/(float)unit->armor[MECH_ARMOR_LOCATION_RCTORSO].maxArmor;
  601. }
  602. rearDamage[7] = .5 + (float)((rratio * rearDamage[4] + lratio * rearDamage[5] + rearDamage[6]))/(lratio + rratio + 1.f);
  603. backDamage[7] = .5 + (float)((rratio * backDamage[4] + lratio * backDamage[5] + backDamage[6]))/(lratio + rratio + 1.f);
  604. doDraw( rearDamage, backDamage, -1, backDamageIndex );
  605. }
  606. }
  607. void MechIcon::doDraw( char* newDamage, char* oldDamage, unsigned long handle, unsigned long index )
  608. {
  609. int i = 0;
  610. int maxToCheck = 8;
  611. if ( index == backDamageIndex )
  612. i = 7;
  613. for ( ; i < maxToCheck; ++i )
  614. {
  615. // if damage has changeed, update that part of the icon, we really don't want to do this
  616. // every frame
  617. if ( newDamage[i] != oldDamage[i] )
  618. {
  619. // find the icon
  620. long texIndex = 0;
  621. int iconsPerLine = ((int)s_textureMemory->width/(int)unitIconX);
  622. int iconsPerPage = ((int)s_textureMemory->width/(int)unitIconY);
  623. int yIndex = index / iconsPerLine;
  624. if ( yIndex >= iconsPerPage )
  625. {
  626. texIndex = yIndex/iconsPerPage;
  627. yIndex = yIndex % iconsPerPage;
  628. }
  629. int xIndex = index % iconsPerLine;
  630. if ( s_textureHandle[texIndex] == -1 )
  631. {
  632. long size = ( 256 * 256 * sizeof( long ) + sizeof( TGAFileHeader ) );
  633. s_textureHandle[texIndex] = gos_NewTextureFromMemory( gos_Texture_Alpha, ".tga", (unsigned char*)s_textureMemory, size, 0 );
  634. }
  635. TEXTUREPTR textureData;
  636. gos_LockTexture( s_textureHandle[texIndex], 0, 0, &textureData );
  637. unsigned long* pData = textureData.pTexture;
  638. // go to write spot in texture
  639. int jLine = yIndex * unitIconY;
  640. int iLine = xIndex * unitIconX;
  641. unsigned long* pLine = (unsigned long*)(pData + (jLine * textureData.Width) + iLine);
  642. unsigned long* pChange = pLine;
  643. unsigned long oldColors[3];
  644. unsigned long newColors[3];
  645. // find the colors we're looking for
  646. for ( int p = 0; p < 3; p++ )
  647. {
  648. int tmp = damageColors[damage[i]][p];
  649. int redVal = (tmp >> 16) & 0x000000ff;
  650. redVal += i;
  651. oldColors[p] = ( tmp & 0xff00ffff ) | (redVal << 16);
  652. tmp = damageColors[newDamage[i]][p];
  653. redVal = (tmp >> 16) & 0x000000ff;
  654. redVal += i;
  655. newColors[p] = ( tmp & 0xff00ffff ) | (redVal << 16);
  656. }
  657. // look through the entire bitmap, changing old colors to new colors
  658. for ( int k = 0; k < unitIconY; ++k )
  659. {
  660. pChange = pLine;
  661. for ( int j = 0; j < unitIconX; ++j )
  662. {
  663. if ( (*pChange)&0xff000000 ) // not transparent
  664. {
  665. for ( p = 0; p < 3; p++ )
  666. {
  667. if ( oldColors[p] == *pChange )
  668. {
  669. *pChange = newColors[p];
  670. }
  671. }
  672. }
  673. pChange++;
  674. }
  675. pLine += textureData.Width;
  676. }
  677. gos_UnLockTexture( s_textureHandle[texIndex] );
  678. }
  679. oldDamage[i] = newDamage[i];
  680. }
  681. }
  682. bool IsDbcsString(const char* pszString)
  683. {
  684. if (pszString) {
  685. while (*pszString) {
  686. if (IsDBCSLeadByte((BYTE)*pszString))
  687. return true;
  688. pszString++;
  689. }
  690. }
  691. return false;
  692. }
  693. void ForceGroupIcon::render()
  694. {
  695. // here I draw the text
  696. if ( !unit )
  697. return;
  698. int forceGroup = -1;
  699. for ( int i = 0; i < 10; ++i )
  700. {
  701. if ( unit->isInUnitGroup( i ) )
  702. forceGroup = i;
  703. }
  704. // draw little colored background
  705. if ( forceGroup == 0 )
  706. forceGroup = 10;
  707. int color = forceGroup == -1 ? ForceGroupColors[10] : ForceGroupColors[forceGroup-1];
  708. float health = unit->getAppearance()->barStatus;
  709. // draw pilotName
  710. GUI_RECT tmpRect = { textArea[locationIndex].left, textArea[locationIndex].top, textArea[locationIndex].right, textArea[locationIndex].bottom };
  711. drawRect( tmpRect, color);
  712. char buffer[256];
  713. strcpy( buffer, unit->getPilot()->getName() );
  714. for ( i = 0; i < strlen( buffer ); i++ )
  715. CharUpper( buffer );
  716. gosFontHandle->render( buffer, textArea[locationIndex].left + 1, pilotTextTop[locationIndex], 0, 0, 0xffffffff, 0, 0 );
  717. // draw the health bar
  718. drawBar( health );
  719. // draw the little unit icon
  720. renderUnitIcon( bmpLocation[locationIndex][0].x, bmpLocation[locationIndex][0].y, bmpLocation[locationIndex][2].x, bmpLocation[locationIndex][2].y );
  721. pilotIcon.render( pilotLocation[locationIndex][0], pilotLocation[locationIndex][1], pilotLocation[locationIndex][2], pilotLocation[locationIndex][3] );
  722. drawEmptyRect( pilotRect[locationIndex], 0xff002f55, 0xff002f55 );
  723. // if has jumpjets, draws jump jet icon
  724. if ( unit->canJump() )
  725. {
  726. jumpJetIcon->move( selectionRect[locationIndex].left, selectionRect[locationIndex].bottom );
  727. jumpJetIcon->render( );
  728. jumpJetIcon->move( -selectionRect[locationIndex].left, -selectionRect[locationIndex].bottom );
  729. }
  730. if ( pilotVideoPilot == unit->getPilot() )
  731. {
  732. gos_VERTEX v[4];
  733. for ( i = 0; i < 4; i++ )
  734. {
  735. v[i] = bmpLocation[locationIndex][i];
  736. v[i].u = 0.f;
  737. v[i].v = 0.f;
  738. }
  739. v[2].x = v[3].x = pilotLocation[locationIndex][2];
  740. v[2].u = v[3].u = .59375;
  741. v[1].v = v[2].v = .828125f;
  742. RECT vRect;
  743. vRect.left = bmpLocation[locationIndex][1].x;
  744. vRect.right = pilotLocation[locationIndex][2];
  745. vRect.top = bmpLocation[locationIndex][3].y;
  746. vRect.bottom = bmpLocation[locationIndex][1].y;
  747. if ( bMovie )
  748. {
  749. if ( unit && (unit->getStatus () == OBJECT_STATUS_SHUTDOWN) )
  750. {
  751. bMovie->stop();
  752. delete bMovie;
  753. bMovie = NULL;
  754. pilotVideoPilot = NULL;
  755. }
  756. else
  757. {
  758. bMovie->setRect(vRect);
  759. bMovie->render();
  760. }
  761. }
  762. else if ( pilotVideoTexture )
  763. {
  764. gos_SetRenderState( gos_State_Texture, pilotVideoTexture );
  765. v[1].v = v[2].v = .4140625;
  766. gos_DrawQuads( v, 4 );
  767. }
  768. }
  769. if ( unit && (unit->getStatus () == OBJECT_STATUS_SHUTDOWN) )
  770. {
  771. drawRect( selectionRect[locationIndex], 0xaa000000 );
  772. }
  773. // if selected, draw white rectangle
  774. if ( unit->getSelected() )
  775. {
  776. drawEmptyRect( selectionRect[locationIndex], 0xffffffff, 0xffffffff );
  777. }
  778. if ( unit->getPilot() )
  779. {
  780. if ( unit->getPilot()->getMessagePlaying() )
  781. {
  782. long color = 0xffffff00;
  783. msgPlayTime += frameLength;
  784. if ( msgPlayTime > .25 )
  785. msgPlayTime = 0;
  786. if ( msgPlayTime > .125 )
  787. color = 0x00000000;
  788. drawEmptyRect( selectionRect[locationIndex], color, color );
  789. }
  790. else
  791. msgPlayTime = 0;
  792. }
  793. // draw dying effect
  794. if ( deathAnimationTime )
  795. {
  796. drawDeathEffect();
  797. }
  798. }
  799. void ForceGroupIcon::renderUnitIcon( float left, float top, float right, float bottom )
  800. {
  801. int texIndex = 0;
  802. int iconsPerLine = ((int)s_textureMemory->width/(int)unitIconX);
  803. int iconsPerPage= ((int)s_textureMemory->width/(int)unitIconY);
  804. int yIndex = damageIconIndex / iconsPerLine;
  805. if ( yIndex >= iconsPerPage )
  806. {
  807. texIndex = yIndex / iconsPerPage;
  808. yIndex = yIndex % iconsPerPage;
  809. }
  810. int xIndex = damageIconIndex % iconsPerLine;
  811. float u = xIndex * unitIconX/s_textureMemory->width + (.1f / 256.f);
  812. float v = yIndex * unitIconY/s_textureMemory->height+ (.1f / 256.f);
  813. float uDelta = unitIconX/s_textureMemory->width + (.1f / 256.f );
  814. float vDelta = unitIconY/s_textureMemory->height + (.1f / 256.f);
  815. gos_SetRenderState( gos_State_Texture, s_textureHandle[texIndex] );
  816. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_AlphaInvAlpha);
  817. gos_SetRenderState( gos_State_Filter, gos_FilterNone);
  818. gos_SetRenderState( gos_State_AlphaTest, true);
  819. bmpLocation[locationIndex][0].u = bmpLocation[locationIndex][1].u = u;
  820. bmpLocation[locationIndex][2].u = bmpLocation[locationIndex][3].u = u + uDelta;
  821. bmpLocation[locationIndex][0].v = bmpLocation[locationIndex][3].v = v;
  822. bmpLocation[locationIndex][1].v = bmpLocation[locationIndex][2].v = v + vDelta;
  823. bmpLocation[locationIndex][0].x = bmpLocation[locationIndex][1].x = left;
  824. bmpLocation[locationIndex][2].x = bmpLocation[locationIndex][3].x = right;
  825. bmpLocation[locationIndex][0].y = bmpLocation[locationIndex][3].y = top;
  826. bmpLocation[locationIndex][1].y = bmpLocation[locationIndex][2].y = bottom;
  827. bmpLocation[locationIndex][4] = bmpLocation[locationIndex][0];
  828. gos_DrawTriangles( bmpLocation[locationIndex], 3 );
  829. gos_DrawTriangles( &bmpLocation[locationIndex][2], 3 );
  830. }
  831. void ForceGroupIcon::renderUnitIconBack( float left, float top, float right, float bottom )
  832. {
  833. int iconsPerLine = ((int)s_textureMemory->width/(int)unitIconX);
  834. int yIndex = backDamageIndex / iconsPerLine;
  835. int xIndex = backDamageIndex % iconsPerLine;
  836. float u = xIndex * unitIconX/s_textureMemory->width+ (.1f / (float)256.f);
  837. float v = yIndex * unitIconY/s_textureMemory->height+ (.1f / (float)256.f);
  838. float uDelta = unitIconX/s_textureMemory->width + (.1f / (float)256.f );
  839. float vDelta = unitIconY/s_textureMemory->height + (.1f / (float)256.f);
  840. gos_SetRenderState( gos_State_Texture, s_textureHandle[0] );
  841. gos_SetRenderState( gos_State_AlphaMode, gos_Alpha_AlphaInvAlpha);
  842. gos_SetRenderState( gos_State_Filter, gos_FilterNone);
  843. gos_SetRenderState( gos_State_AlphaTest, true);
  844. gos_VERTEX vertices[5];
  845. for ( int i = 0; i < 5; i++ )
  846. {
  847. vertices[i].argb = 0xffffffff;
  848. vertices[i].frgb = 0;
  849. vertices[i].z = 0;
  850. vertices[i].rhw = .5;
  851. }
  852. vertices[0].u = vertices[1].u = u;
  853. vertices[2].u = vertices[3].u = u + uDelta;
  854. vertices[0].v = vertices[3].v = v;
  855. vertices[1].v = vertices[2].v = v + vDelta;
  856. vertices[0].x = vertices[1].x = left;
  857. vertices[2].x = vertices[3].x = right;
  858. vertices[0].y = vertices[3].y = top;
  859. vertices[1].y = vertices[2].y = bottom;
  860. vertices[4] = vertices[0];
  861. gos_DrawTriangles( vertices, 3 );
  862. gos_DrawTriangles( &vertices[2], 3 );
  863. }
  864. void ForceGroupIcon::renderPilotIcon( float left, float top, float right, float bottom )
  865. {
  866. pilotIcon.render( left, top, right, bottom );
  867. }
  868. bool VehicleIcon::init( Mover* pMover )
  869. {
  870. if ( !s_VehicleTextures )
  871. {
  872. File file;
  873. char path[256];
  874. strcpy( path, artPath );
  875. if ( Environment.screenWidth == 800 )
  876. strcat( path, "mcui_med5.tga" );
  877. else if ( Environment.screenWidth == 640 )
  878. strcat( path, "mcui_low5.tga" );
  879. else
  880. strcat( path, "mcui_high8.tga" );
  881. setIconVariables();
  882. if ( NO_ERR != file.open( path ) )
  883. {
  884. Assert( 0, 0, "Couldn't open the vehicle parts" );
  885. return false;
  886. }
  887. int size = file.getLength();
  888. s_VehicleTextures = (TGAFileHeader*)new char[size];
  889. file.read( (BYTE*)s_VehicleTextures, size );
  890. BYTE* pTmp = (BYTE*)(s_VehicleTextures + 1);
  891. flipTopToBottom (pTmp, s_VehicleTextures->pixel_depth, s_VehicleTextures->width, s_VehicleTextures->height );
  892. }
  893. pilotIcon.setTextureIndex( 26 );
  894. if ( !pMover )
  895. return 0;
  896. gosASSERT( unitIconX * 4 < ICON_REALSIZE && unitIconY * 4 < ICON_REALSIZE );
  897. int pixelDepth = s_VehicleTextures->pixel_depth/8;
  898. if ( pixelDepth != 4 )
  899. PAUSE(("Texture for VehicleIcon not 32-bit"));
  900. // now need to make a copy of the data
  901. // now need to make a copy of the data
  902. long texIndex = 0;
  903. int iconsPerLine = ((int)s_textureMemory->width/(int)unitIconX);
  904. int iconsPerPage = ((int)s_textureMemory->width/(int)unitIconY);
  905. long row = damageIconIndex/iconsPerLine;
  906. long column = (damageIconIndex % iconsPerLine);
  907. if ( row >= iconsPerPage )
  908. {
  909. texIndex = row/iconsPerPage;
  910. row = row % iconsPerPage;
  911. }
  912. long offsetX = column * unitIconX;
  913. long offsetY = row * unitIconY;
  914. if ( s_textureHandle[texIndex] == -1 )
  915. {
  916. long size = ( 256 * 256 * sizeof( long ) + sizeof( TGAFileHeader ) );
  917. s_textureHandle[texIndex] = gos_NewTextureFromMemory( gos_Texture_Alpha, ".tga", (unsigned char*)s_textureMemory, size, 0 );
  918. }
  919. TEXTUREPTR textureData;
  920. gos_LockTexture( s_textureHandle[texIndex], 0, 0, &textureData );
  921. unsigned long* pDestData, *pDestRow = textureData.pTexture + offsetY * textureData.Width + offsetX;
  922. char* pTmp = (char*)s_VehicleTextures + sizeof ( TGAFileHeader );
  923. unsigned long* pSrcRow = (unsigned long*)pTmp;
  924. long whichMech = pMover->getIconPictureIndex();
  925. offsetY = 0;
  926. offsetX = whichMech * unitIconX;
  927. long tmpOffset = ((s_VehicleTextures->width) * (offsetY ) + offsetX);
  928. pSrcRow += tmpOffset;
  929. unsigned long* pSrcData = pSrcRow;
  930. for( int j = 0; j < unitIconY; ++j )
  931. {
  932. pDestData = pDestRow;
  933. pSrcData = pSrcRow;
  934. for ( int i = 0; i < unitIconX; ++i ) // do four icons per row
  935. {
  936. *pDestData++ = *pSrcData++;
  937. }
  938. pSrcRow += s_VehicleTextures->width;
  939. pDestRow += textureData.Width;
  940. }
  941. gos_UnLockTexture( s_textureHandle[texIndex] );
  942. unit = pMover;
  943. for ( int i = 0; i < 5; ++i )
  944. {
  945. bmpLocation[locationIndex][i].argb = 0xffffffff;
  946. bmpLocation[locationIndex][i].frgb = 0;
  947. bmpLocation[locationIndex][i].rhw = .5;
  948. bmpLocation[locationIndex][i].u = 0.;
  949. bmpLocation[locationIndex][i].v = 0.;
  950. bmpLocation[locationIndex][i].z = 0.;
  951. }
  952. memset( damage, 0, 5 );
  953. return true;
  954. }
  955. void VehicleIcon::update()
  956. {
  957. char newDamage[5];
  958. memset( newDamage, 0, 5 );
  959. // do check against armor location
  960. ArmorLocation armor = unit->armor[GROUNDVEHICLE_LOCATION_FRONT];
  961. float tmp = armor.curArmor/(float)armor.maxArmor;
  962. if ( tmp < .1 )
  963. newDamage[0] = 3;
  964. else if ( tmp < .3 )
  965. newDamage[0] = 2;
  966. else if ( tmp < .6 )
  967. newDamage[0] = 1;
  968. tmp = unit->armor[GROUNDVEHICLE_LOCATION_REAR].curArmor/(float)unit->armor[GROUNDVEHICLE_LOCATION_REAR].maxArmor;
  969. if ( tmp < .1 )
  970. newDamage[1] = 3;
  971. else if ( tmp < .3 )
  972. newDamage[1] = 2;
  973. else if ( tmp < .6 )
  974. newDamage[1] = 1;
  975. tmp = unit->armor[GROUNDVEHICLE_LOCATION_LEFT].curArmor/(float)unit->armor[GROUNDVEHICLE_LOCATION_LEFT].maxArmor;
  976. if ( tmp < .1 )
  977. newDamage[2] = 3;
  978. else if ( tmp < .3 )
  979. newDamage[2] = 2;
  980. else if ( tmp < .6 )
  981. newDamage[2] = 1;
  982. tmp = unit->armor[GROUNDVEHICLE_LOCATION_RIGHT].curArmor/(float)unit->armor[GROUNDVEHICLE_LOCATION_RIGHT].maxArmor;
  983. if ( tmp < .1 )
  984. newDamage[3] = 3;
  985. else if ( tmp < .3 )
  986. newDamage[3] = 2;
  987. else if ( tmp < .6 )
  988. newDamage[3] = 1;
  989. armor = unit->armor[GROUNDVEHICLE_LOCATION_TURRET];
  990. tmp = armor.curArmor/(float)armor.maxArmor;
  991. if ( tmp < .1 )
  992. newDamage[4] = 3;
  993. else if ( tmp < .3 )
  994. newDamage[4] = 2;
  995. else if ( tmp < .6 )
  996. newDamage[4] = 1;
  997. for ( int i = 0; i < 5; ++i )
  998. {
  999. if ( newDamage[i] != damage[i] )
  1000. {
  1001. long texIndex = 0;
  1002. int iconsPerLine = ((int)s_textureMemory->width/(int)unitIconX);
  1003. int iconsPerPage = ((int)s_textureMemory->width/(int)unitIconY);
  1004. int yIndex = damageIconIndex / iconsPerLine;
  1005. int xIndex = damageIconIndex % iconsPerLine;
  1006. if ( yIndex >= iconsPerPage )
  1007. {
  1008. texIndex = yIndex/iconsPerPage;
  1009. yIndex = yIndex % iconsPerPage;
  1010. }
  1011. TEXTUREPTR textureData;
  1012. gos_LockTexture( s_textureHandle[texIndex], 0, 0, &textureData );
  1013. unsigned long* pData = textureData.pTexture;
  1014. // go to write spot in texture
  1015. int jLine = yIndex * unitIconY;
  1016. int iLine = xIndex * unitIconX;
  1017. unsigned long* pLine = (unsigned long*)(pData + (jLine * textureData.Width) + iLine);
  1018. unsigned long* pChange = pLine;
  1019. unsigned long oldColors[3];
  1020. unsigned long newColors[3];
  1021. for ( int p = 0; p < 3; p++ )
  1022. {
  1023. int tmp = damageColors[damage[i]][p];
  1024. int redVal = (tmp >> 16) & 0x000000ff;
  1025. redVal += i;
  1026. oldColors[p] = ( tmp & 0xff00ffff ) | (redVal << 16);
  1027. tmp = damageColors[newDamage[i]][p];
  1028. redVal = (tmp >> 16) & 0x000000ff;
  1029. redVal += i;
  1030. newColors[p] = ( tmp & 0xff00ffff ) | (redVal << 16);
  1031. }
  1032. for ( int k = 0; k < unitIconY; ++k )
  1033. {
  1034. pChange = pLine;
  1035. for ( int j = 0; j < unitIconX; ++j )
  1036. {
  1037. if ( (*pChange)&0xff000000 ) // not transparent
  1038. {
  1039. for ( int p = 0; p < 3; p++ )
  1040. {
  1041. if ( oldColors[p] == *pChange )
  1042. {
  1043. *pChange = newColors[p];
  1044. }
  1045. }
  1046. }
  1047. pChange++;
  1048. }
  1049. pLine += textureData.Width;
  1050. }
  1051. gos_UnLockTexture( s_textureHandle[texIndex] );
  1052. }
  1053. damage[i] = newDamage[i];
  1054. }
  1055. }
  1056. void ForceGroupIcon::drawBar( float barStatus )
  1057. {
  1058. DWORD color = SB_GREEN;
  1059. float barLength = (healthBar[locationIndex].right - healthBar[locationIndex].left) * barStatus;
  1060. /*if (barStatus >= 0.5)
  1061. color = SB_GREEN;
  1062. else if (barStatus > 0.2)
  1063. color = SB_YELLOW;
  1064. else
  1065. color = SB_RED;*/
  1066. GUI_RECT rect = { healthBar[locationIndex].left, healthBar[locationIndex].top,healthBar[locationIndex].left + barLength, healthBar[locationIndex].bottom };
  1067. drawRect( rect, color );
  1068. drawEmptyRect( healthBar[locationIndex], color, color & 0x7f7f7f );
  1069. }
  1070. int ForceGroupIcon::sort( const void* p1, const void* p2 )
  1071. {
  1072. ForceGroupIcon* m1 = *(ForceGroupIcon**)p1;
  1073. ForceGroupIcon* m2 = *(ForceGroupIcon**)p2;
  1074. bool bv1 = dynamic_cast<VehicleIcon*>(m1) ? 1 : 0;
  1075. bool bv2 = dynamic_cast<VehicleIcon*>(m2) ? 1 : 0;
  1076. for ( int i = 1; i < 10; ++i )
  1077. {
  1078. bool bM1 = m1->unit->isInUnitGroup( i == 10 ? 0 : i );
  1079. bool bM2 = m2->unit->isInUnitGroup( i == 10 ? 0 : i );
  1080. if ( bM1 && !bM2 )
  1081. return -1;
  1082. if ( bM2 && !bM1 )
  1083. return 1;
  1084. if ( bM2 && bM1 ) // if same force group, use weight
  1085. {
  1086. break;
  1087. }
  1088. }
  1089. if ( bv2 && !bv1 )
  1090. return -1;
  1091. else if ( bv1 && !bv2 )
  1092. return 1;
  1093. int w1 = m1->unit->getTonnage();
  1094. int w2 = m2->unit->getTonnage();
  1095. if ( w1 < w2 )
  1096. return -1;
  1097. else if ( w2 < w1)
  1098. return 1;
  1099. // OK these are exactly the same, compare pilot names
  1100. int retVal = ( strcmp( m1->getPilotName(), m2->getPilotName() ) );
  1101. if ( retVal == 0 )
  1102. return m1 < m2;
  1103. return retVal;
  1104. }
  1105. const char* ForceGroupIcon::getPilotName()
  1106. {
  1107. return unit->getPilot()->getName();
  1108. }
  1109. void ForceGroupIcon::setLocationIndex( int i )
  1110. {
  1111. locationIndex = i;
  1112. }
  1113. void ForceGroupIcon::drawDeathEffect()
  1114. {
  1115. unit->setSelected( 0 );
  1116. bool bFinished = true;
  1117. deathAnimationTime += frameLength;
  1118. for ( int i = 0; i < NUM_DEATH_INFOS - 1; i++ )
  1119. {
  1120. if ( animationInfos[i].time < deathAnimationTime &&
  1121. animationInfos[i+1].time > deathAnimationTime )
  1122. {
  1123. float totalTime = animationInfos[i+1].time - animationInfos[i].time;
  1124. float currentTime = deathAnimationTime - animationInfos[i].time;
  1125. float percent = currentTime/totalTime;
  1126. // since I know we're going from white to black, I'm only going to much with the alpha separately
  1127. long alphaMin = (animationInfos[i].color >> 24) & 0xff;
  1128. long alphaMax = (animationInfos[i+1].color >> 24)& 0xff;
  1129. long newAlpha = (float)alphaMin + ((float)(alphaMax - alphaMin))*percent;
  1130. long redMin = (animationInfos[i].color & 0x00ff0000)>>16;
  1131. long redMax = (animationInfos[i+1].color & 0x00ff0000)>>16;
  1132. long newRed = (float)redMin + ((float)(redMax - redMin))*percent;
  1133. long greenMin = (animationInfos[i].color & 0x0000ff00)>>8;
  1134. long greenMax = (animationInfos[i+1].color & 0x0000ff00)>>8;
  1135. long newGreen = (float)greenMin + ((float)(greenMax - greenMin))*percent;
  1136. long blueMin = animationInfos[i].color & 0x000000ff;
  1137. long blueMax = animationInfos[i+1].color & 0x000000ff;
  1138. long newBlue = (float)blueMin + ((float)(blueMax - blueMin))*percent;
  1139. long newColor = newBlue + (newGreen << 8) + (newRed << 16) + (newAlpha <<24);
  1140. drawRect( selectionRect[locationIndex], newColor );
  1141. bFinished = false;
  1142. if ( i == 0 )
  1143. {
  1144. long color = 0xff000000;
  1145. if ( deathAnimationTime < .4
  1146. || (deathAnimationTime > .8 && deathAnimationTime < 1.2)
  1147. || deathAnimationTime > 1.6 && deathAnimationTime < 2.0)
  1148. {
  1149. color = 0xffff0000;
  1150. }
  1151. drawEmptyRect( selectionRect[locationIndex], color, color );
  1152. }
  1153. }
  1154. }
  1155. if ( bFinished )
  1156. {
  1157. drawRect( selectionRect[locationIndex], animationInfos[i].color );
  1158. unit->addToUnitGroup( -1 );
  1159. //------------------------------------------------------------
  1160. // This tells all machines to drop this mover from the team...
  1161. if (MPlayer)
  1162. MPlayer->sendReinforcement(0, unit->netRosterIndex, "noname", 0, unit->getPosition(), 7);
  1163. }
  1164. }
  1165. void ForceGroupIcon::setIconVariables()
  1166. {
  1167. switch( Environment.screenWidth )
  1168. {
  1169. case 800:
  1170. PilotIcon::pilotIconX = 25;
  1171. PilotIcon::pilotIconY = 36;
  1172. unitIconX = 32;
  1173. unitIconY = 38;
  1174. break;
  1175. case 640:
  1176. PilotIcon::pilotIconX = 20;
  1177. PilotIcon::pilotIconY = 28;
  1178. unitIconX = 25;
  1179. unitIconY = 30;
  1180. break;
  1181. default:
  1182. PilotIcon::pilotIconX = 33;
  1183. PilotIcon::pilotIconY = 46;
  1184. unitIconX = 40;
  1185. unitIconY = 48;
  1186. break;
  1187. }
  1188. curScreenWidth = Environment.screenWidth;
  1189. }
  1190. PilotIcon::PilotIcon()
  1191. {
  1192. pilotTextureIndex = 0;
  1193. if ( !s_pilotTextureHandle )
  1194. {
  1195. // find proper file based on resolution
  1196. char path[256];
  1197. strcpy( path, "data\\art\\");
  1198. if ( Environment.screenWidth == 640 )
  1199. {
  1200. strcat( path, "mcui_low2.tga" );
  1201. }
  1202. else if ( Environment.screenWidth == 800 )
  1203. {
  1204. strcat( path, "mcui_med2.tga" );
  1205. }
  1206. else
  1207. {
  1208. strcat( path, "mcui_high2.tga" );
  1209. }
  1210. s_pilotTextureHandle = mcTextureManager->loadTexture( path, gos_Texture_Alpha, 0, 0, 0x2);
  1211. // find its width and store it for future reference.
  1212. int gosID = mcTextureManager->get_gosTextureHandle( s_pilotTextureHandle );
  1213. TEXTUREPTR textureData;
  1214. gos_LockTexture( gosID, 0, 0, &textureData );
  1215. s_pilotTextureWidth = textureData.Width;
  1216. gos_UnLockTexture( gosID );
  1217. }
  1218. }
  1219. void PilotIcon::render( float left, float top, float right, float bottom )
  1220. {
  1221. gos_VERTEX pilotLocation[5];
  1222. for ( int i = 0; i < 5; i++ )
  1223. {
  1224. pilotLocation[i].argb = 0xffffffff;
  1225. pilotLocation[i].rhw = .5;
  1226. pilotLocation[i].frgb = 0;
  1227. pilotLocation[i].z = 0;
  1228. }
  1229. pilotLocation[0].x = pilotLocation[1].x = left;
  1230. pilotLocation[3].x = pilotLocation[2].x = right;
  1231. pilotLocation[0].y = pilotLocation[3].y = top;
  1232. pilotLocation[1].y = pilotLocation[2].y = bottom;
  1233. pilotLocation[4] = pilotLocation[0];
  1234. int iconsPerRow = s_pilotTextureWidth / pilotIconX;
  1235. int xIndex = pilotTextureIndex % iconsPerRow;
  1236. int yIndex = pilotTextureIndex / iconsPerRow;
  1237. float xLocation = xIndex * pilotIconX;
  1238. float yLocation = yIndex * pilotIconY;
  1239. pilotLocation[0].u = pilotLocation[1].u = xLocation/s_pilotTextureWidth + (.1f/s_pilotTextureWidth);
  1240. pilotLocation[3].u = pilotLocation[2].u = (xLocation + pilotIconX)/s_pilotTextureWidth+ (.1f/s_pilotTextureWidth);
  1241. pilotLocation[0].v = pilotLocation[3].v = yLocation/s_pilotTextureWidth+ (.1f/s_pilotTextureWidth);
  1242. pilotLocation[1].v = pilotLocation[2].v = (yLocation + pilotIconY)/s_pilotTextureWidth+ (.1f/s_pilotTextureWidth);
  1243. pilotLocation[4] = pilotLocation[0];
  1244. int gosID = mcTextureManager->get_gosTextureHandle( s_pilotTextureHandle );
  1245. gos_SetRenderState( gos_State_Texture, gosID );
  1246. // here I need to draw the pilot icon
  1247. gos_DrawTriangles( pilotLocation, 3 );
  1248. gos_DrawTriangles( &pilotLocation[2], 3 );
  1249. }
  1250. void PilotIcon::setPilot( MechWarrior* pWarrior )
  1251. {
  1252. if ( pWarrior )
  1253. pilotTextureIndex = pWarrior->getPhoto();
  1254. }
  1255. void PilotIcon::swapResolutions( bool bForce)
  1256. {
  1257. if ( s_pilotTextureHandle )
  1258. {
  1259. int gosID = mcTextureManager->get_gosTextureHandle( s_pilotTextureHandle );
  1260. mcTextureManager->removeTexture( gosID );
  1261. }
  1262. s_pilotTextureHandle = 0;
  1263. if ( !s_pilotTextureHandle )
  1264. {
  1265. // find proper file based on resolution
  1266. char path[256];
  1267. strcpy( path, "data\\art\\");
  1268. if ( Environment.screenWidth == 640 )
  1269. {
  1270. strcat( path, "mcui_low2.tga" );
  1271. }
  1272. else if ( Environment.screenWidth == 800 )
  1273. {
  1274. strcat( path, "mcui_med2.tga" );
  1275. }
  1276. else
  1277. {
  1278. strcat( path, "mcui_high2.tga" );
  1279. }
  1280. s_pilotTextureHandle = mcTextureManager->loadTexture( path, gos_Texture_Alpha, 0, 0, 0x2);
  1281. // find its width and store it for future reference.
  1282. int gosID = mcTextureManager->get_gosTextureHandle( s_pilotTextureHandle );
  1283. TEXTUREPTR textureData;
  1284. gos_LockTexture( gosID, 0, 0, &textureData );
  1285. s_pilotTextureWidth = textureData.Width;
  1286. gos_UnLockTexture( gosID );
  1287. }
  1288. }
  1289. //*************************************************************************************************
  1290. // end of file ( MechIcon.cpp )