]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/monsters/lib/spawn.qc
Improve monster team colors
[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(IS_CLIENT(spawnedby))
16                         Send_Notification(NOTIF_ONE, spawnedby, MSG_INFO, INFO_MONSTERS_DISABLED);
17                         
18                 return world;
19         }
20         
21         if(spawnedby.vehicle) // no vehicle player spawning...
22                 return world;
23         
24         if(!spawncode_first_load)
25         {
26                 initialize_field_db();
27                 spawncode_first_load = TRUE;
28         }
29         
30         entity e = spawn();
31         
32         e.spawnflags = MONSTERFLAG_SPAWNED;
33         
34         if not(respwn)
35                 e.spawnflags |= MONSTERFLAG_NORESPAWN;
36         
37         setorigin(e, orig);
38         
39         if not(spawnmonster_checkinlist(monster, autocvar_g_monsters_spawn_list))
40                 monster = "knight";
41         
42         e.realowner = spawnedby;
43         
44         if(moveflag)
45                 e.monster_moveflags = moveflag;
46         
47         if (spawnedby.classname == "monster_swarm")
48                 e.monster_owner = own;  
49         else if(IS_CLIENT(spawnedby))
50         {
51                 if(teamplay && autocvar_g_monsters_teams)
52                         e.team = spawnedby.team; // colors handled in spawn code
53                         
54                 if(teamplay)
55                         e.colormap = 1024;
56                 else
57                         e.colormap = spawnedby.colormap;
58                         
59                 if(autocvar_g_monsters_owners)
60                         e.monster_owner = own; // using owner makes the monster non-solid for its master
61                         
62                 e.angles = spawnedby.angles;
63         }
64         
65         if(autocvar_g_monsters_giants_only)
66                 e.spawnflags |= MONSTERFLAG_GIANT;
67                 
68         monster = strcat("$ spawnfunc_monster_", monster);
69                 
70         target_spawn_edit_entity(e, monster, world, world, world, world, world);
71                 
72         return e;
73 }