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