Xonotic
sv_spawn.qh File Reference
+ Include dependency graph for sv_spawn.qh:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

entity spawnmonster (entity e, string monster, Monster monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag)
 

Function Documentation

◆ spawnmonster()

entity spawnmonster ( entity  e,
string  monster,
Monster  monster_id,
entity  spawnedby,
entity  own,
vector  orig,
bool  respwn,
bool  removeifinvalid,
int  moveflag 
)

Definition at line 14 of file sv_spawn.qc.

References autocvar_g_monsters_owners, autocvar_g_monsters_teams, boolean, FOREACH, IS_PLAYER, MON_FLAG_HIDDEN, Monster_Spawn(), MONSTER_TYPE_PASSIVE, MONSTERFLAG_NORESPAWN, MONSTERFLAG_SPAWNED, NULL, RandomSelection_chosen_ent, RandomSelection_Init(), setorigin(), spawnmonster(), and teamplay.

Referenced by CommonCommand_editmob(), invasion_SpawnChosenMonster(), spawner_use(), and spawnmonster().

15 {
16  e.spawnflags = MONSTERFLAG_SPAWNED;
17 
18  if(!respwn) { e.spawnflags |= MONSTERFLAG_NORESPAWN; }
19  //if(invincible) { e.spawnflags |= MONSTERFLAG_INVINCIBLE; }
20 
21  setorigin(e, orig);
22  bool allow_any = boolean(monster == "anyrandom");
23 
24  if(monster == "random" || allow_any)
25  {
27  FOREACH(Monsters, it != MON_Null && (allow_any || !(it.spawnflags & MON_FLAG_HIDDEN)) && !(it.spawnflags & MONSTER_TYPE_PASSIVE),
28  {
29  RandomSelection_AddEnt(it, 1, 1);
30  });
31 
32  monster_id = RandomSelection_chosen_ent;
33  }
34  else if(monster != "")
35  {
36  bool found = false;
37  FOREACH(Monsters, it != MON_Null,
38  {
39  if(it.netname == monster)
40  {
41  found = true;
42  monster_id = it; // we have the monster, old monster id is no longer required
43  break;
44  }
45  });
46 
47  if(!found && monster_id == MON_Null)
48  {
49  if(removeifinvalid)
50  {
51  delete(e);
52  return NULL; // no good
53  }
54  else
55  {
56  // select a random valid monster type if no valid monster was provided
57  return spawnmonster(e, "random", MON_Null, spawnedby, own, orig, respwn, removeifinvalid, moveflag);
58  }
59  }
60  }
61 
62  e.realowner = spawnedby;
63 
64  if(moveflag)
65  e.monster_moveflags = moveflag;
66 
67  if(IS_PLAYER(spawnedby))
68  {
70  e.team = spawnedby.team; // colors handled in spawn code
71 
73  e.monster_follow = own; // using .owner makes the monster non-solid for its master
74 
75  e.angles_y = spawnedby.angles_y;
76  }
77 
78  // Monster_Spawn checks if monster is valid
79  if(!Monster_Spawn(e, false, monster_id))
80  {
81  delete(e);
82  return NULL; // remove even if told not to, as we didn't spawn any kind of monster
83  }
84 
85  return e;
86 }
const int MON_FLAG_HIDDEN
Definition: monster.qh:16
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:14
ERASEABLE void RandomSelection_Init()
Definition: random.qc:4
const int MONSTERFLAG_NORESPAWN
Definition: sv_monsters.qh:86
bool autocvar_g_monsters_teams
Definition: sv_monsters.qh:25
entity RandomSelection_chosen_ent
Definition: random.qh:5
#define NULL
Definition: post.qh:17
float teamplay
Definition: progsdefs.qc:31
bool autocvar_g_monsters_owners
Definition: sv_monsters.qh:19
bool Monster_Spawn(entity this, bool check_appear, Monster mon)
const int MONSTER_TYPE_PASSIVE
Definition: monster.qh:14
setorigin(ent, v)
#define FOREACH(list, cond, body)
Definition: iter.qh:19
#define boolean(value)
Definition: bool.qh:9
#define IS_PLAYER(v)
Definition: utils.qh:9
const int MONSTERFLAG_SPAWNED
Definition: sv_monsters.qh:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function: