2023-05-14 06:38:02 +00:00
class SpawnListRegular extends Object
dependson ( ZedSpawner )
config ( ZedSpawner ) ;
struct S _SpawnEntryCfg
{
var int Wave ;
var String ZedClass ;
var int RelativeStart ;
var int Delay ;
var int Probability ;
var int SpawnCountBase ;
var int SingleSpawnLimit ;
} ;
var public config Array < S _SpawnEntryCfg > Spawn ;
delegate int SpawnListSort ( S _SpawnEntryCfg A , S _SpawnEntryCfg B )
{
return A . Wave > B . Wave ? - 1 : 0 ;
}
public static function InitConfig ( int Version , int LatestVersion , KFGI _Access KFGIA , E _LogLevel LogLevel )
{
` Log_TraceStatic();
switch ( Version )
{
case ` NO_CONFIG:
ApplyDefault ( KFGIA , LogLevel ) ;
default : break ;
}
if ( LatestVersion != Version )
{
StaticSaveConfig ( ) ;
}
}
private static function ApplyDefault ( KFGI _Access KFGIA , E _LogLevel LogLevel )
{
local S _SpawnEntryCfg SpawnEntry ;
local Array < class < KFPawn _Monster > > KFPM _Zeds ;
local class < KFPawn _Monster > KFPMC ;
` Log_TraceStatic();
default . Spawn . Length = 0 ;
SpawnEntry . Wave = 0 ;
SpawnEntry . SpawnCountBase = 2 ;
SpawnEntry . SingleSpawnLimit = 1 ;
SpawnEntry . RelativeStart = 25 ;
SpawnEntry . Delay = 60 ;
SpawnEntry . Probability = 100 ;
KFPM _Zeds = KFGIA . GetAIClassList ( LogLevel ) ;
foreach KFPM _Zeds ( KFPMC )
{
++ SpawnEntry . Wave ;
SpawnEntry . ZedClass = "KFGameContent." $ String ( KFPMC ) ;
default . Spawn . AddItem ( SpawnEntry ) ;
}
}
public static function Array < S _SpawnEntry > Load ( E _LogLevel LogLevel )
{
local Array < S _SpawnEntry > SpawnList ;
local S _SpawnEntryCfg SpawnEntryCfg ;
local S _SpawnEntry SpawnEntry ;
local int Line ;
local bool Errors ;
` Log_TraceStatic();
` Log_Info("Load spawn list:");
foreach default . Spawn ( SpawnEntryCfg , Line )
{
Errors = false ;
SpawnEntry . Wave = SpawnEntryCfg . Wave ;
if ( SpawnEntryCfg . Wave <= 0 || SpawnEntryCfg . Wave > 255 )
{
` Log_Warn("[" $ Line + 1 $ "]" @ "Wave" @ "(" $ SpawnEntryCfg.ZedClass $ ")" @ "must be greater than 0 and less than 256");
Errors = true ;
}
SpawnEntry . ZedClass = class < KFPawn _Monster > ( DynamicLoadObject ( SpawnEntryCfg . ZedClass , class 'Class' ) ) ;
if ( SpawnEntry . ZedClass == None )
{
` Log_Warn("[" $ Line + 1 $ "]" @ "Can't load zed class:" @ SpawnEntryCfg.ZedClass);
Errors = true ;
}
SpawnEntry . RelativeStartDefault = SpawnEntryCfg . RelativeStart / 100. f ;
if ( SpawnEntryCfg . RelativeStart < 0 || SpawnEntryCfg . RelativeStart > 100 )
{
` Log_Warn("[" $ Line + 1 $ "]" @ "RelativeStart" @ "(" $ SpawnEntryCfg.RelativeStart $ ")" @ "must be greater than or equal 0 and less than or equal 100");
Errors = true ;
}
SpawnEntry . DelayDefault = SpawnEntryCfg . Delay ;
if ( SpawnEntryCfg . Delay <= 0 )
{
` Log_Warn("[" $ Line + 1 $ "]" @ "Delay" @ "(" $ SpawnEntryCfg.Delay $ ")" @ "must be greater than 0");
Errors = true ;
}
SpawnEntry . Probability = SpawnEntryCfg . Probability / 100. f ;
if ( SpawnEntryCfg . Probability <= 0 || SpawnEntryCfg . Probability > 100 )
{
` Log_Warn("[" $ Line + 1 $ "]" @ "Probability" @ "(" $ SpawnEntryCfg.Probability $ ")" @ "must be greater than 0 and less than or equal 100");
Errors = true ;
}
SpawnEntry . SpawnCountBase = SpawnEntryCfg . SpawnCountBase ;
if ( SpawnEntry . SpawnCountBase <= 0 )
{
` Log_Warn("[" $ Line + 1 $ "]" @ "SpawnCountBase" @ "(" $ SpawnEntryCfg.SpawnCountBase $ ")" @ "must be greater than 0");
Errors = true ;
}
SpawnEntry . SingleSpawnLimitDefault = SpawnEntryCfg . SingleSpawnLimit ;
if ( SpawnEntry . SingleSpawnLimit < 0 )
{
` Log_Warn("[" $ Line + 1 $ "]" @ "SingleSpawnLimit" @ "(" $ SpawnEntryCfg.SingleSpawnLimit $ ")" @ "must be equal or greater than 0");
Errors = true ;
}
if ( ! Errors )
{
SpawnList . AddItem ( SpawnEntry ) ;
` Log_Debug("[" $ Line + 1 $ "]" @ "Loaded successfully: (w" $ SpawnEntryCfg.Wave $ ")" @ SpawnEntryCfg.ZedClass);
}
}
default . Spawn . Sort ( SpawnListSort ) ;
if ( SpawnList . Length == default . Spawn . Length )
{
` Log_Info("Regular spawn list loaded successfully (" $ default.Spawn.Length @ "entries)");
}
else
{
` Log_Info("Regular spawn list: loaded" @ SpawnList.Length @ "of" @ default.Spawn.Length @ "entries");
}
return SpawnList ;
}
defaultproperties
{
}