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