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