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