mirror of
https://github.com/1dot13/source.git
synced 2026-08-19 14:20:30 +02:00
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:
+16
-16
@@ -1101,7 +1101,7 @@ void FreeUpNPCFromTurning(SOLDIERTYPE *pSoldier, INT8 bLook)
|
||||
{
|
||||
#ifdef TESTAI
|
||||
DebugMsg( TOPIC_JA2AI, DBG_LEVEL_3,
|
||||
String("FREEUPNPCFROMTURNING: our action %d, desdir %d dir %d",pSoldier->bAction,pSoldier->bDesiredDirection,pSoldier->bDirection) );
|
||||
String("FREEUPNPCFROMTURNING: our action %d, desdir %d dir %d",pSoldier->bAction,pSoldier->bDesiredDirection,pSoldier->ubDirection) );
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1160,7 +1160,7 @@ void ActionDone(SOLDIERTYPE *pSoldier)
|
||||
{
|
||||
#ifdef TESTAI
|
||||
DebugMsg( TOPIC_JA2AI, DBG_LEVEL_3,
|
||||
String("Cancelling actiondone: our action %d, desdir %d dir %d",pSoldier->bAction,pSoldier->bDesiredDirection,pSoldier->bDirection) );
|
||||
String("Cancelling actiondone: our action %d, desdir %d dir %d",pSoldier->bAction,pSoldier->bDesiredDirection,pSoldier->ubDirection) );
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1177,7 +1177,7 @@ void ActionDone(SOLDIERTYPE *pSoldier)
|
||||
|
||||
if ( !pSoldier->fNoAPToFinishMove )
|
||||
{
|
||||
EVENT_StopMerc( pSoldier, pSoldier->sGridNo, pSoldier->bDirection );
|
||||
EVENT_StopMerc( pSoldier, pSoldier->sGridNo, pSoldier->ubDirection );
|
||||
AdjustNoAPToFinishMove( pSoldier, FALSE );
|
||||
}
|
||||
|
||||
@@ -1276,9 +1276,9 @@ void NPCDoesAct(SOLDIERTYPE *pSoldier)
|
||||
|
||||
// CJC Feb 18 99: make sure that soldier is not in the middle of a turn due to visual crap to make enemies
|
||||
// face and point their guns at us
|
||||
if ( pSoldier->bDesiredDirection != pSoldier->bDirection )
|
||||
if ( pSoldier->bDesiredDirection != pSoldier->ubDirection )
|
||||
{
|
||||
pSoldier->bDesiredDirection = pSoldier->bDirection;
|
||||
pSoldier->bDesiredDirection = pSoldier->ubDirection;
|
||||
}
|
||||
|
||||
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"NPCDoesAct done");
|
||||
@@ -1421,16 +1421,16 @@ NameMessage(pSoldier,"will now be freed up from turning...",2000);
|
||||
|
||||
// force him to face in the right direction (as long as it's legal)
|
||||
if ((pSoldier->bDesiredDirection >= 1) && (pSoldier->bDesiredDirection <= 8))
|
||||
pSoldier->bDirection = pSoldier->bDesiredDirection;
|
||||
pSoldier->ubDirection = pSoldier->bDesiredDirection;
|
||||
else
|
||||
pSoldier->bDesiredDirection = pSoldier->bDirection;
|
||||
pSoldier->bDesiredDirection = pSoldier->ubDirection;
|
||||
|
||||
// free up ONLY players from whom we haven't received an AI_ACTION_DONE yet
|
||||
// we can all agree the action is DONE and we can continue...
|
||||
// (otherwise they'll be calling FreeUp... twice and get REAL screwed up)
|
||||
NetSend.msgType = NET_FREE_UP_TURN;
|
||||
NetSend.ubID = pSoldier->ubID;
|
||||
NetSend.misc_UCHAR = pSoldier->bDirection;
|
||||
NetSend.misc_UCHAR = pSoldier->ubDirection;
|
||||
NetSend.answer = pSoldier->bDesiredDirection;
|
||||
|
||||
for (cnt = 0; cnt < MAXPLAYERS; cnt++)
|
||||
@@ -2416,7 +2416,7 @@ INT8 ExecuteAction(SOLDIERTYPE *pSoldier)
|
||||
case AI_ACTION_PULL_TRIGGER: // activate an adjacent panic trigger
|
||||
|
||||
// turn to face trigger first
|
||||
if ( FindStructure( (INT16)(pSoldier->sGridNo + DirectionInc( NORTH )), STRUCTURE_SWITCH ) )
|
||||
if ( FindStructure( pSoldier->sGridNo + DirectionInc( NORTH ), STRUCTURE_SWITCH ) )
|
||||
{
|
||||
SendSoldierSetDesiredDirectionEvent( pSoldier, NORTH );
|
||||
}
|
||||
@@ -2553,17 +2553,17 @@ INT8 ExecuteAction(SOLDIERTYPE *pSoldier)
|
||||
case AI_ACTION_LOCK_DOOR:
|
||||
{
|
||||
STRUCTURE * pStructure;
|
||||
INT8 bDirection;
|
||||
UINT8 ubDirection;
|
||||
INT16 sDoorGridNo;
|
||||
|
||||
bDirection = (INT8) GetDirectionFromGridNo( pSoldier->usActionData, pSoldier );
|
||||
if (bDirection == EAST || bDirection == SOUTH)
|
||||
ubDirection = GetDirectionFromGridNo( (INT16)pSoldier->usActionData, pSoldier );
|
||||
if (ubDirection == EAST || ubDirection == SOUTH)
|
||||
{
|
||||
sDoorGridNo = pSoldier->sGridNo;
|
||||
}
|
||||
else
|
||||
{
|
||||
sDoorGridNo = pSoldier->sGridNo + DirectionInc( bDirection );
|
||||
sDoorGridNo = pSoldier->sGridNo + DirectionInc( ubDirection );
|
||||
}
|
||||
|
||||
pStructure = FindStructure( sDoorGridNo, STRUCTURE_ANYDOOR );
|
||||
@@ -2582,14 +2582,14 @@ INT8 ExecuteAction(SOLDIERTYPE *pSoldier)
|
||||
EndAIGuysTurn( pSoldier );
|
||||
}
|
||||
|
||||
StartInteractiveObject( sDoorGridNo, pStructure->usStructureID, pSoldier, bDirection );
|
||||
InteractWithInteractiveObject( pSoldier, pStructure, bDirection );
|
||||
StartInteractiveObject( sDoorGridNo, pStructure->usStructureID, pSoldier, ubDirection );
|
||||
InteractWithInteractiveObject( pSoldier, pStructure, ubDirection );
|
||||
}
|
||||
break;
|
||||
|
||||
case AI_ACTION_LOWER_GUN:
|
||||
// for now, just do "action done"
|
||||
InternalSoldierReadyWeapon(pSoldier,pSoldier->bDirection,TRUE);
|
||||
InternalSoldierReadyWeapon(pSoldier,pSoldier->ubDirection,TRUE);
|
||||
HandleSight(pSoldier, SIGHT_LOOK );
|
||||
ActionDone( pSoldier );
|
||||
break;
|
||||
|
||||
+11
-11
@@ -448,7 +448,7 @@ BOOLEAN IsActionAffordable(SOLDIERTYPE *pSoldier)
|
||||
{
|
||||
INT8 bMinPointsNeeded = 0;
|
||||
INT8 bAPForStandUp = 0;
|
||||
INT8 bAPToLookAtWall = ( FindDirectionForClimbing( pSoldier->sGridNo ) == pSoldier->bDirection ) ? 0 : 1;
|
||||
INT8 bAPToLookAtWall = ( FindDirectionForClimbing( pSoldier->sGridNo ) == pSoldier->ubDirection ) ? 0 : 1;
|
||||
|
||||
//NumMessage("AffordableAction - Guy#",pSoldier->ubID);
|
||||
|
||||
@@ -583,7 +583,7 @@ INT16 RandomFriendWithin(SOLDIERTYPE *pSoldier)
|
||||
UINT32 uiLoop;
|
||||
UINT16 usMaxDist;
|
||||
UINT8 ubFriendCount, ubFriendIDs[MAXMERCS], ubFriendID;
|
||||
UINT16 usDirection;
|
||||
UINT8 ubDirection;
|
||||
UINT8 ubDirsLeft;
|
||||
BOOLEAN fDirChecked[8];
|
||||
BOOLEAN fRangeRestricted = FALSE, fFound = FALSE;
|
||||
@@ -663,9 +663,9 @@ INT16 RandomFriendWithin(SOLDIERTYPE *pSoldier)
|
||||
// should be close enough, try to find a legal ->sDestination within 1 tile
|
||||
|
||||
// clear dirChecked flag for all 8 directions
|
||||
for (usDirection = 0; usDirection < 8; usDirection++)
|
||||
for (ubDirection = 0; ubDirection < 8; ubDirection++)
|
||||
{
|
||||
fDirChecked[usDirection] = FALSE;
|
||||
fDirChecked[ubDirection] = FALSE;
|
||||
}
|
||||
|
||||
ubDirsLeft = 8;
|
||||
@@ -677,14 +677,14 @@ INT16 RandomFriendWithin(SOLDIERTYPE *pSoldier)
|
||||
// randomly select a direction which hasn't been 'checked' yet
|
||||
do
|
||||
{
|
||||
usDirection = (UINT16) Random(8);
|
||||
ubDirection = (UINT8) Random(8);
|
||||
}
|
||||
while (fDirChecked[usDirection]);
|
||||
while (fDirChecked[ubDirection]);
|
||||
|
||||
fDirChecked[usDirection] = TRUE;
|
||||
fDirChecked[ubDirection] = TRUE;
|
||||
|
||||
// determine the gridno 1 tile away from current friend in this direction
|
||||
usDest = NewGridNo(Menptr[ubFriendID].sGridNo,DirectionInc((INT16)(usDirection + 1)));
|
||||
usDest = NewGridNo(Menptr[ubFriendID].sGridNo,DirectionInc(ubDirection));
|
||||
|
||||
// if that's out of bounds, ignore it & check next direction
|
||||
if (usDest == Menptr[ubFriendID].sGridNo)
|
||||
@@ -2189,7 +2189,7 @@ INT32 CalcManThreatValue( SOLDIERTYPE *pEnemy, INT16 sMyGrid, UINT8 ubReduceForC
|
||||
else
|
||||
{
|
||||
// ADD 5% if man's already facing me
|
||||
if (pEnemy->bDirection == atan8(CenterX(pEnemy->sGridNo),CenterY(pEnemy->sGridNo),CenterX(sMyGrid),CenterY(sMyGrid)))
|
||||
if (pEnemy->ubDirection == atan8(CenterX(pEnemy->sGridNo),CenterY(pEnemy->sGridNo),CenterX(sMyGrid),CenterY(sMyGrid)))
|
||||
{
|
||||
iThreatValue += (iThreatValue / 20);
|
||||
}
|
||||
@@ -2441,13 +2441,13 @@ BOOLEAN ValidCreatureTurn( SOLDIERTYPE * pCreature, INT8 bNewDirection )
|
||||
INT8 bLoop;
|
||||
BOOLEAN fFound;
|
||||
|
||||
bDirChange = (INT8) QuickestDirection( pCreature->bDirection, bNewDirection );
|
||||
bDirChange = (INT8) QuickestDirection( pCreature->ubDirection, bNewDirection );
|
||||
|
||||
for( bLoop = 0; bLoop < 2; bLoop++ )
|
||||
{
|
||||
fFound = TRUE;
|
||||
|
||||
bTempDir = pCreature->bDirection;
|
||||
bTempDir = pCreature->ubDirection;
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
+17
-12
@@ -399,7 +399,7 @@ void CalcBestShot(SOLDIERTYPE *pSoldier, ATTACKTYPE *pBestShot, BOOLEAN shootUns
|
||||
BOOLEAN CloseEnoughForGrenadeToss( INT16 sGridNo, INT16 sGridNo2 )
|
||||
{
|
||||
INT16 sTempGridNo;
|
||||
INT8 bDirection;
|
||||
UINT8 ubDirection;
|
||||
INT16 sXPos, sYPos, sXPos2, sYPos2;
|
||||
UINT8 ubMovementCost;
|
||||
|
||||
@@ -407,10 +407,10 @@ BOOLEAN CloseEnoughForGrenadeToss( INT16 sGridNo, INT16 sGridNo2 )
|
||||
{
|
||||
// checking the same space; if there is a closed door next to location in ANY direction then forget it
|
||||
// (could be the player closed a door on us)
|
||||
for (bDirection = 0; bDirection < NUM_WORLD_DIRECTIONS; bDirection++)
|
||||
for (ubDirection = 0; ubDirection < NUM_WORLD_DIRECTIONS; ubDirection++)
|
||||
{
|
||||
sTempGridNo = NewGridNo( sGridNo, DirectionInc( bDirection ) );
|
||||
ubMovementCost = gubWorldMovementCosts[ sTempGridNo ][ bDirection ][ 0 ];
|
||||
sTempGridNo = NewGridNo( sGridNo, DirectionInc( ubDirection ) );
|
||||
ubMovementCost = gubWorldMovementCosts[ sTempGridNo ][ ubDirection ][ 0 ];
|
||||
if ( IS_TRAVELCOST_DOOR( ubMovementCost ) )
|
||||
{
|
||||
ubMovementCost = DoorTravelCost( NULL, sTempGridNo, ubMovementCost, FALSE, NULL );
|
||||
@@ -437,14 +437,14 @@ BOOLEAN CloseEnoughForGrenadeToss( INT16 sGridNo, INT16 sGridNo2 )
|
||||
sYPos = CenterY( sGridNo );
|
||||
sXPos2 = CenterX( sGridNo2 );
|
||||
sYPos2 = CenterY( sGridNo2 );
|
||||
bDirection = atan8( sXPos, sYPos, sXPos2, sYPos2 );
|
||||
ubDirection = atan8( sXPos, sYPos, sXPos2, sYPos2 );
|
||||
|
||||
// For each step of the loop, we are checking for door or obstacle movement costs. If we
|
||||
// find we're blocked, then this is no good for grenade tossing!
|
||||
do
|
||||
{
|
||||
sTempGridNo = NewGridNo( sTempGridNo, DirectionInc( bDirection ) );
|
||||
ubMovementCost = gubWorldMovementCosts[ sTempGridNo ][ bDirection ][ 0 ];
|
||||
sTempGridNo = NewGridNo( sTempGridNo, DirectionInc( ubDirection ) );
|
||||
ubMovementCost = gubWorldMovementCosts[ sTempGridNo ][ ubDirection ][ 0 ];
|
||||
if ( IS_TRAVELCOST_DOOR( ubMovementCost ) )
|
||||
{
|
||||
ubMovementCost = DoorTravelCost( NULL, sTempGridNo, ubMovementCost, FALSE, NULL );
|
||||
@@ -1575,6 +1575,8 @@ INT32 EstimateShotDamage(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ub
|
||||
INT32 iTotalProt;
|
||||
INT8 bPlatePos;
|
||||
UINT8 ubAmmoType;
|
||||
UINT16 usItem;
|
||||
OBJECTTYPE *pObj;
|
||||
|
||||
/*
|
||||
if ( pOpponent->uiStatusFlags & SOLDIER_VEHICLE )
|
||||
@@ -1584,19 +1586,22 @@ INT32 EstimateShotDamage(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ub
|
||||
}
|
||||
*/
|
||||
|
||||
if ( Item[ pSoldier->inv[pSoldier->ubAttackingHand].usItem ].usItemClass & IC_THROWING_KNIFE )
|
||||
pObj = &(pSoldier->inv[pSoldier->ubAttackingHand]);
|
||||
usItem = pObj->usItem;
|
||||
|
||||
if ( Item[ usItem ].usItemClass & IC_THROWING_KNIFE )
|
||||
{
|
||||
ubAmmoType = AMMO_KNIFE;
|
||||
}
|
||||
else
|
||||
{
|
||||
ubAmmoType = pSoldier->inv[pSoldier->ubAttackingHand].ItemData.Gun.ubGunAmmoType;
|
||||
ubAmmoType = pObj->ItemData.Gun.ubGunAmmoType;
|
||||
}
|
||||
|
||||
// calculate distance to target, obtain his gun's maximum range rating
|
||||
|
||||
iRange = GetRangeInCellCoordsFromGridNoDiff( pSoldier->sGridNo, pOpponent->sGridNo );
|
||||
iMaxRange = Weapon[pSoldier->inv[HANDPOS].usItem].usRange;
|
||||
iMaxRange = Weapon[usItem].usRange;
|
||||
|
||||
// bullet loses speed and penetrating power, 50% loss per maximum range
|
||||
iPowerLost = ((50 * iRange) / iMaxRange);
|
||||
@@ -1604,7 +1609,7 @@ INT32 EstimateShotDamage(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ub
|
||||
// up to 50% extra impact for making particularly accurate successful shots
|
||||
ubBonus = ubChanceToHit / 4; // /4 is really /2 and /2 again
|
||||
|
||||
iDamage = ((GetDamage(&pSoldier->inv[HANDPOS])) * (100 - iPowerLost + ubBonus) / 100) ;
|
||||
iDamage = ((GetDamage(pObj)) * (100 - iPowerLost + ubBonus) / 100) ;
|
||||
|
||||
//NumMessage("Pre-protection damage: ",damage);
|
||||
|
||||
@@ -1679,7 +1684,7 @@ INT32 EstimateShotDamage(SOLDIERTYPE *pSoldier, SOLDIERTYPE *pOpponent, UINT8 ub
|
||||
{
|
||||
// cheat and emphasize shots
|
||||
//iDamage = (iDamage * 15) / 10;
|
||||
switch( pSoldier->inv[pSoldier->ubAttackingHand].usItem )
|
||||
switch( usItem )
|
||||
{
|
||||
// explosive damage is 100-200% that of the rated, so multiply by 3/2s here
|
||||
case CREATURE_QUEEN_SPIT: //TODO: Madd - remove the hardcoding here
|
||||
|
||||
@@ -391,7 +391,7 @@ INT8 CreatureDecideActionGreen( SOLDIERTYPE * pSoldier )
|
||||
// if man has a LEGAL dominant facing, and isn't facing it, he will turn
|
||||
// back towards that facing 50% of the time here (normally just enemies)
|
||||
if ((pSoldier->bDominantDir >= 0) && (pSoldier->bDominantDir <= 8) &&
|
||||
(pSoldier->bDirection != pSoldier->bDominantDir) && PreRandom(2))
|
||||
(pSoldier->ubDirection != pSoldier->bDominantDir) && PreRandom(2))
|
||||
{
|
||||
pSoldier->usActionData = pSoldier->bDominantDir;
|
||||
}
|
||||
@@ -399,7 +399,7 @@ INT8 CreatureDecideActionGreen( SOLDIERTYPE * pSoldier )
|
||||
{
|
||||
pSoldier->usActionData = (UINT16)PreRandom(8);
|
||||
}
|
||||
} while (pSoldier->usActionData == pSoldier->bDirection);
|
||||
} while (pSoldier->usActionData == pSoldier->ubDirection);
|
||||
|
||||
#ifdef DEBUGDECISIONS
|
||||
STR16 tempstr;
|
||||
@@ -479,7 +479,7 @@ INT8 CreatureDecideActionYellow( SOLDIERTYPE * pSoldier )
|
||||
|
||||
// if soldier is not already facing in that direction,
|
||||
// and the noise source is close enough that it could possibly be seen
|
||||
if ((GetAPsToLook( pSoldier ) <= pSoldier->bActionPoints) && (pSoldier->bDirection != ubNoiseDir) && PythSpacesAway(pSoldier->sGridNo,sNoiseGridNo) <= STRAIGHT)
|
||||
if ((GetAPsToLook( pSoldier ) <= pSoldier->bActionPoints) && (pSoldier->ubDirection != ubNoiseDir) && PythSpacesAway(pSoldier->sGridNo,sNoiseGridNo) <= STRAIGHT)
|
||||
{
|
||||
// set base chance according to orders
|
||||
if ((pSoldier->bOrders == STATIONARY) || (pSoldier->bOrders == ONGUARD))
|
||||
@@ -850,7 +850,7 @@ INT8 CreatureDecideActionRed(SOLDIERTYPE *pSoldier, UINT8 ubUnconsciousOK)
|
||||
// note, have to change this to use the level returned from ClosestKnownOpponent
|
||||
sDistVisible = pSoldier->GetMaxDistanceVisible(sClosestOpponent, 0 );
|
||||
|
||||
if ((pSoldier->bDirection != ubOpponentDir) && (PythSpacesAway(pSoldier->sGridNo,sClosestOpponent) <= sDistVisible))
|
||||
if ((pSoldier->ubDirection != ubOpponentDir) && (PythSpacesAway(pSoldier->sGridNo,sClosestOpponent) <= sDistVisible))
|
||||
{
|
||||
// set base chance according to orders
|
||||
if ((pSoldier->bOrders == STATIONARY) || (pSoldier->bOrders == ONGUARD))
|
||||
@@ -1405,7 +1405,7 @@ INT8 CreatureDecideActionBlack( SOLDIERTYPE * pSoldier )
|
||||
bDirection = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sClosestOpponent),CenterY(sClosestOpponent));
|
||||
|
||||
// if we're not facing towards him
|
||||
if (pSoldier->bDirection != bDirection && ValidCreatureTurn( pSoldier, bDirection ) )
|
||||
if (pSoldier->ubDirection != bDirection && ValidCreatureTurn( pSoldier, bDirection ) )
|
||||
{
|
||||
pSoldier->usActionData = bDirection;
|
||||
|
||||
@@ -1699,7 +1699,7 @@ INT8 CrowDecideActionGreen( SOLDIERTYPE * pSoldier )
|
||||
// Change facing
|
||||
sFacingDir = GetDirectionFromGridNo( sCorpseGridNo, pSoldier );
|
||||
|
||||
if ( sFacingDir != pSoldier->bDirection )
|
||||
if ( sFacingDir != pSoldier->ubDirection )
|
||||
{
|
||||
pSoldier->usActionData = sFacingDir;
|
||||
return(AI_ACTION_CHANGE_FACING);
|
||||
|
||||
+21
-21
@@ -550,7 +550,7 @@ INT8 DecideActionBoxerEnteringRing(SOLDIERTYPE *pSoldier)
|
||||
ubDesiredMercDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sDesiredMercLoc),CenterY(sDesiredMercLoc));
|
||||
|
||||
// if not already facing in that direction,
|
||||
if ( pSoldier->bDirection != ubDesiredMercDir && InternalIsValidStance( pSoldier, ubDesiredMercDir, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) )
|
||||
if ( pSoldier->ubDirection != ubDesiredMercDir && InternalIsValidStance( pSoldier, ubDesiredMercDir, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) )
|
||||
{
|
||||
|
||||
pSoldier->usActionData = ubDesiredMercDir;
|
||||
@@ -610,7 +610,7 @@ INT8 DecideActionNamedNPC( SOLDIERTYPE * pSoldier )
|
||||
ubDesiredMercDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sDesiredMercLoc),CenterY(sDesiredMercLoc));
|
||||
|
||||
// if not already facing in that direction,
|
||||
if (pSoldier->bDirection != ubDesiredMercDir && InternalIsValidStance( pSoldier, ubDesiredMercDir, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) )
|
||||
if (pSoldier->ubDirection != ubDesiredMercDir && InternalIsValidStance( pSoldier, ubDesiredMercDir, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) )
|
||||
{
|
||||
|
||||
pSoldier->usActionData = ubDesiredMercDir;
|
||||
@@ -754,7 +754,7 @@ INT8 DecideActionGreen(SOLDIERTYPE *pSoldier)
|
||||
ubRingDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(CENTER_OF_RING),CenterY(CENTER_OF_RING));
|
||||
if ( gfTurnBasedAI || GetAPsToLook( pSoldier ) <= pSoldier->bActionPoints )
|
||||
{
|
||||
if ( pSoldier->bDirection != ubRingDir )
|
||||
if ( pSoldier->ubDirection != ubRingDir )
|
||||
{
|
||||
pSoldier->usActionData = ubRingDir;
|
||||
return( AI_ACTION_CHANGE_FACING );
|
||||
@@ -1220,7 +1220,7 @@ INT8 DecideActionGreen(SOLDIERTYPE *pSoldier)
|
||||
// if man has a LEGAL dominant facing, and isn't facing it, he will turn
|
||||
// back towards that facing 50% of the time here (normally just enemies)
|
||||
if ((pSoldier->bDominantDir >= 0) && (pSoldier->bDominantDir <= 8) &&
|
||||
(pSoldier->bDirection != pSoldier->bDominantDir) && PreRandom(2) && pSoldier->bOrders != SNIPER )
|
||||
(pSoldier->ubDirection != pSoldier->bDominantDir) && PreRandom(2) && pSoldier->bOrders != SNIPER )
|
||||
{
|
||||
pSoldier->usActionData = pSoldier->bDominantDir;
|
||||
}
|
||||
@@ -1234,7 +1234,7 @@ INT8 DecideActionGreen(SOLDIERTYPE *pSoldier)
|
||||
|
||||
if (sNoiseGridNo == NOWHERE ||
|
||||
(ubNoiseDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sNoiseGridNo),CenterY(sNoiseGridNo))
|
||||
) == pSoldier->bDirection )
|
||||
) == pSoldier->ubDirection )
|
||||
|
||||
{
|
||||
pSoldier->usActionData = (UINT16)PreRandom(8);
|
||||
@@ -1244,7 +1244,7 @@ INT8 DecideActionGreen(SOLDIERTYPE *pSoldier)
|
||||
pSoldier->usActionData = ubNoiseDir;
|
||||
}
|
||||
}
|
||||
} while (pSoldier->usActionData == pSoldier->bDirection);
|
||||
} while (pSoldier->usActionData == pSoldier->ubDirection);
|
||||
|
||||
|
||||
#ifdef DEBUGDECISIONS
|
||||
@@ -1355,7 +1355,7 @@ INT8 DecideActionYellow(SOLDIERTYPE *pSoldier)
|
||||
// and the noise source is close enough that it could possibly be seen
|
||||
if ( !gfTurnBasedAI || GetAPsToLook( pSoldier ) <= pSoldier->bActionPoints )
|
||||
{
|
||||
if ((pSoldier->bDirection != ubNoiseDir) && PythSpacesAway(pSoldier->sGridNo,sNoiseGridNo) <= pSoldier->GetMaxDistanceVisible(sNoiseGridNo) )
|
||||
if ((pSoldier->ubDirection != ubNoiseDir) && PythSpacesAway(pSoldier->sGridNo,sNoiseGridNo) <= pSoldier->GetMaxDistanceVisible(sNoiseGridNo) )
|
||||
{
|
||||
// set base chance according to orders
|
||||
if ((pSoldier->bOrders == STATIONARY) || (pSoldier->bOrders == ONGUARD) )
|
||||
@@ -2154,10 +2154,10 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier, UINT8 ubUnconsciousOK)
|
||||
// if firing mortar make sure we have room
|
||||
if ( Item[pSoldier->inv[ BestThrow.bWeaponIn ].usItem].mortar )
|
||||
{
|
||||
ubOpponentDir = (UINT8)GetDirectionFromGridNo( BestThrow.sTarget, pSoldier );
|
||||
ubOpponentDir = GetDirectionFromGridNo( BestThrow.sTarget, pSoldier );
|
||||
|
||||
// Get new gridno!
|
||||
sCheckGridNo = NewGridNo( (UINT16)pSoldier->sGridNo, (UINT16)DirectionInc( ubOpponentDir ) );
|
||||
sCheckGridNo = NewGridNo( pSoldier->sGridNo, DirectionInc( ubOpponentDir ) );
|
||||
|
||||
if ( OKFallDirection( pSoldier, sCheckGridNo, pSoldier->bLevel, ubOpponentDir, pSoldier->usAnimState ) )
|
||||
{
|
||||
@@ -2181,10 +2181,10 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier, UINT8 ubUnconsciousOK)
|
||||
BestThrow.ubPossible = FALSE;
|
||||
|
||||
// try behind us, see if there's room to move back
|
||||
sCheckGridNo = NewGridNo( (UINT16)pSoldier->sGridNo, (UINT16)DirectionInc( gOppositeDirection[ ubOpponentDir ] ) );
|
||||
sCheckGridNo = NewGridNo( pSoldier->sGridNo, DirectionInc( gOppositeDirection[ ubOpponentDir ] ) );
|
||||
if ( OKFallDirection( pSoldier, sCheckGridNo, pSoldier->bLevel, gOppositeDirection[ ubOpponentDir ], pSoldier->usAnimState ) )
|
||||
{
|
||||
pSoldier->usActionData = sCheckGridNo;
|
||||
pSoldier->usActionData = (UINT16) sCheckGridNo;
|
||||
|
||||
return( AI_ACTION_GET_CLOSER );
|
||||
}
|
||||
@@ -2909,7 +2909,7 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier, UINT8 ubUnconsciousOK)
|
||||
|
||||
// if soldier is not already facing in that direction,
|
||||
// and the opponent is close enough that he could possibly be seen
|
||||
if ( pSoldier->bDirection != ubOpponentDir && InternalIsValidStance( pSoldier, ubOpponentDir, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) )
|
||||
if ( pSoldier->ubDirection != ubOpponentDir && InternalIsValidStance( pSoldier, ubOpponentDir, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) )
|
||||
{
|
||||
// turn
|
||||
pSoldier->usActionData = ubOpponentDir;
|
||||
@@ -3162,7 +3162,7 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier, UINT8 ubUnconsciousOK)
|
||||
// note, have to change this to use the level returned from ClosestKnownOpponent
|
||||
sDistVisible = pSoldier->GetMaxDistanceVisible(sClosestOpponent, 0, CALC_FROM_ALL_DIRS );
|
||||
|
||||
if ((pSoldier->bDirection != ubOpponentDir) && (PythSpacesAway(pSoldier->sGridNo,sClosestOpponent) <= sDistVisible))
|
||||
if ((pSoldier->ubDirection != ubOpponentDir) && (PythSpacesAway(pSoldier->sGridNo,sClosestOpponent) <= sDistVisible))
|
||||
{
|
||||
// set base chance according to orders
|
||||
if ((pSoldier->bOrders == STATIONARY) || (pSoldier->bOrders == ONGUARD))
|
||||
@@ -3197,7 +3197,7 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier, UINT8 ubUnconsciousOK)
|
||||
return(AI_ACTION_CHANGE_FACING);
|
||||
}
|
||||
}
|
||||
else if ( pSoldier->bDirection == ubOpponentDir && pSoldier->bOrders == SNIPER )
|
||||
else if ( pSoldier->ubDirection == ubOpponentDir && pSoldier->bOrders == SNIPER )
|
||||
{
|
||||
if (!gfTurnBasedAI || GetAPsToReadyWeapon( pSoldier, READY_RIFLE_CROUCH ) <= pSoldier->bActionPoints)
|
||||
{
|
||||
@@ -3216,7 +3216,7 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier, UINT8 ubUnconsciousOK)
|
||||
if ( sClosestDisturbance != NOWHERE )
|
||||
{
|
||||
ubOpponentDir = atan8( CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), CenterX( sClosestDisturbance ), CenterY( sClosestDisturbance ) );
|
||||
if ( pSoldier->bDirection == ubOpponentDir )
|
||||
if ( pSoldier->ubDirection == ubOpponentDir )
|
||||
{
|
||||
ubOpponentDir = (UINT8) PreRandom( NUM_WORLD_DIRECTIONS );
|
||||
}
|
||||
@@ -3226,7 +3226,7 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier, UINT8 ubUnconsciousOK)
|
||||
ubOpponentDir = (UINT8) PreRandom( NUM_WORLD_DIRECTIONS );
|
||||
}
|
||||
|
||||
if ( (pSoldier->bDirection != ubOpponentDir) )
|
||||
if ( (pSoldier->ubDirection != ubOpponentDir) )
|
||||
{
|
||||
if ( (pSoldier->bActionPoints == pSoldier->bInitialActionPoints || (INT16)PreRandom(100) < 60) && InternalIsValidStance( pSoldier, ubOpponentDir, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) )
|
||||
{
|
||||
@@ -3365,7 +3365,7 @@ INT8 DecideActionRed(SOLDIERTYPE *pSoldier, UINT8 ubUnconsciousOK)
|
||||
if ( sClosestDisturbance != NOWHERE )
|
||||
{
|
||||
ubOpponentDir = atan8( CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), CenterX( sClosestDisturbance ), CenterY( sClosestDisturbance ) );
|
||||
if ( pSoldier->bDirection != ubOpponentDir )
|
||||
if ( pSoldier->ubDirection != ubOpponentDir )
|
||||
{
|
||||
if ( !gfTurnBasedAI || GetAPsToLook( pSoldier ) <= pSoldier->bActionPoints )
|
||||
{
|
||||
@@ -4277,7 +4277,7 @@ INT8 DecideActionBlack(SOLDIERTYPE *pSoldier)
|
||||
if (ubBestStance != 0)
|
||||
{
|
||||
// change stance first!
|
||||
if ( pSoldier->bDirection != bDirection && InternalIsValidStance( pSoldier, bDirection, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) )
|
||||
if ( pSoldier->ubDirection != bDirection && InternalIsValidStance( pSoldier, bDirection, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) )
|
||||
{
|
||||
// we're not facing towards him, so turn first!
|
||||
pSoldier->usActionData = bDirection;
|
||||
@@ -4632,7 +4632,7 @@ INT8 DecideActionBlack(SOLDIERTYPE *pSoldier)
|
||||
if ( pSoldier->usActionData != NOWHERE )
|
||||
{
|
||||
// truncate path to 1 step
|
||||
pSoldier->usActionData = pSoldier->sGridNo + DirectionInc( pSoldier->usPathingData[0] );
|
||||
pSoldier->usActionData = pSoldier->sGridNo + DirectionInc( (UINT8) pSoldier->usPathingData[0] );
|
||||
pSoldier->sFinalDestination = pSoldier->usActionData;
|
||||
pSoldier->bNextAction = AI_ACTION_END_TURN;
|
||||
return( AI_ACTION_GET_CLOSER );
|
||||
@@ -4749,7 +4749,7 @@ INT8 DecideActionBlack(SOLDIERTYPE *pSoldier)
|
||||
bDirection = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sClosestOpponent),CenterY(sClosestOpponent));
|
||||
|
||||
// if we're not facing towards him
|
||||
if (pSoldier->bDirection != bDirection)
|
||||
if (pSoldier->ubDirection != bDirection)
|
||||
{
|
||||
if ( InternalIsValidStance( pSoldier, bDirection, (INT8) pSoldier->usActionData) )
|
||||
{
|
||||
@@ -4807,7 +4807,7 @@ INT8 DecideActionBlack(SOLDIERTYPE *pSoldier)
|
||||
bDirection = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sClosestOpponent),CenterY(sClosestOpponent));
|
||||
|
||||
// if we're not facing towards him
|
||||
if ( pSoldier->bDirection != bDirection && InternalIsValidStance( pSoldier, bDirection, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) )
|
||||
if ( pSoldier->ubDirection != bDirection && InternalIsValidStance( pSoldier, bDirection, gAnimControl[ pSoldier->usAnimState ].ubEndHeight ) )
|
||||
{
|
||||
pSoldier->usActionData = bDirection;
|
||||
|
||||
|
||||
@@ -998,7 +998,7 @@ INT16 TrackScent( SOLDIERTYPE * pSoldier )
|
||||
ubBestStrength = ubStrength;
|
||||
bDir = atan8( (INT16) iXStart, (INT16) iYStart, (INT16) (iXStart + iXDiff), (INT16) (iYStart + iYDiff) );
|
||||
// now convert it into a difference in degree between it and our current dir
|
||||
ubBestDirDiff = abs( pSoldier->bDirection - bDir );
|
||||
ubBestDirDiff = abs( pSoldier->ubDirection - bDir );
|
||||
if (ubBestDirDiff > 4 ) // dir 0 compared with dir 6, for instance
|
||||
{
|
||||
ubBestDirDiff = 8 - ubBestDirDiff;
|
||||
@@ -1018,7 +1018,7 @@ INT16 TrackScent( SOLDIERTYPE * pSoldier )
|
||||
// start by calculating direction to the new gridno
|
||||
bDir = atan8( (INT16) iXStart, (INT16) iYStart, (INT16) (iXStart + iXDiff), (INT16) (iYStart + iYDiff) );
|
||||
// now convert it into a difference in degree between it and our current dir
|
||||
ubDirDiff = abs( pSoldier->bDirection - bDir );
|
||||
ubDirDiff = abs( pSoldier->ubDirection - bDir );
|
||||
if (ubDirDiff > 4 ) // dir 0 compared with dir 6, for instance
|
||||
{
|
||||
ubDirDiff = 8 - ubDirDiff;
|
||||
|
||||
Reference in New Issue
Block a user