]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/arena.qc
handle self/oself CORRECTLY this time
[divverent/nexuiz.git] / data / qcsrc / server / arena.qc
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 warmup;
12
13 void PutObserverInServer();
14 void PutClientInServer();
15 void(entity e) DropFlag;
16 void(entity e) ReturnFlag;
17 void(entity e) removedecor;
18 void dom_controlpoint_setup();
19
20 void reset_map()
21 {
22         if(g_arena)
23         if(cvar("g_arena_warmup"))
24                 warmup = time + cvar("g_arena_warmup");
25         
26         lms_lowest_lives = 999;
27         lms_next_place = player_count;
28
29         self = nextent(world);
30         while(self)
31         {
32                 if(self.flags & FL_CLIENT)                              // reset all players
33                 {
34                         if(time < restart_countdown)
35                         {
36                                 self.frags = (g_lms)?LMS_NewPlayerLives():0;
37                                 self.deaths = 0;
38                                 self.killcount = 0;
39                                 self.classname = "player";
40                                 PutClientInServer();
41                         }
42                         else if(g_arena)
43                         {
44                                 if(self.spawned)
45                                         PutClientInServer();
46                                 else
47                                         PutObserverInServer();
48                         }
49                 }
50                 else if(self.classname == STR_ITEM_KH_KEY)
51                 {
52                         kh_Key_AssignTo(self, world);
53                         //if(self.owner)
54                         //      kh_Key_DropAll(self.owner, TRUE);
55                         kh_Key_Remove(self);
56                 }
57                 else if(self.classname == "droppedweapon"               // cleanup
58                                 || self.classname == "gib"
59                                 || self.classname == "body")
60                 {
61                         remove(self);
62                 }
63                 else if(self.items & (IT_KEY1 | IT_KEY2))
64                 {
65                         DropFlag(self);
66                         ReturnFlag(self);
67                 }
68                 else if(self.classname == "rune")
69                 {
70                         if(self.owner)
71                         if(self.owner.classname != "runematch_spawn_point")
72                                 DropAllRunes(self.owner);
73                         rune_respawn();
74                 }
75                 else if(self.classname == "sprite_waypoint")
76                 {
77                         if(self.health | g_keyhunt)
78                                 WaypointSprite_Kill(self);
79                 }
80                 else if(self.classname == "dom_controlpoint")
81                 {
82                         dom_controlpoint_setup();
83                 }
84                 else if(self.classname == "info_player_deathmatch")
85                 {
86                         self.team = self.team_saved; // reset spawns to their original state too!
87                 }
88                 else if(self.flags & FL_ITEM)                   // reset items
89                 {
90                         self.model = self.mdl;
91                         self.solid = SOLID_TRIGGER;
92                         setorigin (self, self.origin);
93                         self.think = SUB_Null;
94                         self.nextthink = 0;
95                         self.effects = self.effects - (self.effects & EF_STARDUST);
96                 }
97                 else if(self.flags & FL_PROJECTILE)             // remove any projectiles left
98                 {
99                         sound(self, CHAN_BODY, "misc/null.wav", 1, ATTN_NORM);
100                         remove(self);
101                 }
102                 else if(self.isdecor)
103                 {
104                         removedecor(self);
105                 }
106                 // TODO properly reset Onslaught
107                 // TODO properly reset Assault
108                 self = nextent(self);
109         }
110
111         if(g_keyhunt)
112                 kh_Controller_SetThink(cvar("g_balance_keyhunt_delay_round")+RESTART_COUNTDOWN, "", kh_StartRound);
113
114         if(g_arena)
115         if(champion)
116                 UpdateFrags(champion, +1);
117 }
118
119 void Spawnqueue_Insert(entity e)
120 {
121         if(e.spawnqueue_in)
122                 return;
123         dprint(strcat("Into queue: ", e.netname, "\n"));
124         e.spawnqueue_in = TRUE;
125         e.spawnqueue_prev = spawnqueue_last;
126         e.spawnqueue_next = world;
127         if(spawnqueue_last)
128                 spawnqueue_last.spawnqueue_next = e;
129         spawnqueue_last = e;
130         if(!spawnqueue_first)
131                 spawnqueue_first = e;
132 }
133
134 void Spawnqueue_Remove(entity e)
135 {
136         if(!e.spawnqueue_in)
137                 return;
138         dprint(strcat("Out of queue: ", e.netname, "\n"));
139         e.spawnqueue_in = FALSE;
140         if(e == spawnqueue_first)
141                 spawnqueue_first = e.spawnqueue_next;
142         if(e == spawnqueue_last)
143                 spawnqueue_last = e.spawnqueue_prev;
144         if(e.spawnqueue_prev)
145                 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
146         if(e.spawnqueue_next)
147                 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
148         e.spawnqueue_next = world;
149         e.spawnqueue_prev = world;
150 }
151
152 void Spawnqueue_Unmark(entity e)
153 {
154         if(!e.spawned)
155                 return;
156         e.spawned = FALSE;
157         numspawned = numspawned - 1;
158 }
159
160 void Spawnqueue_Mark(entity e)
161 {
162         if(e.spawned)
163                 return;
164         e.spawned = TRUE;
165         numspawned = numspawned + 1;
166 }
167
168 void Arena_Warmup()
169 {
170         float f;
171         string msg;
172
173         if(!g_arena || !arena_roundbased || (time < restart_countdown))
174                 return;
175
176         f = rint(warmup - time);
177
178         msg = NEWLINES;
179         if(time < warmup && self.spawned)
180         {
181                 if(champion)
182                         msg = strcat(msg, "The Champion is ", champion.netname, "^7\n\n\n");
183
184                 if(f)
185                         msg = strcat(msg, "Round will start in ", ftos(f));
186                 else
187                 {
188                         if(self.spawned)
189                                 msg = strcat(msg, "^1Fight!");
190                 }
191
192                 centerprint(self, msg);
193
194                 if(self.spawned)
195                         self.movetype = MOVETYPE_NONE;
196
197                 self.velocity = '0 0 0';
198                 self.avelocity = '0 0 0';
199                 self.movement = '0 0 0';
200                 //self.fixangle = TRUE;
201         }
202         else if(self.movetype == MOVETYPE_NONE)
203         {
204                 self.movetype = MOVETYPE_WALK;
205                 centerprint(self, "\n");
206         }
207
208 }
209
210 float next_round;
211 void Spawnqueue_Check()
212 {
213         if(time < warmup + 1)
214                 return;
215
216         if(!next_round)
217         if(numspawned < 2)
218                 next_round = time + 3;
219
220         if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
221         {
222                 next_round = 0;
223
224                 if(arena_roundbased)
225                 {
226                         champion = find(world, classname, "player");
227                         while(champion && champion.deadflag)
228                                 champion = find(champion, classname, "player");
229                         reset_map();
230                 }
231
232                 while(numspawned < maxspawned && spawnqueue_first)
233                 {
234                         self = spawnqueue_first;
235
236                         bprint ("^4", self.netname, "^4 is the next challenger\n");
237
238                         Spawnqueue_Remove(self);
239                         Spawnqueue_Mark(self);
240
241                         self.classname = "player";
242                         PutClientInServer();
243                 }
244         }
245 }