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