From 7e4843ca970f0829dd34541957e503e18862565b Mon Sep 17 00:00:00 2001
From: Mario <mario.mario@y7mail.com>
Date: Tue, 1 Oct 2013 09:42:40 -0700
Subject: [PATCH] Network model scale, mins & maxs, link sandbox & breakable
 models with CSQC

---
 qcsrc/client/hud.qc                | 12 ++++++------
 qcsrc/client/miscfunctions.qc      | 18 +++++++++---------
 qcsrc/common/csqcmodel_settings.qh |  3 ++-
 qcsrc/csqcmodellib/cl_model.qc     |  5 ++++-
 qcsrc/csqcmodellib/common.qh       |  7 +++++++
 qcsrc/server/func_breakable.qc     | 10 ++++++++++
 qcsrc/server/mutators/sandbox.qc   |  9 ++++++++-
 7 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc
index 398078acec..7dfaa94859 100644
--- a/qcsrc/client/hud.qc
+++ b/qcsrc/client/hud.qc
@@ -142,16 +142,16 @@ float stringwidth_nocolors(string s, vector theSize)
 	return stringwidth(s, FALSE, theSize);
 }
 
-void drawstringright(vector position, string text, vector scale, vector rgb, float theAlpha, float flag)
+void drawstringright(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag)
 {
-	position_x -= 2 / 3 * strlen(text) * scale_x;
-	drawstring(position, text, scale, rgb, theAlpha, flag);
+	position_x -= 2 / 3 * strlen(text) * theScale_x;
+	drawstring(position, text, theScale, rgb, theAlpha, flag);
 }
 
-void drawstringcenter(vector position, string text, vector scale, vector rgb, float theAlpha, float flag)
+void drawstringcenter(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag)
 {
-	position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * scale_x);
-	drawstring(position, text, scale, rgb, theAlpha, flag);
+	position_x = 0.5 * (vid_conwidth - 0.6025 * strlen(text) * theScale_x);
+	drawstring(position, text, theScale, rgb, theAlpha, flag);
 }
 
 // return the string of the onscreen race timer
diff --git a/qcsrc/client/miscfunctions.qc b/qcsrc/client/miscfunctions.qc
index 926e11399d..cdd55f8a4c 100644
--- a/qcsrc/client/miscfunctions.qc
+++ b/qcsrc/client/miscfunctions.qc
@@ -302,18 +302,18 @@ var string _drawpic_picpath;
 		_drawpic_picpath = string_null;\
 	} while(0)
 
-void drawpic_aspect_skin_expanding(vector position, string pic, vector scale, vector rgb, float theAlpha, float flag, float fadelerp)
+void drawpic_aspect_skin_expanding(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
 {
 	float sz;
 	sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
 
-	drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, scale, 1), pic, scale * sz, rgb, theAlpha * (1 - fadelerp), flag);
+	drawpic_aspect_skin(position + expandingbox_resize_centered_box_offset(sz, theScale, 1), pic, theScale * sz, rgb, theAlpha * (1 - fadelerp), flag);
 }
 
-void drawpic_aspect_skin_expanding_two(vector position, string pic, vector scale, vector rgb, float theAlpha, float flag, float fadelerp)
+void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
 {
-	drawpic_aspect_skin_expanding(position, pic, scale, rgb, theAlpha, flag, fadelerp);
-	drawpic_skin(position, pic, scale, rgb, theAlpha * fadelerp, flag);
+	drawpic_aspect_skin_expanding(position, pic, theScale, rgb, theAlpha, flag, fadelerp);
+	drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
 }
 #define SET_POS_AND_SZ_Y_ASPECT(allow_colors)\
 	float textaspect, oldsz;\
@@ -341,14 +341,14 @@ void drawcolorcodedstring_aspect(vector pos, string text, vector sz, float theAl
 }
 
 vector drawfontscale;
