]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/cl_impulse.qc
Weapons: fix impulses
[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 {SELFPARAM();
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)) {
138                                                 Weapon w = get_weaponinfo(self.weapon);
139                                                 w.wr_reload(w);
140                                         }
141                                         break;
142                         }
143                 }
144                 else
145                         self.impulse = imp; // retry in next frame
146         }
147         else if(imp == 21)
148         {
149                 PlayerUseKey ();
150         }
151         else if(imp >= 200 && imp <= 229)
152         {
153                 if(!self.vehicle)
154                 if(self.deadflag == DEAD_NO)
155                 {
156                         // custom order weapon cycling
157                         int i = imp % 10;
158                         m = (imp - (210 + i)); // <0 for prev, =0 for best, >0 for next
159                         W_CycleWeapon(self.(cvar_cl_weaponpriorities[i]), m);
160                 }
161                 else
162                         self.impulse = imp; // retry in next frame
163         }
164         else if(imp >= WEP_IMPULSE_BEGIN && imp <= WEP_IMPULSE_END)
165         {
166                 if(!self.vehicle)
167                 if(self.deadflag == DEAD_NO)
168                         W_SwitchWeapon (imp - WEP_IMPULSE_BEGIN + WEP_FIRST);
169                 else
170                         self.impulse = imp; // retry in next frame
171         }
172         // deploy waypoints
173         else if (imp >= 30 && imp <= 49)
174         {
175                 entity wp;
176                 switch(imp)
177                 {
178                         case 30:
179                                 wp = WaypointSprite_DeployPersonal(WP_Waypoint, self.origin, RADARICON_WAYPOINT);
180                                 if(wp)
181                                         WaypointSprite_Ping(wp);
182                                 sprint(self, "personal waypoint spawned at location\n");
183                                 break;
184                         case 31:
185                                 WarpZone_crosshair_trace(self);
186                                 wp = WaypointSprite_DeployPersonal(WP_Waypoint, trace_endpos, RADARICON_WAYPOINT);
187                                 if(wp)
188                                         WaypointSprite_Ping(wp);
189                                 sprint(self, "personal waypoint spawned at crosshair\n");
190                                 break;
191                         case 32:
192                                 if(vlen(self.death_origin))
193                                 {
194                                         wp = WaypointSprite_DeployPersonal(WP_Waypoint, self.death_origin, RADARICON_WAYPOINT);
195                                         if(wp)
196                                                 WaypointSprite_Ping(wp);
197                                         sprint(self, "personal waypoint spawned at death location\n");
198                                 }
199                                 break;
200                         case 33:
201                                 if(self.deadflag == DEAD_NO && teamplay)
202                                 {
203                                         if (!MUTATOR_CALLHOOK(HelpMePing, self))
204                                         {
205                                                 wp = WaypointSprite_Attach(WP_Helpme, true, RADARICON_HELPME);
206                                                 if(!wp)
207                                                         WaypointSprite_HelpMePing(self.waypointsprite_attachedforcarrier);
208                                                 else
209                                                         WaypointSprite_Ping(wp);
210                                         }
211                                         sprint(self, "HELP ME attached\n");
212                                 }
213                                 break;
214                         case 34:
215                                 wp = WaypointSprite_DeployFixed(WP_Here, false, self.origin, RADARICON_HERE);
216                                 if(wp)
217                                         WaypointSprite_Ping(wp);
218                                 sprint(self, "HERE spawned at location\n");
219                                 break;
220                         case 35:
221                                 WarpZone_crosshair_trace(self);
222                                 wp = WaypointSprite_DeployFixed(WP_Here, false, trace_endpos, RADARICON_HERE);
223                                 if(wp)
224                                         WaypointSprite_Ping(wp);
225                                 sprint(self, "HERE spawned at crosshair\n");
226                                 break;
227                         case 36:
228                                 if(vlen(self.death_origin))
229                                 {
230                                         wp = WaypointSprite_DeployFixed(WP_Here, false, self.death_origin, RADARICON_HERE);
231                                         if(wp)
232                                                 WaypointSprite_Ping(wp);
233                                         sprint(self, "HERE spawned at death location\n");
234                                 }
235                                 break;
236                         case 37:
237                                 wp = WaypointSprite_DeployFixed(WP_Danger, false, self.origin, RADARICON_DANGER);
238                                 if(wp)
239                                         WaypointSprite_Ping(wp);
240                                 sprint(self, "DANGER spawned at location\n");
241                                 break;
242                         case 38:
243                                 WarpZone_crosshair_trace(self);
244                                 wp = WaypointSprite_DeployFixed(WP_Danger, false, trace_endpos, RADARICON_DANGER);
245                                 if(wp)
246                                         WaypointSprite_Ping(wp);
247                                 sprint(self, "DANGER spawned at crosshair\n");
248                                 break;
249                         case 39:
250                                 if(vlen(self.death_origin))
251                                 {
252                                         wp = WaypointSprite_DeployFixed(WP_Danger, false, self.death_origin, RADARICON_DANGER);
253                                         if(wp)
254                                                 WaypointSprite_Ping(wp);
255                                         sprint(self, "DANGER spawned at death location\n");
256                                 }
257                                 break;
258                         case 47:
259                                 WaypointSprite_ClearPersonal();
260                                 if(self.personal)
261                                 {
262                                         remove(self.personal);
263                                         self.personal = world;
264                                 }
265                                 sprint(self, "personal waypoint cleared\n");
266                                 break;
267                         case 48:
268                                 WaypointSprite_ClearOwned();
269                                 if(self.personal)
270                                 {
271                                         remove(self.personal);
272                                         self.personal = world;
273                                 }
274                                 sprint(self, "all waypoints cleared\n");
275                                 break;
276                 }
277         }
278         else if(imp >= 103 && imp <= 107)
279         {
280                 if(autocvar_g_waypointeditor)
281                 {
282                         switch(imp)
283                         {
284                                 case 103:
285                                         waypoint_schedulerelink(waypoint_spawn(self.origin, self.origin, 0));
286                                         bprint(strcat("Waypoint spawned at ",vtos(self.origin),"\n"));
287                                         break;
288                                 case 104:
289                                         e = navigation_findnearestwaypoint(self, false);
290                                         if (e)
291                                         if (!(e.wpflags & WAYPOINTFLAG_GENERATED))
292                                         {
293                                                 bprint(strcat("Waypoint removed at ",vtos(e.origin),"\n"));
294                                                 waypoint_remove(e);
295                                         }
296                                         break;
297                                 case 105:
298                                         waypoint_schedulerelinkall();
299                                         break;
300                                 case 106:
301                                         waypoint_saveall();
302                                         break;
303                                 case 107:
304                                         for(e = findchain(classname, "waypoint"); e; e = e.chain)
305                                         {
306                                                 e.colormod = '0.5 0.5 0.5';
307                                                 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
308                                         }
309                                         e2 = navigation_findnearestwaypoint(self, false);
310                                         navigation_markroutes(e2);
311                                         i = 0;
312                                         m = 0;
313                                         for(e = findchain(classname, "waypoint"); e; e = e.chain)
314                                         {
315                                                 if(e.wpcost >= 10000000)
316                                                 {
317                                                         LOG_INFO("unreachable: ", etos(e), " ", vtos(e.origin), "\n");
318                                                         e.colormod_z = 8;
319                                                         e.effects |= EF_NODEPTHTEST | EF_BLUE;
320                                                         ++i;
321                                                         ++m;
322                                                 }
323                                         }
324                                         if(i)
325                                                 LOG_INFO(ftos(i), " waypoints cannot be reached from here in any way (marked with blue light)\n");
326                                         navigation_markroutes_inverted(e2);
327                                         i = 0;
328                                         for(e = findchain(classname, "waypoint"); e; e = e.chain)
329                                         {
330                                                 if(e.wpcost >= 10000000)
331                                                 {
332                                                         LOG_INFO("cannot reach me: ", etos(e), " ", vtos(e.origin), "\n");
333                                                         e.colormod_x = 8;
334                                                         if(!(e.effects & EF_NODEPTHTEST)) // not already reported before
335                                                                 ++m;
336                                                         e.effects |= EF_NODEPTHTEST | EF_RED;
337                                                         ++i;
338                                                 }
339                                         }
340                                         if(i)
341                                                 LOG_INFO(ftos(i), " waypoints cannot walk to here in any way (marked with red light)\n");
342                                         if(m)
343                                                 LOG_INFO(ftos(m), " waypoints have been marked total\n");
344                                         i = 0;
345                                         for(e = findchain(classname, "info_player_deathmatch"); e; e = e.chain)
346                                         {
347                                                 org = e.origin;
348                                                 tracebox(e.origin, PL_MIN, PL_MAX, e.origin - '0 0 512', MOVE_NOMONSTERS, world);
349                                                 setorigin(e, trace_endpos);
350                                                 if(navigation_findnearestwaypoint(e, false))
351                                                 {
352                                                         setorigin(e, org);
353                                                         e.effects &= ~EF_NODEPTHTEST;
354                                                         e.model = "";
355                                                 }
356                                                 else
357                                                 {
358                                                         setorigin(e, org);
359                                                         LOG_INFO("spawn without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
360                                                         e.effects |= EF_NODEPTHTEST;
361                                                         _setmodel(e, self.model);
362                                                         e.frame = self.frame;
363                                                         e.skin = self.skin;
364                                                         e.colormod = '8 0.5 8';
365                                                         setsize(e, '0 0 0', '0 0 0');
366                                                         ++i;
367                                                 }
368                                         }
369                                         if(i)
370                                                 LOG_INFO(ftos(i), " spawnpoints have no nearest waypoint (marked by player model)\n");
371                                         i = 0;
372                                         entity start;
373                                         start = findchainflags(flags, FL_ITEM);
374                                         for(e = start; e; e = e.chain)
375                                         {
376                                                 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
377                                                 e.colormod = '0.5 0.5 0.5';
378                                         }
379                                         for(e = start; e; e = e.chain)
380                                         {
381                                                 if(navigation_findnearestwaypoint(e, false))
382                                                 {
383                                                 }
384                                                 else
385                                                 {
386                                                         LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
387                                                         e.effects |= EF_NODEPTHTEST | EF_RED;
388                                                         e.colormod_x = 8;
389                                                         ++i;
390                                                 }
391                                         }
392                                         if(i)
393                                                 LOG_INFO(ftos(i), " items have no nearest waypoint and cannot be walked away from (marked with red light)\n");
394                                         i = 0;
395                                         for(e = start; e; e = e.chain)
396                                         {
397                                                 org = e.origin;
398                                                 if(navigation_findnearestwaypoint(e, true))
399                                                 {
400                                                 }
401                                                 else
402                                                 {
403                                                         LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
404                                                         e.effects |= EF_NODEPTHTEST | EF_BLUE;
405                                                         e.colormod_z = 8;
406                                                         ++i;
407                                                 }
408                                         }
409                                         if(i)
410                                                 LOG_INFO(ftos(i), " items have no nearest waypoint and cannot be walked to (marked with blue light)\n");
411                                         break;
412                         }
413                 }
414         }
415 }