]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/cl_impulse.qc
Merge branch 'master' into terencehill/slider_anim_improvements
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_impulse.qc
1 #include "_all.qh"
2 #include "round_handler.qh"
3
4 #include "bot/waypoints.qh"
5
6 #include "weapons/throwing.qh"
7 #include "command/common.qh"
8 #include "cheats.qh"
9 #include "bot/navigation.qh"
10 #include "weapons/selection.qh"
11 #include "weapons/tracing.qh"
12 #include "weapons/weaponsystem.qh"
13 #include "waypointsprites.qh"
14
15 #include "../common/minigames/sv_minigames.qh"
16
17 #include "../common/weapons/all.qh"
18
19 /*
20  * Impulse map:
21  *
22  * 0 reserved (no input)
23  * 1 to 9, 14: weapon shortcuts
24  * 10: next weapon according to linear list
25  * 11: most recently used weapon
26  * 12: previous weapon according to linear list
27  * 13: best weapon according to priority list
28  * 15: next weapon according to priority list
29  * 16: previous weapon according to priority list
30  * 17: throw weapon
31  * 18: next weapon according to sbar_hudselector 1 list
32  * 19: previous weapon according to sbar_hudselector 1 list
33  * 20: reload if needed
34  *
35  * 30 to 39: create waypoints
36  * 47: clear personal waypoints
37  * 48: clear team waypoints
38  *
39  * 99: loaded
40  *
41  * 140: moving clone
42  * 141: ctf speedrun
43  * 142: fixed clone
44  * 143: emergency teleport
45  * 148: unfairly eliminate
46  *
47  * TODO:
48  * 200 to 209: prev weapon shortcuts
49  * 210 to 219: best weapon shortcuts
50  * 220 to 229: next weapon shortcuts
51  * 230 to 253: individual weapons (up to 24)
52  */
53
54 void ImpulseCommands (void)
55 {
56         int imp;
57         vector org;
58         float i;
59         float m;
60         entity e, e2;
61
62         imp = self.impulse;
63         if (!imp || gameover)
64                 return;
65         self.impulse = 0;
66
67         if ( self.active_minigame )
68         if ( MinigameImpulse(imp) )
69                 return;
70
71         // allow only weapon change impulses when not in round time
72         if(round_handler_IsActive() && !round_handler_IsRoundStarted())
73         if(imp == 17 || (imp >= 20 && imp < 200) || imp > 253)
74                 return;
75
76         if (timeout_status == TIMEOUT_ACTIVE) //don't allow any impulses while the game is paused
77                 return;
78
79         if(self.vehicle)
80         if(self.vehicle.deadflag == DEAD_NO)
81         {
82                 if(self.vehicle.vehicles_impulse)
83                 if(self.vehicle.vehicles_impulse(imp))
84                         return;
85                 if(vehicle_impulse(imp))
86                         return;
87         }
88
89         if(CheatImpulse(imp))
90         {
91         }
92         else if (imp >= 1 && imp <= 9)
93         {
94                 // weapon switching impulses
95                 if(self.deadflag == DEAD_NO)
96                         W_NextWeaponOnImpulse(imp);
97                 //else
98                 //      self.impulse = imp; // retry in next frame
99         }
100         else if(imp >= 10 && imp <= 20)
101         {
102                 if(!self.vehicle)
103                 if(self.deadflag == DEAD_NO)
104                 {
105                         switch(imp)
106                         {
107                                 case 10:
108                                         W_NextWeapon(0);
109                                         break;
110                                 case 11:
111                                         W_LastWeapon();
112                                         break;
113                                 case 12:
114                                         W_PreviousWeapon(0);
115                                         break;
116                                 case 13:
117                                         W_SwitchWeapon(w_getbestweapon(self));
118                                         break;
119                                 case 14:
120                                         W_NextWeaponOnImpulse(0);
121                                         break;
122                                 case 15:
123                                         W_NextWeapon(2);
124                                         break;
125                                 case 16:
126                                         W_PreviousWeapon(2);
127                                         break;
128                                 case 17:
129                                         W_ThrowWeapon(W_CalculateProjectileVelocity(self.velocity, v_forward * 750, false), '0 0 0', true);
130                                         break;
131                                 case 18:
132                                         W_NextWeapon(1);
133                                         break;
134                                 case 19:
135                                         W_PreviousWeapon(1);
136                                         break;
137                                 case 20:
138                                         if(!forbidWeaponUse(self)) { WEP_ACTION(self.weapon, WR_RELOAD); }
139                                         break;
140                         }
141                 }
142                 else
143                         self.impulse = imp; // retry in next frame
144         }
145         else if(imp == 21)
146         {
147                 PlayerUseKey ();
148         }
149         else if(imp >= 200 && imp <= 229)
150         {
151                 if(!self.vehicle)
152                 if(self.deadflag == DEAD_NO)
153                 {
154                         // custom order weapon cycling
155                         int i = imp % 10;
156                         m = (imp - (210 + i)); // <0 for prev, =0 for best, >0 for next
157                         W_CycleWeapon(self.(cvar_cl_weaponpriorities[i]), m);
158                 }
159                 else
160                         self.impulse = imp; // retry in next frame
161         }
162         else if(imp >= 230 && imp <= 253)
163         {
164                 if(!self.vehicle)
165                 if(self.deadflag == DEAD_NO)
166                         W_SwitchWeapon (imp - 230 + WEP_FIRST);
167                 else
168                         self.impulse = imp; // retry in next frame
169         }
170         // deploy waypoints
171         else if (imp >= 30 && imp <= 49)
172         {
173                 entity wp;
174                 switch(imp)
175                 {
176                         case 30:
177                                 wp = WaypointSprite_DeployPersonal("waypoint", self.origin, RADARICON_WAYPOINT, '0 1 1');
178                                 if(wp)
179                                         WaypointSprite_Ping(wp);
180                                 sprint(self, "personal waypoint spawned at location\n");
181                                 break;
182                         case 31:
183                                 WarpZone_crosshair_trace(self);
184                                 wp = WaypointSprite_DeployPersonal("waypoint", trace_endpos, RADARICON_WAYPOINT, '0 1 1');
185                                 if(wp)
186                                         WaypointSprite_Ping(wp);
187                                 sprint(self, "personal waypoint spawned at crosshair\n");
188                                 break;
189                         case 32:
190                                 if(vlen(self.death_origin))
191                                 {
192                                         wp = WaypointSprite_DeployPersonal("waypoint", self.death_origin, RADARICON_WAYPOINT, '0 1 1');
193                                         if(wp)
194                                                 WaypointSprite_Ping(wp);
195                                         sprint(self, "personal waypoint spawned at death location\n");
196                                 }
197                                 break;
198                         case 33:
199                                 if(self.deadflag == DEAD_NO && teamplay)
200                                 {
201                                         if (!MUTATOR_CALLHOOK(HelpMePing, self))
202                                         {
203                                                 wp = WaypointSprite_Attach("helpme", true, RADARICON_HELPME, '1 0.5 0');
204                                                 if(!wp)
205                                                         WaypointSprite_HelpMePing(self.waypointsprite_attachedforcarrier);
206                                                 else
207                                                         WaypointSprite_Ping(wp);
208                                         }
209                                         sprint(self, "HELP ME attached\n");
210                                 }
211                                 break;
212                         case 34:
213                                 wp = WaypointSprite_DeployFixed("here", false, self.origin, RADARICON_HERE, '0 1 0');
214                                 if(wp)
215                                         WaypointSprite_Ping(wp);
216                                 sprint(self, "HERE spawned at location\n");
217                                 break;
218                         case 35:
219                                 WarpZone_crosshair_trace(self);
220                                 wp = WaypointSprite_DeployFixed("here", false, trace_endpos, RADARICON_HERE, '0 1 0');
221                                 if(wp)
222                                         WaypointSprite_Ping(wp);
223                                 sprint(self, "HERE spawned at crosshair\n");
224                                 break;
225                         case 36:
226                                 if(vlen(self.death_origin))
227                                 {
228                                         wp = WaypointSprite_DeployFixed("here", false, self.death_origin, RADARICON_HERE, '0 1 0');
229                                         if(wp)
230                                                 WaypointSprite_Ping(wp);
231                                         sprint(self, "HERE spawned at death location\n");
232                                 }
233                                 break;
234                         case 37:
235                                 wp = WaypointSprite_DeployFixed("danger", false, self.origin, RADARICON_DANGER, '1 0.5 0');
236                                 if(wp)
237                                         WaypointSprite_Ping(wp);
238                                 sprint(self, "DANGER spawned at location\n");
239                                 break;
240                         case 38:
241                                 WarpZone_crosshair_trace(self);
242                                 wp = WaypointSprite_DeployFixed("danger", false, trace_endpos, RADARICON_DANGER, '1 0.5 0');
243                                 if(wp)
244                                         WaypointSprite_Ping(wp);
245                                 sprint(self, "DANGER spawned at crosshair\n");
246                                 break;
247                         case 39:
248                                 if(vlen(self.death_origin))
249                                 {
250                                         wp = WaypointSprite_DeployFixed("danger", false, self.death_origin, RADARICON_DANGER, '1 0.5 0');
251                                         if(wp)
252                                                 WaypointSprite_Ping(wp);
253                                         sprint(self, "DANGER spawned at death location\n");
254                                 }
255                                 break;
256                         case 47:
257                                 WaypointSprite_ClearPersonal();
258                                 if(self.personal)
259                                 {
260                                         remove(self.personal);
261                                         self.personal = world;
262                                 }
263                                 sprint(self, "personal waypoint cleared\n");
264                                 break;
265                         case 48:
266                                 WaypointSprite_ClearOwned();
267                                 if(self.personal)
268                                 {
269                                         remove(self.personal);
270                                         self.personal = world;
271                                 }
272                                 sprint(self, "all waypoints cleared\n");
273                                 break;
274                 }
275         }
276         else if(imp >= 103 && imp <= 107)
277         {
278                 if(autocvar_g_waypointeditor)
279                 {
280                         switch(imp)
281                         {
282                                 case 103:
283                                         waypoint_schedulerelink(waypoint_spawn(self.origin, self.origin, 0));
284                                         bprint(strcat("Waypoint spawned at ",vtos(self.origin),"\n"));
285                                         break;
286                                 case 104:
287                                         e = navigation_findnearestwaypoint(self, false);
288                                         if (e)
289                                         if (!(e.wpflags & WAYPOINTFLAG_GENERATED))
290                                         {
291                                                 bprint(strcat("Waypoint removed at ",vtos(e.origin),"\n"));
292                                                 waypoint_remove(e);
293                                         }
294                                         break;
295                                 case 105:
296                                         waypoint_schedulerelinkall();
297                                         break;
298                                 case 106:
299                                         waypoint_saveall();
300                                         break;
301                                 case 107:
302                                         for(e = findchain(classname, "waypoint"); e; e = e.chain)
303                                         {
304                                                 e.colormod = '0.5 0.5 0.5';
305                                                 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
306                                         }
307                                         e2 = navigation_findnearestwaypoint(self, false);
308                                         navigation_markroutes(e2);
309                                         i = 0;
310                                         m = 0;
311                                         for(e = findchain(classname, "waypoint"); e; e = e.chain)
312                                         {
313                                                 if(e.wpcost >= 10000000)
314                                                 {
315                                                         print("unreachable: ", etos(e), " ", vtos(e.origin), "\n");
316                                                         e.colormod_z = 8;
317                                                         e.effects |= EF_NODEPTHTEST | EF_BLUE;
318                                                         ++i;
319                                                         ++m;
320                                                 }
321                                         }
322                                         if(i)
323                                                 print(ftos(i), " waypoints cannot be reached from here in any way (marked with blue light)\n");
324                                         navigation_markroutes_inverted(e2);
325                                         i = 0;
326                                         for(e = findchain(classname, "waypoint"); e; e = e.chain)
327                                         {
328                                                 if(e.wpcost >= 10000000)
329                                                 {
330                                                         print("cannot reach me: ", etos(e), " ", vtos(e.origin), "\n");
331                                                         e.colormod_x = 8;
332                                                         if(!(e.effects & EF_NODEPTHTEST)) // not already reported before
333                                                                 ++m;
334                                                         e.effects |= EF_NODEPTHTEST | EF_RED;
335                                                         ++i;
336                                                 }
337                                         }
338                                         if(i)
339                                                 print(ftos(i), " waypoints cannot walk to here in any way (marked with red light)\n");
340                                         if(m)
341                                                 print(ftos(m), " waypoints have been marked total\n");
342                                         i = 0;
343                                         for(e = findchain(classname, "info_player_deathmatch"); e; e = e.chain)
344                                         {
345                                                 org = e.origin;
346                                                 tracebox(e.origin, PL_MIN, PL_MAX, e.origin - '0 0 512', MOVE_NOMONSTERS, world);
347                                                 setorigin(e, trace_endpos);
348                                                 if(navigation_findnearestwaypoint(e, false))
349                                                 {
350                                                         setorigin(e, org);
351                                                         e.effects &= ~EF_NODEPTHTEST;
352                                                         e.model = "";
353                                                 }
354                                                 else
355                                                 {
356                                                         setorigin(e, org);
357                                                         print("spawn without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
358                                                         e.effects |= EF_NODEPTHTEST;
359                                                         setmodel(e, self.model);
360                                                         e.frame = self.frame;
361                                                         e.skin = self.skin;
362                                                         e.colormod = '8 0.5 8';
363                                                         setsize(e, '0 0 0', '0 0 0');
364                                                         ++i;
365                                                 }
366                                         }
367                                         if(i)
368                                                 print(ftos(i), " spawnpoints have no nearest waypoint (marked by player model)\n");
369                                         i = 0;
370                                         entity start;
371                                         start = findchainflags(flags, FL_ITEM);
372                                         for(e = start; e; e = e.chain)
373                                         {
374                                                 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
375                                                 e.colormod = '0.5 0.5 0.5';
376                                         }
377                                         for(e = start; e; e = e.chain)
378                                         {
379                                                 if(navigation_findnearestwaypoint(e, false))
380                                                 {
381                                                 }
382                                                 else
383                                                 {
384                                                         print("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
385                                                         e.effects |= EF_NODEPTHTEST | EF_RED;
386                                                         e.colormod_x = 8;
387                                                         ++i;
388                                                 }
389                                         }
390                                         if(i)
391                                                 print(ftos(i), " items have no nearest waypoint and cannot be walked away from (marked with red light)\n");
392                                         i = 0;
393                                         for(e = start; e; e = e.chain)
394                                         {
395                                                 org = e.origin;
396                                                 if(navigation_findnearestwaypoint(e, true))
397                                                 {
398                                                 }
399                                                 else
400                                                 {
401                                                         print("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
402                                                         e.effects |= EF_NODEPTHTEST | EF_BLUE;
403                                                         e.colormod_z = 8;
404                                                         ++i;
405                                                 }
406                                         }
407                                         if(i)
408                                                 print(ftos(i), " items have no nearest waypoint and cannot be walked to (marked with blue light)\n");
409                                         break;
410                         }
411                 }
412         }
413 }