]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/cl_impulse.qc
Merge branch 'master' into fruitiex/gamemode_freezetag
[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         local 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 (timeoutStatus == 2) //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_SwitchWeapon (self.cnt); // previously used
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), '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_Reload ();
102                                         break;
103                         }
104                 }
105                 else
106                         self.impulse = imp; // retry in next frame
107         }
108         else if(imp >= 200 && imp <= 229)
109         {
110                 if(self.deadflag == DEAD_NO)
111                 {
112                         // custom order weapon cycling
113                         i = mod(imp, 10);
114                         m = (imp - (210 + i)); // <0 for prev, =0 for best, >0 for next
115                         W_CycleWeapon(self.(cvar_cl_weaponpriorities[i]), m);
116                 }
117                 else
118                         self.impulse = imp; // retry in next frame
119         }
120         else if(imp >= 230 && imp <= 253)
121         {
122                 if(self.deadflag == DEAD_NO)
123                         W_SwitchWeapon (imp - 230 + WEP_FIRST);
124                 else
125                         self.impulse = imp; // retry in next frame
126         }
127         // deploy waypoints
128         else if (imp >= 30 && imp <= 49)
129         {
130                 entity wp;
131                 switch(imp)
132                 {
133                         case 30:
134                                 wp = WaypointSprite_DeployPersonal("waypoint", self.origin);
135                                 if(wp)
136                                 {
137                                         WaypointSprite_UpdateTeamRadar(wp, RADARICON_WAYPOINT, '0 1 1');
138                                         WaypointSprite_Ping(wp);
139                                 }
140                                 sprint(self, "personal waypoint spawned at location\n");
141                                 break;
142                         case 31:
143                                 WarpZone_crosshair_trace(self);
144                                 wp = WaypointSprite_DeployPersonal("waypoint", trace_endpos);
145                                 if(wp)
146                                 {
147                                         WaypointSprite_UpdateTeamRadar(wp, RADARICON_WAYPOINT, '0 1 1');
148                                         WaypointSprite_Ping(wp);
149                                 }
150                                 sprint(self, "personal waypoint spawned at crosshair\n");
151                                 break;
152                         case 32:
153                                 if(vlen(self.death_origin))
154                                 {
155                                         wp = WaypointSprite_DeployPersonal("waypoint", self.death_origin);
156                                         if(wp)
157                                         {
158                                                 WaypointSprite_UpdateTeamRadar(wp, RADARICON_WAYPOINT, '0 1 1');
159                                                 WaypointSprite_Ping(wp);
160                                         }
161                                         sprint(self, "personal waypoint spawned at death location\n");
162                                 }
163                                 break;
164                         case 33:
165                                 if(self.deadflag == DEAD_NO && teams_matter)
166                                 {
167                                         wp = WaypointSprite_Attach("helpme", TRUE);
168                                         if(wp)
169                                                 WaypointSprite_UpdateTeamRadar(wp, RADARICON_HELPME, '1 0.5 0'); // TODO choose better color
170                                         if(!wp)
171                                                 wp = self.waypointsprite_attachedforcarrier; // flag sprite?
172                                         if(wp)
173                                                 WaypointSprite_Ping(wp);
174                                         sprint(self, "HELP ME attached\n");
175                                 }
176                                 break;
177                         case 34:
178                                 wp = WaypointSprite_DeployFixed("here", FALSE, self.origin);
179                                 if(wp)
180                                 {
181                                         WaypointSprite_UpdateTeamRadar(wp, RADARICON_HERE, '0 1 0');
182                                         WaypointSprite_Ping(wp);
183                                 }
184                                 sprint(self, "HERE spawned at location\n");
185                                 break;
186                         case 35:
187                                 WarpZone_crosshair_trace(self);
188                                 wp = WaypointSprite_DeployFixed("here", FALSE, trace_endpos);
189                                 if(wp)
190                                 {
191                                         WaypointSprite_UpdateTeamRadar(wp, RADARICON_HERE, '0 1 0');
192                                         WaypointSprite_Ping(wp);
193                                 }
194                                 sprint(self, "HERE spawned at crosshair\n");
195                                 break;
196                         case 36:
197                                 if(vlen(self.death_origin))
198                                 {
199                                         wp = WaypointSprite_DeployFixed("here", FALSE, self.death_origin);
200                                         if(wp)
201                                         {
202                                                 WaypointSprite_UpdateTeamRadar(wp, RADARICON_HERE, '0 1 0');
203                                                 WaypointSprite_Ping(wp);
204                                         }
205                                         sprint(self, "HERE spawned at death location\n");
206                                 }
207                                 break;
208                         case 37:
209                                 wp = WaypointSprite_DeployFixed("danger", FALSE, self.origin);
210                                 if(wp)
211                                 {
212                                         WaypointSprite_UpdateTeamRadar(wp, RADARICON_DANGER, '1 0.5 0');
213                                         WaypointSprite_Ping(wp);
214                                 }
215                                 sprint(self, "DANGER spawned at location\n");
216                                 break;
217                         case 38:
218                                 WarpZone_crosshair_trace(self);
219                                 wp = WaypointSprite_DeployFixed("danger", FALSE, trace_endpos);
220                                 if(wp)
221                                 {
222                                         WaypointSprite_UpdateTeamRadar(wp, RADARICON_DANGER, '1 0.5 0');
223                                         WaypointSprite_Ping(wp);
224                                 }
225                                 sprint(self, "DANGER spawned at crosshair\n");
226                                 break;
227                         case 39:
228                                 if(vlen(self.death_origin))
229                                 {
230                                         wp = WaypointSprite_DeployFixed("danger", FALSE, self.death_origin);
231                                         if(wp)
232                                         {
233                                                 WaypointSprite_UpdateTeamRadar(wp, RADARICON_DANGER, '1 0.5 0');
234                                                 WaypointSprite_Ping(wp);
235                                         }
236                                         sprint(self, "DANGER spawned at death location\n");
237                                 }
238                                 break;
239                         case 47:
240                                 WaypointSprite_ClearPersonal();
241                                 if(self.personal)
242                                 {
243                                         remove(self.personal);
244                                         self.personal = world;
245                                 }
246                                 sprint(self, "personal waypoint cleared\n");
247                                 break;
248                         case 48:
249                                 WaypointSprite_ClearOwned();
250                                 if(self.personal)
251                                 {
252                                         remove(self.personal);
253                                         self.personal = world;
254                                 }
255                                 sprint(self, "all waypoints cleared\n");
256                                 break;
257                 }
258         }
259         else if(imp >= 103 && imp <= 107)
260         {
261                 if(cvar("g_waypointeditor"))
262                 {
263                         switch(imp)
264                         {
265                                 case 103:
266                                         waypoint_schedulerelink(waypoint_spawn(self.origin, self.origin, 0));
267                                         bprint(strcat("Waypoint spawned at ",vtos(self.origin),"\n"));
268                                         break;
269                                 case 104:
270                                         e = navigation_findnearestwaypoint(self, FALSE);
271                                         if (e)
272                                         if not(e.wpflags & WAYPOINTFLAG_GENERATED)
273                                         {
274                                                 bprint(strcat("Waypoint removed at ",vtos(e.origin),"\n"));
275                                                 waypoint_remove(e);
276                                         }
277                                         break;
278                                 case 105:
279                                         waypoint_schedulerelinkall();
280                                         break;
281                                 case 106:
282                                         waypoint_saveall();
283                                         break;
284                                 case 107:
285                                         for(e = findchain(classname, "waypoint"); e; e = e.chain)
286                                         {
287                                                 e.colormod_x = 1;
288                                                 e.effects &~= EF_NODEPTHTEST | EF_RED | EF_BLUE;
289                                         }
290                                         e2 = navigation_findnearestwaypoint(self, FALSE);
291                                         navigation_markroutes(e2);
292                                         i = 0;
293                                         m = 0;
294                                         for(e = findchain(classname, "waypoint"); e; e = e.chain)
295                                         {
296                                                 if(e.wpcost >= 10000000)
297                                                 {
298                                                         print("unreachable: ", etos(e), " ", vtos(e.origin), "\n");
299                                                         e.colormod_x = 0.1;
300                                                         e.effects |= EF_NODEPTHTEST | EF_BLUE;
301                                                         ++i;
302                                                         ++m;
303                                                 }
304                                         }
305                                         if(i)
306                                                 print(ftos(i), " waypoints cannot be reached from here in any way (marked with blue light)\n");
307                                         navigation_markroutes_inverted(e2);
308                                         i = 0;
309                                         for(e = findchain(classname, "waypoint"); e; e = e.chain)
310                                         {
311                                                 if(e.wpcost >= 10000000)
312                                                 {
313                                                         print("cannot reach me: ", etos(e), " ", vtos(e.origin), "\n");
314                                                         e.colormod_x = 0.1;
315                                                         if not(e.effects & EF_NODEPTHTEST) // not already reported before
316                                                                 ++m;
317                                                         e.effects |= EF_NODEPTHTEST | EF_RED;
318                                                         ++i;
319                                                 }
320                                         }
321                                         if(i)
322                                                 print(ftos(i), " waypoints cannot walk to here in any way (marked with red light)\n");
323                                         if(m)
324                                                 print(ftos(m), " waypoints have been marked total\n");
325                                         i = 0;
326                                         for(e = findchain(classname, "info_player_deathmatch"); e; e = e.chain)
327                                         {
328                                                 org = e.origin;
329                                                 tracebox(e.origin, PL_MIN, PL_MAX, e.origin - '0 0 512', MOVE_NOMONSTERS, world);
330                                                 setorigin(e, trace_endpos);
331                                                 if(navigation_findnearestwaypoint(e, FALSE))
332                                                 {
333                                                         setorigin(e, org);
334                                                         e.effects &~= EF_NODEPTHTEST;
335                                                         e.model = "";
336                                                 }
337                                                 else
338                                                 {
339                                                         setorigin(e, org);
340                                                         print("spawn without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
341                                                         e.effects |= EF_NODEPTHTEST;
342                                                         setmodel(e, self.model);
343                                                         e.frame = self.frame;
344                                                         e.skin = self.skin;
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                                         break;
352                         }
353                 }
354         }
355 #ifdef TETRIS
356         else if(imp == 100)
357                 TetrisImpulse();
358 #endif
359 }