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