From 7732979dccd0be2d113894202177195626e08ddf Mon Sep 17 00:00:00 2001 From: Penguinum Date: Thu, 23 Apr 2015 12:38:40 +0300 Subject: [PATCH] Started working on antiwalls --- qcsrc/client/antiwall.qc | 200 ++++++++++++++++++++++++++++++++++++++ qcsrc/client/antiwall.qh | 18 ++++ qcsrc/client/progs.src | 1 + qcsrc/common/constants.qh | 1 + 4 files changed, 220 insertions(+) create mode 100644 qcsrc/client/antiwall.qc create mode 100644 qcsrc/client/antiwall.qh diff --git a/qcsrc/client/antiwall.qc b/qcsrc/client/antiwall.qc new file mode 100644 index 000000000..87300b75c --- /dev/null +++ b/qcsrc/client/antiwall.qc @@ -0,0 +1,200 @@ +#include "antiwall.qh" + +void Ent_Antiwall_PreDraw() +{ + if (self.inactive) { + self.alpha = 0; + } else { + vector org; + org = getpropertyvec(VF_ORIGIN); + if(!checkpvs(org, self)) + self.alpha = 0; + else if(self.fade_start) { + self.alpha = self.alpha_max / 100.0 * bound(0, + (self.fade_end - vlen(org - self.origin - 0.5 * (self.mins + self.maxs))) + / (self.fade_end - self.fade_start), 1); + } else { + self.alpha = 1; + } + } + if(self.alpha <= 0) + self.drawmask = 0; + else + self.drawmask = MASK_NORMAL; +} + +void Ent_Antiwall_Draw() +{ + float f; + var .vector fld; + + if(self.bgmscriptangular) + fld = angles; + else + fld = origin; + self.fld = self.saved; + + if(self.lodmodelindex1) + { + if(autocvar_cl_modeldetailreduction <= 0) + { + if(self.lodmodelindex2 && autocvar_cl_modeldetailreduction <= -2) + self.modelindex = self.lodmodelindex2; + else if(autocvar_cl_modeldetailreduction <= -1) + self.modelindex = self.lodmodelindex1; + else + self.modelindex = self.lodmodelindex0; + } + else + { + float distance = vlen(NearestPointOnBox(self, view_origin) - view_origin); + f = (distance * current_viewzoom + 100.0) * autocvar_cl_modeldetailreduction; + f *= 1.0 / bound(0.01, view_quality, 1); + if(self.lodmodelindex2 && f > self.loddistance2) + self.modelindex = self.lodmodelindex2; + else if(f > self.loddistance1) + self.modelindex = self.lodmodelindex1; + else + self.modelindex = self.lodmodelindex0; + } + } + + InterpolateOrigin_Do(); + + self.saved = self.fld; + + f = BGMScript(self); + if(f >= 0) + { + if(self.lip < 0) // < 0: alpha goes from 1 to 1-|lip| when toggled (toggling subtracts lip) + self.alpha = 1 + self.lip * f; + else // > 0: alpha goes from 1-|lip| to 1 when toggled (toggling adds lip) + self.alpha = 1 - self.lip * (1 - f); + self.fld = self.fld + self.movedir * f; + } + else + self.alpha = 1; + + if(self.alpha >= ALPHA_MIN_VISIBLE) + self.drawmask = MASK_NORMAL; + else + self.drawmask = 0; +} + +void Ent_Antiwall_Remove() +{ + if(self.bgmscript) + strunzone(self.bgmscript); + self.bgmscript = string_null; +} + +void Ent_Antiwall() +{ + int f; + var .vector fld; + + InterpolateOrigin_Undo(); + self.iflags = IFLAG_ANGLES | IFLAG_ORIGIN; + + if(self.bgmscriptangular) + fld = angles; + else + fld = origin; + self.fld = self.saved; + + f = ReadByte(); + + if(f & 1) + { + if(f & 0x40) + self.colormap = ReadShort(); + else + self.colormap = 0; + } + + if(f & 2) + { + self.origin_x = ReadCoord(); + self.origin_y = ReadCoord(); + self.origin_z = ReadCoord(); + setorigin(self, self.origin); + } + + if(f & 4) + { + if(f & 0x10) + { + self.angles_x = ReadAngle(); + self.angles_y = ReadAngle(); + self.angles_z = ReadAngle(); + } + else + self.angles = '0 0 0'; + } + + if(f & 8) + { + if(f & 0x80) + { + self.lodmodelindex0 = ReadShort(); + self.loddistance1 = ReadShort(); + self.lodmodelindex1 = ReadShort(); + self.loddistance2 = ReadShort(); + self.lodmodelindex2 = ReadShort(); + } + else + { + self.modelindex = ReadShort(); + self.loddistance1 = 0; + self.loddistance2 = 0; + } + self.solid = ReadByte(); + self.scale = ReadShort() / 256.0; + if(f & 0x20) + { + self.mins_x = ReadCoord(); + self.mins_y = ReadCoord(); + self.mins_z = ReadCoord(); + self.maxs_x = ReadCoord(); + self.maxs_y = ReadCoord(); + self.maxs_z = ReadCoord(); + } + else + self.mins = self.maxs = '0 0 0'; + setsize(self, self.mins, self.maxs); + + if(self.bgmscript) + strunzone(self.bgmscript); + self.bgmscript = ReadString(); + if(substring(self.bgmscript, 0, 1) == "<") + { + self.bgmscript = strzone(substring(self.bgmscript, 1, -1)); + self.bgmscriptangular = 1; + } + else + { + self.bgmscript = strzone(self.bgmscript); + self.bgmscriptangular = 0; + } + if(self.bgmscript != "") + { + self.bgmscriptattack = ReadByte() / 64.0; + self.bgmscriptdecay = ReadByte() / 64.0; + self.bgmscriptsustain = ReadByte() / 255.0; + self.bgmscriptrelease = ReadByte() / 64.0; + self.movedir_x = ReadCoord(); + self.movedir_y = ReadCoord(); + self.movedir_z = ReadCoord(); + self.lip = ReadByte() / 255.0; + } + BGMScript_InitEntity(self); + } + + InterpolateOrigin_Note(); + + self.saved = self.fld; + + self.entremove = Ent_Antiwall_Remove; + self.draw = Ent_Antiwall_Draw; +} + diff --git a/qcsrc/client/antiwall.qh b/qcsrc/client/antiwall.qh new file mode 100644 index 000000000..9d96c70dd --- /dev/null +++ b/qcsrc/client/antiwall.qh @@ -0,0 +1,18 @@ +#ifndef ANTIWALL_H +#define ANTIWALL_H + +.float lip; +.float bgmscriptangular; +.int lodmodelindex0, lodmodelindex1, lodmodelindex2; +.float loddistance1, loddistance2; +.vector saved; +.float inactive, alpha_max; +.float fade_start, fade_end; + +void Ent_Antiwall_Draw(); + +void Ent_Antiwall_Remove(); + +void Ent_Antiwall(); +#endif + diff --git a/qcsrc/client/progs.src b/qcsrc/client/progs.src index f80da18d6..535f5084c 100644 --- a/qcsrc/client/progs.src +++ b/qcsrc/client/progs.src @@ -35,6 +35,7 @@ vehicles/vehicles.qc view.qc wall.qc waypointsprites.qc +antiwall.qc command/cl_cmd.qc diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 45a65abbe..d83e6262a 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -78,6 +78,7 @@ const int ENT_CLIENT_ELIMINATEDPLAYERS = 39; const int ENT_CLIENT_TURRET = 40; const int ENT_CLIENT_AUXILIARYXHAIR = 50; const int ENT_CLIENT_VEHICLE = 60; +const int ENT_CLIENT_ANTIWALL = 61; const int ENT_CLIENT_HEALING_ORB = 80; -- 2.39.2