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