]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/cl_impulse.qc
Merge branch 'master' into Mario/minigames_merge
[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 "vehicles/vehicle.qh"
14 #include "waypointsprites.qh"
15
16 #include "../common/minigames/sv_minigames.qh"
17
18 #include "../common/weapons/all.qh"
19
20 /*
21  * Impulse map:
22  *
23  * 0 reserved (no input)
24  * 1 to 9, 14: weapon shortcuts
25  * 10: next weapon according to linear list
26  * 11: most recently used weapon
27  * 12: previous weapon according to linear list
28  * 13: best weapon according to priority list
29  * 15: next weapon according to priority list
30  * 16: previous weapon according to priority list
31  * 17: throw weapon
32  * 18: next weapon according to sbar_hudselector 1 list
33  * 19: previous weapon according to sbar_hudselector 1 list
34  * 20: reload if needed
35  *
36  * 30 to 39: create waypoints
37  * 47: clear personal waypoints
38  * 48: clear team waypoints
39  *
40  * 99: loaded
41  *
42  * 140: moving clone
43  * 141: ctf speedrun
44  * 142: fixed clone
45  * 143: emergency teleport
46  * 148: unfairly eliminate
47  *
48  * TODO:
49  * 200 to 209: prev weapon shortcuts
50  * 210 to 219: best weapon shortcuts
51  * 220 to 229: next weapon shortcuts
52  * 230 to 253: individual weapons (up to 24)
53  */
54
55 void ImpulseCommands (void)
56 {
57         int imp;
58         vector org;
59         float i;
60         float m;
61         entity e, e2;
62
63         imp = self.impulse;
64         if (!imp || gameover)
65                 return;
66         self.impulse = 0;
67
68         if ( self.active_minigame )
69         if ( MinigameImpulse(imp) )
70                 return;
71
72         // allow only weapon change impulses when not in round time
73         if(round_handler_IsActive() && !round_handler_IsRoundStarted())
74         if(imp == 17 || (imp >= 20 && imp < 200) || imp > 253)
75                 return;
76
77         if (timeout_status == TIMEOUT_ACTIVE) //don't allow any impulses while the game is paused
78                 return;
79
80     if(self.vehicle)
81         if(self.vehicle.deadflag == DEAD_NO)
82             if(self.vehicle.vehicles_impulse)
83                 if(self.vehicle.vehicles_impulse(imp))
84                     return;
85
86         if(CheatImpulse(imp))
87         {
88         }
89         else if (imp >= 1 && imp <= 9)
90         {
91                 // weapon switching impulses
92                 if(self.deadflag == DEAD_NO)
93                         W_NextWeaponOnImpulse(imp);
94                 //else
95                 //      self.impulse = imp; // retry in next frame
96         }
97         else if(imp >= 10 && imp <= 20)
98         {
99                 if(self.deadflag == DEAD_NO)
100                 {
101                         switch(imp)
102                         {
103                                 case 10:
104                                         W_NextWeapon(0);
105                                         break;
106                                 case 11:
107                                         W_LastWeapon();
108                                         break;
109                                 case 12:
110                                         W_PreviousWeapon(0);
111                                         break;
112                                 case 13:
113                                         W_SwitchWeapon(w_getbestweapon(self));
114                                         break;
115                                 case 14:
116                                         W_NextWeaponOnImpulse(0);
117                                         break;
118                                 case 15:
119                                         W_NextWeapon(2);
120                                         break;
121                                 case 16:
122                                         W_PreviousWeapon(2);
123                                         break;
124                                 case 17:
125                                         W_ThrowWeapon(W_CalculateProjectileVelocity(self.velocity, v_forward * 750, false), '0 0 0', true);
126                                         break;
127                                 case 18:
128                                         W_NextWeapon(1);
129                                         break;
130                                 case 19:
131                                         W_PreviousWeapon(1);
132                                         break;
133                                 case 20:
134                                         if(!forbidWeaponUse()) { WEP_ACTION(self.weapon, WR_RELOAD); }
135                                         break;
136                         }
137                 }
138                 else
139                         self.impulse = imp; // retry in next frame
140         }
141         else if(imp == 21)
142         {
143                 PlayerUseKey ();
144         }
145         else if(imp >= 200 && imp <= 229)
146         {
147                 if(self.deadflag == DEAD_NO)
148                 {
149                         // custom order weapon cycling
150                         int i = imp % 10;
151                         m = (imp - (210 + i)); // <0 for prev, =0 for best, >0 for next
152                         W_CycleWeapon(self.(cvar_cl_weaponpriorities[i]), m);
153                 }
154                 else
155                         self.impulse = imp; // retry in next frame
156         }
157         else if(imp >= 230 && imp <= 253)
158         {
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))
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 }