1 #include "round_handler.qh"
3 #include "bot/waypoints.qh"
5 #include "weapons/throwing.qh"
6 #include "command/common.qh"
8 #include "bot/navigation.qh"
9 #include "weapons/selection.qh"
10 #include "weapons/tracing.qh"
11 #include "weapons/weaponsystem.qh"
13 #include "../common/minigames/sv_minigames.qh"
15 #include "../common/weapons/all.qh"
16 #include "../common/vehicles/sv_vehicles.qh"
18 #include "../common/mutators/mutator/waypoints/waypointsprites.qh"
22 #define IMPULSE(id) _IMPULSE(IMP_##id)
23 #define _IMPULSE(id) \
24 void id##_handle(entity this); \
25 STATIC_INIT_LATE(id) \
27 id.impulse_handle = id##_handle; \
29 void id##_handle(entity this)
34 * 0 reserved (no input)
41 * 143: emergency teleport
42 * 148: unfairly eliminate
45 * 200 to 209: prev weapon shortcuts
46 * 210 to 219: best weapon shortcuts
47 * 220 to 229: next weapon shortcuts
48 * 230 to 253: individual weapons (up to 24)
51 // weapon switching impulses
54 IMPULSE(weapon_group_##slot) \
58 this.impulse = IMP_weapon_group_##slot.impulse; \
61 W_NextWeaponOnImpulse(slot); \
75 // custom order weapon cycling
77 #define X(slot, dir) \
78 IMPULSE(weapon_priority_##slot##_##dir) \
80 if (this.vehicle) return; \
83 this.impulse = IMP_weapon_priority_##slot##_##dir.impulse; \
86 noref int prev = -1; \
88 noref int next = +1; \
89 W_CycleWeapon(this.cvar_cl_weaponpriorities[slot], dir); \
128 IMPULSE(weapon_byid_##i) \
130 if (this.vehicle) return; \
133 this.impulse = IMP_weapon_byid_##i.impulse; \
136 W_SwitchWeapon(Weapons_from(WEP_FIRST + i)); \
164 IMPULSE(weapon_next_byid)
166 if (this.vehicle) return;
169 this.impulse = IMP_weapon_next_byid.impulse;
175 IMPULSE(weapon_prev_byid)
177 if (this.vehicle) return;
180 this.impulse = IMP_weapon_prev_byid.impulse;
186 IMPULSE(weapon_next_bygroup)
188 if (this.vehicle) return;
191 this.impulse = IMP_weapon_next_bygroup.impulse;
197 IMPULSE(weapon_prev_bygroup)
199 if (this.vehicle) return;
202 this.impulse = IMP_weapon_prev_bygroup.impulse;
208 IMPULSE(weapon_next_bypriority)
210 if (this.vehicle) return;
213 this.impulse = IMP_weapon_next_bypriority.impulse;
219 IMPULSE(weapon_prev_bypriority)
221 if (this.vehicle) return;
224 this.impulse = IMP_weapon_prev_bypriority.impulse;
232 if (this.vehicle) return;
233 if (IS_DEAD(this)) return;
239 if (this.vehicle) return;
240 if (IS_DEAD(this)) return;
241 W_SwitchWeapon(w_getbestweapon(this));
246 if (this.vehicle) return;
247 if (IS_DEAD(this)) return;
248 W_ThrowWeapon(W_CalculateProjectileVelocity(this.velocity, v_forward * 750, false), '0 0 0', true);
251 IMPULSE(weapon_reload)
253 if (this.vehicle) return;
254 if (IS_DEAD(this)) return;
255 if (forbidWeaponUse(this)) return;
256 Weapon w = PS(this).m_weapon;
258 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
259 w.wr_reload(w, actor, weaponentity);
262 void ImpulseCommands(entity this)
264 if (gameover) return;
266 int imp = this.impulse;
270 if (MinigameImpulse(this, imp)) return;
272 if (timeout_status == TIMEOUT_ACTIVE) return; // don't allow any impulses while the game is paused
274 // allow only weapon change impulses when not in round time
275 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
277 #define X(id) case IMP_##id.impulse:
292 X(weapon_next_bygroup)
293 X(weapon_prev_bygroup)
294 X(weapon_next_bypriority)
295 X(weapon_prev_bypriority)
299 X(weapon_priority_0_prev)
300 X(weapon_priority_1_prev)
301 X(weapon_priority_2_prev)
302 X(weapon_priority_3_prev)
303 X(weapon_priority_4_prev)
304 X(weapon_priority_5_prev)
305 X(weapon_priority_6_prev)
306 X(weapon_priority_7_prev)
307 X(weapon_priority_8_prev)
308 X(weapon_priority_9_prev)
309 X(weapon_priority_0_next)
310 X(weapon_priority_1_next)
311 X(weapon_priority_2_next)
312 X(weapon_priority_3_next)
313 X(weapon_priority_4_next)
314 X(weapon_priority_5_next)
315 X(weapon_priority_6_next)
316 X(weapon_priority_7_next)
317 X(weapon_priority_8_next)
318 X(weapon_priority_9_next)
319 X(weapon_priority_0_best)
320 X(weapon_priority_1_best)
321 X(weapon_priority_2_best)
322 X(weapon_priority_3_best)
323 X(weapon_priority_4_best)
324 X(weapon_priority_5_best)
325 X(weapon_priority_6_best)
326 X(weapon_priority_7_best)
327 X(weapon_priority_8_best)
328 X(weapon_priority_9_best)
359 if (vehicle_impulse(this, imp)) return;
361 if (CheatImpulse(imp)) return;
363 FOREACH(IMPULSES, it.impulse == imp, {
364 void(entity) f = it.impulse_handle;
376 IMPULSE(waypoint_personal_here)
378 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this.origin, RADARICON_WAYPOINT);
379 if (wp) WaypointSprite_Ping(wp);
380 sprint(this, "personal waypoint spawned at location\n");
383 IMPULSE(waypoint_personal_crosshair)
385 WarpZone_crosshair_trace(this);
386 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, trace_endpos, RADARICON_WAYPOINT);
387 if (wp) WaypointSprite_Ping(wp);
388 sprint(this, "personal waypoint spawned at crosshair\n");
391 IMPULSE(waypoint_personal_death)
393 if (!this.death_origin) return;
394 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this.death_origin, RADARICON_WAYPOINT);
395 if (wp) WaypointSprite_Ping(wp);
396 sprint(this, "personal waypoint spawned at death location\n");
399 IMPULSE(waypoint_here_follow)
401 if (!teamplay) return;
402 if (IS_DEAD(this)) return;
403 if (!MUTATOR_CALLHOOK(HelpMePing, this))
405 entity wp = WaypointSprite_Attach(WP_Helpme, true, RADARICON_HELPME);
406 if (!wp) WaypointSprite_HelpMePing(this.waypointsprite_attachedforcarrier);
407 else WaypointSprite_Ping(wp);
409 sprint(this, "HELP ME attached\n");
412 IMPULSE(waypoint_here_here)
414 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this.origin, RADARICON_HERE);
415 if (wp) WaypointSprite_Ping(wp);
416 sprint(this, "HERE spawned at location\n");
419 IMPULSE(waypoint_here_crosshair)
421 WarpZone_crosshair_trace(this);
422 entity wp = WaypointSprite_DeployFixed(WP_Here, false, trace_endpos, RADARICON_HERE);
423 if (wp) WaypointSprite_Ping(wp);
424 sprint(this, "HERE spawned at crosshair\n");
427 IMPULSE(waypoint_here_death)
429 if (!this.death_origin) return;
430 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this.death_origin, RADARICON_HERE);
431 if (wp) WaypointSprite_Ping(wp);
432 sprint(this, "HERE spawned at death location\n");
435 IMPULSE(waypoint_danger_here)
437 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this.origin, RADARICON_DANGER);
438 if (wp) WaypointSprite_Ping(wp);
439 sprint(this, "DANGER spawned at location\n");
442 IMPULSE(waypoint_danger_crosshair)
444 WarpZone_crosshair_trace(this);
445 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, trace_endpos, RADARICON_DANGER);
446 if (wp) WaypointSprite_Ping(wp);
447 sprint(this, "DANGER spawned at crosshair\n");
450 IMPULSE(waypoint_danger_death)
452 if (!this.death_origin) return;
453 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this.death_origin, RADARICON_DANGER);
454 if (wp) WaypointSprite_Ping(wp);
455 sprint(this, "DANGER spawned at death location\n");
458 IMPULSE(waypoint_clear_personal)
460 WaypointSprite_ClearPersonal();
463 remove(this.personal);
464 this.personal = NULL;
466 sprint(this, "personal waypoint cleared\n");
469 IMPULSE(waypoint_clear)
471 WaypointSprite_ClearOwned();
474 remove(this.personal);
475 this.personal = NULL;
477 sprint(this, "all waypoints cleared\n");
480 IMPULSE(navwaypoint_spawn)
482 if (!autocvar_g_waypointeditor) return;
483 waypoint_schedulerelink(waypoint_spawn(this.origin, this.origin, 0));
484 bprint(strcat("Waypoint spawned at ", vtos(this.origin), "\n"));
487 IMPULSE(navwaypoint_remove)
489 if (!autocvar_g_waypointeditor) return;
490 entity e = navigation_findnearestwaypoint(this, false);
492 if (e.wpflags & WAYPOINTFLAG_GENERATED) return;
493 bprint(strcat("Waypoint removed at ", vtos(e.origin), "\n"));
497 IMPULSE(navwaypoint_relink)
499 if (!autocvar_g_waypointeditor) return;
500 waypoint_schedulerelinkall();
503 IMPULSE(navwaypoint_save)
505 if (!autocvar_g_waypointeditor) return;
509 IMPULSE(navwaypoint_unreachable)
511 if (!autocvar_g_waypointeditor) return;
512 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
514 e.colormod = '0.5 0.5 0.5';
515 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
517 entity e2 = navigation_findnearestwaypoint(this, false);
518 navigation_markroutes(e2);
524 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
526 if (e.wpcost < 10000000) continue;
527 LOG_INFO("unreachable: ", etos(e), " ", vtos(e.origin), "\n");
529 e.effects |= EF_NODEPTHTEST | EF_BLUE;
533 if (i) LOG_INFOF("%d waypoints cannot be reached from here in any way (marked with blue light)\n", i);
534 navigation_markroutes_inverted(e2);
537 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
539 if (e.wpcost < 10000000) continue;
540 LOG_INFO("cannot reach me: ", etos(e), " ", vtos(e.origin), "\n");
542 if (!(e.effects & EF_NODEPTHTEST)) // not already reported before
544 e.effects |= EF_NODEPTHTEST | EF_RED;
547 if (i) LOG_INFOF("%d waypoints cannot walk to here in any way (marked with red light)\n", i);
548 if (m) LOG_INFOF("%d waypoints have been marked total\n", m);
551 for (entity e = findchain(classname, "info_player_deathmatch"); e; e = e.chain)
553 vector org = e.origin;
554 tracebox(e.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), e.origin - '0 0 512', MOVE_NOMONSTERS, world);
555 setorigin(e, trace_endpos);
556 if (navigation_findnearestwaypoint(e, false))
559 e.effects &= ~EF_NODEPTHTEST;
565 LOG_INFO("spawn without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
566 e.effects |= EF_NODEPTHTEST;
567 _setmodel(e, this.model);
568 e.frame = this.frame;
570 e.colormod = '8 0.5 8';
571 setsize(e, '0 0 0', '0 0 0');
575 if (i) LOG_INFOF("%d spawnpoints have no nearest waypoint (marked by player model)\n", i);
578 entity start = findchainflags(flags, FL_ITEM);
579 for (entity e = start; e; e = e.chain)
581 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
582 e.colormod = '0.5 0.5 0.5';
584 for (entity e = start; e; e = e.chain)
586 if (navigation_findnearestwaypoint(e, false)) continue;
587 LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
588 e.effects |= EF_NODEPTHTEST | EF_RED;
592 if (i) LOG_INFOF("%d items have no nearest waypoint and cannot be walked away from (marked with red light)\n", i);
595 for (entity e = start; e; e = e.chain)
597 if (navigation_findnearestwaypoint(e, true)) continue;
598 LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
599 e.effects |= EF_NODEPTHTEST | EF_BLUE;
603 if (i) LOG_INFOF("%d items have no nearest waypoint and cannot be walked to (marked with blue light)\n", i);