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