]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/spawn.qc
Transifex sync.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / monsters / spawn.qc
1 #if defined(CSQC)
2 #elif defined(MENUQC)
3 #elif defined(SVQC)
4         #include "../../dpdefs/progsdefs.qh"
5     #include "../util.qh"
6     #include "all.qh"
7     #include "sv_monsters.qh"
8     #include "spawn.qh"
9     #include "../../server/autocvars.qh"
10     #include "../../server/defs.qh"
11 #endif
12 entity spawnmonster (string monster, float monster_id, entity spawnedby, entity own, vector orig, float respwn, float invincible, float moveflag)
13 {
14        float i;
15         entity e = spawn();
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
24         if(monster == "random")
25         {
26                 RandomSelection_Init();
27                 for(i = MON_FIRST; i <= MON_LAST; ++i)
28                         RandomSelection_Add(world, i, string_null, 1, 1);
29
30            monster_id = RandomSelection_chosen_float;
31         }
32         else if(monster != "")
33         {
34                 float found = 0;
35                 entity mon;
36                 for(i = MON_FIRST; i <= MON_LAST; ++i)
37                 {
38                         mon = get_monsterinfo(i);
39                         if(mon.netname == monster)
40                         {
41                                 found = true;
42                                 monster_id = mon.monsterid; // we have the monster, old monster id is no longer required
43                                 break;
44                         }
45                 }
46                 if(!found)
47                         monster_id = ((monster_id > 0) ? monster_id : MON_FIRST);
48         }
49
50         e.realowner = spawnedby;
51
52         if(moveflag)
53                 e.monster_moveflags = moveflag;
54
55         if(IS_PLAYER(spawnedby))
56         {
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         entity oldself = self;
68         self = e;
69         Monster_Spawn(monster_id);
70         self = oldself;
71
72         return e;
73 }