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) \
56 if (IS_DEAD(this)) return; \
57 W_NextWeaponOnImpulse(slot); \
71 // custom order weapon cycling
73 #define X(slot, dir) \
74 IMPULSE(weapon_priority_##slot##_##dir) \
76 if (this.vehicle) return; \
77 if (IS_DEAD(this)) return; \
78 noref int prev = -1; \
80 noref int next = +1; \
81 W_CycleWeapon(this.cvar_cl_weaponpriorities[slot], dir); \
120 IMPULSE(weapon_byid_##i) \
122 if (this.vehicle) return; \
123 if (IS_DEAD(this)) return; \
124 W_SwitchWeapon(Weapons_from(WEP_FIRST + i)); \
152 IMPULSE(weapon_next_byid)
154 if (this.vehicle) return;
155 if (IS_DEAD(this)) return;
159 IMPULSE(weapon_prev_byid)
161 if (this.vehicle) return;
162 if (IS_DEAD(this)) return;
166 IMPULSE(weapon_next_bygroup)
168 if (this.vehicle) return;
169 if (IS_DEAD(this)) return;
173 IMPULSE(weapon_prev_bygroup)
175 if (this.vehicle) return;
176 if (IS_DEAD(this)) return;
180 IMPULSE(weapon_next_bypriority)
182 if (this.vehicle) return;
183 if (IS_DEAD(this)) return;
187 IMPULSE(weapon_prev_bypriority)
189 if (this.vehicle) return;
190 if (IS_DEAD(this)) return;
196 if (this.vehicle) return;
197 if (IS_DEAD(this)) return;
203 if (this.vehicle) return;
204 if (IS_DEAD(this)) return;
205 W_SwitchWeapon(w_getbestweapon(this));
210 if (this.vehicle) return;
211 if (IS_DEAD(this)) return;
212 W_ThrowWeapon(W_CalculateProjectileVelocity(this.velocity, v_forward * 750, false), '0 0 0', true);
215 IMPULSE(weapon_reload)
217 if (this.vehicle) return;
218 if (IS_DEAD(this)) return;
219 if (forbidWeaponUse(this)) return;
220 Weapon w = PS(this).m_weapon;
222 .entity weaponentity = weaponentities[0]; // TODO: unhardcode
223 w.wr_reload(w, actor, weaponentity);
226 void ImpulseCommands(entity this)
228 if (gameover) return;
230 int imp = this.impulse;
234 if (MinigameImpulse(this, imp)) return;
236 if (timeout_status == TIMEOUT_ACTIVE) return; // don't allow any impulses while the game is paused
238 // allow only weapon change impulses when not in round time
239 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
241 #define X(id) case IMP_##id.impulse:
256 X(weapon_next_bygroup)
257 X(weapon_prev_bygroup)
258 X(weapon_next_bypriority)
259 X(weapon_prev_bypriority)
263 X(weapon_priority_0_prev)
264 X(weapon_priority_1_prev)
265 X(weapon_priority_2_prev)
266 X(weapon_priority_3_prev)
267 X(weapon_priority_4_prev)
268 X(weapon_priority_5_prev)
269 X(weapon_priority_6_prev)
270 X(weapon_priority_7_prev)
271 X(weapon_priority_8_prev)
272 X(weapon_priority_9_prev)
273 X(weapon_priority_0_next)
274 X(weapon_priority_1_next)
275 X(weapon_priority_2_next)
276 X(weapon_priority_3_next)
277 X(weapon_priority_4_next)
278 X(weapon_priority_5_next)
279 X(weapon_priority_6_next)
280 X(weapon_priority_7_next)
281 X(weapon_priority_8_next)
282 X(weapon_priority_9_next)
283 X(weapon_priority_0_best)
284 X(weapon_priority_1_best)
285 X(weapon_priority_2_best)
286 X(weapon_priority_3_best)
287 X(weapon_priority_4_best)
288 X(weapon_priority_5_best)
289 X(weapon_priority_6_best)
290 X(weapon_priority_7_best)
291 X(weapon_priority_8_best)
292 X(weapon_priority_9_best)
323 if (vehicle_impulse(this, imp)) return;
325 if (CheatImpulse(imp)) return;
327 FOREACH(IMPULSES, it.impulse == imp, {
328 void(entity) f = it.impulse_handle;
340 IMPULSE(waypoint_personal_here)
342 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this.origin, RADARICON_WAYPOINT);
343 if (wp) WaypointSprite_Ping(wp);
344 sprint(this, "personal waypoint spawned at location\n");
347 IMPULSE(waypoint_personal_crosshair)
349 WarpZone_crosshair_trace(this);
350 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, trace_endpos, RADARICON_WAYPOINT);
351 if (wp) WaypointSprite_Ping(wp);
352 sprint(this, "personal waypoint spawned at crosshair\n");
355 IMPULSE(waypoint_personal_death)
357 if (!this.death_origin) return;
358 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this.death_origin, RADARICON_WAYPOINT);
359 if (wp) WaypointSprite_Ping(wp);
360 sprint(this, "personal waypoint spawned at death location\n");
363 IMPULSE(waypoint_here_follow)
365 if (!teamplay) return;
366 if (IS_DEAD(this)) return;
367 if (!MUTATOR_CALLHOOK(HelpMePing, this))
369 entity wp = WaypointSprite_Attach(WP_Helpme, true, RADARICON_HELPME);
370 if (!wp) WaypointSprite_HelpMePing(this.waypointsprite_attachedforcarrier);
371 else WaypointSprite_Ping(wp);
373 sprint(this, "HELP ME attached\n");
376 IMPULSE(waypoint_here_here)
378 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this.origin, RADARICON_HERE);
379 if (wp) WaypointSprite_Ping(wp);
380 sprint(this, "HERE spawned at location\n");
383 IMPULSE(waypoint_here_crosshair)
385 WarpZone_crosshair_trace(this);
386 entity wp = WaypointSprite_DeployFixed(WP_Here, false, trace_endpos, RADARICON_HERE);
387 if (wp) WaypointSprite_Ping(wp);
388 sprint(this, "HERE spawned at crosshair\n");
391 IMPULSE(waypoint_here_death)
393 if (!this.death_origin) return;
394 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this.death_origin, RADARICON_HERE);
395 if (wp) WaypointSprite_Ping(wp);
396 sprint(this, "HERE spawned at death location\n");
399 IMPULSE(waypoint_danger_here)
401 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this.origin, RADARICON_DANGER);
402 if (wp) WaypointSprite_Ping(wp);
403 sprint(this, "DANGER spawned at location\n");
406 IMPULSE(waypoint_danger_crosshair)
408 WarpZone_crosshair_trace(this);
409 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, trace_endpos, RADARICON_DANGER);
410 if (wp) WaypointSprite_Ping(wp);
411 sprint(this, "DANGER spawned at crosshair\n");
414 IMPULSE(waypoint_danger_death)
416 if (!this.death_origin) return;
417 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this.death_origin, RADARICON_DANGER);
418 if (wp) WaypointSprite_Ping(wp);
419 sprint(this, "DANGER spawned at death location\n");
422 IMPULSE(waypoint_clear_personal)
424 WaypointSprite_ClearPersonal();
427 remove(this.personal);
428 this.personal = NULL;
430 sprint(this, "personal waypoint cleared\n");
433 IMPULSE(waypoint_clear)
435 WaypointSprite_ClearOwned();
438 remove(this.personal);
439 this.personal = NULL;
441 sprint(this, "all waypoints cleared\n");
444 IMPULSE(navwaypoint_spawn)
446 if (!autocvar_g_waypointeditor) return;
447 waypoint_schedulerelink(waypoint_spawn(this.origin, this.origin, 0));
448 bprint(strcat("Waypoint spawned at ", vtos(this.origin), "\n"));
451 IMPULSE(navwaypoint_remove)
453 if (!autocvar_g_waypointeditor) return;
454 entity e = navigation_findnearestwaypoint(this, false);
456 if (e.wpflags & WAYPOINTFLAG_GENERATED) return;
457 bprint(strcat("Waypoint removed at ", vtos(e.origin), "\n"));
461 IMPULSE(navwaypoint_relink)
463 if (!autocvar_g_waypointeditor) return;
464 waypoint_schedulerelinkall();
467 IMPULSE(navwaypoint_save)
469 if (!autocvar_g_waypointeditor) return;
473 IMPULSE(navwaypoint_unreachable)
475 if (!autocvar_g_waypointeditor) return;
476 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
478 e.colormod = '0.5 0.5 0.5';
479 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
481 entity e2 = navigation_findnearestwaypoint(this, false);
482 navigation_markroutes(e2);
488 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
490 if (e.wpcost < 10000000) continue;
491 LOG_INFO("unreachable: ", etos(e), " ", vtos(e.origin), "\n");
493 e.effects |= EF_NODEPTHTEST | EF_BLUE;
497 if (i) LOG_INFOF("%d waypoints cannot be reached from here in any way (marked with blue light)\n", i);
498 navigation_markroutes_inverted(e2);
501 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
503 if (e.wpcost < 10000000) continue;
504 LOG_INFO("cannot reach me: ", etos(e), " ", vtos(e.origin), "\n");
506 if (!(e.effects & EF_NODEPTHTEST)) // not already reported before
508 e.effects |= EF_NODEPTHTEST | EF_RED;
511 if (i) LOG_INFOF("%d waypoints cannot walk to here in any way (marked with red light)\n", i);
512 if (m) LOG_INFOF("%d waypoints have been marked total\n", m);
515 for (entity e = findchain(classname, "info_player_deathmatch"); e; e = e.chain)
517 vector org = e.origin;
518 tracebox(e.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), e.origin - '0 0 512', MOVE_NOMONSTERS, world);
519 setorigin(e, trace_endpos);
520 if (navigation_findnearestwaypoint(e, false))
523 e.effects &= ~EF_NODEPTHTEST;
529 LOG_INFO("spawn without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
530 e.effects |= EF_NODEPTHTEST;
531 _setmodel(e, this.model);
532 e.frame = this.frame;
534 e.colormod = '8 0.5 8';
535 setsize(e, '0 0 0', '0 0 0');
539 if (i) LOG_INFOF("%d spawnpoints have no nearest waypoint (marked by player model)\n", i);
542 entity start = findchainflags(flags, FL_ITEM);
543 for (entity e = start; e; e = e.chain)
545 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
546 e.colormod = '0.5 0.5 0.5';
548 for (entity e = start; e; e = e.chain)
550 if (navigation_findnearestwaypoint(e, false)) continue;
551 LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
552 e.effects |= EF_NODEPTHTEST | EF_RED;
556 if (i) LOG_INFOF("%d items have no nearest waypoint and cannot be walked away from (marked with red light)\n", i);
559 for (entity e = start; e; e = e.chain)
561 if (navigation_findnearestwaypoint(e, true)) continue;
562 LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
563 e.effects |= EF_NODEPTHTEST | EF_BLUE;
567 if (i) LOG_INFOF("%d items have no nearest waypoint and cannot be walked to (marked with blue light)\n", i);