]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/arena.qc
removing this makefile also
[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 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                 self = nextent(self);
65         }
66
67         if(champion)
68                 champion.frags += 1;
69 }
70
71 void Spawnqueue_Insert(entity e)
72 {
73         if(e.spawnqueue_in)
74                 return;
75         dprint(strcat("Into queue: ", e.netname, "\n"));
76         e.spawnqueue_in = TRUE;
77         e.spawnqueue_prev = spawnqueue_last;
78         e.spawnqueue_next = world;
79         if(spawnqueue_last)
80                 spawnqueue_last.spawnqueue_next = e;
81         spawnqueue_last = e;
82         if(!spawnqueue_first)
83                 spawnqueue_first = e;
84 }
85
86 void Spawnqueue_Remove(entity e)
87 {
88         if(!e.spawnqueue_in)
89                 return;
90         dprint(strcat("Out of queue: ", e.netname, "\n"));
91         e.spawnqueue_in = FALSE;
92         if(e == spawnqueue_first)
93                 spawnqueue_first = e.spawnqueue_next;
94         if(e == spawnqueue_last)
95                 spawnqueue_last = e.spawnqueue_prev;
96         if(e.spawnqueue_prev)
97                 e.spawnqueue_prev.spawnqueue_next = e.spawnqueue_next;
98         if(e.spawnqueue_next)
99                 e.spawnqueue_next.spawnqueue_prev = e.spawnqueue_prev;
100         e.spawnqueue_next = world;
101         e.spawnqueue_prev = world;
102 }
103
104 void Spawnqueue_Unmark(entity e)
105 {
106         if(!e.spawned)
107                 return;
108         e.spawned = FALSE;
109         numspawned = numspawned - 1;
110 }
111
112 void Spawnqueue_Mark(entity e)
113 {
114         if(e.spawned)
115                 return;
116         e.spawned = TRUE;
117         numspawned = numspawned + 1;
118 }
119
120 void Arena_Warmup()
121 {
122         string msg;
123
124         if(!arena_roundbased)
125                 return;
126
127         msg = newlines;
128         if(time < self.arena_warmup_end)
129         {
130                 float f;
131                 f = rint(self.arena_warmup_end - time);
132
133                 if(champion)
134                         msg = strcat(msg, "The Champion is ", champion.netname, "^7\n\n\n");
135
136                 if(f)
137                         msg = strcat(msg, "Round will start in ", ftos(rint(self.arena_warmup_end - time)));
138                 else
139                 {
140                         if(self.spawned)
141                                 msg = strcat(msg, "^1Fight!");
142                 }
143
144                 centerprint(self, msg);
145
146                 if(self.spawned)
147                         self.movetype = MOVETYPE_NONE;
148         }
149         else if(self.movetype == MOVETYPE_NONE)
150         {
151                 self.movetype = MOVETYPE_WALK;
152                 centerprint(self, "\n");
153         }
154
155 }
156
157 float next_round;
158 void Spawnqueue_Check()
159 {
160         if(!next_round)
161         if(numspawned < 2)
162                 next_round = time + 3;
163
164         if(!arena_roundbased || (next_round && next_round < time && player_count > 1))
165         {
166                 next_round = 0;
167
168                 if(arena_roundbased)
169                 {
170                         champion = find(world, classname, "player");
171                         while(champion && champion.deadflag)
172                                 champion = find(champion, classname, "player");
173                 }
174
175                 while(numspawned < maxspawned && spawnqueue_first)
176                 {
177                         self = spawnqueue_first;
178
179                         bprint (strcat("^4", self.netname, "^4 is the next challenger\n"));
180
181                         Spawnqueue_Remove(self);
182                         Spawnqueue_Mark(self);
183
184                         self.classname = "player";
185                         PutClientInServer();
186                 }
187                 if(arena_roundbased)
188                         reset_map();
189         }
190 }