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