]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/arena.c
- added sampling rate/channels to sound menu (changing the sampling rate requires...
[divverent/nexuiz.git] / data / qcsrc / server / gamec / arena.c
1 float maxspawned;
2 float numspawned;
3 float arena_roundbased;
4 .float spawned;
5 .entity spawnqueue_next;
6 .entity spawnqueue_prev;
7 .float spawnqueue_in;
8 entity spawnqueue_first;
9 entity spawnqueue_last;
10 entity champion;
11 .float arena_warmup_end;
12
13 void PutObserverInServer();
14 void PutClientInServer();
15 void(entity e) DropFlag;
16 void(entity e) ReturnFlag;
17 void(entity e) removedecor;
18
19 void reset_map()
20 {
21         float warmup;
22         
23         self = nextent(world);
24
25         warmup = cvar("g_arena_warmup");
26
27         while(self)
28         {
29                 if(self.classname == "droppedweapon"            // cleanup
30                                 || self.classname == "gib"
31                                 || self.classname == "body")
32                 {
33                         remove(self);
34                 }
35                 else if(self.flags & FL_ITEM)                   // reset items
36                 {
37                         self.model = self.mdl;
38                         self.solid = SOLID_TRIGGER;
39                         setorigin (self, self.origin);
40                         self.think = SUB_Null;
41                         self.nextthink = 0;
42                         self.effects = self.effects - (self.effects & EF_STARDUST);
43                 }
44                 else if(self.flags & FL_PROJECTILE)             // remove any projectiles left
45                 {
46                         sound(self, CHAN_BODY, "misc/null.wav", 1, ATTN_NORM);
47                         remove(self);
48                 }
49                 else if(self.isdecor)
50                 {
51                         removedecor(self);                      
52                 }
53                 else if(self.flags & FL_CLIENT)                 // reset all players
54                 {
55                         if(self.spawned)
56                         {
57                                 if(warmup)
58                                         self.arena_warmup_end = time + warmup;
59                                 PutClientInServer();
60                         }
61                         else if(self.deadflag)
62                                 PutClientInServer();
63
64                         if(self.exteriorweaponentity)
65                                 setmodel(self.exteriorweaponentity, "");
66                         if(self.weaponentity)
67                                 setmodel(self.weaponentity, "");
68                 }
69                 self = nextent(self);
70         }
71
72         if(champion)
73                 champion.frags += 1;
74 }
75
76 void Spawnqueue_Insert(entity e)
77 {
78         if(e.spawnqueue_in)
79                 return;
80         dprint(strcat("Into queue: ", e.netname, "\n"));
81         e.spawnqueue_in = TRUE;
82         e.spawnqueue_prev = spawnqueue_last;
83         e.spawnqueue_next = world;
84         if(spawnqueue_last)
85                 spawnqueue_last.spawnqueue_next = e;
86         spawnqueue_last = e;
87         if(!spawnqueue_first)
88                 spawnqueue_first = e;
89 }
90
91 void Spawnqueue_Remove(entity e)
92 {
93         if(!e.spawnqueue_in)
94                 return;
95         dprint(strcat("Out of queue: ", e.netname, "\n"));
96         e.spawnqueue_in = FALSE;
97         if(e == spawnqueue_first)
98                 spawnqueue_first = e.spawnqueue_next;
99         if(e == spawnqueue_last)
100                 spawnqueue_last = e.spawnqueue_prev;
101         if(e.spawnqueue_prev)
102                 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
103         if(e.spawnqueue_next)
104                 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
105         e.spawnqueue_next = world;
106         e.spawnqueue_prev = world;
107 }
108
109 void Spawnqueue_Unmark(entity e)
110 {
111         if(!e.spawned)
112                 return;
113         e.spawned = FALSE;
114         numspawned = numspawned - 1;
115 }
116
117 void Spawnqueue_Mark(entity e)
118 {
119         if(e.spawned)
120                 return;
121         e.spawned = TRUE;
122         numspawned = numspawned + 1;
123 }
124
125 void Arena_Warmup()
126 {
127         string msg;
128
129         if(!arena_roundbased)
130                 return;
131
132         msg = newlines;
133         if(time < self.arena_warmup_end)
134         {
135                 float f;
136                 f = rint(self.arena_warmup_end - time);
137                 
138                 if(champion)
139                         msg = strcat(msg, "The Champion is ", champion.netname, "^7\n\n\n");
140                 
141                 if(f)
142                         msg = strcat(msg, "Round will start in ", ftos(rint(self.arena_warmup_end - time)));
143                 else
144                 {
145                         if(self.spawned)
146                                 msg = strcat(msg, "^1Fight!");
147                 }
148
149                 centerprint(self, msg);
150                 
151                 if(self.spawned)
152                         self.movetype = MOVETYPE_NONE;
153         }
154         else if(self.movetype == MOVETYPE_NONE)
155         {
156                 self.movetype = MOVETYPE_WALK;
157                 centerprint(self, "\n");
158         }
159         
160 }
161
162 float next_round;
163 void Spawnqueue_Check()
164 {
165         if(!next_round)
166         if(numspawned < 2)
167                 next_round = time + 3;
168
169         if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
170         {
171                 next_round = 0;
172
173                 if(arena_roundbased)
174                 {
175                         champion = find(world, classname, "player");
176                         while(champion && champion.deadflag)
177                                 champion = find(champion, classname, "player");
178                 }
179                 
180                 while(numspawned < maxspawned && spawnqueue_first)
181                 {
182                         self = spawnqueue_first;
183
184                         bprint (strcat("^4", self.netname, "^4 is the next challenger\n"));
185
186                         Spawnqueue_Remove(self);
187                         Spawnqueue_Mark(self);
188                 
189                         self.classname = "player";
190                         PutClientInServer();
191                 }
192                 if(arena_roundbased)
193                         reset_map();
194         }
195 }