Code: Select all
//=============================================================================
// adjustingcf. Adjusts the maximum number of spawned monsters according to current playercount.
//=============================================================================
class adjustingcf expands CreatureFactory;
var int curmaxitems;
var int curplayers;
var() int mperplayer; // How many monsters to add per player
State Spawning
{
function UnTouch(Actor Other)
{
local int i;
if (bStoppable)
{
//check if some other pawn still touching
for (i=0;i<4;i++)
if ( (pawn(Touching[i]) != None) && (!bOnlyPlayerTouched || pawn(Touching[i]).bIsPlayer) )
return;
GotoState('Waiting');
}
}
function Trigger(actor Other, pawn EventInstigator)
{
//only if Other is from this factory
if ( Other.class != prototype )
return;
numitems--;
if (numitems < curmaxitems)
StartBuilding();
}
function bool trySpawn(int start, int end)
{
local int i;
local bool done;
done = false;
i = start;
while (i < end)
{
if (spawnspot[i].Create())
{
done = true;
i = end;
capacity--;
numitems++;
if (capacity == 0)
GotoState('Finished');
}
i++;
}
return done;
}
function Timer()
{
local int start;
local GameInfo GI;
local Bot B;
foreach AllActors(class'GameInfo', GI)
{
curplayers=GI.NumPlayers;
}
foreach ALlActors(class'Bot', B)
{
if (!B.PlayerReplicationInfo.bIsSpectator)
curplayers++;
}
curmaxitems=curplayers*mperplayer;
if (numitems < curmaxitems)
{
//pick a spawn point
start = Rand(numspots);
if ( !trySpawn(start, numspots) )
trySpawn(0, start);
}
if (numitems < curmaxitems)
StartBuilding();
}
Function StartBuilding()
{
local float nextTime;
if (timeDistribution == DIST_Constant)
nextTime = interval;
else if (timeDistribution == DIST_Uniform)
nextTime = 2 * FRand() * interval;
else //timeDistribution is gaussian
nextTime = 0.5 * (FRand() + FRand() + FRand() + FRand()) * interval;
if (capacity > 0)
SetTimer(nextTime, false);
}
function BeginState()
{
if ( !bStoppable )
Disable('UnTouch');
}
Begin:
Timer();
}