#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 (string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool invincible, int moveflag)
-{
- entity e = spawn();
+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;
if(!respwn) { e.spawnflags |= MONSTERFLAG_NORESPAWN; }
- if(invincible) { e.spawnflags |= MONSTERFLAG_INVINCIBLE; }
+ //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,
+ RandomSelection_Init();
+ FOREACH(Monsters, it != MON_Null && (allow_any || !(it.spawnflags & MON_FLAG_HIDDEN)) && !(it.spawnflags & MONSTER_TYPE_PASSIVE),
{
- RandomSelection_Add(it, 0, string_null, 1, 1);
+ RandomSelection_AddEnt(it, 1, 1);
});
- monster_id = RandomSelection_chosen_ent.monsterid;
+ monster_id = RandomSelection_chosen_ent;
}
else if(monster != "")
{
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 = ((monster_id > 0) ? monster_id : MON_FIRST);
+
+ if(!found && monster_id == MON_Null)
+ {
+ if(removeifinvalid)
+ {
+ delete(e);
+ return NULL; // no good
+ }
+ else
+ {
+ // select a random valid monster type if no valid monster was provided
+ return spawnmonster(e, "random", MON_Null, spawnedby, own, orig, respwn, removeifinvalid, moveflag);
+ }
+ }
}
e.realowner = spawnedby;
}
// Monster_Spawn checks if monster is valid
- Monster_Spawn(e, monster_id);
+ if(!Monster_Spawn(e, false, monster_id))
+ {
+ delete(e);
+ return NULL; // remove even if told not to, as we didn't spawn any kind of monster
+ }
return e;
}