From 2ef0fc93424f03e1eb675d135f34979115b80873 Mon Sep 17 00:00:00 2001 From: KimLS Date: Mon, 18 May 2015 21:45:51 -0700 Subject: [PATCH] Change to fishing water location algorithim --- changelog.txt | 3 ++ common/ruletypes.h | 3 +- .../optional/2015_05_18_FishingLineLength.sql | 1 + zone/forage.cpp | 41 +++++++++++-------- 4 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 utils/sql/git/optional/2015_05_18_FishingLineLength.sql diff --git a/changelog.txt b/changelog.txt index 17126ff43..4ad457d78 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,8 @@ EQEMu Changelog (Started on Sept 24, 2003 15:50) ------------------------------------------------------- +== 05/18/2015 == +KLS: Changed how fishing locates water to hopefully be a bit more accurate at the expense of a bit more cpu power per line cast. + == 05/15/2015 == Uleat: Added check to EntityList::CheckSpawnQueue() to bypass dereference if returned iterator is npc_list.end() - should fix the debug assertion failure crash diff --git a/common/ruletypes.h b/common/ruletypes.h index 5c4154cf9..a581e527d 100644 --- a/common/ruletypes.h +++ b/common/ruletypes.h @@ -272,7 +272,8 @@ RULE_BOOL ( Watermap, CheckForWaterWhenMoving, false) // Checks if a mob has mo RULE_BOOL ( Watermap, CheckForWaterOnSendTo, false) // Checks if a mob has moved into/out of water on SendTo RULE_BOOL ( Watermap, CheckForWaterWhenFishing, false) // Only lets a player fish near water (if a water map exists for the zone) RULE_REAL ( Watermap, FishingRodLength, 30) // How far in front of player water must be for fishing to work -RULE_REAL ( Watermap, FishingLineLength, 40) // If water is more than this far below the player, it is considered too far to fish +RULE_REAL ( Watermap, FishingLineLength, 100) // If water is more than this far below the player, it is considered too far to fish +RULE_REAL ( Watermap, FishingLineStepSize, 1) // Basic step size for fishing calc, too small and it will eat cpu, too large and it will miss potential water RULE_CATEGORY_END() RULE_CATEGORY( Spells ) diff --git a/utils/sql/git/optional/2015_05_18_FishingLineLength.sql b/utils/sql/git/optional/2015_05_18_FishingLineLength.sql new file mode 100644 index 000000000..f57c4d02e --- /dev/null +++ b/utils/sql/git/optional/2015_05_18_FishingLineLength.sql @@ -0,0 +1 @@ +UPDATE rule_values SET rule_value=100 WHERE rule_name='Watermap:FishingLineLength'; diff --git a/zone/forage.cpp b/zone/forage.cpp index 96b0efcdc..89d4e254f 100644 --- a/zone/forage.cpp +++ b/zone/forage.cpp @@ -185,26 +185,35 @@ bool Client::CanFish() { rodPosition.x = m_Position.x + RodLength * sin(HeadingDegrees * M_PI/180.0f); rodPosition.y = m_Position.y + RodLength * cos(HeadingDegrees * M_PI/180.0f); + rodPosition.z = m_Position.z; - // Do BestZ to find where the line hanging from the rod intersects the water (if it is water). - // and go 1 unit into the water. - glm::vec3 dest; - dest.x = rodPosition.x; - dest.y = rodPosition.y; - dest.z = m_Position.z+10; - - rodPosition.z = zone->zonemap->FindBestZ(dest, nullptr) + 4; - bool in_lava = zone->watermap->InLava(rodPosition); - bool in_water = zone->watermap->InWater(rodPosition) || zone->watermap->InVWater(rodPosition); - //Message(0, "Rod is at %4.3f, %4.3f, %4.3f, InWater says %d, InLava says %d", RodX, RodY, RodZ, in_water, in_lava); - if (in_lava) { - Message_StringID(MT_Skills, FISHING_LAVA); //Trying to catch a fire elemental or something? + float bestz = zone->zonemap->FindBestZ(rodPosition, nullptr); + float len = m_Position.z - bestz; + if(len > LineLength || len < 0.0f) { + Message_StringID(MT_Skills, FISHING_LAND); return false; } - if((!in_water) || (m_Position.z-rodPosition.z)>LineLength) { //Didn't hit the water OR the water is too far below us - Message_StringID(MT_Skills, FISHING_LAND); //Trying to catch land sharks perhaps? - return false; + + float step_size = RuleR(Watermap, FishingLineStepSize); + + for(float i = 0.0f; i < len; i += step_size) { + glm::vec3 dest(rodPosition.x, rodPosition.y, m_Position.z - i); + + bool in_lava = zone->watermap->InLava(dest); + bool in_water = zone->watermap->InWater(dest) || zone->watermap->InVWater(dest); + + if (in_lava) { + Message_StringID(MT_Skills, FISHING_LAVA); //Trying to catch a fire elemental or something? + return false; + } + + if(in_water) { + return true; + } } + + Message_StringID(MT_Skills, FISHING_LAND); + return false; } return true; }