]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/monsters/spawn.qc
Merge remote-tracking branch 'remotes/origin/master' into TimePath/itemsys
[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         // ensure spawnfunc database is initialized
15         //initialize_field_db();
16
17         entity e = spawn();
18         float i;
19
20         e.spawnflags = MONSTERFLAG_SPAWNED;
21
22         if(!respwn)
23                 e.spawnflags |= MONSTERFLAG_NORESPAWN;
24
25         if(invincible)
26                 e.spawnflags |= MONSTERFLAG_INVINCIBLE;
27
28         setorigin(e, orig);
29
30         if(monster == "random")
31         {
32                 RandomSelection_Init();
33                 for(i = MON_FIRST; i <= MON_LAST; ++i)
34                         RandomSelection_Add(world, 0, (get_monsterinfo(i)).netname, 1, 1);
35
36                 monster = RandomSelection_chosen_string;
37         }
38
39         if(monster != "")
40         {
41                 float found = 0;
42                 entity mon;
43                 for(i = MON_FIRST; i <= MON_LAST; ++i)
44                 {
45                         mon = get_monsterinfo(i);
46                         if(mon.netname == monster)
47                         {
48                                 found = true;
49                                 monster_id = mon.monsterid; // we have the monster, old monster id is no longer required
50                                 break;
51                         }
52                 }
53                 if(!found)
54                         monster = (get_monsterinfo(MON_FIRST)).netname;
55         }
56
57         if(monster == "")
58         if(monster_id)
59                 monster = (get_monsterinfo(monster_id)).netname;
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_owner = own; // using .owner makes the monster non-solid for its master
73
74                 e.angles = spawnedby.angles;
75         }
76
77         //monster = strcat("$ spawnfunc_monster_", monster);
78
79         entity oldself = self;
80         self = e;
81         monster_initialize(monster_id);
82         self = oldself;
83
84         //target_spawn_edit_entity(e, monster, world, world, world, world, world);
85
86         return e;
87 }