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