adjustingcf

Discussions about Coding and Scripting
Post Reply
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

adjustingcf

Post 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();
}
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: adjustingcf

Post 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.
So long, and thanks for all the fish
Post Reply