
void (vector org, entity death_owner) spawn_tdeath;

void (vector org) spawn_tfog;

void () monster_army;
void () monster_boss; //added for alien quake

void () monster_knight;

void () monster_ogre;

void () monster_enforcer;

void () monster_dog;

void () monster_hell_knight;

void () monster_wizard;

void () monster_zombie;

void () monster_demon1;

void () monster_shambler;


//void () big_enforcer;
void () monster_shalrath;


float SVC_UPDATESTAT = 3;
float STAT_TOTALMONSTERS = 12;


float (entity thePoint) isSpawnPointEmpty = {


   local entity neighbors;
   local entity start;

   if ( (start == world) ) {

      return ( TRUE );

   }
   neighbors = findradius (thePoint.origin,FL_MONSTER);
   if ( (neighbors == world) ) {

      return ( TRUE );

   }
   start = neighbors;
   while ( neighbors ) {

      if ( (neighbors != thePoint) ) {

         if ( (neighbors.flags & FL_MONSTER) ) {

            return ( FALSE );

         } else {

            if ( (neighbors.classname == "player") ) {

               return ( FALSE );

            }

         }

      }
      neighbors = neighbors.chain;
      if ( (neighbors == start) ) {

         return ( TRUE );

      }

   }
   return ( TRUE );

};
float () reporttime = {

   return ( starttime );

};

void () monsterspawner = {

   local entity tself;
   local entity cl;
   local float n;

   if ( (((time - lasttime) > TRUE) && (totalmonsterspawn > FALSE)) ) {

      if ( (nspawned == FALSE) ) {

         cl = find (world,classname,"player");
         //centerprint (cl,"The invasion has begun!");

      }
      cl = find (world,classname,"player");
      if ( cl.deadflag ) {

         return ;

      }
      nspawned = (nspawned + TRUE);
      lasttime = time;
      lastmspawn = find (lastmspawn,classname,"info_player_deathmatch");
      if ( (lastmspawn == world) ) {

         return ;

      }
      tself = lastmspawn;
      n = isSpawnPointEmpty (lastmspawn);
      while ( (n == FALSE) ) {

         lastmspawn = find (lastmspawn,classname,"info_player_deathmatch");
         n = isSpawnPointEmpty (lastmspawn);

         if ( (lastmspawn == world) ) {    return;   }
         if ( (lastmspawn == tself) ) {    return;   }

      }

      if ( (lastmspawn == world) ) {

         return ;

      }
      tself = self;
      self = spawn ();
      if ( (lastmspawn.cnt == TRUE) ) {

         n = (totalmonsterspawn & MOVETYPE_PUSH);
         if ( (n == FALSE) ) {

            monster_demon1 ();

         } else {

            if ( (n == TRUE) ) {

               monster_dog ();
					//monster_boss();
            } else {

               if ( (n == FL_SWIM) ) {

               monster_dog ();
					//monster_boss();

               } else {

                  if ( (n == MOVETYPE_WALK) ) {

      		         monster_dog ();
							//monster_boss();
							//monster_ogre();
							
                  } else {

                     if ( (n == MOVETYPE_STEP) ) {

                        if ( ((totalmonsterspawn & FL_CLIENT) == FALSE) ) {

								
								monster_shambler();
                        } else {

                           monster_demon1 ();

                        }

                     } else {

                        if ( (n == MOVETYPE_FLY) ) {

                           monster_demon1 ();

                        } else {

                           if ( (n == MOVETYPE_TOSS) ) {

                              monster_demon1 ();

                           } else {

                              monster_ogre ();

                           }

                        }

                     }

                  }

               }

            }

         }

      } else {

         n = (totalmonsterspawn & MOVETYPE_PUSH);
         if ( (n == FALSE) ) {

            //monster_knight ();
            monster_demon1();

         } else {

            if ( (n == TRUE) ) {

               monster_demon1 ();
               //                  big_enforcer();


            } else {

               if ( (n == FL_SWIM) ) {

                  //if (random() < 0.6)
                     monster_dog ();
                  //else
                    // big_enforcer();


               } else {

                  if ( (n == MOVETYPE_WALK) ) {

                     monster_ogre ();

                  } else {

                     if ( (n == MOVETYPE_STEP) ) {

                        monster_dog ();

                     } else {

                        if ( (n == MOVETYPE_FLY) ) {

                           monster_ogre ();

                        } else {

                           if ( (n == MOVETYPE_TOSS) ) {

                              monster_demon1 ();

                           } else {

                              monster_demon1 ();

                           }

                        }

                     }

                  }

               }

            }

         }

      }
      setorigin (self,lastmspawn.origin);
      spawn_tfog (self.origin);
      spawn_tdeath (self.origin,self);
      self = tself;
      totalmonsterspawn = (totalmonsterspawn - TRUE);

      // Update engine status bar
      WriteByte (MSG_BROADCAST, SVC_UPDATESTAT);
      WriteByte (MSG_BROADCAST, STAT_TOTALMONSTERS);
      WriteLong (MSG_BROADCAST, total_monsters);

      if ( (totalmonsterspawn < TRUE) ) {

         cl = find (world,classname,"player");
         //centerprint (cl,"The invasion has ended!");

      }

   }

};

