Browse Source

Groundspawn adhere to ground (lol)

Fixes #80

forceMapCheck added at Spawn level and applicable to GroundSpawn class, once map is loaded this can force a future map check and send all forced updates to clients to make sure they receive the new Y position.

This was only applied to ground spawns because other spawns may be floating, thus you do not want to force a Y position on them.
Image 4 years ago
parent
commit
5a8ffc3385

+ 1 - 0
EQ2/source/WorldServer/GroundSpawn.h

@@ -48,6 +48,7 @@ public:
 		new_spawn->SetGroundSpawnEntryID(groundspawn_id);
 		new_spawn->SetCollectionSkill(collection_skill.c_str());
 		new_spawn->SetQuestsRequired(GetQuestsRequired());
+		new_spawn->forceMapCheck = forceMapCheck;
 		return new_spawn;
 	}
 	bool IsGroundSpawn(){ return true; }

+ 10 - 3
EQ2/source/WorldServer/Spawn.cpp

@@ -100,6 +100,7 @@ Spawn::Spawn(){
 	last_grid_update = 0;
 	last_location_update = 0.0;
 	last_movement_update = Timer::GetCurrentTime2();
+	forceMapCheck = false;
 }
 
 Spawn::~Spawn(){
@@ -2092,6 +2093,12 @@ void Spawn::ProcessMovement(bool isSpawnListLocked){
 		return;
 	}
 
+	if (forceMapCheck && GetZone() != nullptr && zone->zonemap != nullptr && zone->zonemap->IsMapLoaded())
+	{
+		FixZ(true);
+		forceMapCheck = false;
+	}
+
 	if (GetHP() <= 0 && !IsWidget())
 		return;
 
@@ -2975,8 +2982,8 @@ float Spawn::GetFixedZ(const glm::vec3& destination, int32 z_find_offset) {
 }
 
 
-void Spawn::FixZ(int32 z_find_offset /*= 1*/, bool fix_client_z /*= false*/) {
-	if (IsPlayer() && !fix_client_z || (this->GetInitialState() == 49156)) {
+void Spawn::FixZ(bool forceUpdate) {
+	if (IsPlayer() || (this->GetInitialState() == 49156)) {
 		return;
 	}
 	/*
@@ -2994,7 +3001,7 @@ void Spawn::FixZ(int32 z_find_offset /*= 1*/, bool fix_client_z /*= false*/) {
 		return;
 
 	if ((new_z > -2000) && new_z != BEST_Z_INVALID) {
-		SetY(new_z, false,true);
+		SetY(new_z, forceUpdate, true);
 	}
 	else {
 		LogWrite(MAP__DEBUG, 0, "Map", "[{%s}] is failing to find Z [{%f}]", this->GetName(), std::abs(GetY() - new_z));

+ 3 - 1
EQ2/source/WorldServer/Spawn.h

@@ -918,6 +918,8 @@ public:
 	AppearanceData		appearance;
 	int32	last_movement_update;
 	int32	last_location_update;
+	bool	forceMapCheck;
+
 	bool following;
 	bool	IsPet() { return is_pet; }
 	void	SetPet(bool val) { is_pet = val; }
@@ -965,7 +967,7 @@ public:
 
 	float FindDestGroundZ(glm::vec3 dest, float z_offset);
 	float GetFixedZ(const glm::vec3& destination, int32 z_find_offset = 1);
-	void FixZ(int32 z_find_offset=1, bool fix_client_z=false);
+	void FixZ(bool forceUpdate=false);
 	bool CheckLoS(Spawn* target);
 	bool CheckLoS(glm::vec3 myloc, glm::vec3 oloc);
 

+ 2 - 0
EQ2/source/WorldServer/WorldDatabase.cpp

@@ -1267,6 +1267,8 @@ void WorldDatabase::LoadGroundSpawns(ZoneServer* zone){
 			continue;
 		spawn = new GroundSpawn();
 		spawn->SetDatabaseID(id);
+		spawn->forceMapCheck = true;
+
 		strcpy(spawn->appearance.name, row[1]);
 		vector<EntityCommand*>* primary_command_list = zone->GetEntityCommandList(atoul(row[4]));
 		vector<EntityCommand*>* secondary_command_list = zone->GetEntityCommandList(atoul(row[5]));