#include "items.qh" #include #include #include #include #include #include #include .vector item_glowmod; .bool item_simple; // probably not really needed, but better safe than sorry .float alpha; .bool pushable; .float anim_start_time; // reusing for bob waveform synchronisation .vector angles_held; // reusing for (re)storing original angles void ItemDraw(entity this) { // no bobbing applied to simple items, for consistency's sake (no visual difference between ammo and weapons) bool animate = autocvar_cl_items_animate & 1 && this.item_simple <= 0 && (this.ItemStatus & ITS_ANIMATE1 || this.ItemStatus & ITS_ANIMATE2); // rotation must be set before running physics if(!animate) { this.avelocity_y = 0; this.angles = this.angles_held; // restore angles sent from server } else if(!this.avelocity_y) // unset by MOVETYPE_TOSS or animation was disabled previously { if(this.ItemStatus & ITS_ANIMATE1) this.avelocity_y = 180; else if(this.ItemStatus & ITS_ANIMATE2) this.avelocity_y = -90; } // CSQC physics OR bobbing (both would look weird) float bobheight = 0; // reset bob offset if animations are disabled if(this.move_movetype && (!IS_ONGROUND(this) || this.velocity != '0 0 0')) { // this isn't equivalent to player prediction but allows smooth motion with very low ISF_LOCATION rate // which requires running this even if the item is just outside visible range (it could be moving into range) if(animate) bobheight = this.origin_z - this.oldorigin_z; Movetype_Physics_MatchServer(this, false); this.oldorigin = this.origin; // update real (SVQC equivalent) origin if(animate) { if(bobheight) { this.anim_start_time += frametime; // bobbing is paused this frame this.oldorigin_z -= bobheight; // restore bob offset (CSQC physics uses the offset bbox) } else { this.anim_start_time = time; // starting our bob animation from NOW if(this.ItemStatus & ITS_ANIMATE1) bobheight = 10; // height of wave at 0 time else if(this.ItemStatus & ITS_ANIMATE2) bobheight = 8; // height of wave at 0 time } } } else if(animate) { this.angles += this.avelocity * frametime; // MOVETYPE_TOSS does this while it's moving if(this.ItemStatus & ITS_ANIMATE1) bobheight = 10 + 8 * sin((time - this.anim_start_time) * 2); else if(this.ItemStatus & ITS_ANIMATE2) bobheight = 8 + 4 * sin((time - this.anim_start_time) * 3); } // apply new bob offset if (bobheight != this.origin_z - this.oldorigin_z) { this.origin_z = this.oldorigin_z + bobheight; this.mins_z = 0 - bobheight; // don't want the absmin and absmax to bob this.maxs_z = 48 - bobheight; // bones_was_here TODO: network proper box size for sv_legacy_bbox_expand 0 } // set alpha based on distance this.alpha = 1; this.drawmask = 0; if(this.fade_end && !warpzone_warpzones_exist) { vector org = getpropertyvec(VF_ORIGIN); if(vdist(org - this.origin, >, this.fade_end)) this.alpha = 0; // save on some processing else if(autocvar_cl_items_fadedist > 0) { this.fade_start = max(500, this.fade_end - autocvar_cl_items_fadedist); if(vdist(org - this.origin, >, this.fade_start)) this.alpha = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1); } } if(!this.alpha) return; // modify alpha based on availability and vehicle hud if(this.ItemStatus & ITS_AVAILABLE) { if(hud) // apparently this means we're in a vehicle lol { this.alpha *= autocvar_cl_items_vehicle_alpha; this.colormod = this.glowmod = autocvar_cl_items_vehicle_color; } else if(this.ItemStatus & ITS_STAYWEP) { this.alpha *= autocvar_cl_weapon_stay_alpha; this.colormod = this.glowmod = autocvar_cl_weapon_stay_color; } else { this.colormod = '1 1 1'; this.glowmod = this.item_glowmod; } } else { this.alpha *= autocvar_cl_ghost_items; this.colormod = this.glowmod = autocvar_cl_ghost_items_color; } this.drawmask = this.alpha <= 0 ? 0 : MASK_NORMAL; } void ItemRemove(entity this) { strfree(this.mdl); } HashMap ENT_CLIENT_ITEM_simple; STATIC_INIT(ENT_CLIENT_ITEM_simple) { HM_NEW(ENT_CLIENT_ITEM_simple); } SHUTDOWN(ENT_CLIENT_ITEM_simple) { HM_DELETE(ENT_CLIENT_ITEM_simple); } NET_HANDLE(ENT_CLIENT_ITEM, bool isnew) { int sf = ReadByte(); if(sf & ISF_LOCATION) { float bobheight = this.origin_z - this.oldorigin_z; this.origin = this.oldorigin = ReadVector(); this.origin_z += bobheight; // restore animation offset (SVQC physics is unaware of CSQC bbox offset) setorigin(this, this.origin); // link } if(sf & ISF_ANGLES) { this.angles = this.angles_held = ReadAngleVector(); } if(sf & ISF_SIZE) { setsize(this, '-16 -16 0', '16 16 48'); } if(sf & ISF_STATUS) // need to read/write status first so model can handle simple, fb etc. { this.ItemStatus = ReadByte(); if(this.ItemStatus & ITS_ALLOWFB) this.effects |= EF_FULLBRIGHT; else this.effects &= ~EF_FULLBRIGHT; if(this.ItemStatus & ITS_GLOW) { if(this.ItemStatus & ITS_AVAILABLE) this.effects |= (EF_ADDITIVE | EF_FULLBRIGHT); else this.effects &= ~(EF_ADDITIVE | EF_FULLBRIGHT); } } if(sf & ISF_MODEL) { if (isnew) IL_PUSH(g_drawables, this); this.draw = ItemDraw; this.solid = SOLID_TRIGGER; //this.flags |= FL_ITEM; this.fade_end = ReadShort(); strfree(this.mdl); string _fn = ReadString(); this.item_simple = false; // reset it! if(autocvar_cl_simple_items && (this.ItemStatus & ITS_ALLOWSI)) { string _fn2 = substring(_fn, 0 , strlen(_fn) -4); this.item_simple = true; #define extensions(x) \ x(md3) \ x(dpm) \ x(iqm) \ x(mdl) \ /**/ #define tryext(ext) { \ string s = strcat(_fn2, autocvar_cl_simpleitems_postfix, "." #ext); \ string cached = HM_gets(ENT_CLIENT_ITEM_simple, s); \ if (cached == "") { \ HM_sets(ENT_CLIENT_ITEM_simple, s, cached = fexists(s) ? "1" : "0"); \ } \ if (cached != "0") { \ strcpy(this.mdl, s); \ break; \ } \ } do { extensions(tryext); this.item_simple = false; LOG_TRACEF("Simple item requested for %s but no model exists for it", _fn); } while (0); #undef tryext #undef extensions } if(!this.item_simple) strcpy(this.mdl, _fn); if(this.mdl == "") LOG_WARNF("this.mdl is unset for item %s", this.classname); precache_model(this.mdl); _setmodel(this, this.mdl); this.skin = ReadByte(); setsize(this, '-16 -16 0', '16 16 48'); } if(sf & ISF_COLORMAP) { this.colormap = ReadShort(); this.item_glowmod_x = ReadByte() / 255.0; this.item_glowmod_y = ReadByte() / 255.0; this.item_glowmod_z = ReadByte() / 255.0; } if(sf & ISF_DROP) { this.gravity = 1; this.pushable = true; //this.angles = '0 0 0'; set_movetype(this, MOVETYPE_TOSS); this.velocity = ReadVector(); if(!this.move_time) { this.move_time = time; this.spawntime = time; } else this.move_time = max(this.move_time, time); } this.entremove = ItemRemove; return true; }