]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_impulse.qc
Add a mutator hook for CopyBody
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_impulse.qc
index 59fc183aa495b492e48f3ccbcb4e0f6a47bc0ae4..00c4ec22cd869a0a1cac51f6df9e52be43a52b67 100644 (file)
@@ -1,15 +1,17 @@
+#include "cl_impulse.qh"
 #include "round_handler.qh"
 
-#include "bot/waypoints.qh"
+#include "bot/api.qh"
 
 #include "weapons/throwing.qh"
 #include "command/common.qh"
 #include "cheats.qh"
-#include "bot/navigation.qh"
 #include "weapons/selection.qh"
 #include "weapons/tracing.qh"
 #include "weapons/weaponsystem.qh"
 
+#include <common/state.qh>
+
 #include "../common/minigames/sv_minigames.qh"
 
 #include "../common/weapons/all.qh"
 #define X(slot) \
        IMPULSE(weapon_group_##slot) \
        { \
-               if (this.deadflag != DEAD_NO) return; \
-               W_NextWeaponOnImpulse(slot); \
+               if (IS_DEAD(this)) \
+               { \
+                       this.impulse = IMP_weapon_group_##slot.impulse; \
+                       return; \
+               } \
+               W_NextWeaponOnImpulse(this, slot); \
        }
 X(1)
 X(2)
@@ -74,11 +80,15 @@ X(0)
        IMPULSE(weapon_priority_##slot##_##dir) \
        { \
                if (this.vehicle) return; \
-               if (this.deadflag != DEAD_NO) return; \
+               if (IS_DEAD(this)) \
+               { \
+                       this.impulse = IMP_weapon_priority_##slot##_##dir.impulse; \
+                       return; \
+               } \
                noref int prev = -1; \
                noref int best =  0; \
                noref int next = +1; \
-               W_CycleWeapon(this.cvar_cl_weaponpriorities[slot], dir); \
+               W_CycleWeapon(this, this.cvar_cl_weaponpriorities[slot], dir); \
        }
 X(0, prev)
 X(1, prev)
@@ -120,8 +130,12 @@ X(9, next)
        IMPULSE(weapon_byid_##i) \
        { \
                if (this.vehicle) return; \
-               if (this.deadflag != DEAD_NO) return; \
-               W_SwitchWeapon(Weapons_from(WEP_FIRST + i)); \
+               if (IS_DEAD(this)) \
+               { \
+                       this.impulse = IMP_weapon_byid_##i.impulse; \
+                       return; \
+               } \
+               W_SwitchWeapon(this, Weapons_from(WEP_FIRST + i)); \
        }
 X(0)
 X(1)
@@ -152,73 +166,102 @@ X(23)
 IMPULSE(weapon_next_byid)
 {
        if (this.vehicle) return;
-       if (this.deadflag != DEAD_NO) return;
-       W_NextWeapon(0);
+       if (IS_DEAD(this))
+       {
+               this.impulse = IMP_weapon_next_byid.impulse;
+               return;
+       }
+       W_NextWeapon(this, 0);
 }
 
 IMPULSE(weapon_prev_byid)
 {
        if (this.vehicle) return;
-       if (this.deadflag != DEAD_NO) return;
-       W_PreviousWeapon(0);
+       if (IS_DEAD(this))
+       {
+               this.impulse = IMP_weapon_prev_byid.impulse;
+               return;
+       }
+       W_PreviousWeapon(this, 0);
 }
 
 IMPULSE(weapon_next_bygroup)
 {
        if (this.vehicle) return;
-       if (this.deadflag != DEAD_NO) return;
-       W_NextWeapon(1);
+       if (IS_DEAD(this))
+       {
+               this.impulse = IMP_weapon_next_bygroup.impulse;
+               return;
+       }
+       W_NextWeapon(this, 1);
 }
 
 IMPULSE(weapon_prev_bygroup)
 {
        if (this.vehicle) return;
-       if (this.deadflag != DEAD_NO) return;
-       W_PreviousWeapon(1);
+       if (IS_DEAD(this))
+       {
+               this.impulse = IMP_weapon_prev_bygroup.impulse;
+               return;
+       }
+       W_PreviousWeapon(this, 1);
 }
 
 IMPULSE(weapon_next_bypriority)
 {
        if (this.vehicle) return;
-       if (this.deadflag != DEAD_NO) return;
-       W_NextWeapon(2);
+       if (IS_DEAD(this))
+       {
+               this.impulse = IMP_weapon_next_bypriority.impulse;
+               return;
+       }
+       W_NextWeapon(this, 2);
 }
 
 IMPULSE(weapon_prev_bypriority)
 {
        if (this.vehicle) return;
-       if (this.deadflag != DEAD_NO) return;
-       W_PreviousWeapon(2);
+       if (IS_DEAD(this))
+       {
+               this.impulse = IMP_weapon_prev_bypriority.impulse;
+               return;
+       }
+       W_PreviousWeapon(this, 2);
 }
 
 IMPULSE(weapon_last)
 {
        if (this.vehicle) return;
-       if (this.deadflag != DEAD_NO) return;
-       W_LastWeapon();
+       if (IS_DEAD(this)) return;
+       W_LastWeapon(this);
 }
 
 IMPULSE(weapon_best)
 {
        if (this.vehicle) return;
-       if (this.deadflag != DEAD_NO) return;
-       W_SwitchWeapon(w_getbestweapon(this));
+       if (IS_DEAD(this)) return;
+       W_SwitchWeapon(this, w_getbestweapon(this));
 }
 
 IMPULSE(weapon_drop)
 {
        if (this.vehicle) return;
-       if (this.deadflag != DEAD_NO) return;
-       W_ThrowWeapon(W_CalculateProjectileVelocity(this.velocity, v_forward * 750, false), '0 0 0', true);
+       if (IS_DEAD(this)) return;
+       W_ThrowWeapon(this, weaponentities[0], W_CalculateProjectileVelocity(this, this.velocity, v_forward * 750, false), '0 0 0', true);
 }
 
 IMPULSE(weapon_reload)
 {
        if (this.vehicle) return;
-       if (this.deadflag != DEAD_NO) return;
+       if (IS_DEAD(this)) return;
        if (forbidWeaponUse(this)) return;
        Weapon w = PS(this).m_weapon;
-       w.wr_reload(w);
+       entity actor = this;
+       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+       {
+               .entity weaponentity = weaponentities[slot];
+               w.wr_reload(w, actor, weaponentity);
+       }
 }
 
 void ImpulseCommands(entity this)
@@ -320,7 +363,7 @@ void ImpulseCommands(entity this)
 
        if (vehicle_impulse(this, imp)) return;
 
-       if (CheatImpulse(imp)) return;
+       if (CheatImpulse(this, imp)) return;
 
        FOREACH(IMPULSES, it.impulse == imp, {
                void(entity) f = it.impulse_handle;
@@ -332,12 +375,12 @@ void ImpulseCommands(entity this)
 
 IMPULSE(use)
 {
-       PlayerUseKey();
+       PlayerUseKey(this);
 }
 
 IMPULSE(waypoint_personal_here)
 {
-       entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this.origin, RADARICON_WAYPOINT);
+       entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, this.origin, RADARICON_WAYPOINT);
        if (wp) WaypointSprite_Ping(wp);
        sprint(this, "personal waypoint spawned at location\n");
 }
@@ -345,7 +388,7 @@ IMPULSE(waypoint_personal_here)
 IMPULSE(waypoint_personal_crosshair)
 {
        WarpZone_crosshair_trace(this);
-       entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, trace_endpos, RADARICON_WAYPOINT);
+       entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, trace_endpos, RADARICON_WAYPOINT);
        if (wp) WaypointSprite_Ping(wp);
        sprint(this, "personal waypoint spawned at crosshair\n");
 }
@@ -353,7 +396,7 @@ IMPULSE(waypoint_personal_crosshair)
 IMPULSE(waypoint_personal_death)
 {
        if (!this.death_origin) return;
-       entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this.death_origin, RADARICON_WAYPOINT);
+       entity wp = WaypointSprite_DeployPersonal(WP_Waypoint, this, this.death_origin, RADARICON_WAYPOINT);
        if (wp) WaypointSprite_Ping(wp);
        sprint(this, "personal waypoint spawned at death location\n");
 }
