From 950fc61f8aa76c9ceb9441aa1b5a6edf2962342e Mon Sep 17 00:00:00 2001 From: iopietro Date: Thu, 10 May 2018 20:50:29 +0200 Subject: [PATCH] General fixes +A method in Building.php is now static +Fixed timers in the market +Fixed a bug that did take in account a wrong tournament square when calculating the returning time of the troops --- GameEngine/Automation.php | 9 +-- GameEngine/Building.php | 103 +++++++++++++-------------------- GameEngine/Generator.php | 7 ++- GameEngine/Units.php | 2 +- Templates/Build/16_walking.tpl | 4 +- Templates/Build/17.tpl | 10 +--- Templates/Building.tpl | 4 +- Templates/dorf2.tpl | 14 ++--- Templates/dorf3/1.tpl | 6 +- Templates/field.tpl | 2 +- 10 files changed, 67 insertions(+), 94 deletions(-) diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index 6882726c..ba9a988f 100755 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -120,13 +120,13 @@ class Automation { } public function procResType($ref, $mode = 0) { - global $building; //Capital or only 1 village left = cannot be destroyed - return addslashes(empty($build = $building->procResType($ref)) && !$mode ? "Village can't be" : $build); + return addslashes(empty($build = Building::procResType($ref)) && !$mode ? "Village can't be" : $build); } function recountPop($vid, $use_cache = true){ global $database; + $vid = (int) $vid; $fdata = $database->getResourceLevel($vid, $use_cache); $popTot = 0; @@ -148,6 +148,7 @@ class Automation { function recountCP($vid){ global $database; + $vid = (int) $vid; $fdata = $database->getResourceLevel($vid); $popTot = 0; @@ -3015,7 +3016,7 @@ class Automation { } private function sendSettlersComplete() { - global $database, $building, $autoprefix; + global $database, $autoprefix; if(file_exists($autoprefix."GameEngine/Prevention/settlers.txt")) { unlink($autoprefix."GameEngine/Prevention/settlers.txt"); @@ -3761,7 +3762,7 @@ class Automation { } private function demolitionComplete() { - global $building, $database, $autoprefix; + global $database, $autoprefix; if(file_exists($autoprefix."GameEngine/Prevention/demolition.txt")) { unlink($autoprefix."GameEngine/Prevention/demolition.txt"); diff --git a/GameEngine/Building.php b/GameEngine/Building.php index b9b2e0a0..dca55e2e 100755 --- a/GameEngine/Building.php +++ b/GameEngine/Building.php @@ -293,7 +293,7 @@ class Building { return false; } - public function procResType($ref) { + public static function procResType($ref) { switch($ref) { case 1: return "Woodcutter"; case 2: return "Clay Pit"; @@ -429,7 +429,7 @@ class Building { if($database->addBuilding($village->wid, $id, $village->resarray['f'.$id.'t'], $loop, $time + ($loop == 1 ? ceil(60 / SPEED) : 0), 0, $level['f'.$id] + 1 + count($database->getBuildingByField($village->wid, $id)))) { $database->modifyResource($village->wid, $uprequire['wood'], $uprequire['clay'], $uprequire['iron'], $uprequire['crop'], 0); - $logging->addBuildLog($village->wid, $this->procResType($village->resarray['f'.$id.'t']), ($village->resarray['f'.$id] + ($loopsame > 0 ? 2 : 1)), 0); + $logging->addBuildLog($village->wid, self::procResType($village->resarray['f'.$id.'t']), ($village->resarray['f'.$id] + ($loopsame > 0 ? 2 : 1)), 0); $this->redirect($id); } } @@ -470,10 +470,10 @@ class Building { } $level = $database->getResourceLevel($village->wid); - if($database->addBuilding($village->wid,$id,$village->resarray['f'.$id.'t'],$loop,$time,0,0,$level['f'.$id] + 1 + count($database->getBuildingByField($village->wid,$id)))) { - $logging->addBuildLog($village->wid,$this->procResType($village->resarray['f'.$id.'t']),($village->resarray['f'.$id]-1),2); + if($database->addBuilding($village->wid, $id, $village->resarray['f'.$id.'t'], $loop, $time, 0, 0, $level['f'.$id] + 1 + count($database->getBuildingByField($village->wid, $id)))){ + $logging->addBuildLog($village->wid, self::procResType($village->resarray['f'.$id.'t']), ($village->resarray['f'.$id] - 1), 2); header("Location: dorf2.php"); - exit; + exit(); } } } @@ -506,7 +506,7 @@ class Building { if($this->meetRequirement($tid)) { $level = $database->getResourceLevel($village->wid); if($database->addBuilding($village->wid, $id, $tid, $loop, $time, 0, $level['f' . $id] + 1 + count($database->getBuildingByField($village->wid, $id)))){ - $logging->addBuildLog($village->wid, $this->procResType($tid), ($village->resarray['f' . $id] + 1), 1); + $logging->addBuildLog($village->wid, self::procResType($tid), ($village->resarray['f' . $id] + 1), 1); $database->modifyResource($village->wid, $uprequire['wood'], $uprequire['clay'], $uprequire['iron'], $uprequire['crop'], 0); header("Location: dorf2.php"); exit; @@ -668,47 +668,34 @@ class Building { } } - public function isMax($id,$field,$loop=0) { + public function isMax($id, $field, $loop = 0) { $name = "bid".$id; global $$name,$village,$session; $dataarray = $$name; // special case for Multihunter login which mathematically (because of the resarray length) // allows for building resource fields above level 20 - if ($session->tribe == 0) { - return $village->resarray['f'.$field] == 20; - } + if ($session->tribe == 0) return $village->resarray['f'.$field] == 20; if($id <= 4) { - if($village->capital == 1) { - return ($village->resarray['f'.$field] == (count($dataarray) - 1 - $loop)); - } - else { - return ($village->resarray['f'.$field] == (count($dataarray) - 11 - $loop)); - } - } - else { - return ($village->resarray['f'.$field] == count($dataarray) - $loop); + if($village->capital == 1) return ($village->resarray['f'.$field] == (count($dataarray) - 1 - $loop)); + else return ($village->resarray['f'.$field] == (count($dataarray) - 11 - $loop)); } + else return ($village->resarray['f'.$field] == count($dataarray) - $loop); } - public function getTypeLevel($tid,$vid=0) { - global $village,$database,$session; + public function getTypeLevel($tid, $vid = 0) { + global $village, $database, $session; // Support would not have a village, so this is irrelevant - if ($session->uid == 1) { - return 0; - } + if ($session->uid == 1) return 0; - $keyholder = array(); + $keyholder = []; - if($vid == 0) { - $resourcearray = $village->resarray; - } else { - $resourcearray = $database->getResourceLevel($vid); - } + if($vid == 0) $resourcearray = $village->resarray; + else $resourcearray = $database->getResourceLevel($vid); - foreach(array_keys($resourcearray,$tid) as $key) { + foreach(array_keys($resourcearray, $tid) as $key) { if(strpos($key,'t')) { $key = preg_replace("/[^0-9]/", '', $key); array_push($keyholder, $key); @@ -718,51 +705,41 @@ class Building { $element = count($keyholder); // if we count more than 1 instance of the building (mostly resource fields) - if($element >= 2) { - // resource field - if($tid <= 4) { - $temparray = array(); - - for($i=0;$i<=$element-1;$i++) { - // collect current field level - array_push($temparray,$resourcearray['f'.$keyholder[$i]]); + if($element >= 2){ + // resource field + if($tid <= 4){ + $temparray = []; + + for($i = 0; $i <= $element - 1; $i++){ + // collect current field level + array_push($temparray, $resourcearray['f'.$keyholder[$i]]); } - + // find out the maximum field level for this village $maValue = max($temparray); - foreach ($temparray as $key => $val) { - if ($val == $maValue) { - $target = $key; + foreach($temparray as $key => $val){ + if($val == $maValue){ + $target = $key; } } - } - // village building - else { + }else{ // village building $target = 0; - + // find the highest level built for this building type - for($i=1;$i<=$element-1;$i++) { - if($resourcearray['f'.$keyholder[$i]] > $resourcearray['f'.$keyholder[$target]]) { + for($i = 1; $i <= $element - 1; $i++){ + if($resourcearray['f'.$keyholder[$i]] > $resourcearray['f'.$keyholder[$target]]){ $target = $i; } } } } + // if we count only a single building - else if($element == 1) { - $target = 0; - } - // no building matching search criteria - else { - return 0; - } - - if($keyholder[$target] != "") { - return $resourcearray['f'.$keyholder[$target]]; - } - else { - return 0; - } + else if($element == 1) $target = 0; + else return 0; // no building matching search criteria + + if(!empty($keyholder[$target])) return $resourcearray['f'.$keyholder[$target]]; + else return 0; } diff --git a/GameEngine/Generator.php b/GameEngine/Generator.php index 5eed11f1..15072870 100755 --- a/GameEngine/Generator.php +++ b/GameEngine/Generator.php @@ -35,8 +35,9 @@ class MyGenerator { return substr($encode,0,$length); } - public function procDistanceTime($coor, $thiscoor, $ref, $mode) { + public function procDistanceTime($coor, $thiscoor, $ref, $mode, $vid = 0) { global $bid28, $bid14, $building; + $xdistance = ABS($thiscoor['x'] - $coor['x']); if($xdistance > WORLD_MAX) { $xdistance = (2 * WORLD_MAX + 1) - $xdistance; @@ -54,8 +55,8 @@ class MyGenerator { else $speed = 1; }else{ $speed = $ref; - if($building->getTypeLevel(14) != 0 && $distance >= TS_THRESHOLD) { - $speed *= ($bid14[$building->gettypeLevel(14)]['attri'] / 100) ; + if(($tSquareLevel = $building->getTypeLevel(14, $vid)) > 0 && $distance >= TS_THRESHOLD) { + $speed *= ($bid14[$tSquareLevel]['attri'] / 100) ; } } diff --git a/GameEngine/Units.php b/GameEngine/Units.php index fe9c1e10..7d0c096b 100755 --- a/GameEngine/Units.php +++ b/GameEngine/Units.php @@ -733,7 +733,7 @@ class Units { $fromCor = ['x' => $fromCoor['x'], 'y' => $fromCoor['y']]; $toCor = ['x' => $toCoor['x'], 'y' => $toCoor['y']]; - if(!$mode) return $generator->procDistanceTime($fromCor, $toCor, $unitArray[0], $mode); + if(!$mode) return $generator->procDistanceTime($fromCor, $toCor, $unitArray[0], $mode, $from); $start = ($tribe - 1) * 10 + 1; $end = $tribe * 10; diff --git a/Templates/Build/16_walking.tpl b/Templates/Build/16_walking.tpl index dc53dc1f..626a8e72 100644 --- a/Templates/Build/16_walking.tpl +++ b/Templates/Build/16_walking.tpl @@ -64,10 +64,10 @@ $to = $database->getOMInfo($units[$y]['to']);} - procResType($units[$y]['ctar1']); ?> + "> - procResType($units[$y]['ctar2'])); ?> + diff --git a/Templates/Build/17.tpl b/Templates/Build/17.tpl index 4e531365..cae4eaa2 100644 --- a/Templates/Build/17.tpl +++ b/Templates/Build/17.tpl @@ -238,7 +238,6 @@ if(isset($_POST['ft'])=='check'){

maxcarry; ?>

recieving) > 0) { echo "

".MERCHANT_COMING.":

"; foreach($market->recieving as $recieve) { @@ -247,7 +246,7 @@ echo "

".MERCHANT_COMING.":

"; echo "".$database->getUserField($villageowner,"username",0).""; echo "getMapCheck($recieve['from'])."\">".TRANSPORT_FROM." ".$database->getVillageField($recieve['from'],"name").""; echo "".ARRIVAL_IN.""; - echo "
".$generator->getTimeFormat($recieve['endtime']-time())." h
"; + echo "
timer.">".$generator->getTimeFormat($recieve['endtime']-time())." h
"; $datetime = $generator->procMtime($recieve['endtime']); echo "
"; if($datetime[0] != "today") { @@ -257,7 +256,6 @@ echo "

".MERCHANT_COMING.":

"; echo " ".RESOURCES." "; echo "\"Lumber\"".$recieve['wood']." | \"Clay\"".$recieve['clay']." | \"Iron\"".$recieve['iron']." | \"Crop\"".$recieve['crop'].""; echo ""; - $timer +=1; } } if(count($market->sending) > 0) { @@ -269,7 +267,7 @@ if(count($market->sending) > 0) { echo " $ownername"; echo "getMapCheck($send['to'])."\">".TRANSPORT_TO." ".$database->getVillageField($send['to'],"name").""; echo " ".ARRIVAL_IN." "; - echo "
".$generator->getTimeFormat($send['endtime']-time())." h
"; + echo "
timer.">".$generator->getTimeFormat($send['endtime']-time())." h
"; $datetime = $generator->procMtime($send['endtime']); echo "
"; if($datetime[0] != "today") { @@ -279,7 +277,6 @@ if(count($market->sending) > 0) { echo " ".RESOURCES.""; echo "\"Lumber\"".$send['wood']." | \"Clay\"".$send['clay']." | \"Iron\"".$send['iron']." | \"Crop\"".$send['crop'].""; echo ""; - $timer += 1; } } if(count($market->return) > 0) { @@ -291,7 +288,7 @@ if(count($market->return) > 0) { echo " $ownername"; echo "getMapCheck($return['from'])."\">".RETURNFROM." ".$database->getVillageField($return['from'],"name").""; echo " ".ARRIVAL_IN." "; - echo "
".$generator->getTimeFormat($return['endtime']-time())." h
"; + echo "
timer.">".$generator->getTimeFormat($return['endtime']-time())." h
"; $datetime = $generator->procMtime($return['endtime']); echo "
"; if($datetime[0] != "today") { @@ -300,7 +297,6 @@ if(count($market->return) > 0) { echo "".AT." ".$datetime[1]."
"; echo " "; echo ""; - $timer += 1; } } include("upgrade.tpl"); diff --git a/Templates/Building.tpl b/Templates/Building.tpl index 600e4a48..052b324f 100644 --- a/Templates/Building.tpl +++ b/Templates/Building.tpl @@ -35,7 +35,7 @@ $building->loadBuilding(); if($jobs['master'] == 0){ echo "checker\">"; echo "\"cancel\""; - echo $building->procResType($jobs['type'])." (Level ".$jobs['level'].")"; + echo Building::procResType($jobs['type'])." (Level ".$jobs['level'].")"; if($jobs['loopcon'] == 0) { $BuildingList[] = $jobs['field']; } if($jobs['loopcon'] == 1) { echo " (waiting loop)"; @@ -47,7 +47,7 @@ $building->loadBuilding(); }else{ echo "checker\">"; echo "\"cancel\""; - echo $building->procResType($jobs['type'])." (Level ".$jobs['level'].")"; + echo Building::procResType($jobs['type'])." (Level ".$jobs['level'].")"; } } ?> diff --git a/Templates/dorf2.tpl b/Templates/dorf2.tpl index 73e20b54..23e2b082 100644 --- a/Templates/dorf2.tpl +++ b/Templates/dorf2.tpl @@ -12,10 +12,10 @@ walling()) { - $wtitle = $building->procResType($building->walling())." Level ".$village->resarray['f40']; + $wtitle = Building::procResType($building->walling())." Level ".$village->resarray['f40']; } else { - $wtitle = ($village->resarray['f40'] == 0)? "Outer building site" : $building->procResType($village->resarray['f40t'],0)." Level ".$village->resarray['f40']; + $wtitle = ($village->resarray['f40'] == 0)? "Outer building site" : Building::procResType($village->resarray['f40t'],0)." Level ".$village->resarray['f40']; } ?> @@ -29,14 +29,14 @@ for($t=19;$t<=39;$t++) { if ($village->natar==1 && ( $t== 25 || $t == 26 || $t == 29 || $t == 30 || $t == 33 )) { if ($t==33) { if($village->resarray['f99'] != 0) { - $title = $building->procResType(40). " Level ".$village->resarray['f99']; - }else $title = $building->procResType(40); + $title = Building::procResType(40). " Level ".$village->resarray['f99']; + }else $title = Building::procResType(40); echo ""; } } else { if($village->resarray['f'.$t.'t'] != 0) { - $title = $building->procResType($village->resarray['f'.$t.'t']). " Level ".$village->resarray['f'.$t]; + $title = Building::procResType($village->resarray['f'.$t.'t']). " Level ".$village->resarray['f'.$t]; }else{ $title = "Building site"; if(($t == 39) && ($village->resarray['f'.$t] == 0)) { @@ -72,13 +72,13 @@ for ($i=1;$i<=20;$i++) { $text = "Building site"; $img = "iso"; if($village->resarray['f'.($i+18).'t'] != 0) { - $text = $building->procResType($village->resarray['f'.($i+18).'t'])." Level ".$village->resarray['f'.($i+18)]; + $text = Building::procResType($village->resarray['f'.($i+18).'t'])." Level ".$village->resarray['f'.($i+18)]; $img = "g".$village->resarray['f'.($i+18).'t']; } foreach($building->buildArray as $job) { if($job['field'] == ($i+18)) { $img = 'g'.$job['type'].'b'; - $text = $building->procResType($job['type'])." Level ".$village->resarray['f'.$job['field']]; + $text = Building::procResType($job['type'])." Level ".$village->resarray['f'.$job['field']]; } } echo "\"$text\""; diff --git a/Templates/dorf3/1.tpl b/Templates/dorf3/1.tpl index 1db397b9..ccaab45a 100644 --- a/Templates/dorf3/1.tpl +++ b/Templates/dorf3/1.tpl @@ -19,9 +19,7 @@ $totalmerchants = $building->getTypeLevel(17,$vid); $availmerchants = $totalmerchants - $database->totalMerchantUsed($vid); $incoming_attacks = $database->getMovement(3,$vid,1); - $bui = ''; - $tro = ''; - $att = ''; + $bui = $tro = $att = ''; if (count($incoming_attacks) > 0) { $inc_atts = count($incoming_attacks); @@ -35,7 +33,7 @@ } } foreach($jobs as $b){ - $bui .= ''.$building->procResType($b['type']).''; + $bui .= ''.Building::procResType($b['type']).''; } foreach($unitsArray as $key => $c){ if($key == 99) $key = 51; diff --git a/Templates/field.tpl b/Templates/field.tpl index 655a970c..2733c6da 100644 --- a/Templates/field.tpl +++ b/Templates/field.tpl @@ -27,7 +27,7 @@ if (count($jobs)) { } for ($i=1; $i<=18; $i++) { - echo " procResType($arrayVillage['f'.$i.'t'])." Level ".$arrayVillage['f'.$i].(isset($activeFields[$i]) ? ' (upgrade in progress)' : '')."\"/>\r\n"; + echo " \r\n"; } ?>