Fixed buffer overrun for LUA strings

Made direction variables more consistent as unsigned chars.  Several function prototypes updated for this.
Many memory leaks plugged:  External options, video overlays, laptop file lists, tactical message queue, strategic pathing, autobandage, merc hiring, detailed placements, crate in Drassen, tactical placement
New functions and attributes for soldiers in LUA (still for debugging at best): Soldier.APs (current APs), Soldier.changestance (changes stance, uses game heights)
File catalog ignores .SVN directories (game load speedup)
Fix CTD in mouse regions
JA2 window now refuses to move to negative coords
Checks to prevent DirectX-related infinite loops due to minimizing and task switching
Invading enemies should now appear on the borders even when reinforcements disabled in .ini
Suppression should no longer work on mercs in medium water
Infant/Young creatures use restored spit instead of Molotov
Creatures begin with their 'guns' (spit) 'locked and loaded' (cartridge in chamber)
Further fix to AXP and AlaarDB's weapon ready check:  Now 'firing' is always counted as 'ready'.
Prevent mercs from falling and flying back through obstacles
Check whether battle group is even set before testing its location for battle setup
Burst spread locations now limited to 6, the limit within the soldier struct
Extra burst spread locations zeroed out so that they aren't used unless necessary
Spread code now only shoots at locations in the spread, and will shoot at all 6
Only mercs in the sector where autobandage happens will be made to stand up after it's done
Throwing a grenade at the tail of the plane in Drassen should not result in a CTD
Reset attack busy count when loading a new sector


