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