@@ -361,10 +404,10 @@ IMPULSE(waypoint_personal_death)
 IMPULSE(waypoint_here_follow)
 {
        if (!teamplay) return;
-       if (this.deadflag != DEAD_NO) return;
+       if (IS_DEAD(this)) return;
        if (!MUTATOR_CALLHOOK(HelpMePing, this))
        {
-               entity wp = WaypointSprite_Attach(WP_Helpme, true, RADARICON_HELPME);
+               entity wp = WaypointSprite_Attach(WP_Helpme, this, true, RADARICON_HELPME);
                if (!wp) WaypointSprite_HelpMePing(this.waypointsprite_attachedforcarrier);
                else WaypointSprite_Ping(wp);
        }
@@ -373,7 +416,7 @@ IMPULSE(waypoint_here_follow)
 
 IMPULSE(waypoint_here_here)
 {
-       entity wp = WaypointSprite_DeployFixed(WP_Here, false, this.origin, RADARICON_HERE);
+       entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, this.origin, RADARICON_HERE);
        if (wp) WaypointSprite_Ping(wp);
        sprint(this, "HERE spawned at location\n");
 }
@@ -381,7 +424,7 @@ IMPULSE(waypoint_here_here)
 IMPULSE(waypoint_here_crosshair)
 {
        WarpZone_crosshair_trace(this);
-       entity wp = WaypointSprite_DeployFixed(WP_Here, false, trace_endpos, RADARICON_HERE);
+       entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, trace_endpos, RADARICON_HERE);
        if (wp) WaypointSprite_Ping(wp);
        sprint(this, "HERE spawned at crosshair\n");
 }
