]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/weapons/weapon/crylink.qc
Weapons: store switchweapon as direct weapon reference
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / weapons / weapon / crylink.qc
index 21565113deb92057590483998623cea6a937d410..56f9bba810335032411318d317b10a7be91fd6c2 100644 (file)
@@ -14,48 +14,51 @@ CLASS(Crylink, Weapon)
 /* wepimg    */ ATTRIB(Crylink, model2, string, "weaponcrylink");
 /* refname   */ ATTRIB(Crylink, netname, string, "crylink");
 /* wepname   */ ATTRIB(Crylink, m_name, string, _("Crylink"));
+
+#define X(BEGIN, P, END, class, prefix) \
+       BEGIN(class) \
+               P(class, prefix, ammo, float, BOTH) \
+        P(class, prefix, animtime, float, BOTH) \
+        P(class, prefix, bouncedamagefactor, float, BOTH) \
+        P(class, prefix, bounces, float, BOTH) \
+        P(class, prefix, damage, float, BOTH) \
+        P(class, prefix, edgedamage, float, BOTH) \
+        P(class, prefix, force, float, BOTH) \
+        P(class, prefix, joindelay, float, BOTH) \
+        P(class, prefix, joinexplode, float, BOTH) \
+        P(class, prefix, joinexplode_damage, float, BOTH) \
+        P(class, prefix, joinexplode_edgedamage, float, BOTH) \
+        P(class, prefix, joinexplode_force, float, BOTH) \
+        P(class, prefix, joinexplode_radius, float, BOTH) \
+        P(class, prefix, joinspread, float, BOTH) \
+        P(class, prefix, linkexplode, float, BOTH) \
+        P(class, prefix, middle_fadetime, float, BOTH) \
+        P(class, prefix, middle_lifetime, float, BOTH) \
+        P(class, prefix, other_fadetime, float, BOTH) \
+        P(class, prefix, other_lifetime, float, BOTH) \
+        P(class, prefix, radius, float, BOTH) \
+        P(class, prefix, refire, float, BOTH) \
+        P(class, prefix, reload_ammo, float, NONE) \
+        P(class, prefix, reload_time, float, NONE) \
+        P(class, prefix, secondary, float, NONE) \
+        P(class, prefix, shots, float, BOTH) \
+        P(class, prefix, speed, float, BOTH) \
+        P(class, prefix, spreadtype, float, SEC) \
+        P(class, prefix, spread, float, BOTH) \
+        P(class, prefix, switchdelay_drop, float, NONE) \
+        P(class, prefix, switchdelay_raise, float, NONE) \
+        P(class, prefix, weaponreplace, string, NONE) \
+        P(class, prefix, weaponstartoverride, float, NONE) \
+        P(class, prefix, weaponstart, float, NONE) \
+        P(class, prefix, weaponthrowable, float, NONE) \
+       END()
+       W_PROPS(X, Crylink, crylink)
+#undef X
+
 ENDCLASS(Crylink)
-REGISTER_WEAPON(CRYLINK, NEW(Crylink));
-
-#define CRYLINK_SETTINGS(w_cvar,w_prop) CRYLINK_SETTINGS_LIST(w_cvar, w_prop, CRYLINK, crylink)
-#define CRYLINK_SETTINGS_LIST(w_cvar,w_prop,id,sn) \
-       w_cvar(id, sn, BOTH, ammo) \
-       w_cvar(id, sn, BOTH, animtime) \
-       w_cvar(id, sn, BOTH, damage) \
-       w_cvar(id, sn, BOTH, edgedamage) \
-       w_cvar(id, sn, BOTH, radius) \
-       w_cvar(id, sn, BOTH, force) \
-       w_cvar(id, sn, BOTH, spread) \
-       w_cvar(id, sn, BOTH, refire) \
-       w_cvar(id, sn, BOTH, speed) \
-       w_cvar(id, sn, BOTH, shots) \
-       w_cvar(id, sn, BOTH, bounces) \
-       w_cvar(id, sn, BOTH, bouncedamagefactor) \
-       w_cvar(id, sn, BOTH, middle_lifetime) \
-       w_cvar(id, sn, BOTH, middle_fadetime) \
-       w_cvar(id, sn, BOTH, other_lifetime) \
-       w_cvar(id, sn, BOTH, other_fadetime) \
-       w_cvar(id, sn, BOTH, linkexplode) \
-       w_cvar(id, sn, BOTH, joindelay) \
-       w_cvar(id, sn, BOTH, joinspread) \
-       w_cvar(id, sn, BOTH, joinexplode) \
-       w_cvar(id, sn, BOTH, joinexplode_damage) \
-       w_cvar(id, sn, BOTH, joinexplode_edgedamage) \
-       w_cvar(id, sn, BOTH, joinexplode_radius) \
-       w_cvar(id, sn, BOTH, joinexplode_force) \
-       w_cvar(id, sn, SEC,  spreadtype) \
-       w_cvar(id, sn, NONE, secondary) \
-       w_prop(id, sn, float,  reloading_ammo, reload_ammo) \
-       w_prop(id, sn, float,  reloading_time, reload_time) \
-       w_prop(id, sn, float,  switchdelay_raise, switchdelay_raise) \
-       w_prop(id, sn, float,  switchdelay_drop, switchdelay_drop) \
-       w_prop(id, sn, string, weaponreplace, weaponreplace) \
-       w_prop(id, sn, float,  weaponstart, weaponstart) \
-       w_prop(id, sn, float,  weaponstartoverride, weaponstartoverride) \
-       w_prop(id, sn, float,  weaponthrowable, weaponthrowable)
+REGISTER_WEAPON(CRYLINK, crylink, NEW(Crylink));
 
 #ifdef SVQC
