]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/havocbot/havocbot.qc
server: pass compilation units test
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / havocbot / havocbot.qc
index ced6463c2ec7af55676390036fb3cbdc3030d56a..68ff899ea402dee92dca393f56a0edde7bd2211e 100644 (file)
@@ -6,12 +6,14 @@
 #include "../scripting.qh"
 #include "../waypoints.qh"
 
-#include "../../../common/constants.qh"
-#include "../../../common/items/all.qh"
+#include <common/constants.qh>
+#include <common/physics/player.qh>
+#include <common/state.qh>
+#include <common/items/all.qh>
 
-#include "../../../common/triggers/trigger/jumppads.qh"
+#include <common/triggers/trigger/jumppads.qh>
 
-#include "../../../lib/warpzone/common.qh"
+#include <lib/warpzone/common.qh>
 
 .float speed;
 
@@ -38,7 +40,7 @@ void havocbot_ai()
 
                // TODO: tracewalk() should take care of this job (better path finding under water)
                // if we don't have a goal and we're under water look for a waypoint near the "shore" and push it
-               if(self.deadflag != DEAD_NO)
+               if(IS_DEAD(self))
                if(self.goalcurrent==world)
                if(self.waterlevel==WATERLEVEL_SWIMMING || (self.aistatus & AI_STATUS_OUT_WATER))
                {
@@ -86,7 +88,7 @@ void havocbot_ai()
                bot_strategytoken_taken = true;
        }
 
-       if(self.deadflag != DEAD_NO)
+       if(IS_DEAD(self))
                return;
 
        havocbot_chooseenemy();
@@ -104,17 +106,17 @@ void havocbot_ai()
 
                if(self.weapons)
                {
-                       Weapon w = get_weaponinfo(self.weapon);
+                       Weapon w = PS(self).m_weapon;
                        w.wr_aim(w);
                        if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(self))
                        {
-                               self.BUTTON_ATCK = false;
-                               self.BUTTON_ATCK2 = false;
+                               PHYS_INPUT_BUTTON_ATCK(self) = false;
+                               PHYS_INPUT_BUTTON_ATCK2(self) = false;
                        }
                        else
                        {
-                               if(self.BUTTON_ATCK||self.BUTTON_ATCK2)
-                                       self.lastfiredweapon = self.weapon;
+                               if(PHYS_INPUT_BUTTON_ATCK(self) || PHYS_INPUT_BUTTON_ATCK2(self))
+                                       self.lastfiredweapon = PS(self).m_weapon.m_id;
                        }
                }
                else
@@ -171,12 +173,10 @@ void havocbot_ai()
                if(skill >= 5) // bots can only look for unloaded weapons past this skill
                if(self.clip_load >= 0) // only if we're not reloading a weapon already
                {
-                       for (int i = WEP_FIRST; i <= WEP_LAST; ++i)
-                       {
-                               entity e = get_weaponinfo(i);
-                               if ((self.weapons & WepSet_FromWeapon(i)) && (e.spawnflags & WEP_FLAG_RELOADABLE) && (self.weapon_load[i] < e.reloading_ammo))
-                                       self.switchweapon = i;
-                       }
+                       FOREACH(Weapons, it != WEP_Null, LAMBDA(
+                               if((self.weapons & (it.m_wepset)) && (it.spawnflags & WEP_FLAG_RELOADABLE) && (self.weapon_load[it.m_id] < it.reloading_ammo))
+                                       PS(self).m_switchweapon = it;
+                       ));
                }
        }
 }
@@ -248,7 +248,7 @@ void havocbot_keyboard_movement(vector destorg)
                keyboard.z = 0;
 
        self.havocbot_keyboard = keyboard * maxspeed;
-       if (self.havocbot_ducktime>time) self.BUTTON_CROUCH=true;
+       if (self.havocbot_ducktime>time) PHYS_INPUT_BUTTON_CROUCH(self) = true;
 
        keyboard = self.havocbot_keyboard;
        blend = bound(0,vlen(destorg-self.origin)/autocvar_bot_ai_keyboard_distance,1); // When getting close move with 360 degree
