Home » PLAYER'S HQ 1.13 » JA2 Complete Mods & Sequels » Stracciatella Project (Platform Independent JA2) » Bug: looking for enemies in adjacent sectors
Bug: looking for enemies in adjacent sectors[message #250880]
|
Sun, 02 May 2010 20:10
|
|
mgl |
|
Messages:255
Registered:December 2007 Location: France |
|
|
My game triggered an assertion failure on the sector's coordinates when I arrived in sector (16, . After investigation, it was because it looked in the non-existing sector to the right to see if there were enemies there able to notice my mercs.
The function to scan the adjacent sectors when one of your teams arrive somewhere is in 'Build/Strategic/Strategic_AI.cc'. A comment says that the function will look for patrols and garrisons able to notice you in the four directions.
The problem is with the x coordinates:
The code to scan the sector to the right does nothing if you are on the right edge. Otherwise it looks for a patrol to the right, and if no patrol is found, it looks for a garrison to the left. It triggers an assertion failure when you are on the left edge.
The code to scan the sector on the left mimics this behaviour by looking for a garrison to the right and triggers an assertion failure when you are on the right edge. It's the bug I had.
The code for the sectors above and below is correct.
This is the patch:
Index: Build/Strategic/Strategic_AI.cc
===================================================================
--- Build/Strategic/Strategic_AI.cc (revision 7059)
+++ Build/Strategic/Strategic_AI.cc (working copy)
@@ -1962,6 +1973,7 @@
return FALSE;
if( pPlayerGroup->ubSectorY > 1 )
{
+ /* Adjacent sector to look: above */
GROUP* const pEnemyGroup = FindEnemyMovementGroupInSector(pPlayerGroup->ubSectorX, pPlayerGroup->ubSectorY - 1);
if( pEnemyGroup && AttemptToNoticeAdjacentGroupSucceeds() )
{
@@ -1978,22 +1990,26 @@
}
if( pPlayerGroup->ubSectorX < 16 )
{
- GROUP* const pEnemyGroup = FindEnemyMovementGroupInSector(pPlayerGroup->ubSectorX + 1, pPlayerGroup->ubSectorY);
+ /* Adjacent sector where to look: right */
+ UINT8 const ubAdjX = pPlayerGroup->ubSectorX + 1;
+
+ GROUP* const pEnemyGroup = FindEnemyMovementGroupInSector(ubAdjX, pPlayerGroup->ubSectorY);
if( pEnemyGroup && AttemptToNoticeAdjacentGroupSucceeds() )
{
HandlePlayerGroupNoticedByPatrolGroup( pPlayerGroup, pEnemyGroup );
return FALSE;
}
- pSector = &SectorInfo[ SECTOR( pPlayerGroup->ubSectorX-1, pPlayerGroup->ubSectorY ) ];
+ pSector = &SectorInfo[SECTOR(ubAdjX, pPlayerGroup->ubSectorY)];
ubNumEnemies = pSector->ubNumAdmins + pSector->ubNumTroops + pSector->ubNumElites;
if( ubNumEnemies && pSector->ubGarrisonID != NO_GARRISON && AttemptToNoticeAdjacentGroupSucceeds() )
{
- HandlePlayerGroupNoticedByGarrison( pPlayerGroup, (UINT8)SECTOR( pPlayerGroup->ubSectorX-1, pPlayerGroup->ubSectorY ) );
+ HandlePlayerGroupNoticedByGarrison(pPlayerGroup, (UINT8)SECTOR(ubAdjX, pPlayerGroup->ubSectorY));
return FALSE;
}
}
if( pPlayerGroup->ubSectorY < 16 )
{
+ /* Adjacent sector to look: below */
GROUP* const pEnemyGroup = FindEnemyMovementGroupInSector(pPlayerGroup->ubSectorX, pPlayerGroup->ubSectorY + 1);
if( pEnemyGroup && AttemptToNoticeAdjacentGroupSucceeds() )
{
@@ -2010,17 +2026,20 @@
}
if( pPlayerGroup->ubSectorX > 1 )
{
- GROUP* const pEnemyGroup = FindEnemyMovementGroupInSector(pPlayerGroup->ubSectorX - 1, pPlayerGroup->ubSectorY);
+ /* Adjacent sector where to look: left */
+ UINT8 ubAdjX = pPlayerGroup->ubSectorX - 1;
+
+ GROUP* const pEnemyGroup = FindEnemyMovementGroupInSector(ubAdjX, pPlayerGroup->ubSectorY);
if( pEnemyGroup && AttemptToNoticeAdjacentGroupSucceeds() )
{
HandlePlayerGroupNoticedByPatrolGroup( pPlayerGroup, pEnemyGroup );
return FALSE;
}
- pSector = &SectorInfo[ SECTOR( pPlayerGroup->ubSectorX+1, pPlayerGroup->ubSectorY ) ];
+ pSector = &SectorInfo[SECTOR(ubAdjX, pPlayerGroup->ubSectorY)];
ubNumEnemies = pSector->ubNumAdmins + pSector->ubNumTroops + pSector->ubNumElites;
if( ubNumEnemies && pSector->ubGarrisonID != NO_GARRISON && AttemptToNoticeAdjacentGroupSucceeds() )
{
- HandlePlayerGroupNoticedByGarrison( pPlayerGroup, (UINT8)SECTOR( pPlayerGroup->ubSectorX+1, pPlayerGroup->ubSectorY ) );
+ HandlePlayerGroupNoticedByGarrison(pPlayerGroup, (UINT8)SECTOR(ubAdjX, pPlayerGroup->ubSectorY));
return FALSE;
}
}
I have fixed a number of "pPlayerGroup->ubSectorX +/- 1".
Although the "y" are correct, I think I will do the same to them.
Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Wed Jan 22 14:53:41 GMT+2 2025
Total time taken to generate the page: 0.01138 seconds
|