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 .entity weaponentity = weaponentities[0]; \
64 W_NextWeaponOnImpulse(this, slot, weaponentity); \
78 // custom order weapon cycling
80 #define X(slot, dir) \
81 IMPULSE(weapon_priority_##slot##_##dir) \
83 if (this.vehicle) return; \
86 this.impulse = IMP_weapon_priority_##slot##_##dir.impulse; \
89 noref int prev = -1; \
91 noref int next = +1; \
92 .entity weaponentity = weaponentities[0]; \
93 W_CycleWeapon(this, this.cvar_cl_weaponpriorities[slot], dir, weaponentity); \
132 IMPULSE(weapon_byid_##i) \
134 if (this.vehicle) return; \
137 this.impulse = IMP_weapon_byid_##i.impulse; \
140 .entity weaponentity = weaponentities[0]; \
141 W_SwitchWeapon(this, Weapons_from(WEP_FIRST + i), weaponentity); \
169 IMPULSE(weapon_next_byid)
171 if (this.vehicle) return;
174 this.impulse = IMP_weapon_next_byid.impulse;
177 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
178 W_NextWeapon(this, 0, weaponentity);
181 IMPULSE(weapon_prev_byid)
183 if (this.vehicle) return;
186 this.impulse = IMP_weapon_prev_byid.impulse;
189 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
190 W_PreviousWeapon(this, 0, weaponentity);
193 IMPULSE(weapon_next_bygroup)
195 if (this.vehicle) return;
198 this.impulse = IMP_weapon_next_bygroup.impulse;
201 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
202 W_NextWeapon(this, 1, weaponentity);
205 IMPULSE(weapon_prev_bygroup)
207 if (this.vehicle) return;
210 this.impulse = IMP_weapon_prev_bygroup.impulse;
213 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
214 W_PreviousWeapon(this, 1, weaponentity);
217 IMPULSE(weapon_next_bypriority)
219 if (this.vehicle) return;
222 this.impulse = IMP_weapon_next_bypriority.impulse;
225 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
226 W_NextWeapon(this, 2, weaponentity);
229 IMPULSE(weapon_prev_bypriority)
231 if (this.vehicle) return;
234 this.impulse = IMP_weapon_prev_bypriority.impulse;
237 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
238 W_PreviousWeapon(this, 2, weaponentity);
243 if (this.vehicle) return;
244 if (IS_DEAD(this)) return;
245 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
246 W_LastWeapon(this, weaponentity);
251 if (this.vehicle) return;
252 if (IS_DEAD(this)) return;
253 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
254 W_SwitchWeapon(this, w_getbestweapon(this, weaponentity), weaponentity);
259 if (this.vehicle) return;
260 if (IS_DEAD(this)) return;
261 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
262 W_ThrowWeapon(this, weaponentity, W_CalculateProjectileVelocity(this, this.velocity, v_forward * 750, false), '0 0 0', true);
265 IMPULSE(weapon_reload)
267 if (this.vehicle) return;
268 if (IS_DEAD(this)) return;
269 if (forbidWeaponUse(this)) return;
271 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
273 .entity weaponentity = weaponentities[slot];
274 Weapon w = this.(weaponentity).m_weapon;
275 w.wr_reload(w, actor, weaponentity);
279 void ImpulseCommands(entity this)
281 if (gameover) return;
283 int imp = this.impulse;
287 if (MinigameImpulse(this, imp)) return;
289 if (timeout_status == TIMEOUT_ACTIVE) return; // don't allow any impulses while the game is paused
291 // allow only weapon change impulses when not in round time
292 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
294 #define X(id) case IMP_##id.impulse:
309 X(weapon_next_bygroup)
310 X(weapon_prev_bygroup)
311 X(weapon_next_bypriority)
312 X(weapon_prev_bypriority)
316 X(weapon_priority_0_prev)
317 X(weapon_priority_1_prev)
318 X(weapon_priority_2_prev)
319 X(weapon_priority_3_prev)
320 X(weapon_priority_4_prev)
321 X(weapon_priority_5_prev)
322 X(weapon_priority_6_prev)
323 X(weapon_priority_7_prev)
324 X(weapon_priority_8_prev)
325 X(weapon_priority_9_prev)
326 X(weapon_priority_0_next)
327 X(weapon_priority_1_next)
328 X(weapon_priority_2_next)
329 X(weapon_priority_3_next)
330 X(weapon_priority_4_next)
331 X(weapon_priority_5_next)
332 X(weapon_priority_6_next)
333 X(weapon_priority_7_next)
334 X(weapon_priority_8_next)
335 X(weapon_priority_9_next)
336 X(weapon_priority_0_best)
337 X(weapon_priority_1_best)
338 X(weapon_priority_2_best)
339 X(weapon_priority_3_best)
340 X(weapon_priority_4_best)
341 X(weapon_priority_5_best)
342 X(weapon_priority_6_best)
343 X(weapon_priority_7_best)
344 X(weapon_priority_8_best)
345 X(weapon_priority_9_best)
376 if (vehicle_impulse(this, imp)) return;
378 if (CheatImpulse(this, imp)) return;
380 FOREACH(IMPULSES, it.impulse == imp, {
381 void(entity) f = it.impulse_handle;
393 IMPULSE(waypoint_personal_here)
395 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, this.origin, RADARICON_WAYPOINT);
396 if (wp) WaypointSprite_Ping(wp);
397 sprint(this, "personal waypoint spawned at location\n");
400 IMPULSE(waypoint_personal_crosshair)
402 WarpZone_crosshair_trace(this);
403 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, trace_endpos, RADARICON_WAYPOINT);
404 if (wp) WaypointSprite_Ping(wp);
405 sprint(this, "personal waypoint spawned at crosshair\n");
408 IMPULSE(waypoint_personal_death)
410 if (!this.death_origin) return;
411 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, this.death_origin, RADARICON_WAYPOINT);
412 if (wp) WaypointSprite_Ping(wp);
413 sprint(this, "personal waypoint spawned at death location\n");
416 IMPULSE(waypoint_here_follow)
418 if (!teamplay) return;
419 if (IS_DEAD(this)) return;
420 if (!MUTATOR_CALLHOOK(HelpMePing, this))
422 entity wp = WaypointSprite_Attach(WP_Helpme, this, true, RADARICON_HELPME);
423 if (!wp) WaypointSprite_HelpMePing(this.waypointsprite_attachedforcarrier);
424 else WaypointSprite_Ping(wp);
426 sprint(this, "HELP ME attached\n");
429 IMPULSE(waypoint_here_here)
431 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, this.origin, RADARICON_HERE);
432 if (wp) WaypointSprite_Ping(wp);
433 sprint(this, "HERE spawned at location\n");
436 IMPULSE(waypoint_here_crosshair)
438 WarpZone_crosshair_trace(this);
439 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, trace_endpos, RADARICON_HERE);
440 if (wp) WaypointSprite_Ping(wp);
441 sprint(this, "HERE spawned at crosshair\n");
444 IMPULSE(waypoint_here_death)
446 if (!this.death_origin) return;
447 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, this.death_origin, RADARICON_HERE);
448 if (wp) WaypointSprite_Ping(wp);
449 sprint(this, "HERE spawned at death location\n");
452 IMPULSE(waypoint_danger_here)
454 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, this.origin, RADARICON_DANGER);
455 if (wp) WaypointSprite_Ping(wp);
456 sprint(this, "DANGER spawned at location\n");
459 IMPULSE(waypoint_danger_crosshair)
461 WarpZone_crosshair_trace(this);
462 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, trace_endpos, RADARICON_DANGER);
463 if (wp) WaypointSprite_Ping(wp);
464 sprint(this, "DANGER spawned at crosshair\n");
467 IMPULSE(waypoint_danger_death)
469 if (!this.death_origin) return;
470 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, this.death_origin, RADARICON_DANGER);
471 if (wp) WaypointSprite_Ping(wp);
472 sprint(this, "DANGER spawned at death location\n");
475 IMPULSE(waypoint_clear_personal)
477 WaypointSprite_ClearPersonal(this);
480 delete(this.personal);
481 this.personal = NULL;
483 sprint(this, "personal waypoint cleared\n");
486 IMPULSE(waypoint_clear)
488 WaypointSprite_ClearOwned(this);
491 delete(this.personal);
492 this.personal = NULL;
494 sprint(this, "all waypoints cleared\n");
497 IMPULSE(navwaypoint_spawn)
499 if (!autocvar_g_waypointeditor) return;
500 waypoint_schedulerelink(waypoint_spawn(this.origin, this.origin, 0));
501 bprint(strcat("Waypoint spawned at ", vtos(this.origin), "\n"));
504 IMPULSE(navwaypoint_remove)
506 if (!autocvar_g_waypointeditor) return;
507 entity e = navigation_findnearestwaypoint(this, false);
509 if (e.wpflags & WAYPOINTFLAG_GENERATED) return;
510 bprint(strcat("Waypoint removed at ", vtos(e.origin), "\n"));
514 IMPULSE(navwaypoint_relink)
516 if (!autocvar_g_waypointeditor) return;
517 waypoint_schedulerelinkall();
520 IMPULSE(navwaypoint_save)
522 if (!autocvar_g_waypointeditor) return;
526 IMPULSE(navwaypoint_unreachable)
528 if (!autocvar_g_waypointeditor) return;
529 IL_EACH(g_waypoints, true,
531 it.colormod = '0.5 0.5 0.5';
532 it.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
534 entity e2 = navigation_findnearestwaypoint(this, false);
535 navigation_markroutes(this, e2);
541 IL_EACH(g_waypoints, it.wpcost >= 10000000,
543 LOG_INFO("unreachable: ", etos(it), " ", vtos(it.origin), "\n");
545 it.effects |= EF_NODEPTHTEST | EF_BLUE;
549 if (j) LOG_INFOF("%d waypoints cannot be reached from here in any way (marked with blue light)\n", j);
550 navigation_markroutes_inverted(e2);
553 IL_EACH(g_waypoints, it.wpcost >= 10000000,
555 LOG_INFO("cannot reach me: ", etos(it), " ", vtos(it.origin), "\n");
557 if (!(it.effects & EF_NODEPTHTEST)) // not already reported before
559 it.effects |= EF_NODEPTHTEST | EF_RED;
562 if (j) LOG_INFOF("%d waypoints cannot walk to here in any way (marked with red light)\n", j);
563 if (m) LOG_INFOF("%d waypoints have been marked total\n", m);
566 IL_EACH(g_spawnpoints, true,
568 vector org = it.origin;
569 tracebox(it.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - '0 0 512', MOVE_NOMONSTERS, NULL);
570 setorigin(it, trace_endpos);
571 if (navigation_findnearestwaypoint(it, false))
574 it.effects &= ~EF_NODEPTHTEST;
580 LOG_INFO("spawn without waypoint: ", etos(it), " ", vtos(it.origin), "\n");
581 it.effects |= EF_NODEPTHTEST;
582 _setmodel(it, this.model);
583 it.frame = this.frame;
585 it.colormod = '8 0.5 8';
586 setsize(it, '0 0 0', '0 0 0');
590 if (j) LOG_INFOF("%d spawnpoints have no nearest waypoint (marked by player model)\n", j);
593 IL_EACH(g_items, true,
595 it.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
596 it.colormod = '0.5 0.5 0.5';
598 IL_EACH(g_items, true,
600 if (navigation_findnearestwaypoint(it, false)) continue;
601 LOG_INFO("item without waypoint: ", etos(it), " ", vtos(it.origin), "\n");
602 it.effects |= EF_NODEPTHTEST | EF_RED;
606 if (j) LOG_INFOF("%d items have no nearest waypoint and cannot be walked away from (marked with red light)\n", j);
609 IL_EACH(g_items, true,
611 if (navigation_findnearestwaypoint(it, true)) continue;
612 LOG_INFO("item without waypoint: ", etos(it), " ", vtos(it.origin), "\n");
613 it.effects |= EF_NODEPTHTEST | EF_BLUE;
617 if (j) LOG_INFOF("%d items have no nearest waypoint and cannot be walked to (marked with blue light)\n", j);