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 W_NextWeaponOnImpulse(this, slot); \
77 // custom order weapon cycling
79 #define X(slot, dir) \
80 IMPULSE(weapon_priority_##slot##_##dir) \
82 if (this.vehicle) return; \
85 this.impulse = IMP_weapon_priority_##slot##_##dir.impulse; \
88 noref int prev = -1; \
90 noref int next = +1; \
91 W_CycleWeapon(this, this.cvar_cl_weaponpriorities[slot], dir); \
130 IMPULSE(weapon_byid_##i) \
132 if (this.vehicle) return; \
135 this.impulse = IMP_weapon_byid_##i.impulse; \
138 W_SwitchWeapon(this, Weapons_from(WEP_FIRST + i)); \
166 IMPULSE(weapon_next_byid)
168 if (this.vehicle) return;
171 this.impulse = IMP_weapon_next_byid.impulse;
174 W_NextWeapon(this, 0);
177 IMPULSE(weapon_prev_byid)
179 if (this.vehicle) return;
182 this.impulse = IMP_weapon_prev_byid.impulse;
185 W_PreviousWeapon(this, 0);
188 IMPULSE(weapon_next_bygroup)
190 if (this.vehicle) return;
193 this.impulse = IMP_weapon_next_bygroup.impulse;
196 W_NextWeapon(this, 1);
199 IMPULSE(weapon_prev_bygroup)
201 if (this.vehicle) return;
204 this.impulse = IMP_weapon_prev_bygroup.impulse;
207 W_PreviousWeapon(this, 1);
210 IMPULSE(weapon_next_bypriority)
212 if (this.vehicle) return;
215 this.impulse = IMP_weapon_next_bypriority.impulse;
218 W_NextWeapon(this, 2);
221 IMPULSE(weapon_prev_bypriority)
223 if (this.vehicle) return;
226 this.impulse = IMP_weapon_prev_bypriority.impulse;
229 W_PreviousWeapon(this, 2);
234 if (this.vehicle) return;
235 if (IS_DEAD(this)) return;
241 if (this.vehicle) return;
242 if (IS_DEAD(this)) return;
243 W_SwitchWeapon(this, w_getbestweapon(this));
248 if (this.vehicle) return;
249 if (IS_DEAD(this)) return;
250 W_ThrowWeapon(this, weaponentities[0], W_CalculateProjectileVelocity(this, this.velocity, v_forward * 750, false), '0 0 0', true);
253 IMPULSE(weapon_reload)
255 if (this.vehicle) return;
256 if (IS_DEAD(this)) return;
257 if (forbidWeaponUse(this)) return;
258 Weapon w = PS(this).m_weapon;
260 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
262 .entity weaponentity = weaponentities[slot];
263 w.wr_reload(w, actor, weaponentity);
267 void ImpulseCommands(entity this)
269 if (gameover) return;
271 int imp = this.impulse;
275 if (MinigameImpulse(this, imp)) return;
277 if (timeout_status == TIMEOUT_ACTIVE) return; // don't allow any impulses while the game is paused
279 // allow only weapon change impulses when not in round time
280 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
282 #define X(id) case IMP_##id.impulse:
297 X(weapon_next_bygroup)
298 X(weapon_prev_bygroup)
299 X(weapon_next_bypriority)
300 X(weapon_prev_bypriority)
304 X(weapon_priority_0_prev)
305 X(weapon_priority_1_prev)
306 X(weapon_priority_2_prev)
307 X(weapon_priority_3_prev)
308 X(weapon_priority_4_prev)
309 X(weapon_priority_5_prev)
310 X(weapon_priority_6_prev)
311 X(weapon_priority_7_prev)
312 X(weapon_priority_8_prev)
313 X(weapon_priority_9_prev)
314 X(weapon_priority_0_next)
315 X(weapon_priority_1_next)
316 X(weapon_priority_2_next)
317 X(weapon_priority_3_next)
318 X(weapon_priority_4_next)
319 X(weapon_priority_5_next)
320 X(weapon_priority_6_next)
321 X(weapon_priority_7_next)
322 X(weapon_priority_8_next)
323 X(weapon_priority_9_next)
324 X(weapon_priority_0_best)
325 X(weapon_priority_1_best)
326 X(weapon_priority_2_best)
327 X(weapon_priority_3_best)
328 X(weapon_priority_4_best)
329 X(weapon_priority_5_best)
330 X(weapon_priority_6_best)
331 X(weapon_priority_7_best)
332 X(weapon_priority_8_best)
333 X(weapon_priority_9_best)
364 if (vehicle_impulse(this, imp)) return;
366 if (CheatImpulse(this, imp)) return;
368 FOREACH(IMPULSES, it.impulse == imp, {
369 void(entity) f = it.impulse_handle;
381 IMPULSE(waypoint_personal_here)
383 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, this.origin, RADARICON_WAYPOINT);
384 if (wp) WaypointSprite_Ping(wp);
385 sprint(this, "personal waypoint spawned at location\n");
388 IMPULSE(waypoint_personal_crosshair)
390 WarpZone_crosshair_trace(this);
391 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, trace_endpos, RADARICON_WAYPOINT);
392 if (wp) WaypointSprite_Ping(wp);
393 sprint(this, "personal waypoint spawned at crosshair\n");
396 IMPULSE(waypoint_personal_death)
398 if (!this.death_origin) return;
399 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, this.death_origin, RADARICON_WAYPOINT);
400 if (wp) WaypointSprite_Ping(wp);
401 sprint(this, "personal waypoint spawned at death location\n");
404 IMPULSE(waypoint_here_follow)
406 if (!teamplay) return;
407 if (IS_DEAD(this)) return;
408 if (!MUTATOR_CALLHOOK(HelpMePing, this))
410 entity wp = WaypointSprite_Attach(WP_Helpme, this, true, RADARICON_HELPME);
411 if (!wp) WaypointSprite_HelpMePing(this.waypointsprite_attachedforcarrier);
412 else WaypointSprite_Ping(wp);
414 sprint(this, "HELP ME attached\n");
417 IMPULSE(waypoint_here_here)
419 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, this.origin, RADARICON_HERE);
420 if (wp) WaypointSprite_Ping(wp);
421 sprint(this, "HERE spawned at location\n");
424 IMPULSE(waypoint_here_crosshair)
426 WarpZone_crosshair_trace(this);
427 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, trace_endpos, RADARICON_HERE);
428 if (wp) WaypointSprite_Ping(wp);
429 sprint(this, "HERE spawned at crosshair\n");
432 IMPULSE(waypoint_here_death)
434 if (!this.death_origin) return;
435 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, this.death_origin, RADARICON_HERE);
436 if (wp) WaypointSprite_Ping(wp);
437 sprint(this, "HERE spawned at death location\n");
440 IMPULSE(waypoint_danger_here)
442 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, this.origin, RADARICON_DANGER);
443 if (wp) WaypointSprite_Ping(wp);
444 sprint(this, "DANGER spawned at location\n");
447 IMPULSE(waypoint_danger_crosshair)
449 WarpZone_crosshair_trace(this);
450 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, trace_endpos, RADARICON_DANGER);
451 if (wp) WaypointSprite_Ping(wp);
452 sprint(this, "DANGER spawned at crosshair\n");
455 IMPULSE(waypoint_danger_death)
457 if (!this.death_origin) return;
458 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, this.death_origin, RADARICON_DANGER);
459 if (wp) WaypointSprite_Ping(wp);
460 sprint(this, "DANGER spawned at death location\n");
463 IMPULSE(waypoint_clear_personal)
465 WaypointSprite_ClearPersonal(this);
468 delete(this.personal);
469 this.personal = NULL;
471 sprint(this, "personal waypoint cleared\n");
474 IMPULSE(waypoint_clear)
476 WaypointSprite_ClearOwned(this);
479 delete(this.personal);
480 this.personal = NULL;
482 sprint(this, "all waypoints cleared\n");
485 IMPULSE(navwaypoint_spawn)
487 if (!autocvar_g_waypointeditor) return;
488 waypoint_schedulerelink(waypoint_spawn(this.origin, this.origin, 0));
489 bprint(strcat("Waypoint spawned at ", vtos(this.origin), "\n"));
492 IMPULSE(navwaypoint_remove)
494 if (!autocvar_g_waypointeditor) return;
495 entity e = navigation_findnearestwaypoint(this, false);
497 if (e.wpflags & WAYPOINTFLAG_GENERATED) return;
498 bprint(strcat("Waypoint removed at ", vtos(e.origin), "\n"));
502 IMPULSE(navwaypoint_relink)
504 if (!autocvar_g_waypointeditor) return;
505 waypoint_schedulerelinkall();
508 IMPULSE(navwaypoint_save)
510 if (!autocvar_g_waypointeditor) return;
514 IMPULSE(navwaypoint_unreachable)
516 if (!autocvar_g_waypointeditor) return;
517 IL_EACH(g_waypoints, true,
519 it.colormod = '0.5 0.5 0.5';
520 it.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
522 entity e2 = navigation_findnearestwaypoint(this, false);
523 navigation_markroutes(this, e2);
529 IL_EACH(g_waypoints, it.wpcost >= 10000000,
531 LOG_INFO("unreachable: ", etos(it), " ", vtos(it.origin), "\n");
533 it.effects |= EF_NODEPTHTEST | EF_BLUE;
537 if (j) LOG_INFOF("%d waypoints cannot be reached from here in any way (marked with blue light)\n", j);
538 navigation_markroutes_inverted(e2);
541 IL_EACH(g_waypoints, it.wpcost >= 10000000,
543 LOG_INFO("cannot reach me: ", etos(it), " ", vtos(it.origin), "\n");
545 if (!(it.effects & EF_NODEPTHTEST)) // not already reported before
547 it.effects |= EF_NODEPTHTEST | EF_RED;
550 if (j) LOG_INFOF("%d waypoints cannot walk to here in any way (marked with red light)\n", j);
551 if (m) LOG_INFOF("%d waypoints have been marked total\n", m);
554 IL_EACH(g_spawnpoints, true,
556 vector org = it.origin;
557 tracebox(it.origin, PL_MIN_CONST, PL_MAX_CONST, it.origin - '0 0 512', MOVE_NOMONSTERS, NULL);
558 setorigin(it, trace_endpos);
559 if (navigation_findnearestwaypoint(it, false))
562 it.effects &= ~EF_NODEPTHTEST;
568 LOG_INFO("spawn without waypoint: ", etos(it), " ", vtos(it.origin), "\n");
569 it.effects |= EF_NODEPTHTEST;
570 _setmodel(it, this.model);
571 it.frame = this.frame;
573 it.colormod = '8 0.5 8';
574 setsize(it, '0 0 0', '0 0 0');
578 if (j) LOG_INFOF("%d spawnpoints have no nearest waypoint (marked by player model)\n", j);
581 IL_EACH(g_items, true,
583 it.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
584 it.colormod = '0.5 0.5 0.5';
586 IL_EACH(g_items, true,
588 if (navigation_findnearestwaypoint(it, false)) continue;
589 LOG_INFO("item without waypoint: ", etos(it), " ", vtos(it.origin), "\n");
590 it.effects |= EF_NODEPTHTEST | EF_RED;
594 if (j) LOG_INFOF("%d items have no nearest waypoint and cannot be walked away from (marked with red light)\n", j);
597 IL_EACH(g_items, true,
599 if (navigation_findnearestwaypoint(it, true)) continue;
600 LOG_INFO("item without waypoint: ", etos(it), " ", vtos(it.origin), "\n");
601 it.effects |= EF_NODEPTHTEST | EF_BLUE;
605 if (j) LOG_INFOF("%d items have no nearest waypoint and cannot be walked to (marked with blue light)\n", j);