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