From 278bc92681a4a9a619687c37c09af30ad92b2e56 Mon Sep 17 00:00:00 2001
From: Juhu <5894800-Juhu_@users.noreply.gitlab.com>
Date: Wed, 31 May 2023 02:50:58 +0000
Subject: [PATCH] Area grid linking fixes for DP master

---
 .../common/gamemodes/gamemode/onslaught/cl_controlpoint.qc  | 6 +++++-
 qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc   | 1 +
 qcsrc/common/turrets/cl_turrets.qc                          | 4 ++--
 qcsrc/common/turrets/sv_turrets.qc                          | 2 ++
 qcsrc/common/turrets/turret/walker.qc                       | 3 +--
 qcsrc/common/vehicles/sv_vehicles.qc                        | 3 +--
 qcsrc/common/vehicles/vehicle/bumblebee.qc                  | 2 +-
 qcsrc/common/vehicles/vehicle/raptor_weapons.qc             | 6 +++---
 qcsrc/common/vehicles/vehicle/spiderbot.qc                  | 6 +++---
 qcsrc/server/portals.qc                                     | 1 +
 10 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/cl_controlpoint.qc b/qcsrc/common/gamemodes/gamemode/onslaught/cl_controlpoint.qc
index 7694f02fb6..91a734f41f 100644
--- a/qcsrc/common/gamemodes/gamemode/onslaught/cl_controlpoint.qc
+++ b/qcsrc/common/gamemodes/gamemode/onslaught/cl_controlpoint.qc
@@ -122,7 +122,11 @@ void cpicon_construct(entity this, bool isnew)
 		set_movetype(this.icon_realmodel, MOVETYPE_NOCLIP);
 	}
 
-	if(this.iscaptured) { this.icon_realmodel.solid = SOLID_BBOX; }
+	if(this.iscaptured)
+	{
+		this.icon_realmodel.solid = SOLID_BBOX;
+		setorigin(this.icon_realmodel, this.icon_realmodel.origin); // link
+	}
 
 	set_movetype(this, MOVETYPE_NOCLIP);
 	this.move_time		= time;
diff --git a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc
index e48ea34643..ea07659e34 100644
--- a/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc
+++ b/qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc
@@ -555,6 +555,7 @@ void ons_ControlPoint_Icon_BuildThink(entity this)
 		sound(this, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
 		this.owner.iscaptured = true;
 		this.solid = SOLID_BBOX;
+		setorigin(this, this.origin); // setorigin after change to solid field to ensure area grid linking
 
 		Send_Effect(EFFECT_CAP(this.owner.team), this.owner.origin, '0 0 0', 1);
 
diff --git a/qcsrc/common/turrets/cl_turrets.qc b/qcsrc/common/turrets/cl_turrets.qc
index aff0f764c7..219b23318c 100644
--- a/qcsrc/common/turrets/cl_turrets.qc
+++ b/qcsrc/common/turrets/cl_turrets.qc
@@ -221,6 +221,8 @@ void turret_construct(entity this, bool isnew)
 	setorigin(this, this.origin);
 	_setmodel(this, tur.model);
 	_setmodel(this.tur_head, tur.head_model);
+	this.solid = SOLID_BBOX; // before setsize so it will be linked to the area grid
+	this.tur_head.solid = SOLID_NOT;
 	setsize(this, tur.m_mins, tur.m_maxs);
 	setsize(this.tur_head, '0 0 0', '0 0 0');
 
@@ -235,8 +237,6 @@ void turret_construct(entity this, bool isnew)
 	set_movetype(this, MOVETYPE_NOCLIP);
 	this.tur_head.angles			= this.angles;
 	SetResourceExplicit(this, RES_HEALTH, 255);
-	this.solid						= SOLID_BBOX;
-	this.tur_head.solid				= SOLID_NOT;
 	set_movetype(this, MOVETYPE_NOCLIP);
 	set_movetype(this.tur_head, MOVETYPE_NOCLIP);
 	this.draw						= turret_draw;
diff --git a/qcsrc/common/turrets/sv_turrets.qc b/qcsrc/common/turrets/sv_turrets.qc
index 2e6068bf56..1cca9b1ca1 100644
--- a/qcsrc/common/turrets/sv_turrets.qc
+++ b/qcsrc/common/turrets/sv_turrets.qc
@@ -304,6 +304,8 @@ void turret_respawn(entity this)
 
 	Turret tur = get_turretinfo(this.m_id);
 	tur.tr_setup(tur, this);
+
+	setorigin(this, this.origin); // make sure it's linked to the area grid
 }
 
 
