2 #include "round_handler.qh"
6 #include "weapons/throwing.qh"
7 #include "command/common.qh"
9 #include "clientkill.qh"
10 #include "weapons/selection.qh"
11 #include "weapons/tracing.qh"
12 #include "weapons/weaponsystem.qh"
14 #include <common/state.qh>
16 #include "../common/minigames/sv_minigames.qh"
18 #include <common/weapons/_all.qh>
19 #include "../common/vehicles/sv_vehicles.qh"
21 #include "../common/mutators/mutator/waypoints/waypointsprites.qh"
25 #define IMPULSE(id) _IMPULSE(IMP_##id)
26 #define _IMPULSE(id) \
27 void id##_handle(entity this); \
28 STATIC_INIT_LATE(id) \
30 id.impulse_handle = id##_handle; \
32 void id##_handle(entity this)
37 * 0 reserved (no input)
44 * 143: emergency teleport
45 * 148: unfairly eliminate
48 * 200 to 209: prev weapon shortcuts
49 * 210 to 219: best weapon shortcuts
50 * 220 to 229: next weapon shortcuts
51 * 230 to 253: individual weapons (up to 24)
54 // weapon switching impulses
57 IMPULSE(weapon_group_##slot) \
61 this.impulse = IMP_weapon_group_##slot.impulse; \
64 for(int wepslot = 0; wepslot < MAX_WEAPONSLOTS; ++wepslot) \
66 .entity weaponentity = weaponentities[wepslot]; \
67 W_NextWeaponOnImpulse(this, slot, weaponentity); \
68 if(wepslot == 0 && autocvar_g_weaponswitch_debug != 1) \
84 // custom order weapon cycling
86 #define X(slot, dir) \
87 IMPULSE(weapon_priority_##slot##_##dir) \
89 if (this.vehicle) return; \
92 this.impulse = IMP_weapon_priority_##slot##_##dir.impulse; \
95 noref int prev = -1; \
97 noref int next = +1; \
98 for(int wepslot = 0; wepslot < MAX_WEAPONSLOTS; ++wepslot) \
100 .entity weaponentity = weaponentities[wepslot]; \
101 W_CycleWeapon(this, CS(this).cvar_cl_weaponpriorities[slot], dir, weaponentity); \
102 if(wepslot == 0 && autocvar_g_weaponswitch_debug != 1) \
143 IMPULSE(weapon_byid_##i) \
145 if (this.vehicle) return; \
148 this.impulse = IMP_weapon_byid_##i.impulse; \
151 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) \
153 .entity weaponentity = weaponentities[slot]; \
154 W_SwitchWeapon(this, Weapons_from(WEP_FIRST + i), weaponentity); \
155 if(slot == 0 && autocvar_g_weaponswitch_debug != 1) \
185 IMPULSE(weapon_next_byid)
187 if (this.vehicle) return;
190 this.impulse = IMP_weapon_next_byid.impulse;
193 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
195 .entity weaponentity = weaponentities[slot];
196 W_NextWeapon(this, 0, weaponentity);
198 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
203 IMPULSE(weapon_prev_byid)
205 if (this.vehicle) return;
208 this.impulse = IMP_weapon_prev_byid.impulse;
211 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
213 .entity weaponentity = weaponentities[slot];
214 W_PreviousWeapon(this, 0, weaponentity);
216 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
221 IMPULSE(weapon_next_bygroup)
223 if (this.vehicle) return;
226 this.impulse = IMP_weapon_next_bygroup.impulse;
229 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
231 .entity weaponentity = weaponentities[slot];
232 W_NextWeapon(this, 1, weaponentity);
234 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
239 IMPULSE(weapon_prev_bygroup)
241 if (this.vehicle) return;
244 this.impulse = IMP_weapon_prev_bygroup.impulse;
247 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
249 .entity weaponentity = weaponentities[slot];
250 W_PreviousWeapon(this, 1, weaponentity);
252 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
257 IMPULSE(weapon_next_bypriority)
259 if (this.vehicle) return;
262 this.impulse = IMP_weapon_next_bypriority.impulse;
265 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
267 .entity weaponentity = weaponentities[slot];
268 W_NextWeapon(this, 2, weaponentity);
270 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
275 IMPULSE(weapon_prev_bypriority)
277 if (this.vehicle) return;
280 this.impulse = IMP_weapon_prev_bypriority.impulse;
283 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
285 .entity weaponentity = weaponentities[slot];
286 W_PreviousWeapon(this, 2, weaponentity);
288 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
295 if (this.vehicle) return;
296 if (IS_DEAD(this)) return;
297 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
299 .entity weaponentity = weaponentities[slot];
300 W_LastWeapon(this, weaponentity);
302 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
309 if (this.vehicle) return;
310 if (IS_DEAD(this)) return;
311 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
313 .entity weaponentity = weaponentities[slot];
314 W_SwitchWeapon(this, w_getbestweapon(this, weaponentity), weaponentity);
316 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
323 if (this.vehicle) return;
324 if (IS_DEAD(this)) return;
325 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
327 .entity weaponentity = weaponentities[slot];
328 W_ThrowWeapon(this, weaponentity, W_CalculateProjectileVelocity(this, this.velocity, v_forward * 750, false), '0 0 0', true);
330 if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
335 IMPULSE(weapon_reload)
337 if (this.vehicle) return;
338 if (IS_DEAD(this)) return;
339 if (forbidWeaponUse(this)) return;
341 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
343 .entity weaponentity = weaponentities[slot];
344 Weapon w = this.(weaponentity).m_weapon;
345 w.wr_reload(w, actor, weaponentity);
347 // allow reloading all active slots?
348 //if(slot == 0 && autocvar_g_weaponswitch_debug != 1)
353 void ImpulseCommands(entity this)
355 if (game_stopped) return;
357 int imp = CS(this).impulse;
359 CS(this).impulse = 0;
361 if (MinigameImpulse(this, imp)) return;
363 if (timeout_status == TIMEOUT_ACTIVE) return; // don't allow any impulses while the game is paused
365 // allow only weapon change impulses when not in round time
366 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
368 #define X(id) case IMP_##id.impulse:
383 X(weapon_next_bygroup)
384 X(weapon_prev_bygroup)
385 X(weapon_next_bypriority)
386 X(weapon_prev_bypriority)
390 X(weapon_priority_0_prev)
391 X(weapon_priority_1_prev)
392 X(weapon_priority_2_prev)
393 X(weapon_priority_3_prev)
394 X(weapon_priority_4_prev)
395 X(weapon_priority_5_prev)
396 X(weapon_priority_6_prev)
397 X(weapon_priority_7_prev)
398 X(weapon_priority_8_prev)
399 X(weapon_priority_9_prev)
400 X(weapon_priority_0_next)
401 X(weapon_priority_1_next)
402 X(weapon_priority_2_next)
403 X(weapon_priority_3_next)
404 X(weapon_priority_4_next)
405 X(weapon_priority_5_next)
406 X(weapon_priority_6_next)
407 X(weapon_priority_7_next)
408 X(weapon_priority_8_next)
409 X(weapon_priority_9_next)
410 X(weapon_priority_0_best)
411 X(weapon_priority_1_best)
412 X(weapon_priority_2_best)
413 X(weapon_priority_3_best)
414 X(weapon_priority_4_best)
415 X(weapon_priority_5_best)
416 X(weapon_priority_6_best)
417 X(weapon_priority_7_best)
418 X(weapon_priority_8_best)
419 X(weapon_priority_9_best)
450 if (vehicle_impulse(this, imp)) return;
452 if (CheatImpulse(this, imp)) return;
454 FOREACH(IMPULSES, it.impulse == imp, {
455 void(entity) f = it.impulse_handle;
467 IMPULSE(waypoint_personal_here)
469 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, this.origin, RADARICON_WAYPOINT);
470 if (wp) WaypointSprite_Ping(wp);
471 sprint(this, "personal waypoint spawned at location\n");
474 IMPULSE(waypoint_personal_crosshair)
476 WarpZone_crosshair_trace(this);
477 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, trace_endpos, RADARICON_WAYPOINT);
478 if (wp) WaypointSprite_Ping(wp);
479 sprint(this, "personal waypoint spawned at crosshair\n");
482 IMPULSE(waypoint_personal_death)
484 if (!this.death_origin) return;
485 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, this.death_origin, RADARICON_WAYPOINT);
486 if (wp) WaypointSprite_Ping(wp);
487 sprint(this, "personal waypoint spawned at death location\n");
490 IMPULSE(waypoint_here_follow)
492 if (!teamplay) return;
493 if (IS_DEAD(this)) return;
494 if (!MUTATOR_CALLHOOK(HelpMePing, this))
496 entity wp = WaypointSprite_Attach(WP_Helpme, this, true, RADARICON_HELPME);
497 if (!wp) WaypointSprite_HelpMePing(this.waypointsprite_attachedforcarrier);
498 else WaypointSprite_Ping(wp);
500 sprint(this, "HELP ME attached\n");
503 IMPULSE(waypoint_here_here)
505 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, this.origin, RADARICON_HERE);
506 if (wp) WaypointSprite_Ping(wp);
507 sprint(this, "HERE spawned at location\n");
510 IMPULSE(waypoint_here_crosshair)
512 WarpZone_crosshair_trace(this);
513 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, trace_endpos, RADARICON_HERE);
514 if (wp) WaypointSprite_Ping(wp);
515 sprint(this, "HERE spawned at crosshair\n");
518 IMPULSE(waypoint_here_death)
520 if (!this.death_origin) return;
521 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, this.death_origin, RADARICON_HERE);
522 if (wp) WaypointSprite_Ping(wp);
523 sprint(this, "HERE spawned at death location\n");
526 IMPULSE(waypoint_danger_here)
528 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, this.origin, RADARICON_DANGER);
529 if (wp) WaypointSprite_Ping(wp);
530 sprint(this, "DANGER spawned at location\n");
533 IMPULSE(waypoint_danger_crosshair)
535 WarpZone_crosshair_trace(this);
536 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, trace_endpos, RADARICON_DANGER);
537 if (wp) WaypointSprite_Ping(wp);
538 sprint(this, "DANGER spawned at crosshair\n");
541 IMPULSE(waypoint_danger_death)
543 if (!this.death_origin) return;
544 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, this.death_origin, RADARICON_DANGER);
545 if (wp) WaypointSprite_Ping(wp);
546 sprint(this, "DANGER spawned at death location\n");
549 IMPULSE(waypoint_clear_personal)
551 WaypointSprite_ClearPersonal(this);
554 delete(this.personal);
555 this.personal = NULL;
557 if((g_cts || g_race) && autocvar_g_allow_checkpoints)
560 sprint(this, "personal waypoint cleared\n");
563 IMPULSE(waypoint_clear)
565 WaypointSprite_ClearOwned(this);
568 delete(this.personal);
569 this.personal = NULL;
570 if((g_cts || g_race) && autocvar_g_allow_checkpoints)
573 sprint(this, "all waypoints cleared\n");
576 IMPULSE(navwaypoint_spawn)
578 if (!autocvar_g_waypointeditor) return;
579 waypoint_spawn_fromeditor(this);
582 IMPULSE(navwaypoint_remove)
584 if (!autocvar_g_waypointeditor) return;
585 waypoint_remove_fromeditor(this);
588 IMPULSE(navwaypoint_relink)
590 if (!autocvar_g_waypointeditor) return;
591 waypoint_schedulerelinkall();
594 IMPULSE(navwaypoint_save)
596 if (!autocvar_g_waypointeditor) return;
600 IMPULSE(navwaypoint_unreachable)
602 if (!autocvar_g_waypointeditor) return;
603 waypoint_unreachable(this);