1 #include "cl_impulse.qh"
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, 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 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
261 w.wr_reload(w, actor, weaponentity);
264 void ImpulseCommands(entity this)
266 if (gameover) return;
268 int imp = this.impulse;
272 if (MinigameImpulse(this, imp)) return;
274 if (timeout_status == TIMEOUT_ACTIVE) return; // don't allow any impulses while the game is paused
276 // allow only weapon change impulses when not in round time
277 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
279 #define X(id) case IMP_##id.impulse:
294 X(weapon_next_bygroup)
295 X(weapon_prev_bygroup)
296 X(weapon_next_bypriority)
297 X(weapon_prev_bypriority)
301 X(weapon_priority_0_prev)
302 X(weapon_priority_1_prev)
303 X(weapon_priority_2_prev)
304 X(weapon_priority_3_prev)
305 X(weapon_priority_4_prev)
306 X(weapon_priority_5_prev)
307 X(weapon_priority_6_prev)
308 X(weapon_priority_7_prev)
309 X(weapon_priority_8_prev)
310 X(weapon_priority_9_prev)
311 X(weapon_priority_0_next)
312 X(weapon_priority_1_next)
313 X(weapon_priority_2_next)
314 X(weapon_priority_3_next)
315 X(weapon_priority_4_next)
316 X(weapon_priority_5_next)
317 X(weapon_priority_6_next)
318 X(weapon_priority_7_next)
319 X(weapon_priority_8_next)
320 X(weapon_priority_9_next)
321 X(weapon_priority_0_best)
322 X(weapon_priority_1_best)
323 X(weapon_priority_2_best)
324 X(weapon_priority_3_best)
325 X(weapon_priority_4_best)
326 X(weapon_priority_5_best)
327 X(weapon_priority_6_best)
328 X(weapon_priority_7_best)
329 X(weapon_priority_8_best)
330 X(weapon_priority_9_best)
361 if (vehicle_impulse(this, imp)) return;
363 if (CheatImpulse(this, imp)) return;
365 FOREACH(IMPULSES, it.impulse == imp, {
366 void(entity) f = it.impulse_handle;
378 IMPULSE(waypoint_personal_here)
380 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, this.origin, RADARICON_WAYPOINT);
381 if (wp) WaypointSprite_Ping(wp);
382 sprint(this, "personal waypoint spawned at location\n");
385 IMPULSE(waypoint_personal_crosshair)
387 WarpZone_crosshair_trace(this);
388 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, trace_endpos, RADARICON_WAYPOINT);
389 if (wp) WaypointSprite_Ping(wp);
390 sprint(this, "personal waypoint spawned at crosshair\n");
393 IMPULSE(waypoint_personal_death)
395 if (!this.death_origin) return;
396 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, this.death_origin, RADARICON_WAYPOINT);
397 if (wp) WaypointSprite_Ping(wp);
398 sprint(this, "personal waypoint spawned at death location\n");
401 IMPULSE(waypoint_here_follow)
403 if (!teamplay) return;
404 if (IS_DEAD(this)) return;
405 if (!MUTATOR_CALLHOOK(HelpMePing, this))
407 entity wp = WaypointSprite_Attach(WP_Helpme, this, true, RADARICON_HELPME);
408 if (!wp) WaypointSprite_HelpMePing(this.waypointsprite_attachedforcarrier);
409 else WaypointSprite_Ping(wp);
411 sprint(this, "HELP ME attached\n");
414 IMPULSE(waypoint_here_here)
416 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, this.origin, RADARICON_HERE);
417 if (wp) WaypointSprite_Ping(wp);
418 sprint(this, "HERE spawned at location\n");
421 IMPULSE(waypoint_here_crosshair)
423 WarpZone_crosshair_trace(this);
424 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, trace_endpos, RADARICON_HERE);
425 if (wp) WaypointSprite_Ping(wp);
426 sprint(this, "HERE spawned at crosshair\n");
429 IMPULSE(waypoint_here_death)
431 if (!this.death_origin) return;
432 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, this.death_origin, RADARICON_HERE);
433 if (wp) WaypointSprite_Ping(wp);
434 sprint(this, "HERE spawned at death location\n");
437 IMPULSE(waypoint_danger_here)
439 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, this.origin, RADARICON_DANGER);
440 if (wp) WaypointSprite_Ping(wp);
441 sprint(this, "DANGER spawned at location\n");
444 IMPULSE(waypoint_danger_crosshair)
446 WarpZone_crosshair_trace(this);
447 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, trace_endpos, RADARICON_DANGER);
448 if (wp) WaypointSprite_Ping(wp);
449 sprint(this, "DANGER spawned at crosshair\n");
452 IMPULSE(waypoint_danger_death)
454 if (!this.death_origin) return;
455 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, this.death_origin, RADARICON_DANGER);
456 if (wp) WaypointSprite_Ping(wp);
457 sprint(this, "DANGER spawned at death location\n");
460 IMPULSE(waypoint_clear_personal)
462 WaypointSprite_ClearPersonal(this);
465 delete(this.personal);
466 this.personal = NULL;
468 sprint(this, "personal waypoint cleared\n");
471 IMPULSE(waypoint_clear)
473 WaypointSprite_ClearOwned(this);
476 delete(this.personal);
477 this.personal = NULL;
479 sprint(this, "all waypoints cleared\n");
482 IMPULSE(navwaypoint_spawn)
484 if (!autocvar_g_waypointeditor) return;
485 waypoint_schedulerelink(waypoint_spawn(this.origin, this.origin, 0));
486 bprint(strcat("Waypoint spawned at ", vtos(this.origin), "\n"));
489 IMPULSE(navwaypoint_remove)
491 if (!autocvar_g_waypointeditor) return;
492 entity e = navigation_findnearestwaypoint(this, false);
494 if (e.wpflags & WAYPOINTFLAG_GENERATED) return;
495 bprint(strcat("Waypoint removed at ", vtos(e.origin), "\n"));
499 IMPULSE(navwaypoint_relink)
501 if (!autocvar_g_waypointeditor) return;
502 waypoint_schedulerelinkall();
505 IMPULSE(navwaypoint_save)
507 if (!autocvar_g_waypointeditor) return;
511 IMPULSE(navwaypoint_unreachable)
513 if (!autocvar_g_waypointeditor) return;
514 IL_EACH(g_waypoints, true,
516 it.colormod = '0.5 0.5 0.5';
517 it.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
519 entity e2 = navigation_findnearestwaypoint(this, false);
520 navigation_markroutes(this, e2);
526 IL_EACH(g_waypoints, it.wpcost >= 10000000,
528 LOG_INFO("unreachable: ", etos(it), " ", vtos(it.origin), "\n");
530 it.effects |= EF_NODEPTHTEST | EF_BLUE;
534 if (j) LOG_INFOF("%d waypoints cannot be reached from here in any way (marked with blue light)\n", j);
535 navigation_markroutes_inverted(e2);
538 IL_EACH(g_waypoints, it.wpcost >= 10000000,
540 LOG_INFO("cannot reach me: ", etos(it), " ", vtos(it.origin), "\n");
542 if (!(it.effects & EF_NODEPTHTEST)) // not already reported before
544 it.effects |= EF_NODEPTHTEST | EF_RED;
547 if (j) LOG_INFOF("%d waypoints cannot walk to here in any way (marked with red light)\n", j);
548 if (m) LOG_INFOF("%d waypoints have been marked total\n", m);
551 FOREACH_ENTITY_CLASS("info_player_deathmatch", true,
553 vector org = it.origin;
554 tracebox(it.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - '0 0 512', MOVE_NOMONSTERS, NULL);
555 setorigin(it, trace_endpos);
556 if (navigation_findnearestwaypoint(it, false))
559 it.effects &= ~EF_NODEPTHTEST;
565 LOG_INFO("spawn without waypoint: ", etos(it), " ", vtos(it.origin), "\n");
566 it.effects |= EF_NODEPTHTEST;
567 _setmodel(it, this.model);
568 it.frame = this.frame;
570 it.colormod = '8 0.5 8';
571 setsize(it, '0 0 0', '0 0 0');
575 if (j) LOG_INFOF("%d spawnpoints have no nearest waypoint (marked by player model)\n", j);
578 FOREACH_ENTITY_FLAGS(flags, FL_ITEM,
580 it.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
581 it.colormod = '0.5 0.5 0.5';
583 FOREACH_ENTITY_FLAGS(flags, FL_ITEM,
585 if (navigation_findnearestwaypoint(it, false)) continue;
586 LOG_INFO("item without waypoint: ", etos(it), " ", vtos(it.origin), "\n");
587 it.effects |= EF_NODEPTHTEST | EF_RED;
591 if (j) LOG_INFOF("%d items have no nearest waypoint and cannot be walked away from (marked with red light)\n", j);
594 FOREACH_ENTITY_FLAGS(flags, FL_ITEM,
596 if (navigation_findnearestwaypoint(it, true)) continue;
597 LOG_INFO("item without waypoint: ", etos(it), " ", vtos(it.origin), "\n");
598 it.effects |= EF_NODEPTHTEST | EF_BLUE;
602 if (j) LOG_INFOF("%d items have no nearest waypoint and cannot be walked to (marked with blue light)\n", j);