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 REGISTRY(IMPULSES, 255)
23 REGISTER_REGISTRY(IMPULSES)
24 REGISTRY_SORT(IMPULSES)
25 STATIC_INIT(IMPULSES_renumber)
27 FOREACH(IMPULSES, true, LAMBDA(it.m_id = i));
29 REGISTRY_CHECK(IMPULSES)
31 .void(entity this) impulse_handle;
33 #define IMPULSE(id, n) _IMPULSE(IMP_##id, n)
34 #define _IMPULSE(id, n) \
35 void id##_handle(entity this); \
36 REGISTER(IMPULSES, id, m_id, new(Impulse)) \
40 this.impulse_handle = id##_handle; \
42 void id##_handle(entity this)
47 * 0 reserved (no input)
54 * 143: emergency teleport
55 * 148: unfairly eliminate
58 * 200 to 209: prev weapon shortcuts
59 * 210 to 219: best weapon shortcuts
60 * 220 to 229: next weapon shortcuts
61 * 230 to 253: individual weapons (up to 24)
64 // weapon switching impulses
66 #define X(slot, imp) \
67 IMPULSE(weapon_group_##slot, imp) \
69 if (this.deadflag != DEAD_NO) return; \
70 W_NextWeaponOnImpulse(slot); \
84 IMPULSE(weapon_next_byid, 10)
86 if (this.vehicle) return;
87 if (this.deadflag != DEAD_NO) return;
91 IMPULSE(weapon_prev_byid, 12)
93 if (this.vehicle) return;
94 if (this.deadflag != DEAD_NO) return;
98 IMPULSE(weapon_next_bygroup, 18)
100 if (this.vehicle) return;
101 if (this.deadflag != DEAD_NO) return;
104 IMPULSE(weapon_prev_bygroup, 19)
106 if (this.vehicle) return;
107 if (this.deadflag != DEAD_NO) return;
111 IMPULSE(weapon_next_bypriority, 15)
113 if (this.vehicle) return;
114 if (this.deadflag != DEAD_NO) return;
117 IMPULSE(weapon_prev_bypriority, 16)
119 if (this.vehicle) return;
120 if (this.deadflag != DEAD_NO) return;
124 IMPULSE(weapon_last, 11)
126 if (this.vehicle) return;
127 if (this.deadflag != DEAD_NO) return;
131 IMPULSE(weapon_best, 13)
133 if (this.vehicle) return;
134 if (this.deadflag != DEAD_NO) return;
135 W_SwitchWeapon(w_getbestweapon(this));
138 IMPULSE(weapon_throw, 17)
140 if (this.vehicle) return;
141 if (this.deadflag != DEAD_NO) return;
142 W_ThrowWeapon(W_CalculateProjectileVelocity(this.velocity, v_forward * 750, false), '0 0 0', true);
145 IMPULSE(weapon_reload, 20)
147 if (this.vehicle) return;
148 if (this.deadflag != DEAD_NO) return;
149 if (forbidWeaponUse(this)) return;
150 Weapon w = Weapons_from(this.weapon);
154 void ImpulseCommands(entity this)
156 if (gameover) return;
158 int imp = this.impulse;
162 if (this.active_minigame && MinigameImpulse(imp)) return;
164 if (timeout_status == TIMEOUT_ACTIVE) return; // don't allow any impulses while the game is paused
166 // allow only weapon change impulses when not in round time
167 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
168 if (imp == 17 || (imp >= 20 && imp < 200) || imp > 253) return;
170 if (this.vehicle && this.vehicle.deadflag == DEAD_NO)
172 bool(int) f = this.vehicle.vehicles_impulse;
173 if (f && f(imp)) return;
174 if (vehicle_impulse(imp)) return;
177 if (CheatImpulse(imp)) return;
179 FOREACH(IMPULSES, it.impulse == imp, {
180 it.impulse_handle(this);
184 if (imp >= 200 && imp <= 229)
186 if (!this.vehicle && this.deadflag == DEAD_NO)
188 // custom order weapon cycling
190 int m = (imp - (210 + i)); // <0 for prev, =0 for best, >0 for next
191 W_CycleWeapon(this.(cvar_cl_weaponpriorities[i]), m);
193 // else // don't retry, as this can break weaplast bind
194 // this.impulse = imp; // retry in next frame
196 else if (imp >= WEP_IMPULSE_BEGIN && imp <= WEP_IMPULSE_END)
198 if (!this.vehicle && this.deadflag == DEAD_NO) W_SwitchWeapon(imp - WEP_IMPULSE_BEGIN + WEP_FIRST);
199 // else // don't retry, as this can break weaplast bind
200 // this.impulse = imp; // retry in next frame
209 IMPULSE(waypoint_personal_here, 30)
211 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this.origin, RADARICON_WAYPOINT);
212 if (wp) WaypointSprite_Ping(wp);
213 sprint(this, "personal waypoint spawned at location\n");
216 IMPULSE(waypoint_personal_crosshair, 31)
218 WarpZone_crosshair_trace(this);
219 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, trace_endpos, RADARICON_WAYPOINT);
220 if (wp) WaypointSprite_Ping(wp);
221 sprint(this, "personal waypoint spawned at crosshair\n");
224 IMPULSE(waypoint_personal_death, 32)
226 if (!this.death_origin) return;
227 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this.death_origin, RADARICON_WAYPOINT);
228 if (wp) WaypointSprite_Ping(wp);
229 sprint(this, "personal waypoint spawned at death location\n");
232 IMPULSE(waypoint_here_follow, 33)
234 if (!teamplay) return;
235 if (this.deadflag != DEAD_NO) return;
236 if (!MUTATOR_CALLHOOK(HelpMePing, this))
238 entity wp = WaypointSprite_Attach(WP_Helpme, true, RADARICON_HELPME);
239 if (!wp) WaypointSprite_HelpMePing(this.waypointsprite_attachedforcarrier);
240 else WaypointSprite_Ping(wp);
242 sprint(this, "HELP ME attached\n");
245 IMPULSE(waypoint_here_here, 34)
247 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this.origin, RADARICON_HERE);
248 if (wp) WaypointSprite_Ping(wp);
249 sprint(this, "HERE spawned at location\n");
252 IMPULSE(waypoint_here_crosshair, 35)
254 WarpZone_crosshair_trace(this);
255 entity wp = WaypointSprite_DeployFixed(WP_Here, false, trace_endpos, RADARICON_HERE);
256 if (wp) WaypointSprite_Ping(wp);
257 sprint(this, "HERE spawned at crosshair\n");
260 IMPULSE(waypoint_here_death, 36)
262 if (!this.death_origin) return;
263 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this.death_origin, RADARICON_HERE);
264 if (wp) WaypointSprite_Ping(wp);
265 sprint(this, "HERE spawned at death location\n");
268 IMPULSE(waypoint_danger_here, 37)
270 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this.origin, RADARICON_DANGER);
271 if (wp) WaypointSprite_Ping(wp);
272 sprint(this, "DANGER spawned at location\n");
275 IMPULSE(waypoint_danger_crosshair, 38)
277 WarpZone_crosshair_trace(this);
278 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, trace_endpos, RADARICON_DANGER);
279 if (wp) WaypointSprite_Ping(wp);
280 sprint(this, "DANGER spawned at crosshair\n");
283 IMPULSE(waypoint_danger_death, 39)
285 if (!this.death_origin) return;
286 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this.death_origin, RADARICON_DANGER);
287 if (wp) WaypointSprite_Ping(wp);
288 sprint(this, "DANGER spawned at death location\n");
291 IMPULSE(waypoint_clear_personal, 47)
293 WaypointSprite_ClearPersonal();
296 remove(this.personal);
297 this.personal = NULL;
299 sprint(this, "personal waypoint cleared\n");
302 IMPULSE(waypoint_clear_team, 48)
304 WaypointSprite_ClearOwned();
307 remove(this.personal);
308 this.personal = NULL;
310 sprint(this, "all waypoints cleared\n");
313 IMPULSE(navwaypoint_spawn, 103)
315 if (!autocvar_g_waypointeditor) return;
316 waypoint_schedulerelink(waypoint_spawn(this.origin, this.origin, 0));
317 bprint(strcat("Waypoint spawned at ", vtos(this.origin), "\n"));
320 IMPULSE(navwaypoint_remove, 104)
322 if (!autocvar_g_waypointeditor) return;
323 entity e = navigation_findnearestwaypoint(this, false);
325 if (e.wpflags & WAYPOINTFLAG_GENERATED) return;
326 bprint(strcat("Waypoint removed at ", vtos(e.origin), "\n"));
330 IMPULSE(navwaypoint_relink, 105)
332 if (!autocvar_g_waypointeditor) return;
333 waypoint_schedulerelinkall();
336 IMPULSE(navwaypoint_save, 106)
338 if (!autocvar_g_waypointeditor) return;
342 IMPULSE(navwaypoint_debug, 107)
344 if (!autocvar_g_waypointeditor) return;
345 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
347 e.colormod = '0.5 0.5 0.5';
348 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
350 entity e2 = navigation_findnearestwaypoint(this, false);
351 navigation_markroutes(e2);
357 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
359 if (e.wpcost < 10000000) continue;
360 LOG_INFO("unreachable: ", etos(e), " ", vtos(e.origin), "\n");
362 e.effects |= EF_NODEPTHTEST | EF_BLUE;
366 if (i) LOG_INFOF("%d waypoints cannot be reached from here in any way (marked with blue light)\n", i);
367 navigation_markroutes_inverted(e2);
370 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
372 if (e.wpcost < 10000000) continue;
373 LOG_INFO("cannot reach me: ", etos(e), " ", vtos(e.origin), "\n");
375 if (!(e.effects & EF_NODEPTHTEST)) // not already reported before
377 e.effects |= EF_NODEPTHTEST | EF_RED;
380 if (i) LOG_INFOF("%d waypoints cannot walk to here in any way (marked with red light)\n", i);
381 if (m) LOG_INFOF("%d waypoints have been marked total\n", m);
384 for (entity e = findchain(classname, "info_player_deathmatch"); e; e = e.chain)
386 vector org = e.origin;
387 tracebox(e.origin, PL_MIN, PL_MAX, e.origin - '0 0 512', MOVE_NOMONSTERS, world);
388 setorigin(e, trace_endpos);
389 if (navigation_findnearestwaypoint(e, false))
392 e.effects &= ~EF_NODEPTHTEST;
398 LOG_INFO("spawn without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
399 e.effects |= EF_NODEPTHTEST;
400 _setmodel(e, this.model);
401 e.frame = this.frame;
403 e.colormod = '8 0.5 8';
404 setsize(e, '0 0 0', '0 0 0');
408 if (i) LOG_INFOF("%d spawnpoints have no nearest waypoint (marked by player model)\n", i);
411 entity start = findchainflags(flags, FL_ITEM);
412 for (entity e = start; e; e = e.chain)
414 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
415 e.colormod = '0.5 0.5 0.5';
417 for (entity e = start; e; e = e.chain)
419 if (navigation_findnearestwaypoint(e, false)) continue;
420 LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
421 e.effects |= EF_NODEPTHTEST | EF_RED;
425 if (i) LOG_INFOF("%d items have no nearest waypoint and cannot be walked away from (marked with red light)\n", i);
428 for (entity e = start; e; e = e.chain)
430 if (navigation_findnearestwaypoint(e, true)) continue;
431 LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
432 e.effects |= EF_NODEPTHTEST | EF_BLUE;
436 if (i) LOG_INFOF("%d items have no nearest waypoint and cannot be walked to (marked with blue light)\n", i);