- Added INI Setting and ability to manually train mobile militia at a cost

- Added INI setting and ability to train veteran militia

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@586 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
AcyForsythe
2006-10-01 06:52:06 +00:00
parent e88e16c038
commit 11b2e75e32
10 changed files with 477 additions and 191 deletions
+233 -97
View File
@@ -24,6 +24,7 @@
#include "GameSettings.h"
#endif
#include "MilitiaSquads.h"
#define SIZE_OF_MILITIA_COMPLETED_TRAINING_LIST 50
// temporary local global variables
@@ -33,6 +34,7 @@ INT16 gsTownSectorServerSkipY = -1;
UINT8 gubTownSectorServerIndex = 0;
BOOLEAN gfYesNoPromptIsForContinue = FALSE; // this flag remembers whether we're starting new training, or continuing
INT32 giTotalCostOfTraining = 0;
BOOLEAN gfAreWeTrainingMobile = FALSE;
//the completed list of sector soldiers for training militia
@@ -81,7 +83,7 @@ void TownMilitiaTrainingCompleted( SOLDIERTYPE *pTrainer, INT16 sMapX, INT16 sMa
INT32 iMaxMilitiaPerSector = gGameExternalOptions.iMaxMilitiaPerSector;
INT32 iTrainingSquadSize = gGameExternalOptions.iTrainingSquadSize;
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Militia1");
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Militia1");
// get town index
ubTownId = StrategicMap[ sMapX + sMapY * MAP_WORLD_X ].bNameId;
@@ -101,101 +103,149 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Militia1");
// 4) If not enough GREENS there to promote, promote GREENs in other sectors.
// 5) If all friendly sectors of this town are completely filled with REGULAR militia, then training effect is wasted
while (ubMilitiaTrained < iTrainingSquadSize)
// Kaiden: Roaming Militia Training:
// If we're not training roaming militia,
// then we will handle everything as normal.
if( (IsMilitiaTrainableFromSoldiersSectorMaxed( pTrainer )) && (gGameExternalOptions.gfmusttrainroaming))
{
// is there room for another militia in the training sector itself?
if (CountAllMilitiaInSector(sMapX, sMapY) < iMaxMilitiaPerSector)
CreateMilitiaSquads(sMapX, sMapY );
}
else
{
while (ubMilitiaTrained < iTrainingSquadSize)
{
// great! Create a new GREEN militia guy in the training sector
StrategicAddMilitiaToSector(sMapX, sMapY, GREEN_MILITIA, 1);
// is there room for another militia in the training sector itself?
if (CountAllMilitiaInSector(sMapX, sMapY) < iMaxMilitiaPerSector)
{
// great! Create a new GREEN militia guy in the training sector
StrategicAddMilitiaToSector(sMapX, sMapY, GREEN_MILITIA, 1);
}
else
{
fFoundOne = FALSE;
if( ubTownId != BLANK_SECTOR )
{
InitFriendlyTownSectorServer(ubTownId, sMapX, sMapY);
// check other eligible sectors in this town for room for another militia
while( ServeNextFriendlySectorInTown( &sNeighbourX, &sNeighbourY ) )
{
// is there room for another militia in this neighbouring sector ?
if (CountAllMilitiaInSector(sNeighbourX, sNeighbourY) < iMaxMilitiaPerSector)
{
// great! Create a new GREEN militia guy in the neighbouring sector
StrategicAddMilitiaToSector(sNeighbourX, sNeighbourY, GREEN_MILITIA, 1);
fFoundOne = TRUE;
break;
}
}
}
// if we still haven't been able to train anyone
if (!fFoundOne)
{
// alrighty, then. We'll have to *promote* guys instead.
// are there any GREEN militia men in the training sector itself?
if (MilitiaInSectorOfRank(sMapX, sMapY, GREEN_MILITIA) > 0)
{
// great! Promote a GREEN militia guy in the training sector to a REGULAR
StrategicPromoteMilitiaInSector(sMapX, sMapY, GREEN_MILITIA, 1);
fFoundOne = TRUE;
}
else
{
if( ubTownId != BLANK_SECTOR )
{
// dammit! Last chance - try to find other eligible sectors in the same town with a Green guy to be promoted
InitFriendlyTownSectorServer(ubTownId, sMapX, sMapY);
// check other eligible sectors in this town for room for another militia
while( ServeNextFriendlySectorInTown( &sNeighbourX, &sNeighbourY ) )
{
// are there any GREEN militia men in the neighbouring sector ?
if (MilitiaInSectorOfRank(sNeighbourX, sNeighbourY, GREEN_MILITIA) > 0)
{
// great! Promote a GREEN militia guy in the neighbouring sector to a REGULAR
StrategicPromoteMilitiaInSector(sNeighbourX, sNeighbourY, GREEN_MILITIA, 1);
fFoundOne = TRUE;
break;
}
}
}
// Kaiden: Veteran militia training
// This is essentially copy/pasted from above
// But the names have been changed to protect the innocent
if ((!fFoundOne) && (gGameExternalOptions.gfTrainVeteranMilitia))
{
// are there any REGULAR militia men in the training sector itself?
if (MilitiaInSectorOfRank(sMapX, sMapY, REGULAR_MILITIA) > 0)
{
// great! Promote a REGULAR militia guy in the training sector to a REGULAR
StrategicPromoteMilitiaInSector(sMapX, sMapY, REGULAR_MILITIA, 1);
fFoundOne = TRUE;
}
else
{
if( ubTownId != BLANK_SECTOR )
{
// dammit! Last chance - try to find other eligible sectors in the same town with a Green guy to be promoted
InitFriendlyTownSectorServer(ubTownId, sMapX, sMapY);
// check other eligible sectors in this town for room for another militia
while( ServeNextFriendlySectorInTown( &sNeighbourX, &sNeighbourY ) )
{
// are there any REGULAR militia men in the neighbouring sector ?
if (MilitiaInSectorOfRank(sNeighbourX, sNeighbourY, REGULAR_MILITIA) > 0)
{
// great! Promote a GREEN militia guy in the neighbouring sector to a REGULAR
StrategicPromoteMilitiaInSector(sNeighbourX, sNeighbourY, REGULAR_MILITIA, 1);
fFoundOne = TRUE;
break;
}
}
}
}
}
// if we still haven't been able to train anyone
if (!fFoundOne)
{
// Well, that's it. All eligible sectors of this town are full of REGULARs or ELITEs.
// The training goes to waste in this situation.
break; // the main while loop
}
}
}
}
// next, please!
ubMilitiaTrained++;
}
else
// if anyone actually got trained
if (ubMilitiaTrained > 0)
{
fFoundOne = FALSE;
// update the screen display
fMapPanelDirty = TRUE;
if( ubTownId != BLANK_SECTOR )
{
InitFriendlyTownSectorServer(ubTownId, sMapX, sMapY);
// check other eligible sectors in this town for room for another militia
while( ServeNextFriendlySectorInTown( &sNeighbourX, &sNeighbourY ) )
{
// is there room for another militia in this neighbouring sector ?
if (CountAllMilitiaInSector(sNeighbourX, sNeighbourY) < iMaxMilitiaPerSector)
{
// great! Create a new GREEN militia guy in the neighbouring sector
StrategicAddMilitiaToSector(sNeighbourX, sNeighbourY, GREEN_MILITIA, 1);
fFoundOne = TRUE;
break;
}
}
// loyalty in this town increases a bit because we obviously care about them...
IncrementTownLoyalty( ubTownId, LOYALTY_BONUS_FOR_TOWN_TRAINING );
}
// if we still haven't been able to train anyone
if (!fFoundOne)
{
// alrighty, then. We'll have to *promote* guys instead.
// are there any GREEN militia men in the training sector itself?
if (MilitiaInSectorOfRank(sMapX, sMapY, GREEN_MILITIA) > 0)
{
// great! Promote a GREEN militia guy in the training sector to a REGULAR
StrategicPromoteMilitiaInSector(sMapX, sMapY, GREEN_MILITIA, 1);
}
else
{
if( ubTownId != BLANK_SECTOR )
{
// dammit! Last chance - try to find other eligible sectors in the same town with a Green guy to be promoted
InitFriendlyTownSectorServer(ubTownId, sMapX, sMapY);
// check other eligible sectors in this town for room for another militia
while( ServeNextFriendlySectorInTown( &sNeighbourX, &sNeighbourY ) )
{
// are there any GREEN militia men in the neighbouring sector ?
if (MilitiaInSectorOfRank(sNeighbourX, sNeighbourY, GREEN_MILITIA) > 0)
{
// great! Promote a GREEN militia guy in the neighbouring sector to a REGULAR
StrategicPromoteMilitiaInSector(sNeighbourX, sNeighbourY, GREEN_MILITIA, 1);
fFoundOne = TRUE;
break;
}
}
}
// if we still haven't been able to train anyone
if (!fFoundOne)
{
// Well, that's it. All eligible sectors of this town are full of REGULARs or ELITEs.
// The training goes to waste in this situation.
break; // the main while loop
}
}
}
}
// next, please!
ubMilitiaTrained++;
}
// if anyone actually got trained
if (ubMilitiaTrained > 0)
{
// update the screen display
fMapPanelDirty = TRUE;
if( ubTownId != BLANK_SECTOR )
{
// loyalty in this town increases a bit because we obviously care about them...
IncrementTownLoyalty( ubTownId, LOYALTY_BONUS_FOR_TOWN_TRAINING );
}
}
// the trainer announces to player that he's finished his assignment. Make his sector flash!
AssignmentDone( pTrainer, TRUE, FALSE );
@@ -519,9 +569,21 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Militia2");
iNumberOfSectors = GetNumberOfUnpaidTrainableSectors( );
Assert( iNumberOfSectors > 0 );
// Kaiden: Roaming Militia Training:
// We want to charge more for Roaming
// get total cost
giTotalCostOfTraining = iMilitiaTrainingCost * iNumberOfSectors;
Assert( giTotalCostOfTraining > 0 );
if( IsMilitiaTrainableFromSoldiersSectorMaxed( pSoldier ) && (gGameExternalOptions.gfmusttrainroaming))
{
giTotalCostOfTraining = (iMilitiaTrainingCost*gGameExternalOptions.iMilitiaCostModifier) * iNumberOfSectors;
Assert( giTotalCostOfTraining > 0 );
gfAreWeTrainingMobile = TRUE;
}
else
{
giTotalCostOfTraining = iMilitiaTrainingCost * iNumberOfSectors;
Assert( giTotalCostOfTraining > 0 );
}
gfYesNoPromptIsForContinue = FALSE;
@@ -579,6 +641,7 @@ void HandleInterfaceMessageForContinuingTrainingMilitia( SOLDIERTYPE *pSoldier )
INT32 iMinLoyaltyToTrain = gGameExternalOptions.iMinLoyaltyToTrain;
INT32 iMilitiaTrainingCost = gGameExternalOptions.iMilitiaTrainingCost;
DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Militia3");
sSectorX = pSoldier->sSectorX;
@@ -599,7 +662,12 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Militia3");
return;
}
if ( IsMilitiaTrainableFromSoldiersSectorMaxed( pSoldier ) )
// Kaiden: Roaming Militia Training:
// Changed the if condition from
// if ( IsMilitiaTrainableFromSoldiersSectorMaxed( pSoldier ) )
// And we're not training mobile militia from a SAM Site
if (( IsMilitiaTrainableFromSoldiersSectorMaxed( pSoldier )) && (IsThisSectorASAMSector(sSectorX,sSectorY,0 )))
{
// we're full!!! go home!
bTownId = GetTownIdForSector( sSectorX, sSectorY );
@@ -618,10 +686,47 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Militia3");
DoContinueMilitiaTrainingMessageBox( sSectorX, sSectorY, sString, MSG_BOX_FLAG_OK, CantTrainMilitiaOkBoxCallback );
return;
}
else
{
if (( IsMilitiaTrainableFromSoldiersSectorMaxed( pSoldier )) && (!gGameExternalOptions.gfmusttrainroaming))
{
// we're full!!! go home!
bTownId = GetTownIdForSector( sSectorX, sSectorY );
if ( bTownId == BLANK_SECTOR )
{
// wilderness SAM site
GetSectorIDString( sSectorX, sSectorY, 0, sStringB, TRUE );
void (*tempFptr)(INT16 , INT16 , INT8 , CHAR16 *, BOOLEAN) = GetSectorIDString;
swprintf( (wchar_t *)sString, (wchar_t *)pMilitiaConfirmStrings[ 10 ], sStringB, tempFptr, iMinLoyaltyToTrain );
}
else
{
// town
swprintf( (wchar_t *)sString, (wchar_t *)pMilitiaConfirmStrings[ 10 ], pTownNames[ bTownId ], iMinLoyaltyToTrain );
}
DoContinueMilitiaTrainingMessageBox( sSectorX, sSectorY, sString, MSG_BOX_FLAG_OK, CantTrainMilitiaOkBoxCallback );
return;
}
}
// continue training always handles just one sector at a time
giTotalCostOfTraining = iMilitiaTrainingCost;
// Kaiden: Roaming Militia Training:
// Charging more to train Roaming Militia
if ( IsMilitiaTrainableFromSoldiersSectorMaxed( pSoldier ) && (gGameExternalOptions.gfmusttrainroaming))
{
giTotalCostOfTraining = (iMilitiaTrainingCost*gGameExternalOptions.iMilitiaCostModifier);
gfAreWeTrainingMobile = TRUE;
}
else
{
// continue training always handles just one sector at a time
giTotalCostOfTraining = iMilitiaTrainingCost;
}
// can player afford to continue training?
if( LaptopSaveInfo.iCurrentBalance < giTotalCostOfTraining )
{
@@ -804,9 +909,19 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Militia4");
if( SectorOursAndPeaceful( sSectorX, sSectorY, 0 ) )
{
// don't count GREEN militia, they can be trained into regulars first
iNumberOfMilitia += MilitiaInSectorOfRank( sSectorX, sSectorY, REGULAR_MILITIA );
iNumberOfMilitia += MilitiaInSectorOfRank( sSectorX, sSectorY, ELITE_MILITIA );
iMaxNumber += iMaxMilitiaPerSector;
// Kaiden: Veteran Militia Training:
// And we don't count regulars either if we're training veterans
if (gGameExternalOptions.gfTrainVeteranMilitia)
{
iNumberOfMilitia += MilitiaInSectorOfRank( sSectorX, sSectorY, ELITE_MILITIA );
iMaxNumber += iMaxMilitiaPerSector;
}
else
{
iNumberOfMilitia += MilitiaInSectorOfRank( sSectorX, sSectorY, REGULAR_MILITIA );
iNumberOfMilitia += MilitiaInSectorOfRank( sSectorX, sSectorY, ELITE_MILITIA );
iMaxNumber += iMaxMilitiaPerSector;
}
}
}
@@ -840,11 +955,23 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Militia5");
if( SectorOursAndPeaceful( sSectorX, sSectorY, 0 ) )
{
// don't count GREEN militia, they can be trained into regulars first
iNumberOfMilitia += MilitiaInSectorOfRank( sSectorX, sSectorY, REGULAR_MILITIA );
iNumberOfMilitia += MilitiaInSectorOfRank( sSectorX, sSectorY, ELITE_MILITIA );
iMaxNumber += iMaxMilitiaPerSector;
// Kaiden: Veteran Militia Training:
// And we don't count regulars either if we're training veterans
if (gGameExternalOptions.gfTrainVeteranMilitia)
{
iNumberOfMilitia += MilitiaInSectorOfRank( sSectorX, sSectorY, ELITE_MILITIA );
iMaxNumber += iMaxMilitiaPerSector;
}
else
{
iNumberOfMilitia += MilitiaInSectorOfRank( sSectorX, sSectorY, REGULAR_MILITIA );
iNumberOfMilitia += MilitiaInSectorOfRank( sSectorX, sSectorY, ELITE_MILITIA );
iMaxNumber += iMaxMilitiaPerSector;
}
}
// now check the number of militia
if ( iMaxNumber > iNumberOfMilitia )
{
@@ -1123,8 +1250,17 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Militia6");
Assert( SectorInfo[ ubSector ].fMilitiaTrainingPaid == FALSE );
// spend the money
AddTransactionToPlayersBook( TRAIN_TOWN_MILITIA, ubSector, GetWorldTotalMin(), -( iMilitiaTrainingCost ) );
// Kaiden: Roaming Militia Training:
// Charging more to train Roaming Militia
if ( gfAreWeTrainingMobile)
{
AddTransactionToPlayersBook( TRAIN_TOWN_MILITIA, ubSector, GetWorldTotalMin(), -( iMilitiaTrainingCost*gGameExternalOptions.iMilitiaCostModifier ) );
gfAreWeTrainingMobile = FALSE;
}
else
{
AddTransactionToPlayersBook( TRAIN_TOWN_MILITIA, ubSector, GetWorldTotalMin(), -( iMilitiaTrainingCost ) );
}
// mark this sector sectors as being paid up
SectorInfo[ ubSector ].fMilitiaTrainingPaid = TRUE;