2 #include "round_handler.qh"
6 #include "weapons/throwing.qh"
7 #include "command/common.qh"
9 #include "weapons/selection.qh"
10 #include "weapons/tracing.qh"
11 #include "weapons/weaponsystem.qh"
13 #include <common/state.qh>
15 #include "../common/minigames/sv_minigames.qh"
17 #include <common/weapons/_all.qh>
18 #include "../common/vehicles/sv_vehicles.qh"
20 #include "../common/mutators/mutator/waypoints/waypointsprites.qh"
24 #define IMPULSE(id) _IMPULSE(IMP_##id)
25 #define _IMPULSE(id) \
26 void id##_handle(entity this); \
27 STATIC_INIT_LATE(id) \
29 id.impulse_handle = id##_handle; \
31 void id##_handle(entity this)
36 * 0 reserved (no input)
43 * 143: emergency teleport
44 * 148: unfairly eliminate
47 * 200 to 209: prev weapon shortcuts
48 * 210 to 219: best weapon shortcuts
49 * 220 to 229: next weapon shortcuts
50 * 230 to 253: individual weapons (up to 24)
53 // weapon switching impulses
56 IMPULSE(weapon_group_##slot) \
60 this.impulse = IMP_weapon_group_##slot.impulse; \
63 for(int wepslot = 0; wepslot < MAX_WEAPONSLOTS; ++wepslot) \
65 .entity weaponentity = weaponentities[wepslot]; \
66 W_NextWeaponOnImpulse(this, slot, weaponentity); \
67 if(wepslot == 0 && autocvar_g_weaponswitch_debug != 1) \
83 // custom order weapon cycling
85 #define X(slot, dir) \
86 IMPULSE(weapon_priority_##slot##_##dir) \
88 if (this.vehicle) return; \
91 this.impulse = IMP_weapon_priority_##slot##_##dir.impulse; \
94 noref int prev = -1; \
96 noref int next = +1; \
97 for(int wepslot = 0; wepslot < MAX_WEAPONSLOTS; ++wepslot) \
99 .entity weaponentity = weaponentities[wepslot]; \
100 W_CycleWeapon(this, CS(this).cvar_cl_weaponpriorities[slot], dir, weaponentity); \
101 if(wepslot == 0 && autocvar_g_weaponswitch_debug != 1) \
142 IMPULSE(weapon_byid_##i) \
144 if (this.vehicle) return; \
147 this.impulse = IMP_weapon_byid_##i.impulse; \
150 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) \
152 .entity weaponentity = weaponentities[slot]; \
153 W_SwitchWeapon(this, Weapons_from(WEP_FIRST + i), weaponentity); \
154 if(slot == 0 && autocvar_g_weaponswitch_debug != 1) \
184 IMPULSE(weapon_next_byid)
186 if (this.vehicle) return;
189 this.impulse = IMP_weapon_next_byid.impulse;
192 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
194 .entity weaponentity = weaponentities[slot];
195 W_NextWeapon(this, 0, weaponentity);
197 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
202 IMPULSE(weapon_prev_byid)
204 if (this.vehicle) return;
207 this.impulse = IMP_weapon_prev_byid.impulse;
210 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
212 .entity weaponentity = weaponentities[slot];
213 W_PreviousWeapon(this, 0, weaponentity);
215 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
220 IMPULSE(weapon_next_bygroup)
222 if (this.vehicle) return;
225 this.impulse = IMP_weapon_next_bygroup.impulse;
228 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
230 .entity weaponentity = weaponentities[slot];
231 W_NextWeapon(this, 1, weaponentity);
233 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
238 IMPULSE(weapon_prev_bygroup)
240 if (this.vehicle) return;
243 this.impulse = IMP_weapon_prev_bygroup.impulse;
246 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
248 .entity weaponentity = weaponentities[slot];
249 W_PreviousWeapon(this, 1, weaponentity);
251 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
256 IMPULSE(weapon_next_bypriority)
258 if (this.vehicle) return;
261 this.impulse = IMP_weapon_next_bypriority.impulse;
264 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
266 .entity weaponentity = weaponentities[slot];
267 W_NextWeapon(this, 2, weaponentity);
269 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
274 IMPULSE(weapon_prev_bypriority)
276 if (this.vehicle) return;
279 this.impulse = IMP_weapon_prev_bypriority.impulse;
282 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
284 .entity weaponentity = weaponentities[slot];
285 W_PreviousWeapon(this, 2, weaponentity);
287 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
294 if (this.vehicle) return;
295 if (IS_DEAD(this)) return;
296 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
298 .entity weaponentity = weaponentities[slot];
299 W_LastWeapon(this, weaponentity);
301 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
308 if (this.vehicle) return;
309 if (IS_DEAD(this)) return;
310 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
312 .entity weaponentity = weaponentities[slot];
313 W_SwitchWeapon(this, w_getbestweapon(this, weaponentity), weaponentity);
315 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
322 if (this.vehicle) return;
323 if (IS_DEAD(this)) return;
324 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
326 .entity weaponentity = weaponentities[slot];
327 W_ThrowWeapon(this, weaponentity, W_CalculateProjectileVelocity(this, this.velocity, v_forward * 750, false), '0 0 0', true);
329 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
334 IMPULSE(weapon_reload)
336 if (this.vehicle) return;
337 if (IS_DEAD(this)) return;
338 if (forbidWeaponUse(this)) return;
340 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
342 .entity weaponentity = weaponentities[slot];
343 Weapon w = this.(weaponentity).m_weapon;
344 w.wr_reload(w, actor, weaponentity);
346 // allow reloading all active slots?
347 //if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
352 void ImpulseCommands(entity this)
354 if (game_stopped) return;
356 int imp = CS(this).impulse;
358 CS(this).impulse = 0;
360 if (MinigameImpulse(this, imp)) return;
362 if (timeout_status == TIMEOUT_ACTIVE) return; // don't allow any impulses while the game is paused
364 // allow only weapon change impulses when not in round time
365 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
367 #define X(id) case IMP_##id.impulse:
382 X(weapon_next_bygroup)
383 X(weapon_prev_bygroup)
384 X(weapon_next_bypriority)
385 X(weapon_prev_bypriority)
389 X(weapon_priority_0_prev)
390 X(weapon_priority_1_prev)
391 X(weapon_priority_2_prev)
392 X(weapon_priority_3_prev)
393 X(weapon_priority_4_prev)
394 X(weapon_priority_5_prev)
395 X(weapon_priority_6_prev)
396 X(weapon_priority_7_prev)
397 X(weapon_priority_8_prev)
398 X(weapon_priority_9_prev)
399 X(weapon_priority_0_next)
400 X(weapon_priority_1_next)
401 X(weapon_priority_2_next)
402 X(weapon_priority_3_next)
403 X(weapon_priority_4_next)
404 X(weapon_priority_5_next)
405 X(weapon_priority_6_next)
406 X(weapon_priority_7_next)
407 X(weapon_priority_8_next)
408 X(weapon_priority_9_next)
409 X(weapon_priority_0_best)
410 X(weapon_priority_1_best)
411 X(weapon_priority_2_best)
412 X(weapon_priority_3_best)
413 X(weapon_priority_4_best)
414 X(weapon_priority_5_best)
415 X(weapon_priority_6_best)
416 X(weapon_priority_7_best)
417 X(weapon_priority_8_best)
418 X(weapon_priority_9_best)
449 if (vehicle_impulse(this, imp)) return;
451 if (CheatImpulse(this, imp)) return;
453 FOREACH(IMPULSES, it.impulse == imp, {
454 void(entity) f = it.impulse_handle;
466 IMPULSE(waypoint_personal_here)
468 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, this.origin, RADARICON_WAYPOINT);
469 if (wp) WaypointSprite_Ping(wp);
470 sprint(this, "personal waypoint spawned at location\n");
473 IMPULSE(waypoint_personal_crosshair)
475 WarpZone_crosshair_trace(this);
476 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, trace_endpos, RADARICON_WAYPOINT);
477 if (wp) WaypointSprite_Ping(wp);
478 sprint(this, "personal waypoint spawned at crosshair\n");
481 IMPULSE(waypoint_personal_death)
483 if (!this.death_origin) return;
484 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, this.death_origin, RADARICON_WAYPOINT);
485 if (wp) WaypointSprite_Ping(wp);
486 sprint(this, "personal waypoint spawned at death location\n");
489 IMPULSE(waypoint_here_follow)
491 if (!teamplay) return;
492 if (IS_DEAD(this)) return;
493 if (!MUTATOR_CALLHOOK(HelpMePing, this))
495 entity wp = WaypointSprite_Attach(WP_Helpme, this, true, RADARICON_HELPME);
496 if (!wp) WaypointSprite_HelpMePing(this.waypointsprite_attachedforcarrier);
497 else WaypointSprite_Ping(wp);
499 sprint(this, "HELP ME attached\n");
502 IMPULSE(waypoint_here_here)
504 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, this.origin, RADARICON_HERE);
505 if (wp) WaypointSprite_Ping(wp);
506 sprint(this, "HERE spawned at location\n");
509 IMPULSE(waypoint_here_crosshair)
511 WarpZone_crosshair_trace(this);
512 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, trace_endpos, RADARICON_HERE);
513 if (wp) WaypointSprite_Ping(wp);
514 sprint(this, "HERE spawned at crosshair\n");
517 IMPULSE(waypoint_here_death)
519 if (!this.death_origin) return;
520 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, this.death_origin, RADARICON_HERE);
521 if (wp) WaypointSprite_Ping(wp);
522 sprint(this, "HERE spawned at death location\n");
525 IMPULSE(waypoint_danger_here)
527 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, this.origin, RADARICON_DANGER);
528 if (wp) WaypointSprite_Ping(wp);
529 sprint(this, "DANGER spawned at location\n");
532 IMPULSE(waypoint_danger_crosshair)
534 WarpZone_crosshair_trace(this);
535 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, trace_endpos, RADARICON_DANGER);
536 if (wp) WaypointSprite_Ping(wp);
537 sprint(this, "DANGER spawned at crosshair\n");
540 IMPULSE(waypoint_danger_death)
542 if (!this.death_origin) return;
543 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, this.death_origin, RADARICON_DANGER);
544 if (wp) WaypointSprite_Ping(wp);
545 sprint(this, "DANGER spawned at death location\n");
548 IMPULSE(waypoint_clear_personal)
550 WaypointSprite_ClearPersonal(this);
553 delete(this.personal);
554 this.personal = NULL;
556 if((g_cts || g_race) && autocvar_g_allow_checkpoints)
559 sprint(this, "personal waypoint cleared\n");
562 IMPULSE(waypoint_clear)
564 WaypointSprite_ClearOwned(this);
567 delete(this.personal);
568 this.personal = NULL;
569 if((g_cts || g_race) && autocvar_g_allow_checkpoints)
572 sprint(this, "all waypoints cleared\n");
575 IMPULSE(navwaypoint_spawn)
577 if (!autocvar_g_waypointeditor) return;
578 waypoint_spawn_fromeditor(this);
581 IMPULSE(navwaypoint_remove)
583 if (!autocvar_g_waypointeditor) return;
584 waypoint_remove_fromeditor(this);
587 IMPULSE(navwaypoint_relink)
589 if (!autocvar_g_waypointeditor) return;
590 waypoint_schedulerelinkall();
593 IMPULSE(navwaypoint_save)
595 if (!autocvar_g_waypointeditor) return;
599 IMPULSE(navwaypoint_unreachable)
601 if (!autocvar_g_waypointeditor) return;
602 waypoint_unreachable(this);