@@ -389,14 +432,14 @@ IMPULSE(waypoint_here_crosshair)
 IMPULSE(waypoint_here_death)
 {
        if (!this.death_origin) return;
-       entity wp = WaypointSprite_DeployFixed(WP_Here, false, this.death_origin, RADARICON_HERE);
+       entity wp = WaypointSprite_DeployFixed(WP_Here, false, this, this.death_origin, RADARICON_HERE);
        if (wp) WaypointSprite_Ping(wp);
        sprint(this, "HERE spawned at death location\n");
 }
 
 IMPULSE(waypoint_danger_here)
 {
-       entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this.origin, RADARICON_DANGER);
+       entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, this.origin, RADARICON_DANGER);
        if (wp) WaypointSprite_Ping(wp);
        sprint(this, "DANGER spawned at location\n");
 }
@@ -404,7 +447,7 @@ IMPULSE(waypoint_danger_here)
 IMPULSE(waypoint_danger_crosshair)
 {
        WarpZone_crosshair_trace(this);
-       entity wp = WaypointSprite_DeployFixed(WP_Danger, false, trace_endpos, RADARICON_DANGER);
+       entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, trace_endpos, RADARICON_DANGER);
        if (wp) WaypointSprite_Ping(wp);
        sprint(this, "DANGER spawned at crosshair\n");
 }
