• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

PC KFAISpawnManager.GetNextSpawnTimeMod() returns an int

pie1055

Grizzled Veteran
Jul 6, 2011
507
78
Bedlam
Category:
Code

Reproducibility:
Always

Summary:
The function definition GetNextSpawnTimeMod() in the class KFAISpawnManager returns a float but the actual return line uses Max() instead of FMax() so the value gets truncated and fractional information is lost, possibly throwing other math off down the line.

Description:
The code I'm using/seeing/looking at is located in "Steam\steamapps\common\killingfloor2\Development\Src\KFGame\Classes\KFAISpawnManager.uc" and is up-to-date AFAIK. Anyways the function definition is;
Code:
function float GetNextSpawnTimeMod()
and the only return line in the function is;
Code:
return Max(SpawnTimeMod, 0.f);
Since the function is supposed to return a float, the local variable SpawnTimeMod is a float, the 0.f in the return line is a float, and anything with "mod" in the name is usually short for "modifier" which usually means float, it seems as though the return should be using FMax() instead of Max() to return the value of SpawnTimeMod(as long as it's > 0.0f) WITHOUT truncating the fractional data as it currently does since Max() returns an int. Additionally, the class has a subclass in "Steam\steamapps\common\killingfloor2\Development\Src\KFGameContent\Classes\KFAISpawnManager_Endless.uc" which "extends"(or whatever the unrealscript terminology is) the GetNextSpawnTimeMod() function and also uses Max() instead of FMax() in the line;
Code:
SpawnTimeMod = Max(SpawnTimeMod, SpawnTimeModMin);
Where yet again SpawnTimeMod and SpawnTimeModMin are both floats but the assignment truncates the fractional data because of the use of Max() instead of FMax(). Of course, these cases could intentionally be truncating the floats but it seems unlikely and I sure as hell know I forget about Unreal's 'F' function variations that use/return floats instead of ints all the time(FClamp(), FMin(), FRand(), etc). It doesn't help that at least with the version of Unrealscript that KF2 uses it happily gobbles up floats into int function parameters and vice versa without so much as a warning in the build process about conversions but then again I'm running "kfeditor make" in the windows command shell so who knows how that compares to the actual devs' experience.

Online/Offline:
Both