]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/assault.qc
More documentation and some minor changes for drag code
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / assault.qc
1 void spawnfunc_func_breakable();
2 void target_objective_decrease_activate();
3 .entity assault_decreaser;
4 .entity assault_sprite;
5
6 void spawnfunc_info_player_attacker() {
7         if(!g_assault)
8         {
9                 remove(self);
10                 return;
11         }
12         self.team = COLOR_TEAM1; // red, gets swapped every round
13         spawnfunc_info_player_deathmatch();
14 }
15
16 void spawnfunc_info_player_defender() {
17         if(!g_assault)
18         {
19                 remove(self);
20                 return;
21         }
22         self.team = COLOR_TEAM2; // blue, gets swapped every round
23         spawnfunc_info_player_deathmatch();
24 }
25
26 // reset this objective. Used when spawning an objective
27 // and when a new round starts
28 void assault_objective_reset() {
29         self.health = ASSAULT_VALUE_INACTIVE;
30 }
31
32 void assault_objective_use() {
33         // activate objective
34         self.health = 100;
35         //print("^2Activated objective ", self.targetname, "=", etos(self), "\n");
36         //print("Activator is ", activator.classname, "\n");
37
38         entity oldself;
39         oldself = self;
40
41         for(self = world; (self = find(self, target, oldself.targetname)); )
42         {
43                 if(self.classname == "target_objective_decrease")
44                         target_objective_decrease_activate();
45         }
46
47         self = oldself;
48 }
49
50 void spawnfunc_target_objective() {
51         if(!g_assault)
52         {
53                 remove(self);
54                 return;
55         }
56         self.classname = "target_objective";
57         self.use = assault_objective_use;
58         assault_objective_reset();
59         self.reset = assault_objective_reset;
60 }
61
62
63 // decrease the health of targeted objectives
64 void assault_objective_decrease_use() {
65         if(activator.team != assault_attacker_team) {
66                 // wrong team triggered decrease
67                 return;
68         }
69
70         if(other.assault_sprite)
71         {
72                 WaypointSprite_Disown(other.assault_sprite, waypointsprite_deadlifetime);
73                 if(other.classname == "func_assault_destructible")
74                         other.sprite = world;
75         }
76         else
77                 return; // already activated! cannot activate again!
78
79         if(self.enemy.health < ASSAULT_VALUE_INACTIVE)
80         {
81                 if(self.enemy.health - self.dmg > 0.5)
82                 {
83                         PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.dmg);
84                         self.enemy.health = self.enemy.health - self.dmg;
85                 }
86                 else
87                 {
88                         PlayerTeamScore_Add(activator, SP_SCORE, ST_SCORE, self.enemy.health);
89                         PlayerTeamScore_Add(activator, SP_ASSAULT_OBJECTIVES, ST_ASSAULT_OBJECTIVES, 1);
90                         self.enemy.health = -1;
91
92                         entity oldself, oldactivator;
93
94                         oldself = self;
95                         self = oldself.enemy;
96                                 if(self.message)
97                                 {
98                                         entity player;
99                                         string s;
100                                         FOR_EACH_PLAYER(player)
101                                         {
102                                                 s = strcat(self.message, "\n");
103                                                 centerprint(player, s);
104                                         }
105                                 }
106
107                                 oldactivator = activator;
108                                 activator = oldself;
109                                         SUB_UseTargets();
110                                 activator = oldactivator;
111                         self = oldself;
112                 }
113         }
114 }
115
116 void assault_setenemytoobjective()
117 {
118         entity objective;
119         for(objective = world; (objective = find(objective, targetname, self.target)); ) {
120                 if(objective.classname == "target_objective") {
121                         if(self.enemy == world)
122                                 self.enemy = objective;
123                         else
124                                 objerror("more than one objective as target - fix the map!");
125                         break;
126                 }
127         }
128
129         if(self.enemy == world)
130                 objerror("no objective as target - fix the map!");
131 }
132
133 float assault_decreaser_sprite_visible(entity e)
134 {
135         entity decreaser;
136
137         decreaser = self.assault_decreaser;
138
139         if(decreaser.enemy.health >= ASSAULT_VALUE_INACTIVE)
140                 return FALSE;
141
142         return TRUE;
143 }
144
145 void target_objective_decrease_activate()
146 {
147         entity ent, spr;
148         self.owner = world;
149         for(ent = world; (ent = find(ent, target, self.targetname)); )
150         {
151                 if(ent.assault_sprite != world)
152                 {
153                         WaypointSprite_Disown(ent.assault_sprite, waypointsprite_deadlifetime);
154                         if(ent.classname == "func_assault_destructible")
155                                 ent.sprite = world;
156                 }
157
158                 spr = WaypointSprite_SpawnFixed("<placeholder>", 0.5 * (ent.absmin + ent.absmax), ent, assault_sprite, RADARICON_OBJECTIVE, '1 0.5 0');
159                 spr.assault_decreaser = self;
160                 spr.waypointsprite_visible_for_player = assault_decreaser_sprite_visible;
161                 spr.classname = "sprite_waypoint";
162                 WaypointSprite_UpdateRule(spr, assault_attacker_team, SPRITERULE_TEAMPLAY);
163                 if(ent.classname == "func_assault_destructible")
164                 {
165                         WaypointSprite_UpdateSprites(spr, "as-defend", "as-destroy", "as-destroy");
166                         WaypointSprite_UpdateMaxHealth(spr, ent.max_health);
167                         WaypointSprite_UpdateHealth(spr, ent.health);
168                         ent.sprite = spr;
169                 }
170                 else
171                         WaypointSprite_UpdateSprites(spr, "as-defend", "as-push", "as-push");
172         }
173 }
174
175 void target_objective_decrease_findtarget()
176 {
177         assault_setenemytoobjective();
178 }
179
180 //=============================================================================
181
182 void spawnfunc_target_objective_decrease() {
183         if(!g_assault)
184         {
185                 remove(self);
186                 return;
187         }
188
189         self.classname = "target_objective_decrease";
190
191         if(!self.dmg) {
192                 self.dmg = 101;
193         }
194         self.use = assault_objective_decrease_use;
195         self.health = ASSAULT_VALUE_INACTIVE;
196         self.max_health = ASSAULT_VALUE_INACTIVE;
197         self.enemy = world;
198
199         InitializeEntity(self, target_objective_decrease_findtarget, INITPRIO_FINDTARGET);
200 }
201
202 // destructible walls that can be used to trigger target_objective_decrease
203 void spawnfunc_func_assault_destructible() {
204         if(!g_assault)
205         {
206                 remove(self);
207                 return;
208         }
209         self.spawnflags = 3;
210         self.classname = "func_assault_destructible";
211         if(assault_attacker_team == COLOR_TEAM1) {
212                 self.team = COLOR_TEAM2;
213         } else {
214                 self.team = COLOR_TEAM1;
215         }
216         spawnfunc_func_breakable();
217 }
218
219 void assault_wall_think() {
220         if(self.enemy.health < 0) {
221                 self.model = "";
222                 self.solid = SOLID_NOT;
223         } else {
224                 self.model = self.mdl;
225                 self.solid = SOLID_BSP;
226         }
227
228         self.nextthink = time + 0.2;
229 }
230
231 void spawnfunc_func_assault_wall() {
232         if(!g_assault)
233         {
234                 remove(self);
235                 return;
236         }
237         self.classname = "func_assault_wall";
238         self.mdl = self.model;
239         setmodel(self, self.mdl);
240         self.solid = SOLID_BSP;
241         self.think = assault_wall_think;
242         self.nextthink = time;
243         InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
244 }
245
246
247 void target_assault_roundend_reset() {
248         //print("round end reset\n");
249         self.cnt = self.cnt + 1; // up round counter
250         self.winning = 0; // up round
251 }
252
253 void target_assault_roundend_use() {
254         self.winning = 1; // round has been won by attackers
255 }
256
257 void spawnfunc_target_assault_roundend() {
258         if(!g_assault)
259         {
260                 remove(self);
261                 return;
262         }
263         self.winning = 0; // round not yet won by attackers
264         self.classname = "target_assault_roundend";
265         self.use = target_assault_roundend_use;
266         self.cnt = 0; // first round
267         self.reset = target_assault_roundend_reset;
268 }
269
270 void assault_roundstart_use() {
271
272         activator = self;
273         SUB_UseTargets();
274
275
276 #ifdef TTURRETS_ENABLED
277         entity ent, oldself;
278
279         //(Re)spawn all turrets
280         oldself = self;
281         ent = find(world, classname, "turret_main");
282         while(ent) {
283                 // Swap turret teams
284                 if(ent.team == COLOR_TEAM1)
285                         ent.team = COLOR_TEAM2;
286                 else
287                         ent.team = COLOR_TEAM1;
288
289                 self = ent;
290
291                 // Dubbles as teamchange
292                 turret_stdproc_respawn();
293
294                 ent = find(ent, classname, "turret_main");
295         }
296         self = oldself;
297 #endif
298
299
300 }
301
302 void spawnfunc_target_assault_roundstart() {
303         if(!g_assault)
304         {
305                 remove(self);
306                 return;
307         }
308         assault_attacker_team = COLOR_TEAM1;
309         self.classname = "target_assault_roundstart";
310         self.use = assault_roundstart_use;
311         self.reset2 = assault_roundstart_use;
312         InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
313 }
314
315 // trigger new round
316 // reset objectives, toggle spawnpoints, reset triggers, ...
317 void vehicles_clearrturn();
318 void vehicles_spawn();
319 void assault_new_round()
320 {
321     entity oldself;
322         //bprint("ASSAULT: new round\n");
323
324         oldself = self;
325         // Eject players from vehicles
326     FOR_EACH_PLAYER(self)
327     {
328         if(self.vehicle)
329             vehicles_exit(VHEF_RELESE);
330     }
331
332     self = findchainflags(vehicle_flags, VHF_ISVEHICLE);
333     while(self)
334     {
335         vehicles_clearrturn();
336         vehicles_spawn();
337         self = self.chain;
338     }
339
340     self = oldself;
341
342         // up round counter
343         self.winning = self.winning + 1;
344
345         // swap attacker/defender roles
346         if(assault_attacker_team == COLOR_TEAM1) {
347                 assault_attacker_team = COLOR_TEAM2;
348         } else {
349                 assault_attacker_team = COLOR_TEAM1;
350         }
351
352
353         entity ent;
354         for(ent = world; (ent = nextent(ent)); )
355         {
356                 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
357                 {
358                         if(ent.team_saved == COLOR_TEAM1)
359                                 ent.team_saved = COLOR_TEAM2;
360                         else if(ent.team_saved == COLOR_TEAM2)
361                                 ent.team_saved = COLOR_TEAM1;
362                 }
363         }
364
365         // reset the level with a countdown
366         cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
367         ReadyRestartForce(); // sets game_starttime
368 }