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));
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;
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);
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;
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);
}
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
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)
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)
{
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))
{
{
actor.weapon = 0;
actor.switchingweapon = 0;
- actor.(weaponentity).state = WS_CLEAR;
+ this.state = WS_CLEAR;
actor.weaponname = "";
// actor.items &= ~IT_AMMO;
return;
// 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:
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
)
{
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;
// 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));
}
}
- 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
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();
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
{
}
}
- 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