]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/weapons/weaponsystem.qc
Merge branch 'TimePath/entitydebugger' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / weapons / weaponsystem.qc
index 49934d62ed94082bea67c0f5b35a9ed06c7f8352..132740eaa88386f2cc99fcfc63849b71d6beb76c 100644 (file)
@@ -320,12 +320,14 @@ vector CL_Weapon_GetShotOrg(float wpn)
        return ret;
 }
 
+..entity weaponentity_fld;
+
 void CL_Weaponentity_Think()
 {
        SELFPARAM();
        this.nextthink = time;
        if (intermission_running) this.frame = this.anim_idle.x;
-       .entity weaponentity = weaponentities[0];  // TODO: unhardcode
+       .entity weaponentity = this.weaponentity_fld;
        if (this.owner.(weaponentity) != this)
        {
                if (this.(weaponentity)) remove(this.(weaponentity));
@@ -355,6 +357,7 @@ void CL_Weaponentity_Think()
        this.effects &= ~EF_TELEPORT_BIT;
        this.effects &= ~EF_RESTARTANIM_BIT;
        this.effects |= tb;
+       if (weaponentity != weaponentities[0]) this.effects |= EF_NODRAW;
 
        if (this.owner.alpha == default_player_alpha) this.alpha = default_weapon_alpha;
        else if (this.owner.alpha != 0) this.alpha = this.owner.alpha;
@@ -372,7 +375,7 @@ void CL_Weaponentity_Think()
 
        this.angles = '0 0 0';
 
-       float f = (this.owner.weapon_nextthink - time);
+       float f = this.weapon_nextthink - time;
        if (this.state == WS_RAISE && !intermission_running)
        {
                entity newwep = Weapons_from(this.owner.switchweapon);
@@ -451,6 +454,7 @@ void CL_SpawnWeaponentity(entity e, .entity weaponentity)
        view.angles = '0 0 0';
        view.viewmodelforclient = e;
        view.flags = 0;
+       view.weaponentity_fld = weaponentity;
        view.think = CL_Weaponentity_Think;
        view.customizeentityforclient = CL_Weaponentity_CustomizeEntityForClient;
        view.nextthink = time;
@@ -479,16 +483,18 @@ void w_clear(Weapon thiswep, entity actor, .entity weaponentity, int fire)
                actor.weapon = 0;
                actor.switchingweapon = 0;
        }
-       if (actor.(weaponentity))
+       entity this = actor.(weaponentity);
+       if (this)
        {
-               actor.(weaponentity).state = WS_CLEAR;
-               actor.(weaponentity).effects = 0;
+               this.state = WS_CLEAR;
+               this.effects = 0;
        }
 }
 
 void w_ready(Weapon thiswep, entity actor, .entity weaponentity, int fire)
 {
-       if (actor.(weaponentity)) actor.(weaponentity).state = WS_READY;
+       entity this = actor.(weaponentity);
+       if (this) this.state = WS_READY;
        weapon_thinkf(actor, weaponentity, WFRAME_IDLE, 1000000, w_ready);
 }
 
@@ -563,15 +569,17 @@ bool weapon_prepareattack_check(Weapon thiswep, entity actor, .entity weaponenti
                int slot = weaponslot(weaponentity);
                // don't fire if previous attack is not finished
                if (ATTACK_FINISHED(actor, slot) > time + actor.weapon_frametime * 0.5) return false;
+               entity this = actor.(weaponentity);
                // don't fire while changing weapon
-               if (actor.(weaponentity).state != WS_READY) return false;
+               if (this.state != WS_READY) return false;
        }
        return true;
 }
 
 void weapon_prepareattack_do(entity actor, .entity weaponentity, bool secondary, float attacktime)
 {
-       actor.(weaponentity).state = WS_INUSE;
+       entity this = actor.(weaponentity);
+       this.state = WS_INUSE;
 
        actor.spawnshieldtime = min(actor.spawnshieldtime, time);  // kill spawn shield when you fire
 
@@ -603,10 +611,11 @@ bool weapon_prepareattack(Weapon thiswep, entity actor, .entity weaponentity, bo
 void weapon_thinkf(entity actor, .entity weaponentity, float fr, float t, void(Weapon thiswep, entity actor,
        .entity weaponentity, int fire) func)
 {
+       entity this = actor.(weaponentity);
        bool restartanim;
        if (fr == WFRAME_DONTCHANGE)
        {
-               fr = actor.(weaponentity).wframe;
+               fr = this.wframe;
                restartanim = false;
        }
        else if (fr == WFRAME_IDLE)
@@ -622,43 +631,43 @@ void weapon_thinkf(entity actor, .entity weaponentity, float fr, float t, void(W
        vector or = v_right;
        vector ou = v_up;
 
-       if (actor.(weaponentity))
+       if (this)
        {
-               actor.(weaponentity).wframe = fr;
+               this.wframe = fr;
                vector a = '0 0 0';
-               if (fr == WFRAME_IDLE) a = actor.(weaponentity).anim_idle;
-               else if (fr == WFRAME_FIRE1) a = actor.(weaponentity).anim_fire1;
-               else if (fr == WFRAME_FIRE2) a = actor.(weaponentity).anim_fire2;
+               if (fr == WFRAME_IDLE) a = this.anim_idle;
+               else if (fr == WFRAME_FIRE1) a = this.anim_fire1;
+               else if (fr == WFRAME_FIRE2) a = this.anim_fire2;
                else  // if (fr == WFRAME_RELOAD)
-                       a = actor.(weaponentity).anim_reload;
+                       a = this.anim_reload;
                a.z *= g_weaponratefactor;
-               setanim(actor.(weaponentity), a, restartanim == false, restartanim, restartanim);
+               setanim(this, a, restartanim == false, restartanim, restartanim);
        }
 
        v_forward = of;
        v_right = or;
        v_up = ou;
 
-       if (actor.weapon_think == w_ready && func != w_ready && actor.(weaponentity).state == WS_RAISE) backtrace(
+       if (this.weapon_think == w_ready && func != w_ready && this.state == WS_RAISE) backtrace(
                        "Tried to override initial weapon think function - should this really happen?");
 
        t *= W_WeaponRateFactor();
 
        // VorteX: haste can be added here
-       if (actor.weapon_think == w_ready)
+       if (this.weapon_think == w_ready)
        {
-               actor.weapon_nextthink = time;
+               this.weapon_nextthink = time;
                // dprint("started firing at ", ftos(time), "\n");
        }
-       if (actor.weapon_nextthink < time - actor.weapon_frametime * 1.5
-           || actor.weapon_nextthink > time + actor.weapon_frametime * 1.5)
+       if (this.weapon_nextthink < time - actor.weapon_frametime * 1.5
+           || this.weapon_nextthink > time + actor.weapon_frametime * 1.5)
        {
-               actor.weapon_nextthink = time;
+               this.weapon_nextthink = time;
                // dprint("reset weapon animation timer at ", ftos(time), "\n");
        }
-       actor.weapon_nextthink = actor.weapon_nextthink + t;
-       actor.weapon_think = func;
-       // dprint("next ", ftos(actor.weapon_nextthink), "\n");
+       this.weapon_nextthink = this.weapon_nextthink + t;
+       this.weapon_think = func;
+       // dprint("next ", ftos(this.weapon_nextthink), "\n");
 
        if ((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t)
        {
@@ -687,10 +696,12 @@ bool forbidWeaponUse(entity player)
 
 void W_WeaponFrame(entity actor)
 {
-       .entity weaponentity = weaponentities[0];              // TODO: unhardcode
+       .entity weaponentity = weaponentities[0]; // TODO: unhardcode
+       entity this = actor.(weaponentity);
        if (frametime) actor.weapon_frametime = frametime;
 
-       if (!actor.(weaponentity) || actor.health < 1) return; // Dead player can't use weapons and injure impulse commands
+       if (!this || actor.health < 1) return; // Dead player can't use weapons and injure impulse commands
+
 
        if (forbidWeaponUse(actor))
        {
@@ -706,7 +717,7 @@ void W_WeaponFrame(entity actor)
        {
                actor.weapon = 0;
                actor.switchingweapon = 0;
-               actor.(weaponentity).state = WS_CLEAR;
+               this.state = WS_CLEAR;
                actor.weaponname = "";
                // actor.items &= ~IT_AMMO;
                return;
@@ -720,10 +731,10 @@ void W_WeaponFrame(entity actor)
        // Change weapon
        if (actor.weapon != actor.switchweapon)
        {
-               switch (actor.(weaponentity).state)
+               switch (this.state)
                {
                        default:
-                               LOG_WARNINGF("unhandled weaponentity (%i) state for player (%i): %d\n", actor.(weaponentity), actor, actor.(weaponentity).state);
+                               LOG_WARNINGF("unhandled weaponentity (%i) state for player (%i): %d\n", this, actor, this.state);
                                break;
                        case WS_INUSE:
                        case WS_RAISE:
@@ -740,7 +751,7 @@ void W_WeaponFrame(entity actor)
                                actor.bulletcounter = 0;
                                actor.ammo_field = newwep.ammo_field;
                                newwep.wr_setup(newwep);
-                               actor.(weaponentity).state = WS_RAISE;
+                               this.state = WS_RAISE;
 
                                // set our clip load to the load of the weapon we switched to, if it's reloadable
                                if ((newwep.spawnflags & WEP_FLAG_RELOADABLE) && newwep.reloading_ammo)  // prevent accessing undefined cvars
@@ -778,7 +789,7 @@ void W_WeaponFrame(entity actor)
                                   )
                                {
                                        sound(actor, CH_WEAPON_SINGLE, SND_WEAPON_SWITCH, VOL_BASE, ATTN_NORM);
-                                       actor.(weaponentity).state = WS_DROP;
+                                       this.state = WS_DROP;
                                        weapon_thinkf(actor, weaponentity, WFRAME_DONTCHANGE, oldwep.switchdelay_drop, w_clear);
                                }
                                break;
@@ -788,17 +799,15 @@ void W_WeaponFrame(entity actor)
 
        // LordHavoc: network timing test code
        // if (actor.button0)
-       //      print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(actor, slot)), " >= ", ftos(actor.weapon_nextthink), "\n");
+       //      print(ftos(frametime), " ", ftos(time), " >= ", ftos(ATTACK_FINISHED(actor, slot)), " >= ", ftos(this.weapon_nextthink), "\n");
 
        int w = actor.weapon;
 
        // call the think code which may fire the weapon
        // and do so multiple times to resolve framerate dependency issues if the
        // server framerate is very low and the weapon fire rate very high
-       int c = 0;
-       while (c < W_TICSPERFRAME)
+       for (int c = 0; c < W_TICSPERFRAME; ++c)
        {
-               c += 1;
                if (w && !(actor.weapons & WepSet_FromWeapon(w)))
                {
                        if (actor.weapon == actor.switchweapon) W_SwitchWeapon_Force(actor, w_getbestweapon(actor));
@@ -846,15 +855,15 @@ void W_WeaponFrame(entity actor)
                        }
                }
 
-               if (time + actor.weapon_frametime * 0.5 >= actor.weapon_nextthink)
+               if (time + actor.weapon_frametime * 0.5 >= this.weapon_nextthink)
                {
-                       if (actor.weapon_think)
+                       if (this.weapon_think)
                        {
                                v_forward = fo;
                                v_right = ri;
                                v_up = up;
                                Weapon wpn = Weapons_from(actor.weapon);
-                               actor.weapon_think(wpn, actor, weaponentity,
+                               this.weapon_think(wpn, actor, weaponentity,
                                        (actor.BUTTON_ATCK ? 1 : 0) | (actor.BUTTON_ATCK2 ? 2 : 0));
                        }
                        else
@@ -871,8 +880,9 @@ void W_AttachToShotorg(entity actor, entity flash, vector offset)
        flash.owner = actor;
        flash.angles_z = random() * 360;
 
-       if (gettagindex(actor.(weaponentity), "shot")) setattachment(flash, actor.(weaponentity), "shot");
-       else setattachment(flash, actor.(weaponentity), "tag_shot");
+       entity this = actor.(weaponentity);
+       if (gettagindex(this, "shot")) setattachment(flash, this, "shot");
+       else setattachment(flash, this, "tag_shot");
        setorigin(flash, offset);
 
        entity xflash = spawn();
@@ -880,10 +890,10 @@ void W_AttachToShotorg(entity actor, entity flash, vector offset)
 
        flash.viewmodelforclient = actor;
 
-       if (actor.(weaponentity).oldorigin.x > 0)
+       if (this.oldorigin.x > 0)
        {
                setattachment(xflash, actor.exteriorweaponentity, "");
-               setorigin(xflash, actor.(weaponentity).oldorigin + offset);
+               setorigin(xflash, this.oldorigin + offset);
        }
        else
        {
@@ -1020,12 +1030,13 @@ void W_Reload(entity actor, float sent_ammo_min, string sent_sound)
                }
        }
 
-       if (actor.(weaponentity))
+       entity this = actor.(weaponentity);
+       if (this)
        {
-               if (actor.(weaponentity).wframe == WFRAME_RELOAD) return;
+               if (this.wframe == WFRAME_RELOAD) return;
 
                // allow switching away while reloading, but this will cause a new reload!
-               actor.(weaponentity).state = WS_READY;
+               this.state = WS_READY;
        }
 
        // now begin the reloading process