- if (name != "")
- {
- // if there is a child entity, hide it until we're sure we use it
- if (this.weaponentity[slot]) this.weaponentity[slot].model = "";
- _setmodel(this, W_Model(strcat("v_", name, ".md3")));
- int v_shot_idx = gettagindex(this, "shot"); // used later
- if (!v_shot_idx) v_shot_idx = gettagindex(this, "tag_shot");
-
- _setmodel(this, W_Model(strcat("h_", name, ".iqm")));
- // preset some defaults that work great for renamed zym files (which don't need an animinfo)
- this.anim_fire1 = animfixfps(this, '0 1 0.01', '0 0 0');
- this.anim_fire2 = animfixfps(this, '1 1 0.01', '0 0 0');
- this.anim_idle = animfixfps(this, '2 1 0.01', '0 0 0');
- this.anim_reload = animfixfps(this, '3 1 0.01', '0 0 0');
-
- // if we have a "weapon" tag, let's attach the v_ model to it ("invisible hand" style model)
- // if we don't, this is a "real" animated model
- if (gettagindex(this, "weapon"))
- {
- if (!this.weaponentity[slot]) this.weaponentity[slot] = spawn();
- _setmodel(this.weaponentity[slot], W_Model(strcat("v_", name, ".md3")));
- setattachment(this.weaponentity[slot], this, "weapon");
- }
- else if (gettagindex(this, "tag_weapon"))
- {
- if (!this.weaponentity[slot]) this.weaponentity[slot] = spawn();
- _setmodel(this.weaponentity[slot], W_Model(strcat("v_", name, ".md3")));
- setattachment(this.weaponentity[slot], this, "tag_weapon");
- }
- else
- {
- if (this.weaponentity[slot]) remove(this.weaponentity[slot]);
- this.weaponentity[slot] = NULL;
- }
-
- setorigin(this, '0 0 0');
- this.angles = '0 0 0';
- this.frame = 0;
- this.viewmodelforclient = NULL;
-
- float idx;
-
- if (v_shot_idx) // v_ model attached to invisible h_ model
- {
- this.movedir = gettaginfo(this.weaponentity[slot], v_shot_idx);
- }
- else
- {
- idx = gettagindex(this, "shot");
- if (!idx) idx = gettagindex(this, "tag_shot");
- if (idx)
- {
- this.movedir = gettaginfo(this, idx);
- }
- else
- {
- LOG_INFO("WARNING: weapon model ", this.model,
- " does not support the 'shot' tag, will display shots TOTALLY wrong\n");
- this.movedir = '0 0 0';
- }
- }
-
- if (this.weaponentity[slot]) // v_ model attached to invisible h_ model
- {
- idx = gettagindex(this.weaponentity[slot], "shell");
- if (!idx) idx = gettagindex(this.weaponentity[slot], "tag_shell");
- if (idx) this.spawnorigin = gettaginfo(this.weaponentity[slot], idx);
- }
- else
- {
- idx = 0;
- }
- if (!idx)
- {
- idx = gettagindex(this, "shell");
- if (!idx) idx = gettagindex(this, "tag_shell");
- if (idx)
- {
- this.spawnorigin = gettaginfo(this, idx);
- }
- else
- {
- LOG_INFO("WARNING: weapon model ", this.model,
- " does not support the 'shell' tag, will display casings wrong\n");
- this.spawnorigin = this.movedir;
- }
- }
-
- if (v_shot_idx)
- {
- this.oldorigin = '0 0 0'; // use regular attachment
- }
- else
- {
- if (this.weaponentity[slot])
- {
- idx = gettagindex(this, "weapon");
- if (!idx) idx = gettagindex(this, "tag_weapon");
- }
- else
- {
- idx = gettagindex(this, "handle");
- if (!idx) idx = gettagindex(this, "tag_handle");
- }
- if (idx)
- {
- this.oldorigin = this.movedir - gettaginfo(this, idx);
- }
- else
- {
- LOG_INFO("WARNING: weapon model ", this.model,
- " does not support the 'handle' tag and neither does the v_ model support the 'shot' tag, will display muzzle flashes TOTALLY wrong\n");
- this.oldorigin = '0 0 0'; // there is no way to recover from this
- }
- }
-
- this.viewmodelforclient = this.owner;
- }
- else
- {
- this.model = "";
- if (this.weaponentity[slot]) remove(this.weaponentity[slot]);
- this.weaponentity[slot] = NULL;
- this.movedir = '0 0 0';
- this.spawnorigin = '0 0 0';
- this.oldorigin = '0 0 0';
- this.anim_fire1 = '0 1 0.01';
- this.anim_fire2 = '0 1 0.01';
- this.anim_idle = '0 1 0.01';
- this.anim_reload = '0 1 0.01';
- }
-
- this.view_ofs = '0 0 0';
-
- if (this.movedir.x >= 0)
- {
- vector v0 = this.movedir;
- this.movedir = shotorg_adjust(v0, false, false, this.owner.cvar_cl_gunalign);
- this.view_ofs = shotorg_adjust(v0, false, true, this.owner.cvar_cl_gunalign) - v0;
- }
- this.owner.stat_shotorg = compressShotOrigin(this.movedir);
- this.movedir = decompressShotOrigin(this.owner.stat_shotorg); // make them match perfectly
-
- this.spawnorigin += this.view_ofs; // offset the casings origin by the same amount
-
- // check if an instant weapon switch occurred
- setorigin(this, this.view_ofs);
- // reset animstate now
- this.wframe = WFRAME_IDLE;
- setanim(this, this.anim_idle, true, false, true);
-}
-
-vector CL_Weapon_GetShotOrg(float wpn)
-{
- entity wi = get_weaponinfo(wpn);