Page 1 of 1

adjustingcf

Posted: Thu Feb 28, 2019 5:30 am
by Barbie
Can someone tell how many are spawned with this factory? (Found in MH-Canals][-fix.unr)

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();
}

Re: adjustingcf

Posted: Thu Feb 28, 2019 4:42 pm
by JackGriffin
There's been a bunch of different attempts at sliding-scale monster counts. Most of them are...tragic. If you must have adjusting I always thought it was better to adjust damage done by the players and/or health of the monsters. Messing with the counts can just have too many trigger issues.