]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/monsters/sv_spawn.qc
Merge branch 'master' into terencehill/ft_autorevive_progress
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / sv_spawn.qc
index 884fb3dea154828ee26b392be65e1cfb48afdf8e..0a5f350eeb523bb6ef4d35981be8481a86d0178f 100644 (file)
@@ -1,14 +1,17 @@
 #include "sv_spawn.qh"
+
 #if defined(CSQC)
 #elif defined(MENUQC)
 #elif defined(SVQC)
-    #include "../util.qh"
-    #include "all.qh"
-    #include "sv_monsters.qh"
-    #include <server/autocvars.qh>
-    #include <server/defs.qh>
+       #include <common/monsters/all.qh>
+       #include <common/monsters/sv_monsters.qh>
+       #include <common/stats.qh>
+       #include <common/util.qh>
+       #include <common/weapons/_all.qh>
+       #include <server/weapons/common.qh>
 #endif
-entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag)
+
+entity spawnmonster (entity e, string monster, Monster monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag)
 {
        e.spawnflags = MONSTERFLAG_SPAWNED;
 
@@ -16,16 +19,17 @@ entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby,
        //if(invincible) { e.spawnflags |= MONSTERFLAG_INVINCIBLE; }
 
        setorigin(e, orig);
+       bool allow_any = boolean(monster == "anyrandom");
 
-       if(monster == "random")
+       if(monster == "random" || allow_any)
        {
-               RandomSelection_Init(); 
-               FOREACH(Monsters, it != MON_Null && !(it.spawnflags & MONSTER_TYPE_PASSIVE) && !(it.spawnflags & MON_FLAG_HIDDEN),
+               RandomSelection_Init();
+               FOREACH(Monsters, it != MON_Null && (allow_any || !(it.spawnflags & MON_FLAG_HIDDEN)) && !(it.spawnflags & MONSTER_TYPE_PASSIVE),
                {
                        RandomSelection_AddEnt(it, 1, 1);
                });
 
-               monster_id = RandomSelection_chosen_ent.monsterid;
+               monster_id = RandomSelection_chosen_ent;
        }
        else if(monster != "")
        {
@@ -35,12 +39,12 @@ entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby,
                        if(it.netname == monster)
                        {
                                found = true;
-                               monster_id = it.monsterid; // we have the monster, old monster id is no longer required
+                               monster_id = it; // we have the monster, old monster id is no longer required
                                break;
                        }
                });
 
-               if(!found && !monster_id)
+               if(!found && monster_id == MON_Null)
                {
                        if(removeifinvalid)
                        {
@@ -48,7 +52,10 @@ entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby,
                                return NULL; // no good
                        }
                        else
-                               monster_id = MON_FIRST;
+                       {
+                               // select a random valid monster type if no valid monster was provided
+                               return spawnmonster(e, "random", MON_Null, spawnedby, own, orig, respwn, removeifinvalid, moveflag);
+                       }
                }
        }