-void drawstring_expanding(vector position, string text, vector scale, vector rgb, float theAlpha, float flag, float fadelerp)
+void drawstring_expanding(vector position, string text, vector theScale, vector rgb, float theAlpha, float flag, float fadelerp)
 {
 	float sz;
 	sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
 
 	drawfontscale = sz * '1 1 0';
 	dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
-	drawstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, FALSE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), rgb, theAlpha * (1 - fadelerp), flag);
+	drawstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth(text, FALSE, theScale * (sz / drawfontscale_x)) / (theScale_x * sz)), text, theScale * (sz / drawfontscale_x), rgb, theAlpha * (1 - fadelerp), flag);
 	// width parameter:
 	//    (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
 	//    SIZE1
@@ -361,14 +361,14 @@ void drawstring_aspect_expanding(vector pos, string text, vector sz, vector colo
 	drawstring_expanding(pos, text, '1 1 0' * sz_y, color, theAlpha, drawflag, fadelerp);
 }
 
-void drawcolorcodedstring_expanding(vector position, string text, vector scale, float theAlpha, float flag, float fadelerp)
+void drawcolorcodedstring_expanding(vector position, string text, vector theScale, float theAlpha, float flag, float fadelerp)
 {
 	float sz;
 	sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
 
 	drawfontscale = sz * '1 1 0';
 	dummyfunction(0, 0, 0, 0, 0, 0, 0, 0);
-	drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, scale, stringwidth(text, TRUE, scale * (sz / drawfontscale_x)) / (scale_x * sz)), text, scale * (sz / drawfontscale_x), theAlpha * (1 - fadelerp), flag);
+	drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth(text, TRUE, theScale * (sz / drawfontscale_x)) / (theScale_x * sz)), text, theScale * (sz / drawfontscale_x), theAlpha * (1 - fadelerp), flag);
 	drawfontscale = '1 1 0';
 }
 
diff --git a/qcsrc/common/csqcmodel_settings.qh b/qcsrc/common/csqcmodel_settings.qh
index a9ed986dee..8b7524a1f7 100644
--- a/qcsrc/common/csqcmodel_settings.qh
+++ b/qcsrc/common/csqcmodel_settings.qh
@@ -45,7 +45,8 @@
 		CSQCMODEL_PROPERTY(512, float, ReadChar, WriteChar, anim_upper_action) \
 		CSQCMODEL_PROPERTY(512, float, ReadApproxPastTime, WriteApproxPastTime, anim_upper_time) \
 		CSQCMODEL_PROPERTY(1024, float, ReadAngle, WriteAngle, v_angle_x) \
-	CSQCMODEL_ENDIF
+	CSQCMODEL_ENDIF \
+	CSQCMODEL_PROPERTY_SCALED(4096, float, ReadShort, WriteShort, scale, 256, 0, 16384)
 // TODO get rid of colormod/glowmod here, find good solution for nex charge glowmod hack; also get rid of some useless properties on non-players that only exist for CopyBody
 
 // add hook function calls here
diff --git a/qcsrc/csqcmodellib/cl_model.qc b/qcsrc/csqcmodellib/cl_model.qc
index 2c7bc2d925..3333096423 100644
--- a/qcsrc/csqcmodellib/cl_model.qc
+++ b/qcsrc/csqcmodellib/cl_model.qc
@@ -236,8 +236,11 @@ void CSQCModel_Read(float isnew)
 #undef CSQCMODEL_IF
 
 	if(sf & CSQCMODEL_PROPERTY_MODELINDEX)
+	{
+		vector oldmins = self.mins, oldmaxs = self.maxs;
 		setmodelindex(self, self.modelindex); // this retrieves the .model key and sets mins/maxs/absmin/absmax
-		// FIXME do we WANT this to override mins/maxs?
+		setsize(self, oldmins, oldmaxs);
+	}
 
 	if(sf & CSQCMODEL_PROPERTY_TELEPORTED)
 	{
diff --git a/qcsrc/csqcmodellib/common.qh b/qcsrc/csqcmodellib/common.qh
index f6044cb283..f0a3d5243e 100644
--- a/qcsrc/csqcmodellib/common.qh
+++ b/qcsrc/csqcmodellib/common.qh
@@ -58,6 +58,7 @@ IN THE SOFTWARE.\
 #define CSQCMODEL_PROPERTY_PITCHROLL 1024
 #define CSQCMODEL_PROPERTY_FRAME2 512
 #define CSQCMODEL_PROPERTY_LERPFRAC 256
+#define CSQCMODEL_PROPERTY_SIZE 128
 
 #define ALLPROPERTIES_COMMON \
 	CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_FRAME, float, ReadByte, WriteByte, frame) \
