From bdfe99b7f650d9c4681935c61b8a3449134336bf Mon Sep 17 00:00:00 2001 From: Martin Ambrus Date: Mon, 13 Nov 2017 19:03:59 +0100 Subject: [PATCH] fix: alleviating the bad math, which is impossible to quick-fix for me --- GameEngine/Automation.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index ab151f73..087c3f79 100755 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -1110,8 +1110,20 @@ class Automation { // building/field was damaged, let's calculate the actual damage { //TODO: MUST TO BE FIX This part goes also below 0 if u have a lot of catapults + // TODO: this whole math seems incorrect, it needs a revision, and potentially a rewrite $totallvl = round( sqrt( pow( ( $tblevel + 0.5 ), 2 ) - ( ( !$twoRowsCatapultSetup ? (int) $battlepart[4] : (int) $battlepart[4] / 2 ) * 8 ) ) ); + // sometimes this goes above the actual level, so in that case we just reverse everything + // and take the buiding down so many levels + if ($totallvl > $tblevel) { + $totallvl = $tblevel - ($totallvl - $tblevel); + } + + // don't allow this to go below 0 + if ($totallvl <= 0) { + $totallvl = 1; + } + // no damage to the building/field if ( $tblevel >= $totallvl ) { $info_cata = " was not damaged.";