@@ -275,7 +275,7 @@ void havocbot_bunnyhop(vector dir)
        if(self.aistatus & AI_STATUS_DANGER_AHEAD)
        {
                self.aistatus &= ~AI_STATUS_RUNNING;
-               self.BUTTON_JUMP = false;
+               PHYS_INPUT_BUTTON_JUMP(self) = false;
                self.bot_canruntogoal = 0;
                self.bot_timelastseengoal = 0;
                return;
@@ -297,7 +297,7 @@ void havocbot_bunnyhop(vector dir)
        bunnyhopdistance = vlen(self.origin - gco);
 
        // Run only to visible goals
-       if(self.flags & FL_ONGROUND)
+       if(IS_ONGROUND(self))
        if(self.speed==maxspeed)
        if(checkpvs(self.origin + self.view_ofs, self.goalcurrent))
        {
@@ -351,12 +351,12 @@ void havocbot_bunnyhop(vector dir)
                                        {
                                                self.aistatus &= ~AI_STATUS_RUNNING;
                                                if(bunnyhopdistance > autocvar_bot_ai_bunnyhop_stopdistance)
-                                                       self.BUTTON_JUMP = true;
+                                                       PHYS_INPUT_BUTTON_JUMP(self) = true;
                                        }
                                        else
                                        {
                                                self.aistatus |= AI_STATUS_RUNNING;
-                                               self.BUTTON_JUMP = true;
+                                               PHYS_INPUT_BUTTON_JUMP(self) = true;
                                        }
                                }
                        }
@@ -373,10 +373,10 @@ void havocbot_bunnyhop(vector dir)
 #if 0
        // Release jump button
        if(!cvar("sv_pogostick"))
-       if((self.flags & FL_ONGROUND) == 0)
+       if((IS_ONGROUND(self)) == 0)
        {
                if(self.velocity.z < 0 || vlen(self.velocity)<maxspeed)
-                       self.BUTTON_JUMP = false;
+                       PHYS_INPUT_BUTTON_JUMP(self) = false;
 
                // Strafe
                if(self.aistatus & AI_STATUS_RUNNING)
@@ -479,8 +479,8 @@ void havocbot_movetogoal()
                }
 
                // Flying
