Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_spawn.qc
Go to the documentation of this file.
1#include "sv_spawn.qh"
2
3#ifdef SVQC
6 #include <common/stats.qh>
7 #include <common/util.qh>
10#endif
11
12entity spawnmonster(entity e, string monster, Monster monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag)
13{
14 e.spawnflags = MONSTERFLAG_SPAWNED;
15
16 if (!respwn)
17 e.spawnflags |= MONSTERFLAG_NORESPAWN;
18 //if (invincible) e.spawnflags |= MONSTERFLAG_INVINCIBLE;
19
20 setorigin(e, orig);
21 bool allow_any = (monster == "anyrandom");
22
23 if (monster == "random" || allow_any)
24 {
26 FOREACH(Monsters, it != MON_Null && (allow_any || !(it.spawnflags & MON_FLAG_HIDDEN)) && !(it.spawnflags & MONSTER_TYPE_PASSIVE),
27 RandomSelection_AddEnt(it, 1, 1));
28 monster_id = RandomSelection_chosen_ent;
29 }
30 else if (monster != "")
31 {
32 bool found = false;
33 FOREACH(Monsters, it != MON_Null && it.netname == monster,
34 {
35 found = true;
36 monster_id = it; // we have the monster, old monster id is no longer required
37 break;
38 });
39
40 if (!found && monster_id == MON_Null)
41 {
42 if (removeifinvalid)
43 {
44 delete(e);
45 return NULL; // no good
46 }
47 else // select a random valid monster type if no valid monster was provided
48 return spawnmonster(e, "random", MON_Null, spawnedby, own, orig, respwn, removeifinvalid, moveflag);
49 }
50 }
51
52 e.realowner = spawnedby;
53
54 if (moveflag)
55 e.monster_moveflags = moveflag;
56
57 if (IS_PLAYER(spawnedby))
58 {
60 e.team = spawnedby.team; // colors handled in spawn code
62 e.monster_follow = own; // using .owner makes the monster non-solid for its master
63
64 e.angles.y = spawnedby.angles.y;
65 }
66
67 // Monster_Spawn checks if monster is valid
68 if (!Monster_Spawn(e, false, monster_id))
69 {
70 delete(e);
71 return NULL; // remove even if told not to, as we didn't spawn any kind of monster
72 }
73
74 return e;
75}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define IS_PLAYER(s)
Definition player.qh:242
#define FOREACH(list, cond, body)
Definition iter.qh:19
const int MONSTER_TYPE_PASSIVE
doesn't target or chase enemies
Definition monster.qh:15
const int MON_FLAG_HIDDEN
Definition monster.qh:17
#define NULL
Definition post.qh:14
ERASEABLE void RandomSelection_Init()
Definition random.qc:4
#define RandomSelection_AddEnt(e, weight, priority)
Definition random.qh:14
entity RandomSelection_chosen_ent
Definition random.qh:5
vector
Definition self.qh:92
bool Monster_Spawn(entity this, bool check_appear, Monster mon)
Setup the basic required properties for a monster.
const int MONSTERFLAG_NORESPAWN
monster doesn't respawn (revive)
const int MONSTERFLAG_SPAWNED
flag for spawned monsters
bool autocvar_g_monsters_owners
bool autocvar_g_monsters_teams
entity spawnmonster(entity e, string monster, Monster monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag)
Definition sv_spawn.qc:12
bool teamplay
Definition teams.qh:59