@@ -412,17 +455,17 @@ IMPULSE(waypoint_danger_crosshair)
 IMPULSE(waypoint_danger_death)
 {
        if (!this.death_origin) return;
-       entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this.death_origin, RADARICON_DANGER);
+       entity wp = WaypointSprite_DeployFixed(WP_Danger, false, this, this.death_origin, RADARICON_DANGER);
        if (wp) WaypointSprite_Ping(wp);
        sprint(this, "DANGER spawned at death location\n");
 }
 
 IMPULSE(waypoint_clear_personal)
 {
-       WaypointSprite_ClearPersonal();
+       WaypointSprite_ClearPersonal(this);
        if (this.personal)
        {
-               remove(this.personal);
+               delete(this.personal);
                this.personal = NULL;
        }
        sprint(this, "personal waypoint cleared\n");
@@ -430,10 +473,10 @@ IMPULSE(waypoint_clear_personal)
 
 IMPULSE(waypoint_clear)
 {
-       WaypointSprite_ClearOwned();
+       WaypointSprite_ClearOwned(this);
        if (this.personal)
        {
-               remove(this.personal);
+               delete(this.personal);
                this.personal = NULL;
        }
        sprint(this, "all waypoints cleared\n");
@@ -471,96 +514,93 @@ IMPULSE(navwaypoint_save)
 IMPULSE(navwaypoint_unreachable)
 {
        if (!autocvar_g_waypointeditor) return;
-       for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
+       IL_EACH(g_waypoints, true,
        {
-               e.colormod = '0.5 0.5 0.5';
-               e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
-       }
+               it.colormod = '0.5 0.5 0.5';
+               it.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
+       });
        entity e2 = navigation_findnearestwaypoint(this, false);
-       navigation_markroutes(e2);
+       navigation_markroutes(this, e2);
 
-       int i, m;
+       int j, m;
 
-       i = 0;
+       j = 0;
        m = 0;
-       for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
+       IL_EACH(g_waypoints, it.wpcost >= 10000000,
        {
-               if (e.wpcost < 10000000) continue;
-               LOG_INFO("unreachable: ", etos(e), " ", vtos(e.origin), "\n");
-               e.colormod_z = 8;
-               e.effects |= EF_NODEPTHTEST | EF_BLUE;
-               ++i;
+               LOG_INFO("unreachable: ", etos(it), " ", vtos(it.origin), "\n");
+               it.colormod_z = 8;
+               it.effects |= EF_NODEPTHTEST | EF_BLUE;
+               ++j;
                ++m;
-       }
-       if (i) LOG_INFOF("%d waypoints cannot be reached from here in any way (marked with blue light)\n", i);
+       });
+       if (j) LOG_INFOF("%d waypoints cannot be reached from here in any way (marked with blue light)\n", j);
        navigation_markroutes_inverted(e2);
 
-       i = 0;
-       for (entity e = findchain(classname, "waypoint"); e; e = e.chain)
+       j = 0;
+       IL_EACH(g_waypoints, it.wpcost >= 10000000,
        {
-               if (e.wpcost < 10000000) continue;
-               LOG_INFO("cannot reach me: ", etos(e), " ", vtos(e.origin), "\n");
-               e.colormod_x = 8;
-               if (!(e.effects & EF_NODEPTHTEST))  // not already reported before
+               LOG_INFO("cannot reach me: ", etos(it), " ", vtos(it.origin), "\n");
+               it.colormod_x = 8;
+               if (!(it.effects & EF_NODEPTHTEST))  // not already reported before
                        ++m;
-               e.effects |= EF_NODEPTHTEST | EF_RED;
-               ++i;
-       }
-       if (i) LOG_INFOF("%d waypoints cannot walk to here in any way (marked with red light)\n", i);
+               it.effects |= EF_NODEPTHTEST | EF_RED;
+               ++j;
+       });
+       if (j) LOG_INFOF("%d waypoints cannot walk to here in any way (marked with red light)\n", j);
        if (m) LOG_INFOF("%d waypoints have been marked total\n", m);
 
