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, n) _IMPULSE(IMP_##id, n)
23 #define _IMPULSE(id, n) \
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
53 #define X(slot, imp) \
54 IMPULSE(weapon_group_##slot, imp) \
56 if (this.deadflag != DEAD_NO) return; \
57 W_NextWeaponOnImpulse(slot); \
71 IMPULSE(weapon_next_byid, 10)
73 if (this.vehicle) return;
74 if (this.deadflag != DEAD_NO) return;
78 IMPULSE(weapon_prev_byid, 12)
80 if (this.vehicle) return;
81 if (this.deadflag != DEAD_NO) return;
85 IMPULSE(weapon_next_bygroup, 18)
87 if (this.vehicle) return;
88 if (this.deadflag != DEAD_NO) return;
92 IMPULSE(weapon_prev_bygroup, 19)
94 if (this.vehicle) return;
95 if (this.deadflag != DEAD_NO) return;
99 IMPULSE(weapon_next_bypriority, 15)
101 if (this.vehicle) return;
102 if (this.deadflag != DEAD_NO) return;
106 IMPULSE(weapon_prev_bypriority, 16)
108 if (this.vehicle) return;
109 if (this.deadflag != DEAD_NO) return;
113 IMPULSE(weapon_last, 11)
115 if (this.vehicle) return;
116 if (this.deadflag != DEAD_NO) return;
120 IMPULSE(weapon_best, 13)
122 if (this.vehicle) return;
123 if (this.deadflag != DEAD_NO) return;
124 W_SwitchWeapon(w_getbestweapon(this));
127 IMPULSE(weapon_drop, 17)
129 if (this.vehicle) return;
130 if (this.deadflag != DEAD_NO) return;
131 W_ThrowWeapon(W_CalculateProjectileVelocity(this.velocity, v_forward * 750, false), '0 0 0', true);
134 IMPULSE(weapon_reload, 20)
136 if (this.vehicle) return;
137 if (this.deadflag != DEAD_NO) return;
138 if (forbidWeaponUse(this)) return;
139 Weapon w = Weapons_from(this.weapon);
143 void ImpulseCommands(entity this)
145 if (gameover) return;
147 int imp = this.impulse;
151 if (MinigameImpulse(this, imp)) return;
153 if (timeout_status == TIMEOUT_ACTIVE) return; // don't allow any impulses while the game is paused
155 // allow only weapon change impulses when not in round time
156 if (round_handler_IsActive() && !round_handler_IsRoundStarted())
157 if (imp == 17 || (imp >= 20 && imp < 200) || imp > 253) return;
159 if (vehicle_impulse(this, imp)) return;
161 if (CheatImpulse(imp)) return;
163 FOREACH(IMPULSES, it.impulse == imp, {
164 void(entity) f = it.impulse_handle;
170 if (imp >= 200 && imp <= 229)
172 if (!this.vehicle && this.deadflag == DEAD_NO)
174 // custom order weapon cycling
176 int m = (imp - (210 + i)); // <0 for prev, =0 for best, >0 for next
177 W_CycleWeapon(this.(cvar_cl_weaponpriorities[i]), m);
179 // else // don't retry, as this can break weaplast bind
180 // this.impulse = imp; // retry in next frame
182 else if (imp >= WEP_IMPULSE_BEGIN && imp <= WEP_IMPULSE_END)
184 if (!this.vehicle && this.deadflag == DEAD_NO) W_SwitchWeapon(imp - WEP_IMPULSE_BEGIN + WEP_FIRST);
185 // else // don't retry, as this can break weaplast bind
186 // this.impulse = imp; // retry in next frame
195 IMPULSE(waypoint_personal_here, 30)
197 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this.origin, RADARICON_WAYPOINT);
198 if (wp) WaypointSprite_Ping(wp);
199 sprint(this, "personal waypoint spawned at location\n");
202 IMPULSE(waypoint_personal_crosshair, 31)
204 WarpZone_crosshair_trace(this);
205 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, trace_endpos, RADARICON_WAYPOINT);
206 if (wp) WaypointSprite_Ping(wp);
207 sprint(this, "personal waypoint spawned at crosshair\n");
210 IMPULSE(waypoint_personal_death, 32)
212 if (!this.death_origin) return;
213 entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this.death_origin, RADARICON_WAYPOINT);
214 if (wp) WaypointSprite_Ping(wp);
215 sprint(this, "personal waypoint spawned at death location\n");
218 IMPULSE(waypoint_here_follow, 33)
220 if (!teamplay) return;
221 if (this.deadflag != DEAD_NO) return;
222 if (!MUTATOR_CALLHOOK(HelpMePing, this))
224 entity wp = WaypointSprite_Attach(WP_Helpme, true, RADARICON_HELPME);
225 if (!wp) WaypointSprite_HelpMePing(this.waypointsprite_attachedforcarrier);
226 else WaypointSprite_Ping(wp);
228 sprint(this, "HELP ME attached\n");
231 IMPULSE(waypoint_here_here, 34)
233 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this.origin, RADARICON_HERE);
234 if (wp) WaypointSprite_Ping(wp);
235 sprint(this, "HERE spawned at location\n");
238 IMPULSE(waypoint_here_crosshair, 35)
240 WarpZone_crosshair_trace(this);
241 entity wp = WaypointSprite_DeployFixed(WP_Here, false, trace_endpos, RADARICON_HERE);
242 if (wp) WaypointSprite_Ping(wp);
243 sprint(this, "HERE spawned at crosshair\n");
246 IMPULSE(waypoint_here_death, 36)
248 if (!this.death_origin) return;
249 entity wp = WaypointSprite_DeployFixed(WP_Here, false, this.death_origin, RADARICON_HERE);
250 if (wp) WaypointSprite_Ping(wp);
251 sprint(this, "HERE spawned at death location\n");
254 IMPULSE(waypoint_danger_here, 37)
256 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this.origin, RADARICON_DANGER);
257 if (wp) WaypointSprite_Ping(wp);
258 sprint(this, "DANGER spawned at location\n");
261 IMPULSE(waypoint_danger_crosshair, 38)
263 WarpZone_crosshair_trace(this);
264 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, trace_endpos, RADARICON_DANGER);
265 if (wp) WaypointSprite_Ping(wp);
266 sprint(this, "DANGER spawned at crosshair\n");
269 IMPULSE(waypoint_danger_death, 39)
271 if (!this.death_origin) return;
272 entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this.death_origin, RADARICON_DANGER);
273 if (wp) WaypointSprite_Ping(wp);
274 sprint(this, "DANGER spawned at death location\n");
277 IMPULSE(waypoint_clear_personal, 47)
279 WaypointSprite_ClearPersonal();
282 remove(this.personal);
283 this.personal = NULL;
285 sprint(this, "personal waypoint cleared\n");
288 IMPULSE(waypoint_clear, 48)
290 WaypointSprite_ClearOwned();
293 remove(this.personal);
294 this.personal = NULL;
296 sprint(this, "all waypoints cleared\n");
299 IMPULSE(navwaypoint_spawn, 103)
301 if (!autocvar_g_waypointeditor) return;
302 waypoint_schedulerelink(waypoint_spawn(this.origin, this.origin, 0));
303 bprint(strcat("Waypoint spawned at ", vtos(this.origin), "\n"));
306 IMPULSE(navwaypoint_remove, 104)
308 if (!autocvar_g_waypointeditor) return;
309 entity e = navigation_findnearestwaypoint(this, false);
311 if (e.wpflags & WAYPOINTFLAG_GENERATED) return;
312 bprint(strcat("Waypoint removed at ", vtos(e.origin), "\n"));
316 IMPULSE(navwaypoint_relink, 105)
318 if (!autocvar_g_waypointeditor) return;
319 waypoint_schedulerelinkall();
322 IMPULSE(navwaypoint_save, 106)
324 if (!autocvar_g_waypointeditor) return;
328 IMPULSE(navwaypoint_unreachable, 107)
330 if (!autocvar_g_waypointeditor) return;
331 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
333 e.colormod = '0.5 0.5 0.5';
334 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
336 entity e2 = navigation_findnearestwaypoint(this, false);
337 navigation_markroutes(e2);
343 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
345 if (e.wpcost < 10000000) continue;
346 LOG_INFO("unreachable: ", etos(e), " ", vtos(e.origin), "\n");
348 e.effects |= EF_NODEPTHTEST | EF_BLUE;
352 if (i) LOG_INFOF("%d waypoints cannot be reached from here in any way (marked with blue light)\n", i);
353 navigation_markroutes_inverted(e2);
356 for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
358 if (e.wpcost < 10000000) continue;
359 LOG_INFO("cannot reach me: ", etos(e), " ", vtos(e.origin), "\n");
361 if (!(e.effects & EF_NODEPTHTEST)) // not already reported before
363 e.effects |= EF_NODEPTHTEST | EF_RED;
366 if (i) LOG_INFOF("%d waypoints cannot walk to here in any way (marked with red light)\n", i);
367 if (m) LOG_INFOF("%d waypoints have been marked total\n", m);
370 for (entity e = findchain(classname, "info_player_deathmatch"); e; e = e.chain)
372 vector org = e.origin;
373 tracebox(e.origin, PL_MIN, PL_MAX, e.origin - '0 0 512', MOVE_NOMONSTERS, world);
374 setorigin(e, trace_endpos);
375 if (navigation_findnearestwaypoint(e, false))
378 e.effects &= ~EF_NODEPTHTEST;
384 LOG_INFO("spawn without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
385 e.effects |= EF_NODEPTHTEST;
386 _setmodel(e, this.model);
387 e.frame = this.frame;
389 e.colormod = '8 0.5 8';
390 setsize(e, '0 0 0', '0 0 0');
394 if (i) LOG_INFOF("%d spawnpoints have no nearest waypoint (marked by player model)\n", i);
397 entity start = findchainflags(flags, FL_ITEM);
398 for (entity e = start; e; e = e.chain)
400 e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
401 e.colormod = '0.5 0.5 0.5';
403 for (entity e = start; e; e = e.chain)
405 if (navigation_findnearestwaypoint(e, false)) continue;
406 LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
407 e.effects |= EF_NODEPTHTEST | EF_RED;
411 if (i) LOG_INFOF("%d items have no nearest waypoint and cannot be walked away from (marked with red light)\n", i);
414 for (entity e = start; e; e = e.chain)
416 if (navigation_findnearestwaypoint(e, true)) continue;
417 LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
418 e.effects |= EF_NODEPTHTEST | EF_BLUE;
422 if (i) LOG_INFOF("%d items have no nearest waypoint and cannot be walked to (marked with blue light)\n", i);