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