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