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