From c3e3dd71484d563af474cb4b9e8624b6093e0b0f Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 2 Aug 2020 08:37:28 +1000 Subject: [PATCH] Reorganise item code so that VM-specific code is in its correct directories and not considered common code --- qcsrc/client/_mod.inc | 1 + qcsrc/client/_mod.qh | 1 + qcsrc/client/hud/hud.qc | 2 +- qcsrc/client/hud/panel/ammo.qc | 2 +- qcsrc/client/items/_mod.inc | 2 + qcsrc/client/items/_mod.qh | 2 + qcsrc/client/items/items.qc | 273 ++++++++++++++++ qcsrc/client/items/items.qh | 19 ++ qcsrc/client/main.qc | 2 +- qcsrc/common/_all.inc | 1 - qcsrc/common/_mod.inc | 1 - qcsrc/common/_mod.qh | 1 - qcsrc/common/items/item.qh | 28 +- qcsrc/common/items/item/ammo.qh | 2 +- qcsrc/common/items/item/armor.qh | 2 +- qcsrc/common/items/item/health.qh | 2 +- qcsrc/common/items/item/jetpack.qh | 2 +- qcsrc/common/items/item/powerup.qh | 4 + .../common/mutators/mutator/instagib/items.qh | 6 + qcsrc/lib/warpzone/common.qc | 2 +- qcsrc/server/bot/default/bot.qc | 2 +- qcsrc/server/bot/default/navigation.qc | 2 +- qcsrc/server/compat/quake3.qc | 2 +- qcsrc/server/g_damage.qc | 2 +- qcsrc/server/g_damage.qh | 2 +- qcsrc/server/items/_mod.inc | 1 + qcsrc/server/items/_mod.qh | 1 + qcsrc/{common => server/items}/items.qc | 309 +----------------- qcsrc/{common => server/items}/items.qh | 46 --- qcsrc/server/miscfunctions.qc | 2 +- qcsrc/server/miscfunctions.qh | 2 +- qcsrc/server/weapons/common.qc | 2 +- qcsrc/server/weapons/csqcprojectile.qc | 2 +- qcsrc/server/weapons/selection.qc | 2 +- qcsrc/server/weapons/spawning.qc | 2 +- qcsrc/server/weapons/throwing.qc | 2 +- qcsrc/server/weapons/weaponsystem.qc | 2 +- 37 files changed, 373 insertions(+), 365 deletions(-) create mode 100644 qcsrc/client/items/_mod.inc create mode 100644 qcsrc/client/items/_mod.qh create mode 100644 qcsrc/client/items/items.qc create mode 100644 qcsrc/client/items/items.qh rename qcsrc/{common => server/items}/items.qc (85%) rename qcsrc/{common => server/items}/items.qh (75%) diff --git a/qcsrc/client/_mod.inc b/qcsrc/client/_mod.inc index ab9184b9b9..1bd12928a9 100644 --- a/qcsrc/client/_mod.inc +++ b/qcsrc/client/_mod.inc @@ -13,5 +13,6 @@ #include #include +#include #include #include diff --git a/qcsrc/client/_mod.qh b/qcsrc/client/_mod.qh index 971cc01de6..1f008660b9 100644 --- a/qcsrc/client/_mod.qh +++ b/qcsrc/client/_mod.qh @@ -13,5 +13,6 @@ #include #include +#include #include #include diff --git a/qcsrc/client/hud/hud.qc b/qcsrc/client/hud/hud.qc index 0bcf1fefde..c8191ba9e3 100644 --- a/qcsrc/client/hud/hud.qc +++ b/qcsrc/client/hud/hud.qc @@ -1,6 +1,7 @@ #include "hud.qh" #include +#include #include #include #include "panel/scoreboard.qh" @@ -8,7 +9,6 @@ #include "../mapvoting.qh" #include "../teamradar.qh" #include -#include #include #include #include diff --git a/qcsrc/client/hud/panel/ammo.qc b/qcsrc/client/hud/panel/ammo.qc index ea4c1f5acf..69a42f426d 100644 --- a/qcsrc/client/hud/panel/ammo.qc +++ b/qcsrc/client/hud/panel/ammo.qc @@ -2,9 +2,9 @@ #include #include +#include #include #include -#include #include #include diff --git a/qcsrc/client/items/_mod.inc b/qcsrc/client/items/_mod.inc new file mode 100644 index 0000000000..781cf2a60d --- /dev/null +++ b/qcsrc/client/items/_mod.inc @@ -0,0 +1,2 @@ +// generated file; do not modify +#include diff --git a/qcsrc/client/items/_mod.qh b/qcsrc/client/items/_mod.qh new file mode 100644 index 0000000000..39d72e23aa --- /dev/null +++ b/qcsrc/client/items/_mod.qh @@ -0,0 +1,2 @@ +// generated file; do not modify +#include diff --git a/qcsrc/client/items/items.qc b/qcsrc/client/items/items.qc new file mode 100644 index 0000000000..72f69ee07f --- /dev/null +++ b/qcsrc/client/items/items.qc @@ -0,0 +1,273 @@ +#include "items.qh" + +#include + +#include +#include +#include +#include +#include +#include + +bool autocvar_cl_ghost_items_vehicle = true; +.vector item_glowmod; +.bool item_simple; // probably not really needed, but better safe than sorry +.float alpha; +void Item_SetAlpha(entity this) +{ + bool veh_hud = (hud && autocvar_cl_ghost_items_vehicle); + + if(!veh_hud && (this.ItemStatus & ITS_AVAILABLE)) + { + this.alpha = 1; + 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; + } + + if((!veh_hud) && (this.ItemStatus & ITS_STAYWEP)) + { + this.colormod = this.glowmod = autocvar_cl_weapon_stay_color; + this.alpha = autocvar_cl_weapon_stay_alpha; + } + + this.drawmask = ((this.alpha <= 0) ? 0 : MASK_NORMAL); +} + +void ItemDraw(entity this) +{ + if(this.gravity) + { + Movetype_Physics_MatchServer(this, false); + if(IS_ONGROUND(this)) + { // For some reason avelocity gets set to '0 0 0' here ... + this.oldorigin = this.origin; + this.gravity = 0; + + if(autocvar_cl_animate_items) + { // ... so reset it if animations are requested. + if(this.ItemStatus & ITS_ANIMATE1) + this.avelocity = '0 180 0'; + + if(this.ItemStatus & ITS_ANIMATE2) + this.avelocity = '0 -90 0'; + } + + // delay is for blocking item's position for a while; + // it's a workaround for dropped weapons that receive the position + // another time right after they spawn overriding animation position + this.onground_time = time + 0.5; + } + } + else if (autocvar_cl_animate_items && !this.item_simple) // no bobbing applied to simple items, for consistency's sake (no visual difference between ammo and weapons) + { + if(this.ItemStatus & ITS_ANIMATE1) + { + this.angles += this.avelocity * frametime; + float fade_in = bound(0, time - this.onground_time, 1); + setorigin(this, this.oldorigin + fade_in * ('0 0 10' + '0 0 8' * sin((time - this.onground_time) * 2))); + } + + if(this.ItemStatus & ITS_ANIMATE2) + { + this.angles += this.avelocity * frametime; + float fade_in = bound(0, time - this.onground_time, 1); + setorigin(this, this.oldorigin + fade_in * ('0 0 8' + '0 0 4' * sin((time - this.onground_time) * 3))); + } + } + + Item_SetAlpha(this); +} + +void Item_PreDraw(entity this) +{ + if(warpzone_warpzones_exist) + { + setpredraw(this, func_null); // no need to keep running this + return; + } + float alph; + vector org = getpropertyvec(VF_ORIGIN); + //if(!checkpvs(org, this)) // this makes sense as long as we don't support recursive warpzones + //alph = 0; // this shouldn't be needed, since items behind walls are culled anyway + if(this.fade_start) + { + if(vdist(org - this.origin, >, this.fade_end)) + alph = 0; // save on some processing + else if(vdist(org - this.origin, <, this.fade_start)) + alph = 1; // more processing saved + else + alph = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1); + } + else + alph = 1; + //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs)); + if(!hud && (this.ItemStatus & ITS_AVAILABLE)) + this.alpha = alph; + if(alph <= 0) + this.drawmask = 0; + //else + //this.drawmask = MASK_NORMAL; // reset by the setalpha function +} + +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) + { + this.origin = ReadVector(); + setorigin(this, this.origin); + this.oldorigin = this.origin; + } + + if(sf & ISF_ANGLES) + { + this.angles = 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(); + + Item_SetAlpha(this); + + 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) + { + this.drawmask = MASK_NORMAL; + set_movetype(this, MOVETYPE_TOSS); + if (isnew) IL_PUSH(g_drawables, this); + this.draw = ItemDraw; + this.solid = SOLID_TRIGGER; + //this.flags |= FL_ITEM; + + this.fade_end = ReadShort(); + this.fade_start = ReadShort(); + if(!warpzone_warpzones_exist && this.fade_start && !autocvar_cl_items_nofade) + setpredraw(this, Item_PreDraw); + + 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); + + 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(); + setorigin(this, this.oldorigin); + + if(!this.move_time) + { + this.move_time = time; + this.spawntime = time; + } + else + this.move_time = max(this.move_time, time); + } + + if(autocvar_cl_animate_items) + { + if(this.ItemStatus & ITS_ANIMATE1) + this.avelocity = '0 180 0'; + + if(this.ItemStatus & ITS_ANIMATE2) + this.avelocity = '0 -90 0'; + } + + this.entremove = ItemRemove; + + return true; +} diff --git a/qcsrc/client/items/items.qh b/qcsrc/client/items/items.qh new file mode 100644 index 0000000000..78e109db46 --- /dev/null +++ b/qcsrc/client/items/items.qh @@ -0,0 +1,19 @@ +#pragma once + +const int AMMO_COUNT = 4; // amount of ammo types to show in the ammo panel + +.float onground_time; + +bool autocvar_cl_items_nofade; +float autocvar_cl_animate_items = 1; +float autocvar_cl_ghost_items = 0.45; +vector autocvar_cl_ghost_items_color = '-1 -1 -1'; +vector autocvar_cl_weapon_stay_color = '2 0.5 0.5'; +float autocvar_cl_weapon_stay_alpha = 0.75; +float autocvar_cl_simple_items = 0; +string autocvar_cl_simpleitems_postfix = "_simple"; +.float spawntime; +.float gravity; +.vector colormod; + +void ItemDraw(entity this); diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index ab508e490e..9660a8137f 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -1,6 +1,7 @@ #include "main.qh" #include "defs.qh" +#include #include #include "miscfunctions.qh" #include @@ -16,7 +17,6 @@ #include "hud/panel/quickmenu.qh" #include "shownames.qh" #include "view.qh" -#include #include "weapons/projectile.qh" #include #include diff --git a/qcsrc/common/_all.inc b/qcsrc/common/_all.inc index 492b752ba1..fa80064c9a 100644 --- a/qcsrc/common/_all.inc +++ b/qcsrc/common/_all.inc @@ -39,7 +39,6 @@ noref float autocvar_net_connecttimeout = 30; #include "effects/all.qc" #include "impulses/all.qc" #include "notifications/all.qc" -#include "items.qc" #endif #include "items/_mod.inc" diff --git a/qcsrc/common/_mod.inc b/qcsrc/common/_mod.inc index 5df2bbd819..bc4b66aec1 100644 --- a/qcsrc/common/_mod.inc +++ b/qcsrc/common/_mod.inc @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/qcsrc/common/_mod.qh b/qcsrc/common/_mod.qh index 853712e13c..7aadf6aa1d 100644 --- a/qcsrc/common/_mod.qh +++ b/qcsrc/common/_mod.qh @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/qcsrc/common/items/item.qh b/qcsrc/common/items/item.qh index ef909382b8..02151e3074 100644 --- a/qcsrc/common/items/item.qh +++ b/qcsrc/common/items/item.qh @@ -11,6 +11,7 @@ #include #endif +#ifdef GAMEQC const int IT_UNLIMITED_AMMO = BIT(0); // when this bit is set, using a weapon does not reduce ammo. Checkpoints can give this powerup. const int IT_UNLIMITED_SUPERWEAPONS = BIT(1); // when this bit is set, superweapons don't expire. Checkpoints can give this powerup. @@ -23,8 +24,6 @@ const int IT_RESOURCE = BIT(5); // bitflag to mark this item as a reso const int IT_KEY1 = BIT(6); const int IT_KEY2 = BIT(7); -const int IT_CTF_SHIELDED = BIT(8); // set for the flag shield - // special colorblend meaning in engine const int IT_INVISIBILITY = BIT(9); const int IT_INVINCIBLE = BIT(10); @@ -34,6 +33,31 @@ const int IT_STRENGTH = BIT(12); // item masks const int IT_PICKUPMASK = IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS | IT_JETPACK | IT_FUEL_REGEN; // strength and invincible are handled separately +// item networking +const int ISF_LOCATION = BIT(1); +const int ISF_MODEL = BIT(2); +const int ISF_STATUS = BIT(3); +const int ISF_COLORMAP = BIT(4); +const int ISF_DROP = BIT(5); +const int ISF_ANGLES = BIT(6); +const int ISF_SIZE = BIT(7); + +REGISTER_NET_LINKED(ENT_CLIENT_ITEM) + +// item status +.int ItemStatus; +const int ITS_STAYWEP = BIT(0); +const int ITS_ANIMATE1 = BIT(1); +const int ITS_ANIMATE2 = BIT(2); +const int ITS_AVAILABLE = BIT(3); +const int ITS_ALLOWFB = BIT(4); +const int ITS_ALLOWSI = BIT(5); +const int ITS_GLOW = BIT(6); + +.float fade_start; +.float fade_end; +#endif + #ifdef SVQC .float strength_finished; // NOTE: this field is used only by map entities, it does not directly apply the strength stat .float invincible_finished; // ditto diff --git a/qcsrc/common/items/item/ammo.qh b/qcsrc/common/items/item/ammo.qh index aae18626dd..187080b37b 100644 --- a/qcsrc/common/items/item/ammo.qh +++ b/qcsrc/common/items/item/ammo.qh @@ -3,7 +3,7 @@ #include "pickup.qh" #include #ifdef SVQC - #include + #include #include #endif diff --git a/qcsrc/common/items/item/armor.qh b/qcsrc/common/items/item/armor.qh index 469288b77b..e5ae8e36bd 100644 --- a/qcsrc/common/items/item/armor.qh +++ b/qcsrc/common/items/item/armor.qh @@ -11,7 +11,7 @@ CLASS(Armor, Pickup) ENDCLASS(Armor) #ifdef SVQC - #include + #include #endif #ifdef GAMEQC diff --git a/qcsrc/common/items/item/health.qh b/qcsrc/common/items/item/health.qh index 734a3f39b4..27f5dafc6e 100644 --- a/qcsrc/common/items/item/health.qh +++ b/qcsrc/common/items/item/health.qh @@ -11,7 +11,7 @@ CLASS(Health, Pickup) ENDCLASS(Health) #ifdef SVQC - #include + #include #endif #ifdef GAMEQC diff --git a/qcsrc/common/items/item/jetpack.qh b/qcsrc/common/items/item/jetpack.qh index 41a6711200..962f16170b 100644 --- a/qcsrc/common/items/item/jetpack.qh +++ b/qcsrc/common/items/item/jetpack.qh @@ -1,7 +1,7 @@ #pragma once #ifdef SVQC - #include + #include #endif #include "ammo.qh" diff --git a/qcsrc/common/items/item/powerup.qh b/qcsrc/common/items/item/powerup.qh index 43414b3d06..395db46566 100644 --- a/qcsrc/common/items/item/powerup.qh +++ b/qcsrc/common/items/item/powerup.qh @@ -45,7 +45,9 @@ REGISTER_ITEM(Strength, Powerup) { this.m_color = '0 0 1'; this.m_waypoint = _("Strength"); this.m_waypointblink = 2; +#ifdef GAMEQC this.m_itemid = IT_STRENGTH; +#endif #ifdef SVQC this.m_iteminit = powerup_strength_init; #endif @@ -81,7 +83,9 @@ REGISTER_ITEM(Shield, Powerup) { this.m_color = '1 0 1'; this.m_waypoint = _("Shield"); this.m_waypointblink = 2; +#ifdef GAMEQC this.m_itemid = IT_INVINCIBLE; +#endif #ifdef SVQC this.m_iteminit = powerup_shield_init; #endif diff --git a/qcsrc/common/mutators/mutator/instagib/items.qh b/qcsrc/common/mutators/mutator/instagib/items.qh index c0aa831218..4724eda173 100644 --- a/qcsrc/common/mutators/mutator/instagib/items.qh +++ b/qcsrc/common/mutators/mutator/instagib/items.qh @@ -61,7 +61,9 @@ REGISTER_ITEM(ExtraLife, Powerup) { this.m_color = '1 0 0'; this.m_waypoint = _("Extra life"); this.m_waypointblink = 2; +#ifdef SVQC this.m_itemid = IT_RESOURCE; +#endif } SPAWNFUNC_ITEM(item_extralife, ITEM_ExtraLife) @@ -93,7 +95,9 @@ REGISTER_ITEM(Invisibility, Powerup) { this.m_color = '0 0 1'; this.m_waypoint = _("Invisibility"); this.m_waypointblink = 2; +#ifdef GAMEQC this.m_itemid = IT_STRENGTH; +#endif #ifdef SVQC this.m_iteminit = powerup_invisibility_init; #endif @@ -128,7 +132,9 @@ REGISTER_ITEM(Speed, Powerup) { this.m_color = '1 0 1'; this.m_waypoint = _("Speed"); this.m_waypointblink = 2; +#ifdef GAMEQC this.m_itemid = IT_INVINCIBLE; +#endif #ifdef SVQC this.m_iteminit = powerup_speed_init; #endif diff --git a/qcsrc/lib/warpzone/common.qc b/qcsrc/lib/warpzone/common.qc index 2438864a5e..830c56de65 100644 --- a/qcsrc/lib/warpzone/common.qc +++ b/qcsrc/lib/warpzone/common.qc @@ -1,7 +1,7 @@ #include "common.qh" #if defined(CSQC) - #include + #include #elif defined(MENUQC) #elif defined(SVQC) #include diff --git a/qcsrc/server/bot/default/bot.qc b/qcsrc/server/bot/default/bot.qc index 4594da27f7..bcf02da4bc 100644 --- a/qcsrc/server/bot/default/bot.qc +++ b/qcsrc/server/bot/default/bot.qc @@ -19,7 +19,7 @@ #include "../../constants.qh" #include "../../defs.qh" #include "../../race.qh" -#include +#include #include diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index 08da16f6f7..26d69abbd0 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -7,7 +7,7 @@ #include "bot.qh" #include "waypoints.qh" -#include +#include #include diff --git a/qcsrc/server/compat/quake3.qc b/qcsrc/server/compat/quake3.qc index 4103ccf29a..4c8073b1ad 100644 --- a/qcsrc/server/compat/quake3.qc +++ b/qcsrc/server/compat/quake3.qc @@ -2,10 +2,10 @@ #include #include +#include #include #include #include -#include #include #include #include diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index b26c779ebf..074a070e9f 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -4,13 +4,13 @@ #include "bot/api.qh" #include "g_hook.qh" #include +#include #include #include "teamplay.qh" #include "scores.qh" #include "spawnpoints.qh" #include "../common/state.qh" #include "../common/physics/player.qh" -#include "../common/items.qh" #include "resources.qh" #include "../common/vehicles/all.qh" #include "../common/items/_mod.qh" diff --git a/qcsrc/server/g_damage.qh b/qcsrc/server/g_damage.qh index 27cd8197d2..794b27ccc2 100644 --- a/qcsrc/server/g_damage.qh +++ b/qcsrc/server/g_damage.qh @@ -4,6 +4,7 @@ #elif defined(MENUQC) #elif defined(SVQC) #include + #include #include #include #include @@ -13,7 +14,6 @@ #include "weapons/accuracy.qh" #include "weapons/csqcprojectile.qh" #include "weapons/selection.qh" - #include #include "autocvars.qh" #include "constants.qh" #include "defs.qh" diff --git a/qcsrc/server/items/_mod.inc b/qcsrc/server/items/_mod.inc index 9c55d0b5c3..33936e230b 100644 --- a/qcsrc/server/items/_mod.inc +++ b/qcsrc/server/items/_mod.inc @@ -1,2 +1,3 @@ // generated file; do not modify +#include #include diff --git a/qcsrc/server/items/_mod.qh b/qcsrc/server/items/_mod.qh index eb6ff1ce5d..d64b2c0bf2 100644 --- a/qcsrc/server/items/_mod.qh +++ b/qcsrc/server/items/_mod.qh @@ -1,2 +1,3 @@ // generated file; do not modify +#include #include diff --git a/qcsrc/common/items.qc b/qcsrc/server/items/items.qc similarity index 85% rename from qcsrc/common/items.qc rename to qcsrc/server/items/items.qc index 02f44c3890..66b5bc9d4d 100644 --- a/qcsrc/common/items.qc +++ b/qcsrc/server/items/items.qc @@ -1,306 +1,30 @@ #include "items.qh" -#include "items/_mod.qh" +#include -#if defined(SVQC) +#include - #include "../server/bot/api.qh" +#include - #include +#include +#include +#include - #include "../server/weapons/common.qh" - #include "../server/weapons/selection.qh" - #include "../server/weapons/weaponsystem.qh" +#include +#include +#include +#include +#include - #include "constants.qh" - #include - #include - #include "mapobjects/subs.qh" - #include "util.qh" +#include - #include +#include - #include +#include +#include - #include - #include +#include - #include "../lib/warpzone/util_server.qh" -#elif defined(CSQC) - #include "physics/movetypes/movetypes.qh" - #include - #include "../lib/csqcmodel/cl_model.qh" - #include "../lib/csqcmodel/common.qh" -#endif - -REGISTER_NET_LINKED(ENT_CLIENT_ITEM) - -#ifdef CSQC -bool autocvar_cl_ghost_items_vehicle = true; -.vector item_glowmod; -.bool item_simple; // probably not really needed, but better safe than sorry -void Item_SetAlpha(entity this) -{ - bool veh_hud = (hud && autocvar_cl_ghost_items_vehicle); - - if(!veh_hud && (this.ItemStatus & ITS_AVAILABLE)) - { - this.alpha = 1; - 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; - } - - if((!veh_hud) && (this.ItemStatus & ITS_STAYWEP)) - { - this.colormod = this.glowmod = autocvar_cl_weapon_stay_color; - this.alpha = autocvar_cl_weapon_stay_alpha; - } - - this.drawmask = ((this.alpha <= 0) ? 0 : MASK_NORMAL); -} - -void ItemDraw(entity this) -{ - if(this.gravity) - { - Movetype_Physics_MatchServer(this, false); - if(IS_ONGROUND(this)) - { // For some reason avelocity gets set to '0 0 0' here ... - this.oldorigin = this.origin; - this.gravity = 0; - - if(autocvar_cl_animate_items) - { // ... so reset it if animations are requested. - if(this.ItemStatus & ITS_ANIMATE1) - this.avelocity = '0 180 0'; - - if(this.ItemStatus & ITS_ANIMATE2) - this.avelocity = '0 -90 0'; - } - - // delay is for blocking item's position for a while; - // it's a workaround for dropped weapons that receive the position - // another time right after they spawn overriding animation position - this.onground_time = time + 0.5; - } - } - else if (autocvar_cl_animate_items && !this.item_simple) // no bobbing applied to simple items, for consistency's sake (no visual difference between ammo and weapons) - { - if(this.ItemStatus & ITS_ANIMATE1) - { - this.angles += this.avelocity * frametime; - float fade_in = bound(0, time - this.onground_time, 1); - setorigin(this, this.oldorigin + fade_in * ('0 0 10' + '0 0 8' * sin((time - this.onground_time) * 2))); - } - - if(this.ItemStatus & ITS_ANIMATE2) - { - this.angles += this.avelocity * frametime; - float fade_in = bound(0, time - this.onground_time, 1); - setorigin(this, this.oldorigin + fade_in * ('0 0 8' + '0 0 4' * sin((time - this.onground_time) * 3))); - } - } - - Item_SetAlpha(this); -} - -void Item_PreDraw(entity this) -{ - if(warpzone_warpzones_exist) - { - setpredraw(this, func_null); // no need to keep running this - return; - } - float alph; - vector org = getpropertyvec(VF_ORIGIN); - //if(!checkpvs(org, this)) // this makes sense as long as we don't support recursive warpzones - //alph = 0; // this shouldn't be needed, since items behind walls are culled anyway - if(this.fade_start) - { - if(vdist(org - this.origin, >, this.fade_end)) - alph = 0; // save on some processing - else if(vdist(org - this.origin, <, this.fade_start)) - alph = 1; // more processing saved - else - alph = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1); - } - else - alph = 1; - //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs)); - if(!hud && (this.ItemStatus & ITS_AVAILABLE)) - this.alpha = alph; - if(alph <= 0) - this.drawmask = 0; - //else - //this.drawmask = MASK_NORMAL; // reset by the setalpha function -} - -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) - { - this.origin = ReadVector(); - setorigin(this, this.origin); - this.oldorigin = this.origin; - } - - if(sf & ISF_ANGLES) - { - this.angles = 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(); - - Item_SetAlpha(this); - - 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) - { - this.drawmask = MASK_NORMAL; - set_movetype(this, MOVETYPE_TOSS); - if (isnew) IL_PUSH(g_drawables, this); - this.draw = ItemDraw; - this.solid = SOLID_TRIGGER; - //this.flags |= FL_ITEM; - - this.fade_end = ReadShort(); - this.fade_start = ReadShort(); - if(!warpzone_warpzones_exist && this.fade_start && !autocvar_cl_items_nofade) - setpredraw(this, Item_PreDraw); - - 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); - - 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(); - setorigin(this, this.oldorigin); - - if(!this.move_time) - { - this.move_time = time; - this.spawntime = time; - } - else - this.move_time = max(this.move_time, time); - } - - if(autocvar_cl_animate_items) - { - if(this.ItemStatus & ITS_ANIMATE1) - this.avelocity = '0 180 0'; - - if(this.ItemStatus & ITS_ANIMATE2) - this.avelocity = '0 -90 0'; - } - - this.entremove = ItemRemove; - - return true; -} - -#endif - -#ifdef SVQC bool ItemSend(entity this, entity to, int sf) { if(this.gravity) @@ -1917,4 +1641,3 @@ float GiveItems(entity e, float beginarg, float endarg) return got; } -#endif diff --git a/qcsrc/common/items.qh b/qcsrc/server/items/items.qh similarity index 75% rename from qcsrc/common/items.qh rename to qcsrc/server/items/items.qh index 7b0d760df6..825bd2f019 100644 --- a/qcsrc/common/items.qh +++ b/qcsrc/server/items/items.qh @@ -1,53 +1,8 @@ #pragma once -const int AMMO_COUNT = 4; // amount of ammo types to show in the ammo panel - -// item networking -const int ISF_LOCATION = BIT(1); -const int ISF_MODEL = BIT(2); -const int ISF_STATUS = BIT(3); - const int ITS_STAYWEP = BIT(0); - const int ITS_ANIMATE1 = BIT(1); - const int ITS_ANIMATE2 = BIT(2); - const int ITS_AVAILABLE = BIT(3); - const int ITS_ALLOWFB = BIT(4); - const int ITS_ALLOWSI = BIT(5); - const int ITS_GLOW = BIT(6); -const int ISF_COLORMAP = BIT(4); -const int ISF_DROP = BIT(5); -const int ISF_ANGLES = BIT(6); -const int ISF_SIZE = BIT(7); - -.int ItemStatus; - -.float onground_time; -.float fade_start; -.float fade_end; - -#ifdef SVQC void StartItem(entity this, entity a); .int item_group; .int item_group_count; -#endif - -#ifdef CSQC - -bool autocvar_cl_items_nofade; -float autocvar_cl_animate_items = 1; -float autocvar_cl_ghost_items = 0.45; -vector autocvar_cl_ghost_items_color = '-1 -1 -1'; -vector autocvar_cl_weapon_stay_color = '2 0.5 0.5'; -float autocvar_cl_weapon_stay_alpha = 0.75; -float autocvar_cl_simple_items = 0; -string autocvar_cl_simpleitems_postfix = "_simple"; -.float spawntime; -.float gravity; -.vector colormod; - -void ItemDraw(entity this); - -#endif -#ifdef SVQC float autocvar_sv_simple_items; bool ItemSend(entity this, entity to, int sf); @@ -135,4 +90,3 @@ spawnfunc(target_items); #define POSTGIVE_VALUE_ROT(e,f,t,rotfield,rottime,regenfield,regentime,snd_incr,snd_decr) GiveRot((e), save_##f, (e).f, rotfield, rottime, regenfield, regentime); GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr) float GiveItems(entity e, float beginarg, float endarg); -#endif diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index bb99abb4b9..73b7329788 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -6,8 +6,8 @@ #include "g_hook.qh" #include #include "ipban.qh" +#include #include -#include "../common/items.qh" #include "mapvoting.qh" #include "resources.qh" #include diff --git a/qcsrc/server/miscfunctions.qh b/qcsrc/server/miscfunctions.qh index bafd368f67..7b440bb0da 100644 --- a/qcsrc/server/miscfunctions.qh +++ b/qcsrc/server/miscfunctions.qh @@ -3,7 +3,7 @@ #include #include -#include +#include #include diff --git a/qcsrc/server/weapons/common.qc b/qcsrc/server/weapons/common.qc index 3592e3f7e1..c910983b94 100644 --- a/qcsrc/server/weapons/common.qc +++ b/qcsrc/server/weapons/common.qc @@ -1,8 +1,8 @@ #include "common.qh" #include +#include #include -#include #include #include #include diff --git a/qcsrc/server/weapons/csqcprojectile.qc b/qcsrc/server/weapons/csqcprojectile.qc index f6fc2e6221..504bbd4510 100644 --- a/qcsrc/server/weapons/csqcprojectile.qc +++ b/qcsrc/server/weapons/csqcprojectile.qc @@ -1,8 +1,8 @@ #include "csqcprojectile.qh" #include +#include #include -#include #include "../command/common.qh" diff --git a/qcsrc/server/weapons/selection.qc b/qcsrc/server/weapons/selection.qc index 94034bdbb8..3f362016d3 100644 --- a/qcsrc/server/weapons/selection.qc +++ b/qcsrc/server/weapons/selection.qc @@ -1,7 +1,7 @@ #include "selection.qh" #include "weaponsystem.qh" -#include +#include #include #include #include diff --git a/qcsrc/server/weapons/spawning.qc b/qcsrc/server/weapons/spawning.qc index 684ea842b9..63bc865e29 100644 --- a/qcsrc/server/weapons/spawning.qc +++ b/qcsrc/server/weapons/spawning.qc @@ -3,7 +3,7 @@ #include "weaponsystem.qh" #include "../resources.qh" #include -#include +#include #include #include diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index d111a7a4fa..395bfb9b1c 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -4,7 +4,7 @@ #include "../resources.qh" #include #include -#include +#include #include "../g_damage.qh" #include #include diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index dc2ed5dfed..73727759bf 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -3,11 +3,11 @@ #include "selection.qh" #include "../command/common.qh" +#include #include #include "../round_handler.qh" #include #include -#include #include #include #include -- 2.39.2