Inventory Choosing.c 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147
  1. #ifdef PRECOMPILEDHEADERS
  2. #include "Tactical All.h"
  3. #else
  4. #include <memory.h>
  5. #include "Inventory Choosing.h"
  6. #include "animation data.h"
  7. #include "Items.h"
  8. #include "Random.h"
  9. #include "Weapons.h"
  10. #include "Strategic Status.h"
  11. #include "Campaign.h"
  12. #include "GameSettings.h"
  13. #endif
  14. #define ENEMYAMMODROPRATE 50 // % of time enemies drop ammunition
  15. #define ENEMYGRENADEDROPRATE 25 // % of time enemies drop grenades
  16. #define ENEMYEQUIPDROPRATE 15 // % of stuff enemies drop equipment
  17. // only 1/10th of what enemies drop...
  18. #define MILITIAAMMODROPRATE 5 // % of time enemies drop ammunition
  19. #define MILITIAGRENADEDROPRATE 3 // % of time enemies drop grenades
  20. #define MILITIAEQUIPDROPRATE 2 // % of stuff enemies drop equipment
  21. #define MAX_MORTARS_PER_TEAM 1 // one team can't randomly roll more than this many mortars per sector
  22. UINT32 guiMortarsRolledByTeam = 0;
  23. ARMY_GUN_CHOICE_TYPE gRegularArmyGunChoices[ARMY_GUN_LEVELS] =
  24. { // INDEX CLASS #CHOICES
  25. { /* 0 - lo pistols */ 2, SW38, DESERTEAGLE, -1, -1, -1 },
  26. { /* 1 - hi pistols */ 2, GLOCK_17, BERETTA_93R, -1, -1, -1 },
  27. { /* 2 - lo SMG/shotgun */ 2, M870, MP5K, -1, -1, -1 },
  28. { /* 3 - lo rifles */ 1, MINI14, -1, -1, -1, -1 },
  29. { /* 4 - hi SMGs */ 2, MAC10, COMMANDO, -1, -1, -1 },
  30. { /* 5 - med rifles */ 1, G41, -1, -1, -1, -1 },
  31. { /* 6 - sniper rifles */ 1, M24, -1, -1, -1, -1 },
  32. { /* 7 - hi rifles */ 2, M14, C7, -1, -1, -1 },
  33. { /* 8 - best rifle */ 1, FNFAL, -1, -1, -1, -1 },
  34. { /* 9 - machine guns */ 1, MINIMI, -1, -1, -1, -1 },
  35. { /* 10- rocket rifle */ 2, ROCKET_RIFLE, MINIMI, -1, -1, -1 },
  36. };
  37. ARMY_GUN_CHOICE_TYPE gExtendedArmyGunChoices[ARMY_GUN_LEVELS] =
  38. { // INDEX CLASS #CHOICES
  39. { /* 0 - lo pistols */ 5, SW38, BARRACUDA, DESERTEAGLE, GLOCK_17, M1911, },
  40. { /* 1 - hi pist/shtgn */ 4, GLOCK_18, BERETTA_93R, BERETTA_92F, M870, -1 },
  41. { /* 2 - lo SMGs/shtgn */ 5, TYPE85, THOMPSON, MP53, MP5K, SPAS15 },
  42. { /* 3 - lo rifles */ 2, MINI14, SKS, -1, -1, -1 },
  43. { /* 4 - hi SMGs */ 3, MAC10, AKSU74, COMMANDO, -1, -1 },
  44. { /* 5 - med rifles */ 4, AKM, G3A3, G41, AK74, -1 },
  45. { /* 6 - sniper rifles */ 2, DRAGUNOV, M24, -1, -1, -1 },
  46. { /* 7 - hi rifles */ 4, FAMAS, M14, AUG, C7, -1 },
  47. { /* 8 - best rifle */ 1, FNFAL, -1, -1, -1, -1 },
  48. { /* 9 - machine guns */ 3, MINIMI, RPK74, HK21E, -1, -1 },
  49. { /* 10- rocket rifle */ 4, ROCKET_RIFLE, ROCKET_RIFLE, RPK74, HK21E, -1},
  50. };
  51. void RandomlyChooseWhichItemsAreDroppable( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass );
  52. void EquipTank( SOLDIERCREATE_STRUCT *pp );
  53. void ChooseKitsForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bKitClass );
  54. void ChooseMiscGearForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bMiscClass );
  55. void ChooseBombsForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bBombClass );
  56. void InitArmyGunTypes(void)
  57. {
  58. ARMY_GUN_CHOICE_TYPE *pGunChoiceTable;
  59. UINT32 uiGunLevel;
  60. UINT32 uiChoice;
  61. INT8 bItemNo;
  62. UINT8 ubWeapon;
  63. // depending on selection of the gun nut option
  64. if (gGameOptions.fGunNut)
  65. {
  66. // use table of extended gun choices
  67. pGunChoiceTable = &(gExtendedArmyGunChoices[0]);
  68. }
  69. else
  70. {
  71. // use table of regular gun choices
  72. pGunChoiceTable = &(gRegularArmyGunChoices[0]);
  73. }
  74. // for each gun category
  75. for (uiGunLevel = 0; uiGunLevel < ARMY_GUN_LEVELS; uiGunLevel++)
  76. {
  77. // choose one the of the possible gun choices to be used by the army for this game & store it
  78. uiChoice = Random(pGunChoiceTable[ uiGunLevel ].ubChoices);
  79. bItemNo = pGunChoiceTable[ uiGunLevel ].bItemNo[ uiChoice ];
  80. AssertMsg(bItemNo != -1, "Invalid army gun choice in table");
  81. gStrategicStatus.ubStandardArmyGunIndex[uiGunLevel] = (UINT8) bItemNo;
  82. }
  83. // set all flags that track whether this weapon type has been dropped before to FALSE
  84. for (ubWeapon = 0; ubWeapon < MAX_WEAPONS; ubWeapon++)
  85. {
  86. gStrategicStatus.fWeaponDroppedAlready[ubWeapon] = FALSE;
  87. }
  88. // avoid auto-drops for the gun class with the crappiest guns in it
  89. MarkAllWeaponsOfSameGunClassAsDropped( SW38 );
  90. }
  91. INT8 GetWeaponClass( UINT16 usGun )
  92. {
  93. UINT32 uiGunLevel, uiLoop;
  94. // always use the extended list since it contains all guns...
  95. for (uiGunLevel = 0; uiGunLevel < ARMY_GUN_LEVELS; uiGunLevel++)
  96. {
  97. for ( uiLoop = 0; uiLoop < gExtendedArmyGunChoices[ uiGunLevel ].ubChoices; uiLoop++ )
  98. {
  99. if ( gExtendedArmyGunChoices[ uiGunLevel ].bItemNo[ uiLoop ] == usGun )
  100. {
  101. return( (INT8) uiGunLevel );
  102. }
  103. }
  104. }
  105. return( -1 );
  106. }
  107. void MarkAllWeaponsOfSameGunClassAsDropped( UINT16 usWeapon )
  108. {
  109. INT8 bGunClass;
  110. UINT32 uiLoop;
  111. // mark that item itself as dropped, whether or not it's part of a gun class
  112. gStrategicStatus.fWeaponDroppedAlready[ usWeapon ] = TRUE;
  113. bGunClass = GetWeaponClass( usWeapon );
  114. // if the gun belongs to a gun class (mortars, GLs, LAWs, etc. do not and are handled independently)
  115. if ( bGunClass != -1 )
  116. {
  117. // then mark EVERY gun in that class as dropped
  118. for ( uiLoop = 0; uiLoop < gExtendedArmyGunChoices[ bGunClass ].ubChoices; uiLoop++ )
  119. {
  120. gStrategicStatus.fWeaponDroppedAlready[ gExtendedArmyGunChoices[ bGunClass ].bItemNo[ uiLoop ] ] = TRUE;
  121. }
  122. }
  123. }
  124. //Chooses equipment based on the relative equipment level (0-4) with best being 4. It allocates a range
  125. //of equipment to choose from.
  126. //NOTE: I'm just winging it for the decisions on which items that different groups can have. Basically,
  127. // there are variations, so a guy at a certain level may get a better gun and worse armour or vice versa.
  128. void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8 bEquipmentRating )
  129. {
  130. OBJECTTYPE *pItem;
  131. //general rating information
  132. INT8 bRating = 0;
  133. //numbers of items
  134. INT8 bAmmoClips = 0;
  135. INT8 bGrenades = 0;
  136. BOOLEAN fAttachment = FALSE;
  137. //item levels
  138. INT8 bWeaponClass = 0;
  139. INT8 bHelmetClass = 0;
  140. INT8 bVestClass = 0;
  141. INT8 bLeggingClass = 0;
  142. INT8 bAttachClass = 0;
  143. INT8 bGrenadeClass = 0;
  144. INT8 bKnifeClass = 0;
  145. INT8 bKitClass = 0;
  146. INT8 bMiscClass = 0;
  147. INT8 bBombClass = 0;
  148. //special weapons
  149. BOOLEAN fMortar = FALSE;
  150. BOOLEAN fGrenadeLauncher = FALSE;
  151. BOOLEAN fLAW = FALSE;
  152. INT32 i;
  153. INT8 bEquipmentModifier;
  154. UINT8 ubMaxSpecialWeaponRoll;
  155. Assert( pp );
  156. // kids don't get anything 'cause they don't have any weapon animations and the rest is inappropriate
  157. if ( ( pp->bBodyType == HATKIDCIV ) || ( pp->bBodyType == KIDCIV ) )
  158. {
  159. return;
  160. }
  161. if ( ( pp->bBodyType == TANK_NE ) || ( pp->bBodyType == TANK_NW ) )
  162. {
  163. EquipTank( pp );
  164. return;
  165. }
  166. Assert( ( bSoldierClass >= SOLDIER_CLASS_NONE ) && ( bSoldierClass <= SOLDIER_CLASS_ELITE_MILITIA ) );
  167. Assert( ( bEquipmentRating >= 0 ) && ( bEquipmentRating <= 4 ) );
  168. // equipment level is modified by 1/10 of the difficulty percentage, -5, so it's between -5 to +5
  169. // (on normal, this is actually -4 to +4, easy is -5 to +3, and hard is -3 to +5)
  170. bEquipmentModifier = bEquipmentRating + ( ( CalcDifficultyModifier( bSoldierClass ) / 10 ) - 5 );
  171. switch( bSoldierClass )
  172. {
  173. case SOLDIER_CLASS_NONE:
  174. // ammo is here only so that civilians with pre-assigned ammo will get some clips for it!
  175. bAmmoClips = (INT8)(1 + Random( 2 ));
  176. // civilians get nothing, anyone who should get something should be preassigned by Linda
  177. break;
  178. case SOLDIER_CLASS_ADMINISTRATOR:
  179. case SOLDIER_CLASS_GREEN_MILITIA:
  180. bRating = BAD_ADMINISTRATOR_EQUIPMENT_RATING + bEquipmentModifier;
  181. bRating = (INT8)max( MIN_EQUIPMENT_CLASS, min( MAX_EQUIPMENT_CLASS, bRating ) );
  182. bWeaponClass = bRating;
  183. //Note: in some cases the class of armour and/or helmet won't be high enough to make
  184. // the lowest level.
  185. bVestClass = bRating;
  186. bHelmetClass = bRating;
  187. // no leggings
  188. if( Random( 2 ) )
  189. bKnifeClass = bRating;
  190. bAmmoClips = (INT8)(1 + Random( 2 ));
  191. if( bRating >= GOOD_ADMINISTRATOR_EQUIPMENT_RATING )
  192. {
  193. bAmmoClips++;
  194. bKitClass = bRating;
  195. bMiscClass = bRating;
  196. }
  197. if( bRating >= GREAT_ADMINISTRATOR_EQUIPMENT_RATING )
  198. {
  199. bGrenades = 1, bGrenadeClass = bRating;
  200. }
  201. if( ( bRating > MIN_EQUIPMENT_CLASS ) && bRating < MAX_EQUIPMENT_CLASS )
  202. { //Randomly decide if there is to be an upgrade of guns vs armour (one goes up, the other down)
  203. switch( Random( 5 ) )
  204. {
  205. case 0: bWeaponClass++, bVestClass--; break; //better gun, worse armour
  206. case 1: bWeaponClass--, bVestClass++; break; //worse gun, better armour
  207. }
  208. }
  209. break;
  210. case SOLDIER_CLASS_ARMY:
  211. case SOLDIER_CLASS_REG_MILITIA:
  212. //army guys tend to have a broad range of equipment
  213. bRating = BAD_ARMY_EQUIPMENT_RATING + bEquipmentModifier;
  214. bRating = (INT8)max( MIN_EQUIPMENT_CLASS, min( MAX_EQUIPMENT_CLASS, bRating ) );
  215. bWeaponClass = bRating;
  216. bVestClass = bRating;
  217. bHelmetClass = bRating;
  218. bGrenadeClass = bRating;
  219. if( ( bRating >= GOOD_ARMY_EQUIPMENT_RATING ) && ( Random( 100 ) < 33 ) )
  220. {
  221. fAttachment = TRUE;
  222. bAttachClass = bRating;
  223. }
  224. bAmmoClips = (INT8)(2 + Random( 2 ));
  225. if( bRating >= AVERAGE_ARMY_EQUIPMENT_RATING )
  226. {
  227. bGrenades = (INT8)Random( 2 );
  228. bKitClass = bRating;
  229. bMiscClass = bRating;
  230. }
  231. if( bRating >= GOOD_ARMY_EQUIPMENT_RATING )
  232. {
  233. bGrenades++;
  234. }
  235. if( bRating >= GREAT_ARMY_EQUIPMENT_RATING )
  236. {
  237. bGrenades++;
  238. bLeggingClass = bRating;
  239. if ( Chance( 25 ) )
  240. {
  241. bBombClass = bRating;
  242. }
  243. }
  244. if( Random( 2 ) )
  245. bKnifeClass = bRating;
  246. if( ( bRating > MIN_EQUIPMENT_CLASS ) && bRating < MAX_EQUIPMENT_CLASS )
  247. {
  248. switch( Random( 7 ) )
  249. {
  250. case 3: bWeaponClass++, bVestClass--; break; //better gun, worse armour
  251. case 4: bWeaponClass--, bVestClass++; break; //worse gun, better armour
  252. case 5: bVestClass++, bHelmetClass--; break; //better armour, worse helmet
  253. case 6: bVestClass--, bHelmetClass++; break; //worse armour, better helmet
  254. }
  255. }
  256. // if well-enough equipped, 1/5 chance of something really special
  257. if( ( bRating >= GREAT_ARMY_EQUIPMENT_RATING ) && ( Random( 100 ) < 20 ) )
  258. {
  259. //give this man a special weapon! No mortars if underground, however
  260. ubMaxSpecialWeaponRoll = ( !IsAutoResolveActive() && ( gbWorldSectorZ != 0 ) ) ? 6 : 7;
  261. switch ( Random ( ubMaxSpecialWeaponRoll ) )
  262. {
  263. case 0:
  264. case 1:
  265. case 2:
  266. if ( pp->bExpLevel >= 3 )
  267. {
  268. //grenade launcher
  269. fGrenadeLauncher = TRUE;
  270. bGrenades = 3 + (INT8)(Random( 3 )); //3-5
  271. }
  272. break;
  273. case 3:
  274. case 4:
  275. case 5:
  276. if ( pp->bExpLevel >= 4 )
  277. {
  278. // LAW rocket launcher
  279. fLAW = TRUE;
  280. }
  281. break;
  282. case 6:
  283. // one per team maximum!
  284. if ( ( pp->bExpLevel >= 5 ) && ( guiMortarsRolledByTeam < MAX_MORTARS_PER_TEAM ) )
  285. {
  286. //mortar
  287. fMortar = TRUE;
  288. guiMortarsRolledByTeam++;
  289. // the grenades will actually represent mortar shells in this case
  290. bGrenades = 2 + (INT8)(Random( 3 )); //2-4
  291. bGrenadeClass = MORTAR_GRENADE_CLASS;
  292. }
  293. break;
  294. }
  295. }
  296. break;
  297. case SOLDIER_CLASS_ELITE:
  298. case SOLDIER_CLASS_ELITE_MILITIA:
  299. bRating = BAD_ELITE_EQUIPMENT_RATING + bEquipmentModifier;
  300. bRating = (INT8)max( MIN_EQUIPMENT_CLASS, min( MAX_EQUIPMENT_CLASS, bRating ) );
  301. bWeaponClass = bRating;
  302. bHelmetClass = bRating;
  303. bVestClass = bRating;
  304. bLeggingClass = bRating;
  305. bAttachClass = bRating;
  306. bGrenadeClass = bRating;
  307. bKitClass = bRating;
  308. bMiscClass = bRating;
  309. if ( Chance( 25 ) )
  310. {
  311. bBombClass = bRating;
  312. }
  313. bAmmoClips = (INT8)(3 + Random( 2 ));
  314. bGrenades = (INT8)(1 + Random( 3 ));
  315. if( ( bRating >= AVERAGE_ELITE_EQUIPMENT_RATING ) && ( Random( 100 ) < 75 ) )
  316. {
  317. fAttachment = TRUE;
  318. bAttachClass = bRating;
  319. }
  320. if( Random( 2 ) )
  321. bKnifeClass = bRating;
  322. if( ( bRating > MIN_EQUIPMENT_CLASS ) && bRating < MAX_EQUIPMENT_CLASS )
  323. {
  324. switch( Random( 11 ) )
  325. {
  326. case 4: bWeaponClass++, bVestClass--; break;
  327. case 5: bWeaponClass--, bVestClass--; break;
  328. case 6: bVestClass++, bHelmetClass--; break;
  329. case 7: bGrenades += 2; break;
  330. case 8: bHelmetClass++; break;
  331. case 9: bVestClass++; break;
  332. case 10: bWeaponClass++; break;
  333. }
  334. }
  335. // if well-enough equipped, 1/3 chance of something really special
  336. if( ( bRating >= GOOD_ELITE_EQUIPMENT_RATING ) && ( Random( 100 ) < 33 ) )
  337. {
  338. //give this man a special weapon! No mortars if underground, however
  339. ubMaxSpecialWeaponRoll = ( !IsAutoResolveActive() && ( gbWorldSectorZ != 0 ) ) ? 6 : 7;
  340. switch ( Random ( ubMaxSpecialWeaponRoll ) )
  341. {
  342. case 0:
  343. case 1:
  344. case 2:
  345. //grenade launcher
  346. fGrenadeLauncher = TRUE;
  347. bGrenades = 4 + (INT8)(Random( 4 )); //4-7
  348. break;
  349. case 3:
  350. case 4:
  351. case 5:
  352. // LAW rocket launcher
  353. fLAW = TRUE;
  354. break;
  355. case 6:
  356. // one per team maximum!
  357. if ( guiMortarsRolledByTeam < MAX_MORTARS_PER_TEAM )
  358. {
  359. //mortar
  360. fMortar = TRUE;
  361. guiMortarsRolledByTeam++;
  362. // the grenades will actually represent mortar shells in this case
  363. bGrenades = 3 + (INT8)(Random( 5 )); //3-7
  364. bGrenadeClass = MORTAR_GRENADE_CLASS;
  365. }
  366. break;
  367. }
  368. }
  369. break;
  370. }
  371. for ( i = 0; i < NUM_INV_SLOTS; i++ )
  372. { //clear items, but only if they have write status.
  373. if( !(pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE) )
  374. {
  375. memset( &(pp->Inv[ i ]), 0, sizeof( OBJECTTYPE ) );
  376. pp->Inv[ i ].fFlags |= OBJECT_UNDROPPABLE;
  377. }
  378. else
  379. { //check to see what kind of item is here. If we find a gun, for example, it'll make the
  380. //bWeaponClass negative to signify that a gun has already been specified, and later
  381. //code will use that to determine that and to pick ammo for it.
  382. pItem = &pp->Inv[ i ];
  383. if( !pItem )
  384. continue;
  385. switch( Item[ pItem->usItem ].usItemClass )
  386. {
  387. case IC_GUN:
  388. if ( pItem->usItem != ROCKET_LAUNCHER )
  389. {
  390. bWeaponClass *= -1;
  391. }
  392. else // rocket launcher!
  393. {
  394. fLAW = FALSE;
  395. }
  396. break;
  397. case IC_AMMO:
  398. bAmmoClips = 0;
  399. break;
  400. case IC_BLADE:
  401. case IC_THROWING_KNIFE:
  402. bKnifeClass = 0;
  403. break;
  404. case IC_LAUNCHER:
  405. fGrenadeLauncher = FALSE;
  406. fMortar = FALSE;
  407. break;
  408. case IC_ARMOUR:
  409. if( i == HELMETPOS )
  410. bHelmetClass = 0;
  411. else if( i == VESTPOS )
  412. bVestClass = 0;
  413. else if( i == LEGPOS )
  414. bLeggingClass = 0;
  415. break;
  416. case IC_GRENADE:
  417. bGrenades = 0;
  418. bGrenadeClass = 0;
  419. break;
  420. case IC_MEDKIT:
  421. case IC_KIT:
  422. bKitClass = 0;
  423. break;
  424. case IC_MISC:
  425. bMiscClass = 0;
  426. case IC_BOMB:
  427. bBombClass = 0;
  428. break;
  429. }
  430. }
  431. }
  432. // special: militia shouldn't drop bombs
  433. if ( !( SOLDIER_CLASS_ENEMY( bSoldierClass ) ) )
  434. {
  435. bBombClass = 0;
  436. }
  437. //Now actually choose the equipment!
  438. ChooseWeaponForSoldierCreateStruct( pp, bWeaponClass, bAmmoClips, bAttachClass, fAttachment );
  439. ChooseGrenadesForSoldierCreateStruct( pp, bGrenades, bGrenadeClass, fGrenadeLauncher );
  440. ChooseArmourForSoldierCreateStruct( pp, bHelmetClass, bVestClass, bLeggingClass );
  441. ChooseSpecialWeaponsForSoldierCreateStruct( pp, bKnifeClass, fGrenadeLauncher, fLAW, fMortar );
  442. ChooseFaceGearForSoldierCreateStruct( pp );
  443. ChooseKitsForSoldierCreateStruct( pp, bKitClass );
  444. ChooseMiscGearForSoldierCreateStruct( pp, bMiscClass );
  445. ChooseBombsForSoldierCreateStruct( pp, bBombClass );
  446. ChooseLocationSpecificGearForSoldierCreateStruct( pp );
  447. RandomlyChooseWhichItemsAreDroppable( pp, bSoldierClass );
  448. }
  449. //When using the class values, they should all range from 0-11, 0 meaning that there will be no
  450. //selection for that particular type of item, and 1-11 means to choose an item if possible. 1 is
  451. //the worst class of item, while 11 is the best.
  452. void ChooseWeaponForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bWeaponClass,
  453. INT8 bAmmoClips, INT8 bAttachClass, BOOLEAN fAttachment )
  454. {
  455. INVTYPE *pItem;
  456. OBJECTTYPE Object;
  457. UINT16 i;
  458. UINT16 usRandom;
  459. UINT16 usNumMatches = 0;
  460. UINT16 usGunIndex = 0;
  461. UINT16 usAmmoIndex = 0;
  462. UINT16 usAttachIndex = 0;
  463. UINT8 ubChanceStandardAmmo;
  464. INT8 bStatus;
  465. // Choose weapon:
  466. // WEAPONS are very important, and are therefore handled differently using special pre-generated tables.
  467. // It was requested that enemies use only a small subset of guns with a lot duplication of the same gun type.
  468. // if gun was pre-selected (rcvd negative weapon class) and needs ammo
  469. if( bWeaponClass < 0 && bAmmoClips )
  470. { //Linda has added a specific gun to the merc's inventory, but no ammo. So, we
  471. //will choose ammunition that works with the gun.
  472. for( i = 0; i < NUM_INV_SLOTS; i++ )
  473. {
  474. if( Item[ pp->Inv[ i ].usItem ].usItemClass == IC_GUN )
  475. {
  476. usGunIndex = pp->Inv[ i ].usItem;
  477. ubChanceStandardAmmo = 100 - (bWeaponClass * -9); // weapon class is negative!
  478. usAmmoIndex = RandomMagazine( usGunIndex, ubChanceStandardAmmo );
  479. if ( usGunIndex == ROCKET_RIFLE )
  480. {
  481. pp->Inv[ i ].ubImprintID = (NO_PROFILE + 1);
  482. }
  483. break;
  484. }
  485. }
  486. if( bAmmoClips && usAmmoIndex )
  487. {
  488. CreateItems( usAmmoIndex, 100, bAmmoClips, &Object );
  489. Object.fFlags |= OBJECT_UNDROPPABLE;
  490. PlaceObjectInSoldierCreateStruct( pp, &Object );
  491. }
  492. return;
  493. }
  494. if (bWeaponClass < 1)
  495. return; //empty handed / pre-selected
  496. // reduce anything over 11 to 11
  497. if (bWeaponClass > ARMY_GUN_LEVELS)
  498. {
  499. bWeaponClass = ARMY_GUN_LEVELS;
  500. }
  501. // the weapon class here ranges from 1 to 11, so subtract 1 to get a gun level
  502. usGunIndex = SelectStandardArmyGun( (UINT8) (bWeaponClass - 1));
  503. if( bAmmoClips )
  504. { //We have a gun, so choose ammo clips
  505. // check default ammo first...
  506. usAmmoIndex = DefaultMagazine( usGunIndex );
  507. switch( Magazine[ Item[ usAmmoIndex ].ubClassIndex ].ubAmmoType )
  508. {
  509. case AMMO_AP:
  510. case AMMO_SUPER_AP:
  511. // assault rifle, rocket rifle (etc) - high chance of having AP ammo
  512. ubChanceStandardAmmo = 80;
  513. break;
  514. default:
  515. ubChanceStandardAmmo = 100 - (bWeaponClass * 9);
  516. break;
  517. }
  518. usAmmoIndex = RandomMagazine( usGunIndex, ubChanceStandardAmmo );
  519. }
  520. //Choose attachment
  521. if( bAttachClass && fAttachment )
  522. {
  523. usNumMatches = 0;
  524. while( bAttachClass && !usNumMatches )
  525. { //Count the number of valid attachments.
  526. for( i = 0; i < MAXITEMS; i++ )
  527. {
  528. pItem = &Item[ i ];
  529. if( pItem->usItemClass == IC_MISC && pItem->ubCoolness == bAttachClass && ValidAttachment( i, usGunIndex ) )
  530. usNumMatches++;
  531. }
  532. if( !usNumMatches )
  533. {
  534. bAttachClass--;
  535. }
  536. }
  537. if( usNumMatches )
  538. {
  539. usRandom = (UINT16)Random( usNumMatches );
  540. for( i = 0; i < MAXITEMS; i++ )
  541. {
  542. pItem = &Item[ i ];
  543. if( pItem->usItemClass == IC_MISC && pItem->ubCoolness == bAttachClass && ValidAttachment( i, usGunIndex ) )
  544. {
  545. if( usRandom )
  546. usRandom--;
  547. else
  548. {
  549. usAttachIndex = i;
  550. break;
  551. }
  552. }
  553. }
  554. }
  555. }
  556. //Now, we have chosen all of the correct items. Now, we will assign them into the slots.
  557. //Because we are dealing with enemies, automatically give them full ammo in their weapon.
  558. if( !(pp->Inv[ HANDPOS ].fFlags & OBJECT_NO_OVERWRITE) )
  559. {
  560. switch( pp->ubSoldierClass )
  561. {
  562. case SOLDIER_CLASS_ADMINISTRATOR:
  563. case SOLDIER_CLASS_ARMY:
  564. case SOLDIER_CLASS_GREEN_MILITIA:
  565. case SOLDIER_CLASS_REG_MILITIA:
  566. //Admins/Troops: 60-75% + 1% every 4% progress
  567. bStatus = (INT8)(60 + Random( 16 ));
  568. bStatus += (INT8)(HighestPlayerProgressPercentage() / 4);
  569. bStatus = (INT8)min( 100, bStatus );
  570. break;
  571. case SOLDIER_CLASS_ELITE:
  572. case SOLDIER_CLASS_ELITE_MILITIA:
  573. //85-90% + 1% every 10% progress
  574. bStatus = (INT8)(85 + Random( 6 ));
  575. bStatus += (INT8)(HighestPlayerProgressPercentage() / 10);
  576. bStatus = (INT8)min( 100, bStatus );
  577. break;
  578. default:
  579. bStatus = (INT8)(50 + Random( 51 ) );
  580. break;
  581. }
  582. // don't allow it to be lower than marksmanship, we don't want it to affect their chances of hitting
  583. bStatus = (INT8)max( pp->bMarksmanship, bStatus );
  584. CreateItem( usGunIndex, bStatus, &(pp->Inv[ HANDPOS ]) );
  585. pp->Inv[ HANDPOS ].fFlags |= OBJECT_UNDROPPABLE;
  586. // Rocket Rifles must come pre-imprinted, in case carrier gets killed without getting a shot off
  587. if ( usGunIndex == ROCKET_RIFLE )
  588. {
  589. pp->Inv[ HANDPOS ].ubImprintID = (NO_PROFILE + 1);
  590. }
  591. }
  592. else
  593. { //slot locked, so don't add any attachments to it!
  594. usAttachIndex = 0;
  595. }
  596. //Ammo
  597. if( bAmmoClips && usAmmoIndex )
  598. {
  599. CreateItems( usAmmoIndex, 100, bAmmoClips, &Object );
  600. Object.fFlags |= OBJECT_UNDROPPABLE;
  601. PlaceObjectInSoldierCreateStruct( pp, &Object );
  602. }
  603. if( usAttachIndex )
  604. {
  605. CreateItem( usAttachIndex, 100, &Object );
  606. Object.fFlags |= OBJECT_UNDROPPABLE;
  607. AttachObject( NULL, &(pp->Inv[ HANDPOS ]), &Object );
  608. }
  609. }
  610. void ChooseGrenadesForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bGrenades, INT8 bGrenadeClass, BOOLEAN fGrenadeLauncher )
  611. {
  612. OBJECTTYPE Object;
  613. INT16 sNumPoints;
  614. UINT16 usItem;
  615. UINT8 ubBaseQuality;
  616. UINT8 ubQualityVariation;
  617. //numbers of each type the player will get!
  618. UINT8 ubNumStun = 0;
  619. UINT8 ubNumTear = 0;
  620. UINT8 ubNumMustard = 0;
  621. UINT8 ubNumMini = 0;
  622. UINT8 ubNumReg = 0;
  623. UINT8 ubNumSmoke = 0;
  624. UINT8 ubNumFlare = 0;
  625. //determine how many *points* the enemy will get to spend on grenades...
  626. sNumPoints = bGrenades * bGrenadeClass;
  627. //no points, no grenades!
  628. if( !sNumPoints )
  629. return;
  630. // special mortar shell handling
  631. if (bGrenadeClass == MORTAR_GRENADE_CLASS)
  632. {
  633. CreateItems( MORTAR_SHELL, (INT8) (80 + Random(21)), bGrenades, &Object );
  634. Object.fFlags |= OBJECT_UNDROPPABLE;
  635. PlaceObjectInSoldierCreateStruct( pp, &Object );
  636. return;
  637. }
  638. Assert( bGrenadeClass <= 11 );
  639. //determine the quality of grenades. The elite guys get the best quality, while the others
  640. //get progressively worse.
  641. ubBaseQuality = (UINT8)min( 45 + bGrenadeClass * 5, 90 );
  642. ubQualityVariation = 101 - ubBaseQuality;
  643. //now, purchase the grenades.
  644. while( sNumPoints > 0 )
  645. {
  646. if( sNumPoints >= 20 )
  647. { //Choose randomly between mustard and regular
  648. if( Random( 2 ) && !fGrenadeLauncher )
  649. ubNumMustard++, sNumPoints -= 10;
  650. else
  651. ubNumReg++, sNumPoints -= 9;
  652. }
  653. if( sNumPoints >= 10 )
  654. { //Choose randomly between any
  655. switch( Random( 7 ) )
  656. {
  657. case 0: if ( !fGrenadeLauncher )
  658. {
  659. ubNumMustard++; sNumPoints -= 10; break;
  660. }
  661. // if grenade launcher, pick regular instead
  662. case 1: ubNumReg++; sNumPoints -= 9; break;
  663. case 2: if ( !fGrenadeLauncher )
  664. {
  665. ubNumMini++; sNumPoints -= 7; break;
  666. }
  667. // if grenade launcher, pick tear instead
  668. case 3: ubNumTear++; sNumPoints -= 6; break;
  669. case 4: ubNumStun++; sNumPoints -= 5; break;
  670. case 5: ubNumSmoke++; sNumPoints -= 4; break;
  671. case 6: if (!fGrenadeLauncher )
  672. {
  673. ubNumFlare++; sNumPoints -= 3;
  674. }
  675. break;
  676. }
  677. }
  678. // JA2 Gold: don't make mini-grenades take all points available, and add chance of break lights
  679. if( sNumPoints >= 1 && sNumPoints < 10 )
  680. {
  681. switch( Random( 10 ) )
  682. {
  683. case 0:
  684. case 1:
  685. case 2:
  686. ubNumSmoke++;
  687. sNumPoints -= 4;
  688. break;
  689. case 3:
  690. case 4:
  691. ubNumTear++;
  692. sNumPoints -= 6;
  693. break;
  694. case 5:
  695. case 6:
  696. if (!fGrenadeLauncher)
  697. {
  698. ubNumFlare++;
  699. sNumPoints -= 3;
  700. }
  701. break;
  702. case 7:
  703. case 8:
  704. ubNumStun++;
  705. sNumPoints -= 5;
  706. break;
  707. case 9:
  708. if (!fGrenadeLauncher)
  709. {
  710. ubNumMini++;
  711. sNumPoints -= 7;
  712. }
  713. break;
  714. }
  715. }
  716. /*
  717. if( usNumPoints >= 1 && usNumPoints < 10 )
  718. { //choose randomly between either stun or tear, (normal with rare chance)
  719. switch( Random( 10 ) )
  720. {
  721. case 0:
  722. case 1:
  723. case 2:
  724. case 3:
  725. ubNumSmoke++;
  726. if( usNumPoints > 4 )
  727. usNumPoints -= 4;
  728. else
  729. usNumPoints = 0;
  730. break;
  731. case 4:
  732. case 5:
  733. case 6:
  734. ubNumTear++;
  735. if( usNumPoints > 6 )
  736. usNumPoints -= 6;
  737. else
  738. usNumPoints = 0;
  739. break;
  740. case 7:
  741. case 8:
  742. ubNumStun++;
  743. if( usNumPoints > 5 )
  744. usNumPoints -= 5;
  745. else
  746. usNumPoints = 0;
  747. break;
  748. case 9:
  749. ubNumMini++;
  750. usNumPoints = 0;
  751. break;
  752. }
  753. }
  754. */
  755. }
  756. //Create the grenades and add them to the soldier
  757. if( ubNumSmoke )
  758. {
  759. if ( fGrenadeLauncher )
  760. {
  761. usItem = GL_SMOKE_GRENADE;
  762. }
  763. else
  764. {
  765. usItem = SMOKE_GRENADE;
  766. }
  767. CreateItems( usItem, (INT8)(ubBaseQuality + Random( ubQualityVariation )), ubNumSmoke, &Object );
  768. Object.fFlags |= OBJECT_UNDROPPABLE;
  769. PlaceObjectInSoldierCreateStruct( pp, &Object );
  770. }
  771. if( ubNumTear )
  772. {
  773. if ( fGrenadeLauncher )
  774. {
  775. usItem = GL_TEARGAS_GRENADE;
  776. }
  777. else
  778. {
  779. usItem = TEARGAS_GRENADE;
  780. }
  781. CreateItems( usItem, (INT8)(ubBaseQuality + Random( ubQualityVariation )), ubNumTear, &Object );
  782. Object.fFlags |= OBJECT_UNDROPPABLE;
  783. PlaceObjectInSoldierCreateStruct( pp, &Object );
  784. }
  785. if( ubNumStun )
  786. {
  787. if ( fGrenadeLauncher )
  788. {
  789. usItem = GL_STUN_GRENADE;
  790. }
  791. else
  792. {
  793. usItem = STUN_GRENADE;
  794. }
  795. CreateItems( usItem, (INT8)(ubBaseQuality + Random( ubQualityVariation )), ubNumStun, &Object );
  796. Object.fFlags |= OBJECT_UNDROPPABLE;
  797. PlaceObjectInSoldierCreateStruct( pp, &Object );
  798. }
  799. if( ubNumReg )
  800. {
  801. if ( fGrenadeLauncher )
  802. {
  803. usItem = GL_HE_GRENADE;
  804. }
  805. else
  806. {
  807. usItem = HAND_GRENADE;
  808. }
  809. CreateItems( usItem, (INT8)(ubBaseQuality + Random( ubQualityVariation )), ubNumReg, &Object );
  810. Object.fFlags |= OBJECT_UNDROPPABLE;
  811. PlaceObjectInSoldierCreateStruct( pp, &Object );
  812. }
  813. if( ubNumMini )
  814. {
  815. CreateItems( MINI_GRENADE, (INT8)(ubBaseQuality + Random( ubQualityVariation )), ubNumMini, &Object );
  816. Object.fFlags |= OBJECT_UNDROPPABLE;
  817. PlaceObjectInSoldierCreateStruct( pp, &Object );
  818. }
  819. if( ubNumMustard )
  820. {
  821. CreateItems( MUSTARD_GRENADE, (INT8)(ubBaseQuality + Random( ubQualityVariation )), ubNumMustard, &Object );
  822. Object.fFlags |= OBJECT_UNDROPPABLE;
  823. PlaceObjectInSoldierCreateStruct( pp, &Object );
  824. }
  825. if( ubNumFlare )
  826. {
  827. CreateItems( BREAK_LIGHT, (INT8)(ubBaseQuality + Random( ubQualityVariation )), ubNumFlare, &Object );
  828. Object.fFlags |= OBJECT_UNDROPPABLE;
  829. PlaceObjectInSoldierCreateStruct( pp, &Object );
  830. }
  831. }
  832. void ChooseArmourForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bHelmetClass, INT8 bVestClass, INT8 bLeggingsClass )
  833. {
  834. UINT16 i;
  835. INVTYPE *pItem;
  836. UINT16 usRandom;
  837. UINT16 usNumMatches;
  838. INT8 bOrigVestClass = bVestClass;
  839. OBJECTTYPE Object;
  840. //Choose helmet
  841. if( bHelmetClass )
  842. {
  843. usNumMatches = 0;
  844. while( bHelmetClass && !usNumMatches )
  845. { //First step is to count the number of helmets in the helmet class range. If we
  846. //don't find one, we keep lowering the class until we do.
  847. for( i = 0; i < MAXITEMS; i++ )
  848. {
  849. pItem = &Item[ i ];
  850. // NOTE: This relies on treated armor to have a coolness of 0 in order for enemies not to be equipped with it
  851. if( pItem->usItemClass == IC_ARMOUR && pItem->ubCoolness == bHelmetClass )
  852. {
  853. if( Armour[ pItem->ubClassIndex ].ubArmourClass == ARMOURCLASS_HELMET )
  854. usNumMatches++;
  855. }
  856. }
  857. if( !usNumMatches )
  858. bHelmetClass--;
  859. }
  860. if( usNumMatches )
  861. { //There is a helmet that we can choose.
  862. usRandom = (UINT16)Random( usNumMatches );
  863. for( i = 0; i < MAXITEMS; i++ )
  864. {
  865. pItem = &Item[ i ];
  866. if( pItem->usItemClass == IC_ARMOUR && pItem->ubCoolness == bHelmetClass )
  867. {
  868. if( Armour[ pItem->ubClassIndex ].ubArmourClass == ARMOURCLASS_HELMET )
  869. {
  870. if( usRandom )
  871. usRandom--;
  872. else
  873. {
  874. if( !(pp->Inv[ HELMETPOS ].fFlags & OBJECT_NO_OVERWRITE) )
  875. {
  876. CreateItem( i, (INT8)(70+Random(31)), &(pp->Inv[ HELMETPOS ]) );
  877. pp->Inv[ HELMETPOS ].fFlags |= OBJECT_UNDROPPABLE;
  878. }
  879. break;
  880. }
  881. }
  882. }
  883. }
  884. }
  885. }
  886. //Choose vest
  887. if( bVestClass )
  888. {
  889. usNumMatches = 0;
  890. while( bVestClass && !usNumMatches )
  891. { //First step is to count the number of armours in the armour class range. If we
  892. //don't find one, we keep lowering the class until we do.
  893. for( i = 0; i < MAXITEMS; i++ )
  894. {
  895. // these 3 have a non-zero coolness, and would otherwise be selected, so skip them
  896. if ( ( i == TSHIRT ) || ( i == LEATHER_JACKET ) || ( i == TSHIRT_DEIDRANNA ) )
  897. continue;
  898. pItem = &Item[ i ];
  899. // NOTE: This relies on treated armor to have a coolness of 0 in order for enemies not to be equipped with it
  900. if( pItem->usItemClass == IC_ARMOUR && pItem->ubCoolness == bVestClass )
  901. {
  902. if( Armour[ pItem->ubClassIndex ].ubArmourClass == ARMOURCLASS_VEST )
  903. usNumMatches++;
  904. }
  905. }
  906. if( !usNumMatches )
  907. bVestClass--;
  908. }
  909. if( usNumMatches )
  910. { //There is an armour that we can choose.
  911. usRandom = (UINT16)Random( usNumMatches );
  912. for( i = 0; i < MAXITEMS; i++ )
  913. {
  914. // these 3 have a non-zero coolness, and would otherwise be selected, so skip them
  915. if ( ( i == TSHIRT ) || ( i == LEATHER_JACKET ) || ( i == TSHIRT_DEIDRANNA ) )
  916. continue;
  917. pItem = &Item[ i ];
  918. if( pItem->usItemClass == IC_ARMOUR && pItem->ubCoolness == bVestClass )
  919. {
  920. if( Armour[ pItem->ubClassIndex ].ubArmourClass == ARMOURCLASS_VEST )
  921. {
  922. if( usRandom )
  923. usRandom--;
  924. else
  925. {
  926. if( !(pp->Inv[ VESTPOS ].fFlags & OBJECT_NO_OVERWRITE) )
  927. {
  928. CreateItem( i, (INT8)(70+Random(31)), &(pp->Inv[ VESTPOS ]) );
  929. pp->Inv[ VESTPOS ].fFlags |= OBJECT_UNDROPPABLE;
  930. if ( ( i == KEVLAR_VEST ) || ( i == SPECTRA_VEST ) )
  931. {
  932. // roll to see if he gets a CERAMIC PLATES, too. Higher chance the higher his entitled vest class is
  933. if (( INT8 ) Random( 100 ) < ( 15 * ( bOrigVestClass - pItem->ubCoolness ) ) )
  934. {
  935. CreateItem( CERAMIC_PLATES, (INT8)(70+Random(31)), &Object );
  936. Object.fFlags |= OBJECT_UNDROPPABLE;
  937. AttachObject( NULL, &(pp->Inv[ VESTPOS ]), &Object );
  938. }
  939. }
  940. }
  941. break;
  942. }
  943. }
  944. }
  945. }
  946. }
  947. }
  948. //Choose Leggings
  949. if( bLeggingsClass )
  950. {
  951. usNumMatches = 0;
  952. while( bLeggingsClass && !usNumMatches )
  953. { //First step is to count the number of Armours in the Armour class range. If we
  954. //don't find one, we keep lowering the class until we do.
  955. for( i = 0; i < MAXITEMS; i++ )
  956. {
  957. pItem = &Item[ i ];
  958. // NOTE: This relies on treated armor to have a coolness of 0 in order for enemies not to be equipped with it
  959. if( pItem->usItemClass == IC_ARMOUR && pItem->ubCoolness == bLeggingsClass )
  960. {
  961. if( Armour[ pItem->ubClassIndex ].ubArmourClass == ARMOURCLASS_LEGGINGS )
  962. usNumMatches++;
  963. }
  964. }
  965. if( !usNumMatches )
  966. bLeggingsClass--;
  967. }
  968. if( usNumMatches )
  969. { //There is a legging that we can choose.
  970. usRandom = (UINT16)Random( usNumMatches );
  971. for( i = 0; i < MAXITEMS; i++ )
  972. {
  973. pItem = &Item[ i ];
  974. if( pItem->usItemClass == IC_ARMOUR && pItem->ubCoolness == bLeggingsClass )
  975. {
  976. if( Armour[ pItem->ubClassIndex ].ubArmourClass == ARMOURCLASS_LEGGINGS )
  977. {
  978. if( usRandom )
  979. usRandom--;
  980. else
  981. {
  982. if( !(pp->Inv[ LEGPOS ].fFlags & OBJECT_NO_OVERWRITE) )
  983. {
  984. CreateItem( i, (INT8)(70+Random(31)), &(pp->Inv[ LEGPOS ]) );
  985. pp->Inv[ LEGPOS ].fFlags |= OBJECT_UNDROPPABLE;
  986. break;
  987. }
  988. }
  989. }
  990. }
  991. }
  992. }
  993. }
  994. }
  995. void ChooseSpecialWeaponsForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bKnifeClass,
  996. BOOLEAN fGrenadeLauncher, BOOLEAN fLAW, BOOLEAN fMortar )
  997. {
  998. UINT16 i;
  999. INVTYPE *pItem;
  1000. UINT16 usRandom;
  1001. UINT16 usNumMatches = 0;
  1002. UINT16 usKnifeIndex = 0;
  1003. OBJECTTYPE Object;
  1004. //Choose knife
  1005. while( bKnifeClass && !usNumMatches )
  1006. { //First step is to count the number of weapons in the weapon class range. If we
  1007. //don't find one, we keep lowering the class until we do.
  1008. for( i = 0; i < MAXITEMS; i++ )
  1009. {
  1010. pItem = &Item[ i ];
  1011. if( ( pItem->usItemClass == IC_BLADE || pItem->usItemClass == IC_THROWING_KNIFE ) && pItem->ubCoolness == bKnifeClass )
  1012. {
  1013. usNumMatches++;
  1014. }
  1015. }
  1016. if( !usNumMatches )
  1017. bKnifeClass--;
  1018. }
  1019. if( usNumMatches )
  1020. { //There is a knife that we can choose.
  1021. usRandom = (UINT16)Random( usNumMatches );
  1022. for( i = 0; i < MAXITEMS; i++ )
  1023. {
  1024. pItem = &Item[ i ];
  1025. if( ( pItem->usItemClass == IC_BLADE || pItem->usItemClass == IC_THROWING_KNIFE ) && pItem->ubCoolness == bKnifeClass )
  1026. {
  1027. if( usRandom )
  1028. usRandom--;
  1029. else
  1030. {
  1031. usKnifeIndex = i;
  1032. break;
  1033. }
  1034. }
  1035. }
  1036. }
  1037. if( usKnifeIndex )
  1038. {
  1039. CreateItem( usKnifeIndex, (INT8)(70 + Random( 31 )), &Object );
  1040. Object.fFlags |= OBJECT_UNDROPPABLE;
  1041. PlaceObjectInSoldierCreateStruct( pp, &Object );
  1042. }
  1043. if (fGrenadeLauncher)
  1044. {
  1045. // give grenade launcher
  1046. CreateItem( GLAUNCHER, (INT8)(50 + Random( 51 )), &Object );
  1047. Object.fFlags |= OBJECT_UNDROPPABLE;
  1048. PlaceObjectInSoldierCreateStruct( pp, &Object );
  1049. }
  1050. if (fLAW)
  1051. {
  1052. // give rocket launcher
  1053. CreateItem( ROCKET_LAUNCHER, (INT8)(50 + Random( 51 )), &Object );
  1054. Object.fFlags |= OBJECT_UNDROPPABLE;
  1055. PlaceObjectInSoldierCreateStruct( pp, &Object );
  1056. }
  1057. if (fMortar)
  1058. {
  1059. // make sure we're not distributing them underground!
  1060. Assert( IsAutoResolveActive() || ( gbWorldSectorZ == 0 ) );
  1061. // give mortar
  1062. CreateItem( MORTAR, (INT8)(50 + Random( 51 )), &Object );
  1063. Object.fFlags |= OBJECT_UNDROPPABLE;
  1064. PlaceObjectInSoldierCreateStruct( pp, &Object );
  1065. }
  1066. }
  1067. void ChooseFaceGearForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp )
  1068. {
  1069. INT32 i;
  1070. INT8 bDifficultyRating = CalcDifficultyModifier( pp->ubSoldierClass );
  1071. if ( gWorldSectorX == TIXA_SECTOR_X && gWorldSectorY == TIXA_SECTOR_Y && StrategicMap[ TIXA_SECTOR_X + TIXA_SECTOR_Y * MAP_WORLD_X ].fEnemyControlled )
  1072. { //Tixa is a special case that is handled differently.
  1073. return;
  1074. }
  1075. //Look for any face item in the big pocket positions (the only place they can be added in the editor)
  1076. //If any are found, then don't assign any
  1077. for( i = BIGPOCK1POS; i < BIGPOCK4POS; i++ )
  1078. {
  1079. if( Item[ pp->Inv[ i ].usItem ].usItemClass == IC_FACE )
  1080. {
  1081. return;
  1082. }
  1083. }
  1084. //KM: (NEW)
  1085. //Note the lack of overwritable item checking here. This is because faceitems are not
  1086. //supported in the editor, hence they can't have this status.
  1087. switch( pp->ubSoldierClass )
  1088. {
  1089. case SOLDIER_CLASS_ELITE:
  1090. case SOLDIER_CLASS_ELITE_MILITIA:
  1091. //All elites get a gasmask and either night goggles or uv goggles.
  1092. if( Chance( 75 ) )
  1093. {
  1094. CreateItem( GASMASK, (INT8)(70+Random(31)), &(pp->Inv[ HEAD1POS ]) );
  1095. pp->Inv[ HEAD1POS ].fFlags |= OBJECT_UNDROPPABLE;
  1096. }
  1097. else
  1098. {
  1099. CreateItem( EXTENDEDEAR, (INT8)(70+Random(31)), &(pp->Inv[ HEAD1POS ]) );
  1100. pp->Inv[ HEAD1POS ].fFlags |= OBJECT_UNDROPPABLE;
  1101. }
  1102. if( Chance( 75 ) )
  1103. {
  1104. CreateItem( NIGHTGOGGLES, (INT8)(70+Random(31)), &(pp->Inv[ HEAD2POS ]) );
  1105. pp->Inv[ HEAD2POS ].fFlags |= OBJECT_UNDROPPABLE;
  1106. }
  1107. else
  1108. {
  1109. CreateItem( UVGOGGLES, (INT8)(70+Random(31)), &(pp->Inv[ HEAD2POS ]) );
  1110. pp->Inv[ HEAD2POS ].fFlags |= OBJECT_UNDROPPABLE;
  1111. }
  1112. break;
  1113. case SOLDIER_CLASS_ARMY:
  1114. case SOLDIER_CLASS_REG_MILITIA:
  1115. if( Chance( bDifficultyRating / 2 ) )
  1116. { //chance of getting a face item
  1117. if( Chance( 50 ) )
  1118. {
  1119. CreateItem( GASMASK, (INT8)(70+Random(31)), &(pp->Inv[ HEAD1POS ]) );
  1120. pp->Inv[ HEAD1POS ].fFlags |= OBJECT_UNDROPPABLE;
  1121. }
  1122. else
  1123. {
  1124. CreateItem( NIGHTGOGGLES, (INT8)(70+Random(31)), &(pp->Inv[ HEAD1POS ]) );
  1125. pp->Inv[ HEAD1POS ].fFlags |= OBJECT_UNDROPPABLE;
  1126. }
  1127. }
  1128. if( Chance( bDifficultyRating / 3 ) )
  1129. { //chance of getting a extended ear
  1130. CreateItem( EXTENDEDEAR, (INT8)(70+Random(31)), &(pp->Inv[ HEAD2POS ]) );
  1131. pp->Inv[ HEAD2POS ].fFlags |= OBJECT_UNDROPPABLE;
  1132. }
  1133. break;
  1134. case SOLDIER_CLASS_ADMINISTRATOR:
  1135. case SOLDIER_CLASS_GREEN_MILITIA:
  1136. break;
  1137. }
  1138. }
  1139. void ChooseKitsForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bKitClass )
  1140. {
  1141. UINT16 i;
  1142. INVTYPE *pItem;
  1143. UINT16 usRandom;
  1144. UINT16 usNumMatches = 0;
  1145. OBJECTTYPE Object;
  1146. UINT16 usKitItem = 0;
  1147. // we want these mostly to be first aid and medical kits, and for those kit class doesn't matter, they're always useful
  1148. if ( Chance( 50 ) )
  1149. {
  1150. usKitItem = FIRSTAIDKIT;
  1151. }
  1152. else
  1153. if ( Chance( 25 ) )
  1154. {
  1155. usKitItem = MEDICKIT;
  1156. }
  1157. else
  1158. {
  1159. // count how many non-medical KITS are eligible ( of sufficient or lower coolness)
  1160. for( i = 0; i < MAXITEMS; i++ )
  1161. {
  1162. pItem = &Item[ i ];
  1163. // skip toolkits
  1164. if( ( pItem->usItemClass == IC_KIT ) && ( pItem->ubCoolness > 0 ) && pItem->ubCoolness <= bKitClass && ( i != TOOLKIT ) )
  1165. {
  1166. usNumMatches++;
  1167. }
  1168. }
  1169. // if any are eligible, pick one of them at random
  1170. if( usNumMatches )
  1171. {
  1172. usRandom = (UINT16)Random( usNumMatches );
  1173. for( i = 0; i < MAXITEMS; i++ )
  1174. {
  1175. pItem = &Item[ i ];
  1176. // skip toolkits
  1177. if( ( pItem->usItemClass == IC_KIT ) && ( pItem->ubCoolness > 0 ) && pItem->ubCoolness <= bKitClass && ( i != TOOLKIT ) )
  1178. {
  1179. if( usRandom )
  1180. usRandom--;
  1181. else
  1182. {
  1183. usKitItem = i;
  1184. break;
  1185. }
  1186. }
  1187. }
  1188. }
  1189. }
  1190. if ( usKitItem != 0 )
  1191. {
  1192. CreateItem( usKitItem, (INT8)(80 + Random( 21 )), &Object );
  1193. Object.fFlags |= OBJECT_UNDROPPABLE;
  1194. PlaceObjectInSoldierCreateStruct( pp, &Object );
  1195. }
  1196. }
  1197. void ChooseMiscGearForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bMiscClass )
  1198. {
  1199. UINT16 i;
  1200. INVTYPE *pItem;
  1201. UINT16 usRandom;
  1202. UINT16 usNumMatches = 0;
  1203. OBJECTTYPE Object;
  1204. // not all of these are IC_MISC, some are IC_PUNCH (not covered anywhere else)
  1205. INT32 iMiscItemsList[] =
  1206. {
  1207. CANTEEN,
  1208. CANTEEN,
  1209. CANTEEN,
  1210. CANTEEN,
  1211. ALCOHOL,
  1212. ALCOHOL,
  1213. ADRENALINE_BOOSTER,
  1214. ADRENALINE_BOOSTER,
  1215. REGEN_BOOSTER,
  1216. BRASS_KNUCKLES,
  1217. CHEWING_GUM,
  1218. CIGARS,
  1219. GOLDWATCH,
  1220. -1
  1221. };
  1222. // count how many are eligible
  1223. i = 0;
  1224. while ( iMiscItemsList[ i ] != -1 )
  1225. {
  1226. pItem = &Item[ iMiscItemsList [ i ] ];
  1227. if( ( pItem->ubCoolness > 0 ) && ( pItem->ubCoolness <= bMiscClass ) )
  1228. {
  1229. // exclude REGEN_BOOSTERs unless Sci-Fi flag is on
  1230. if ( ( iMiscItemsList [ i ] != REGEN_BOOSTER ) || ( gGameOptions.fSciFi ) )
  1231. {
  1232. usNumMatches++;
  1233. }
  1234. }
  1235. i++;
  1236. }
  1237. // if any are eligible, pick one of them at random
  1238. if( usNumMatches )
  1239. {
  1240. usRandom = (UINT16)Random( usNumMatches );
  1241. i = 0;
  1242. while ( iMiscItemsList[ i ] != -1 )
  1243. {
  1244. pItem = &Item[ iMiscItemsList [ i ] ];
  1245. if( ( pItem->ubCoolness > 0 ) && ( pItem->ubCoolness <= bMiscClass ) )
  1246. {
  1247. // exclude REGEN_BOOSTERs unless Sci-Fi flag is on
  1248. if ( ( iMiscItemsList [ i ] != REGEN_BOOSTER ) || ( gGameOptions.fSciFi ) )
  1249. {
  1250. if( usRandom )
  1251. usRandom--;
  1252. else
  1253. {
  1254. CreateItem( ( UINT16 ) iMiscItemsList[ i ], (INT8)(80 + Random( 21 )), &Object );
  1255. Object.fFlags |= OBJECT_UNDROPPABLE;
  1256. PlaceObjectInSoldierCreateStruct( pp, &Object );
  1257. break;
  1258. }
  1259. }
  1260. }
  1261. i++;
  1262. }
  1263. }
  1264. }
  1265. void ChooseBombsForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bBombClass )
  1266. {
  1267. UINT16 i;
  1268. INVTYPE *pItem;
  1269. UINT16 usRandom;
  1270. UINT16 usNumMatches = 0;
  1271. OBJECTTYPE Object;
  1272. // count how many are eligible
  1273. for( i = 0; i < MAXITEMS; i++ )
  1274. {
  1275. pItem = &Item[ i ];
  1276. if( ( pItem->usItemClass == IC_BOMB ) && ( pItem->ubCoolness > 0 ) && ( pItem->ubCoolness <= bBombClass ) )
  1277. {
  1278. usNumMatches++;
  1279. }
  1280. }
  1281. // if any are eligible, pick one of them at random
  1282. if( usNumMatches )
  1283. {
  1284. usRandom = (UINT16)Random( usNumMatches );
  1285. for( i = 0; i < MAXITEMS; i++ )
  1286. {
  1287. pItem = &Item[ i ];
  1288. if( ( pItem->usItemClass == IC_BOMB ) && ( pItem->ubCoolness > 0 ) && ( pItem->ubCoolness <= bBombClass ) )
  1289. {
  1290. if( usRandom )
  1291. usRandom--;
  1292. else
  1293. {
  1294. CreateItem( i, (INT8)(80 + Random( 21 )), &Object );
  1295. Object.fFlags |= OBJECT_UNDROPPABLE;
  1296. PlaceObjectInSoldierCreateStruct( pp, &Object );
  1297. break;
  1298. }
  1299. }
  1300. }
  1301. }
  1302. }
  1303. void ChooseLocationSpecificGearForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp )
  1304. {
  1305. OBJECTTYPE Object;
  1306. // If this is Tixa and the player doesn't control Tixa then give all enemies gas masks,
  1307. // but somewhere on their person, not in their face positions
  1308. if ( gWorldSectorX == TIXA_SECTOR_X && gWorldSectorY == TIXA_SECTOR_Y && StrategicMap[ TIXA_SECTOR_X + TIXA_SECTOR_Y * MAP_WORLD_X ].fEnemyControlled )
  1309. {
  1310. CreateItem( GASMASK, (INT8) (95+Random(6)), &Object );
  1311. PlaceObjectInSoldierCreateStruct( pp, &Object );
  1312. }
  1313. }
  1314. BOOLEAN PlaceObjectInSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, OBJECTTYPE *pObject )
  1315. {
  1316. INT8 i;
  1317. if( !Item[ pObject->usItem ].ubPerPocket )
  1318. { //ubPerPocket == 0 will only fit in large pockets.
  1319. pObject->ubNumberOfObjects = 1;
  1320. for( i = BIGPOCK1POS; i <= BIGPOCK4POS; i++ )
  1321. {
  1322. if( !(pp->Inv[ i ].usItem) && !(pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE) )
  1323. {
  1324. memcpy( &(pp->Inv[ i ]), pObject, sizeof( OBJECTTYPE ) );
  1325. return TRUE;
  1326. }
  1327. }
  1328. return FALSE;
  1329. }
  1330. else
  1331. {
  1332. pObject->ubNumberOfObjects = (UINT8)min( Item[ pObject->usItem ].ubPerPocket, pObject->ubNumberOfObjects );
  1333. //try to get it into a small pocket first
  1334. for( i = SMALLPOCK1POS; i <= SMALLPOCK8POS; i++ )
  1335. {
  1336. if( !(pp->Inv[ i ].usItem) && !(pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE) )
  1337. {
  1338. memcpy( &(pp->Inv[ i ]), pObject, sizeof( OBJECTTYPE ) );
  1339. return TRUE;
  1340. }
  1341. }
  1342. for( i = BIGPOCK1POS; i <= BIGPOCK4POS; i++ )
  1343. { //no space free in small pockets, so put it into a large pocket.
  1344. if( !(pp->Inv[ i ].usItem) && !(pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE) )
  1345. {
  1346. memcpy( &(pp->Inv[ i ]), pObject, sizeof( OBJECTTYPE ) );
  1347. return TRUE;
  1348. }
  1349. }
  1350. }
  1351. return FALSE;
  1352. }
  1353. void RandomlyChooseWhichItemsAreDroppable( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass )
  1354. {
  1355. INT32 i;
  1356. // UINT16 usRandomNum;
  1357. UINT32 uiItemClass;
  1358. UINT8 ubNumMatches = 0;
  1359. UINT16 usItem;
  1360. UINT8 ubAmmoDropRate;
  1361. UINT8 ubGrenadeDropRate;
  1362. UINT8 ubOtherDropRate;
  1363. BOOLEAN fWeapon = FALSE;
  1364. BOOLEAN fGrenades = FALSE; // this includes all grenades!
  1365. BOOLEAN fAmmo = FALSE;
  1366. BOOLEAN fArmour = FALSE;
  1367. BOOLEAN fKnife = FALSE;
  1368. BOOLEAN fKit = FALSE;
  1369. BOOLEAN fFace = FALSE;
  1370. BOOLEAN fMisc = FALSE;
  1371. /*
  1372. //40% of soldiers will have droppable items.
  1373. usRandomNum = (UINT16)Random( 1000 );
  1374. if( usRandomNum >= 400 )
  1375. return;
  1376. //so now the number is 0-399. This is kind of like a D&D die roll where
  1377. //various numbers drop different items, or even more than one item. At this
  1378. //point, we don't care if the enemy has anything in the slot that is made droppable.
  1379. //Any items containing the OBJECT_NO_OVERWRITE slot is rejected for droppable
  1380. //consideration.
  1381. if( usRandomNum < 32 ) //3.2% of dead bodies present the possibility of several items (0-5 items : avg 3).
  1382. { //31 is the magic number that allows all 5 item classes to be dropped!
  1383. if( usRandomNum & 16 )
  1384. fWeapon = TRUE;
  1385. if( usRandomNum & 8 )
  1386. fAmmo = TRUE;
  1387. if( usRandomNum & 4 )
  1388. fGrenades = TRUE;
  1389. if( usRandomNum & 2 )
  1390. fArmour = TRUE;
  1391. if( usRandomNum & 1 )
  1392. fMisc = TRUE;
  1393. }
  1394. else if( usRandomNum < 100 ) //6.8% chance of getting 2-3 different items.
  1395. { //do a more generalized approach to dropping items.
  1396. switch( usRandomNum / 10 )
  1397. {
  1398. case 3: fWeapon = TRUE; fAmmo = TRUE; break;
  1399. case 4: fWeapon = TRUE; fGrenades = TRUE; break;
  1400. case 5: fGrenades = TRUE; fMisc = TRUE; break;
  1401. case 6: fGrenades = TRUE; fArmour = TRUE; break;
  1402. case 7: fAmmo = TRUE; fArmour = TRUE; break;
  1403. case 8: fAmmo = TRUE; fArmour = TRUE; fMisc = TRUE; break;
  1404. case 9: fGrenades = TRUE; fAmmo = TRUE; fMisc = TRUE; break;
  1405. }
  1406. }
  1407. else
  1408. {
  1409. switch( usRandomNum / 50 ) //30% chance of getting 1-2 items (no weapons)
  1410. {
  1411. case 2: fGrenades = TRUE; break;
  1412. case 3: fAmmo = TRUE; break;
  1413. case 4: fArmour = TRUE; break;
  1414. case 5: fMisc = TRUE; break;
  1415. case 6: fAmmo = TRUE; fMisc = TRUE; break;
  1416. case 7: fGrenades = TRUE; fAmmo = TRUE; break;
  1417. }
  1418. }
  1419. fKnife = (Random(3)) ? FALSE : TRUE;
  1420. */
  1421. // only enemy soldiers use auto-drop system!
  1422. // don't use the auto-drop system in auto-resolve: player won't see what's being used & enemies will often win & keep'em
  1423. if ( SOLDIER_CLASS_ENEMY( bSoldierClass ) && !IsAutoResolveActive() )
  1424. {
  1425. // SPECIAL handling for weapons: we'll always drop a weapon type that has never been dropped before
  1426. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1427. {
  1428. usItem = pp->Inv[ i ].usItem;
  1429. // if it's a weapon (monster parts included - they won't drop due to checks elsewhere!)
  1430. if ((usItem > NONE) && (usItem < MAX_WEAPONS))
  1431. {
  1432. // and we're allowed to change its flags
  1433. if(! (pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE ))
  1434. {
  1435. // and it's never been dropped before in this game
  1436. if (!gStrategicStatus.fWeaponDroppedAlready[usItem])
  1437. {
  1438. // mark it as droppable, and remember we did so. If the player never kills this particular dude, oh well,
  1439. // tough luck, he missed his chance for an easy reward, he'll have to wait til next time and need some luck...
  1440. pp->Inv[ i ].fFlags &= ~OBJECT_UNDROPPABLE;
  1441. MarkAllWeaponsOfSameGunClassAsDropped( usItem );
  1442. }
  1443. }
  1444. }
  1445. }
  1446. }
  1447. if ( SOLDIER_CLASS_MILITIA( bSoldierClass ) )
  1448. {
  1449. // militia (they drop much less stuff)
  1450. ubAmmoDropRate = MILITIAAMMODROPRATE;
  1451. ubGrenadeDropRate = MILITIAGRENADEDROPRATE;
  1452. ubOtherDropRate = MILITIAEQUIPDROPRATE;
  1453. }
  1454. else
  1455. {
  1456. // enemy army
  1457. ubAmmoDropRate = ENEMYAMMODROPRATE;
  1458. ubGrenadeDropRate = ENEMYGRENADEDROPRATE;
  1459. ubOtherDropRate = ENEMYEQUIPDROPRATE;
  1460. }
  1461. if( Random(100) < ubAmmoDropRate )
  1462. fAmmo = TRUE;
  1463. if( Random(100) < ubOtherDropRate )
  1464. fWeapon = TRUE;
  1465. if( Random(100) < ubOtherDropRate )
  1466. fArmour = TRUE;
  1467. if( Random(100) < ubOtherDropRate )
  1468. fKnife = TRUE;
  1469. if( Random(100) < ubGrenadeDropRate )
  1470. fGrenades = TRUE;
  1471. if( Random(100) < ubOtherDropRate )
  1472. fKit = TRUE;
  1473. if( Random(100) < (UINT32)(ubOtherDropRate / 3) )
  1474. fFace = TRUE;
  1475. if( Random(100) < ubOtherDropRate )
  1476. fMisc = TRUE;
  1477. //Now, that the flags are set for each item, we now have to search through the item slots to
  1478. //see if we can find a matching item, however, if we find any items in a particular class that
  1479. //have the OBJECT_NO_OVERWRITE flag set, we will not make any items droppable for that class
  1480. //because the editor would have specified it already.
  1481. if( fAmmo )
  1482. {
  1483. // now drops ALL ammo found, not just the first slot
  1484. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1485. {
  1486. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1487. if( uiItemClass == IC_AMMO )
  1488. {
  1489. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1490. continue;
  1491. else
  1492. {
  1493. pp->Inv[ i ].fFlags &= ~OBJECT_UNDROPPABLE;
  1494. }
  1495. }
  1496. }
  1497. }
  1498. if( fWeapon )
  1499. {
  1500. ubNumMatches = 0;
  1501. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1502. {
  1503. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1504. if( uiItemClass == IC_GUN || uiItemClass == IC_LAUNCHER )
  1505. {
  1506. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1507. break;
  1508. else
  1509. ubNumMatches++;
  1510. }
  1511. }
  1512. if ( ubNumMatches > 0 )
  1513. {
  1514. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1515. {
  1516. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1517. if( uiItemClass == IC_GUN || uiItemClass == IC_LAUNCHER )
  1518. {
  1519. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1520. break;
  1521. else if( !Random( ubNumMatches-- ) )
  1522. {
  1523. pp->Inv[ i ].fFlags &= ~OBJECT_UNDROPPABLE;
  1524. break;
  1525. }
  1526. }
  1527. }
  1528. }
  1529. }
  1530. if( fArmour )
  1531. {
  1532. ubNumMatches = 0;
  1533. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1534. {
  1535. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1536. if( uiItemClass == IC_ARMOUR )
  1537. {
  1538. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1539. break;
  1540. else
  1541. ubNumMatches++;
  1542. }
  1543. }
  1544. if ( ubNumMatches > 0 )
  1545. {
  1546. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1547. {
  1548. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1549. if( uiItemClass == IC_ARMOUR )
  1550. {
  1551. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1552. break;
  1553. else if( !Random( ubNumMatches-- ) )
  1554. {
  1555. pp->Inv[ i ].fFlags &= ~OBJECT_UNDROPPABLE;
  1556. break;
  1557. }
  1558. }
  1559. }
  1560. }
  1561. }
  1562. if( fKnife)
  1563. {
  1564. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1565. {
  1566. // drops FIRST knife found
  1567. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1568. if( uiItemClass == IC_BLADE || uiItemClass == IC_THROWING_KNIFE )
  1569. {
  1570. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1571. break;
  1572. else
  1573. {
  1574. pp->Inv[ i ].fFlags &= ~OBJECT_UNDROPPABLE;
  1575. break;
  1576. }
  1577. }
  1578. }
  1579. }
  1580. // note that they'll only drop ONE TYPE of grenade if they have multiple types (very common)
  1581. if( fGrenades )
  1582. {
  1583. ubNumMatches = 0;
  1584. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1585. {
  1586. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1587. if( uiItemClass & IC_GRENADE )
  1588. {
  1589. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1590. break;
  1591. else
  1592. ubNumMatches++;
  1593. }
  1594. }
  1595. if ( ubNumMatches > 0 )
  1596. {
  1597. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1598. {
  1599. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1600. if( uiItemClass & IC_GRENADE )
  1601. {
  1602. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1603. break;
  1604. else if( !Random( ubNumMatches-- ) )
  1605. {
  1606. pp->Inv[ i ].fFlags &= ~OBJECT_UNDROPPABLE;
  1607. break;
  1608. }
  1609. }
  1610. }
  1611. }
  1612. }
  1613. if( fKit )
  1614. {
  1615. ubNumMatches = 0;
  1616. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1617. {
  1618. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1619. if( uiItemClass == IC_MEDKIT || uiItemClass == IC_KIT )
  1620. {
  1621. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1622. break;
  1623. else
  1624. ubNumMatches++;
  1625. }
  1626. }
  1627. if ( ubNumMatches > 0 )
  1628. {
  1629. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1630. {
  1631. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1632. if( uiItemClass == IC_MEDKIT || uiItemClass == IC_KIT )
  1633. {
  1634. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1635. break;
  1636. else if( !Random( ubNumMatches-- ) )
  1637. {
  1638. pp->Inv[ i ].fFlags &= ~OBJECT_UNDROPPABLE;
  1639. break;
  1640. }
  1641. }
  1642. }
  1643. }
  1644. }
  1645. if( fFace )
  1646. {
  1647. ubNumMatches = 0;
  1648. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1649. {
  1650. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1651. if( uiItemClass == IC_FACE )
  1652. {
  1653. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1654. break;
  1655. else
  1656. ubNumMatches++;
  1657. }
  1658. }
  1659. if ( ubNumMatches > 0 )
  1660. {
  1661. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1662. {
  1663. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1664. if( uiItemClass == IC_FACE )
  1665. {
  1666. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1667. break;
  1668. else if( !Random( ubNumMatches-- ) )
  1669. {
  1670. pp->Inv[ i ].fFlags &= ~OBJECT_UNDROPPABLE;
  1671. break;
  1672. }
  1673. }
  1674. }
  1675. }
  1676. }
  1677. if( fMisc )
  1678. {
  1679. ubNumMatches = 0;
  1680. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1681. {
  1682. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1683. if( uiItemClass == IC_MISC )
  1684. {
  1685. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1686. break;
  1687. else
  1688. ubNumMatches++;
  1689. }
  1690. }
  1691. if ( ubNumMatches > 0 )
  1692. {
  1693. for( i = 0; i < NUM_INV_SLOTS; i++ )
  1694. {
  1695. uiItemClass = Item[ pp->Inv[ i ].usItem ].usItemClass;
  1696. if( uiItemClass == IC_MISC )
  1697. {
  1698. if( pp->Inv[ i ].fFlags & OBJECT_NO_OVERWRITE )
  1699. break;
  1700. else if( !Random( ubNumMatches-- ) )
  1701. {
  1702. pp->Inv[ i ].fFlags &= ~OBJECT_UNDROPPABLE;
  1703. break;
  1704. }
  1705. }
  1706. }
  1707. }
  1708. }
  1709. }
  1710. void AssignCreatureInventory( SOLDIERTYPE *pSoldier )
  1711. {
  1712. UINT32 uiChanceToDrop = 0;
  1713. BOOLEAN fMaleCreature = FALSE;
  1714. BOOLEAN fBloodcat = FALSE;
  1715. // all creature items in this first section are only offensive/defensive placeholders, and
  1716. // never get dropped, because they're not real items!
  1717. switch( pSoldier->ubBodyType)
  1718. {
  1719. case ADULTFEMALEMONSTER:
  1720. CreateItem( CREATURE_OLD_FEMALE_CLAWS, 100, &(pSoldier->inv[HANDPOS]) );
  1721. CreateItem( CREATURE_OLD_FEMALE_HIDE, 100, &(pSoldier->inv[HELMETPOS]) );
  1722. CreateItem( CREATURE_OLD_FEMALE_HIDE, 100, &(pSoldier->inv[VESTPOS]) );
  1723. CreateItem( CREATURE_OLD_FEMALE_HIDE, 100, &(pSoldier->inv[LEGPOS]) );
  1724. uiChanceToDrop = 30;
  1725. break;
  1726. case AM_MONSTER:
  1727. CreateItem( CREATURE_OLD_MALE_CLAWS, 100, &(pSoldier->inv[HANDPOS]) );
  1728. CreateItem( CREATURE_OLD_MALE_SPIT, 100, &(pSoldier->inv[SECONDHANDPOS]) );
  1729. CreateItem( CREATURE_OLD_MALE_HIDE, 100, &(pSoldier->inv[HELMETPOS]) );
  1730. CreateItem( CREATURE_OLD_MALE_HIDE, 100, &(pSoldier->inv[VESTPOS]) );
  1731. CreateItem( CREATURE_OLD_MALE_HIDE, 100, &(pSoldier->inv[LEGPOS]) );
  1732. uiChanceToDrop = 30;
  1733. fMaleCreature = TRUE;
  1734. break;
  1735. case YAF_MONSTER:
  1736. CreateItem( CREATURE_YOUNG_FEMALE_CLAWS, 100, &(pSoldier->inv[HANDPOS]) );
  1737. CreateItem( CREATURE_YOUNG_FEMALE_HIDE, 100, &(pSoldier->inv[HELMETPOS]) );
  1738. CreateItem( CREATURE_YOUNG_FEMALE_HIDE, 100, &(pSoldier->inv[VESTPOS]) );
  1739. CreateItem( CREATURE_YOUNG_FEMALE_HIDE, 100, &(pSoldier->inv[LEGPOS]) );
  1740. uiChanceToDrop = 15;
  1741. break;
  1742. case YAM_MONSTER:
  1743. CreateItem( CREATURE_YOUNG_MALE_CLAWS, 100, &(pSoldier->inv[HANDPOS]) );
  1744. CreateItem( CREATURE_YOUNG_MALE_SPIT, 100, &(pSoldier->inv[SECONDHANDPOS]) );
  1745. CreateItem( CREATURE_YOUNG_MALE_HIDE, 100, &(pSoldier->inv[HELMETPOS]) );
  1746. CreateItem( CREATURE_YOUNG_MALE_HIDE, 100, &(pSoldier->inv[VESTPOS]) );
  1747. CreateItem( CREATURE_YOUNG_MALE_HIDE, 100, &(pSoldier->inv[LEGPOS]) );
  1748. uiChanceToDrop = 15;
  1749. fMaleCreature = TRUE;
  1750. break;
  1751. case INFANT_MONSTER:
  1752. CreateItem( CREATURE_INFANT_SPIT, 100, &(pSoldier->inv[HANDPOS]) );
  1753. CreateItem( CREATURE_INFANT_HIDE, 100, &(pSoldier->inv[HELMETPOS]) );
  1754. CreateItem( CREATURE_INFANT_HIDE, 100, &(pSoldier->inv[VESTPOS]) );
  1755. CreateItem( CREATURE_INFANT_HIDE, 100, &(pSoldier->inv[LEGPOS]) );
  1756. uiChanceToDrop = 5;
  1757. break;
  1758. case LARVAE_MONSTER:
  1759. uiChanceToDrop = 0;
  1760. break;
  1761. case QUEENMONSTER:
  1762. CreateItem( CREATURE_QUEEN_SPIT, 100, &(pSoldier->inv[HANDPOS]) );
  1763. CreateItem( CREATURE_QUEEN_TENTACLES, 100, &(pSoldier->inv[SECONDHANDPOS]) );
  1764. CreateItem( CREATURE_QUEEN_HIDE, 100, &(pSoldier->inv[HELMETPOS]) );
  1765. CreateItem( CREATURE_QUEEN_HIDE, 100, &(pSoldier->inv[VESTPOS]) );
  1766. CreateItem( CREATURE_QUEEN_HIDE, 100, &(pSoldier->inv[LEGPOS]) );
  1767. // she can't drop anything, because the items are unreachable anyways (she's too big!)
  1768. uiChanceToDrop = 0;
  1769. break;
  1770. case BLOODCAT:
  1771. CreateItem( BLOODCAT_CLAW_ATTACK, 100, &(pSoldier->inv[HANDPOS]) );
  1772. CreateItem( BLOODCAT_BITE, 100, &(pSoldier->inv[SECONDHANDPOS]) );
  1773. fBloodcat = TRUE;
  1774. uiChanceToDrop = 30;
  1775. break;
  1776. default:
  1777. AssertMsg( FALSE, String( "Invalid creature bodytype %d", pSoldier->ubBodyType ) );
  1778. return;
  1779. }
  1780. #ifndef JA2DEMO
  1781. // decide if the creature will drop any REAL bodyparts
  1782. if (Random(100) < uiChanceToDrop)
  1783. {
  1784. CreateItem( (UINT16)(fBloodcat ? BLOODCAT_CLAWS : CREATURE_PART_CLAWS), (INT8) (80 + Random(21)), &(pSoldier->inv[BIGPOCK1POS]) );
  1785. }
  1786. if (Random(100) < uiChanceToDrop)
  1787. {
  1788. CreateItem( (UINT16)(fBloodcat ? BLOODCAT_TEETH : CREATURE_PART_FLESH), (INT8) (80 + Random(21)), &(pSoldier->inv[BIGPOCK2POS]) );
  1789. }
  1790. // as requested by ATE, males are more likely to drop their "organs" (he actually suggested this, I'm serious!)
  1791. if (fMaleCreature)
  1792. {
  1793. // increase chance by 50%
  1794. uiChanceToDrop += (uiChanceToDrop / 2);
  1795. }
  1796. if (Random(100) < uiChanceToDrop)
  1797. {
  1798. CreateItem( (UINT16)(fBloodcat ? BLOODCAT_PELT : CREATURE_PART_ORGAN), (INT8) (80 + Random(21)), &(pSoldier->inv[BIGPOCK3POS]) );
  1799. }
  1800. #endif
  1801. }
  1802. void ReplaceExtendedGuns( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass )
  1803. {
  1804. UINT32 uiLoop, uiLoop2, uiAttachDestIndex;
  1805. INT8 bWeaponClass;
  1806. OBJECTTYPE OldObj;
  1807. UINT16 usItem, usNewGun, usAmmo, usNewAmmo;
  1808. for ( uiLoop = 0; uiLoop < NUM_INV_SLOTS; uiLoop++ )
  1809. {
  1810. usItem = pp->Inv[ uiLoop ].usItem;
  1811. if ( ( Item[ usItem ].usItemClass & IC_GUN ) && ExtendedGunListGun( usItem ) )
  1812. {
  1813. if ( bSoldierClass == SOLDIER_CLASS_NONE )
  1814. {
  1815. usNewGun = StandardGunListReplacement( usItem );
  1816. }
  1817. else
  1818. {
  1819. bWeaponClass = GetWeaponClass( usItem );
  1820. AssertMsg( bWeaponClass != -1, String( "Gun %d does not have a match in the extended gun array", usItem ) );
  1821. usNewGun = SelectStandardArmyGun( bWeaponClass );
  1822. }
  1823. if ( usNewGun != NOTHING )
  1824. {
  1825. // have to replace! but first (ugh) must store backup (b/c of attachments)
  1826. CopyObj( &(pp->Inv[ uiLoop ]), &OldObj );
  1827. CreateItem( usNewGun, OldObj.bGunStatus, &(pp->Inv[ uiLoop ]) );
  1828. pp->Inv[ uiLoop ].fFlags = OldObj.fFlags;
  1829. // copy any valid attachments; for others, just drop them...
  1830. if ( ItemHasAttachments( &OldObj ) )
  1831. {
  1832. // we're going to copy into the first attachment position first :-)
  1833. uiAttachDestIndex = 0;
  1834. // loop!
  1835. for ( uiLoop2 = 0; uiLoop2 < MAX_ATTACHMENTS; uiLoop2++ )
  1836. {
  1837. if ( ( OldObj.usAttachItem[ uiLoop2 ] != NOTHING ) && ValidAttachment( OldObj.usAttachItem[ uiLoop2 ], usNewGun ) )
  1838. {
  1839. pp->Inv[ uiLoop ].usAttachItem[ uiAttachDestIndex ] = OldObj.usAttachItem[ uiLoop2 ];
  1840. pp->Inv[ uiLoop ].bAttachStatus[ uiAttachDestIndex ] = OldObj.bAttachStatus[ uiLoop2 ];
  1841. uiAttachDestIndex++;
  1842. }
  1843. }
  1844. }
  1845. // must search through inventory and replace ammo accordingly
  1846. for ( uiLoop2 = 0; uiLoop2 < NUM_INV_SLOTS; uiLoop2++ )
  1847. {
  1848. usAmmo = pp->Inv[ uiLoop2 ].usItem;
  1849. if ( (Item[ usAmmo ].usItemClass & IC_AMMO) )
  1850. {
  1851. usNewAmmo = FindReplacementMagazineIfNecessary( usItem, usAmmo, usNewGun );
  1852. if (usNewAmmo != NOTHING )
  1853. {
  1854. // found a new magazine, replace...
  1855. CreateItems( usNewAmmo, 100, pp->Inv[ uiLoop2 ].ubNumberOfObjects, &( pp->Inv[ uiLoop2 ] ) );
  1856. }
  1857. }
  1858. }
  1859. }
  1860. }
  1861. }
  1862. }
  1863. UINT16 SelectStandardArmyGun( UINT8 uiGunLevel )
  1864. {
  1865. ARMY_GUN_CHOICE_TYPE *pGunChoiceTable;
  1866. UINT32 uiChoice;
  1867. UINT16 usGunIndex;
  1868. // pick the standard army gun for this weapon class from table
  1869. // usGunIndex = gStrategicStatus.ubStandardArmyGunIndex[uiGunLevel];
  1870. // decided to randomize it afterall instead of repeating the same weapon over and over
  1871. // depending on selection of the gun nut option
  1872. if (gGameOptions.fGunNut)
  1873. {
  1874. // use table of extended gun choices
  1875. pGunChoiceTable = &(gExtendedArmyGunChoices[0]);
  1876. }
  1877. else
  1878. {
  1879. // use table of regular gun choices
  1880. pGunChoiceTable = &(gRegularArmyGunChoices[0]);
  1881. }
  1882. // choose one the of the possible gun choices
  1883. uiChoice = Random(pGunChoiceTable[ uiGunLevel ].ubChoices);
  1884. usGunIndex = pGunChoiceTable[ uiGunLevel ].bItemNo[ uiChoice ];
  1885. Assert(usGunIndex);
  1886. return(usGunIndex);
  1887. }
  1888. void EquipTank( SOLDIERCREATE_STRUCT *pp )
  1889. {
  1890. OBJECTTYPE Object;
  1891. // tanks get special equipment, and they drop nothing (MGs are hard-mounted & non-removable)
  1892. // main cannon
  1893. CreateItem( TANK_CANNON, ( INT8 )( 80 + Random( 21 ) ), &( pp->Inv[ HANDPOS ]) );
  1894. pp->Inv[ HANDPOS ].fFlags |= OBJECT_UNDROPPABLE;
  1895. // machine gun
  1896. CreateItems( MINIMI, ( INT8 )( 80 + Random( 21 ) ), 1, &Object );
  1897. Object.fFlags |= OBJECT_UNDROPPABLE;
  1898. PlaceObjectInSoldierCreateStruct( pp, &Object );
  1899. // tanks don't deplete shells or ammo...
  1900. CreateItems( TANK_SHELL, 100, 1, &Object );
  1901. Object.fFlags |= OBJECT_UNDROPPABLE;
  1902. PlaceObjectInSoldierCreateStruct( pp, &Object );
  1903. // armour equal to spectra all over (for vs explosives)
  1904. CreateItem( SPECTRA_VEST, 100, &(pp->Inv[ VESTPOS ]) );
  1905. pp->Inv[ VESTPOS ].fFlags |= OBJECT_UNDROPPABLE;
  1906. CreateItem( SPECTRA_HELMET, 100, &(pp->Inv[ HELMETPOS ]) );
  1907. pp->Inv[ HELMETPOS ].fFlags |= OBJECT_UNDROPPABLE;
  1908. CreateItem( SPECTRA_LEGGINGS, 100, &(pp->Inv[ LEGPOS ]) );
  1909. pp->Inv[ LEGPOS ].fFlags |= OBJECT_UNDROPPABLE;
  1910. }
  1911. void ResetMortarsOnTeamCount( void )
  1912. {
  1913. guiMortarsRolledByTeam = 0;
  1914. }