]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/assault.qc
same for stopsound()
[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         local 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         if(assault_attacker_team == COLOR_TEAM1) {
211                 self.team = COLOR_TEAM2;
212         } else {
213                 self.team = COLOR_TEAM1;
214         }
215         spawnfunc_func_breakable();
216 }
217
218 void assault_wall_think() {
219         if(self.enemy.health < 0) {
220                 self.model = "";
221                 self.solid = SOLID_NOT;
222         } else {
223                 self.model = self.mdl;
224                 self.solid = SOLID_BSP;
225         }
226
227         self.nextthink = time + 0.2;
228 }
229
230 void spawnfunc_func_assault_wall() {
231         if(!g_assault)
232         {
233                 remove(self);
234                 return;
235         }
236         self.classname = "func_assault_wall";
237         self.mdl = self.model;
238         setmodel(self, self.mdl);
239         self.solid = SOLID_BSP;
240         self.think = assault_wall_think;
241         self.nextthink = time;
242         InitializeEntity(self, assault_setenemytoobjective, INITPRIO_FINDTARGET);
243 }
244
245
246 void target_assault_roundend_reset() {
247         //print("round end reset\n");
248         self.cnt = self.cnt + 1; // up round counter
249         self.winning = 0; // up round
250 }
251
252 void target_assault_roundend_use() {
253         self.winning = 1; // round has been won by attackers
254 }
255
256 void spawnfunc_target_assault_roundend() {
257         if(!g_assault)
258         {
259                 remove(self);
260                 return;
261         }
262         self.winning = 0; // round not yet won by attackers
263         self.classname = "target_assault_roundend";
264         self.use = target_assault_roundend_use;
265         self.cnt = 0; // first round
266         self.reset = target_assault_roundend_reset;
267 }
268
269 void assault_roundstart_use() {
270
271         activator = self;
272         SUB_UseTargets();
273
274         
275 #ifdef TTURRETS_ENABLED
276         entity ent, oldself;
277
278         //(Re)spawn all turrets
279         oldself = self;
280         ent = find(world, classname, "turret_main");
281         while(ent) {
282                 // Swap turret teams
283                 if(ent.team == COLOR_TEAM1)
284                         ent.team = COLOR_TEAM2;
285                 else
286                         ent.team = COLOR_TEAM1;
287
288                 self = ent;
289
290                 // Dubbles as teamchange
291                 turret_stdproc_respawn();
292
293                 ent = find(ent, classname, "turret_main");
294         }
295         self = oldself;
296 #endif
297
298
299 }
300
301 void spawnfunc_target_assault_roundstart() {
302         if(!g_assault)
303         {
304                 remove(self);
305                 return;
306         }
307         assault_attacker_team = COLOR_TEAM1;
308         self.classname = "target_assault_roundstart";
309         self.use = assault_roundstart_use;
310         self.reset2 = assault_roundstart_use;
311         InitializeEntity(self, assault_roundstart_use, INITPRIO_FINDTARGET);
312 }
313
314 // trigger new round
315 // reset objectives, toggle spawnpoints, reset triggers, ...
316 void assault_new_round() {
317         //bprint("ASSAULT: new round\n");
318
319         // up round counter
320         self.winning = self.winning + 1;
321
322         // swap attacker/defender roles
323         if(assault_attacker_team == COLOR_TEAM1) {
324                 assault_attacker_team = COLOR_TEAM2;
325         } else {
326                 assault_attacker_team = COLOR_TEAM1;
327         }
328
329
330         local entity ent;
331         for(ent = world; (ent = nextent(ent)); )
332         {
333                 if(clienttype(ent) == CLIENTTYPE_NOTACLIENT)
334                 {
335                         if(ent.team_saved == COLOR_TEAM1)
336                                 ent.team_saved = COLOR_TEAM2;
337                         else if(ent.team_saved == COLOR_TEAM2)
338                                 ent.team_saved = COLOR_TEAM1;
339                 }
340         }
341
342         // reset the level with a countdown
343         cvar_set("timelimit", ftos(ceil(time - game_starttime) / 60));
344         ReadyRestartForce(); // sets game_starttime
345 }