-CRYLINK_SETTINGS(WEP_ADD_CVAR, WEP_ADD_PROP)
 .float gravity;
 .float crylink_waitrelease;
 .entity crylink_lastgroup;
@@ -108,10 +111,10 @@ void W_Crylink_Dequeue(entity e)
        W_Crylink_Dequeue_Raw(e.realowner, e.queueprev, e, e.queuenext);
 }
 
-void W_Crylink_Reset(void)
-{SELFPARAM();
-       W_Crylink_Dequeue(self);
-       remove(self);
+void W_Crylink_Reset(entity this)
+{
+       W_Crylink_Dequeue(this);
+       remove(this);
 }
 
 // force projectile to explode
@@ -225,7 +228,7 @@ vector W_Crylink_LinkJoin(entity e, float jspeed)
        return targ_origin;
 }
 
-void W_Crylink_LinkJoinEffect_Think(void)
+void W_Crylink_LinkJoinEffect_Think()
 {SELFPARAM();
        // is there at least 2 projectiles very close?
        entity e, p;
@@ -290,7 +293,7 @@ float W_Crylink_Touch_WouldHitFriendly(entity projectile, float rad)
 }
 
 // NO bounce protection, as bounces are limited!
-void W_Crylink_Touch(void)
+void W_Crylink_Touch()
 {SELFPARAM();
        float finalhit;
        float f;
@@ -335,7 +338,7 @@ void W_Crylink_Touch(void)
        //      CSQCProjectile(proj, true, PROJECTILE_CRYLINK, true);
 }
 
-void W_Crylink_Fadethink(void)
+void W_Crylink_Fadethink()
 {SELFPARAM();
        W_Crylink_Dequeue(self);
        remove(self);
@@ -366,10 +369,9 @@ void W_Crylink_Attack(Weapon thiswep)
        proj = prevproj = firstproj = world;
        for(counter = 0; counter < shots; ++counter)
        {
-               proj = spawn();
+               proj = new(spike);
                proj.reset = W_Crylink_Reset;
                proj.realowner = proj.owner = self;
-               proj.classname = "spike";
                proj.bot_dodge = true;
                proj.bot_dodgerating = WEP_CVAR_PRI(crylink, damage);
                if(shots == 1) {
@@ -475,10 +477,9 @@ void W_Crylink_Attack2(Weapon thiswep)
        proj = prevproj = firstproj = world;
        for(counter = 0; counter < shots; ++counter)
        {
-               proj = spawn();
+               proj = new(spike);
                proj.reset = W_Crylink_Reset;
                proj.realowner = proj.owner = self;
-               proj.classname = "spike";
                proj.bot_dodge = true;
                proj.bot_dodgerating = WEP_CVAR_SEC(crylink, damage);
                if(shots == 1) {
@@ -574,30 +575,29 @@ void W_Crylink_Attack2(Weapon thiswep)
                        else
                                self.BUTTON_ATCK2 = bot_aim(WEP_CVAR_SEC(crylink, speed), 0, WEP_CVAR_SEC(crylink, middle_lifetime), false);
                }
-               METHOD(Crylink, wr_think, void(entity thiswep, entity actor, int slot, int fire))
+               METHOD(Crylink, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire))
                {
                        if(autocvar_g_balance_crylink_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(crylink, ammo), WEP_CVAR_SEC(crylink, ammo))) { // forced reload
-                               Weapon w = get_weaponinfo(actor.weapon);
-                               w.wr_reload(w);
+                               thiswep.wr_reload(thiswep);
                        }
 
                        if(fire & 1)
                        {
                                if(actor.crylink_waitrelease != 1)
-                               if(weapon_prepareattack(thiswep, actor, slot, false, WEP_CVAR_PRI(crylink, refire)))
+                               if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(crylink, refire)))
                                {
                                        W_Crylink_Attack(thiswep);
-                                       weapon_thinkf(actor, slot, WFRAME_FIRE1, WEP_CVAR_PRI(crylink, animtime), w_ready);
+                                       weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(crylink, animtime), w_ready);
                                }
                        }
 
                        if((fire & 2) && autocvar_g_balance_crylink_secondary)
                        {
                                if(actor.crylink_waitrelease != 2)
-                               if(weapon_prepareattack(thiswep, actor, slot, true, WEP_CVAR_SEC(crylink, refire)))
+                               if(weapon_prepareattack(thiswep, actor, weaponentity, true, WEP_CVAR_SEC(crylink, refire)))
                                {
                                        W_Crylink_Attack2(thiswep);
-                                       weapon_thinkf(actor, slot, WFRAME_FIRE2, WEP_CVAR_SEC(crylink, animtime), w_ready);
+                                       weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, WEP_CVAR_SEC(crylink, animtime), w_ready);
                                }
                        }
 
