]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/monsters/sv_spawn.qc
Use monster definitions directly instead of a set ID, reduces registry calls needed...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / sv_spawn.qc
index d456282d429ee6fbc6c5113f90b7f57484b8fcff..f4ae76df8ce919049741f1763cb6a795c5857da2 100644 (file)
@@ -8,7 +8,7 @@
     #include <server/autocvars.qh>
     #include <server/defs.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;
 
@@ -26,7 +26,7 @@ entity spawnmonster (entity e, string monster, int monster_id, entity spawnedby,
                        RandomSelection_AddEnt(it, 1, 1);
                });
 
-               monster_id = RandomSelection_chosen_ent.monsterid;
+               monster_id = RandomSelection_chosen_ent;
        }
        else if(monster != "")
        {
@@ -36,12 +36,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)
                        {
@@ -49,7 +49,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);
+                       }
                }
        }