]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/sv_spawn.qc
Merge branch 'master' into Mario/q3compat_sanity. Also store supported map features...
[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, Monster 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         {
23                 RandomSelection_Init();
24                 FOREACH(Monsters, it != MON_Null && (allow_any || !(it.spawnflags & MON_FLAG_HIDDEN)) && !(it.spawnflags & MONSTER_TYPE_PASSIVE),
25                 {
26                         RandomSelection_AddEnt(it, 1, 1);
27                 });
28
29                 monster_id = RandomSelection_chosen_ent;
30         }
31         else if(monster != "")
32         {
33                 bool found = false;
34                 FOREACH(Monsters, it != MON_Null,
35                 {
36                         if(it.netname == monster)
37                         {
38                                 found = true;
39                                 monster_id = it; // we have the monster, old monster id is no longer required
40                                 break;
41                         }
42                 });
43
44                 if(!found && monster_id == MON_Null)
45                 {
46                         if(removeifinvalid)
47                         {
48                                 delete(e);
49                                 return NULL; // no good
50                         }
51                         else
52                         {
53                                 // select a random valid monster type if no valid monster was provided
54                                 return spawnmonster(e, "random", MON_Null, spawnedby, own, orig, respwn, removeifinvalid, moveflag);
55                         }
56                 }
57         }
58
59         e.realowner = spawnedby;
60
61         if(moveflag)
62                 e.monster_moveflags = moveflag;
63
64         if(IS_PLAYER(spawnedby))
65         {
66                 if(teamplay && autocvar_g_monsters_teams)
67                         e.team = spawnedby.team; // colors handled in spawn code
68
69                 if(autocvar_g_monsters_owners)
70                         e.monster_follow = own; // using .owner makes the monster non-solid for its master
71
72                 e.angles_y = spawnedby.angles_y;
73         }
74
75         // Monster_Spawn checks if monster is valid
76         if(!Monster_Spawn(e, false, monster_id))
77         {
78                 delete(e);
79                 return NULL; // remove even if told not to, as we didn't spawn any kind of monster
80         }
81
82         return e;
83 }