]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/sv_spawn.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / sv_spawn.qc
1 #include "sv_spawn.qh"
2 #if defined(CSQC)
3 #elif defined(MENUQC)
4 #elif defined(SVQC)
5 #include "../util.qh"
6 #include "all.qh"
7 #include "sv_monsters.qh"
8 #include <server/autocvars.qh>
9 #include <server/defs.qh>
10 #endif
11 entity spawnmonster(entity e, string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool removeifinvalid, int moveflag)
12 {
13         e.spawnflags = MONSTERFLAG_SPAWNED;
14
15         if (!respwn) { e.spawnflags |= MONSTERFLAG_NORESPAWN; }
16         // if(invincible) { e.spawnflags |= MONSTERFLAG_INVINCIBLE; }
17
18         setorigin(e, orig);
19         bool allow_any = boolean(monster == "anyrandom");
20
21         if (monster == "random" || allow_any) {
22                 RandomSelection_Init();
23                 FOREACH(Monsters, it != MON_Null && (allow_any || (!(it.spawnflags & MONSTER_TYPE_PASSIVE) && !(it.spawnflags & MON_FLAG_HIDDEN))),
24                 {
25                         RandomSelection_AddEnt(it, 1, 1);
26                 });
27
28                 monster_id = RandomSelection_chosen_ent.monsterid;
29         } else if (monster != "") {
30                 bool found = false;
31                 FOREACH(Monsters, it != MON_Null,
32                 {
33                         if (it.netname == monster) {
34                                 found = true;
35                                 monster_id = it.monsterid; // we have the monster, old monster id is no longer required
36                                 break;
37                         }
38                 });
39
40                 if (!found && !monster_id) {
41                         if (removeifinvalid) {
42                                 delete(e);
43                                 return NULL; // no good
44                         } else {
45                                 monster_id = MON_FIRST;
46                         }
47                 }
48         }
49
50         e.realowner = spawnedby;
51
52         if (moveflag) {
53                 e.monster_moveflags = moveflag;
54         }
55
56         if (IS_PLAYER(spawnedby)) {
57                 if (teamplay && autocvar_g_monsters_teams) {
58                         e.team = spawnedby.team; // colors handled in spawn code
59                 }
60                 if (autocvar_g_monsters_owners) {
61                         e.monster_follow = own;  // using .owner makes the monster non-solid for its master
62                 }
63                 e.angles_y = spawnedby.angles_y;
64         }
65
66         // Monster_Spawn checks if monster is valid
67         if (!Monster_Spawn(e, false, monster_id)) {
68                 delete(e);
69                 return NULL; // remove even if told not to, as we didn't spawn any kind of monster
70         }
71
72         return e;
73 }