Soldier Add.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  1. #ifdef PRECOMPILEDHEADERS
  2. #include "Tactical All.h"
  3. #else
  4. #include "sgp.h"
  5. #include "Soldier Control.h"
  6. #include "overhead.h"
  7. #include "overhead types.h"
  8. #include "isometric utils.h"
  9. #include "interface panels.h"
  10. #include "soldier macros.h"
  11. #include "strategicmap.h"
  12. #include "strategic.h"
  13. #include "animation control.h"
  14. #include "soldier create.h"
  15. #include "Soldier Init List.h"
  16. #include "soldier add.h"
  17. #include "Map Information.h"
  18. #include "fov.h"
  19. #include "pathai.h"
  20. #include "Random.h"
  21. #endif
  22. // Adds a soldier to a world gridno and set's direction
  23. void AddSoldierToSectorGridNo( SOLDIERTYPE *pSoldier, INT16 sGridNo, UINT8 ubDirection, BOOLEAN fUseAnimation, UINT16 usAnimState, UINT16 usAnimCode );
  24. UINT16 FindGridNoFromSweetSpotWithStructData( SOLDIERTYPE *pSoldier, UINT16 usAnimState, INT16 sSweetGridNo, INT8 ubRadius, UINT8 *pubDirection, BOOLEAN fClosestToMerc );
  25. // SO, STEPS IN CREATING A MERC!
  26. // 1 ) Setup the SOLDIERCREATE_STRUCT
  27. // Among other things, this struct needs a sSectorX, sSectorY, and a valid InsertionDirection
  28. // and InsertionGridNo.
  29. // This GridNo will be determined by a prevouis function that will examine the sector
  30. // Infomration regarding placement positions and pick one
  31. // 2 ) Call TacticalCreateSoldier() which will create our soldier
  32. // What it does is: Creates a soldier in the MercPtrs[] array.
  33. // Allocates the Animation cache for this merc
  34. // Loads up the intial aniamtion file
  35. // Creates initial palettes, etc
  36. // And other cool things.
  37. // Now we have an allocated soldier, we just need to set him in the world!
  38. // 3) When we want them in the world, call AddSoldierToSector().
  39. // This function sets the graphic in the world, lighting effects, etc
  40. // It also formally adds it to the TacticalSoldier slot and interface panel slot.
  41. //Kris: modified to actually path from sweetspot to gridno. Previously, it only checked if the
  42. //destination was sittable (though it was possible that that location would be trapped.
  43. UINT16 FindGridNoFromSweetSpot( SOLDIERTYPE *pSoldier, INT16 sSweetGridNo, INT8 ubRadius, UINT8 *pubDirection )
  44. {
  45. INT16 sTop, sBottom;
  46. INT16 sLeft, sRight;
  47. INT16 cnt1, cnt2;
  48. INT16 sGridNo;
  49. INT32 uiRange, uiLowestRange = 999999;
  50. INT16 sLowestGridNo=-1;
  51. INT32 leftmost;
  52. BOOLEAN fFound = FALSE;
  53. SOLDIERTYPE soldier;
  54. UINT8 ubSaveNPCAPBudget;
  55. UINT8 ubSaveNPCDistLimit;
  56. //Save AI pathing vars. changing the distlimit restricts how
  57. //far away the pathing will consider.
  58. ubSaveNPCAPBudget = gubNPCAPBudget;
  59. ubSaveNPCDistLimit = gubNPCDistLimit;
  60. gubNPCAPBudget = 0;
  61. gubNPCDistLimit = ubRadius;
  62. //create dummy soldier, and use the pathing to determine which nearby slots are
  63. //reachable.
  64. memset( &soldier, 0, sizeof( SOLDIERTYPE ) );
  65. soldier.bLevel = 0;
  66. soldier.bTeam = 1;
  67. soldier.sGridNo = sSweetGridNo;
  68. sTop = ubRadius;
  69. sBottom = -ubRadius;
  70. sLeft = - ubRadius;
  71. sRight = ubRadius;
  72. //clear the mapelements of potential residue MAPELEMENT_REACHABLE flags
  73. //in the square region.
  74. // ATE: CHECK FOR BOUNDARIES!!!!!!
  75. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  76. {
  77. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  78. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  79. {
  80. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  81. if( sGridNo >=0 && sGridNo < WORLD_MAX && sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS ) )
  82. {
  83. gpWorldLevelData[ sGridNo ].uiFlags &= (~MAPELEMENT_REACHABLE);
  84. }
  85. }
  86. }
  87. //Now, find out which of these gridnos are reachable
  88. //(use the fake soldier and the pathing settings)
  89. FindBestPath( &soldier, NOWHERE, 0, WALKING, COPYREACHABLE, ( PATH_IGNORE_PERSON_AT_DEST | PATH_THROUGH_PEOPLE ) );
  90. uiLowestRange = 999999;
  91. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  92. {
  93. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  94. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  95. {
  96. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  97. if( sGridNo >=0 && sGridNo < WORLD_MAX && sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS )
  98. && gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE )
  99. {
  100. // Go on sweet stop
  101. if ( NewOKDestination( pSoldier, sGridNo, TRUE, pSoldier->bLevel ) )
  102. {
  103. // ATE: INstead of using absolute range, use the path cost!
  104. //uiRange = PlotPath( &soldier, sGridNo, NO_COPYROUTE, NO_PLOT, TEMPORARY, WALKING, NOT_STEALTH, FORWARD, 50 );
  105. uiRange = CardinalSpacesAway( sSweetGridNo, sGridNo );
  106. // if ( uiRange == 0 )
  107. // {
  108. // uiRange = 999999;
  109. // }
  110. if ( uiRange < uiLowestRange )
  111. {
  112. sLowestGridNo = sGridNo;
  113. uiLowestRange = uiRange;
  114. fFound = TRUE;
  115. }
  116. }
  117. }
  118. }
  119. }
  120. gubNPCAPBudget = ubSaveNPCAPBudget;
  121. gubNPCDistLimit = ubSaveNPCDistLimit;
  122. if ( fFound )
  123. {
  124. // Set direction to center of map!
  125. *pubDirection = (UINT8)GetDirectionToGridNoFromGridNo( sLowestGridNo, ( ( ( WORLD_ROWS / 2 ) * WORLD_COLS ) + ( WORLD_COLS / 2 ) ) );
  126. return( sLowestGridNo );
  127. }
  128. else
  129. {
  130. return( NOWHERE );
  131. }
  132. }
  133. UINT16 FindGridNoFromSweetSpotThroughPeople( SOLDIERTYPE *pSoldier, INT16 sSweetGridNo, INT8 ubRadius, UINT8 *pubDirection )
  134. {
  135. INT16 sTop, sBottom;
  136. INT16 sLeft, sRight;
  137. INT16 cnt1, cnt2;
  138. INT16 sGridNo;
  139. INT32 uiRange, uiLowestRange = 999999;
  140. INT16 sLowestGridNo=-1;
  141. INT32 leftmost;
  142. BOOLEAN fFound = FALSE;
  143. SOLDIERTYPE soldier;
  144. UINT8 ubSaveNPCAPBudget;
  145. UINT8 ubSaveNPCDistLimit;
  146. //Save AI pathing vars. changing the distlimit restricts how
  147. //far away the pathing will consider.
  148. ubSaveNPCAPBudget = gubNPCAPBudget;
  149. ubSaveNPCDistLimit = gubNPCDistLimit;
  150. gubNPCAPBudget = 0;
  151. gubNPCDistLimit = ubRadius;
  152. //create dummy soldier, and use the pathing to determine which nearby slots are
  153. //reachable.
  154. memset( &soldier, 0, sizeof( SOLDIERTYPE ) );
  155. soldier.bLevel = 0;
  156. soldier.bTeam = pSoldier->bTeam;
  157. soldier.sGridNo = sSweetGridNo;
  158. sTop = ubRadius;
  159. sBottom = -ubRadius;
  160. sLeft = - ubRadius;
  161. sRight = ubRadius;
  162. //clear the mapelements of potential residue MAPELEMENT_REACHABLE flags
  163. //in the square region.
  164. // ATE: CHECK FOR BOUNDARIES!!!!!!
  165. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  166. {
  167. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  168. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  169. {
  170. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  171. if( sGridNo >=0 && sGridNo < WORLD_MAX && sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS ) )
  172. {
  173. gpWorldLevelData[ sGridNo ].uiFlags &= (~MAPELEMENT_REACHABLE);
  174. }
  175. }
  176. }
  177. //Now, find out which of these gridnos are reachable
  178. //(use the fake soldier and the pathing settings)
  179. FindBestPath( &soldier, NOWHERE, 0, WALKING, COPYREACHABLE, ( PATH_IGNORE_PERSON_AT_DEST | PATH_THROUGH_PEOPLE ) );
  180. uiLowestRange = 999999;
  181. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  182. {
  183. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  184. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  185. {
  186. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  187. if( sGridNo >=0 && sGridNo < WORLD_MAX && sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS )
  188. && gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE )
  189. {
  190. // Go on sweet stop
  191. if ( NewOKDestination( pSoldier, sGridNo, TRUE, pSoldier->bLevel ) )
  192. {
  193. uiRange = GetRangeInCellCoordsFromGridNoDiff( sSweetGridNo, sGridNo );
  194. {
  195. if ( uiRange < uiLowestRange )
  196. {
  197. sLowestGridNo = sGridNo;
  198. uiLowestRange = uiRange;
  199. fFound = TRUE;
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. gubNPCAPBudget = ubSaveNPCAPBudget;
  207. gubNPCDistLimit = ubSaveNPCDistLimit;
  208. if ( fFound )
  209. {
  210. // Set direction to center of map!
  211. *pubDirection = (UINT8)GetDirectionToGridNoFromGridNo( sLowestGridNo, ( ( ( WORLD_ROWS / 2 ) * WORLD_COLS ) + ( WORLD_COLS / 2 ) ) );
  212. return( sLowestGridNo );
  213. }
  214. else
  215. {
  216. return( NOWHERE );
  217. }
  218. }
  219. //Kris: modified to actually path from sweetspot to gridno. Previously, it only checked if the
  220. //destination was sittable (though it was possible that that location would be trapped.
  221. UINT16 FindGridNoFromSweetSpotWithStructData( SOLDIERTYPE *pSoldier, UINT16 usAnimState, INT16 sSweetGridNo, INT8 ubRadius, UINT8 *pubDirection, BOOLEAN fClosestToMerc )
  222. {
  223. INT16 sTop, sBottom;
  224. INT16 sLeft, sRight;
  225. INT16 cnt1, cnt2, cnt3;
  226. INT16 sGridNo;
  227. INT32 uiRange, uiLowestRange = 999999;
  228. INT16 sLowestGridNo=-1;
  229. INT32 leftmost;
  230. BOOLEAN fFound = FALSE;
  231. SOLDIERTYPE soldier;
  232. UINT8 ubSaveNPCAPBudget;
  233. UINT8 ubSaveNPCDistLimit;
  234. UINT8 ubBestDirection=0;
  235. //Save AI pathing vars. changing the distlimit restricts how
  236. //far away the pathing will consider.
  237. ubSaveNPCAPBudget = gubNPCAPBudget;
  238. ubSaveNPCDistLimit = gubNPCDistLimit;
  239. gubNPCAPBudget = 0;
  240. gubNPCDistLimit = ubRadius;
  241. //create dummy soldier, and use the pathing to determine which nearby slots are
  242. //reachable.
  243. memset( &soldier, 0, sizeof( SOLDIERTYPE ) );
  244. soldier.bLevel = 0;
  245. soldier.bTeam = 1;
  246. soldier.sGridNo = sSweetGridNo;
  247. sTop = ubRadius;
  248. sBottom = -ubRadius;
  249. sLeft = - ubRadius;
  250. sRight = ubRadius;
  251. // If we are already at this gridno....
  252. if ( pSoldier->sGridNo == sSweetGridNo && !( pSoldier->uiStatusFlags & SOLDIER_VEHICLE ) )
  253. {
  254. *pubDirection = pSoldier->bDirection;
  255. return( sSweetGridNo );
  256. }
  257. //clear the mapelements of potential residue MAPELEMENT_REACHABLE flags
  258. //in the square region.
  259. // ATE: CHECK FOR BOUNDARIES!!!!!!
  260. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  261. {
  262. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  263. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  264. {
  265. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  266. if( sGridNo >=0 && sGridNo < WORLD_MAX && sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS ) )
  267. {
  268. gpWorldLevelData[ sGridNo ].uiFlags &= (~MAPELEMENT_REACHABLE);
  269. }
  270. }
  271. }
  272. //Now, find out which of these gridnos are reachable
  273. //(use the fake soldier and the pathing settings)
  274. FindBestPath( &soldier, NOWHERE, 0, WALKING, COPYREACHABLE, ( PATH_IGNORE_PERSON_AT_DEST | PATH_THROUGH_PEOPLE ) );
  275. uiLowestRange = 999999;
  276. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  277. {
  278. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  279. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  280. {
  281. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  282. if( sGridNo >=0 && sGridNo < WORLD_MAX && sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS )
  283. && gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE )
  284. {
  285. // Go on sweet stop
  286. if ( NewOKDestination( pSoldier, sGridNo, TRUE, pSoldier->bLevel ) )
  287. {
  288. BOOLEAN fDirectionFound = FALSE;
  289. UINT16 usOKToAddStructID;
  290. STRUCTURE_FILE_REF * pStructureFileRef;
  291. UINT16 usAnimSurface;
  292. if ( pSoldier->pLevelNode != NULL )
  293. {
  294. if ( pSoldier->pLevelNode->pStructureData != NULL )
  295. {
  296. usOKToAddStructID = pSoldier->pLevelNode->pStructureData->usStructureID;
  297. }
  298. else
  299. {
  300. usOKToAddStructID = INVALID_STRUCTURE_ID;
  301. }
  302. }
  303. else
  304. {
  305. usOKToAddStructID = INVALID_STRUCTURE_ID;
  306. }
  307. // Get animation surface...
  308. usAnimSurface = DetermineSoldierAnimationSurface( pSoldier, usAnimState );
  309. // Get structure ref...
  310. pStructureFileRef = GetAnimationStructureRef( pSoldier->ubID, usAnimSurface, usAnimState );
  311. if( !pStructureFileRef )
  312. {
  313. Assert( 0 );
  314. }
  315. // Check each struct in each direction
  316. for( cnt3 = 0; cnt3 < 8; cnt3++ )
  317. {
  318. if (OkayToAddStructureToWorld( (INT16)sGridNo, pSoldier->bLevel, &(pStructureFileRef->pDBStructureRef[gOneCDirection[ cnt3 ]]), usOKToAddStructID ) )
  319. {
  320. fDirectionFound = TRUE;
  321. break;
  322. }
  323. }
  324. if ( fDirectionFound )
  325. {
  326. if ( fClosestToMerc )
  327. {
  328. uiRange = FindBestPath( pSoldier, sGridNo, pSoldier->bLevel, pSoldier->usUIMovementMode, NO_COPYROUTE, 0 );
  329. if (uiRange == 0 )
  330. {
  331. uiRange = 999;
  332. }
  333. }
  334. else
  335. {
  336. uiRange = GetRangeInCellCoordsFromGridNoDiff( sSweetGridNo, sGridNo );
  337. }
  338. if ( uiRange < uiLowestRange )
  339. {
  340. ubBestDirection = (UINT8)cnt3;
  341. sLowestGridNo = sGridNo;
  342. uiLowestRange = uiRange;
  343. fFound = TRUE;
  344. }
  345. }
  346. }
  347. }
  348. }
  349. }
  350. gubNPCAPBudget = ubSaveNPCAPBudget;
  351. gubNPCDistLimit = ubSaveNPCDistLimit;
  352. if ( fFound )
  353. {
  354. // Set direction we chose...
  355. *pubDirection = ubBestDirection;
  356. return( sLowestGridNo );
  357. }
  358. else
  359. {
  360. return( NOWHERE );
  361. }
  362. }
  363. UINT16 FindGridNoFromSweetSpotWithStructDataUsingGivenDirectionFirst( SOLDIERTYPE *pSoldier, UINT16 usAnimState, INT16 sSweetGridNo, INT8 ubRadius, UINT8 *pubDirection, BOOLEAN fClosestToMerc, INT8 bGivenDirection )
  364. {
  365. INT16 sTop, sBottom;
  366. INT16 sLeft, sRight;
  367. INT16 cnt1, cnt2, cnt3;
  368. INT16 sGridNo;
  369. INT32 uiRange, uiLowestRange = 999999;
  370. INT16 sLowestGridNo=-1;
  371. INT32 leftmost;
  372. BOOLEAN fFound = FALSE;
  373. SOLDIERTYPE soldier;
  374. UINT8 ubSaveNPCAPBudget;
  375. UINT8 ubSaveNPCDistLimit;
  376. UINT8 ubBestDirection=0;
  377. //Save AI pathing vars. changing the distlimit restricts how
  378. //far away the pathing will consider.
  379. ubSaveNPCAPBudget = gubNPCAPBudget;
  380. ubSaveNPCDistLimit = gubNPCDistLimit;
  381. gubNPCAPBudget = 0;
  382. gubNPCDistLimit = ubRadius;
  383. //create dummy soldier, and use the pathing to determine which nearby slots are
  384. //reachable.
  385. memset( &soldier, 0, sizeof( SOLDIERTYPE ) );
  386. soldier.bLevel = 0;
  387. soldier.bTeam = 1;
  388. soldier.sGridNo = sSweetGridNo;
  389. sTop = ubRadius;
  390. sBottom = -ubRadius;
  391. sLeft = - ubRadius;
  392. sRight = ubRadius;
  393. // If we are already at this gridno....
  394. if ( pSoldier->sGridNo == sSweetGridNo && !( pSoldier->uiStatusFlags & SOLDIER_VEHICLE ) )
  395. {
  396. *pubDirection = pSoldier->bDirection;
  397. return( sSweetGridNo );
  398. }
  399. //clear the mapelements of potential residue MAPELEMENT_REACHABLE flags
  400. //in the square region.
  401. // ATE: CHECK FOR BOUNDARIES!!!!!!
  402. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  403. {
  404. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  405. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  406. {
  407. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  408. if( sGridNo >=0 && sGridNo < WORLD_MAX && sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS ) )
  409. {
  410. gpWorldLevelData[ sGridNo ].uiFlags &= (~MAPELEMENT_REACHABLE);
  411. }
  412. }
  413. }
  414. //Now, find out which of these gridnos are reachable
  415. //(use the fake soldier and the pathing settings)
  416. FindBestPath( &soldier, NOWHERE, 0, WALKING, COPYREACHABLE, ( PATH_IGNORE_PERSON_AT_DEST | PATH_THROUGH_PEOPLE ) );
  417. uiLowestRange = 999999;
  418. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  419. {
  420. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  421. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  422. {
  423. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  424. if( sGridNo >=0 && sGridNo < WORLD_MAX && sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS )
  425. && gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE )
  426. {
  427. // Go on sweet stop
  428. if ( NewOKDestination( pSoldier, sGridNo, TRUE, pSoldier->bLevel ) )
  429. {
  430. BOOLEAN fDirectionFound = FALSE;
  431. UINT16 usOKToAddStructID;
  432. STRUCTURE_FILE_REF * pStructureFileRef;
  433. UINT16 usAnimSurface;
  434. if ( pSoldier->pLevelNode != NULL )
  435. {
  436. if ( pSoldier->pLevelNode->pStructureData != NULL )
  437. {
  438. usOKToAddStructID = pSoldier->pLevelNode->pStructureData->usStructureID;
  439. }
  440. else
  441. {
  442. usOKToAddStructID = INVALID_STRUCTURE_ID;
  443. }
  444. }
  445. else
  446. {
  447. usOKToAddStructID = INVALID_STRUCTURE_ID;
  448. }
  449. // Get animation surface...
  450. usAnimSurface = DetermineSoldierAnimationSurface( pSoldier, usAnimState );
  451. // Get structure ref...
  452. pStructureFileRef = GetAnimationStructureRef( pSoldier->ubID, usAnimSurface, usAnimState );
  453. if( !pStructureFileRef )
  454. {
  455. Assert( 0 );
  456. }
  457. // OK, check the perfered given direction first
  458. if (OkayToAddStructureToWorld( (INT16)sGridNo, pSoldier->bLevel, &(pStructureFileRef->pDBStructureRef[gOneCDirection[ bGivenDirection ]]), usOKToAddStructID ) )
  459. {
  460. fDirectionFound = TRUE;
  461. cnt3 = bGivenDirection;
  462. }
  463. else
  464. {
  465. // Check each struct in each direction
  466. for( cnt3 = 0; cnt3 < 8; cnt3++ )
  467. {
  468. if ( cnt3 != bGivenDirection )
  469. {
  470. if (OkayToAddStructureToWorld( (INT16)sGridNo, pSoldier->bLevel, &(pStructureFileRef->pDBStructureRef[gOneCDirection[ cnt3 ]]), usOKToAddStructID ) )
  471. {
  472. fDirectionFound = TRUE;
  473. break;
  474. }
  475. }
  476. }
  477. }
  478. if ( fDirectionFound )
  479. {
  480. if ( fClosestToMerc )
  481. {
  482. uiRange = FindBestPath( pSoldier, sGridNo, pSoldier->bLevel, pSoldier->usUIMovementMode, NO_COPYROUTE, 0 );
  483. if (uiRange == 0 )
  484. {
  485. uiRange = 999;
  486. }
  487. }
  488. else
  489. {
  490. uiRange = GetRangeInCellCoordsFromGridNoDiff( sSweetGridNo, sGridNo );
  491. }
  492. if ( uiRange < uiLowestRange )
  493. {
  494. ubBestDirection = (UINT8)cnt3;
  495. sLowestGridNo = sGridNo;
  496. uiLowestRange = uiRange;
  497. fFound = TRUE;
  498. }
  499. }
  500. }
  501. }
  502. }
  503. }
  504. gubNPCAPBudget = ubSaveNPCAPBudget;
  505. gubNPCDistLimit = ubSaveNPCDistLimit;
  506. if ( fFound )
  507. {
  508. // Set direction we chose...
  509. *pubDirection = ubBestDirection;
  510. return( sLowestGridNo );
  511. }
  512. else
  513. {
  514. return( NOWHERE );
  515. }
  516. }
  517. UINT16 FindGridNoFromSweetSpotWithStructDataFromSoldier( SOLDIERTYPE *pSoldier, UINT16 usAnimState, INT8 ubRadius, UINT8 *pubDirection, BOOLEAN fClosestToMerc, SOLDIERTYPE *pSrcSoldier )
  518. {
  519. INT16 sTop, sBottom;
  520. INT16 sLeft, sRight;
  521. INT16 cnt1, cnt2, cnt3;
  522. INT16 sGridNo;
  523. INT32 uiRange, uiLowestRange = 999999;
  524. INT16 sLowestGridNo=-1;
  525. INT32 leftmost;
  526. BOOLEAN fFound = FALSE;
  527. UINT8 ubSaveNPCAPBudget;
  528. UINT8 ubSaveNPCDistLimit;
  529. UINT8 ubBestDirection=0;
  530. INT16 sSweetGridNo;
  531. SOLDIERTYPE soldier;
  532. sSweetGridNo = pSrcSoldier->sGridNo;
  533. //Save AI pathing vars. changing the distlimit restricts how
  534. //far away the pathing will consider.
  535. ubSaveNPCAPBudget = gubNPCAPBudget;
  536. ubSaveNPCDistLimit = gubNPCDistLimit;
  537. gubNPCAPBudget = 0;
  538. gubNPCDistLimit = ubRadius;
  539. //create dummy soldier, and use the pathing to determine which nearby slots are
  540. //reachable.
  541. memset( &soldier, 0, sizeof( SOLDIERTYPE ) );
  542. soldier.bLevel = 0;
  543. soldier.bTeam = 1;
  544. soldier.sGridNo = sSweetGridNo;
  545. sTop = ubRadius;
  546. sBottom = -ubRadius;
  547. sLeft = - ubRadius;
  548. sRight = ubRadius;
  549. //clear the mapelements of potential residue MAPELEMENT_REACHABLE flags
  550. //in the square region.
  551. // ATE: CHECK FOR BOUNDARIES!!!!!!
  552. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  553. {
  554. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  555. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  556. {
  557. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  558. if( sGridNo >=0 && sGridNo < WORLD_MAX && sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS ) )
  559. {
  560. gpWorldLevelData[ sGridNo ].uiFlags &= (~MAPELEMENT_REACHABLE);
  561. }
  562. }
  563. }
  564. //Now, find out which of these gridnos are reachable
  565. FindBestPath( &soldier, NOWHERE, 0, WALKING, COPYREACHABLE, ( PATH_IGNORE_PERSON_AT_DEST | PATH_THROUGH_PEOPLE ) );
  566. uiLowestRange = 999999;
  567. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  568. {
  569. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  570. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  571. {
  572. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  573. if( sGridNo >=0 && sGridNo < WORLD_MAX && sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS )
  574. && gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE )
  575. {
  576. // Go on sweet stop
  577. if ( NewOKDestination( pSoldier, sGridNo, TRUE, pSoldier->bLevel ) )
  578. {
  579. BOOLEAN fDirectionFound = FALSE;
  580. UINT16 usOKToAddStructID;
  581. STRUCTURE_FILE_REF * pStructureFileRef;
  582. UINT16 usAnimSurface;
  583. if ( fClosestToMerc != 3 )
  584. {
  585. if ( pSoldier->pLevelNode != NULL && pSoldier->pLevelNode->pStructureData != NULL )
  586. {
  587. usOKToAddStructID = pSoldier->pLevelNode->pStructureData->usStructureID;
  588. }
  589. else
  590. {
  591. usOKToAddStructID = INVALID_STRUCTURE_ID;
  592. }
  593. // Get animation surface...
  594. usAnimSurface = DetermineSoldierAnimationSurface( pSoldier, usAnimState );
  595. // Get structure ref...
  596. pStructureFileRef = GetAnimationStructureRef( pSoldier->ubID, usAnimSurface, usAnimState );
  597. // Check each struct in each direction
  598. for( cnt3 = 0; cnt3 < 8; cnt3++ )
  599. {
  600. if (OkayToAddStructureToWorld( (INT16)sGridNo, pSoldier->bLevel, &(pStructureFileRef->pDBStructureRef[gOneCDirection[ cnt3 ]]), usOKToAddStructID ) )
  601. {
  602. fDirectionFound = TRUE;
  603. break;
  604. }
  605. }
  606. }
  607. else
  608. {
  609. fDirectionFound = TRUE;
  610. cnt3 = (UINT8)Random( 8 );
  611. }
  612. if ( fDirectionFound )
  613. {
  614. if ( fClosestToMerc == 1 )
  615. {
  616. uiRange = GetRangeInCellCoordsFromGridNoDiff( pSoldier->sGridNo, sGridNo );
  617. }
  618. else if ( fClosestToMerc == 2 )
  619. {
  620. uiRange = GetRangeInCellCoordsFromGridNoDiff( pSoldier->sGridNo, sGridNo ) + GetRangeInCellCoordsFromGridNoDiff( sSweetGridNo, sGridNo );
  621. }
  622. else
  623. {
  624. //uiRange = GetRangeInCellCoordsFromGridNoDiff( sSweetGridNo, sGridNo );
  625. uiRange = abs((sSweetGridNo / MAXCOL) - (sGridNo / MAXCOL)) +
  626. abs((sSweetGridNo % MAXROW) - (sGridNo % MAXROW));
  627. }
  628. if ( uiRange < uiLowestRange || (uiRange == uiLowestRange && PythSpacesAway( pSoldier->sGridNo, sGridNo ) < PythSpacesAway( pSoldier->sGridNo, sLowestGridNo ) ) )
  629. {
  630. ubBestDirection = (UINT8)cnt3;
  631. sLowestGridNo = sGridNo;
  632. uiLowestRange = uiRange;
  633. fFound = TRUE;
  634. }
  635. }
  636. }
  637. }
  638. }
  639. }
  640. gubNPCAPBudget = ubSaveNPCAPBudget;
  641. gubNPCDistLimit = ubSaveNPCDistLimit;
  642. if ( fFound )
  643. {
  644. // Set direction we chose...
  645. *pubDirection = ubBestDirection;
  646. return( sLowestGridNo );
  647. }
  648. else
  649. {
  650. return( NOWHERE );
  651. }
  652. }
  653. UINT16 FindGridNoFromSweetSpotExcludingSweetSpot( SOLDIERTYPE *pSoldier, INT16 sSweetGridNo, INT8 ubRadius, UINT8 *pubDirection )
  654. {
  655. INT16 sTop, sBottom;
  656. INT16 sLeft, sRight;
  657. INT16 cnt1, cnt2;
  658. INT16 sGridNo;
  659. INT32 uiRange, uiLowestRange = 999999;
  660. INT16 sLowestGridNo=-1;
  661. INT32 leftmost;
  662. BOOLEAN fFound = FALSE;
  663. sTop = ubRadius;
  664. sBottom = -ubRadius;
  665. sLeft = - ubRadius;
  666. sRight = ubRadius;
  667. uiLowestRange = 999999;
  668. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  669. {
  670. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  671. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  672. {
  673. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  674. if ( sSweetGridNo == sGridNo )
  675. {
  676. continue;
  677. }
  678. if ( sGridNo >=0 && sGridNo < WORLD_MAX &&
  679. sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS ) )
  680. {
  681. // Go on sweet stop
  682. if ( NewOKDestination( pSoldier, sGridNo, TRUE, pSoldier->bLevel ) )
  683. {
  684. uiRange = GetRangeInCellCoordsFromGridNoDiff( sSweetGridNo, sGridNo );
  685. if ( uiRange < uiLowestRange )
  686. {
  687. sLowestGridNo = sGridNo;
  688. uiLowestRange = uiRange;
  689. fFound = TRUE;
  690. }
  691. }
  692. }
  693. }
  694. }
  695. if ( fFound )
  696. {
  697. // Set direction to center of map!
  698. *pubDirection = (UINT8)GetDirectionToGridNoFromGridNo( sLowestGridNo, ( ( ( WORLD_ROWS / 2 ) * WORLD_COLS ) + ( WORLD_COLS / 2 ) ) );
  699. return( sLowestGridNo );
  700. }
  701. else
  702. {
  703. return( NOWHERE );
  704. }
  705. }
  706. UINT16 FindGridNoFromSweetSpotExcludingSweetSpotInQuardent( SOLDIERTYPE *pSoldier, INT16 sSweetGridNo, INT8 ubRadius, UINT8 *pubDirection, INT8 ubQuardentDir )
  707. {
  708. INT16 sTop, sBottom;
  709. INT16 sLeft, sRight;
  710. INT16 cnt1, cnt2;
  711. INT16 sGridNo;
  712. INT32 uiRange, uiLowestRange = 999999;
  713. INT16 sLowestGridNo=-1;
  714. INT32 leftmost;
  715. BOOLEAN fFound = FALSE;
  716. sTop = ubRadius;
  717. sBottom = -ubRadius;
  718. sLeft = - ubRadius;
  719. sRight = ubRadius;
  720. // Switch on quadrent
  721. if ( ubQuardentDir == SOUTHEAST )
  722. {
  723. sBottom = 0;
  724. sLeft = 0;
  725. }
  726. uiLowestRange = 999999;
  727. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  728. {
  729. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  730. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  731. {
  732. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  733. if ( sSweetGridNo == sGridNo )
  734. {
  735. continue;
  736. }
  737. if ( sGridNo >=0 && sGridNo < WORLD_MAX &&
  738. sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS ) )
  739. {
  740. // Go on sweet stop
  741. if ( NewOKDestination( pSoldier, sGridNo, TRUE, pSoldier->bLevel ) )
  742. {
  743. uiRange = GetRangeInCellCoordsFromGridNoDiff( sSweetGridNo, sGridNo );
  744. if ( uiRange < uiLowestRange )
  745. {
  746. sLowestGridNo = sGridNo;
  747. uiLowestRange = uiRange;
  748. fFound = TRUE;
  749. }
  750. }
  751. }
  752. }
  753. }
  754. if ( fFound )
  755. {
  756. // Set direction to center of map!
  757. *pubDirection = (UINT8)GetDirectionToGridNoFromGridNo( sLowestGridNo, ( ( ( WORLD_ROWS / 2 ) * WORLD_COLS ) + ( WORLD_COLS / 2 ) ) );
  758. return( sLowestGridNo );
  759. }
  760. else
  761. {
  762. return( NOWHERE );
  763. }
  764. }
  765. BOOLEAN CanSoldierReachGridNoInGivenTileLimit( SOLDIERTYPE *pSoldier, INT16 sGridNo, INT16 sMaxTiles, INT8 bLevel )
  766. {
  767. INT32 iNumTiles;
  768. INT16 sActionGridNo;
  769. UINT8 ubDirection;
  770. if ( pSoldier->bLevel != bLevel )
  771. {
  772. return( FALSE );
  773. }
  774. sActionGridNo = FindAdjacentGridEx( pSoldier, sGridNo, &ubDirection, NULL, FALSE, FALSE );
  775. if ( sActionGridNo == -1 )
  776. {
  777. sActionGridNo = sGridNo;
  778. }
  779. if ( sActionGridNo == pSoldier->sGridNo )
  780. {
  781. return( TRUE );
  782. }
  783. iNumTiles = FindBestPath( pSoldier, sActionGridNo, pSoldier->bLevel, WALKING, NO_COPYROUTE, PATH_IGNORE_PERSON_AT_DEST );
  784. if ( iNumTiles <= sMaxTiles && iNumTiles != 0 )
  785. {
  786. return( TRUE );
  787. }
  788. else
  789. {
  790. return( FALSE );
  791. }
  792. }
  793. UINT16 FindRandomGridNoFromSweetSpot( SOLDIERTYPE *pSoldier, INT16 sSweetGridNo, INT8 ubRadius, UINT8 *pubDirection )
  794. {
  795. INT16 sX, sY;
  796. INT16 sGridNo;
  797. INT32 leftmost;
  798. BOOLEAN fFound = FALSE;
  799. UINT32 cnt = 0;
  800. SOLDIERTYPE soldier;
  801. UINT8 ubSaveNPCAPBudget;
  802. UINT8 ubSaveNPCDistLimit;
  803. UINT8 ubBestDirection=0;
  804. INT16 sTop, sBottom;
  805. INT16 sLeft, sRight;
  806. INT16 cnt1, cnt2;
  807. UINT8 ubRoomNum;
  808. //Save AI pathing vars. changing the distlimit restricts how
  809. //far away the pathing will consider.
  810. ubSaveNPCAPBudget = gubNPCAPBudget;
  811. ubSaveNPCDistLimit = gubNPCDistLimit;
  812. gubNPCAPBudget = 0;
  813. gubNPCDistLimit = ubRadius;
  814. //create dummy soldier, and use the pathing to determine which nearby slots are
  815. //reachable.
  816. memset( &soldier, 0, sizeof( SOLDIERTYPE ) );
  817. soldier.bLevel = 0;
  818. soldier.bTeam = 1;
  819. soldier.sGridNo = sSweetGridNo;
  820. sTop = ubRadius;
  821. sBottom = -ubRadius;
  822. sLeft = - ubRadius;
  823. sRight = ubRadius;
  824. // ATE: CHECK FOR BOUNDARIES!!!!!!
  825. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  826. {
  827. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  828. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  829. {
  830. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  831. if( sGridNo >=0 && sGridNo < WORLD_MAX && sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS ) )
  832. {
  833. gpWorldLevelData[ sGridNo ].uiFlags &= (~MAPELEMENT_REACHABLE);
  834. }
  835. }
  836. }
  837. //Now, find out which of these gridnos are reachable
  838. //(use the fake soldier and the pathing settings)
  839. FindBestPath( &soldier, NOWHERE, 0, WALKING, COPYREACHABLE, ( PATH_IGNORE_PERSON_AT_DEST | PATH_THROUGH_PEOPLE ) );
  840. do
  841. {
  842. sX = (UINT16)Random( ubRadius );
  843. sY = (UINT16)Random( ubRadius );
  844. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * sY ) )/ WORLD_COLS ) * WORLD_COLS;
  845. sGridNo = sSweetGridNo + ( WORLD_COLS * sY ) + sX;
  846. if ( sGridNo >=0 && sGridNo < WORLD_MAX &&
  847. sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS )
  848. && gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE )
  849. {
  850. // Go on sweet stop
  851. if ( NewOKDestination( pSoldier, sGridNo, TRUE , pSoldier->bLevel) )
  852. {
  853. // If we are a crow, we need this additional check
  854. if ( pSoldier->ubBodyType == CROW )
  855. {
  856. if ( !InARoom( sGridNo, &ubRoomNum ) )
  857. {
  858. fFound = TRUE;
  859. }
  860. }
  861. else
  862. {
  863. fFound = TRUE;
  864. }
  865. }
  866. }
  867. cnt++;
  868. if ( cnt > 2000 )
  869. {
  870. return( NOWHERE );
  871. }
  872. } while( !fFound );
  873. // Set direction to center of map!
  874. *pubDirection = (UINT8)GetDirectionToGridNoFromGridNo( sGridNo, ( ( ( WORLD_ROWS / 2 ) * WORLD_COLS ) + ( WORLD_COLS / 2 ) ) );
  875. gubNPCAPBudget = ubSaveNPCAPBudget;
  876. gubNPCDistLimit = ubSaveNPCDistLimit;
  877. return( sGridNo );
  878. }
  879. UINT16 FindRandomGridNoFromSweetSpotExcludingSweetSpot( SOLDIERTYPE *pSoldier, INT16 sSweetGridNo, INT8 ubRadius, UINT8 *pubDirection )
  880. {
  881. INT16 sX, sY;
  882. INT16 sGridNo;
  883. INT32 leftmost;
  884. BOOLEAN fFound = FALSE;
  885. UINT32 cnt = 0;
  886. do
  887. {
  888. sX = (UINT16)Random( ubRadius );
  889. sY = (UINT16)Random( ubRadius );
  890. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * sY ) )/ WORLD_COLS ) * WORLD_COLS;
  891. sGridNo = sSweetGridNo + ( WORLD_COLS * sY ) + sX;
  892. if ( sGridNo == sSweetGridNo )
  893. {
  894. continue;
  895. }
  896. if ( sGridNo >=0 && sGridNo < WORLD_MAX &&
  897. sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS ) )
  898. {
  899. // Go on sweet stop
  900. if ( NewOKDestination( pSoldier, sGridNo, TRUE, pSoldier->bLevel ) )
  901. {
  902. fFound = TRUE;
  903. }
  904. }
  905. cnt++;
  906. if ( cnt > 2000 )
  907. {
  908. return( NOWHERE );
  909. }
  910. } while( !fFound );
  911. // Set direction to center of map!
  912. *pubDirection = (UINT8)GetDirectionToGridNoFromGridNo( sGridNo, ( ( ( WORLD_ROWS / 2 ) * WORLD_COLS ) + ( WORLD_COLS / 2 ) ) );
  913. return( sGridNo );
  914. }
  915. BOOLEAN InternalAddSoldierToSector( UINT8 ubID, BOOLEAN fCalculateDirection, BOOLEAN fUseAnimation, UINT16 usAnimState, UINT16 usAnimCode )
  916. {
  917. UINT8 ubDirection, ubCalculatedDirection;
  918. SOLDIERTYPE *pSoldier;
  919. INT16 sGridNo;
  920. INT16 sExitGridNo;
  921. pSoldier = MercPtrs[ ubID ];
  922. if ( pSoldier->bActive )
  923. {
  924. // ATE: Make sure life of elliot is OK if from a meanwhile
  925. if ( AreInMeanwhile() && pSoldier->ubProfile == ELLIOT )
  926. {
  927. if ( pSoldier->bLife < OKLIFE )
  928. {
  929. pSoldier->bLife = 25;
  930. }
  931. }
  932. // ADD SOLDIER TO SLOT!
  933. if (pSoldier->uiStatusFlags & SOLDIER_OFF_MAP)
  934. {
  935. AddAwaySlot( pSoldier );
  936. // Guy is NOT "in sector"
  937. pSoldier->bInSector = FALSE;
  938. }
  939. else
  940. {
  941. AddMercSlot( pSoldier );
  942. // Add guy to sector flag
  943. pSoldier->bInSector = TRUE;
  944. }
  945. // If a driver or passenger - stop here!
  946. if ( pSoldier->uiStatusFlags & SOLDIER_DRIVER || pSoldier->uiStatusFlags & SOLDIER_PASSENGER )
  947. {
  948. return( FALSE );
  949. }
  950. // Add to panel
  951. CheckForAndAddMercToTeamPanel( pSoldier );
  952. pSoldier->usQuoteSaidFlags &= (~SOLDIER_QUOTE_SAID_SPOTTING_CREATURE_ATTACK);
  953. pSoldier->usQuoteSaidFlags &= (~SOLDIER_QUOTE_SAID_SMELLED_CREATURE);
  954. pSoldier->usQuoteSaidFlags &= (~SOLDIER_QUOTE_SAID_WORRIED_ABOUT_CREATURES);
  955. // Add to interface if the are ours
  956. if ( pSoldier->bTeam == CREATURE_TEAM )
  957. {
  958. sGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, STANDING, pSoldier->sInsertionGridNo, 7, &ubCalculatedDirection, FALSE );
  959. if( fCalculateDirection )
  960. ubDirection = ubCalculatedDirection;
  961. else
  962. ubDirection = pSoldier->ubInsertionDirection;
  963. }
  964. else
  965. {
  966. if( pSoldier->sInsertionGridNo == NOWHERE )
  967. { //Add the soldier to the respective entrypoint. This is an error condition.
  968. }
  969. if( pSoldier->uiStatusFlags & SOLDIER_VEHICLE )
  970. {
  971. sGridNo = FindGridNoFromSweetSpotWithStructDataUsingGivenDirectionFirst( pSoldier, STANDING, pSoldier->sInsertionGridNo, 12, &ubCalculatedDirection, FALSE, pSoldier->ubInsertionDirection );
  972. // ATE: Override insertion direction
  973. pSoldier->ubInsertionDirection = ubCalculatedDirection;
  974. }
  975. else
  976. {
  977. sGridNo = FindGridNoFromSweetSpot( pSoldier, pSoldier->sInsertionGridNo, 7, &ubCalculatedDirection );
  978. // ATE: Error condition - if nowhere use insertion gridno!
  979. if ( sGridNo == NOWHERE )
  980. {
  981. sGridNo = pSoldier->sInsertionGridNo;
  982. }
  983. }
  984. // Override calculated direction if we were told to....
  985. if ( pSoldier->ubInsertionDirection > 100 )
  986. {
  987. pSoldier->ubInsertionDirection = pSoldier->ubInsertionDirection - 100;
  988. fCalculateDirection = FALSE;
  989. }
  990. if ( fCalculateDirection )
  991. {
  992. ubDirection = ubCalculatedDirection;
  993. // Check if we need to get direction from exit grid...
  994. if ( pSoldier->bUseExitGridForReentryDirection )
  995. {
  996. pSoldier->bUseExitGridForReentryDirection = FALSE;
  997. // OK, we know there must be an exit gridno SOMEWHERE close...
  998. sExitGridNo = FindClosestExitGrid( pSoldier, sGridNo, 10 );
  999. if ( sExitGridNo != NOWHERE )
  1000. {
  1001. // We found one
  1002. // Calculate direction...
  1003. ubDirection = (UINT8)GetDirectionToGridNoFromGridNo( sExitGridNo, sGridNo );
  1004. }
  1005. }
  1006. }
  1007. else
  1008. {
  1009. ubDirection = pSoldier->ubInsertionDirection;
  1010. }
  1011. }
  1012. //Add
  1013. if(gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
  1014. AddSoldierToSectorGridNo( pSoldier, sGridNo, pSoldier->bDirection, fUseAnimation, usAnimState, usAnimCode );
  1015. else
  1016. AddSoldierToSectorGridNo( pSoldier, sGridNo, ubDirection, fUseAnimation, usAnimState, usAnimCode );
  1017. CheckForPotentialAddToBattleIncrement( pSoldier );
  1018. return( TRUE );
  1019. }
  1020. return( FALSE );
  1021. }
  1022. BOOLEAN AddSoldierToSector( UINT8 ubID )
  1023. {
  1024. return( InternalAddSoldierToSector( ubID, TRUE, FALSE, 0 , 0) );
  1025. }
  1026. BOOLEAN AddSoldierToSectorNoCalculateDirection( UINT8 ubID )
  1027. {
  1028. return( InternalAddSoldierToSector( ubID, FALSE, FALSE, 0, 0 ) );
  1029. }
  1030. BOOLEAN AddSoldierToSectorNoCalculateDirectionUseAnimation( UINT8 ubID, UINT16 usAnimState, UINT16 usAnimCode )
  1031. {
  1032. return( InternalAddSoldierToSector( ubID, FALSE, TRUE, usAnimState, usAnimCode ) );
  1033. }
  1034. void InternalSoldierInSectorSleep( SOLDIERTYPE *pSoldier, INT16 sGridNo, BOOLEAN fDoTransition )
  1035. {
  1036. INT16 sWorldX, sWorldY;
  1037. UINT8 ubNewDirection;
  1038. INT16 sGoodGridNo;
  1039. UINT16 usAnim = SLEEPING;
  1040. if ( !pSoldier->bInSector )
  1041. {
  1042. return;
  1043. }
  1044. if ( AM_AN_EPC( pSoldier ) )
  1045. {
  1046. usAnim = STANDING;
  1047. }
  1048. // OK, look for sutable placement....
  1049. sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, usAnim, sGridNo, 5, &ubNewDirection, FALSE );
  1050. sWorldX = CenterX( sGoodGridNo );
  1051. sWorldY = CenterY( sGoodGridNo );
  1052. EVENT_SetSoldierPosition( pSoldier, sWorldX, sWorldY );
  1053. EVENT_SetSoldierDirection( pSoldier, ubNewDirection );
  1054. EVENT_SetSoldierDesiredDirection( pSoldier, ubNewDirection );
  1055. //pSoldier->bDesiredDirection = pSoldier->bDirection;
  1056. if ( AM_AN_EPC( pSoldier ) )
  1057. {
  1058. EVENT_InitNewSoldierAnim( pSoldier, STANDING, 1, TRUE );
  1059. }
  1060. else
  1061. {
  1062. if ( fDoTransition )
  1063. {
  1064. EVENT_InitNewSoldierAnim( pSoldier, GOTO_SLEEP, 1, TRUE );
  1065. }
  1066. else
  1067. {
  1068. EVENT_InitNewSoldierAnim( pSoldier, SLEEPING, 1, TRUE );
  1069. }
  1070. }
  1071. }
  1072. void SoldierInSectorIncompaciated( SOLDIERTYPE *pSoldier, INT16 sGridNo )
  1073. {
  1074. INT16 sWorldX, sWorldY;
  1075. UINT8 ubNewDirection;
  1076. INT16 sGoodGridNo;
  1077. if ( !pSoldier->bInSector )
  1078. {
  1079. return;
  1080. }
  1081. // OK, look for sutable placement....
  1082. sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, STAND_FALLFORWARD_STOP, sGridNo, 5, &ubNewDirection, FALSE );
  1083. sWorldX = CenterX( sGoodGridNo );
  1084. sWorldY = CenterY( sGoodGridNo );
  1085. EVENT_SetSoldierPosition( pSoldier, sWorldX, sWorldY );
  1086. EVENT_SetSoldierDirection( pSoldier, ubNewDirection );
  1087. EVENT_SetSoldierDesiredDirection( pSoldier, ubNewDirection );
  1088. //pSoldier->bDesiredDirection = pSoldier->bDirection;
  1089. EVENT_InitNewSoldierAnim( pSoldier, STAND_FALLFORWARD_STOP, 1, TRUE );
  1090. }
  1091. /*
  1092. void SoldierInSectorSleep( SOLDIERTYPE *pSoldier, INT16 sGridNo )
  1093. {
  1094. InternalSoldierInSectorSleep( pSoldier, sGridNo, TRUE );
  1095. }
  1096. */
  1097. void SoldierInSectorPatient( SOLDIERTYPE *pSoldier, INT16 sGridNo )
  1098. {
  1099. INT16 sWorldX, sWorldY;
  1100. UINT8 ubNewDirection;
  1101. INT16 sGoodGridNo;
  1102. if ( !pSoldier->bInSector )
  1103. {
  1104. return;
  1105. }
  1106. // OK, look for sutable placement....
  1107. sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, BEING_PATIENT, sGridNo, 5, &ubNewDirection, FALSE );
  1108. sWorldX = CenterX( sGoodGridNo );
  1109. sWorldY = CenterY( sGoodGridNo );
  1110. EVENT_SetSoldierPosition( pSoldier, sWorldX, sWorldY );
  1111. EVENT_SetSoldierDirection( pSoldier, ubNewDirection );
  1112. EVENT_SetSoldierDesiredDirection( pSoldier, ubNewDirection );
  1113. //pSoldier->bDesiredDirection = pSoldier->bDirection;
  1114. if ( !IS_MERC_BODY_TYPE( pSoldier ) )
  1115. {
  1116. EVENT_InitNewSoldierAnim( pSoldier, STANDING, 1, TRUE );
  1117. }
  1118. else
  1119. {
  1120. EVENT_InitNewSoldierAnim( pSoldier, BEING_PATIENT, 1, TRUE );
  1121. }
  1122. }
  1123. void SoldierInSectorDoctor( SOLDIERTYPE *pSoldier, INT16 sGridNo )
  1124. {
  1125. INT16 sWorldX, sWorldY;
  1126. UINT8 ubNewDirection;
  1127. INT16 sGoodGridNo;
  1128. if ( !pSoldier->bInSector )
  1129. {
  1130. return;
  1131. }
  1132. // OK, look for sutable placement....
  1133. sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, BEING_DOCTOR, sGridNo, 5, &ubNewDirection, FALSE );
  1134. sWorldX = CenterX( sGoodGridNo );
  1135. sWorldY = CenterY( sGoodGridNo );
  1136. EVENT_SetSoldierPosition( pSoldier, sWorldX, sWorldY );
  1137. EVENT_SetSoldierDirection( pSoldier, ubNewDirection );
  1138. EVENT_SetSoldierDesiredDirection( pSoldier, ubNewDirection );
  1139. //pSoldier->bDesiredDirection = pSoldier->bDirection;
  1140. if ( !IS_MERC_BODY_TYPE( pSoldier ) )
  1141. {
  1142. EVENT_InitNewSoldierAnim( pSoldier, STANDING, 1, TRUE );
  1143. }
  1144. else
  1145. {
  1146. EVENT_InitNewSoldierAnim( pSoldier, BEING_DOCTOR, 1, TRUE );
  1147. }
  1148. }
  1149. void SoldierInSectorRepair( SOLDIERTYPE *pSoldier, INT16 sGridNo )
  1150. {
  1151. INT16 sWorldX, sWorldY;
  1152. UINT8 ubNewDirection;
  1153. INT16 sGoodGridNo;
  1154. if ( !pSoldier->bInSector )
  1155. {
  1156. return;
  1157. }
  1158. // OK, look for sutable placement....
  1159. sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, BEING_REPAIRMAN, sGridNo, 5, &ubNewDirection, FALSE );
  1160. sWorldX = CenterX( sGoodGridNo );
  1161. sWorldY = CenterY( sGoodGridNo );
  1162. EVENT_SetSoldierPosition( pSoldier, sWorldX, sWorldY );
  1163. EVENT_SetSoldierDirection( pSoldier, ubNewDirection );
  1164. EVENT_SetSoldierDesiredDirection( pSoldier, ubNewDirection );
  1165. //pSoldier->bDesiredDirection = pSoldier->bDirection;
  1166. if ( !IS_MERC_BODY_TYPE( pSoldier ) )
  1167. {
  1168. EVENT_InitNewSoldierAnim( pSoldier, STANDING, 1, TRUE );
  1169. }
  1170. else
  1171. {
  1172. EVENT_InitNewSoldierAnim( pSoldier, BEING_REPAIRMAN, 1, TRUE );
  1173. }
  1174. }
  1175. extern void EVENT_SetSoldierPositionAndMaybeFinalDestAndMaybeNotDestination( SOLDIERTYPE *pSoldier, FLOAT dNewXPos, FLOAT dNewYPos, BOOLEAN fUpdateDest, BOOLEAN fUpdateFinalDest );
  1176. void AddSoldierToSectorGridNo( SOLDIERTYPE *pSoldier, INT16 sGridNo, UINT8 ubDirection, BOOLEAN fUseAnimation, UINT16 usAnimState, UINT16 usAnimCode )
  1177. {
  1178. INT16 sWorldX, sWorldY;
  1179. INT16 sNewGridNo;
  1180. UINT8 ubNewDirection;
  1181. UINT8 ubInsertionCode;
  1182. BOOLEAN fUpdateFinalPosition = TRUE;
  1183. // Add merc to gridno
  1184. sWorldX = CenterX( sGridNo );
  1185. sWorldY = CenterY( sGridNo );
  1186. // Set reserved location!
  1187. pSoldier->sReservedMovementGridNo = NOWHERE;
  1188. // Save OLD insertion code.. as this can change...
  1189. ubInsertionCode = pSoldier->ubStrategicInsertionCode;
  1190. // Remove any pending animations
  1191. pSoldier->usPendingAnimation = NO_PENDING_ANIMATION;
  1192. pSoldier->usPendingAnimation2 = NO_PENDING_ANIMATION;
  1193. pSoldier->ubPendingDirection = NO_PENDING_DIRECTION;
  1194. pSoldier->ubPendingAction = NO_PENDING_ACTION;
  1195. //If we are not loading a saved game
  1196. if( (gTacticalStatus.uiFlags & LOADING_SAVED_GAME ) )
  1197. {
  1198. // Set final dest to be the same...
  1199. fUpdateFinalPosition = FALSE;
  1200. }
  1201. // If this is a special insertion location, get path!
  1202. if ( ubInsertionCode == INSERTION_CODE_ARRIVING_GAME )
  1203. {
  1204. EVENT_SetSoldierPositionAndMaybeFinalDestAndMaybeNotDestination( pSoldier, sWorldX, sWorldY, fUpdateFinalPosition, fUpdateFinalPosition );
  1205. EVENT_SetSoldierDirection( pSoldier, ubDirection );
  1206. EVENT_SetSoldierDesiredDirection( pSoldier, ubDirection );
  1207. }
  1208. else if ( ubInsertionCode == INSERTION_CODE_CHOPPER )
  1209. {
  1210. }
  1211. else
  1212. {
  1213. EVENT_SetSoldierPositionAndMaybeFinalDestAndMaybeNotDestination( pSoldier, sWorldX, sWorldY, fUpdateFinalPosition, fUpdateFinalPosition );
  1214. //if we are loading, dont set the direction ( they are already set )
  1215. if( !(gTacticalStatus.uiFlags & LOADING_SAVED_GAME ) )
  1216. {
  1217. EVENT_SetSoldierDirection( pSoldier, ubDirection );
  1218. EVENT_SetSoldierDesiredDirection( pSoldier, ubDirection );
  1219. }
  1220. }
  1221. if( !(gTacticalStatus.uiFlags & LOADING_SAVED_GAME ) )
  1222. {
  1223. if ( !( pSoldier->uiStatusFlags & SOLDIER_DEAD ) )
  1224. {
  1225. if ( pSoldier->bTeam == gbPlayerNum )
  1226. {
  1227. RevealRoofsAndItems( pSoldier, TRUE, FALSE, pSoldier->bLevel, TRUE );
  1228. // ATE: Patch fix: If we are in an non-interruptable animation, stop!
  1229. if ( pSoldier->usAnimState == HOPFENCE )
  1230. {
  1231. pSoldier->fInNonintAnim = FALSE;
  1232. SoldierGotoStationaryStance( pSoldier );
  1233. }
  1234. EVENT_StopMerc( pSoldier, sGridNo, ubDirection );
  1235. }
  1236. }
  1237. // If just arriving, set a destination to walk into from!
  1238. if ( ubInsertionCode == INSERTION_CODE_ARRIVING_GAME )
  1239. {
  1240. // Find a sweetspot near...
  1241. sNewGridNo = FindGridNoFromSweetSpot( pSoldier, gMapInformation.sNorthGridNo, 4, &ubNewDirection );
  1242. EVENT_GetNewSoldierPath( pSoldier, sNewGridNo, WALKING );
  1243. }
  1244. // If he's an enemy... set presence
  1245. if ( !pSoldier->bNeutral && (pSoldier->bSide != gbPlayerNum ) )
  1246. {
  1247. // ATE: Added if not bloodcats
  1248. // only do this once they are seen.....
  1249. if ( pSoldier->ubBodyType != BLOODCAT )
  1250. {
  1251. SetEnemyPresence( );
  1252. }
  1253. }
  1254. }
  1255. if ( !( pSoldier->uiStatusFlags & SOLDIER_DEAD ) )
  1256. {
  1257. //if we are loading a 'pristine' map ( ie, not loading a saved game )
  1258. if( !(gTacticalStatus.uiFlags & LOADING_SAVED_GAME ) )
  1259. {
  1260. // ATE: Double check if we are on the roof that there is a roof there!
  1261. if ( pSoldier->bLevel == 1 )
  1262. {
  1263. if ( !FindStructure( pSoldier->sGridNo, STRUCTURE_ROOF ) )
  1264. {
  1265. SetSoldierHeight( pSoldier, (FLOAT)( 0 ) );
  1266. }
  1267. }
  1268. if ( ubInsertionCode != INSERTION_CODE_ARRIVING_GAME )
  1269. {
  1270. // default to standing on arrival
  1271. if ( pSoldier->usAnimState != HELIDROP )
  1272. {
  1273. if ( fUseAnimation )
  1274. {
  1275. EVENT_InitNewSoldierAnim( pSoldier, usAnimState, usAnimCode, TRUE );
  1276. }
  1277. else if ( pSoldier->ubBodyType != CROW )
  1278. {
  1279. EVENT_InitNewSoldierAnim( pSoldier, STANDING, 1, TRUE );
  1280. }
  1281. }
  1282. // ATE: if we are below OK life, make them lie down!
  1283. if ( pSoldier->bLife < OKLIFE )
  1284. {
  1285. SoldierInSectorIncompaciated( pSoldier, pSoldier->sInsertionGridNo );
  1286. }
  1287. else if ( pSoldier->fMercAsleep == TRUE )
  1288. {
  1289. InternalSoldierInSectorSleep( pSoldier, pSoldier->sInsertionGridNo, FALSE );
  1290. }
  1291. else if ( pSoldier->bAssignment == PATIENT )
  1292. {
  1293. SoldierInSectorPatient( pSoldier, pSoldier->sInsertionGridNo );
  1294. }
  1295. else if ( pSoldier->bAssignment == DOCTOR )
  1296. {
  1297. SoldierInSectorDoctor( pSoldier, pSoldier->sInsertionGridNo );
  1298. }
  1299. else if ( pSoldier->bAssignment == REPAIR )
  1300. {
  1301. SoldierInSectorRepair( pSoldier, pSoldier->sInsertionGridNo );
  1302. }
  1303. // ATE: Make sure movement mode is up to date!
  1304. pSoldier->usUIMovementMode = GetMoveStateBasedOnStance( pSoldier, gAnimControl[ pSoldier->usAnimState ].ubEndHeight );
  1305. }
  1306. }
  1307. else
  1308. {
  1309. // THIS ALL SHOULD HAVE BEEN HANDLED BY THE FACT THAT A GAME WAS LOADED
  1310. //EVENT_InitNewSoldierAnim( pSoldier, pSoldier->usAnimState, pSoldier->usAniCode, TRUE );
  1311. // if the merc had a final destination, get the merc walking there
  1312. //if( pSoldier->sFinalDestination != pSoldier->sGridNo )
  1313. //{
  1314. // EVENT_GetNewSoldierPath( pSoldier, pSoldier->sFinalDestination, pSoldier->usUIMovementMode );
  1315. //}
  1316. }
  1317. }
  1318. }
  1319. // IsMercOnTeam() checks to see if the passed in Merc Profile ID is currently on the player's team
  1320. BOOLEAN IsMercOnTeam(UINT8 ubMercID)
  1321. {
  1322. UINT16 cnt;
  1323. UINT8 ubLastTeamID;
  1324. SOLDIERTYPE *pTeamSoldier;
  1325. cnt = gTacticalStatus.Team[ OUR_TEAM ].bFirstID;
  1326. ubLastTeamID = gTacticalStatus.Team[ OUR_TEAM ].bLastID;
  1327. // look for all mercs on the same team,
  1328. for ( pTeamSoldier = MercPtrs[ cnt ]; cnt <= ubLastTeamID; cnt++,pTeamSoldier++)
  1329. {
  1330. if ( pTeamSoldier->ubProfile == ubMercID )
  1331. {
  1332. if( pTeamSoldier->bActive )
  1333. return(TRUE);
  1334. }
  1335. }
  1336. return(FALSE);
  1337. }
  1338. // ATE: Added this new function for contract renewals
  1339. BOOLEAN IsMercOnTeamAndAlive(UINT8 ubMercID)
  1340. {
  1341. UINT16 cnt;
  1342. UINT8 ubLastTeamID;
  1343. SOLDIERTYPE *pTeamSoldier;
  1344. cnt = gTacticalStatus.Team[ OUR_TEAM ].bFirstID;
  1345. ubLastTeamID = gTacticalStatus.Team[ OUR_TEAM ].bLastID;
  1346. // look for all mercs on the same team,
  1347. for ( pTeamSoldier = MercPtrs[ cnt ]; cnt <= ubLastTeamID; cnt++,pTeamSoldier++)
  1348. {
  1349. if ( pTeamSoldier->ubProfile == ubMercID )
  1350. {
  1351. if( pTeamSoldier->bActive )
  1352. {
  1353. if ( pTeamSoldier->bLife > 0 )
  1354. {
  1355. return(TRUE);
  1356. }
  1357. }
  1358. }
  1359. }
  1360. return(FALSE);
  1361. }
  1362. BOOLEAN IsMercOnTeamAndInOmertaAlready(UINT8 ubMercID)
  1363. {
  1364. UINT16 cnt;
  1365. UINT8 ubLastTeamID;
  1366. SOLDIERTYPE *pTeamSoldier;
  1367. cnt = gTacticalStatus.Team[ OUR_TEAM ].bFirstID;
  1368. ubLastTeamID = gTacticalStatus.Team[ OUR_TEAM ].bLastID;
  1369. // look for all mercs on the same team,
  1370. for ( pTeamSoldier = MercPtrs[ cnt ]; cnt <= ubLastTeamID; cnt++,pTeamSoldier++)
  1371. {
  1372. if ( pTeamSoldier->ubProfile == ubMercID )
  1373. {
  1374. if ( pTeamSoldier->bActive && pTeamSoldier->bAssignment != IN_TRANSIT )
  1375. return(TRUE);
  1376. }
  1377. }
  1378. return(FALSE);
  1379. }
  1380. BOOLEAN IsMercOnTeamAndInOmertaAlreadyAndAlive(UINT8 ubMercID)
  1381. {
  1382. UINT16 cnt;
  1383. UINT8 ubLastTeamID;
  1384. SOLDIERTYPE *pTeamSoldier;
  1385. cnt = gTacticalStatus.Team[ OUR_TEAM ].bFirstID;
  1386. ubLastTeamID = gTacticalStatus.Team[ OUR_TEAM ].bLastID;
  1387. // look for all mercs on the same team,
  1388. for ( pTeamSoldier = MercPtrs[ cnt ]; cnt <= ubLastTeamID; cnt++,pTeamSoldier++)
  1389. {
  1390. if ( pTeamSoldier->ubProfile == ubMercID )
  1391. {
  1392. if ( pTeamSoldier->bActive && pTeamSoldier->bAssignment != IN_TRANSIT )
  1393. {
  1394. if ( pTeamSoldier->bLife > 0 )
  1395. {
  1396. return(TRUE);
  1397. }
  1398. }
  1399. }
  1400. }
  1401. return(FALSE);
  1402. }
  1403. // GetSoldierIDFromMercID() Gets the Soldier ID from the Merc Profile ID, else returns -1
  1404. INT16 GetSoldierIDFromMercID(UINT8 ubMercID)
  1405. {
  1406. UINT16 cnt;
  1407. UINT8 ubLastTeamID;
  1408. SOLDIERTYPE *pTeamSoldier;
  1409. cnt = gTacticalStatus.Team[ OUR_TEAM ].bFirstID;
  1410. ubLastTeamID = gTacticalStatus.Team[ OUR_TEAM ].bLastID;
  1411. // look for all mercs on the same team,
  1412. for ( pTeamSoldier = MercPtrs[ cnt ]; cnt <= ubLastTeamID; cnt++,pTeamSoldier++)
  1413. {
  1414. if ( pTeamSoldier->ubProfile == ubMercID )
  1415. {
  1416. if( pTeamSoldier->bActive )
  1417. return( cnt );
  1418. }
  1419. }
  1420. return( -1 );
  1421. }