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