************************************************************

* Merged Source Code from Development Trunk: Revision 4063 *
************************************************************
- Source Code is merged from: https://81.169.133.124/source/ja2/branches/Wanne/JA2%201.13%20MP
- This will be the Source for the Beta 2011 Test

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@4064 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Wanne
2011-01-18 09:11:09 +00:00
parent 44e1646410
commit 91087ca8c0
469 changed files with 118108 additions and 24678 deletions
+545 -226
View File
@@ -273,10 +273,54 @@ void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8
// So in the same time when admins hold crappy weapons, elites get stuff up to nearly 6 level
// in Drassen counter-attack. In this situation it is very hard to make balanced xml-file(IMHO).
// Made in optional form
if ( gGameExternalOptions.fSlowProgressForEnemyItemsChoice )
bEquipmentModifier = ( CalcDifficultyModifier( bSoldierClass ) / 10 );
else
bEquipmentModifier = bEquipmentRating + ( ( CalcDifficultyModifier( bSoldierClass ) / 10 ) - 5 );
// SANDRO - new behaviour of progress setting
bEquipmentModifier = bEquipmentRating + ( ( CalcDifficultyModifier( bSoldierClass ) / 10 ) - 5 );
switch( gGameOptions.ubProgressSpeedOfItemsChoices )
{
case ITEM_PROGRESS_VERY_SLOW:
// On "Very Slow", at the beginning of the game, the modifier is -5 and goes up to -1 at +-100% game progress
bEquipmentModifier -= (1 + (4 - (HighestPlayerProgressPercentage() / 25) ));
break;
case ITEM_PROGRESS_SLOW:
// On "Slow", it's -3 until hit at least 10% game progress, then -2 till 40%, then -1 till 80%
if (HighestPlayerProgressPercentage() < 10 )
bEquipmentModifier -= 3;
else if (HighestPlayerProgressPercentage() < 40 )
bEquipmentModifier -= 2;
else if (HighestPlayerProgressPercentage() < 80 )
bEquipmentModifier -= 1;
break;
case ITEM_PROGRESS_NORMAL:
// Nothing needed here
break;
case ITEM_PROGRESS_FAST:
// On "Fast", it's just +1 at the beginning and rise up through out the game
if (HighestPlayerProgressPercentage() < 25 )
bEquipmentModifier += 1;
else if (HighestPlayerProgressPercentage() < 60 )
bEquipmentModifier += 2;
else if (HighestPlayerProgressPercentage() < 90 )
bEquipmentModifier += 3;
else
bEquipmentModifier += 4;
break;
case ITEM_PROGRESS_VERY_FAST:
// "Very Fast" just make everyone loaded with top gear quickly
if (HighestPlayerProgressPercentage() < 10 )
bEquipmentModifier += 2;
else if (HighestPlayerProgressPercentage() < 25 )
bEquipmentModifier += 3;
else if (HighestPlayerProgressPercentage() < 50 )
bEquipmentModifier += 4;
else if (HighestPlayerProgressPercentage() < 80 )
bEquipmentModifier += 5;
else
bEquipmentModifier += 6;
break;
default:
break;
}
switch( bSoldierClass )
{
@@ -287,12 +331,14 @@ void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8
// civilians get nothing, anyone who should get something should be preassigned by Linda
break;
// SANDRO - I've split the item choosing below, so the item choices for militia can be
// handled differently than for enemies.
case SOLDIER_CLASS_ADMINISTRATOR:
case SOLDIER_CLASS_GREEN_MILITIA:
if ( gGameExternalOptions.fSlowProgressForEnemyItemsChoice )
bRating = bEquipmentModifier - ( bSoldierClass == SOLDIER_CLASS_GREEN_MILITIA );
else
bRating = BAD_ADMINISTRATOR_EQUIPMENT_RATING + bEquipmentModifier;
//if ( gGameOptions.fSlowProgressForEnemyItemsChoice )
// bRating = bEquipmentModifier - ( bSoldierClass == SOLDIER_CLASS_ADMINISTRATOR );
//else
bRating = BAD_ADMINISTRATOR_EQUIPMENT_RATING + bEquipmentModifier;
bRating = (INT8)max( MIN_EQUIPMENT_CLASS, min( MAX_EQUIPMENT_CLASS, bRating ) );
bWeaponClass = bRating;
@@ -305,7 +351,7 @@ void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8
bHelmetClass = bRating;
// no leggings
if( Random( 2 ) )
if( Chance( 30 ) )
bKnifeClass = bRating;
bAmmoClips = (INT8)(3 + Random( 2 ));
@@ -325,6 +371,53 @@ void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8
bGrenades = 1, bGrenadeClass = bRating;
}
if( ( bRating > MIN_EQUIPMENT_CLASS ) && bRating < MAX_EQUIPMENT_CLASS )
{ //Randomly decide if there is to be an upgrade of guns vs armour (one goes up, the other down)
switch( Random( 5 ) )
{
case 0: bWeaponClass++, bVestClass--; break; //better gun, worse armour
case 1: bWeaponClass--, bVestClass++; break; //worse gun, better armour
}
}
break;
case SOLDIER_CLASS_GREEN_MILITIA:
bRating = BAD_ADMINISTRATOR_EQUIPMENT_RATING + bEquipmentModifier;
///////////////////////////////////////////////////////////////////////////////////////////
// SANDRO - Militia equipment quality bonus
if ( gGameExternalOptions.bGreenMilitiaEquipmentQualityModifier != 0 )
bRating += gGameExternalOptions.bGreenMilitiaEquipmentQualityModifier;
///////////////////////////////////////////////////////////////////////////////////////////
bRating = (INT8)max( MIN_EQUIPMENT_CLASS, min( MAX_EQUIPMENT_CLASS, bRating ) );
bWeaponClass = bRating;
//Headrocktest, remove for release
//bLBEClass = bRating;
//Note: in some cases the class of armour and/or helmet won't be high enough to make
// the lowest level.
bVestClass = bRating;
bHelmetClass = bRating;
if( Chance( 15 ) )
bKnifeClass = bRating;
bAmmoClips = (INT8)(3 + Random( 2 ));
if( bRating >= GOOD_ADMINISTRATOR_EQUIPMENT_RATING )
{
bAmmoClips++;
bMiscClass = bRating;
}
if( bRating >= GREAT_ADMINISTRATOR_EQUIPMENT_RATING )
{
bGrenades = 1, bGrenadeClass = bRating;
}
if( ( bRating > MIN_EQUIPMENT_CLASS ) && bRating < MAX_EQUIPMENT_CLASS )
{ //Randomly decide if there is to be an upgrade of guns vs armour (one goes up, the other down)
switch( Random( 5 ) )
@@ -336,11 +429,10 @@ void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8
break;
case SOLDIER_CLASS_ARMY:
case SOLDIER_CLASS_REG_MILITIA:
//army guys tend to have a broad range of equipment
if ( gGameExternalOptions.fSlowProgressForEnemyItemsChoice )
bRating = bEquipmentModifier - ( bSoldierClass == SOLDIER_CLASS_REG_MILITIA );
else
//if ( gGameOptions.fSlowProgressForEnemyItemsChoice )
// bRating = bEquipmentModifier - ( bSoldierClass == SOLDIER_CLASS_ARMY );
//else
bRating = BAD_ARMY_EQUIPMENT_RATING + bEquipmentModifier;
bRating = (INT8)max( MIN_EQUIPMENT_CLASS, min( MAX_EQUIPMENT_CLASS, bRating ) );
@@ -350,12 +442,14 @@ void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8
bGrenadeClass = bRating;
// Headrock: Added LBE set to Coolness Rating
bLBEClass = bRating;
//WarmSteel - attachments don't need to be as high a class, controversional and might be better to externalize?
bAttachClass = bRating*3/8;
if( ( bRating >= GOOD_ARMY_EQUIPMENT_RATING ) && ( Random( 100 ) < 33 ) )
if( ( bRating >= GOOD_ARMY_EQUIPMENT_RATING ) && Chance(33) )
{
fAttachment = TRUE;
bAttachClass = bRating;
bAttachClass = bRating*5/8;
}
bAmmoClips = (INT8)(3 + Random( 2 ));
@@ -384,12 +478,12 @@ void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8
}
}
if( Random( 2 ) )
if( Chance( 35 ) )
bKnifeClass = bRating;
// Headrock: Chance for soldier to carry better LBE
if( Chance( 50 ) )
bLBEClass++;
//if( Chance( 50 ) )
// bLBEClass++;
if( ( bRating > MIN_EQUIPMENT_CLASS ) && bRating < MAX_EQUIPMENT_CLASS )
{
@@ -454,12 +548,115 @@ void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8
}
}
break;
case SOLDIER_CLASS_REG_MILITIA:
bRating = BAD_ARMY_EQUIPMENT_RATING + bEquipmentModifier;
///////////////////////////////////////////////////////////////////////////////////////////
// SANDRO - Militia equipment quality bonus
if ( gGameExternalOptions.bRegularMilitiaEquipmentQualityModifier != 0 )
bRating += gGameExternalOptions.bRegularMilitiaEquipmentQualityModifier;
///////////////////////////////////////////////////////////////////////////////////////////
bRating = (INT8)max( MIN_EQUIPMENT_CLASS, min( MAX_EQUIPMENT_CLASS, bRating ) );
bWeaponClass = bRating;
bVestClass = bRating;
bHelmetClass = bRating;
bGrenadeClass = bRating;
//WarmSteel - attachments don't need to be as high a class, controversional and might be better to externalize?
bAttachClass = bRating*3/8;
if( ( bRating >= GOOD_ARMY_EQUIPMENT_RATING ) && Chance(33) )
{
fAttachment = TRUE;
bAttachClass = bRating*5/8;
}
bAmmoClips = (INT8)(3 + Random( 2 ));
if( bRating >= AVERAGE_ARMY_EQUIPMENT_RATING )
{
bGrenades = (INT8)Random( 2 );
bKitClass = bRating;
bMiscClass = bRating;
}
if( bRating >= GOOD_ARMY_EQUIPMENT_RATING )
{
bGrenades++;
}
if( bRating >= GREAT_ARMY_EQUIPMENT_RATING )
{
bGrenades++;
bLeggingClass = bRating;
if ( Chance( 25 ) )
{
bBombClass = bRating;
}
}
if( Chance( 20 ) )
bKnifeClass = bRating;
if( ( bRating > MIN_EQUIPMENT_CLASS ) && bRating < MAX_EQUIPMENT_CLASS )
{
switch( Random( 7 ) )
{
case 3: bWeaponClass++, bVestClass--; break; //better gun, worse armour
case 4: bWeaponClass--, bVestClass++; break; //worse gun, better armour
case 5: bVestClass++, bHelmetClass--; break; //better armour, worse helmet
case 6: bVestClass--, bHelmetClass++; break; //worse armour, better helmet
}
}
// if well-enough equipped, 1/5 chance of something really special
if( ( bRating >= GREAT_ARMY_EQUIPMENT_RATING ) && ( Random( 100 ) < 20 ) )
{
//give this man a special weapon! No mortars if underground, however
ubMaxSpecialWeaponRoll = ( !IsAutoResolveActive() && ( gbWorldSectorZ != 0 ) ) ? 6 : 7;
switch ( Random ( ubMaxSpecialWeaponRoll ) )
{
case 0:
case 1:
case 2:
if ( pp->bExpLevel >= 3 )
{
//grenade launcher
fGrenadeLauncher = TRUE;
bGrenades = 3 + (INT8)(Random( 3 )); //3-5
}
break;
case 3:
case 4:
if ( pp->bExpLevel >= 4 )
{
// LAW rocket launcher
fLAW = TRUE;
}
break;
case 5:
if ( pp->bExpLevel >= 5 )
{
// RPG rocket launcher
fRPG = TRUE;
bGrenades = 2 + (INT8)(Random( 3 )); //2-4
bGrenadeClass = RPG_GRENADE_CLASS;
}
break;
}
}
break;
case SOLDIER_CLASS_ELITE:
case SOLDIER_CLASS_ELITE_MILITIA:
if ( gGameExternalOptions.fSlowProgressForEnemyItemsChoice )
bRating = bEquipmentModifier - ( bSoldierClass == SOLDIER_CLASS_ELITE_MILITIA );
else
//if ( gGameOptions.fSlowProgressForEnemyItemsChoice )
// bRating = bEquipmentModifier - ( bSoldierClass == SOLDIER_CLASS_ELITE );
//else
bRating = BAD_ELITE_EQUIPMENT_RATING + bEquipmentModifier;
bRating = (INT8)max( MIN_EQUIPMENT_CLASS, min( MAX_EQUIPMENT_CLASS, bRating ) );
@@ -467,7 +664,7 @@ void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8
bHelmetClass = bRating;
bVestClass = bRating;
bLeggingClass = bRating;
bAttachClass = bRating;
bAttachClass = bRating*7/8;
bGrenadeClass = bRating;
bKitClass = bRating;
bMiscClass = bRating;
@@ -483,13 +680,13 @@ void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8
bAmmoClips = (INT8)(3 + Random( 2 ));
bGrenades = (INT8)(2 + Random( 3 ));
if( ( bRating >= AVERAGE_ELITE_EQUIPMENT_RATING ) && ( Random( 100 ) < 75 ) )
if( ( bRating >= AVERAGE_ELITE_EQUIPMENT_RATING ) && Chance(75) )
{
fAttachment = TRUE;
bAttachClass = bRating;
}
if( Random( 2 ) )
if( Chance( 35 ) )
bKnifeClass = bRating;
if( ( bRating > MIN_EQUIPMENT_CLASS ) && bRating < MAX_EQUIPMENT_CLASS )
@@ -549,6 +746,106 @@ void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8
}
}
break;
case SOLDIER_CLASS_ELITE_MILITIA:
bRating = BAD_ELITE_EQUIPMENT_RATING + bEquipmentModifier;
///////////////////////////////////////////////////////////////////////////////////////////
// SANDRO - Militia equipment quality bonus
if ( gGameExternalOptions.bVeteranMilitiaEquipmentQualityModifier != 0 )
bRating += gGameExternalOptions.bVeteranMilitiaEquipmentQualityModifier;
///////////////////////////////////////////////////////////////////////////////////////////
bRating = (INT8)max( MIN_EQUIPMENT_CLASS, min( MAX_EQUIPMENT_CLASS, bRating ) );
bWeaponClass = bRating;
bHelmetClass = bRating;
bVestClass = bRating;
bLeggingClass = bRating;
bAttachClass = bRating*7/8;
bGrenadeClass = bRating;
bKitClass = bRating;
bMiscClass = bRating;
if ( Chance( 25 ) )
{
bBombClass = bRating;
}
bAmmoClips = (INT8)(3 + Random( 2 ));
bGrenades = (INT8)(2 + Random( 3 ));
if( ( bRating >= AVERAGE_ELITE_EQUIPMENT_RATING ) && Chance(75) )
{
fAttachment = TRUE;
bAttachClass = bRating;
}
if( Chance( 25 ) )
bKnifeClass = bRating;
if( ( bRating > MIN_EQUIPMENT_CLASS ) && bRating < MAX_EQUIPMENT_CLASS )
{
UINT32 uiRange = ((UsingNewInventorySystem() == false)) ? Random(10) : Random(11);
switch( uiRange )
{
case 4: bWeaponClass++, bVestClass--; break;
case 5: bWeaponClass--, bVestClass--; break;
case 6: bVestClass++, bHelmetClass--; break;
case 7: bGrenades += 2; break;
case 8: bHelmetClass++; break;
case 9: bVestClass++; break;
case 10: bWeaponClass++; break;
//case 11: bLBEClass++; break;
}
}
// if well-enough equipped, 1/3 chance of something really special
if( ( bRating >= GOOD_ELITE_EQUIPMENT_RATING ) && ( Random( 100 ) < 60 ) )
{
//give this man a special weapon! No mortars if underground, however
ubMaxSpecialWeaponRoll = ( !IsAutoResolveActive() && ( gbWorldSectorZ != 0 ) ) ? 4 : 5;
switch ( Random ( ubMaxSpecialWeaponRoll ) )
{
case 0:
//grenade launcher
fGrenadeLauncher = TRUE;
bGrenades = 4 + (INT8)(Random( 4 )); //4-7
break;
case 1:
case 2:
// LAW rocket launcher
fLAW = TRUE;
break;
case 3:
// RPG rocket launcher
fRPG = TRUE;
bGrenades = 3 + (INT8)(Random( 5 )); //3-7
bGrenadeClass = RPG_GRENADE_CLASS;
break;
case 4:
// one per team maximum!
if ( guiMortarsRolledByTeam < MAX_MORTARS_PER_TEAM )
{
//mortar
fMortar = TRUE;
guiMortarsRolledByTeam++;
// the grenades will actually represent mortar shells in this case
bGrenades = 3 + (INT8)(Random( 5 )); //3-7
bGrenadeClass = MORTAR_GRENADE_CLASS;
}
else
{
// RPG rocket launcher
fRPG = TRUE;
bGrenades = 3 + (INT8)(Random( 5 )); //3-7
bGrenadeClass = RPG_GRENADE_CLASS;
}
break;
}
}
break;
}
for ( i = 0; i < pp->Inv.size(); i++ )
@@ -638,17 +935,22 @@ void GenerateRandomEquipment( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass, INT8
//Now actually choose the equipment!
ChooseWeaponForSoldierCreateStruct( pp, bWeaponClass, bAmmoClips, bAttachClass, fAttachment );
// Headrock: This is where the program calls LBE choosing
ChooseLBEsForSoldierCreateStruct( pp, bLBEClass );
if ( SOLDIER_CLASS_ENEMY( bSoldierClass )) // BUT ONLY FOR ENEMIES, NOT MILITIA - SANDRO
{
if (Chance(50)) // Make EDB gear rare
ChooseLBEsForSoldierCreateStruct( pp, bLBEClass );
}
ChooseSpecialWeaponsForSoldierCreateStruct( pp, bKnifeClass, fGrenadeLauncher, fLAW, fMortar, fRPG );
ChooseGrenadesForSoldierCreateStruct( pp, bGrenades, bGrenadeClass, fGrenadeLauncher );
ChooseArmourForSoldierCreateStruct( pp, bHelmetClass, bVestClass, bLeggingClass );
ChooseFaceGearForSoldierCreateStruct( pp );
ChooseKitsForSoldierCreateStruct( pp, bKitClass );
if (Chance(65))
{ ChooseKitsForSoldierCreateStruct( pp, bKitClass ); } // Kits not so often - SANDRO
ChooseMiscGearForSoldierCreateStruct( pp, bMiscClass );
ChooseBombsForSoldierCreateStruct( pp, bBombClass );
//ADB why is this here twice?
// Headrock: This is where the program calls LBE choosing
ChooseLBEsForSoldierCreateStruct( pp, bLBEClass );
//ChooseLBEsForSoldierCreateStruct( pp, bLBEClass ); // SANDRO - removed duplicated
ChooseLocationSpecificGearForSoldierCreateStruct( pp );
RandomlyChooseWhichItemsAreDroppable( pp, bSoldierClass );
@@ -729,147 +1031,7 @@ void ChooseWeaponForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bWeaponC
// the weapon class here ranges from 1 to 11, so subtract 1 to get a gun level
usGunIndex = SelectStandardArmyGun( (UINT8) (bWeaponClass - 1));
//sniper rifles get sniper scopes
if ( Weapon[usGunIndex].ubWeaponType == GUN_SN_RIFLE )
{
usScopeIndex = PickARandomAttachment(SCOPE,usGunIndex,bAttachClass,TRUE);
if ( usScopeIndex == 0 )
{
// find any one that works
usScopeIndex = PickARandomAttachment(SCOPE,usGunIndex,bAttachClass,FALSE);
}
}
//Choose attachment
if( bAttachClass && ( fAttachment ))
{
usAttachIndex = PickARandomAttachment(ATTACHMENTS,usGunIndex,bAttachClass,FALSE);
if ( Item[usGunIndex].defaultattachment > 0 )
{
if ( Item[usGunIndex].defaultattachment == usAttachIndex )
usAttachIndex = 0;
else
{
//check for incompatibilities
for(i = 0;i<sizeof(IncompatibleAttachments);i++)
{
if ( IncompatibleAttachments[i][0] == NONE )
break;
if ( IncompatibleAttachments[i][0] == usAttachIndex && IncompatibleAttachments[i][1] == Item[usGunIndex].defaultattachment )
{
// default attachment wins
usAttachIndex = 0;
break;
}
}
}
if ( usScopeIndex > 0 )
{
if ( Item[usGunIndex].defaultattachment == usScopeIndex )
usScopeIndex = 0;
else
{
//check for incompatibilities w/scope
for(i = 0;i<sizeof(IncompatibleAttachments);i++)
{
if ( IncompatibleAttachments[i][0] == NONE )
break;
if ( IncompatibleAttachments[i][0] == usScopeIndex && IncompatibleAttachments[i][1] == Item[usGunIndex].defaultattachment )
{
// default attachment wins
usScopeIndex = 0;
break;
}
}
}
}
}
else if ( usScopeIndex > 0 )
{
//check for incompatibilities with scope
for(i = 0;i<sizeof(IncompatibleAttachments);i++)
{
if ( IncompatibleAttachments[i][0] == NONE )
break;
if ( IncompatibleAttachments[i][0] == usAttachIndex && IncompatibleAttachments[i][1] == usScopeIndex )
{
// scope wins
usAttachIndex = 0;
break;
}
}
}
else
{
//check for chance of second attachment
if ( ( bAttachClass - Item[usAttachIndex].ubCoolness ) > 0 && Random(2) )
{
usAttachIndex2 = PickARandomAttachment(ATTACHMENTS,usGunIndex,bAttachClass,FALSE);
//check for incompatibilities with 1st attachment
for(i = 0;i<sizeof(IncompatibleAttachments);i++)
{
if ( IncompatibleAttachments[i][0] == NONE )
break;
if ( IncompatibleAttachments[i][0] == usAttachIndex && IncompatibleAttachments[i][1] == usAttachIndex2 )
{
// 1st attachment wins
usAttachIndex2 = 0;
break;
}
}
}
}
#ifdef obsoleteCode
//usNumMatches = 0;
//while( bAttachClass && !usNumMatches )
//{ //Count the number of valid attachments.
// for( i = 0; i < MAXITEMS; i++ )
// {
// if ( Item[i].usItemClass == 0 )
// break;
// pItem = &Item[ i ];
// if( pItem->usItemClass == IC_MISC && pItem->ubCoolness <= bAttachClass && ValidAttachment( i, usGunIndex ) )
// usNumMatches++;
// }
// if( !usNumMatches )
// {
// bAttachClass--;
// }
//}
//if( usNumMatches )
//{
// else
// {
// usRandom = (UINT16)Random( usNumMatches );
// for( i = 0; i < MAXITEMS; i++ )
// {
// if ( Item[i].usItemClass == 0 )
// break;
// pItem = &Item[ i ];
// if( pItem->usItemClass == IC_MISC && pItem->ubCoolness <= bAttachClass && )
// {
// if( usRandom )
// usRandom--;
// else
// {
// usAttachIndex = i;
// break;
// }
// }
// }
// }
//}
#endif //obsoleteCode
}
//WarmSteel - Removed the attachment check here. why check twice anyway?
//Now, we have chosen all of the correct items. Now, we will assign them into the slots.
//Because we are dealing with enemies, automatically give them full ammo in their weapon.
switch( pp->ubSoldierClass )
@@ -907,34 +1069,135 @@ void ChooseWeaponForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bWeaponC
pp->Inv[ HANDPOS ][0]->data.ubImprintID = (NO_PROFILE + 1);
}
if( (pp->Inv[ HANDPOS ].fFlags & OBJECT_NO_OVERWRITE) )
{ //slot locked, so don't add any attachments to it!
usAttachIndex = 0;
}
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"ChooseWeaponForSoldierCreateStruct: Gun Created");
if( !(pp->Inv[ HANDPOS ].fFlags & OBJECT_NO_OVERWRITE) )
{ //slot not locked, so add attachments to it
if(UsingNewAttachmentSystem()==false){
if ( Weapon[usGunIndex].ubWeaponType == GUN_SN_RIFLE )
{
usScopeIndex = PickARandomAttachment(SCOPE,usGunIndex,bAttachClass,TRUE);
if ( usScopeIndex == 0 )
{
// find any one that works
usScopeIndex = PickARandomAttachment(SCOPE,usGunIndex,bAttachClass,FALSE);
}
}
if( usScopeIndex > 0 && ValidItemAttachment(&(pp->Inv[ HANDPOS ]),usScopeIndex,TRUE,FALSE) )
{
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("ChooseWeaponForSoldierCreateStruct: Create Scope %d",usScopeIndex));
CreateItem( usScopeIndex, 100, &gTempObject );
gTempObject.fFlags |= OBJECT_UNDROPPABLE;
pp->Inv[ HANDPOS ].AttachObject( NULL, &gTempObject );
}
if( usAttachIndex > 0 && ValidItemAttachment(&(pp->Inv[ HANDPOS ]),usAttachIndex,TRUE,FALSE))
{
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("ChooseWeaponForSoldierCreateStruct: Create Attachment %d",usAttachIndex));
CreateItem( usAttachIndex, 100, &gTempObject );
gTempObject.fFlags |= OBJECT_UNDROPPABLE;
pp->Inv[ HANDPOS ].AttachObject( NULL, &gTempObject );
}
if( usAttachIndex2 > 0 && ValidItemAttachment(&(pp->Inv[ HANDPOS ]),usAttachIndex2,TRUE,FALSE))
{
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("ChooseWeaponForSoldierCreateStruct: Create 2nd Attachment %d",usAttachIndex2));
CreateItem( usAttachIndex2, 100, &gTempObject );
gTempObject.fFlags |= OBJECT_UNDROPPABLE;
pp->Inv[ HANDPOS ].AttachObject( NULL, &gTempObject );
if( ValidItemAttachment(&(pp->Inv[ HANDPOS ]),usScopeIndex,TRUE,FALSE) )
{
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("ChooseWeaponForSoldierCreateStruct: Create Scope %d",usScopeIndex));
CreateItem( usScopeIndex, 100, &gTempObject );
gTempObject.fFlags |= OBJECT_UNDROPPABLE;
pp->Inv[ HANDPOS ].AttachObject( NULL, &gTempObject, FALSE );
} else {
usScopeIndex = 0;
}
//Choose attachment
if( bAttachClass && ( fAttachment ))
usAttachIndex = PickARandomAttachment(ATTACHMENTS,usGunIndex,bAttachClass,FALSE);
if( ValidItemAttachment(&(pp->Inv[ HANDPOS ]),usAttachIndex,TRUE,FALSE))
{
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("ChooseWeaponForSoldierCreateStruct: Create Attachment %d",usAttachIndex));
CreateItem( usAttachIndex, 100, &gTempObject );
gTempObject.fFlags |= OBJECT_UNDROPPABLE;
pp->Inv[ HANDPOS ].AttachObject( NULL, &gTempObject, FALSE );
} else {
usAttachIndex = 0;
}
//check for chance of second attachment
if ( ( bAttachClass - Item[usAttachIndex].ubCoolness ) > 0 && Random(2) )
usAttachIndex2 = PickARandomAttachment(ATTACHMENTS,usGunIndex,bAttachClass,FALSE);
if( ValidItemAttachment(&(pp->Inv[ HANDPOS ]),usAttachIndex2,TRUE,FALSE))
{
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("ChooseWeaponForSoldierCreateStruct: Create 2nd Attachment %d",usAttachIndex2));
CreateItem( usAttachIndex2, 100, &gTempObject );
gTempObject.fFlags |= OBJECT_UNDROPPABLE;
pp->Inv[ HANDPOS ].AttachObject( NULL, &gTempObject, FALSE );
} else {
usAttachIndex2 = 0;
}
} else {
//The total pool of coolness we have for all the attachments. If fAttachment is true, the chance of getting an attachment is boosted.
INT8 iMiscAttachmentChance = 40 + (fAttachment * 20);
//Add a value equal to the avarage amount of attachments that will be on this gun.
//Because the guns scope does not subtract from this value, -1.
INT16 iAttachmentCoolnessPool = (bAttachClass * (gGameExternalOptions.iMaxEnemyAttachments-1) * iMiscAttachmentChance) / 100;
BOOLEAN fFoundValidAttachment = FALSE;
BOOLEAN fRandomPassed = FALSE;
BOOLEAN fGetMatchingCoolness = FALSE;
UINT16 usTryCount = 0;
//When using NAS, we want more attachments.
if ( Weapon[usGunIndex].ubWeaponType == GUN_SN_RIFLE )
{
usScopeIndex = PickARandomAttachment(SCOPE,usGunIndex,bAttachClass,TRUE);
if ( usScopeIndex == 0 )
{
// find any one that works
usScopeIndex = PickARandomAttachment(SCOPE,usGunIndex,bAttachClass,FALSE);
}
//Guns should have a fairly good chance of having a scope. Even when they're not sniper rifles.
//They're likely to be crappier, though.
} else if (Chance(75) && fAttachment){
usScopeIndex = PickARandomAttachment(SCOPE,usGunIndex,bAttachClass-1,FALSE);
}
if( ValidItemAttachmentSlot(&(pp->Inv[ HANDPOS ]),usScopeIndex, TRUE,FALSE) )
{
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("ChooseWeaponForSoldierCreateStruct: Create Scope %d",usScopeIndex));
CreateItem( usScopeIndex, 100, &gTempObject );
gTempObject.fFlags |= OBJECT_UNDROPPABLE;
pp->Inv[ HANDPOS ].AttachObject( NULL, &gTempObject, FALSE );
}
//Loop for the maximum amount of attachments (-1 because we can already have a scope by here)
//cnt = -1 because we start with ++ing it
for(INT16 cnt = -1; cnt < (gGameExternalOptions.iMaxEnemyAttachments-1); ){
usTryCount++;
usAttachIndex = 0;
//Our coolness pool was depleted, we won't find any more attachments anyway.
if(iAttachmentCoolnessPool <= 0)
break;
//Only move on to the next attachment if 1: we found a good one. 2: randomness decided this attachment won't be. 3: We've exceeded the maximum number of tries.
if(fFoundValidAttachment || !fRandomPassed || usTryCount > 20){
cnt++;
usTryCount = 0;
fFoundValidAttachment = FALSE;
//Determine if this attachments deserves to be.
fRandomPassed = Chance(iMiscAttachmentChance);
//Sometimes allow lower grade attachments.
fGetMatchingCoolness = Chance(70);
}
if (fRandomPassed)
usAttachIndex = PickARandomAttachment(ATTACHMENTS,usGunIndex,bAttachClass,fGetMatchingCoolness);
if(!usAttachIndex){
continue;
}
if( ValidItemAttachmentSlot(&(pp->Inv[ HANDPOS ]),usAttachIndex, TRUE,FALSE))
{
fFoundValidAttachment = TRUE;
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("ChooseWeaponForSoldierCreateStruct: Created Attachment %d, num: %d",usAttachIndex, cnt));
CreateItem( usAttachIndex, 100, &gTempObject );
gTempObject.fFlags |= OBJECT_UNDROPPABLE;
pp->Inv[ HANDPOS ].AttachObject( NULL, &gTempObject, FALSE );
iAttachmentCoolnessPool -= Item[usAttachIndex].ubCoolness;
}
}
}
}
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("ChooseWeaponForSoldierCreateStruct: Set bullets"));
//set bullets = to magsize including any attachments (c-mag adapters, etc)
@@ -1309,30 +1572,72 @@ void ChooseArmourForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bHelmetC
//UINT16 i;
//INVTYPE *pItem;
//UINT16 usRandom;
UINT16 usItem = 0;
UINT16 usItem = 0, usHelmetItem = 0, usVestItem = 0, usLeggingsItem = 0;
//UINT16 usNumMatches;
// INT8 bOrigVestClass = bVestClass;
//INT8 bOrigVestClass = bVestClass;
INT8 i;
//tais: always get any armor... smeagol doesnt like naked people..
if(gGameExternalOptions.fSoldiersWearAnyArmour)
{
if(bHelmetClass < 1) bHelmetClass = 1;
//search for a non-empty class with items we need
for(i=bHelmetClass;i<=10;i++)
{
usHelmetItem = PickARandomItem(HELMET,i );
//if we find a non-empty class change to that and break
if(usHelmetItem > 0)
{
bHelmetClass = i;
break;
}
}
if(bVestClass < 1) bVestClass = 1;
//search for a non-empty class with items we need
for(i=bVestClass;i<=10;i++)
{
usVestItem = PickARandomItem(VEST,i );
//if we find a non-empty class change to that and break
if(usVestItem > 0)
{
bVestClass = i;
break;
}
}
if(bLeggingsClass < 1) bLeggingsClass = 1;
//search for a non-empty class with items we need
for(i=bLeggingsClass;i<=10;i++)
{
usLeggingsItem = PickARandomItem(LEGS,i );
//if we find a non-empty class change to that and break
if(usLeggingsItem > 0)
{
bLeggingsClass = i;
break;
}
}
}
//Madd: added minimum protection of 10 for armours to be used by enemies
//Choose helmet
if( bHelmetClass )
{
usItem = PickARandomItem(HELMET,bHelmetClass );
if ( usItem > 0 && Item[usItem].usItemClass == IC_ARMOUR && !(pp->Inv[ HELMETPOS ].fFlags & OBJECT_NO_OVERWRITE) && Armour[ Item[usItem].ubClassIndex ].ubArmourClass == ARMOURCLASS_HELMET )
if(!gGameExternalOptions.fSoldiersWearAnyArmour) usHelmetItem = PickARandomItem(HELMET,bHelmetClass );
if ( usHelmetItem > 0 && Item[usHelmetItem].usItemClass == IC_ARMOUR && !(pp->Inv[ HELMETPOS ].fFlags & OBJECT_NO_OVERWRITE) && Armour[ Item[usHelmetItem].ubClassIndex ].ubArmourClass == ARMOURCLASS_HELMET )
{
CreateItem( usItem, (INT8)(70+Random(31)), &(pp->Inv[ HELMETPOS ]) );
CreateItem( usHelmetItem, (INT8)(70+Random(31)), &(pp->Inv[ HELMETPOS ]) );
pp->Inv[ HELMETPOS ].fFlags |= OBJECT_UNDROPPABLE;
// roll to see if he gets an attachment, too. Higher chance the higher his entitled helmet class is
if (( INT8 ) Random( 100 ) < ( 15 * ( bHelmetClass - Item[usItem].ubCoolness ) ) )
if (( INT8 ) Random( 100 ) < ( 15 * ( bHelmetClass - Item[usHelmetItem].ubCoolness ) ) )
{
UINT16 usAttachment = PickARandomAttachment(ARMOURATTACHMENT,usItem, bHelmetClass, FALSE);
UINT16 usAttachment = PickARandomAttachment(ARMOURATTACHMENT,usHelmetItem, bHelmetClass, FALSE);
if ( usAttachment > 0 )
{
CreateItem( usAttachment, (INT8)(70+Random(31)), &gTempObject );
gTempObject.fFlags |= OBJECT_UNDROPPABLE;
pp->Inv[ HELMETPOS ].AttachObject( NULL, &gTempObject );
pp->Inv[ HELMETPOS ].AttachObject( NULL, &gTempObject, FALSE );
}
}
@@ -1391,21 +1696,21 @@ void ChooseArmourForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bHelmetC
//Choose vest
if( bVestClass )
{
usItem = PickARandomItem(VEST,bVestClass );
if ( usItem > 0 && Item[usItem].usItemClass == IC_ARMOUR && !(pp->Inv[ VESTPOS ].fFlags & OBJECT_NO_OVERWRITE) && Armour[ Item[usItem].ubClassIndex ].ubArmourClass == ARMOURCLASS_VEST )
if(!gGameExternalOptions.fSoldiersWearAnyArmour) usVestItem = PickARandomItem(VEST,bVestClass );
if ( usVestItem > 0 && Item[usVestItem].usItemClass == IC_ARMOUR && !(pp->Inv[ VESTPOS ].fFlags & OBJECT_NO_OVERWRITE) && Armour[ Item[usVestItem].ubClassIndex ].ubArmourClass == ARMOURCLASS_VEST )
{
CreateItem( usItem, (INT8)(70+Random(31)), &(pp->Inv[ VESTPOS ]) );
CreateItem( usVestItem, (INT8)(70+Random(31)), &(pp->Inv[ VESTPOS ]) );
pp->Inv[ VESTPOS ].fFlags |= OBJECT_UNDROPPABLE;
// roll to see if he gets a CERAMIC PLATES, too. Higher chance the higher his entitled vest class is
if (( INT8 ) Random( 100 ) < ( 15 * ( bVestClass - Item[usItem].ubCoolness ) ) )
if (( INT8 ) Random( 100 ) < ( 15 * ( bVestClass - Item[usVestItem].ubCoolness ) ) )
{
UINT16 usAttachment = PickARandomAttachment(ARMOURATTACHMENT,usItem, bVestClass, FALSE);
UINT16 usAttachment = PickARandomAttachment(ARMOURATTACHMENT,usVestItem, bVestClass, FALSE);
if ( usAttachment > 0 )
{
CreateItem( usAttachment, (INT8)(70+Random(31)), &gTempObject );
gTempObject.fFlags |= OBJECT_UNDROPPABLE;
pp->Inv[ VESTPOS ].AttachObject( NULL, &gTempObject );
pp->Inv[ VESTPOS ].AttachObject( NULL, &gTempObject, FALSE );
}
}
@@ -1485,21 +1790,21 @@ void ChooseArmourForSoldierCreateStruct( SOLDIERCREATE_STRUCT *pp, INT8 bHelmetC
//Choose Leggings
if( bLeggingsClass )
{
usItem = PickARandomItem(LEGS,bLeggingsClass);
if ( usItem > 0 && Item[usItem].usItemClass == IC_ARMOUR && !(pp->Inv[ LEGPOS ].fFlags & OBJECT_NO_OVERWRITE) && Armour[ Item[usItem].ubClassIndex ].ubArmourClass == ARMOURCLASS_LEGGINGS )
if(!gGameExternalOptions.fSoldiersWearAnyArmour) usLeggingsItem = PickARandomItem(LEGS,bLeggingsClass );
if ( usLeggingsItem > 0 && Item[usLeggingsItem].usItemClass == IC_ARMOUR && !(pp->Inv[ LEGPOS ].fFlags & OBJECT_NO_OVERWRITE) && Armour[ Item[usLeggingsItem].ubClassIndex ].ubArmourClass == ARMOURCLASS_LEGGINGS )
{
CreateItem( usItem, (INT8)(70+Random(31)), &(pp->Inv[ LEGPOS ]) );
CreateItem( usLeggingsItem, (INT8)(70+Random(31)), &(pp->Inv[ LEGPOS ]) );
pp->Inv[ LEGPOS ].fFlags |= OBJECT_UNDROPPABLE;
// roll to see if he gets an attachment, too. Higher chance the higher his entitled Leggings class is
if (( INT8 ) Random( 100 ) < ( 15 * ( bLeggingsClass - Item[usItem].ubCoolness ) ) )
if (( INT8 ) Random( 100 ) < ( 15 * ( bLeggingsClass - Item[usLeggingsItem].ubCoolness ) ) )
{
UINT16 usAttachment = PickARandomAttachment(ARMOURATTACHMENT,usItem, bLeggingsClass, FALSE);
UINT16 usAttachment = PickARandomAttachment(ARMOURATTACHMENT,usLeggingsItem, bLeggingsClass, FALSE);
if ( usAttachment > 0 )
{
CreateItem( usAttachment, (INT8)(70+Random(31)), &gTempObject );
gTempObject.fFlags |= OBJECT_UNDROPPABLE;
pp->Inv[ LEGPOS ].AttachObject( NULL, &gTempObject );
pp->Inv[ LEGPOS ].AttachObject( NULL, &gTempObject, FALSE);
}
}
@@ -2137,7 +2442,8 @@ void RandomlyChooseWhichItemsAreDroppable( SOLDIERCREATE_STRUCT *pp, INT8 bSoldi
UINT32 uiRandomValue = 0;
//Madd
if ( gGameSettings.fOptions[TOPTION_DROP_ALL] )
//if ( gGameSettings.fOptions[TOPTION_DROP_ALL] ) // EXTERNILIZED TO THE INI INSTEAD - SANDRO
if ( gGameOptions.fEnemiesDropAllItems )
{
ENEMYAMMODROPRATE = 100;
ENEMYGRENADEDROPRATE = 100;
@@ -2253,7 +2559,8 @@ else
usItem = pp->Inv[ i ].usItem;
//TODO: someday maybe pp->Inv[i].fFlags &= ~ITEM_REPAIRABLE;
if ( gGameSettings.fOptions[TOPTION_DROP_ALL] )
//if ( gGameSettings.fOptions[TOPTION_DROP_ALL] ) // EXTERNILIZED TO THE INI INSTEAD - SANDRO
if ( gGameOptions.fEnemiesDropAllItems )
{
// WANNE: "Drop all" should mean "Drop all"
/*
@@ -2294,7 +2601,8 @@ else
}
}
if ( gGameSettings.fOptions[TOPTION_DROP_ALL] )
//if ( gGameSettings.fOptions[TOPTION_DROP_ALL] ) // EXTERNILIZED TO THE INI INSTEAD - SANDRO
if ( gGameOptions.fEnemiesDropAllItems )
return;
@@ -2925,12 +3233,14 @@ void ReplaceExtendedGuns( SOLDIERCREATE_STRUCT *pp, INT8 bSoldierClass )
CreateItem( usNewGun, (*pObj)[0]->data.gun.bGunStatus, &gTempObject );
gTempObject.fFlags = (*pObj).fFlags;
for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) {
gTempObject.AttachObject(0, &(*iter));
}
//init attachments
InitItemAttachments(pObj);
//for any old attachments that don't fit on the new gun, place or drop them
RemoveProhibitedAttachments(0, &gTempObject, usNewGun);
for (attachmentList::iterator iter = (*pObj)[0]->attachments.begin(); iter != (*pObj)[0]->attachments.end(); ++iter) {
if(iter->exists()){
gTempObject.AttachObject(0, &(*iter), FALSE);
}
}
//copy it over
*pObj = gTempObject;
@@ -3173,7 +3483,7 @@ UINT16 PickARandomAttachment(UINT8 typeIndex, UINT16 usBaseItem, UINT8 maxCoolne
return 0;
// check up to 10 times for an item with a matching coolness
for (int i=0; i < 10;i++)
for (int i=0; i < 50; i++)
{
//if we've already tried more times then there are items + 1, limit the looping to speed up the game, and just plain give up
if ( i > gArmyItemChoices[ typeIndex ].ubChoices )
@@ -3182,14 +3492,23 @@ UINT16 PickARandomAttachment(UINT8 typeIndex, UINT16 usBaseItem, UINT8 maxCoolne
uiChoice = Random(gArmyItemChoices[ typeIndex ].ubChoices);
usItem = gArmyItemChoices[ typeIndex ].bItemNo[ uiChoice ];
if ( usItem >= 0 && Item[usItem].ubCoolness <= maxCoolness && ValidAttachment(usItem,usBaseItem))
BOOLEAN fDefaultAttachment = FALSE;
for(UINT8 cnt = 0; cnt < MAX_DEFAULT_ATTACHMENTS; cnt++){
if(Item[usBaseItem].defaultattachments[cnt] == 0)
break;
if(Item[usBaseItem].defaultattachments[cnt] == usItem){
fDefaultAttachment = TRUE;
}
}
if ( usItem >= 0 && Item[usItem].ubCoolness <= maxCoolness && ValidAttachment(usItem,usBaseItem) && !fDefaultAttachment)
{
// pick a default item in case we don't find anything with a matching coolness, but pick the coolest item we can find
if ( defaultItem == 0 || Item[usItem].ubCoolness > Item[defaultItem].ubCoolness )
defaultItem = usItem;
// found something with the right coolness
if ( Item[usItem].ubCoolness == maxCoolness || !getMatchingCoolness )
if ( (Item[usItem].ubCoolness >= maxCoolness-2) || !getMatchingCoolness )
{
// DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("PickARandomAttachment: baseItem = %d, usItem = %d",usBaseItem, usItem));
if (ItemIsLegal(usItem))