diff --git a/qcsrc/common/turrets/turret/walker.qc b/qcsrc/common/turrets/turret/walker.qc
index 139a3a364f..051ea0accd 100644
--- a/qcsrc/common/turrets/turret/walker.qc
+++ b/qcsrc/common/turrets/turret/walker.qc
@@ -209,7 +209,7 @@ void walker_fire_rocket(entity this, vector org)
 
     entity rocket = new(walker_rocket);
     setorigin(rocket, org);
-
+    rocket.solid			  = SOLID_BBOX; // before setsize so it will be linked to the area grid
     sound (this, CH_WEAPON_A, SND_HAGAR_FIRE, VOL_BASE, ATTEN_NORM);
     setsize (rocket, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
 
@@ -238,7 +238,6 @@ void walker_fire_rocket(entity this, vector org)
     rocket.flags = FL_PROJECTILE;
     IL_PUSH(g_projectiles, rocket);
     IL_PUSH(g_bot_dodge, rocket);
-    rocket.solid			  = SOLID_BBOX;
     rocket.max_health		 = time + 9;
     rocket.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_HEAT;
 
diff --git a/qcsrc/common/vehicles/sv_vehicles.qc b/qcsrc/common/vehicles/sv_vehicles.qc
index 302b39a0d1..f18d867c60 100644
--- a/qcsrc/common/vehicles/sv_vehicles.qc
+++ b/qcsrc/common/vehicles/sv_vehicles.qc
@@ -819,8 +819,6 @@ void vehicles_exit(entity vehic, bool eject)
 			WriteAngle(MSG_ONE, 0);
 		}
 
-		setsize(player, STAT(PL_MIN, player), STAT(PL_MAX, player));
-
 		player.takedamage		= DAMAGE_AIM;
 		player.solid			= SOLID_SLIDEBOX;
 		set_movetype(player, MOVETYPE_WALK);
@@ -840,6 +838,7 @@ void vehicles_exit(entity vehic, bool eject)
 		}
 		player.last_vehiclecheck = time + 3;
 		player.vehicle_enter_delay = time + 2;
+		setsize(player, STAT(PL_MIN, player), STAT(PL_MAX, player));
 
 		CSQCVehicleSetup(player, HUD_NORMAL);
 
diff --git a/qcsrc/common/vehicles/vehicle/bumblebee.qc b/qcsrc/common/vehicles/vehicle/bumblebee.qc
index 8b34473e39..a7fcafc385 100644
--- a/qcsrc/common/vehicles/vehicle/bumblebee.qc
+++ b/qcsrc/common/vehicles/vehicle/bumblebee.qc
@@ -238,7 +238,6 @@ void bumblebee_gunner_exit(entity this, int _exitflag)
 	}
 
 	CSQCVehicleSetup(player, HUD_NORMAL);
-	setsize(player, STAT(PL_MIN, player), STAT(PL_MAX, player));
 
 	player.takedamage     = DAMAGE_AIM;
 	player.solid          = SOLID_SLIDEBOX;
@@ -257,6 +256,7 @@ void bumblebee_gunner_exit(entity this, int _exitflag)
 		delete(gunner.(weaponentity));
 	}
 	player.vehicle_enter_delay = time + 2;
+	setsize(player, STAT(PL_MIN, player), STAT(PL_MAX, player));
 
 	fixedmakevectors(vehic.angles);
 