@@ -65,6 +66,12 @@ IN THE SOFTWARE.\
 	CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_ORIGIN, float, ReadCoord, WriteCoord, origin_x) \
 	CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_ORIGIN, float, ReadCoord, WriteCoord, origin_y) \
 	CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_ORIGIN, float, ReadCoord, WriteCoord, origin_z) \
+	CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_SIZE, float, ReadCoord, WriteCoord, mins_x) \
+	CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_SIZE, float, ReadCoord, WriteCoord, mins_y) \
+	CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_SIZE, float, ReadCoord, WriteCoord, mins_z) \
+	CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_SIZE, float, ReadCoord, WriteCoord, maxs_x) \
+	CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_SIZE, float, ReadCoord, WriteCoord, maxs_y) \
+	CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_SIZE, float, ReadCoord, WriteCoord, maxs_z) \
 	CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_PITCHROLL, float, ReadAngle, WriteAngle, angles_x) \
 	CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_YAW, float, ReadAngle, WriteAngle, angles_y) \
 	CSQCMODEL_PROPERTY(CSQCMODEL_PROPERTY_PITCHROLL, float, ReadAngle, WriteAngle, angles_z) \
diff --git a/qcsrc/server/func_breakable.qc b/qcsrc/server/func_breakable.qc
index 8dca538f1a..29f42189a3 100644
--- a/qcsrc/server/func_breakable.qc
+++ b/qcsrc/server/func_breakable.qc
@@ -209,9 +209,17 @@ void func_breakable_damage(entity inflictor, entity attacker, float damage, floa
 	}
 }
 
+void func_breakable_think()
+{
+	self.nextthink = time;
+	CSQCMODEL_AUTOUPDATE();
+}
+
 void func_breakable_reset()
 {
 	self.team = self.team_saved;
+	self.think = func_breakable_think;
+	self.nextthink = time;
 	func_breakable_look_restore();
 	if(self.spawnflags & 1)
 		func_breakable_behave_destroyed();
@@ -268,6 +276,8 @@ void spawnfunc_func_breakable() {
 
 	self.reset = func_breakable_reset;
 	func_breakable_reset();
+	
+	CSQCMODEL_AUTOINIT();
 }
 
 // for use in maps with a "model" key set
diff --git a/qcsrc/server/mutators/sandbox.qc b/qcsrc/server/mutators/sandbox.qc
index 94ba20f10d..daaad42ec2 100644
--- a/qcsrc/server/mutators/sandbox.qc
+++ b/qcsrc/server/mutators/sandbox.qc
@@ -56,6 +56,8 @@ void sandbox_ObjectFunction_Think()
 	}
 
 	self.nextthink = time;
+	
+	CSQCMODEL_AUTOUPDATE();
 }
 
 .float old_solid, old_movetype;
@@ -137,7 +139,7 @@ entity sandbox_ObjectSpawn(float database)
 {
 	// spawn a new object with default properties
 
-	entity e;
+	entity e, oldself;
 	e = spawn();
 	e.classname = "object";
 	e.takedamage = DAMAGE_AIM;
@@ -172,6 +174,11 @@ entity sandbox_ObjectSpawn(float database)
 		setorigin(e, trace_endpos);
 		e.angles_y = self.v_angle_y;
 	}
+	
+	oldself = self;
+	self = e;
+	CSQCMODEL_AUTOINIT();
+	self = oldself;
 
 	object_count += 1;
 	return e;
-- 
2.39.5