mirror of
https://github.com/1dot13/source.git
synced 2026-07-29 13:52:17 +02:00
Initialized many variables
Fix for enemy invasions and reinforcements git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1192 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
+92
-137
@@ -1,28 +1,29 @@
|
||||
#ifdef PRECOMPILEDHEADERS
|
||||
#include "Strategic All.h"
|
||||
#include "Strategic All.h"
|
||||
#else
|
||||
#include "Town Militia.h"
|
||||
#include "Militia Control.h"
|
||||
#include "Campaign Types.h"
|
||||
#include "strategic.h"
|
||||
#include "strategicmap.h"
|
||||
#include "Overhead.h"
|
||||
#include "Strategic Town Loyalty.h"
|
||||
#include "Utilities.h"
|
||||
#include "random.h"
|
||||
#include "text.h"
|
||||
#include "Map Screen Interface.h"
|
||||
#include "Interface.h"
|
||||
#include "Laptopsave.h"
|
||||
#include "finances.h"
|
||||
#include "Game Clock.h"
|
||||
#include "Assignments.h"
|
||||
#include "squads.h"
|
||||
#include "Soldier Create.h"
|
||||
#include "Dialogue Control.h"
|
||||
#include "Queen Command.h"
|
||||
#include "GameSettings.h"
|
||||
#include "Soldier Init List.h"
|
||||
#include "Town Militia.h"
|
||||
#include "Militia Control.h"
|
||||
#include "Campaign Types.h"
|
||||
#include "strategic.h"
|
||||
#include "strategicmap.h"
|
||||
#include "Overhead.h"
|
||||
#include "Strategic Town Loyalty.h"
|
||||
#include "Utilities.h"
|
||||
#include "random.h"
|
||||
#include "text.h"
|
||||
#include "Map Screen Interface.h"
|
||||
#include "Interface.h"
|
||||
#include "Laptopsave.h"
|
||||
#include "finances.h"
|
||||
#include "Game Clock.h"
|
||||
#include "Assignments.h"
|
||||
#include "squads.h"
|
||||
#include "Soldier Create.h"
|
||||
#include "Dialogue Control.h"
|
||||
#include "Queen Command.h"
|
||||
#include "GameSettings.h"
|
||||
#include "Soldier Init List.h"
|
||||
#include "Inventory Choosing.h"
|
||||
#endif
|
||||
|
||||
#include "Reinforcement.h"
|
||||
@@ -35,7 +36,7 @@ void GetNumberOfEnemiesInFiveSectors( INT16 sSectorX, INT16 sSectorY, UINT8 *pub
|
||||
UINT8 ubNumAdmins, ubNumTroops, ubNumElites;
|
||||
UINT16 pusMoveDir[4][3];
|
||||
UINT8 ubDirNumber, ubIndex;
|
||||
|
||||
|
||||
GetNumberOfStationaryEnemiesInSector( sSectorX, sSectorY, pubNumAdmins, pubNumTroops, pubNumElites );
|
||||
|
||||
GetNumberOfMobileEnemiesInSectorWithoutRoadBlock( sSectorX, sSectorY, &ubNumAdmins, &ubNumTroops, &ubNumElites );
|
||||
@@ -73,7 +74,7 @@ void GetNumberOfEnemiesInFiveSectors( INT16 sSectorX, INT16 sSectorY, UINT8 *pub
|
||||
ubNumAdmins--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
GetNumberOfMobileEnemiesInSectorWithoutRoadBlock( SECTORX( pusMoveDir[ ubIndex ][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ), &ubNumAdmins, &ubNumTroops, &ubNumElites );
|
||||
|
||||
@@ -88,7 +89,7 @@ UINT8 NumEnemiesInFiveSectors( INT16 sMapX, INT16 sMapY )
|
||||
UINT8 ubNumAdmins, ubNumTroops, ubNumElites;
|
||||
|
||||
GetNumberOfEnemiesInFiveSectors( sMapX, sMapY, &ubNumAdmins, &ubNumTroops, &ubNumElites );
|
||||
|
||||
|
||||
return ubNumAdmins + ubNumTroops + ubNumElites;
|
||||
}
|
||||
|
||||
@@ -133,7 +134,7 @@ UINT8 CountAllMilitiaInFiveSectors(INT16 sMapX, INT16 sMapY)
|
||||
UINT8 ubResult = 0;
|
||||
UINT16 pusMoveDir[4][3];
|
||||
UINT8 ubDirNumber, ubIndex;
|
||||
|
||||
|
||||
ubResult = CountAllMilitiaInSector( sMapX, sMapY );
|
||||
|
||||
if( !gGameExternalOptions.gfAllowReinforcements )
|
||||
@@ -154,7 +155,7 @@ UINT8 MilitiaInFiveSectorsOfRank( INT16 sMapX, INT16 sMapY, UINT8 ubRank )
|
||||
UINT8 ubResult = 0;
|
||||
UINT16 pusMoveDir[4][3];
|
||||
UINT8 ubDirNumber, ubIndex;
|
||||
|
||||
|
||||
ubResult = MilitiaInSectorOfRank( sMapX, sMapY, ubRank );
|
||||
|
||||
if( !gGameExternalOptions.gfAllowReinforcements )
|
||||
@@ -166,7 +167,7 @@ UINT8 MilitiaInFiveSectorsOfRank( INT16 sMapX, INT16 sMapY, UINT8 ubRank )
|
||||
for( ubIndex = 0; ubIndex < ubDirNumber; ubIndex++ )
|
||||
ubResult += MilitiaInSectorOfRank( SECTORX( pusMoveDir[ ubIndex ][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ), ubRank );
|
||||
|
||||
|
||||
|
||||
return ubResult;
|
||||
}
|
||||
|
||||
@@ -176,13 +177,13 @@ BOOLEAN ARMoveBestMilitiaManFromAdjacentSector(INT16 sMapX, INT16 sMapY)
|
||||
UINT16 pusMoveDir[4][3];
|
||||
UINT8 ubDirNumber;
|
||||
UINT8 ubRandom;
|
||||
|
||||
|
||||
if( !gGameExternalOptions.gfAllowReinforcements )
|
||||
return FALSE;
|
||||
|
||||
if( CountAllMilitiaInSector( sMapX, sMapY ) >= gGameExternalOptions.guiMaxMilitiaSquadSize ||
|
||||
CountAllMilitiaInFiveSectors( sMapX, sMapY ) - CountAllMilitiaInSector( sMapX, sMapY ) == 0 )
|
||||
return FALSE;
|
||||
return FALSE;
|
||||
|
||||
GenerateDirectionInfos( sMapX, sMapY, &ubDirNumber, pusMoveDir,
|
||||
( GetTownIdForSector( sMapX, sMapY ) != BLANK_SECTOR ? TRUE : FALSE ), TRUE, IS_ONLY_IN_CITIES );
|
||||
@@ -191,7 +192,7 @@ BOOLEAN ARMoveBestMilitiaManFromAdjacentSector(INT16 sMapX, INT16 sMapY)
|
||||
|
||||
while( !MoveOneBestMilitiaMan( SECTORX( pusMoveDir[ ubRandom ][ 0 ] ), SECTORY( pusMoveDir[ ubRandom ][ 0 ] ), sMapX, sMapY ) )
|
||||
ubRandom = Random( ubDirNumber );
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -199,7 +200,7 @@ BOOLEAN ARRemoveMilitiaMan( INT16 sMapX, INT16 sMapY, UINT8 ubRank )
|
||||
{
|
||||
UINT16 pusMoveDir[4][3];
|
||||
UINT8 ubDirNumber, ubRandom;
|
||||
|
||||
|
||||
if( MilitiaInSectorOfRank( sMapX, sMapY, ubRank ) )
|
||||
{
|
||||
StrategicRemoveMilitiaFromSector( sMapX, sMapY, ubRank, 1 );
|
||||
@@ -260,78 +261,24 @@ UINT8 DoReinforcementAsPendingEnemy( INT16 sMapX, INT16 sMapY )
|
||||
GenerateDirectionInfos( sMapX, sMapY, &ubDirNumber, pusMoveDir,
|
||||
( GetTownIdForSector( sMapX, sMapY ) != BLANK_SECTOR ? TRUE : FALSE ), TRUE, IS_ONLY_IN_CITIES );
|
||||
|
||||
|
||||
#if 0
|
||||
// Combine this with the next part so that reinforcements from enemy groups can also come in from random sides
|
||||
for( ubIndex = 0; ubIndex < ubDirNumber; ubIndex++ )
|
||||
if( NumMobileEnemiesInSector( SECTORX( pusMoveDir[ ubIndex ][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ) ) && GetEnemyGroupInSector( SECTORX( pusMoveDir[ ubIndex][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ) ) )
|
||||
{
|
||||
while ((pGroup = GetEnemyGroupInSector( SECTORX( pusMoveDir[ ubIndex][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ) ) ) != NULL)
|
||||
{
|
||||
pGroup = GetEnemyGroupInSector( SECTORX( pusMoveDir[ ubIndex][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ) );
|
||||
|
||||
pGroup->ubPrevX = pGroup->ubSectorX;
|
||||
pGroup->ubPrevY = pGroup->ubSectorY;
|
||||
|
||||
pGroup->ubSectorX = pGroup->ubNextX = (UINT8)sMapX;
|
||||
pGroup->ubSectorY = pGroup->ubNextY = (UINT8)sMapY;
|
||||
|
||||
return (UINT8)pusMoveDir[ ubIndex ][ 2 ];
|
||||
gfPendingEnemies = TRUE;
|
||||
ResetMortarsOnTeamCount();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if( NumEnemiesInFiveSectors( sMapX, sMapY ) - NumEnemiesInSector( sMapX, sMapY ) == 0 )
|
||||
{
|
||||
return 255;
|
||||
}else
|
||||
for(;;)
|
||||
while( ubDirNumber > 0)
|
||||
{
|
||||
ubIndex = Random(ubDirNumber);
|
||||
#if 0
|
||||
// This should be handled in AddPossiblePendingEnemiesToBattle
|
||||
if( NumMobileEnemiesInSector( SECTORX( pusMoveDir[ ubIndex ][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ) ) && GetEnemyGroupInSector( SECTORX( pusMoveDir[ ubIndex][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ) ) )
|
||||
{
|
||||
UINT8 numElite;
|
||||
UINT8 numTroop;
|
||||
UINT8 numAdmin;
|
||||
|
||||
pGroup = GetEnemyGroupInSector( SECTORX( pusMoveDir[ ubIndex][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ) );
|
||||
pEnemyGroup = pGroup->pEnemyGroup;
|
||||
numElite = pEnemyGroup->ubNumElites - pEnemyGroup->ubElitesInBattle;
|
||||
numTroop = pEnemyGroup->ubNumTroops - pEnemyGroup->ubTroopsInBattle;
|
||||
numAdmin = pEnemyGroup->ubNumAdmins - pEnemyGroup->ubAdminsInBattle;
|
||||
|
||||
if (numElite + numTroop + numAdmin <= 1)
|
||||
{
|
||||
// The entire group has finally moved into the sector.
|
||||
pGroup->ubPrevX = pGroup->ubSectorX;
|
||||
pGroup->ubPrevY = pGroup->ubSectorY;
|
||||
|
||||
pGroup->ubSectorX = pGroup->ubNextX = (UINT8)sMapX;
|
||||
pGroup->ubSectorY = pGroup->ubNextY = (UINT8)sMapY;
|
||||
|
||||
return (UINT8)pusMoveDir[ ubIndex ][ 2 ];
|
||||
}
|
||||
|
||||
if (numAdmin + numTroop + numElite)
|
||||
{
|
||||
// Otherwise we move a soldier into the sector from the group
|
||||
if( numElite )
|
||||
{
|
||||
(pThisSector->ubNumElites)++;
|
||||
(pEnemyGroup->ubElitesInBattle)++;
|
||||
}else if( numTroop )
|
||||
{
|
||||
(pThisSector->ubNumTroops)++;
|
||||
(pEnemyGroup->ubTroopsInBattle)++;
|
||||
}else if( numAdmin )
|
||||
{
|
||||
(pThisSector->ubNumAdmins)++;
|
||||
(pEnemyGroup->ubAdminsInBattle)++;
|
||||
}
|
||||
|
||||
return (UINT8)pusMoveDir[ ubIndex ][ 2 ];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if( NumEnemiesInSector( SECTORX( pusMoveDir[ ubIndex ][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ) ) > gubReinforcementMinEnemyStaticGroupSize )
|
||||
{
|
||||
@@ -363,7 +310,15 @@ UINT8 DoReinforcementAsPendingEnemy( INT16 sMapX, INT16 sMapY )
|
||||
|
||||
return (UINT8)pusMoveDir[ ubIndex ][ 2 ];
|
||||
}
|
||||
else
|
||||
{
|
||||
// If there are no reinforcements from this direction, remove this as a direction
|
||||
memcpy( &(pusMoveDir[ubIndex][0]), &(pusMoveDir[ --ubDirNumber][0]), sizeof(pusMoveDir[0]));
|
||||
}
|
||||
}
|
||||
|
||||
// No reinforcements from other sectors are available
|
||||
return 255;
|
||||
}
|
||||
|
||||
|
||||
@@ -391,7 +346,7 @@ UINT8 DoReinforcementAsPendingMilitia( INT16 sMapX, INT16 sMapY, UINT8 *pubRank
|
||||
if( !gGameExternalOptions.gfAllowReinforcements )
|
||||
return 255;
|
||||
|
||||
// pThisSector = &SectorInfo[ SECTOR( sMapX, sMapY ) ];
|
||||
// pThisSector = &SectorInfo[ SECTOR( sMapX, sMapY ) ];
|
||||
|
||||
GenerateDirectionInfos( sMapX, sMapY, &ubDirNumber, pusMoveDir,
|
||||
( GetTownIdForSector( sMapX, sMapY ) != BLANK_SECTOR ? TRUE : FALSE ), TRUE, IS_ONLY_IN_CITIES );
|
||||
@@ -402,33 +357,33 @@ UINT8 DoReinforcementAsPendingMilitia( INT16 sMapX, INT16 sMapY, UINT8 *pubRank
|
||||
return 255;
|
||||
}else
|
||||
for(;;)
|
||||
{
|
||||
ubIndex = Random(ubDirNumber);
|
||||
if( CountAllMilitiaInSector( SECTORX( pusMoveDir[ ubIndex ][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ) ) )
|
||||
{
|
||||
pSector = &SectorInfo[ pusMoveDir[ ubIndex ][ 0 ] ];
|
||||
ubIndex = Random(ubDirNumber);
|
||||
if( CountAllMilitiaInSector( SECTORX( pusMoveDir[ ubIndex ][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ) ) )
|
||||
{
|
||||
pSector = &SectorInfo[ pusMoveDir[ ubIndex ][ 0 ] ];
|
||||
|
||||
if( pSector->ubNumberOfCivsAtLevel[ ELITE_MILITIA ] )
|
||||
{
|
||||
StrategicAddMilitiaToSector( sMapX, sMapY,ELITE_MILITIA, 1 );
|
||||
StrategicRemoveMilitiaFromSector( SECTORX( pusMoveDir[ ubIndex ][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ),ELITE_MILITIA, 1 );
|
||||
*pubRank = ELITE_MILITIA;
|
||||
}else if( pSector->ubNumberOfCivsAtLevel[ REGULAR_MILITIA ] )
|
||||
{
|
||||
StrategicAddMilitiaToSector( sMapX, sMapY,REGULAR_MILITIA, 1 );
|
||||
StrategicRemoveMilitiaFromSector( SECTORX( pusMoveDir[ ubIndex ][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ),REGULAR_MILITIA, 1 );
|
||||
*pubRank = REGULAR_MILITIA;
|
||||
}else if( pSector->ubNumberOfCivsAtLevel[ GREEN_MILITIA ] )
|
||||
{
|
||||
StrategicAddMilitiaToSector( sMapX, sMapY,GREEN_MILITIA, 1 );
|
||||
StrategicRemoveMilitiaFromSector( SECTORX( pusMoveDir[ ubIndex ][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ),GREEN_MILITIA, 1 );
|
||||
*pubRank = GREEN_MILITIA;
|
||||
if( pSector->ubNumberOfCivsAtLevel[ ELITE_MILITIA ] )
|
||||
{
|
||||
StrategicAddMilitiaToSector( sMapX, sMapY,ELITE_MILITIA, 1 );
|
||||
StrategicRemoveMilitiaFromSector( SECTORX( pusMoveDir[ ubIndex ][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ),ELITE_MILITIA, 1 );
|
||||
*pubRank = ELITE_MILITIA;
|
||||
}else if( pSector->ubNumberOfCivsAtLevel[ REGULAR_MILITIA ] )
|
||||
{
|
||||
StrategicAddMilitiaToSector( sMapX, sMapY,REGULAR_MILITIA, 1 );
|
||||
StrategicRemoveMilitiaFromSector( SECTORX( pusMoveDir[ ubIndex ][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ),REGULAR_MILITIA, 1 );
|
||||
*pubRank = REGULAR_MILITIA;
|
||||
}else if( pSector->ubNumberOfCivsAtLevel[ GREEN_MILITIA ] )
|
||||
{
|
||||
StrategicAddMilitiaToSector( sMapX, sMapY,GREEN_MILITIA, 1 );
|
||||
StrategicRemoveMilitiaFromSector( SECTORX( pusMoveDir[ ubIndex ][ 0 ] ), SECTORY( pusMoveDir[ ubIndex ][ 0 ] ),GREEN_MILITIA, 1 );
|
||||
*pubRank = GREEN_MILITIA;
|
||||
}
|
||||
|
||||
return (UINT8)pusMoveDir[ ubIndex ][ 2 ];
|
||||
}
|
||||
|
||||
return (UINT8)pusMoveDir[ ubIndex ][ 2 ];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -441,42 +396,42 @@ void AddPossiblePendingMilitiaToBattle()
|
||||
static UINT8 ubPredefinedInsertionCode = 255;
|
||||
static UINT8 ubPredefinedRank = 255;
|
||||
|
||||
// if( !PlayerMercsInSector( (UINT8)gWorldSectorX, (UINT8)gWorldSectorY, 0 ) || !CountAllMilitiaInSector( gWorldSectorX, gWorldSectorY )
|
||||
// || !NumEnemiesInSector( gWorldSectorX, gWorldSectorY ) ) return;
|
||||
// if( !PlayerMercsInSector( (UINT8)gWorldSectorX, (UINT8)gWorldSectorY, 0 ) || !CountAllMilitiaInSector( gWorldSectorX, gWorldSectorY )
|
||||
// || !NumEnemiesInSector( gWorldSectorX, gWorldSectorY ) ) return;
|
||||
if( !PlayerMercsInSector( (UINT8)gWorldSectorX, (UINT8)gWorldSectorY, 0 )
|
||||
|| !(gTacticalStatus.uiFlags & WANT_MILITIA_REINFORCEMENTS)
|
||||
|| !NumEnemiesInSector( gWorldSectorX, gWorldSectorY )
|
||||
)
|
||||
return;
|
||||
//gGameExternalOptions.guiMaxMilitiaSquadSize - CountAllMilitiaInSector( gWorldSectorX, gWorldSectorY );
|
||||
//gGameExternalOptions.guiMaxMilitiaSquadSize - CountAllMilitiaInSector( gWorldSectorX, gWorldSectorY );
|
||||
ubSlots = NumFreeMilitiaSlots();
|
||||
if( !ubSlots )
|
||||
{ //no available slots to add militia to. Try again later...
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if( ubPredefinedInsertionCode != 255 && ubPredefinedRank != 255 &&
|
||||
CountAllMilitiaInSector( gWorldSectorX, gWorldSectorY ) )
|
||||
{
|
||||
ubNumElites = ubNumRegulars = ubNumGreens = 0;
|
||||
|
||||
// while( ubSlots )
|
||||
// while( ubSlots )
|
||||
switch( ubPredefinedRank )
|
||||
{
|
||||
case ELITE_MILITIA:
|
||||
ubSlots--;
|
||||
ubNumElites++;
|
||||
break;
|
||||
case REGULAR_MILITIA:
|
||||
ubSlots--;
|
||||
ubNumRegulars++;
|
||||
break;
|
||||
case GREEN_MILITIA:
|
||||
ubSlots--;
|
||||
ubNumGreens++;
|
||||
break;
|
||||
default:
|
||||
ubSlots--;
|
||||
case ELITE_MILITIA:
|
||||
ubSlots--;
|
||||
ubNumElites++;
|
||||
break;
|
||||
case REGULAR_MILITIA:
|
||||
ubSlots--;
|
||||
ubNumRegulars++;
|
||||
break;
|
||||
case GREEN_MILITIA:
|
||||
ubSlots--;
|
||||
ubNumGreens++;
|
||||
break;
|
||||
default:
|
||||
ubSlots--;
|
||||
}
|
||||
|
||||
if( ubNumGreens || ubNumRegulars || ubNumElites )
|
||||
@@ -488,7 +443,7 @@ void AddPossiblePendingMilitiaToBattle()
|
||||
|
||||
if( ubSlots )
|
||||
{ //After going through the process, we have finished with some free slots and no more enemies to add.
|
||||
//So, we can turn off the flag, as this check is no longer needed.
|
||||
//So, we can turn off the flag, as this check is no longer needed.
|
||||
ubPredefinedInsertionCode = DoReinforcementAsPendingMilitia( gWorldSectorX, gWorldSectorY, &ubPredefinedRank );
|
||||
|
||||
if( ubPredefinedInsertionCode != 255 )
|
||||
|
||||
Reference in New Issue
Block a user