]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/spawn.qc
s/world/NULL/
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / spawn.qc
1 #if defined(CSQC)
2 #elif defined(MENUQC)
3 #elif defined(SVQC)
4     #include "../util.qh"
5     #include "all.qh"
6     #include "sv_monsters.qh"
7     #include "spawn.qh"
8     #include <server/autocvars.qh>
9     #include <server/defs.qh>
10 #endif
11 entity spawnmonster (string monster, float monster_id, entity spawnedby, entity own, vector orig, float respwn, float invincible, float moveflag)
12 {
13        float i;
14         entity e = spawn();
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
23         if(monster == "random")
24         {
25                 RandomSelection_Init();
26                 for(i = MON_FIRST; i <= MON_LAST; ++i)
27                         RandomSelection_Add(NULL, i, string_null, 1, 1);
28
29            monster_id = RandomSelection_chosen_float;
30         }
31         else if(monster != "")
32         {
33                 float found = 0;
34                 entity mon;
35                 for(i = MON_FIRST; i <= MON_LAST; ++i)
36                 {
37                         mon = get_monsterinfo(i);
38                         if(mon.netname == monster)
39                         {
40                                 found = true;
41                                 monster_id = mon.monsterid; // we have the monster, old monster id is no longer required
42                                 break;
43                         }
44                 }
45                 if(!found)
46                         monster_id = ((monster_id > 0) ? monster_id : MON_FIRST);
47         }
48
49         e.realowner = spawnedby;
50
51         if(moveflag)
52                 e.monster_moveflags = moveflag;
53
54         if(IS_PLAYER(spawnedby))
55         {
56                 if(teamplay && autocvar_g_monsters_teams)
57                         e.team = spawnedby.team; // colors handled in spawn code
58
59                 if(autocvar_g_monsters_owners)
60                         e.monster_follow = own; // using .owner makes the monster non-solid for its master
61
62                 e.angles_y = spawnedby.angles_y;
63         }
64
65         // Monster_Spawn checks if monster is valid
66         Monster_Spawn(e, monster_id);
67
68         return e;
69 }