]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/monsters/lib/spawn.qc
Use a cvar for monster list rather than a hardcoded string (invalid value is replaced...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / monsters / lib / spawn.qc
1 float spawnmonster_checkinlist(string monster, string list)
2 {
3         string l = strcat(" ", list, " ");
4         
5         if(strstrofs(l, strcat(" ", monster, " "), 0) >= 0)
6                 return TRUE;
7         
8         return FALSE;
9 }
10
11 entity spawnmonster (string monster, entity spawnedby, entity own, vector orig, float respwn, float moveflag)
12 {
13         if not(autocvar_g_monsters)
14         {
15                 if(spawnedby.flags & FL_CLIENT)
16                         sprint(spawnedby, "Monsters are disabled. Enable g_monsters to spawn monsters\n");
17                 return world;
18         }
19         
20         if(spawnedby.vehicle) // no vehicle player spawning...
21                 return world;
22         
23         if(!spawncode_first_load)
24         {
25                 initialize_field_db();
26                 spawncode_first_load = TRUE;
27         }
28         
29         entity e = spawn();
30         
31         e.spawnflags = MONSTERFLAG_SPAWNED;
32         
33         if not(respwn)
34                 e.spawnflags |= MONSTERFLAG_NORESPAWN;
35         
36         setorigin(e, orig);
37         
38         if not(spawnmonster_checkinlist(monster, autocvar_g_monsters_spawn_list))
39                 monster = "knight";
40         
41         e.realowner = spawnedby;
42         
43         if(moveflag)
44                 e.monster_moveflags = moveflag;
45         
46         if (spawnedby.classname == "monster_swarm")
47                 e.monster_owner = own;  
48         else if(spawnedby.flags & FL_CLIENT)
49         {
50                 if(teamplay && autocvar_g_monsters_teams)
51                         e.team = spawnedby.team; // colors handled in spawn code
52                         
53                 if not(teamplay)
54                         e.colormap = spawnedby.colormap;
55                         
56                 if(autocvar_g_monsters_owners)
57                         e.monster_owner = own; // using owner makes the monster non-solid for its master
58                         
59                 e.angles = spawnedby.angles;
60         }
61         
62         if(autocvar_g_monsters_giants_only)
63                 e.spawnflags |= MONSTERFLAG_GIANT;
64                 
65         monster = strcat("$ spawnfunc_monster_", monster);
66                 
67         target_spawn_edit_entity(e, monster, world, world, world, world, world);
68                 
69         return e;
70 }