fix possible division by zero when rounding
This commit is contained in:
parent
3fbf4e9c20
commit
0de9c0088c
@ -35,8 +35,8 @@ struct S_SpawnEntry
|
|||||||
var float RelativeStart;
|
var float RelativeStart;
|
||||||
var int DelayDefault;
|
var int DelayDefault;
|
||||||
var int Delay;
|
var int Delay;
|
||||||
var int SpawnsLeft;
|
var int PawnsLeft;
|
||||||
var int SpawnsTotal;
|
var int PawnsTotal;
|
||||||
var bool SpawnAtPlayerStart;
|
var bool SpawnAtPlayerStart;
|
||||||
var bool ForceSpawn;
|
var bool ForceSpawn;
|
||||||
var String ZedNameFiller;
|
var String ZedNameFiller;
|
||||||
@ -287,7 +287,7 @@ private function SpawnTimer()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SE.SpawnsLeft > 0)
|
if (SE.PawnsLeft > 0)
|
||||||
{
|
{
|
||||||
SpawnEntry(SpawnListCurrent, Index);
|
SpawnEntry(SpawnListCurrent, Index);
|
||||||
}
|
}
|
||||||
@ -403,8 +403,9 @@ private function AdjustSpawnList(out Array<S_SpawnEntry> List)
|
|||||||
local S_SpawnEntry SE;
|
local S_SpawnEntry SE;
|
||||||
local int Index;
|
local int Index;
|
||||||
local float Cycle, Players;
|
local float Cycle, Players;
|
||||||
local float MSB, MSC, MSP;
|
local float B, TM, TCM, TPM;
|
||||||
local float MLB, MLC, MLP;
|
local float L, LM, LCM, LPM;
|
||||||
|
local float PawnTotalF, PawnLimitF;
|
||||||
local int ZedNameMaxLength;
|
local int ZedNameMaxLength;
|
||||||
|
|
||||||
`ZS_Trace(`Location);
|
`ZS_Trace(`Location);
|
||||||
@ -412,13 +413,16 @@ private function AdjustSpawnList(out Array<S_SpawnEntry> List)
|
|||||||
Cycle = float(CurrentCycle);
|
Cycle = float(CurrentCycle);
|
||||||
Players = float(PlayerCount());
|
Players = float(PlayerCount());
|
||||||
|
|
||||||
MSB = CfgSpawn.default.ZedTotalMultiplier;
|
B = float(SE.SpawnCountBase);
|
||||||
MSC = CfgSpawn.default.SpawnTotalCycleMultiplier;
|
L = float(SE.SingleSpawnLimitDefault);
|
||||||
MSP = CfgSpawn.default.SpawnTotalPlayerMultiplier;
|
|
||||||
|
|
||||||
MLB = CfgSpawn.default.SingleSpawnLimitMultiplier;
|
TM = CfgSpawn.default.ZedTotalMultiplier;
|
||||||
MLC = CfgSpawn.default.SingleSpawnLimitCycleMultiplier;
|
TCM = CfgSpawn.default.SpawnTotalCycleMultiplier;
|
||||||
MLP = CfgSpawn.default.SingleSpawnLimitPlayerMultiplier;
|
TPM = CfgSpawn.default.SpawnTotalPlayerMultiplier;
|
||||||
|
|
||||||
|
LM = CfgSpawn.default.SingleSpawnLimitMultiplier;
|
||||||
|
LCM = CfgSpawn.default.SingleSpawnLimitCycleMultiplier;
|
||||||
|
LPM = CfgSpawn.default.SingleSpawnLimitPlayerMultiplier;
|
||||||
|
|
||||||
ZedNameMaxLength = 0;
|
ZedNameMaxLength = 0;
|
||||||
foreach List(SE, Index)
|
foreach List(SE, Index)
|
||||||
@ -438,10 +442,13 @@ private function AdjustSpawnList(out Array<S_SpawnEntry> List)
|
|||||||
List[Index].Delay = 0;
|
List[Index].Delay = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PawnTotalF = B * (TM + TCM * (Cycle - 1.0f) + TPM * (Players - 1.0f));
|
||||||
|
PawnLimitF = L * (LM + LCM * (Cycle - 1.0f) + LPM * (Players - 1.0f));
|
||||||
|
|
||||||
List[Index].ForceSpawn = false;
|
List[Index].ForceSpawn = false;
|
||||||
List[Index].SpawnsTotal = Round(SE.SpawnCountBase * (MSB + MSC * (Cycle - 1.0f) + MSP * (Players - 1.0f)));
|
List[Index].PawnsTotal = Max(Round(PawnTotalF), 1);
|
||||||
List[Index].SingleSpawnLimit = Round(SE.SingleSpawnLimitDefault * (MLB + MLC * (Cycle - 1.0f) + MLP * (Players - 1.0f)));
|
List[Index].SingleSpawnLimit = Max(Round(PawnLimitF), 1);
|
||||||
List[Index].SpawnsLeft = List[Index].SpawnsTotal;
|
List[Index].PawnsLeft = List[Index].PawnsTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach List(SE, Index)
|
foreach List(SE, Index)
|
||||||
@ -476,7 +483,7 @@ private function SpawnTimerLogger(bool Stop, optional String Comment)
|
|||||||
private function SpawnEntry(out Array<S_SpawnEntry> SpawnList, int Index)
|
private function SpawnEntry(out Array<S_SpawnEntry> SpawnList, int Index)
|
||||||
{
|
{
|
||||||
local S_SpawnEntry SE;
|
local S_SpawnEntry SE;
|
||||||
local int FreeSpawnSlots, SpawnCount, Spawned;
|
local int FreeSpawnSlots, PawnCount, Spawned;
|
||||||
local String Action, Comment, NextSpawn;
|
local String Action, Comment, NextSpawn;
|
||||||
|
|
||||||
`ZS_Trace(`Location);
|
`ZS_Trace(`Location);
|
||||||
@ -486,13 +493,13 @@ private function SpawnEntry(out Array<S_SpawnEntry> SpawnList, int Index)
|
|||||||
SpawnList[Index].Delay = SE.DelayDefault;
|
SpawnList[Index].Delay = SE.DelayDefault;
|
||||||
if (FRand() <= SE.Probability || SE.ForceSpawn)
|
if (FRand() <= SE.Probability || SE.ForceSpawn)
|
||||||
{
|
{
|
||||||
if (SE.SingleSpawnLimit == 0 || SE.SpawnsLeft < SE.SingleSpawnLimit)
|
if (SE.SingleSpawnLimit == 0 || SE.PawnsLeft < SE.SingleSpawnLimit)
|
||||||
{
|
{
|
||||||
SpawnCount = SE.SpawnsLeft;
|
PawnCount = SE.PawnsLeft;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SpawnCount = SE.SingleSpawnLimit;
|
PawnCount = SE.SingleSpawnLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CfgSpawn.default.bShadowSpawn && !KFGIS.MyKFGRI.IsBossWave())
|
if (CfgSpawn.default.bShadowSpawn && !KFGIS.MyKFGRI.IsBossWave())
|
||||||
@ -501,16 +508,16 @@ private function SpawnEntry(out Array<S_SpawnEntry> SpawnList, int Index)
|
|||||||
if (FreeSpawnSlots == 0)
|
if (FreeSpawnSlots == 0)
|
||||||
{
|
{
|
||||||
NoFreeSpawnSlots = true;
|
NoFreeSpawnSlots = true;
|
||||||
SpawnList[Index].SpawnsLeft = 0;
|
SpawnList[Index].PawnsLeft = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (SpawnCount > FreeSpawnSlots)
|
else if (PawnCount > FreeSpawnSlots)
|
||||||
{
|
{
|
||||||
SpawnCount = FreeSpawnSlots;
|
PawnCount = FreeSpawnSlots;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Spawned = SpawnZed(SE.ZedClass, SpawnCount, SE.SpawnAtPlayerStart);
|
Spawned = SpawnZed(SE.ZedClass, PawnCount, SE.SpawnAtPlayerStart);
|
||||||
if (Spawned == INDEX_NONE)
|
if (Spawned == INDEX_NONE)
|
||||||
{
|
{
|
||||||
SpawnList[Index].Delay = 5;
|
SpawnList[Index].Delay = 5;
|
||||||
@ -538,10 +545,10 @@ private function SpawnEntry(out Array<S_SpawnEntry> SpawnList, int Index)
|
|||||||
Spawned = SE.SingleSpawnLimit;
|
Spawned = SE.SingleSpawnLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpawnList[Index].SpawnsLeft -= Spawned;
|
SpawnList[Index].PawnsLeft -= Spawned;
|
||||||
if (SpawnList[Index].SpawnsLeft > 0)
|
if (SpawnList[Index].PawnsLeft > 0)
|
||||||
{
|
{
|
||||||
NextSpawn = "next after" @ SE.DelayDefault $ "sec," @ "pawns left:" @ SpawnList[Index].SpawnsLeft;
|
NextSpawn = "next after" @ SE.DelayDefault $ "sec," @ "pawns left:" @ SpawnList[Index].PawnsLeft;
|
||||||
}
|
}
|
||||||
SpawnLog(SE, Action, Comment, NextSpawn);
|
SpawnLog(SE, Action, Comment, NextSpawn);
|
||||||
}
|
}
|
||||||
@ -593,7 +600,7 @@ private function Vector PlayerStartLocation()
|
|||||||
return KFGIS.FindPlayerStart(None, 0).Location;
|
return KFGIS.FindPlayerStart(None, 0).Location;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function int SpawnZed(class<KFPawn_Monster> ZedClass, int SpawnCount, bool SpawnAtPlayerStart)
|
private function int SpawnZed(class<KFPawn_Monster> ZedClass, int PawnCount, bool SpawnAtPlayerStart)
|
||||||
{
|
{
|
||||||
local Array<class<KFPawn_Monster> > CustomSquad;
|
local Array<class<KFPawn_Monster> > CustomSquad;
|
||||||
local Vector SpawnLocation, PlayerStart;
|
local Vector SpawnLocation, PlayerStart;
|
||||||
@ -614,7 +621,7 @@ private function int SpawnZed(class<KFPawn_Monster> ZedClass, int SpawnCount, bo
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (Index = 0; Index < SpawnCount; Index++)
|
for (Index = 0; Index < PawnCount; Index++)
|
||||||
{
|
{
|
||||||
CustomSquad.AddItem(ZedClass);
|
CustomSquad.AddItem(ZedClass);
|
||||||
}
|
}
|
||||||
@ -635,7 +642,7 @@ private function int SpawnZed(class<KFPawn_Monster> ZedClass, int SpawnCount, bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
Spawned = 0; Failed = 0;
|
Spawned = 0; Failed = 0;
|
||||||
while (Failed + Spawned < SpawnCount)
|
while (Failed + Spawned < PawnCount)
|
||||||
{
|
{
|
||||||
KFPM = Spawn(ZedClass,,, SpawnLocation, rot(0,0,1),, true);
|
KFPM = Spawn(ZedClass,,, SpawnLocation, rot(0,0,1),, true);
|
||||||
if (KFPM == None)
|
if (KFPM == None)
|
||||||
|
Loading…
Reference in New Issue
Block a user