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