@@ -614,9 +614,8 @@ void W_Crylink_Attack2(Weapon thiswep)
 
                                                pos = W_Crylink_LinkJoin(actor.crylink_lastgroup, WEP_CVAR_BOTH(crylink, isprimary, joinspread) * WEP_CVAR_BOTH(crylink, isprimary, speed));
 
-                                               linkjoineffect = spawn();
+                                               linkjoineffect = new(linkjoineffect);
                                                linkjoineffect.think = W_Crylink_LinkJoinEffect_Think;
-                                               linkjoineffect.classname = "linkjoineffect";
                                                linkjoineffect.nextthink = time + w_crylink_linkjoin_time;
                                                linkjoineffect.owner = actor;
                                                setorigin(linkjoineffect, pos);
@@ -627,15 +626,11 @@ void W_Crylink_Attack2(Weapon thiswep)
                                        {
                                                // ran out of ammo!
                                                actor.cnt = WEP_CRYLINK.m_id;
-                                               actor.switchweapon = w_getbestweapon(actor);
+                                               PS(actor).m_switchweapon = w_getbestweapon(actor);
                                        }
                                }
                        }
                }
-               METHOD(Crylink, wr_init, void(entity thiswep))
-               {
-                       CRYLINK_SETTINGS(WEP_SKIP_CVAR, WEP_SET_PROP);
-               }
                METHOD(Crylink, wr_checkammo1, bool(entity thiswep))
                {
                        SELFPARAM();
@@ -658,10 +653,6 @@ void W_Crylink_Attack2(Weapon thiswep)
                        ammo_amount += self.(weapon_load[WEP_CRYLINK.m_id]) >= WEP_CVAR_SEC(crylink, ammo);
                        return ammo_amount;
                }
-               METHOD(Crylink, wr_config, void(entity thiswep))
-               {
-                       CRYLINK_SETTINGS(WEP_CONFIG_WRITE_CVARS, WEP_CONFIG_WRITE_PROPS);
-               }
                METHOD(Crylink, wr_reload, void(entity thiswep))
                {
                        W_Reload(self, min(WEP_CVAR_PRI(crylink, ammo), WEP_CVAR_SEC(crylink, ammo)), SND(RELOAD));
@@ -683,13 +674,13 @@ void W_Crylink_Attack2(Weapon thiswep)
                        org2 = w_org + w_backoff * 2;
                        if(w_deathtype & HITTYPE_SECONDARY)
                        {
-                               pointparticles(particleeffectnum(EFFECT_CRYLINK_IMPACT2), org2, '0 0 0', 1);
+                               pointparticles(EFFECT_CRYLINK_IMPACT2, org2, '0 0 0', 1);
                                if(!w_issilent)
                                        sound(self, CH_SHOTS, SND_CRYLINK_IMPACT2, VOL_BASE, ATTN_NORM);
                        }
                        else
                        {
-                               pointparticles(particleeffectnum(EFFECT_CRYLINK_IMPACT), org2, '0 0 0', 1);
+                               pointparticles(EFFECT_CRYLINK_IMPACT, org2, '0 0 0', 1);
                                if(!w_issilent)
                                        sound(self, CH_SHOTS, SND_CRYLINK_IMPACT, VOL_BASE, ATTN_NORM);
                        }