-       i = 0;
-       for (entity e = findchain(classname, "info_player_deathmatch"); e; e = e.chain)
+       j = 0;
+       FOREACH_ENTITY_CLASS("info_player_deathmatch", true,
        {
-               vector org = e.origin;
-               tracebox(e.origin, PL_MIN, PL_MAX, e.origin - '0 0 512', MOVE_NOMONSTERS, world);
-               setorigin(e, trace_endpos);
-               if (navigation_findnearestwaypoint(e, false))
+               vector org = it.origin;
+               tracebox(it.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - '0 0 512', MOVE_NOMONSTERS, NULL);
+               setorigin(it, trace_endpos);
+               if (navigation_findnearestwaypoint(it, false))
                {
-                       setorigin(e, org);
-                       e.effects &= ~EF_NODEPTHTEST;
-                       e.model = "";
+                       setorigin(it, org);
+                       it.effects &= ~EF_NODEPTHTEST;
+                       it.model = "";
                }
                else
                {
-                       setorigin(e, org);
-                       LOG_INFO("spawn without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
-                       e.effects |= EF_NODEPTHTEST;
-                       _setmodel(e, this.model);
-                       e.frame = this.frame;
-                       e.skin = this.skin;
-                       e.colormod = '8 0.5 8';
-                       setsize(e, '0 0 0', '0 0 0');
-                       ++i;
+                       setorigin(it, org);
+                       LOG_INFO("spawn without waypoint: ", etos(it), " ", vtos(it.origin), "\n");
+                       it.effects |= EF_NODEPTHTEST;
+                       _setmodel(it, this.model);
+                       it.frame = this.frame;
+                       it.skin = this.skin;
+                       it.colormod = '8 0.5 8';
+                       setsize(it, '0 0 0', '0 0 0');
+                       ++j;
                }
-       }
-       if (i) LOG_INFOF("%d spawnpoints have no nearest waypoint (marked by player model)\n", i);
+       });
+       if (j) LOG_INFOF("%d spawnpoints have no nearest waypoint (marked by player model)\n", j);
 
-       i = 0;
-       entity start = findchainflags(flags, FL_ITEM);
-       for (entity e = start; e; e = e.chain)
+       j = 0;
+       FOREACH_ENTITY_FLAGS(flags, FL_ITEM,
        {
-               e.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
-               e.colormod = '0.5 0.5 0.5';
-       }
-       for (entity e = start; e; e = e.chain)
+               it.effects &= ~(EF_NODEPTHTEST | EF_RED | EF_BLUE);
+               it.colormod = '0.5 0.5 0.5';
+       });
+       FOREACH_ENTITY_FLAGS(flags, FL_ITEM,
        {
-               if (navigation_findnearestwaypoint(e, false)) continue;
-               LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
-               e.effects |= EF_NODEPTHTEST | EF_RED;
-               e.colormod_x = 8;
-               ++i;
-       }
-       if (i) LOG_INFOF("%d items have no nearest waypoint and cannot be walked away from (marked with red light)\n", i);
+               if (navigation_findnearestwaypoint(it, false)) continue;
+               LOG_INFO("item without waypoint: ", etos(it), " ", vtos(it.origin), "\n");
+               it.effects |= EF_NODEPTHTEST | EF_RED;
+               it.colormod_x = 8;
+               ++j;
+       });
+       if (j) LOG_INFOF("%d items have no nearest waypoint and cannot be walked away from (marked with red light)\n", j);
 
-       i = 0;
-       for (entity e = start; e; e = e.chain)
+       j = 0;
+       FOREACH_ENTITY_FLAGS(flags, FL_ITEM,
        {
-               if (navigation_findnearestwaypoint(e, true)) continue;
-               LOG_INFO("item without waypoint: ", etos(e), " ", vtos(e.origin), "\n");
-               e.effects |= EF_NODEPTHTEST | EF_BLUE;
-               e.colormod_z = 8;
-               ++i;
-       }
-       if (i) LOG_INFOF("%d items have no nearest waypoint and cannot be walked to (marked with blue light)\n", i);
+               if (navigation_findnearestwaypoint(it, true)) continue;
+               LOG_INFO("item without waypoint: ", etos(it), " ", vtos(it.origin), "\n");
+               it.effects |= EF_NODEPTHTEST | EF_BLUE;
+               it.colormod_z = 8;
+               ++j;
+       });
+       if (j) LOG_INFOF("%d items have no nearest waypoint and cannot be walked to (marked with blue light)\n", j);
 }