Rotting Corpses.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941
  1. #ifdef PRECOMPILEDHEADERS
  2. #include "Tactical All.h"
  3. #else
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include "wcheck.h"
  7. #include "stdlib.h"
  8. #include "debug.h"
  9. #include "soldier control.h"
  10. #include "weapons.h"
  11. #include "handle items.h"
  12. #include "worlddef.h"
  13. #include "worldman.h"
  14. #include "rotting corpses.h"
  15. #include "tile cache.h"
  16. #include "isometric utils.h"
  17. #include "animation control.h"
  18. #include "utilities.h"
  19. #include "game clock.h"
  20. #include "soldier create.h"
  21. #include "renderworld.h"
  22. #include "soldier add.h"
  23. #include "strategicmap.h"
  24. #include "los.h"
  25. #include "opplist.h"
  26. #include "structure.h"
  27. #include "message.h"
  28. #include "sound control.h"
  29. #include "pathai.h"
  30. #include "Random.h"
  31. #include "dialogue control.h"
  32. #include "items.h"
  33. #include "smell.h"
  34. #include "World Items.h"
  35. #include "explosion control.h"
  36. #include "GameSettings.h"
  37. #endif
  38. #define CORPSE_WARNING_MAX 5
  39. #define CORPSE_WARNING_DIST 5
  40. #define CORPSE_INDEX_OFFSET 10000
  41. //#define DELAY_UNTIL_ROTTING ( 1 * NUM_SEC_IN_DAY )
  42. #define DELAY_UNTIL_ROTTING ( 1 * NUM_SEC_IN_DAY / 60 )
  43. #define DELAY_UNTIL_DONE_ROTTING ( 3 * NUM_SEC_IN_DAY / 60 )
  44. #define MAX_NUM_CROWS 6
  45. // From lighting
  46. extern SGPPaletteEntry gpLightColors[3];
  47. extern UINT16 gusShadeLevels[16][3];
  48. void MakeCorpseVisible( SOLDIERTYPE *pSoldier, ROTTING_CORPSE *pCorpse );
  49. // When adding a corpse, add struct data...
  50. CHAR8 zCorpseFilenames[ NUM_CORPSES ][70] =
  51. {
  52. "",
  53. "ANIMS\\CORPSES\\S_D_JFK.STI",
  54. "ANIMS\\CORPSES\\S_D_BCK.STI",
  55. "ANIMS\\CORPSES\\S_D_FWD.STI",
  56. "ANIMS\\CORPSES\\S_D_DHD.STI",
  57. "ANIMS\\CORPSES\\S_D_PRN.STI",
  58. "ANIMS\\CORPSES\\S_D_WTR.STI",
  59. "ANIMS\\CORPSES\\S_D_FALL.STI",
  60. "ANIMS\\CORPSES\\S_D_FALLF.STI",
  61. "ANIMS\\CORPSES\\M_D_JFK.STI",
  62. "ANIMS\\CORPSES\\M_D_BCK.STI",
  63. "ANIMS\\CORPSES\\M_D_FWD.STI",
  64. "ANIMS\\CORPSES\\M_D_DHD.STI",
  65. "ANIMS\\CORPSES\\M_D_PRN.STI",
  66. "ANIMS\\CORPSES\\S_D_WTR.STI",
  67. "ANIMS\\CORPSES\\M_D_FALL.STI",
  68. "ANIMS\\CORPSES\\M_D_FALLF.STI",
  69. "ANIMS\\CORPSES\\F_D_JFK.STI",
  70. "ANIMS\\CORPSES\\F_D_BCK.STI",
  71. "ANIMS\\CORPSES\\F_D_FWD.STI",
  72. "ANIMS\\CORPSES\\F_D_DHD.STI",
  73. "ANIMS\\CORPSES\\F_D_PRN.STI",
  74. "ANIMS\\CORPSES\\S_D_WTR.STI",
  75. "ANIMS\\CORPSES\\F_D_FALL.STI",
  76. "ANIMS\\CORPSES\\F_D_FALLF.STI",
  77. // Civs....
  78. "ANIMS\\CORPSES\\M_DEAD1.STI",
  79. "ANIMS\\CORPSES\\K_DEAD2.STI",
  80. "ANIMS\\CORPSES\\H_DEAD2.STI",
  81. "ANIMS\\CORPSES\\FT_DEAD1.STI",
  82. "ANIMS\\CORPSES\\S_DEAD1.STI",
  83. "ANIMS\\CORPSES\\W_DEAD1.STI",
  84. "ANIMS\\CORPSES\\CP_DEAD1.STI",
  85. "ANIMS\\CORPSES\\M_DEAD2.STI",
  86. "ANIMS\\CORPSES\\K_DEAD1.STI",
  87. "ANIMS\\CORPSES\\H_DEAD1.STI",
  88. "ANIMS\\CORPSES\\FT_DEAD2.STI",
  89. "ANIMS\\CORPSES\\S_DEAD2.STI",
  90. "ANIMS\\CORPSES\\W_DEAD2.STI",
  91. "ANIMS\\CORPSES\\CP_DEAD2.STI",
  92. "ANIMS\\CORPSES\\CT_DEAD.STI",
  93. "ANIMS\\CORPSES\\CW_DEAD1.STI",
  94. "ANIMS\\CORPSES\\MN_DEAD2.STI",
  95. "ANIMS\\CORPSES\\I_DEAD1.STI",
  96. "ANIMS\\CORPSES\\L_DEAD1.STI",
  97. "ANIMS\\CORPSES\\P_DECOMP2.STI",
  98. "ANIMS\\CORPSES\\TK_WREK.STI",
  99. "ANIMS\\CORPSES\\TK2_WREK.STI",
  100. "ANIMS\\CORPSES\\HM_WREK.STI",
  101. "ANIMS\\CORPSES\\IC_WREK.STI",
  102. "ANIMS\\CORPSES\\QN_DEAD.STI",
  103. "ANIMS\\CORPSES\\J_DEAD.STI",
  104. "ANIMS\\CORPSES\\S_BURNT.STI",
  105. "ANIMS\\CORPSES\\S_EXPLD.STI",
  106. };
  107. // When adding a corpse, add struct data...
  108. CHAR8 zNoBloodCorpseFilenames[ NUM_CORPSES ][70] =
  109. {
  110. "",
  111. "ANIMS\\CORPSES\\M_D_JFK_NB.STI",
  112. "ANIMS\\CORPSES\\S_D_BCK_NB.STI",
  113. "ANIMS\\CORPSES\\S_D_FWD_NB.STI",
  114. "ANIMS\\CORPSES\\S_D_DHD_NB.STI",
  115. "ANIMS\\CORPSES\\S_D_PRN_NB.STI",
  116. "ANIMS\\CORPSES\\S_D_WTR.STI",
  117. "ANIMS\\CORPSES\\S_D_FALL_NB.STI",
  118. "ANIMS\\CORPSES\\S_D_FALLF_NB.STI",
  119. "ANIMS\\CORPSES\\M_D_JFK_NB.STI",
  120. "ANIMS\\CORPSES\\M_D_BCK_NB.STI",
  121. "ANIMS\\CORPSES\\M_D_FWD_NB.STI",
  122. "ANIMS\\CORPSES\\M_D_DHD_NB.STI",
  123. "ANIMS\\CORPSES\\M_D_PRN_NB.STI",
  124. "ANIMS\\CORPSES\\S_D_WTR.STI",
  125. "ANIMS\\CORPSES\\M_D_FALL_NB.STI",
  126. "ANIMS\\CORPSES\\M_D_FALLF_NB.STI",
  127. "ANIMS\\CORPSES\\F_D_JFK_NB.STI",
  128. "ANIMS\\CORPSES\\F_D_BCK_NB.STI",
  129. "ANIMS\\CORPSES\\F_D_FWD_NB.STI",
  130. "ANIMS\\CORPSES\\F_D_DHD_NB.STI",
  131. "ANIMS\\CORPSES\\F_D_PRN_NB.STI",
  132. "ANIMS\\CORPSES\\S_D_WTR.STI",
  133. "ANIMS\\CORPSES\\F_D_FALL_NB.STI",
  134. "ANIMS\\CORPSES\\F_D_FALLF_NB.STI",
  135. // Civs....
  136. "ANIMS\\CORPSES\\M_DEAD1_NB.STI",
  137. "ANIMS\\CORPSES\\K_DEAD2_NB.STI",
  138. "ANIMS\\CORPSES\\H_DEAD2_NB.STI",
  139. "ANIMS\\CORPSES\\FT_DEAD1_NB.STI",
  140. "ANIMS\\CORPSES\\S_DEAD1_NB.STI",
  141. "ANIMS\\CORPSES\\W_DEAD1_NB.STI",
  142. "ANIMS\\CORPSES\\CP_DEAD1_NB.STI",
  143. "ANIMS\\CORPSES\\M_DEAD2_NB.STI",
  144. "ANIMS\\CORPSES\\K_DEAD1_NB.STI",
  145. "ANIMS\\CORPSES\\H_DEAD1_NB.STI",
  146. "ANIMS\\CORPSES\\FT_DEAD2_NB.STI",
  147. "ANIMS\\CORPSES\\S_DEAD2_NB.STI",
  148. "ANIMS\\CORPSES\\W_DEAD2_NB.STI",
  149. "ANIMS\\CORPSES\\CP_DEAD2_NB.STI",
  150. "ANIMS\\CORPSES\\CT_DEAD.STI",
  151. "ANIMS\\CORPSES\\CW_DEAD1.STI",
  152. "ANIMS\\CORPSES\\MN_DEAD2.STI",
  153. "ANIMS\\CORPSES\\I_DEAD1.STI",
  154. "ANIMS\\CORPSES\\L_DEAD1.STI",
  155. "ANIMS\\CORPSES\\P_DECOMP2.STI",
  156. "ANIMS\\CORPSES\\TK_WREK.STI",
  157. "ANIMS\\CORPSES\\TK2_WREK.STI",
  158. "ANIMS\\CORPSES\\HM_WREK.STI",
  159. "ANIMS\\CORPSES\\IC_WREK.STI",
  160. "ANIMS\\CORPSES\\QN_DEAD.STI",
  161. "ANIMS\\CORPSES\\J_DEAD.STI",
  162. "ANIMS\\CORPSES\\S_BURNT.STI",
  163. "ANIMS\\CORPSES\\S_EXPLD.STI",
  164. };
  165. UINT8 gb4DirectionsFrom8[8] =
  166. {
  167. 7, // NORTH
  168. 0, // NE
  169. 0, // E
  170. 0, // SE
  171. 1, // S
  172. 0, // SW,
  173. 2, // W,
  174. 0 // NW
  175. };
  176. UINT8 gb2DirectionsFrom8[8] =
  177. {
  178. 0, // NORTH
  179. 7, // NE
  180. 7, // E
  181. 7, // SE
  182. 0, // S
  183. 7, // SW,
  184. 7, // W,
  185. 7 // NW
  186. };
  187. BOOLEAN gbCorpseValidForDecapitation[ NUM_CORPSES ] =
  188. {
  189. 0,
  190. 0,
  191. 1,
  192. 1,
  193. 1,
  194. 1,
  195. 1,
  196. 1,
  197. 1,
  198. 0,
  199. 1,
  200. 1,
  201. 1,
  202. 1,
  203. 1,
  204. 1,
  205. 1,
  206. 0,
  207. 1,
  208. 1,
  209. 1,
  210. 1,
  211. 1,
  212. 1,
  213. 1,
  214. // Civs....
  215. 1,
  216. 1,
  217. 1,
  218. 1,
  219. 1,
  220. 1,
  221. 1,
  222. 1,
  223. 1,
  224. 1,
  225. 1,
  226. 1,
  227. 1,
  228. 1,
  229. 0,
  230. 0,
  231. 0,
  232. 0,
  233. 0,
  234. 1,
  235. 0,
  236. 0,
  237. 0,
  238. 0,
  239. 0,
  240. 0,
  241. 0,
  242. 0,
  243. };
  244. INT8 gDecapitatedCorpse[ NUM_CORPSES ] =
  245. {
  246. 0,
  247. SMERC_JFK,
  248. SMERC_JFK,
  249. SMERC_JFK,
  250. SMERC_JFK,
  251. SMERC_JFK,
  252. SMERC_JFK,
  253. SMERC_JFK,
  254. SMERC_JFK,
  255. MMERC_JFK,
  256. MMERC_JFK,
  257. MMERC_JFK,
  258. MMERC_JFK,
  259. MMERC_JFK,
  260. MMERC_JFK,
  261. MMERC_JFK,
  262. MMERC_JFK,
  263. FMERC_JFK,
  264. FMERC_JFK,
  265. FMERC_JFK,
  266. FMERC_JFK,
  267. FMERC_JFK,
  268. FMERC_JFK,
  269. FMERC_JFK,
  270. FMERC_JFK,
  271. // Civs....
  272. 0,
  273. 0,
  274. 0,
  275. 0,
  276. 0,
  277. 0,
  278. 0,
  279. 0,
  280. 0,
  281. 0,
  282. 0,
  283. 0,
  284. 0,
  285. 0,
  286. 0,
  287. 0,
  288. 0,
  289. 0,
  290. 0,
  291. 0,
  292. 0,
  293. 0,
  294. 0,
  295. 0,
  296. 0,
  297. 0,
  298. 0,
  299. 0,
  300. };
  301. ROTTING_CORPSE gRottingCorpse[ MAX_ROTTING_CORPSES ];
  302. INT32 giNumRottingCorpse = 0;
  303. BOOLEAN CreateCorpsePalette( ROTTING_CORPSE *pCorpse );
  304. BOOLEAN CreateCorpseShadedPalette( ROTTING_CORPSE *pCorpse, UINT32 uiBase, SGPPaletteEntry *pShadePal);
  305. void ReduceAmmoDroppedByNonPlayerSoldiers( SOLDIERTYPE *pSoldier, INT32 iInvSlot );
  306. INT32 GetFreeRottingCorpse(void)
  307. {
  308. INT32 iCount;
  309. for(iCount=0; iCount < giNumRottingCorpse; iCount++)
  310. {
  311. if(( gRottingCorpse[iCount].fActivated == FALSE ) )
  312. return((INT32)iCount);
  313. }
  314. if(giNumRottingCorpse < MAX_ROTTING_CORPSES )
  315. return((INT32)giNumRottingCorpse++);
  316. return(-1);
  317. }
  318. void RecountRottingCorpses(void)
  319. {
  320. INT32 uiCount;
  321. if ( giNumRottingCorpse > 0 )
  322. {
  323. for(uiCount=giNumRottingCorpse-1; (uiCount >=0) ; uiCount--)
  324. {
  325. if( ( gRottingCorpse[uiCount].fActivated == FALSE ) )
  326. {
  327. giNumRottingCorpse=(UINT32)(uiCount+1);
  328. break;
  329. }
  330. }
  331. }
  332. }
  333. UINT16 GetCorpseStructIndex( ROTTING_CORPSE_DEFINITION *pCorpseDef, BOOLEAN fForImage )
  334. {
  335. INT8 bDirection;
  336. switch( pCorpseDef->ubType )
  337. {
  338. case QUEEN_MONSTER_DEAD:
  339. case BURNT_DEAD:
  340. case EXPLODE_DEAD:
  341. bDirection = 0;
  342. break;
  343. case ICECREAM_DEAD:
  344. case HUMMER_DEAD:
  345. // OK , these have 2 directions....
  346. bDirection = gb2DirectionsFrom8[ pCorpseDef->bDirection ];
  347. if ( fForImage )
  348. {
  349. bDirection = gOneCDirection[ bDirection ];
  350. }
  351. break;
  352. case SMERC_FALL:
  353. case SMERC_FALLF:
  354. case MMERC_FALL:
  355. case MMERC_FALLF:
  356. case FMERC_FALL:
  357. case FMERC_FALLF:
  358. // OK , these have 4 directions....
  359. bDirection = gb4DirectionsFrom8[ pCorpseDef->bDirection ];
  360. if ( fForImage )
  361. {
  362. bDirection = gOneCDirection[ bDirection ];
  363. }
  364. break;
  365. default:
  366. // Uses 8
  367. bDirection = pCorpseDef->bDirection;
  368. if ( fForImage )
  369. {
  370. bDirection = gOneCDirection[ bDirection ];
  371. }
  372. break;
  373. }
  374. return( bDirection );
  375. }
  376. INT32 AddRottingCorpse( ROTTING_CORPSE_DEFINITION *pCorpseDef )
  377. {
  378. INT32 iIndex;
  379. ROTTING_CORPSE *pCorpse;
  380. ANITILE_PARAMS AniParams;
  381. UINT8 ubLevelID;
  382. STRUCTURE_FILE_REF * pStructureFileRef = NULL;
  383. INT8 zFilename[150];
  384. DB_STRUCTURE_REF *pDBStructureRef;
  385. UINT8 ubLoop;
  386. INT16 sTileGridNo;
  387. DB_STRUCTURE_TILE ** ppTile;
  388. UINT16 usStructIndex;
  389. UINT32 uiDirectionUseFlag;
  390. if ( pCorpseDef->sGridNo == NOWHERE )
  391. {
  392. return( -1 );
  393. }
  394. if ( pCorpseDef->ubType == NO_CORPSE )
  395. {
  396. return( -1 );
  397. }
  398. if( ( iIndex = GetFreeRottingCorpse() )==(-1) )
  399. return(-1);
  400. pCorpse = &gRottingCorpse[ iIndex ];
  401. // Copy elements in
  402. memcpy( pCorpse, pCorpseDef, sizeof( ROTTING_CORPSE_DEFINITION ) );
  403. uiDirectionUseFlag = ANITILE_USE_DIRECTION_FOR_START_FRAME;
  404. // If we are a soecial type...
  405. switch( pCorpseDef->ubType )
  406. {
  407. case SMERC_FALL:
  408. case SMERC_FALLF:
  409. case MMERC_FALL:
  410. case MMERC_FALLF:
  411. case FMERC_FALL:
  412. case FMERC_FALLF:
  413. uiDirectionUseFlag = ANITILE_USE_4DIRECTION_FOR_START_FRAME;
  414. }
  415. if( !(gTacticalStatus.uiFlags & LOADING_SAVED_GAME ) )
  416. {
  417. // OK, AS WE ADD, CHECK FOR TOD AND DECAY APPROPRIATELY
  418. if ( ( ( GetWorldTotalMin( ) - pCorpse->def.uiTimeOfDeath ) > DELAY_UNTIL_ROTTING ) && ( pCorpse->def.ubType < ROTTING_STAGE2 ) )
  419. {
  420. if ( pCorpse->def.ubType <= FMERC_FALLF )
  421. {
  422. // Rott!
  423. pCorpse->def.ubType = ROTTING_STAGE2;
  424. }
  425. }
  426. // If time of death is a few days, now, don't add at all!
  427. if ( ( ( GetWorldTotalMin( ) - pCorpse->def.uiTimeOfDeath ) > DELAY_UNTIL_DONE_ROTTING ) )
  428. {
  429. return( -1 );
  430. }
  431. }
  432. // Check if on roof or not...
  433. if ( pCorpse->def.bLevel == 0 )
  434. {
  435. //ubLevelID = ANI_OBJECT_LEVEL;
  436. ubLevelID = ANI_STRUCT_LEVEL;
  437. }
  438. else
  439. {
  440. ubLevelID = ANI_ONROOF_LEVEL;
  441. }
  442. memset( &AniParams, 0, sizeof( ANITILE_PARAMS ) );
  443. AniParams.sGridNo = pCorpse->def.sGridNo;
  444. AniParams.ubLevelID = ubLevelID;
  445. AniParams.sDelay = (INT16)( 150 );
  446. AniParams.sStartFrame = 0;
  447. AniParams.uiFlags = ANITILE_CACHEDTILE | ANITILE_PAUSED | ANITILE_OPTIMIZEFORSLOWMOVING | ANITILE_ANIMATE_Z | ANITILE_ERASEITEMFROMSAVEBUFFFER | uiDirectionUseFlag;
  448. AniParams.sX = CenterX( pCorpse->def.sGridNo );
  449. AniParams.sY = CenterY( pCorpse->def.sGridNo );
  450. AniParams.sZ = (INT16)pCorpse->def.sHeightAdjustment;
  451. AniParams.uiUserData3 = pCorpse->def.bDirection;
  452. if ( !gGameSettings.fOptions[ TOPTION_BLOOD_N_GORE ] )
  453. {
  454. strcpy( AniParams.zCachedFile, zNoBloodCorpseFilenames[ pCorpse->def.ubType ] );
  455. }
  456. else
  457. {
  458. strcpy( AniParams.zCachedFile, zCorpseFilenames[ pCorpse->def.ubType ] );
  459. }
  460. pCorpse->pAniTile = CreateAnimationTile( &AniParams );
  461. if ( pCorpse->pAniTile == NULL )
  462. {
  463. pCorpse->fActivated = FALSE;
  464. return( -1 );
  465. }
  466. // Set flag and index values
  467. pCorpse->pAniTile->pLevelNode->uiFlags |= ( LEVELNODE_ROTTINGCORPSE );
  468. pCorpse->pAniTile->pLevelNode->ubShadeLevel = gpWorldLevelData[ pCorpse->def.sGridNo ].pLandHead->ubShadeLevel;
  469. pCorpse->pAniTile->pLevelNode->ubSumLights = gpWorldLevelData[ pCorpse->def.sGridNo ].pLandHead->ubSumLights;
  470. pCorpse->pAniTile->pLevelNode->ubMaxLights = gpWorldLevelData[ pCorpse->def.sGridNo ].pLandHead->ubMaxLights;
  471. pCorpse->pAniTile->pLevelNode->ubNaturalShadeLevel = gpWorldLevelData[ pCorpse->def.sGridNo ].pLandHead->ubNaturalShadeLevel;
  472. pCorpse->pAniTile->uiUserData = iIndex;
  473. pCorpse->iID = iIndex;
  474. pCorpse->fActivated = TRUE;
  475. if ( Random( 100 ) > 50 )
  476. {
  477. pCorpse->fAttractCrowsOnlyWhenOnScreen = TRUE;
  478. }
  479. else
  480. {
  481. pCorpse->fAttractCrowsOnlyWhenOnScreen = FALSE;
  482. }
  483. pCorpse->iCachedTileID = pCorpse->pAniTile->sCachedTileID;
  484. if ( pCorpse->iCachedTileID == -1 )
  485. {
  486. DeleteAniTile( pCorpse->pAniTile );
  487. pCorpse->fActivated = FALSE;
  488. return( -1 );
  489. }
  490. // Get palette and create palettes and do substitutions
  491. if ( !CreateCorpsePalette( pCorpse ) )
  492. {
  493. DeleteAniTile( pCorpse->pAniTile );
  494. pCorpse->fActivated = FALSE;
  495. return( -1 );
  496. }
  497. SetRenderFlags(RENDER_FLAG_FULL);
  498. if ( pCorpse->def.usFlags & ROTTING_CORPSE_VEHICLE )
  499. {
  500. pCorpse->pAniTile->uiFlags |= ( ANITILE_FORWARD | ANITILE_LOOPING );
  501. // Turn off pause...
  502. pCorpse->pAniTile->uiFlags &= (~ANITILE_PAUSED);
  503. }
  504. InvalidateWorldRedundency( );
  505. // OK, loop through gridnos for corpse and remove blood.....
  506. // Get root filename... this removes path and extension
  507. // USed to find struct data fo rthis corpse...
  508. GetRootName( zFilename, AniParams.zCachedFile );
  509. // Add structure data.....
  510. CheckForAndAddTileCacheStructInfo( pCorpse->pAniTile->pLevelNode, pCorpse->def.sGridNo, ( UINT16 ) ( pCorpse->iCachedTileID ), GetCorpseStructIndex( pCorpseDef, TRUE ) );
  511. pStructureFileRef = GetCachedTileStructureRefFromFilename( zFilename );
  512. if ( pStructureFileRef != NULL )
  513. {
  514. usStructIndex = GetCorpseStructIndex( pCorpseDef, TRUE );
  515. pDBStructureRef = &(pStructureFileRef->pDBStructureRef[ usStructIndex ] );
  516. for (ubLoop = 0; ubLoop < pDBStructureRef->pDBStructure->ubNumberOfTiles; ubLoop++)
  517. {
  518. ppTile = pDBStructureRef->ppTile;
  519. sTileGridNo = pCorpseDef->sGridNo + ppTile[ ubLoop ]->sPosRelToBase;
  520. //Remove blood
  521. RemoveBlood( sTileGridNo, pCorpseDef->bLevel );
  522. }
  523. }
  524. // OK, we're done!
  525. return( iIndex );
  526. }
  527. void FreeCorpsePalettes( ROTTING_CORPSE *pCorpse )
  528. {
  529. INT32 cnt;
  530. // Free palettes
  531. MemFree( pCorpse->p8BPPPalette );
  532. MemFree( pCorpse->p16BPPPalette );
  533. for ( cnt = 0; cnt < NUM_CORPSE_SHADES; cnt++ )
  534. {
  535. if ( pCorpse->pShades[ cnt ] != NULL )
  536. {
  537. MemFree( pCorpse->pShades[ cnt ] );
  538. pCorpse->pShades[ cnt ] = NULL;
  539. }
  540. }
  541. }
  542. void RemoveCorpses( )
  543. {
  544. INT32 iCount;
  545. for(iCount=0; iCount < giNumRottingCorpse; iCount++)
  546. {
  547. if( ( gRottingCorpse[iCount].fActivated ) )
  548. {
  549. RemoveCorpse( iCount );
  550. }
  551. }
  552. giNumRottingCorpse = 0;
  553. }
  554. void RemoveCorpse( INT32 iCorpseID )
  555. {
  556. // Remove!
  557. gRottingCorpse[ iCorpseID ].fActivated = FALSE;
  558. DeleteAniTile( gRottingCorpse[ iCorpseID ].pAniTile );
  559. FreeCorpsePalettes( &( gRottingCorpse[ iCorpseID ] ) );
  560. }
  561. BOOLEAN CreateCorpsePalette( ROTTING_CORPSE *pCorpse )
  562. {
  563. CHAR8 zColFilename[ 100 ];
  564. INT8 bBodyTypePalette;
  565. SGPPaletteEntry Temp8BPPPalette[ 256 ];
  566. pCorpse->p8BPPPalette = MemAlloc( sizeof( SGPPaletteEntry ) * 256 );
  567. CHECKF( pCorpse->p8BPPPalette != NULL );
  568. bBodyTypePalette = GetBodyTypePaletteSubstitutionCode( NULL, pCorpse->def.ubBodyType, zColFilename );
  569. // If this corpse has cammo,
  570. if ( pCorpse->def.ubType == ROTTING_STAGE2 )
  571. {
  572. bBodyTypePalette = 0;
  573. }
  574. else if ( pCorpse->def.usFlags & ROTTING_CORPSE_USE_CAMMO_PALETTE )
  575. {
  576. strcpy( zColFilename, "ANIMS\\camo.COL" );
  577. bBodyTypePalette = 1;
  578. }
  579. if ( bBodyTypePalette == -1 )
  580. {
  581. // Use palette from HVOBJECT, then use substitution for pants, etc
  582. memcpy( pCorpse->p8BPPPalette, gpTileCache[ pCorpse->iCachedTileID ].pImagery->vo->pPaletteEntry, sizeof( pCorpse->p8BPPPalette ) * 256 );
  583. // Substitute based on head, etc
  584. SetPaletteReplacement( pCorpse->p8BPPPalette, pCorpse->def.HeadPal );
  585. SetPaletteReplacement( pCorpse->p8BPPPalette, pCorpse->def.VestPal );
  586. SetPaletteReplacement( pCorpse->p8BPPPalette, pCorpse->def.PantsPal );
  587. SetPaletteReplacement( pCorpse->p8BPPPalette, pCorpse->def.SkinPal );
  588. }
  589. else if ( bBodyTypePalette == 0 )
  590. {
  591. // Use palette from hvobject
  592. memcpy( pCorpse->p8BPPPalette, gpTileCache[ pCorpse->iCachedTileID ].pImagery->vo->pPaletteEntry, sizeof( pCorpse->p8BPPPalette ) * 256 );
  593. }
  594. else
  595. {
  596. // Use col file
  597. if ( CreateSGPPaletteFromCOLFile( Temp8BPPPalette, zColFilename ) )
  598. {
  599. // Copy into palette
  600. memcpy( pCorpse->p8BPPPalette, Temp8BPPPalette, sizeof( pCorpse->p8BPPPalette ) * 256 );
  601. }
  602. else
  603. {
  604. // Use palette from hvobject
  605. memcpy( pCorpse->p8BPPPalette, gpTileCache[ pCorpse->iCachedTileID ].pImagery->vo->pPaletteEntry, sizeof( pCorpse->p8BPPPalette ) * 256 );
  606. }
  607. }
  608. // -- BUILD 16BPP Palette from this
  609. pCorpse->p16BPPPalette = Create16BPPPalette( pCorpse->p8BPPPalette );
  610. CreateCorpsePaletteTables( pCorpse );
  611. return( TRUE );
  612. }
  613. BOOLEAN TurnSoldierIntoCorpse( SOLDIERTYPE *pSoldier, BOOLEAN fRemoveMerc, BOOLEAN fCheckForLOS )
  614. {
  615. ROTTING_CORPSE_DEFINITION Corpse;
  616. UINT8 ubType;
  617. INT32 cnt;
  618. UINT16 usItemFlags = 0; //WORLD_ITEM_DONTRENDER;
  619. INT32 iCorpseID;
  620. INT8 bVisible = -1;
  621. OBJECTTYPE *pObj;
  622. UINT8 ubNumGoo;
  623. INT16 sNewGridNo;
  624. OBJECTTYPE ItemObject;
  625. if ( pSoldier->sGridNo == NOWHERE )
  626. {
  627. return( FALSE );
  628. }
  629. // ATE: Change to fix crash when item in hand
  630. if ( gpItemPointer != NULL && gpItemPointerSoldier == pSoldier )
  631. {
  632. CancelItemPointer( );
  633. }
  634. // Setup some values!
  635. memset( &Corpse, 0, sizeof( Corpse ) );
  636. Corpse.ubBodyType = pSoldier->ubBodyType;
  637. Corpse.sGridNo = pSoldier->sGridNo;
  638. Corpse.dXPos = pSoldier->dXPos;
  639. Corpse.dYPos = pSoldier->dYPos;
  640. Corpse.bLevel = pSoldier->bLevel;
  641. Corpse.ubProfile = pSoldier->ubProfile;
  642. if ( Corpse.bLevel > 0 )
  643. {
  644. Corpse.sHeightAdjustment = (INT16)( pSoldier->sHeightAdjustment - WALL_HEIGHT );
  645. }
  646. SET_PALETTEREP_ID ( Corpse.HeadPal, pSoldier->HeadPal );
  647. SET_PALETTEREP_ID ( Corpse.VestPal, pSoldier->VestPal );
  648. SET_PALETTEREP_ID ( Corpse.SkinPal, pSoldier->SkinPal );
  649. SET_PALETTEREP_ID ( Corpse.PantsPal, pSoldier->PantsPal );
  650. if ( pSoldier->bCamo != 0 )
  651. {
  652. Corpse.usFlags |= ROTTING_CORPSE_USE_CAMMO_PALETTE;
  653. }
  654. // Determine corpse type!
  655. ubType = (UINT8)gubAnimSurfaceCorpseID[ pSoldier->ubBodyType][ pSoldier->usAnimState ];
  656. Corpse.bDirection = pSoldier->bDirection;
  657. // If we are a vehicle.... only use 1 direction....
  658. if ( pSoldier->uiStatusFlags & SOLDIER_VEHICLE )
  659. {
  660. Corpse.usFlags |= ROTTING_CORPSE_VEHICLE;
  661. if ( pSoldier->ubBodyType != ICECREAMTRUCK && pSoldier->ubBodyType != HUMVEE )
  662. {
  663. Corpse.bDirection = 7;
  664. }
  665. else
  666. {
  667. Corpse.bDirection = gb2DirectionsFrom8[ Corpse.bDirection ];
  668. }
  669. }
  670. if ( ubType == QUEEN_MONSTER_DEAD || ubType == BURNT_DEAD || ubType == EXPLODE_DEAD )
  671. {
  672. Corpse.bDirection = 7;
  673. }
  674. // ATE: If bDirection, get opposite
  675. // if ( ubType == SMERC_FALLF || ubType == MMERC_FALLF || ubType == FMERC_FALLF )
  676. //{
  677. // Corpse.bDirection = gOppositeDirection[ Corpse.bDirection ];
  678. // }
  679. // Set time of death
  680. Corpse.uiTimeOfDeath = GetWorldTotalMin( );
  681. // If corpse is not valid. make items visible
  682. if ( ubType == NO_CORPSE && pSoldier->bTeam != gbPlayerNum )
  683. {
  684. usItemFlags &= (~WORLD_ITEM_DONTRENDER );
  685. }
  686. // ATE: If the queen is killed, she should
  687. // make items visible because it ruins end sequence....
  688. if ( pSoldier->ubProfile == QUEEN || pSoldier->bTeam == gbPlayerNum )
  689. {
  690. bVisible = 1;
  691. }
  692. // Not for a robot...
  693. if ( AM_A_ROBOT( pSoldier ) )
  694. {
  695. }
  696. else if ( ubType == QUEEN_MONSTER_DEAD )
  697. {
  698. gTacticalStatus.fLockItemLocators = FALSE;
  699. ubNumGoo = 6 - ( gGameOptions.ubDifficultyLevel - DIF_LEVEL_EASY );
  700. sNewGridNo = pSoldier->sGridNo + ( WORLD_COLS * 2 );
  701. for ( cnt = 0; cnt < ubNumGoo; cnt++ )
  702. {
  703. CreateItem( JAR_QUEEN_CREATURE_BLOOD, 100, &ItemObject );
  704. AddItemToPool( sNewGridNo, &ItemObject, bVisible , pSoldier->bLevel, usItemFlags, -1 );
  705. }
  706. }
  707. else
  708. {
  709. // OK, Place what objects this guy was carrying on the ground!
  710. for ( cnt = 0; cnt < NUM_INV_SLOTS; cnt++ )
  711. {
  712. pObj = &( pSoldier->inv[ cnt ] );
  713. if ( pObj->usItem != NOTHING )
  714. {
  715. // Check if it's supposed to be dropped
  716. if ( !( pObj->fFlags & OBJECT_UNDROPPABLE ) || pSoldier->bTeam == gbPlayerNum )
  717. {
  718. // and make sure that it really is a droppable item type
  719. if ( !(Item[ pObj->usItem ].fFlags & ITEM_DEFAULT_UNDROPPABLE) )
  720. {
  721. ReduceAmmoDroppedByNonPlayerSoldiers( pSoldier, cnt );
  722. AddItemToPool( pSoldier->sGridNo, pObj, bVisible , pSoldier->bLevel, usItemFlags, -1 );
  723. }
  724. }
  725. }
  726. }
  727. DropKeysInKeyRing( pSoldier, pSoldier->sGridNo, pSoldier->bLevel, bVisible, FALSE, 0, FALSE );
  728. }
  729. // Make team look for items
  730. AllSoldiersLookforItems( TRUE );
  731. //if we are to call TacticalRemoveSoldier after adding the corpse
  732. if( fRemoveMerc )
  733. {
  734. // If not a player, you can completely remove soldiertype
  735. // otherwise, just remove their graphic
  736. if ( pSoldier->bTeam != gbPlayerNum )
  737. {
  738. // Remove merc!
  739. // ATE: Remove merc slot first - will disappear if no corpse data found!
  740. TacticalRemoveSoldier( pSoldier->ubID );
  741. }
  742. else
  743. {
  744. RemoveSoldierFromGridNo( pSoldier );
  745. }
  746. if ( ubType == NO_CORPSE )
  747. {
  748. return( TRUE );
  749. }
  750. // Set type
  751. Corpse.ubType = ubType;
  752. // Add corpse!
  753. iCorpseID = AddRottingCorpse( &Corpse );
  754. }
  755. else
  756. {
  757. if ( ubType == NO_CORPSE )
  758. {
  759. return( TRUE );
  760. }
  761. // Set type
  762. Corpse.ubType = ubType;
  763. // Add corpse!
  764. iCorpseID = AddRottingCorpse( &Corpse );
  765. }
  766. // If this is our guy......make visible...
  767. //if ( pSoldier->bTeam == gbPlayerNum )
  768. {
  769. MakeCorpseVisible( pSoldier, &( gRottingCorpse[ iCorpseID ] ) );
  770. }
  771. return( TRUE );
  772. }
  773. INT16 FindNearestRottingCorpse( SOLDIERTYPE *pSoldier )
  774. {
  775. INT32 uiRange, uiLowestRange = 999999;
  776. INT16 sLowestGridNo = NOWHERE;
  777. INT32 cnt;
  778. ROTTING_CORPSE *pCorpse;
  779. // OK, loop through our current listing of bodies
  780. for ( cnt = 0; cnt < giNumRottingCorpse; cnt++ )
  781. {
  782. pCorpse = &(gRottingCorpse[ cnt ] );
  783. if ( pCorpse->fActivated )
  784. {
  785. // Check rotting state
  786. if ( pCorpse->def.ubType == ROTTING_STAGE2 )
  787. {
  788. uiRange = GetRangeInCellCoordsFromGridNoDiff( pSoldier->sGridNo, pCorpse->def.sGridNo );
  789. if ( uiRange < uiLowestRange )
  790. {
  791. sLowestGridNo = pCorpse->def.sGridNo;
  792. uiLowestRange = uiRange;
  793. }
  794. }
  795. }
  796. }
  797. return( sLowestGridNo );
  798. }
  799. void AddCrowToCorpse( ROTTING_CORPSE *pCorpse )
  800. {
  801. SOLDIERCREATE_STRUCT MercCreateStruct;
  802. INT8 bBodyType = CROW;
  803. UINT8 iNewIndex;
  804. INT16 sGridNo;
  805. UINT8 ubDirection;
  806. SOLDIERTYPE *pSoldier;
  807. UINT8 ubRoomNum;
  808. // No crows inside :(
  809. if ( InARoom( pCorpse->def.sGridNo, &ubRoomNum ) )
  810. {
  811. return;
  812. }
  813. // Put him flying over corpse pisition
  814. memset( &MercCreateStruct, 0, sizeof( MercCreateStruct ) );
  815. MercCreateStruct.ubProfile = NO_PROFILE;
  816. MercCreateStruct.sSectorX = gWorldSectorX;
  817. MercCreateStruct.sSectorY = gWorldSectorY;
  818. MercCreateStruct.bSectorZ = gbWorldSectorZ;
  819. MercCreateStruct.bBodyType = bBodyType;
  820. MercCreateStruct.bDirection = SOUTH;
  821. MercCreateStruct.bTeam = CIV_TEAM;
  822. MercCreateStruct.sInsertionGridNo = pCorpse->def.sGridNo;
  823. RandomizeNewSoldierStats( &MercCreateStruct );
  824. if ( TacticalCreateSoldier( &MercCreateStruct, &iNewIndex ) != NULL )
  825. {
  826. pSoldier = MercPtrs[ iNewIndex ];
  827. sGridNo = FindRandomGridNoFromSweetSpot( pSoldier, pCorpse->def.sGridNo, 2, &ubDirection );
  828. if ( sGridNo != NOWHERE )
  829. {
  830. pSoldier->ubStrategicInsertionCode = INSERTION_CODE_GRIDNO;
  831. pSoldier->usStrategicInsertionData = sGridNo;
  832. pSoldier->sInsertionGridNo = sGridNo;
  833. pSoldier->sDesiredHeight = 0;
  834. // Add to sector
  835. AddSoldierToSector( iNewIndex );
  836. // Change to fly animation
  837. //sGridNo = FindRandomGridNoFromSweetSpot( pSoldier, pCorpse->def.sGridNo, 5, &ubDirection );
  838. //pSoldier->usUIMovementMode = CROW_FLY;
  839. //EVENT_GetNewSoldierPath( pSoldier, sGridNo, pSoldier->usUIMovementMode );
  840. // Setup action data to point back to corpse....
  841. pSoldier->uiPendingActionData1 = pCorpse->iID;
  842. pSoldier->sPendingActionData2 = pCorpse->def.sGridNo;
  843. pCorpse->def.bNumServicingCrows++;
  844. }
  845. }
  846. }
  847. void HandleCrowLeave( SOLDIERTYPE *pSoldier )
  848. {
  849. ROTTING_CORPSE *pCorpse;
  850. // Check if this crow is still referencing the same corpse...
  851. pCorpse = &(gRottingCorpse[ pSoldier->uiPendingActionData1 ] );
  852. // Double check grindo...
  853. if ( pSoldier->sPendingActionData2 == pCorpse->def.sGridNo )
  854. {
  855. // We have a match
  856. // Adjust crow servicing count...
  857. pCorpse->def.bNumServicingCrows--;
  858. if ( pCorpse->def.bNumServicingCrows < 0 )
  859. {
  860. pCorpse->def.bNumServicingCrows = 0;
  861. }
  862. }
  863. }
  864. void HandleCrowFlyAway( SOLDIERTYPE *pSoldier )
  865. {
  866. UINT8 ubDirection;
  867. INT16 sGridNo;
  868. // Set desired height
  869. pSoldier->sDesiredHeight = 100;
  870. // Change to fly animation
  871. sGridNo = FindRandomGridNoFromSweetSpot( pSoldier, pSoldier->sGridNo, 5, &ubDirection );
  872. pSoldier->usUIMovementMode = CROW_FLY;
  873. SendGetNewSoldierPathEvent( pSoldier, sGridNo, pSoldier->usUIMovementMode );
  874. }
  875. void HandleRottingCorpses( )
  876. {
  877. ROTTING_CORPSE *pCorpse;
  878. INT8 bNumCrows = 0;
  879. UINT32 uiChosenCorpseID;
  880. // Don't allow crows here if flags not set
  881. if ( !gTacticalStatus.fGoodToAllowCrows )
  882. {
  883. return;
  884. }
  885. // ATE: If it's too late, don't!
  886. if( NightTime() )
  887. {
  888. return;
  889. }
  890. if ( gbWorldSectorZ > 0 )
  891. {
  892. return;
  893. }
  894. // ATE: Check for multiple crows.....
  895. // Couint how many we have now...
  896. {
  897. UINT8 bLoop;
  898. SOLDIERTYPE * pSoldier;
  899. for (bLoop=gTacticalStatus.Team[ CIV_TEAM ].bFirstID, pSoldier=MercPtrs[bLoop]; bLoop <= gTacticalStatus.Team[ CIV_TEAM ].bLastID; bLoop++, pSoldier++)
  900. {
  901. if (pSoldier->bActive && pSoldier->bInSector && (pSoldier->bLife >= OKLIFE) && !( pSoldier->uiStatusFlags & SOLDIER_GASSED ) )
  902. {
  903. if ( pSoldier->ubBodyType == CROW )
  904. {
  905. bNumCrows++;
  906. }
  907. }
  908. }
  909. }
  910. // Once population gets down to 0, we can add more again....
  911. if ( bNumCrows == 0 )
  912. {
  913. gTacticalStatus.fDontAddNewCrows = FALSE;
  914. }
  915. if ( gTacticalStatus.fDontAddNewCrows )
  916. {
  917. return;
  918. }
  919. if ( bNumCrows >= gTacticalStatus.ubNumCrowsPossible )
  920. {
  921. gTacticalStatus.fDontAddNewCrows = TRUE;
  922. return;
  923. }
  924. if ( gTacticalStatus.Team[ CREATURE_TEAM ].bTeamActive )
  925. {
  926. // don't add any crows while there are predators around
  927. return;
  928. }
  929. // Pick one to attact a crow...
  930. {
  931. uiChosenCorpseID = Random( giNumRottingCorpse );
  932. pCorpse = &(gRottingCorpse[ uiChosenCorpseID ] );
  933. if ( pCorpse->fActivated )
  934. {
  935. if ( !( pCorpse->def.usFlags & ROTTING_CORPSE_VEHICLE ) )
  936. {
  937. if ( pCorpse->def.ubType == ROTTING_STAGE2 )
  938. {
  939. if ( GridNoOnScreen( pCorpse->def.sGridNo ) )
  940. {
  941. return;
  942. }
  943. AddCrowToCorpse( pCorpse );
  944. AddCrowToCorpse( pCorpse );
  945. }
  946. }
  947. }
  948. }
  949. }
  950. void MakeCorpseVisible( SOLDIERTYPE *pSoldier, ROTTING_CORPSE *pCorpse )
  951. {
  952. pCorpse->def.bVisible = 1;
  953. SetRenderFlags( RENDER_FLAG_FULL );
  954. }
  955. void AllMercsOnTeamLookForCorpse( ROTTING_CORPSE *pCorpse, INT8 bTeam )
  956. {
  957. INT32 cnt;
  958. SOLDIERTYPE *pSoldier;
  959. INT16 sDistVisible;
  960. INT16 sGridNo;
  961. // If this cump is already visible, return
  962. if ( pCorpse->def.bVisible == 1 )
  963. {
  964. return;
  965. }
  966. if ( !pCorpse->fActivated )
  967. {
  968. return;
  969. }
  970. // IF IT'S THE SELECTED GUY, MAKE ANOTHER SELECTED!
  971. cnt = gTacticalStatus.Team[ bTeam ].bFirstID;
  972. sGridNo = pCorpse->def.sGridNo;
  973. // look for all mercs on the same team,
  974. for ( pSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ bTeam ].bLastID; cnt++,pSoldier++ )
  975. {
  976. // ATE: Ok, lets check for some basic things here!
  977. if ( pSoldier->bLife >= OKLIFE && pSoldier->sGridNo != NOWHERE && pSoldier->bActive && pSoldier->bInSector )
  978. {
  979. // is he close enough to see that gridno if he turns his head?
  980. sDistVisible = DistanceVisible( pSoldier, DIRECTION_IRRELEVANT, DIRECTION_IRRELEVANT, sGridNo, pCorpse->def.bLevel );
  981. if (PythSpacesAway( pSoldier->sGridNo, sGridNo ) <= sDistVisible )
  982. {
  983. // and we can trace a line of sight to his x,y coordinates?
  984. // (taking into account we are definitely aware of this guy now)
  985. if ( SoldierTo3DLocationLineOfSightTest( pSoldier, sGridNo, pCorpse->def.bLevel, 3, (UINT8) sDistVisible, TRUE ) )
  986. {
  987. MakeCorpseVisible( pSoldier, pCorpse );
  988. return;
  989. }
  990. }
  991. }
  992. }
  993. }
  994. void MercLooksForCorpses( SOLDIERTYPE *pSoldier )
  995. {
  996. INT32 cnt;
  997. INT16 sDistVisible;
  998. INT16 sGridNo;
  999. ROTTING_CORPSE *pCorpse;
  1000. // Should we say disgust quote?
  1001. if ( ( pSoldier->usQuoteSaidFlags & SOLDIER_QUOTE_SAID_ROTTINGCORPSE ) )
  1002. {
  1003. return;
  1004. }
  1005. if ( pSoldier->ubProfile == NO_PROFILE )
  1006. {
  1007. return;
  1008. }
  1009. if ( AM_AN_EPC( pSoldier ) )
  1010. {
  1011. return;
  1012. }
  1013. if ( QuoteExp_HeadShotOnly[ pSoldier->ubProfile ] == 1 )
  1014. {
  1015. return;
  1016. }
  1017. // Every so often... do a corpse quote...
  1018. if ( Random( 400 ) <= 2 )
  1019. {
  1020. // Loop through all corpses....
  1021. for ( cnt = 0; cnt < giNumRottingCorpse; cnt++ )
  1022. {
  1023. pCorpse = &(gRottingCorpse[ cnt ] );
  1024. if ( !pCorpse->fActivated )
  1025. {
  1026. continue;
  1027. }
  1028. // Has this corpse rotted enough?
  1029. if ( pCorpse->def.ubType == ROTTING_STAGE2 )
  1030. {
  1031. sGridNo = pCorpse->def.sGridNo;
  1032. // is he close enough to see that gridno if he turns his head?
  1033. sDistVisible = DistanceVisible( pSoldier, DIRECTION_IRRELEVANT, DIRECTION_IRRELEVANT, sGridNo, pCorpse->def.bLevel );
  1034. if (PythSpacesAway( pSoldier->sGridNo, sGridNo ) <= sDistVisible )
  1035. {
  1036. // and we can trace a line of sight to his x,y coordinates?
  1037. // (taking into account we are definitely aware of this guy now)
  1038. if ( SoldierTo3DLocationLineOfSightTest( pSoldier, sGridNo, pCorpse->def.bLevel, 3, (UINT8) sDistVisible, TRUE ) )
  1039. {
  1040. TacticalCharacterDialogue( pSoldier, QUOTE_HEADSHOT );
  1041. pSoldier->usQuoteSaidFlags |= SOLDIER_QUOTE_SAID_ROTTINGCORPSE;
  1042. BeginMultiPurposeLocator( sGridNo, pCorpse->def.bLevel, FALSE );
  1043. // Slide to...
  1044. SlideToLocation( 0, sGridNo );
  1045. return;
  1046. }
  1047. }
  1048. }
  1049. }
  1050. }
  1051. }
  1052. void RebuildAllCorpseShadeTables( )
  1053. {
  1054. INT32 cnt;
  1055. ROTTING_CORPSE *pCorpse;
  1056. // Loop through all corpses....
  1057. for ( cnt = 0; cnt < giNumRottingCorpse; cnt++ )
  1058. {
  1059. pCorpse = &(gRottingCorpse[ cnt ] );
  1060. // If this cump is already visible, continue
  1061. if ( pCorpse->def.bVisible == 1 )
  1062. {
  1063. continue;
  1064. }
  1065. if ( !pCorpse->fActivated )
  1066. {
  1067. continue;
  1068. }
  1069. // Rebuild shades....
  1070. }
  1071. }
  1072. UINT16 CreateCorpsePaletteTables( ROTTING_CORPSE *pCorpse )
  1073. {
  1074. SGPPaletteEntry LightPal[256];
  1075. UINT32 uiCount;
  1076. // create the basic shade table
  1077. for(uiCount=0; uiCount < 256; uiCount++)
  1078. {
  1079. // combine the rgb of the light color with the object's palette
  1080. LightPal[uiCount].peRed=(UINT8)(__min((UINT16)pCorpse->p8BPPPalette[uiCount].peRed+(UINT16)gpLightColors[0].peRed, 255));
  1081. LightPal[uiCount].peGreen=(UINT8)(__min((UINT16)pCorpse->p8BPPPalette[uiCount].peGreen+(UINT16)gpLightColors[0].peGreen, 255));
  1082. LightPal[uiCount].peBlue=(UINT8)(__min((UINT16)pCorpse->p8BPPPalette[uiCount].peBlue+(UINT16)gpLightColors[0].peBlue, 255));
  1083. }
  1084. // build the shade tables
  1085. CreateCorpseShadedPalette( pCorpse, 0, LightPal );
  1086. // build neutral palette as well!
  1087. // Set current shade table to neutral color
  1088. return(TRUE);
  1089. }
  1090. BOOLEAN CreateCorpseShadedPalette( ROTTING_CORPSE *pCorpse, UINT32 uiBase, SGPPaletteEntry *pShadePal )
  1091. {
  1092. UINT32 uiCount;
  1093. pCorpse->pShades[uiBase] = Create16BPPPaletteShaded( pShadePal, gusShadeLevels[0][0],
  1094. gusShadeLevels[0][1],
  1095. gusShadeLevels[0][2], TRUE);
  1096. for(uiCount=1; uiCount < 16; uiCount++)
  1097. {
  1098. pCorpse->pShades[uiBase+uiCount]=Create16BPPPaletteShaded( pShadePal, gusShadeLevels[uiCount][0],
  1099. gusShadeLevels[uiCount][1],
  1100. gusShadeLevels[uiCount][2], FALSE);
  1101. }
  1102. return(TRUE);
  1103. }
  1104. ROTTING_CORPSE *FindCorpseBasedOnStructure( INT16 sGridNo, STRUCTURE *pStructure )
  1105. {
  1106. LEVELNODE *pLevelNode;
  1107. ROTTING_CORPSE *pCorpse = NULL;
  1108. pLevelNode = gpWorldLevelData[ sGridNo ].pStructHead;
  1109. while( pLevelNode != NULL )
  1110. {
  1111. if (pLevelNode->pStructureData == pStructure )
  1112. {
  1113. break;
  1114. }
  1115. pLevelNode = pLevelNode->pNext;
  1116. }
  1117. if ( pLevelNode != NULL )
  1118. {
  1119. // Get our corpse....
  1120. pCorpse = &( gRottingCorpse[ pLevelNode->pAniTile->uiUserData ] );
  1121. }
  1122. return( pCorpse );
  1123. }
  1124. void CorpseHit( INT16 sGridNo, UINT16 usStructureID )
  1125. {
  1126. #if 0
  1127. STRUCTURE *pStructure, *pBaseStructure;
  1128. ROTTING_CORPSE *pCorpse = NULL;
  1129. INT16 sBaseGridNo;
  1130. pStructure = FindStructureByID( sGridNo, usStructureID );
  1131. // Get base....
  1132. pBaseStructure = FindBaseStructure( pStructure );
  1133. // Find base gridno...
  1134. sBaseGridNo = pBaseStructure->sGridNo;
  1135. // Get corpse ID.....
  1136. pCorpse = FindCorpseBasedOnStructure( sBaseGridNo, pBaseStructure );
  1137. if ( pCorpse == NULL )
  1138. {
  1139. #ifdef JA2TESTVERSION
  1140. ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_TESTVERSION, L"Bullet hit corpse but corpse cannot be found at: %d", sBaseGridNo );
  1141. #endif
  1142. return;
  1143. }
  1144. // Twitch the bugger...
  1145. #ifdef JA2BETAVERSION
  1146. ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_TESTVERSION, L"Corpse hit" );
  1147. #endif
  1148. if ( GridNoOnScreen( sBaseGridNo ) )
  1149. {
  1150. // Twitch....
  1151. // Set frame...
  1152. SetAniTileFrame( pCorpse->pAniTile, 1 );
  1153. // Go reverse...
  1154. pCorpse->pAniTile->uiFlags |= ( ANITILE_BACKWARD | ANITILE_PAUSE_AFTER_LOOP );
  1155. // Turn off pause...
  1156. pCorpse->pAniTile->uiFlags &= (~ANITILE_PAUSED);
  1157. }
  1158. // PLay a sound....
  1159. PlayJA2Sample( (UINT32)( BULLET_IMPACT_2 ), RATE_11025, SoundVolume( MIDVOLUME, sGridNo ), 1, SoundDir( sGridNo ) );
  1160. #endif
  1161. }
  1162. void VaporizeCorpse( INT16 sGridNo, UINT16 usStructureID )
  1163. {
  1164. STRUCTURE *pStructure, *pBaseStructure;
  1165. ROTTING_CORPSE *pCorpse = NULL;
  1166. INT16 sBaseGridNo;
  1167. ANITILE_PARAMS AniParams;
  1168. pStructure = FindStructureByID( sGridNo, usStructureID );
  1169. // Get base....
  1170. pBaseStructure = FindBaseStructure( pStructure );
  1171. // Find base gridno...
  1172. sBaseGridNo = pBaseStructure->sGridNo;
  1173. // Get corpse ID.....
  1174. pCorpse = FindCorpseBasedOnStructure( sBaseGridNo, pBaseStructure );
  1175. if ( pCorpse == NULL )
  1176. {
  1177. #ifdef JA2TESTVERSION
  1178. ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_TESTVERSION, L"Vaporize corpse but corpse cannot be found at: %d", sBaseGridNo );
  1179. #endif
  1180. return;
  1181. }
  1182. if ( pCorpse->def.usFlags & ROTTING_CORPSE_VEHICLE )
  1183. {
  1184. return;
  1185. }
  1186. if ( GridNoOnScreen( sBaseGridNo ) )
  1187. {
  1188. // Add explosion
  1189. memset( &AniParams, 0, sizeof( ANITILE_PARAMS ) );
  1190. AniParams.sGridNo = sBaseGridNo;
  1191. AniParams.ubLevelID = ANI_STRUCT_LEVEL;
  1192. AniParams.sDelay = (INT16)( 80 );
  1193. AniParams.sStartFrame = 0;
  1194. AniParams.uiFlags = ANITILE_CACHEDTILE | ANITILE_FORWARD;
  1195. AniParams.sX = CenterX( sBaseGridNo );
  1196. AniParams.sY = CenterY( sBaseGridNo );
  1197. AniParams.sZ = (INT16)pCorpse->def.sHeightAdjustment;
  1198. strcpy( AniParams.zCachedFile, "TILECACHE\\GEN_BLOW.STI" );
  1199. CreateAnimationTile( &AniParams );
  1200. // Remove....
  1201. RemoveCorpse( pCorpse->iID );
  1202. SetRenderFlags( RENDER_FLAG_FULL );
  1203. if ( pCorpse->def.bLevel == 0 )
  1204. {
  1205. // Set some blood......
  1206. SpreadEffect( sBaseGridNo, (UINT8)( ( 2 ) ), 0, NOBODY, BLOOD_SPREAD_EFFECT, 0, -1 );
  1207. }
  1208. }
  1209. // PLay a sound....
  1210. PlayJA2Sample( (UINT32)( BODY_EXPLODE_1 ), RATE_11025, SoundVolume( HIGHVOLUME, sGridNo ), 1, SoundDir( sGridNo ) );
  1211. }
  1212. INT16 FindNearestAvailableGridNoForCorpse( ROTTING_CORPSE_DEFINITION *pDef, INT8 ubRadius )
  1213. {
  1214. INT16 sSweetGridNo;
  1215. INT16 sTop, sBottom;
  1216. INT16 sLeft, sRight;
  1217. INT16 cnt1, cnt2, cnt3;
  1218. INT16 sGridNo;
  1219. INT32 uiRange, uiLowestRange = 999999;
  1220. INT16 sLowestGridNo=0;
  1221. INT32 leftmost;
  1222. BOOLEAN fFound = FALSE;
  1223. SOLDIERTYPE soldier;
  1224. UINT8 ubSaveNPCAPBudget;
  1225. UINT8 ubSaveNPCDistLimit;
  1226. STRUCTURE_FILE_REF * pStructureFileRef = NULL;
  1227. INT8 zFilename[150];
  1228. UINT8 ubBestDirection=0;
  1229. BOOLEAN fSetDirection = FALSE;
  1230. cnt3 = 0;
  1231. // Get root filename... this removes path and extension
  1232. // USed to find struct data fo rthis corpse...
  1233. GetRootName( zFilename, zCorpseFilenames[pDef->ubType ] );
  1234. pStructureFileRef = GetCachedTileStructureRefFromFilename( zFilename );
  1235. sSweetGridNo = pDef->sGridNo;
  1236. //Save AI pathing vars. changing the distlimit restricts how
  1237. //far away the pathing will consider.
  1238. ubSaveNPCAPBudget = gubNPCAPBudget;
  1239. ubSaveNPCDistLimit = gubNPCDistLimit;
  1240. gubNPCAPBudget = 0;
  1241. gubNPCDistLimit = ubRadius;
  1242. //create dummy soldier, and use the pathing to determine which nearby slots are
  1243. //reachable.
  1244. memset( &soldier, 0, sizeof( SOLDIERTYPE ) );
  1245. soldier.bTeam = 1;
  1246. soldier.sGridNo = sSweetGridNo;
  1247. sTop = ubRadius;
  1248. sBottom = -ubRadius;
  1249. sLeft = - ubRadius;
  1250. sRight = ubRadius;
  1251. //clear the mapelements of potential residue MAPELEMENT_REACHABLE flags
  1252. //in the square region.
  1253. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  1254. {
  1255. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  1256. {
  1257. sGridNo = sSweetGridNo + (WORLD_COLS * cnt1) + cnt2;
  1258. if ( sGridNo >=0 && sGridNo < WORLD_MAX )
  1259. {
  1260. gpWorldLevelData[ sGridNo ].uiFlags &= (~MAPELEMENT_REACHABLE);
  1261. }
  1262. }
  1263. }
  1264. //Now, find out which of these gridnos are reachable
  1265. //(use the fake soldier and the pathing settings)
  1266. FindBestPath( &soldier, NOWHERE, 0, WALKING, COPYREACHABLE, 0 );
  1267. uiLowestRange = 999999;
  1268. for( cnt1 = sBottom; cnt1 <= sTop; cnt1++ )
  1269. {
  1270. leftmost = ( ( sSweetGridNo + ( WORLD_COLS * cnt1 ) )/ WORLD_COLS ) * WORLD_COLS;
  1271. for( cnt2 = sLeft; cnt2 <= sRight; cnt2++ )
  1272. {
  1273. sGridNo = sSweetGridNo + ( WORLD_COLS * cnt1 ) + cnt2;
  1274. if ( sGridNo >=0 && sGridNo < WORLD_MAX && sGridNo >= leftmost && sGridNo < ( leftmost + WORLD_COLS ) &&
  1275. gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE )
  1276. {
  1277. // Go on sweet stop
  1278. if ( NewOKDestination( &soldier, sGridNo, TRUE, soldier.bLevel ) )
  1279. {
  1280. BOOLEAN fDirectionFound = FALSE;
  1281. BOOLEAN fCanSetDirection = FALSE;
  1282. // Check each struct in each direction
  1283. if ( pStructureFileRef == NULL )
  1284. {
  1285. fDirectionFound = TRUE;
  1286. }
  1287. else
  1288. {
  1289. for( cnt3 = 0; cnt3 < 8; cnt3++ )
  1290. {
  1291. if ( OkayToAddStructureToWorld( (INT16)sGridNo, pDef->bLevel, &(pStructureFileRef->pDBStructureRef[gOneCDirection[ cnt3 ]]), INVALID_STRUCTURE_ID ) )
  1292. {
  1293. fDirectionFound = TRUE;
  1294. fCanSetDirection = TRUE;
  1295. break;
  1296. }
  1297. }
  1298. }
  1299. if ( fDirectionFound )
  1300. {
  1301. uiRange = GetRangeInCellCoordsFromGridNoDiff( sSweetGridNo, sGridNo );
  1302. if ( uiRange < uiLowestRange )
  1303. {
  1304. if ( fCanSetDirection )
  1305. {
  1306. ubBestDirection = (UINT8)cnt3;
  1307. fSetDirection = TRUE;
  1308. }
  1309. sLowestGridNo = sGridNo;
  1310. uiLowestRange = uiRange;
  1311. fFound = TRUE;
  1312. }
  1313. }
  1314. }
  1315. }
  1316. }
  1317. }
  1318. gubNPCAPBudget = ubSaveNPCAPBudget;
  1319. gubNPCDistLimit = ubSaveNPCDistLimit;
  1320. if ( fFound )
  1321. {
  1322. if ( fSetDirection )
  1323. {
  1324. pDef->bDirection = ubBestDirection;
  1325. }
  1326. return sLowestGridNo;
  1327. }
  1328. return NOWHERE;
  1329. }
  1330. BOOLEAN IsValidDecapitationCorpse( ROTTING_CORPSE *pCorpse )
  1331. {
  1332. if ( pCorpse->def.fHeadTaken )
  1333. {
  1334. return( FALSE );
  1335. }
  1336. return( gbCorpseValidForDecapitation[ pCorpse->def.ubType ] );
  1337. }
  1338. ROTTING_CORPSE *GetCorpseAtGridNo( INT16 sGridNo, INT8 bLevel )
  1339. {
  1340. STRUCTURE *pStructure, *pBaseStructure;
  1341. INT16 sBaseGridNo;
  1342. pStructure = FindStructure( sGridNo, STRUCTURE_CORPSE );
  1343. if ( pStructure != NULL )
  1344. {
  1345. // Get base....
  1346. pBaseStructure = FindBaseStructure( pStructure );
  1347. // Find base gridno...
  1348. sBaseGridNo = pBaseStructure->sGridNo;
  1349. if ( pBaseStructure != NULL )
  1350. {
  1351. return( FindCorpseBasedOnStructure( sBaseGridNo, pBaseStructure ) );
  1352. }
  1353. }
  1354. return( NULL );
  1355. }
  1356. void DecapitateCorpse( SOLDIERTYPE *pSoldier, INT16 sGridNo, INT8 bLevel )
  1357. {
  1358. OBJECTTYPE Object;
  1359. ROTTING_CORPSE *pCorpse;
  1360. ROTTING_CORPSE_DEFINITION CorpseDef;
  1361. UINT16 usHeadIndex = HEAD_1;
  1362. pCorpse = GetCorpseAtGridNo( sGridNo, bLevel );
  1363. if ( pCorpse == NULL )
  1364. {
  1365. return;
  1366. }
  1367. if ( IsValidDecapitationCorpse( pCorpse ) )
  1368. {
  1369. // Decapitate.....
  1370. // Copy corpse definition...
  1371. memcpy( &CorpseDef, &(pCorpse->def), sizeof( ROTTING_CORPSE_DEFINITION ) );
  1372. // Add new one...
  1373. CorpseDef.ubType = gDecapitatedCorpse[ CorpseDef.ubType ];
  1374. pCorpse->def.fHeadTaken = TRUE;
  1375. if ( CorpseDef.ubType != 0 )
  1376. {
  1377. // Remove old one...
  1378. RemoveCorpse( pCorpse->iID );
  1379. AddRottingCorpse( &CorpseDef );
  1380. }
  1381. // Add head item.....
  1382. // Pick the head based on profile type...
  1383. switch( pCorpse->def.ubProfile )
  1384. {
  1385. case 83:
  1386. usHeadIndex = HEAD_2;
  1387. break;
  1388. case 111:
  1389. usHeadIndex = HEAD_3;
  1390. break;
  1391. case 64:
  1392. usHeadIndex = HEAD_4;
  1393. break;
  1394. case 112:
  1395. usHeadIndex = HEAD_5;
  1396. break;
  1397. case 82:
  1398. usHeadIndex = HEAD_6;
  1399. break;
  1400. case 110:
  1401. usHeadIndex = HEAD_7;
  1402. break;
  1403. }
  1404. CreateItem( usHeadIndex, 100, &Object );
  1405. AddItemToPool( sGridNo, &Object, INVISIBLE, 0, 0, 0 );
  1406. // All teams lok for this...
  1407. NotifySoldiersToLookforItems( );
  1408. }
  1409. }
  1410. void GetBloodFromCorpse( SOLDIERTYPE *pSoldier )
  1411. {
  1412. ROTTING_CORPSE *pCorpse;
  1413. INT8 bObjSlot;
  1414. OBJECTTYPE Object;
  1415. // OK, get corpse
  1416. pCorpse = &( gRottingCorpse[ pSoldier->uiPendingActionData4 ] );
  1417. bObjSlot = FindObj( pSoldier, JAR );
  1418. // What kind of corpse ami I?
  1419. switch( pCorpse->def.ubType )
  1420. {
  1421. case ADULTMONSTER_DEAD:
  1422. case INFANTMONSTER_DEAD:
  1423. // Can get creature blood....
  1424. CreateItem( JAR_CREATURE_BLOOD, 100, &Object );
  1425. break;
  1426. case QUEEN_MONSTER_DEAD:
  1427. CreateItem( JAR_QUEEN_CREATURE_BLOOD, 100, &Object );
  1428. break;
  1429. default:
  1430. CreateItem( JAR_HUMAN_BLOOD, 100, &Object );
  1431. break;
  1432. }
  1433. if ( bObjSlot != NO_SLOT )
  1434. {
  1435. SwapObjs( &(pSoldier->inv[ bObjSlot ] ), &Object );
  1436. }
  1437. }
  1438. void ReduceAmmoDroppedByNonPlayerSoldiers( SOLDIERTYPE *pSoldier, INT32 iInvSlot )
  1439. {
  1440. OBJECTTYPE *pObj;
  1441. Assert( pSoldier );
  1442. Assert( ( iInvSlot >= 0 ) && ( iInvSlot < NUM_INV_SLOTS ) );
  1443. pObj = &( pSoldier->inv[ iInvSlot ] );
  1444. // if not a player soldier
  1445. if ( pSoldier->bTeam != gbPlayerNum )
  1446. {
  1447. // if it's ammo
  1448. if ( Item[ pObj->usItem ].usItemClass == IC_AMMO )
  1449. {
  1450. //don't drop all the clips, just a random # of them between 1 and how many there are
  1451. pObj->ubNumberOfObjects = ( UINT8 ) ( 1 + Random( pObj->ubNumberOfObjects ) );
  1452. // recalculate the weight
  1453. pObj->ubWeight = CalculateObjectWeight( pObj );
  1454. }
  1455. }
  1456. }
  1457. void LookForAndMayCommentOnSeeingCorpse( SOLDIERTYPE *pSoldier, INT16 sGridNo, UINT8 ubLevel )
  1458. {
  1459. ROTTING_CORPSE *pCorpse;
  1460. INT8 bToleranceThreshold = 0;
  1461. INT32 cnt;
  1462. SOLDIERTYPE *pTeamSoldier;
  1463. if ( QuoteExp_HeadShotOnly[ pSoldier->ubProfile ] == 1 )
  1464. {
  1465. return;
  1466. }
  1467. pCorpse = GetCorpseAtGridNo( sGridNo, ubLevel );
  1468. if ( pCorpse == NULL )
  1469. {
  1470. return;
  1471. }
  1472. if ( pCorpse->def.ubType != ROTTING_STAGE2 )
  1473. {
  1474. return;
  1475. }
  1476. // If servicing qrows, tolerance is now 1
  1477. if ( pCorpse->def.bNumServicingCrows > 0 )
  1478. {
  1479. bToleranceThreshold++;
  1480. }
  1481. // Check tolerance
  1482. if ( pSoldier->bCorpseQuoteTolerance <= bToleranceThreshold )
  1483. {
  1484. // Say quote...
  1485. TacticalCharacterDialogue( pSoldier, QUOTE_HEADSHOT );
  1486. BeginMultiPurposeLocator( sGridNo, ubLevel, FALSE );
  1487. // Reset values....
  1488. pSoldier->bCorpseQuoteTolerance = (INT8)( Random(3) + 1 );
  1489. // 50% chance of adding 1 to other mercs....
  1490. if ( Random( 2 ) == 1 )
  1491. {
  1492. // IF IT'S THE SELECTED GUY, MAKE ANOTHER SELECTED!
  1493. cnt = gTacticalStatus.Team[ gbPlayerNum ].bFirstID;
  1494. // look for all mercs on the same team,
  1495. for ( pTeamSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; cnt++,pTeamSoldier++ )
  1496. {
  1497. // ATE: Ok, lets check for some basic things here!
  1498. if ( pTeamSoldier->bLife >= OKLIFE && pTeamSoldier->sGridNo != NOWHERE && pTeamSoldier->bActive && pTeamSoldier->bInSector )
  1499. {
  1500. pTeamSoldier->bCorpseQuoteTolerance++;
  1501. }
  1502. }
  1503. }
  1504. }
  1505. }
  1506. INT16 GetGridNoOfCorpseGivenProfileID( UINT8 ubProfileID )
  1507. {
  1508. INT32 cnt;
  1509. ROTTING_CORPSE *pCorpse;
  1510. // Loop through all corpses....
  1511. for ( cnt = 0; cnt < giNumRottingCorpse; cnt++ )
  1512. {
  1513. pCorpse = &(gRottingCorpse[ cnt ] );
  1514. if ( pCorpse->fActivated )
  1515. {
  1516. if ( pCorpse->def.ubProfile == ubProfileID )
  1517. {
  1518. return( pCorpse->def.sGridNo );
  1519. }
  1520. }
  1521. }
  1522. return( NOWHERE );
  1523. }
  1524. void DecayRottingCorpseAIWarnings( void )
  1525. {
  1526. INT32 cnt;
  1527. ROTTING_CORPSE * pCorpse;
  1528. for ( cnt = 0; cnt < giNumRottingCorpse; cnt++ )
  1529. {
  1530. pCorpse = &(gRottingCorpse[ cnt ] );
  1531. if ( pCorpse->fActivated && pCorpse->def.ubAIWarningValue > 0 )
  1532. {
  1533. pCorpse->def.ubAIWarningValue--;
  1534. }
  1535. }
  1536. }
  1537. UINT8 GetNearestRottingCorpseAIWarning( INT16 sGridNo )
  1538. {
  1539. INT32 cnt;
  1540. ROTTING_CORPSE * pCorpse;
  1541. UINT8 ubHighestWarning = 0;
  1542. for ( cnt = 0; cnt < giNumRottingCorpse; cnt++ )
  1543. {
  1544. pCorpse = &(gRottingCorpse[ cnt ] );
  1545. if ( pCorpse->fActivated && pCorpse->def.ubAIWarningValue > 0 )
  1546. {
  1547. if ( PythSpacesAway( sGridNo, pCorpse->def.sGridNo ) <= CORPSE_WARNING_DIST )
  1548. {
  1549. if ( pCorpse->def.ubAIWarningValue > ubHighestWarning )
  1550. {
  1551. ubHighestWarning = pCorpse->def.ubAIWarningValue;
  1552. }
  1553. }
  1554. }
  1555. }
  1556. return( ubHighestWarning );
  1557. }