-               self.BUTTON_HOOK = true;
-               if(self.navigation_jetpack_point.z - PL_MAX.z + PL_MIN.z < self.origin.z)
+               PHYS_INPUT_BUTTON_HOOK(self) = true;
+               if(self.navigation_jetpack_point.z - STAT(PL_MAX, NULL).z + STAT(PL_MIN, NULL).z < self.origin.z)
                {
                        self.movement_x = dir * v_forward * maxspeed;
                        self.movement_y = dir * v_right * maxspeed;
@@ -556,7 +556,7 @@ void havocbot_movetogoal()
 
        // If there is a trigger_hurt right below try to use the jetpack or make a rocketjump
        if(skill>6)
-       if (!(self.flags & FL_ONGROUND))
+       if (!(IS_ONGROUND(self)))
        {
                tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 -65536', MOVE_NOMONSTERS, self);
                if(tracebox_hits_trigger_hurt(self.origin, self.mins, self.maxs, trace_endpos ))
@@ -567,11 +567,11 @@ void havocbot_movetogoal()
                        {
                                if(self.velocity.z<0)
                                {
-                                       self.BUTTON_HOOK = true;
+                                       PHYS_INPUT_BUTTON_HOOK(self) = true;
                                }
                        }
                        else
-                               self.BUTTON_HOOK = true;
+                               PHYS_INPUT_BUTTON_HOOK(self) = true;
 
                        // If there is no goal try to move forward
 
@@ -603,7 +603,7 @@ void havocbot_movetogoal()
                else if(self.health>WEP_CVAR(devastator, damage)*0.5)
                {
                        if(self.velocity.z < 0)
-                       if(client_hasweapon(self, WEP_DEVASTATOR.m_id, true, false))
+                       if(client_hasweapon(self, WEP_DEVASTATOR, true, false))
                        {
                                self.movement_x = maxspeed;
 
@@ -611,15 +611,15 @@ void havocbot_movetogoal()
                                {
                                        if(time > self.rocketjumptime)
                                        {
-                                               self.BUTTON_ATCK2 = true;
+                                               PHYS_INPUT_BUTTON_ATCK2(self) = true;
                                                self.rocketjumptime = 0;
                                        }
                                        return;
                                }
 
-                               self.switchweapon = WEP_DEVASTATOR.m_id;
+                               PS(self).m_switchweapon = WEP_DEVASTATOR;
                                self.v_angle_x = 90;
-                               self.BUTTON_ATCK = true;
+                               PHYS_INPUT_BUTTON_ATCK(self) = true;
                                self.rocketjumptime = time + WEP_CVAR(devastator, detonatedelay);
                                return;
                        }
@@ -640,9 +640,9 @@ void havocbot_movetogoal()
                if(self.waterlevel>WATERLEVEL_SWIMMING)
                        dir.z = 1;
                else if(self.velocity.z >= 0 && !(self.waterlevel == WATERLEVEL_WETFEET && self.watertype == CONTENT_WATER))
-                       self.BUTTON_JUMP = true;
+                       PHYS_INPUT_BUTTON_JUMP(self) = true;
                else
-                       self.BUTTON_JUMP = false;
+                       PHYS_INPUT_BUTTON_JUMP(self) = false;
                makevectors(self.v_angle.y * '0 1 0');
                self.movement_x = dir * v_forward * maxspeed;
                self.movement_y = dir * v_right * maxspeed;
@@ -698,9 +698,9 @@ void havocbot_movetogoal()
                        {
                                if(self.velocity.z >= 0 && !(self.watertype == CONTENT_WATER && gco.z < self.origin.z) &&
                                        ( !(self.waterlevel == WATERLEVEL_WETFEET && self.watertype == CONTENT_WATER) || self.aistatus & AI_STATUS_OUT_WATER))
-                                       self.BUTTON_JUMP = true;
+                                       PHYS_INPUT_BUTTON_JUMP(self) = true;
                                else
-                                       self.BUTTON_JUMP = false;
+                                       PHYS_INPUT_BUTTON_JUMP(self) = false;
                        }
                        dir = normalize(flatdir);
                        makevectors(self.v_angle.y * '0 1 0');
@@ -724,7 +724,7 @@ void havocbot_movetogoal()
                                        s = trace_fraction;
                                        tracebox(self.origin + jumpstepheightvec, self.mins, self.maxs, self.origin + self.velocity * 0.2 + jumpstepheightvec, false, self);
                                        if (trace_fraction > s)
-                                               self.BUTTON_JUMP = 1;
+                                               PHYS_INPUT_BUTTON_JUMP(self) = true;
                                }
                        }
 
@@ -740,7 +740,7 @@ void havocbot_movetogoal()
                        // Check head-banging against walls
                        if(vlen(self.origin + self.view_ofs - trace_endpos) < 25 && !(self.aistatus & AI_STATUS_OUT_WATER))
                        {
-                               self.BUTTON_JUMP = true;
+                               PHYS_INPUT_BUTTON_JUMP(self) = true;
                                if(self.facingwalltime && time > self.facingwalltime)
                                {
                                        self.ignoregoal = self.goalcurrent;
@@ -769,7 +769,7 @@ void havocbot_movetogoal()
                        self.aistatus &= ~AI_STATUS_DANGER_AHEAD;
 
                        if(trace_fraction == 1 && self.jumppadcount == 0 && !self.goalcurrent.wphardwired )
-                       if((self.flags & FL_ONGROUND) || (self.aistatus & AI_STATUS_RUNNING) || self.BUTTON_JUMP == true)
+                       if((IS_ONGROUND(self)) || (self.aistatus & AI_STATUS_RUNNING) || PHYS_INPUT_BUTTON_JUMP(self))
                        {
                                // Look downwards
                                traceline(dst_ahead , dst_down, true, world);
@@ -817,7 +817,7 @@ void havocbot_movetogoal()
 
                dir = normalize(dir + dodge + evadeobstacle + evadelava);
        //      self.bot_dodgevector = dir;
-       //      self.bot_dodgevector_jumpbutton = self.BUTTON_JUMP;
+       //      self.bot_dodgevector_jumpbutton = PHYS_INPUT_BUTTON_JUMP(self);
        }
 
        if(time < self.ladder_time)
@@ -836,7 +836,7 @@ void havocbot_movetogoal()
 
        //dir = self.bot_dodgevector;
        //if (self.bot_dodgevector_jumpbutton)
-       //      self.BUTTON_JUMP = 1;
+       //      PHYS_INPUT_BUTTON_JUMP(self) = true;
        self.movement_x = dir * v_forward * maxspeed;
        self.movement_y = dir * v_right * maxspeed;
        self.movement_z = dir * v_up * maxspeed;
@@ -851,8 +851,8 @@ void havocbot_movetogoal()
        if(skill+self.bot_moveskill >= autocvar_bot_ai_bunnyhop_skilloffset)
                havocbot_bunnyhop(dir);
 
-       if ((dir * v_up) >= autocvar_sv_jumpvelocity*0.5 && (self.flags & FL_ONGROUND)) self.BUTTON_JUMP=1;
-       if (((dodge * v_up) > 0) && random()*frametime >= 0.2*bound(0,(10-skill-self.bot_dodgeskill)*0.1,1)) self.BUTTON_JUMP=true;
+       if ((dir * v_up) >= autocvar_sv_jumpvelocity*0.5 && (IS_ONGROUND(self))) PHYS_INPUT_BUTTON_JUMP(self) = true;
+       if (((dodge * v_up) > 0) && random()*frametime >= 0.2*bound(0,(10-skill-self.bot_dodgeskill)*0.1,1)) PHYS_INPUT_BUTTON_JUMP(self) = true;
        if (((dodge * v_up) < 0) && random()*frametime >= 0.5*bound(0,(10-skill-self.bot_dodgeskill)*0.1,1)) self.havocbot_ducktime=time+0.3/bound(0.1,skill+self.bot_dodgeskill,10);
 }
 
@@ -992,14 +992,11 @@ float havocbot_chooseweapon_checkreload(int new_weapon)
        // if this weapon is scheduled for reloading, don't switch to it during combat
        if (self.weapon_load[new_weapon] < 0)
        {
-               float i, other_weapon_available = false;
-               for(i = WEP_FIRST; i <= WEP_LAST; ++i)
-               {
-                       Weapon w = get_weaponinfo(i);
-                       // if we are out of ammo for all other weapons, it's an emergency to switch to anything else
-                       if (w.wr_checkammo1(w) + w.wr_checkammo2(w))
+               bool other_weapon_available = false;
+               FOREACH(Weapons, it != WEP_Null, LAMBDA(
+                       if(it.wr_checkammo1(it) + it.wr_checkammo2(it))
                                other_weapon_available = true;
-               }
+               ));
                if(other_weapon_available)
                        return true;
        }
@@ -1014,7 +1011,7 @@ void havocbot_chooseweapon()
        // ;)
        if(g_weaponarena_weapons == WEPSET(TUBA))
        {
-               self.switchweapon = WEP_TUBA.m_id;
+               PS(self).m_switchweapon = WEP_TUBA;
                return;
        }
 
@@ -1022,15 +1019,14 @@ void havocbot_chooseweapon()
        if(self.enemy==world)
        {
                // If no weapon was chosen get the first available weapon
-               if(self.weapon==0)
-               for(i = WEP_FIRST; i <= WEP_LAST; ++i) if(i != WEP_BLASTER.m_id)
-               {
-                       if(client_hasweapon(self, i, true, false))
+               if(PS(self).m_weapon==WEP_Null)
+               FOREACH(Weapons, it != WEP_Null, LAMBDA(
+                       if(client_hasweapon(self, it, true, false))
                        {
-                               self.switchweapon = i;
+                               PS(self).m_switchweapon = it;
                                return;
                        }
-               }
+               ));
                return;
        }
 
@@ -1045,7 +1041,7 @@ void havocbot_chooseweapon()
        // Should it do a weapon combo?
        float af, ct, combo_time, combo;
 
-       af = ATTACK_FINISHED(self);
+       af = ATTACK_FINISHED(self, 0);
        ct = autocvar_bot_ai_weapon_combo_threshold;
 
        // Bots with no skill will be 4 times more slower than "godlike" bots when doing weapon combos
@@ -1055,7 +1051,7 @@ void havocbot_chooseweapon()
        combo = false;
 
        if(autocvar_bot_ai_weapon_combo)
-       if(self.weapon == self.lastfiredweapon)
+       if(PS(self).m_weapon.m_id == self.lastfiredweapon)
        if(af > combo_time)
        {
                combo = true;
@@ -1071,11 +1067,11 @@ void havocbot_chooseweapon()
                if ( distance > bot_distance_far ) {
                        for(i=0; i < Weapons_COUNT && bot_weapons_far[i] != -1 ; ++i){
                                w = bot_weapons_far[i];
-                               if ( client_hasweapon(self, w, true, false) )
+                               if ( client_hasweapon(self, Weapons_from(w), true, false) )
                                {
-                                       if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
+                                       if ((PS(self).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(w))
                                                continue;
-                                       self.switchweapon = w;
+                                       PS(self).m_switchweapon = Weapons_from(w);
                                        return;
                                }
                        }
@@ -1085,11 +1081,11 @@ void havocbot_chooseweapon()
                if ( distance > bot_distance_close) {
                        for(i=0; i < Weapons_COUNT && bot_weapons_mid[i] != -1 ; ++i){
                                w = bot_weapons_mid[i];
-                               if ( client_hasweapon(self, w, true, false) )
+                               if ( client_hasweapon(self, Weapons_from(w), true, false) )
                                {
-                                       if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
+                                       if ((PS(self).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(w))
                                                continue;
-                                       self.switchweapon = w;
+                                       PS(self).m_switchweapon = Weapons_from(w);
                                        return;
                                }
                        }
@@ -1098,11 +1094,11 @@ void havocbot_chooseweapon()
                // Choose weapons for close distance
                for(i=0; i < Weapons_COUNT && bot_weapons_close[i] != -1 ; ++i){
                        w = bot_weapons_close[i];
-                       if ( client_hasweapon(self, w, true, false) )
+                       if ( client_hasweapon(self, Weapons_from(w), true, false) )
                        {
-                               if ((self.weapon == w && combo) || havocbot_chooseweapon_checkreload(w))
+                               if ((PS(self).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(w))
                                        continue;
-                               self.switchweapon = w;
+                               PS(self).m_switchweapon = Weapons_from(w);
                                return;
                        }
                }