git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1347 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Overhaul
2007-09-11 11:19:03 +00:00
parent 63a7b27b29
commit ffc70e9723
81 changed files with 972 additions and 679 deletions
+88 -62
View File
@@ -1314,28 +1314,36 @@ BOOLEAN FireWeapon( SOLDIERTYPE *pSoldier , INT16 sTargetGridNo )
else
{
// ATE: PAtch up - bookkeeping for spreading done out of whak
if ( pSoldier->fDoSpread && !pSoldier->bDoBurst )
if ( pSoldier->fDoSpread)
{
pSoldier->fDoSpread = FALSE;
}
if ( pSoldier->fDoSpread >= MAX_BURST_SPREAD_TARGETS )
{
//If we have more than MAX_BURST_SPREAD_TARGETS bullets, loop over and start again from the first target location
pSoldier->fDoSpread = 1;
if (pSoldier->bDoBurst )
{
pSoldier->fDoSpread = FALSE;
}
// 0verhaul: The original code seemed brain damaged: If the current spread target was 0 it would shoot at the
// non-spread target grid # instead. Also fDoSpread is used as a counter from 1 to MAX_BURST_SPREAD_TARGETS,
// but was actually reset before it got there. So the final spread target would never be shot at. Hopefully this
// will work better.
else if (pSoldier->fDoSpread > MAX_BURST_SPREAD_TARGETS ||
pSoldier->sSpreadLocations[ pSoldier->fDoSpread - 1 ] == 0)
{
if (pSoldier->fDoSpread == 1)
{
// If no spread locations are defined, don't spread
pSoldier->fDoSpread = 0;
}
else
{
// If we hit the end of the array, either by finding a 0 or by exceeding its size, reset
pSoldier->fDoSpread = 1;
}
}
}
if ( pSoldier->fDoSpread )
{
if ( pSoldier->sSpreadLocations[ pSoldier->fDoSpread - 1 ] != 0 )
{
UseGun( pSoldier, pSoldier->sSpreadLocations[ pSoldier->fDoSpread - 1 ] );
}
else
{
UseGun( pSoldier, sTargetGridNo );
}
UseGun( pSoldier, pSoldier->sSpreadLocations[ pSoldier->fDoSpread - 1 ] );
pSoldier->fDoSpread++;
}
else
@@ -1357,28 +1365,36 @@ BOOLEAN FireWeapon( SOLDIERTYPE *pSoldier , INT16 sTargetGridNo )
UseGun( pSoldier, sTargetGridNo );
else
// ATE: PAtch up - bookkeeping for spreading done out of whak
if ( pSoldier->fDoSpread && !pSoldier->bDoBurst )
if ( pSoldier->fDoSpread)
{
pSoldier->fDoSpread = FALSE;
}
if (!pSoldier->bDoBurst )
{
pSoldier->fDoSpread = FALSE;
}
if ( pSoldier->fDoSpread >= MAX_BURST_SPREAD_TARGETS )
{
//If we have more than MAX_BURST_SPREAD_TARGETS bullets, loop over and start again from the first target location
pSoldier->fDoSpread = 1;
// 0verhaul: The original code seemed brain damaged: If the current spread target was 0 it would shoot at the
// non-spread target grid # instead. Also fDoSpread is used as a counter from 1 to MAX_BURST_SPREAD_TARGETS,
// but was actually reset before it got there. So the final spread target would never be shot at. Hopefully this
// will work better.
else if ( pSoldier->fDoSpread > MAX_BURST_SPREAD_TARGETS ||
pSoldier->sSpreadLocations[ pSoldier->fDoSpread - 1 ] == 0)
{
if (pSoldier->fDoSpread == 1)
{
// If no spread locations are defined, don't spread
pSoldier->fDoSpread = 0;
}
else
{
// If we hit the end of the array, either by finding a 0 or by exceeding its size, reset
pSoldier->fDoSpread = 1;
}
}
}
if ( pSoldier->fDoSpread )
{
if ( pSoldier->sSpreadLocations[ pSoldier->fDoSpread - 1 ] != 0 )
{
UseLauncher( pSoldier, pSoldier->sSpreadLocations[ pSoldier->fDoSpread - 1 ] );
}
else
{
UseLauncher( pSoldier, sTargetGridNo );
}
UseLauncher( pSoldier, pSoldier->sSpreadLocations[ pSoldier->fDoSpread - 1 ] );
pSoldier->fDoSpread++;
}
else
@@ -1917,7 +1933,7 @@ BOOLEAN UseGun( SOLDIERTYPE *pSoldier , INT16 sTargetGridNo )
}
// Direction to center of explosion
ubDirection = gOppositeDirection[ pSoldier->bDirection ];
ubDirection = gOppositeDirection[ pSoldier->ubDirection ];
sNewGridNo = NewGridNo( (UINT16)pSoldier->sGridNo, (UINT16)(1 * DirectionInc( ubDirection ) ) );
// Check if a person exists here and is not prone....
@@ -1932,7 +1948,7 @@ BOOLEAN UseGun( SOLDIERTYPE *pSoldier , INT16 sTargetGridNo )
DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("Incrementing Attack: Exaust from LAW", gTacticalStatus.ubAttackBusyCount ) );
DebugAttackBusy( "Incrementing Attack: Exaust from LAW\n" );
EVENT_SoldierGotHit( MercPtrs[ ubMerc ], MINI_GRENADE, 10, 200, pSoldier->bDirection, 0, pSoldier->ubID, 0, ANIM_CROUCH, 0, sNewGridNo );
EVENT_SoldierGotHit( MercPtrs[ ubMerc ], MINI_GRENADE, 10, 200, pSoldier->ubDirection, 0, pSoldier->ubID, 0, ANIM_CROUCH, 0, sNewGridNo );
}
}
}
@@ -2602,7 +2618,7 @@ BOOLEAN UseThrown( SOLDIERTYPE *pSoldier, INT16 sTargetGridNo )
//AXP 25.03.2007: Cleaned up throwing AP costs. Now only turning + stance change AP
// costs are deducted. Final throw cost is deducted on creating the grenade object
if ( (UINT8)GetDirectionFromGridNo( sTargetGridNo, pSoldier ) != pSoldier->bDirection )
if ( (UINT8)GetDirectionFromGridNo( sTargetGridNo, pSoldier ) != pSoldier->ubDirection )
sAPCost += (INT16)GetAPsToLook( pSoldier );
sAPCost += (INT16)GetAPsToChangeStance( pSoldier, ANIM_STAND );
@@ -2897,29 +2913,30 @@ BOOLEAN DoSpecialEffectAmmoMiss( UINT8 ubAttackerID, INT16 sGridNo, INT16 sXPos,
// gTacticalStatus.ubAttackBusyCount++;
// DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("Incrementing Attack: Explosion gone off, COunt now %d", gTacticalStatus.ubAttackBusyCount ) );
PlayJA2Sample( CREATURE_GAS_NOISE, RATE_11025, SoundVolume( HIGHVOLUME, sGridNo ), 1, SoundDir( sGridNo ) );
PlayJA2Sample( CREATURE_GAS_NOISE, RATE_11025, SoundVolume( HIGHVOLUME, sGridNo ), 1, SoundDir( sGridNo ) );
// 0verhaul: Not ready to simplify this to a single call yet. What we need in order to
// fix this correctly is to detach 'alien spit' as a special caliber and instead add 3 new calibers for actual "ammo":
// very small spit, small spit, and large spit. Then we need to add a special effect miss index to point to the
// appropriate smoke effect to disperse.
//NewSmokeEffect( sGridNo, usItem, 0, ubAttackerID);
// WDS fix 07/25/2007
// Don't have monsters cause explosions
// NewSmokeEffect( sGridNo, usItem, 0, ubAttackerID );
// Do Spread effect.......
switch( usItem )
{
case CREATURE_YOUNG_MALE_SPIT:
case CREATURE_INFANT_SPIT:
// // Do Spread effect.......
// switch( usItem )
// {
// case CREATURE_YOUNG_MALE_SPIT:
//case CREATURE_INFANT_SPIT:
NewSmokeEffect( sGridNo, VERY_SMALL_CREATURE_GAS, 0, ubAttackerID );
break;
case CREATURE_OLD_MALE_SPIT:
NewSmokeEffect( sGridNo, SMALL_CREATURE_GAS, 0, ubAttackerID );
break;
// NewSmokeEffect( sGridNo, VERY_SMALL_CREATURE_GAS, 0, ubAttackerID );
// break;
// case CREATURE_OLD_MALE_SPIT:
// NewSmokeEffect( sGridNo, SMALL_CREATURE_GAS, 0, ubAttackerID );
// break;
// case CREATURE_QUEEN_SPIT:
// NewSmokeEffect( sGridNo, LARGE_CREATURE_GAS, 0, ubAttackerID );
// break;
// }
}
case CREATURE_QUEEN_SPIT:
NewSmokeEffect( sGridNo, LARGE_CREATURE_GAS, 0, ubAttackerID );
break;
}
}
return( FALSE );
}
@@ -2980,7 +2997,7 @@ void WeaponHit( UINT16 usSoldierID, UINT16 usWeaponIndex, INT16 sDamage, INT16 s
DoSpecialEffectAmmoMiss( ubAttackerID, pTargetSoldier->sGridNo, sXPos, sYPos, sZPos, FALSE, FALSE, 0 );
// OK, SHOT HAS HIT, DO THINGS APPROPRIATELY
// ATE: This is 'cause of that darn smoke effect that could potnetially kill
// ATE: This is 'cause of that darn smoke effect that could potentially kill
// the poor bastard .. so check
if ( !pTargetSoldier->fDoingExternalDeath )
{
@@ -2988,7 +3005,7 @@ void WeaponHit( UINT16 usSoldierID, UINT16 usWeaponIndex, INT16 sDamage, INT16 s
}
// else
// {
// Buddy had died from additional dammage - free up attacker here...
// Buddy had died from additional damage - free up attacker here...
// ReduceAttackBusyCount( pTargetSoldier->ubAttackerID, FALSE );
// DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String("Special effect killed before bullet impact, attack count now %d", gTacticalStatus.ubAttackBusyCount) );
// OutputDebugString( "Special effect killed before bullet impact\n" );
@@ -3228,7 +3245,7 @@ void StructureHit( INT32 iBullet, UINT16 usWeaponIndex, INT8 bWeaponStatus, UINT
usMissTileType = FIRSTMISS;
// Check if we are in water...
if ( gpWorldLevelData[ sGridNo ].ubTerrainID == LOW_WATER || gpWorldLevelData[ sGridNo ].ubTerrainID == DEEP_WATER )
if ( TERRAIN_IS_WATER( gpWorldLevelData[ sGridNo ].ubTerrainID) )
{
usMissTileIndex = SECONDMISS1;
usMissTileType = SECONDMISS;
@@ -3688,7 +3705,7 @@ UINT32 CalcChanceToHitGun(SOLDIERTYPE *pSoldier, UINT16 sGridNo, UINT8 ubAimTime
{
iSightRange = SoldierTo3DLocationLineOfSightTest( pSoldier, sGridNo, pSoldier->bTargetLevel, pSoldier->bTargetCubeLevel, TRUE, NO_DISTANCE_LIMIT );
}
//restore old flag
gAnimControl[ pSoldier->usAnimState ].uiFlags = oldFlag;
@@ -4498,7 +4515,7 @@ INT32 BulletImpact( SOLDIERTYPE *pFirer, SOLDIERTYPE * pTarget, UINT8 ubHitLocat
break;
case AIM_SHOT_LEGS:
// is the damage enough to make us fall over?
if ( pubSpecial && IS_MERC_BODY_TYPE( pTarget ) && gAnimControl[ pTarget->usAnimState ].ubEndHeight == ANIM_STAND && pTarget->bOverTerrainType != LOW_WATER && pTarget->bOverTerrainType != MED_WATER && pTarget->bOverTerrainType != DEEP_WATER )
if ( pubSpecial && IS_MERC_BODY_TYPE( pTarget ) && gAnimControl[ pTarget->usAnimState ].ubEndHeight == ANIM_STAND && !MercInWater( pTarget) )
{
if (iImpactForCrits > MIN_DAMAGE_FOR_AUTO_FALL_OVER )
{
@@ -5355,6 +5372,14 @@ INT32 CalcMaxTossRange( SOLDIERTYPE * pSoldier, UINT16 usItem, BOOLEAN fArmed )
// better max range due to expertise
iRange = iRange * (100 + gbSkillTraitBonus[THROWING] * NUM_SKILL_TRAITS( pSoldier, THROWING ) ) / 100;
}
// Adjust for thrower's stance
if (gAnimControl[ pSoldier->usAnimState ].ubEndHeight < ANIM_STAND)
{
// For now we just assume the thrower is crouched since we don't allow prone tossing at the moment
// So dock 30% from the distance
iRange = (iRange * 70) / 100;
}
}
if (iRange < 1)
@@ -5768,12 +5793,13 @@ BOOLEAN WeaponReady(SOLDIERTYPE * pSoldier)
if ( AM_A_ROBOT( pSoldier) )
return TRUE;
#endif
if ( gAnimControl[ pSoldier->usAnimState ].uiFlags & ANIM_FIREREADY )
if ( (gAnimControl[ pSoldier->usAnimState ].uiFlags & ANIM_FIREREADY ) ||
(gAnimControl[ pSoldier->usAnimState ].uiFlags & ANIM_FIRE ) )
return TRUE;
else
return FALSE;
}
INT8 GetAPsToReload( OBJECTTYPE *pObj )
{
// DebugMsg(TOPIC_JA2,DBG_LEVEL_3,String("GetAPsToReload"));