adjustingcf

Discussions about Coding and Scripting

adjustingcf

Postby Barbie » Thu Feb 28, 2019 5:30 am

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
User avatar
Barbie
Godlike
 
Posts: 1623
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: adjustingcf

Postby JackGriffin » Thu Feb 28, 2019 4:42 pm

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.
"You damn kids, back in my time we made the items, maps and games ourselves with an unwieldy engine using counter-intuitive crash-prone tools and we liked it so much we built communities around this which nowadays look like cults because they're quasi-parallel societies based on the same old games." -Hellkeeper
User avatar
JackGriffin
Godlike
 
Posts: 3723
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: Hack coder


Return to Coding, Scripting

Who is online

Users browsing this forum: No registered users and 1 guest