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