HandlePrison:

- more precise calculation of prisoner to guard ratio
- improved calculation of random number of prisoners escaping (allow single prisoner/max prisoners to escape when not guarded)
- check that someone actually escaped before showing riot message
- limit ubNumTroops to 255 (like in other places) as 512 makes no sense for UINT8 value

git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9390 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Sevenfm
2022-07-31 15:30:22 +00:00
parent 612cc2a405
commit 058a2cd40f
+19 -12
View File
@@ -8746,24 +8746,31 @@ void HandlePrison( INT16 sMapX, INT16 sMapY, INT8 bZ )
{
FLOAT prisonertoguardratio = 1.0f;
if ( prisonguardvalue )
prisonertoguardratio = (FLOAT)(prisonerriotvalue / prisonguardvalue);
prisonertoguardratio = (FLOAT)prisonerriotvalue / (FLOAT)prisonguardvalue;
// in a riot, prisoners escape and are added to the sector as enemies. Not all might escape - the worse the prisoner/guard ratio, the more escape
INT16 escapedprisoners[PRISONER_MAX] = {0};
for (int i = PRISONER_ADMIN; i < PRISONER_MAX; ++i )
escapedprisoners[i] = min( Random( aPrisoners[i] * prisonertoguardratio ), aPrisoners[i] );
INT16 sTotalEscapedPrisoners = 0;
for (int i = PRISONER_ADMIN; i < PRISONER_MAX; ++i)
{
escapedprisoners[i] = min(Random(1 + aPrisoners[i] * prisonertoguardratio), aPrisoners[i]);
sTotalEscapedPrisoners += escapedprisoners[i];
}
// add enemies (PRISONER_CIVILIAN just flee)
pSectorInfo->ubNumTroops = min( 512, pSectorInfo->ubNumTroops + escapedprisoners[PRISONER_REGULAR] );
pSectorInfo->ubNumElites = min( 512, pSectorInfo->ubNumElites + escapedprisoners[PRISONER_ELITE] + escapedprisoners[PRISONER_OFFICER] + escapedprisoners[PRISONER_GENERAL] );
pSectorInfo->ubNumAdmins = min( 512, pSectorInfo->ubNumAdmins + escapedprisoners[PRISONER_ADMIN] );
if (sTotalEscapedPrisoners > 0)
{
// add enemies (PRISONER_CIVILIAN just flee)
pSectorInfo->ubNumTroops = min(255, pSectorInfo->ubNumTroops + escapedprisoners[PRISONER_REGULAR]);
pSectorInfo->ubNumElites = min(255, pSectorInfo->ubNumElites + escapedprisoners[PRISONER_ELITE] + escapedprisoners[PRISONER_OFFICER] + escapedprisoners[PRISONER_GENERAL]);
pSectorInfo->ubNumAdmins = min(255, pSectorInfo->ubNumAdmins + escapedprisoners[PRISONER_ADMIN]);
// reduce prisoner count!
// we have to change the sign
for ( int i = PRISONER_ADMIN; i < PRISONER_MAX; ++i )
escapedprisoners[i] = -escapedprisoners[i];
// reduce prisoner count!
// we have to change the sign
for (int i = PRISONER_ADMIN; i < PRISONER_MAX; ++i)
escapedprisoners[i] = -escapedprisoners[i];
ChangeNumberOfPrisoners( pSectorInfo, escapedprisoners );
ChangeNumberOfPrisoners(pSectorInfo, escapedprisoners);
}
ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, szPrisonerTextStr[STR_PRISONER_RIOT], wSectorName );
}