]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/sv_spawn.qc
8c658252071977f014458e29dff9d1f71c54205e
[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 (string monster, int monster_id, entity spawnedby, entity own, vector orig, bool respwn, bool invincible, int moveflag)
12 {
13         entity e = spawn();
14
15         e.spawnflags = MONSTERFLAG_SPAWNED;
16
17         if(!respwn) { e.spawnflags |= MONSTERFLAG_NORESPAWN; }
18         if(invincible) { e.spawnflags |= MONSTERFLAG_INVINCIBLE; }
19
20         setorigin(e, orig);
21
22         if(monster == "random")
23         {
24                 RandomSelection_Init(); 
25                 FOREACH(Monsters, it != MON_Null && !(it.spawnflags & MONSTER_TYPE_PASSIVE),
26                 {
27                         RandomSelection_AddEnt(it, 1, 1);
28                 });
29
30                 monster_id = RandomSelection_chosen_ent.monsterid;
31         }
32         else if(monster != "")
33         {
34                 bool found = false;
35                 FOREACH(Monsters, it != MON_Null,
36                 {
37                         if(it.netname == monster)
38                         {
39                                 found = true;
40                                 monster_id = it.monsterid; // we have the monster, old monster id is no longer required
41                                 break;
42                         }
43                 });
44                 if(!found)
45                         monster_id = ((monster_id > 0) ? monster_id : MON_FIRST);
46         }
47
48         e.realowner = spawnedby;
49
50         if(moveflag)
51                 e.monster_moveflags = moveflag;
52
53         if(IS_PLAYER(spawnedby))
54         {
55                 if(teamplay && autocvar_g_monsters_teams)
56                         e.team = spawnedby.team; // colors handled in spawn code
57
58                 if(autocvar_g_monsters_owners)
59                         e.monster_follow = own; // using .owner makes the monster non-solid for its master
60
61                 e.angles_y = spawnedby.angles_y;
62         }
63
64         // Monster_Spawn checks if monster is valid
65         Monster_Spawn(e, monster_id);
66
67         return e;
68 }