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:
Overhaul
2007-08-13 03:39:54 +00:00
parent ca8cb7b89a
commit 6ec2c5da7d
79 changed files with 2621 additions and 2584 deletions
+1 -1
View File
@@ -455,7 +455,7 @@ void RenderStationaryGroups()
INT32 x, y, xp, yp;
CHAR16 str[20];
INT32 iSector = 0;
UINT8 ubIconColor;
UINT8 ubIconColor = 0;
UINT8 ubGroupSize = 0;
+2 -2
View File
@@ -3950,7 +3950,7 @@ INT16 GetSoldierStudentPts( SOLDIERTYPE *pSoldier, INT8 bTrainStat, BOOLEAN fAtG
INT8 bSkill = 0;
INT16 sBestTrainingPts, sTrainingPtsDueToInstructor;
UINT16 usMaxTrainerPts, usBestMaxTrainerPts;
UINT16 usMaxTrainerPts, usBestMaxTrainerPts = 0;
UINT32 uiCnt;
SOLDIERTYPE * pTrainer;
@@ -8106,7 +8106,7 @@ void HandleShadingOfLinesForSquadMenu( void )
UINT32 uiCounter;
SOLDIERTYPE *pSoldier = NULL;
UINT32 uiMaxSquad;
INT8 bResult;
INT8 bResult = 0;
if ( ( fShowSquadMenu == FALSE ) || ( ghSquadBox == -1 ) )
+1 -1
View File
@@ -622,7 +622,7 @@ void AddCreaturesToBattle( UINT8 ubNumYoungMales, UINT8 ubNumYoungFemales, UINT8
{
INT32 iRandom;
SOLDIERTYPE *pSoldier;
MAPEDGEPOINTINFO MapEdgepointInfo;
MAPEDGEPOINTINFO MapEdgepointInfo = { };
UINT8 bDesiredDirection=0;
UINT8 ubCurrSlot = 0;
+1 -1
View File
@@ -180,7 +180,7 @@ UINT16 LarryItems[ NUM_LARRY_ITEMS ][ 3 ] =
void HourlyLarryUpdate( void )
{
SOLDIERTYPE * pSoldier;
INT8 bSlot, bBoozeSlot;
INT8 bSlot = NO_SLOT, bBoozeSlot;
INT8 bLarryItemLoop;
UINT16 usTemptation = 0;
UINT16 usCashAmount;
File diff suppressed because it is too large Load Diff
+3
View File
@@ -6387,6 +6387,9 @@ void HandleLowerLevelMapBlit( void )
case( 3 ):
GetVideoObject( &hHandle, guiSubLevel3 );
break;
default:
AssertMsg( 0, "Invalid underground sector level");
return;
}
// handle the blt of the sublevel
+1
View File
@@ -761,6 +761,7 @@ void ProcessImplicationsOfMeanwhile( void )
else
{
Assert( 0 );
return;
}
gMercProfiles[ MADLAB ].sSectorX = sSectorX;
gMercProfiles[ MADLAB ].sSectorY = sSectorY;
+1 -1
View File
@@ -1745,7 +1745,7 @@ void PutNonSquadMercsInPlayerGroupOnSquads( GROUP *pGroup, BOOLEAN fExitVehicles
PLAYERGROUP *pPlayer, *pNextPlayer;
SOLDIERTYPE *pSoldier;
INT8 bUniqueVehicleSquad = -1;
BOOLEAN fSuccess;
BOOLEAN fSuccess = FALSE;
if ( pGroup->fVehicle )
+6
View File
@@ -1341,7 +1341,9 @@ void AddPossiblePendingEnemiesToBattle()
else if( pGroup->ubSectorY > pGroup->ubPrevY )
ubInsertionCode = INSERTION_CODE_NORTH;
else
{
Assert(0);
}
}
else if( pGroup->ubNextX && pGroup->ubNextY )
{
@@ -1354,11 +1356,15 @@ void AddPossiblePendingEnemiesToBattle()
else if( pGroup->ubSectorY > pGroup->ubNextY )
ubInsertionCode = INSERTION_CODE_NORTH;
else
{
Assert(0);
}
}
else
{
// The group has no movement orders. Where did it come from?
Assert(0);
}
if( pGroup->pEnemyGroup->ubElitesInBattle < pGroup->pEnemyGroup->ubNumElites )
{ //Add an elite troop
+92 -137
View File
@@ -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 )
+3
View File
@@ -78,6 +78,9 @@ void HandleStrategicTurn( )
}
else
{
// If none of these conditions are true, then don't do an end of turn
uiCheckTime = 0xffffffff;
if ( giTimeCompressMode == TIME_COMPRESS_X1 || giTimeCompressMode == 0 )
{
uiCheckTime = NUM_REAL_SEC_PER_TACTICAL_TURN;
+2 -1
View File
@@ -46,8 +46,9 @@
RuntimeLibrary="1"
RuntimeTypeInfo="false"
UsePrecompiledHeader="0"
WarningLevel="3"
WarningLevel="4"
DebugInformationFormat="4"
DisableSpecificWarnings="4100"
/>
<Tool
Name="VCManagedResourceCompilerTool"
+1 -1
View File
@@ -3075,7 +3075,7 @@ void JumpIntoAdjacentSector( UINT8 ubTacticalDirection, UINT8 ubJumpCode, INT16
SOLDIERTYPE *pValidSoldier = NULL;
GROUP *pGroup;
UINT32 uiTraverseTime=0;
UINT8 ubDirection;
UINT8 ubDirection = 0xff;
EXITGRID ExitGrid;
INT8 bPrevAssignment;
UINT8 ubPrevGroupID;