]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mapobjects/models.qc
Some more cleanup to map objects, allow trigger_delay and trigger_counter to be deact...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mapobjects / models.qc
index 9b1f2f8a49309593a815954fb9800be70302e7be..bcaca193f476981a9c76041126dc5891e1592e40 100644 (file)
@@ -3,22 +3,13 @@
 #ifdef SVQC
 #include <server/defs.qh>
 #include <server/miscfunctions.qh>
-#include <server/g_subs.qh>
 #include <common/net_linked.qh>
 #include "subs.qh"
 #include "triggers.qh"
-
-entityclass(BGMScript);
-classfield(BGMScript) .string bgmscript;
-classfield(BGMScript) .float bgmscriptattack;
-classfield(BGMScript) .float bgmscriptdecay;
-classfield(BGMScript) .float bgmscriptsustain;
-classfield(BGMScript) .float bgmscriptrelease;
+#include "bgmscript.qh"
 
 #include <common/constants.qh>
-#include "../../lib/csqcmodel/sv_model.qh"
-
-.float modelscale;
+#include <lib/csqcmodel/sv_model.qh>
 
 void g_model_setcolormaptoactivator(entity this, entity actor, entity trigger)
 {
@@ -42,6 +33,11 @@ void g_clientmodel_setcolormaptoactivator(entity this, entity actor, entity trig
 
 void g_clientmodel_use(entity this, entity actor, entity trigger)
 {
+       // Flag to set func_clientwall state
+       // 1 == deactivate, 2 == activate, 0 == do nothing
+       if(this.classname == "func_clientwall" || this.classname == "func_clientillusionary")
+               this.antiwall_flag = trigger.antiwall_flag;
+
        if (this.antiwall_flag == 1)
        {
                this.inactive = 1;
@@ -149,10 +145,10 @@ bool g_clientmodel_genericsendentity(entity this, entity to, int sf)
                        WriteVector(MSG_ENTITY, this.movedir);
                        WriteByte(MSG_ENTITY, floor(this.lip * 255));
                }
-               WriteByte(MSG_ENTITY, this.fade_start);
-               WriteByte(MSG_ENTITY, this.fade_end);
-               WriteByte(MSG_ENTITY, this.alpha_max);
-               WriteByte(MSG_ENTITY, this.alpha_min);
+               WriteShort(MSG_ENTITY, bound(0, this.fade_start, 65535));
+               WriteShort(MSG_ENTITY, bound(0, this.fade_end, 65535));
+               WriteByte(MSG_ENTITY, floor(this.alpha_max * 256));
+               WriteByte(MSG_ENTITY, floor(this.alpha_min * 256));
                WriteByte(MSG_ENTITY, this.inactive);
                WriteShort(MSG_ENTITY, this.fade_vertical_offset);
        }
@@ -162,21 +158,24 @@ bool g_clientmodel_genericsendentity(entity this, entity to, int sf)
 
 
 #define G_MODEL_INIT(ent,sol) \
-       if(ent.geomtype) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
+       if(ent.geomtype && autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
        if(!ent.scale) ent.scale = ent.modelscale; \
-       SetBrushEntityModel(ent); \
+       SetBrushEntityModel(ent,true); \
        ent.use = g_model_setcolormaptoactivator; \
        InitializeEntity(ent, g_model_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
-       if(!ent.solid) ent.solid = (sol); else if(ent.solid < 0) ent.solid = SOLID_NOT;
+       if(!ent.solid) ent.solid = (sol); \
+       else if(ent.solid < 0) ent.solid = SOLID_NOT;
 
 #define G_CLIENTMODEL_INIT(ent,sol) \
-       if(ent.geomtype) if(autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
+       if(ent.geomtype && autocvar_physics_ode && checkextension("DP_PHYSICS_ODE")) set_movetype(ent, MOVETYPE_PHYSICS); \
        if(!ent.scale) ent.scale = ent.modelscale; \
-       SetBrushEntityModel(ent); \
+       SetBrushEntityModel(ent,true); \
        ent.use = g_clientmodel_use; \
        InitializeEntity(ent, g_clientmodel_dropbyspawnflags, INITPRIO_DROPTOFLOOR); \
-       if(!ent.solid) ent.solid = (sol); else if(ent.solid < 0) ent.solid = SOLID_NOT; \
-       if(!ent.bgmscriptsustain) ent.bgmscriptsustain = 1; else if(ent.bgmscriptsustain < 0) ent.bgmscriptsustain = 0; \
+       if(!ent.solid) ent.solid = (sol); \
+       else if(ent.solid < 0) ent.solid = SOLID_NOT; \
+       if(!ent.bgmscriptsustain) ent.bgmscriptsustain = 1; \
+       else if(ent.bgmscriptsustain < 0) ent.bgmscriptsustain = 0; \
        Net_LinkEntity(ent, true, 0, g_clientmodel_genericsendentity); \
        ent.default_solid = sol;
 
@@ -188,9 +187,227 @@ spawnfunc(misc_models)            { this.angles_x = -this.angles.x; G_MODEL_INIT
 // non-solid brush entities:
 spawnfunc(func_illusionary)       { G_MODEL_INIT      (this, SOLID_NOT) } // Q1 name (WARNING: MISPREDICTED)
 spawnfunc(func_clientillusionary) { G_CLIENTMODEL_INIT(this, SOLID_NOT) } // brush entity
-spawnfunc(func_static)            { G_MODEL_INIT      (this, SOLID_NOT) } // DEPRECATED old alias name from some other game
 
 // solid brush entities
 spawnfunc(func_wall)              { G_MODEL_INIT      (this, SOLID_BSP) } // Q1 name
 spawnfunc(func_clientwall)        { G_CLIENTMODEL_INIT(this, SOLID_BSP) } // brush entity (WARNING: MISPREDICTED)
+spawnfunc(func_static)            { G_MODEL_INIT      (this, SOLID_BSP) } // DEPRECATED old alias name from some other game
+#elif defined(CSQC)
+.float alpha;
+.float scale;
+.vector movedir;
+
+void Ent_Wall_PreDraw(entity this)
+{
+       float alph = this.alpha;
+       if (this.inactive)
+       {
+               alph = 0;
+       }
+       else
+       {
+               vector org = getpropertyvec(VF_ORIGIN);
+               if(!checkpvs(org, this))
+                       alph = 0;
+               else if(this.fade_start || this.fade_end) {
+                       vector offset = '0 0 0';
+                       offset_z = this.fade_vertical_offset;
+                       vector player_dist_math = org - this.origin - 0.5 * (this.mins + this.maxs) + offset;
+                       if (this.fade_end == this.fade_start)
+                       {
+                               if (vdist(player_dist_math, >=, this.fade_start))
+                                       alph = 0;
+                               else
+                                       alph = 1;
+                       }
+                       else
+                       {
+                               float player_dist = vlen(player_dist_math);
+                               alph = (this.alpha_min + this.alpha_max * bound(0,
+                                                          (this.fade_end - player_dist)
+                                                          / (this.fade_end - this.fade_start), 1)) / 100.0;
+                       }
+               }
+               else
+               {
+                       alph = 1;
+               }
+       }
+       this.alpha = alph;
+       this.drawmask = (alph <= 0) ? 0 : MASK_NORMAL;
+}
+
+void Ent_Wall_Draw(entity this)
+{
+       float f;
+       var .vector fld;
+
+       if(this.bgmscriptangular)
+               fld = angles;
+       else
+               fld = origin;
+       this.(fld) = this.saved;
+
+       if(this.lodmodelindex1)
+       {
+               if(autocvar_cl_modeldetailreduction <= 0)
+               {
+                       if(this.lodmodelindex2 && autocvar_cl_modeldetailreduction <= -2)
+                               this.modelindex = this.lodmodelindex2;
+                       else if(autocvar_cl_modeldetailreduction <= -1)
+                               this.modelindex = this.lodmodelindex1;
+                       else
+                               this.modelindex = this.lodmodelindex0;
+               }
+               else
+               {
+                       float distance = vlen(NearestPointOnBox(this, view_origin) - view_origin);
+                       f = (distance * current_viewzoom + 100.0) * autocvar_cl_modeldetailreduction;
+                       f *= 1.0 / bound(0.01, view_quality, 1);
+                       if(this.lodmodelindex2 && f > this.loddistance2)
+                               this.modelindex = this.lodmodelindex2;
+                       else if(f > this.loddistance1)
+                               this.modelindex = this.lodmodelindex1;
+                       else
+                               this.modelindex = this.lodmodelindex0;
+               }
+       }
+
+       InterpolateOrigin_Do(this);
+
+       this.saved = this.(fld);
+
+       f = doBGMScript(this);
+       if(f >= 0)
+       {
+               if(this.lip < 0) // < 0: alpha goes from 1 to 1-|lip| when toggled (toggling subtracts lip)
+                       this.alpha = 1 + this.lip * f;
+               else // > 0: alpha goes from 1-|lip| to 1 when toggled (toggling adds lip)
+                       this.alpha = 1 - this.lip * (1 - f);
+               this.(fld) = this.(fld) + this.movedir * f;
+       }
+       else
+               this.alpha = 1;
+
+       if(this.alpha >= ALPHA_MIN_VISIBLE)
+               this.drawmask = MASK_NORMAL;
+       else
+               this.drawmask = 0;
+}
+
+void Ent_Wall_Remove(entity this)
+{
+       strfree(this.bgmscript);
+}
+
+NET_HANDLE(ENT_CLIENT_WALL, bool isnew)
+{
+       int f;
+       var .vector fld;
+
+       InterpolateOrigin_Undo(this);
+       this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
+
+       if(this.bgmscriptangular)
+               fld = angles;
+       else
+               fld = origin;
+       this.(fld) = this.saved;
+
+       f = ReadByte();
+
+       if(f & 1)
+       {
+               if(f & 0x40)
+                       this.colormap = ReadShort();
+               else
+                       this.colormap = 0;
+               this.skin = ReadByte();
+       }
+
+       if(f & 2)
+       {
+               this.origin = ReadVector();
+               setorigin(this, this.origin);
+       }
+
+       if(f & 4)
+       {
+               if(f & 0x10)
+               {
+                       this.angles_x = ReadAngle();
+                       this.angles_y = ReadAngle();
+                       this.angles_z = ReadAngle();
+               }
+               else
+                       this.angles = '0 0 0';
+       }
+
+       if(f & 8)
+       {
+               if(f & 0x80)
+               {
+                       this.lodmodelindex0 = ReadShort();
+                       this.loddistance1 = ReadShort();
+                       this.lodmodelindex1 = ReadShort();
+                       this.loddistance2 = ReadShort();
+                       this.lodmodelindex2 = ReadShort();
+               }
+               else
+               {
+                       this.modelindex = ReadShort();
+                       this.loddistance1 = 0;
+                       this.loddistance2 = 0;
+               }
+               this.solid = ReadByte();
+               this.scale = ReadShort() / 256.0;
+               if(f & 0x20)
+               {
+                       this.mins = ReadVector();
+                       this.maxs = ReadVector();
+               }
+               else
+                       this.mins = this.maxs = '0 0 0';
+               setsize(this, this.mins, this.maxs);
+
+               string s = ReadString();
+               if(substring(s, 0, 1) == "<")
+               {
+                       strcpy(this.bgmscript, substring(s, 1, -1));
+                       this.bgmscriptangular = 1;
+               }
+               else
+               {
+                       strcpy(this.bgmscript, s);
+                       this.bgmscriptangular = 0;
+               }
+               if(this.bgmscript != "")
+               {
+                       this.bgmscriptattack = ReadByte() / 64.0;
+                       this.bgmscriptdecay = ReadByte() / 64.0;
+                       this.bgmscriptsustain = ReadByte() / 255.0;
+                       this.bgmscriptrelease = ReadByte() / 64.0;
+                       this.movedir = ReadVector();
+                       this.lip = ReadByte() / 255.0;
+               }
+               this.fade_start = ReadShort();
+               this.fade_end = ReadShort();
+               this.alpha_max = ReadByte() / 255.0;
+               this.alpha_min = ReadByte() / 255.0;
+               this.inactive = ReadByte();
+               this.fade_vertical_offset = ReadShort();
+               BGMScript_InitEntity(this);
+       }
+
+       return = true;
+
+       InterpolateOrigin_Note(this);
+
+       this.saved = this.(fld);
+
+       this.entremove = Ent_Wall_Remove;
+       this.draw = Ent_Wall_Draw;
+       if (isnew) IL_PUSH(g_drawables, this);
+       setpredraw(this, Ent_Wall_PreDraw);
+}
 #endif