1 #include "round_handler.qh"
3 #include "bot/waypoints.qh"
5 #include "weapons/throwing.qh"
6 #include "command/common.qh"
8 #include "bot/navigation.qh"
9 #include "weapons/selection.qh"
10 #include "weapons/tracing.qh"
11 #include "weapons/weaponsystem.qh"
13 #include "../common/minigames/sv_minigames.qh"
15 #include "../common/weapons/all.qh"
16 #include "../common/vehicles/sv_vehicles.qh"
18 #include "../common/mutators/mutator/waypoints/waypointsprites.qh"
22 #define IMPULSE(id, n) _IMPULSE(IMP_##id, n)
23 #define _IMPULSE(id, n) \
24 void id##_handle(entity this); \
25 STATIC_INIT_LATE(id) \
27 id.impulse_handle = id##_handle; \
29 void id##_handle(entity this)
34 * 0 reserved (no input)
41 * 143: emergency teleport
42 * 148: unfairly eliminate
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)
51 // weapon switching impulses
53 #define X(slot, imp) \
54 IMPULSE(weapon_group_##slot, imp) \
56 if (this.deadflag != DEAD_NO) return; \
57 W_NextWeaponOnImpulse(slot); \
71 // custom order weapon cycling
73 #define X(slot, dir, imp) \
74 IMPULSE(weapon_priority_##slot##_##dir, imp) \
76 if (this.vehicle) return; \
77 if (this.deadflag != DEAD_NO) return; \
78 noref int prev = -1; \
80 noref int next = +1; \
81 W_CycleWeapon(this.cvar_cl_weaponpriorities[slot], dir); \
117 IMPULSE(weapon_next_byid, 10)
119 if (this.vehicle) return;
120 if (this.deadflag != DEAD_NO) return;
124 IMPULSE(weapon_prev_byid, 12)
126 if (this.vehicle) return;
127 if (this.deadflag != DEAD_NO) return;
131 IMPULSE(weapon_next_bygroup, 18)
133 if (this.vehicle) return;
134 if (this.deadflag != DEAD_NO) return;
138 IMPULSE(weapon_prev_bygroup, 19)
140 if (this.vehicle) return;
141 if (this.deadflag != DEAD_NO) return;
145 IMPULSE(weapon_next_bypriority, 15)
147 if (this.vehicle) return;
148 if (this.deadflag != DEAD_NO) return;
152 IMPULSE(weapon_prev_bypriority, 16)
154 if (this.vehicle) return;
155 if (this.deadflag != DEAD_NO) return;
159 IMPULSE(weapon_last, 11)
161 if (this.vehicle) return;
162 if (this.deadflag != DEAD_NO) return;
166 IMPULSE(weapon_best, 13)
168 if (this.vehicle) return;
169 if (this.deadflag != DEAD_NO) return;
170 W_SwitchWeapon(w_getbestweapon(this));
173 IMPULSE(weapon_drop, 17)
175 if (this.vehicle) return;
176 if (this.deadflag != DEAD_NO) return;
177 W_ThrowWeapon(W_CalculateProjectileVelocity(this.velocity, v_forward * 750, false), '0 0 0', true);
180 IMPULSE(weapon_reload, 20)
182 if (this.vehicle) return;
183 if (this.deadflag != DEAD_NO) return;
184 if (forbidWeaponUse(this)) return;
185 Weapon w = Weapons_from(this.weapon);
189 void ImpulseCommands(entity this)
191 if (gameover) return;
193 int imp = this.impulse;
197 if (MinigameImpulse(this, imp)) return;
199 if (timeout_status == TIMEOUT_ACTIVE) return; // don't allow any impulses while the game is paused
201 // allow only weapon change impulses when not in round time
202 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
204 #define X(id) case IMP_##id.impulse:
207 case WEP_IMPULSE_BEGIN <= imp && imp <= WEP_IMPULSE_END:
220 X(weapon_next_bygroup)
221 X(weapon_prev_bygroup)
222 X(weapon_next_bypriority)
223 X(weapon_prev_bypriority)
227 X(weapon_priority_0_prev)
228 X(weapon_priority_1_prev)
229 X(weapon_priority_2_prev)
230 X(weapon_priority_3_prev)
231 X(weapon_priority_4_prev)
232 X(weapon_priority_5_prev)
233 X(weapon_priority_6_prev)
234 X(weapon_priority_7_prev)
235 X(weapon_priority_8_prev)
236 X(weapon_priority_9_prev)
237 X(weapon_priority_0_next)
238 X(weapon_priority_1_next)
239 X(weapon_priority_2_next)
240 X(weapon_priority_3_next)
241 X(weapon_priority_4_next)
242 X(weapon_priority_5_next)
243 X(weapon_priority_6_next)
244 X(weapon_priority_7_next)
245 X(weapon_priority_8_next)
246 X(weapon_priority_9_next)
247 X(weapon_priority_0_best)
248 X(weapon_priority_1_best)
249 X(weapon_priority_2_best)
250 X(weapon_priority_3_best)
251 X(weapon_priority_4_best)
252 X(weapon_priority_5_best)
253 X(weapon_priority_6_best)
254 X(weapon_priority_7_best)
255 X(weapon_priority_8_best)
256 X(weapon_priority_9_best)
263 if (vehicle_impulse(this, imp)) return;
265 if (CheatImpulse(imp)) return;
267 FOREACH(IMPULSES, it.impulse == imp, {
268 void(entity) f = it.impulse_handle;
274 if (imp >= WEP_IMPULSE_BEGIN && imp <= WEP_IMPULSE_END)
276 if (!this.vehicle && this.deadflag == DEAD_NO) W_SwitchWeapon(imp - WEP_IMPULSE_BEGIN + WEP_FIRST);
285 IMPULSE(waypoint_personal_here, 30)
287 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this.origin, RADARICON_WAYPOINT);
288 if (wp) WaypointSprite_Ping(wp);
289 sprint(this, "personal waypoint spawned at location\n");
292 IMPULSE(waypoint_personal_crosshair, 31)
294 WarpZone_crosshair_trace(this);
295 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, trace_endpos, RADARICON_WAYPOINT);
296 if (wp) WaypointSprite_Ping(wp);
297 sprint(this, "personal waypoint spawned at crosshair\n");
300 IMPULSE(waypoint_personal_death, 32)
302 if (!this.death_origin) return;
303 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this.death_origin, RADARICON_WAYPOINT);
304 if (wp) WaypointSprite_Ping(wp);
305 sprint(this, "personal waypoint spawned at death location\n");
308 IMPULSE(waypoint_here_follow, 33)
310 if (!teamplay) return;
311 if (this.deadflag != DEAD_NO) return;
312 if (!MUTATOR_CALLHOOK(HelpMePing, this))
314 entity wp = WaypointSprite_Attach(WP_Helpme, true, RADARICON_HELPME);
315 if (!wp) WaypointSprite_HelpMePing(this.waypointsprite_attachedforcarrier);
316 else WaypointSprite_Ping(wp);
318 sprint(this, "HELP ME attached\n");
321 IMPULSE(waypoint_here_here, 34)
323 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this.origin, RADARICON_HERE);
324 if (wp) WaypointSprite_Ping(wp);
325 sprint(this, "HERE spawned at location\n");
328 IMPULSE(waypoint_here_crosshair, 35)
330 WarpZone_crosshair_trace(this);
331 entity wp = WaypointSprite_DeployFixed(WP_Here, false, trace_endpos, RADARICON_HERE);
332 if (wp) WaypointSprite_Ping(wp);
333 sprint(this, "HERE spawned at crosshair\n");
336 IMPULSE(waypoint_here_death, 36)
338 if (!this.death_origin) return;
339 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this.death_origin, RADARICON_HERE);
340 if (wp) WaypointSprite_Ping(wp);
341 sprint(this, "HERE spawned at death location\n");
344 IMPULSE(waypoint_danger_here, 37)
346 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this.origin, RADARICON_DANGER);
347 if (wp) WaypointSprite_Ping(wp);
348 sprint(this, "DANGER spawned at location\n");
351 IMPULSE(waypoint_danger_crosshair, 38)
353 WarpZone_crosshair_trace(this);
354 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, trace_endpos, RADARICON_DANGER);
355 if (wp) WaypointSprite_Ping(wp);
356 sprint(this, "DANGER spawned at crosshair\n");
359 IMPULSE(waypoint_danger_death, 39)
361 if (!this.death_origin) return;
362 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this.death_origin, RADARICON_DANGER);
363 if (wp) WaypointSprite_Ping(wp);
364 sprint(this, "DANGER spawned at death location\n");
367 IMPULSE(waypoint_clear_personal, 47)
369 WaypointSprite_ClearPersonal();
372 remove(this.personal);
373 this.personal = NULL;
375 sprint(this, "personal waypoint cleared\n");
378 IMPULSE(waypoint_clear, 48)
380 WaypointSprite_ClearOwned();
383 remove(this.personal);
384 this.personal = NULL;
386 sprint(this, "all waypoints cleared\n");
389 IMPULSE(navwaypoint_spawn, 103)
391 if (!autocvar_g_waypointeditor) return;
392 waypoint_schedulerelink(waypoint_spawn(this.origin, this.origin, 0));
393 bprint(strcat("Waypoint spawned at ", vtos(this.origin), "\n"));
396 IMPULSE(navwaypoint_remove, 104)
398 if (!autocvar_g_waypointeditor) return;
399 entity e = navigation_findnearestwaypoint(this, false);
401 if (e.wpflags & WAYPOINTFLAG_GENERATED) return;
402 bprint(strcat("Waypoint removed at ", vtos(e.origin), "\n"));
406 IMPULSE(navwaypoint_relink, 105)
408 if (!autocvar_g_waypointeditor) return;
409 waypoint_schedulerelinkall();
412 IMPULSE(navwaypoint_save, 106)
414 if (!autocvar_g_waypointeditor) return;
418 IMPULSE(navwaypoint_unreachable, 107)
420 if (!autocvar_g_waypointeditor) return;
421 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
423 e.colormod = '0.5 0.5 0.5';
424 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
426 entity e2 = navigation_findnearestwaypoint(this, false);
427 navigation_markroutes(e2);
433 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
435 if (e.wpcost < 10000000) continue;
436 LOG_INFO("unreachable: ", etos(e), " ", vtos(e.origin), "\n");
438 e.effects |= EF_NODEPTHTEST | EF_BLUE;
442 if (i) LOG_INFOF("%d waypoints cannot be reached from here in any way (marked with blue light)\n", i);
443 navigation_markroutes_inverted(e2);
446 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
448 if (e.wpcost < 10000000) continue;
449 LOG_INFO("cannot reach me: ", etos(e), " ", vtos(e.origin), "\n");
451 if (!(e.effects & EF_NODEPTHTEST)) // not already reported before
453 e.effects |= EF_NODEPTHTEST | EF_RED;
456 if (i) LOG_INFOF("%d waypoints cannot walk to here in any way (marked with red light)\n", i);
457 if (m) LOG_INFOF("%d waypoints have been marked total\n", m);
460 for (entity e = findchain(classname, "info_player_deathmatch"); e; e = e.chain)
462 vector org = e.origin;
463 tracebox(e.origin, PL_MIN, PL_MAX, e.origin - '0 0 512', MOVE_NOMONSTERS, world);
464 setorigin(e, trace_endpos);
465 if (navigation_findnearestwaypoint(e, false))
468 e.effects &= ~EF_NODEPTHTEST;
474 LOG_INFO("spawn without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
475 e.effects |= EF_NODEPTHTEST;
476 _setmodel(e, this.model);
477 e.frame = this.frame;
479 e.colormod = '8 0.5 8';
480 setsize(e, '0 0 0', '0 0 0');
484 if (i) LOG_INFOF("%d spawnpoints have no nearest waypoint (marked by player model)\n", i);
487 entity start = findchainflags(flags, FL_ITEM);
488 for (entity e = start; e; e = e.chain)
490 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
491 e.colormod = '0.5 0.5 0.5';
493 for (entity e = start; e; e = e.chain)
495 if (navigation_findnearestwaypoint(e, false)) continue;
496 LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
497 e.effects |= EF_NODEPTHTEST | EF_RED;
501 if (i) LOG_INFOF("%d items have no nearest waypoint and cannot be walked away from (marked with red light)\n", i);
504 for (entity e = start; e; e = e.chain)
506 if (navigation_findnearestwaypoint(e, true)) continue;
507 LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
508 e.effects |= EF_NODEPTHTEST | EF_BLUE;
512 if (i) LOG_INFOF("%d items have no nearest waypoint and cannot be walked to (marked with blue light)\n", i);