diff --git a/qcsrc/common/vehicles/vehicle/raptor_weapons.qc b/qcsrc/common/vehicles/vehicle/raptor_weapons.qc
index dc219f571c..dc2f293d65 100644
--- a/qcsrc/common/vehicles/vehicle/raptor_weapons.qc
+++ b/qcsrc/common/vehicles/vehicle/raptor_weapons.qc
@@ -66,6 +66,7 @@ METHOD(RaptorFlare, wr_think, void(entity thiswep, entity actor, .entity weapone
             setmodel(_flare, MDL_VEH_RAPTOR_FLARE);
             _flare.effects = EF_LOWPRECISION | EF_FLAME;
             _flare.scale = 0.5;
+            _flare.solid = SOLID_CORPSE; // before setorigin so it will be linked to the area grid
             setorigin(_flare, actor.origin - '0 0 16');
             set_movetype(_flare, MOVETYPE_TOSS);
             _flare.gravity = 0.15;
@@ -73,7 +74,6 @@ METHOD(RaptorFlare, wr_think, void(entity thiswep, entity actor, .entity weapone
             setthink(_flare, raptor_flare_think);
             _flare.nextthink = time;
             _flare.owner = veh ? veh : player;
-            _flare.solid = SOLID_CORPSE;
             _flare.takedamage = DAMAGE_YES;
             _flare.event_damage = raptor_flare_damage;
             SetResourceExplicit(_flare, RES_HEALTH, 20);
@@ -154,6 +154,7 @@ void raptor_bombdrop(entity this)
     entity bomb_2 = new(bombmount_right);
 
     vector org = gettaginfo(this, gettagindex(this, "bombmount_left"));
+    bomb_1.solid	 = bomb_2.solid	  = SOLID_BBOX; // before setorigin to ensure area grid linking
     setorigin(bomb_1, org);
     org = gettaginfo(this, gettagindex(this, "bombmount_right"));
     setorigin(bomb_2, org);
@@ -174,7 +175,6 @@ void raptor_bombdrop(entity this)
 
     bomb_1.owner	 = bomb_2.owner	  = this;
     bomb_1.realowner = bomb_2.realowner  = this.owner;
-    bomb_1.solid	 = bomb_2.solid	  = SOLID_BBOX;
     bomb_1.gravity   = bomb_2.gravity	= 1;
 
     PROJECTILE_MAKETRIGGER(bomb_1);
@@ -234,11 +234,11 @@ void RaptorCBShellfragToss(vector _org, vector _vel, vector _ang)
 {
     entity sfrag = new(RaptorCBShellfrag);
     setmodel(sfrag, MDL_VEH_RAPTOR_CB_FRAGMENT);
+    sfrag.solid = SOLID_CORPSE; // before setorigin to ensure area grid linking
     setorigin(sfrag, _org);
 
     set_movetype(sfrag, MOVETYPE_BOUNCE);
     sfrag.gravity = 0.15;
-    sfrag.solid = SOLID_CORPSE;
 
     sfrag.draw = RaptorCBShellfragDraw;
     IL_PUSH(g_drawables, sfrag);
diff --git a/qcsrc/common/vehicles/vehicle/spiderbot.qc b/qcsrc/common/vehicles/vehicle/spiderbot.qc
index d6a371b765..460f6edf4b 100644
--- a/qcsrc/common/vehicles/vehicle/spiderbot.qc
+++ b/qcsrc/common/vehicles/vehicle/spiderbot.qc
@@ -418,10 +418,10 @@ void spiderbot_blowup(entity this)
 	b.angles = this.angles;
 	setsize(b, this.mins, this.maxs);
 
+	h.solid = SOLID_BBOX; // before setorigin for immediate area grid linking
 	vector org = gettaginfo(this, gettagindex(this, "tag_head"));
 	setorigin(h, org);
 	set_movetype(h, MOVETYPE_BOUNCE);
-	h.solid = SOLID_BBOX;
 	h.velocity = v_up * (500 + random() * 500) + randomvec() * 128;
 	h.modelflags = MF_ROCKET;
 	h.effects = EF_FLAME | EF_LOWPRECISION;
@@ -434,17 +434,17 @@ void spiderbot_blowup(entity this)
 	setthink(h, spiderbot_headfade);
 	h.nextthink = time;
 
+	g1.solid = SOLID_CORPSE; // before setorigin for immediate area grid linking
 	org = gettaginfo(this.tur_head, gettagindex(this.tur_head, "tag_hardpoint01"));
 	setorigin(g1, org);
 	set_movetype(g1, MOVETYPE_TOSS);
-	g1.solid = SOLID_CORPSE;
 	g1.velocity = v_forward * 700 + (randomvec() * 32);
 	g1.avelocity = randomvec() * 180;
 
+	g2.solid = SOLID_CORPSE; // before setorigin for immediate area grid linking
 	org = gettaginfo(this.tur_head, gettagindex(this.tur_head, "tag_hardpoint02"));
 	setorigin(g2, org);
 	set_movetype(g2, MOVETYPE_TOSS);
-	g2.solid = SOLID_CORPSE;
 	g2.velocity = v_forward * 700 + (randomvec() * 32);
 	g2.avelocity = randomvec() * 180;
 
diff --git a/qcsrc/server/portals.qc b/qcsrc/server/portals.qc
index 2cf8db682f..405d179ca8 100644
--- a/qcsrc/server/portals.qc
+++ b/qcsrc/server/portals.qc
@@ -404,6 +404,7 @@ void Portal_Connect(entity teleporter, entity destination)
 #else
 	teleporter.solid = SOLID_BSP;
 #endif
+	setorigin(teleporter, teleporter.origin); // link it to the area grid
 }
 
 void Portal_Remove(entity portal, float killed)
-- 
2.39.5