diff --git a/Admin/Mods/addTroops.php b/Admin/Mods/addTroops.php index e6968e6a..558f3bf2 100644 --- a/Admin/Mods/addTroops.php +++ b/Admin/Mods/addTroops.php @@ -12,6 +12,7 @@ ################################################################################# include_once("../../Account.php"); +include_once("../../Technology.php"); if (!isset($_SESSION)) session_start(); if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!"); @@ -29,80 +30,29 @@ foreach ($_POST as $key => $value) { $_POST[$key] = (int) $value; } -$u1 = $_POST['u1']; -$u2 = $_POST['u2']; -$u3 = $_POST['u3']; -$u4 = $_POST['u4']; -$u5 = $_POST['u5']; -$u6 = $_POST['u6']; -$u7 = $_POST['u7']; -$u8 = $_POST['u8']; -$u9 = $_POST['u9']; -$u10 = $_POST['u10']; -//////////////////// -$u11 = $_POST['u11']; -$u12 = $_POST['u12']; -$u13 = $_POST['u13']; -$u14 = $_POST['u14']; -$u15 = $_POST['u15']; -$u16 = $_POST['u16']; -$u17 = $_POST['u17']; -$u18 = $_POST['u18']; -$u19 = $_POST['u19']; -$u20 = $_POST['u20']; -//////////////////// -$u21 = $_POST['u21']; -$u22 = $_POST['u22']; -$u23 = $_POST['u23']; -$u24 = $_POST['u24']; -$u25 = $_POST['u25']; -$u26 = $_POST['u26']; -$u27 = $_POST['u27']; -$u28 = $_POST['u28']; -$u29 = $_POST['u29']; -$u30 = $_POST['u30']; -//////////////////// -$u31 = $_POST['u31']; -$u32 = $_POST['u32']; -$u33 = $_POST['u33']; -$u34 = $_POST['u34']; -$u35 = $_POST['u35']; -$u36 = $_POST['u36']; -$u37 = $_POST['u37']; -$u38 = $_POST['u38']; -$u39 = $_POST['u39']; -$u40 = $_POST['u40']; -//////////////////// -$u41 = $_POST['u41']; -$u42 = $_POST['u42']; -$u43 = $_POST['u43']; -$u44 = $_POST['u44']; -$u45 = $_POST['u45']; -$u46 = $_POST['u46']; -$u47 = $_POST['u47']; -$u48 = $_POST['u48']; -$u49 = $_POST['u49']; -$u50 = $_POST['u50']; +for($i = 1; $i <= 50; $i++) ${"u".$i} = $_POST['u'.$i]; if($user['tribe'] == 1){ -$q = "UPDATE ".TB_PREFIX."units SET u1 = $u1, u2 = $u2, u3 = $u3, u4 = $u4, u5 = $u5, u6 = $u6, u7 = $u7, u8 = $u8, u9 = $u9, u10 = $u10 WHERE vref = $id"; -mysqli_query($GLOBALS["link"], $q); + $q = "UPDATE ".TB_PREFIX."units SET u1 = $u1, u2 = $u2, u3 = $u3, u4 = $u4, u5 = $u5, u6 = $u6, u7 = $u7, u8 = $u8, u9 = $u9, u10 = $u10 WHERE vref = $id"; + mysqli_query($GLOBALS["link"], $q); } else if($user['tribe'] == 2){ -$q = "UPDATE ".TB_PREFIX."units SET u11 = '$u11', u12 = '$u12', u13 = '$u13', u14 = '$u14', u15 = '$u15', u16 = '$u16', u17 = '$u17', u18 = '$u18', u19 = '$u19', u20 = '$u20' WHERE vref = $id"; -mysqli_query($GLOBALS["link"], $q); + $q = "UPDATE ".TB_PREFIX."units SET u11 = '$u11', u12 = '$u12', u13 = '$u13', u14 = '$u14', u15 = '$u15', u16 = '$u16', u17 = '$u17', u18 = '$u18', u19 = '$u19', u20 = '$u20' WHERE vref = $id"; + mysqli_query($GLOBALS["link"], $q); } else if($user['tribe'] == 3){ -$q = "UPDATE ".TB_PREFIX."units SET u21 = '$u21', u22 = '$u22', u23 = '$u23', u24 = '$u24', u25 = '$u25', u26 = '$u26', u27 = '$u27', u28 = '$u28', u29 = '$u29', u30 = '$u30' WHERE vref = $id"; -mysqli_query($GLOBALS["link"], $q); + $q = "UPDATE ".TB_PREFIX."units SET u21 = '$u21', u22 = '$u22', u23 = '$u23', u24 = '$u24', u25 = '$u25', u26 = '$u26', u27 = '$u27', u28 = '$u28', u29 = '$u29', u30 = '$u30' WHERE vref = $id"; + mysqli_query($GLOBALS["link"], $q); } else if($user['tribe'] == 4){ -$q = "UPDATE ".TB_PREFIX."units SET u31 = '$u31', u32 = '$u32', u33 = '$u33', u34 = '$u34', u35 = '$u35', u36 = '$u36', u37 = '$u37', u38 = '$u38', u39 = '$u39', u40 = '$u40' WHERE vref = $id"; -mysqli_query($GLOBALS["link"], $q); + $q = "UPDATE ".TB_PREFIX."units SET u31 = '$u31', u32 = '$u32', u33 = '$u33', u34 = '$u34', u35 = '$u35', u36 = '$u36', u37 = '$u37', u38 = '$u38', u39 = '$u39', u40 = '$u40' WHERE vref = $id"; + mysqli_query($GLOBALS["link"], $q); } else if($user['tribe'] == 5){ -$q = "UPDATE ".TB_PREFIX."units SET u41 = '$u41', u42 = '$u42', u43 = '$u43', u44 = '$u44', u45 = '$u45', u46 = '$u46', u47 = '$u47', u48 = '$u48', u49 = '$u49', u50 = '$u50' WHERE vref = $id"; -mysqli_query($GLOBALS["link"], $q); + $q = "UPDATE ".TB_PREFIX."units SET u41 = '$u41', u42 = '$u42', u43 = '$u43', u44 = '$u44', u45 = '$u45', u46 = '$u46', u47 = '$u47', u48 = '$u48', u49 = '$u49', u50 = '$u50' WHERE vref = $id"; + mysqli_query($GLOBALS["link"], $q); } mysqli_query($GLOBALS["link"], "Insert into ".TB_PREFIX."admin_log values (0,".(int) $_SESSION['id'].",'Changed troop anmount in village $id ',".time().")"); +$database->addStarvationData($village['wref']); + header("Location: ../../../Admin/admin.php?p=addTroops&did=".$id."&d"); ?> \ No newline at end of file diff --git a/Admin/Templates/addTroops.tpl b/Admin/Templates/addTroops.tpl index a3434a47..87860c7c 100644 --- a/Admin/Templates/addTroops.tpl +++ b/Admin/Templates/addTroops.tpl @@ -9,7 +9,7 @@ ## Copyright: TravianZ (c) 2010-2014. All rights reserved. ## ## ## ################################################################################# -$unarray = array(1=>U1,U2,U3,U4,U5,U6,U7,U8,U9,U10,U11,U12,U13,U14,U15,U16,U17,U18,U19,U20,U21,U22,U23,U24,U25,U26,U27,U28,U29,U30,U31,U32,U33,U34,U35,U36,U37,U38,U39,U40,U41,U42,U43,U44,U45,U46,U47,U48,U49,U50,U99,U0); +$unarray = [1=>U1,U2,U3,U4,U5,U6,U7,U8,U9,U10,U11,U12,U13,U14,U15,U16,U17,U18,U19,U20,U21,U22,U23,U24,U25,U26,U27,U28,U29,U30,U31,U32,U33,U34,U35,U36,U37,U38,U39,U40,U41,U42,U43,U44,U45,U46,U47,U48,U49,U50,U99,U0]; if($_SESSION['access'] < 9) die(ACCESS_DENIED_ADMIN); $id = $_GET['did']; if(isset($id)) @@ -17,12 +17,8 @@ if(isset($id)) $units = $database->getUnit($village['wref']); $coor = $database->getCoor($village['wref']); $tribe = $user['tribe']; - if($tribe ==1){ $img = 0;} - if($tribe ==2){ $img = 10;} - if($tribe ==3){ $img = 20;} - if($tribe ==4){ $img = 30;} - if($tribe ==5){ $img = 40;} - if($tribe ==6){ $img = 50;} + $img = ($tribe - 1) * 10; + include("search2.tpl"); ?>
@@ -34,7 +30,7 @@ if(isset($id)) Edit troops '.$unarray[$img+$i].' diff --git a/GameEngine/Admin/Mods/addTroops.php b/GameEngine/Admin/Mods/addTroops.php index a52ccafa..770aa5dc 100755 --- a/GameEngine/Admin/Mods/addTroops.php +++ b/GameEngine/Admin/Mods/addTroops.php @@ -13,25 +13,23 @@ if(!isset($_SESSION)) session_start(); if($_SESSION['access'] < 9) die(ACCESS_DENIED_ADMIN); include_once("../../Database.php"); +include_once("../../Technology.php"); +include_once("../../Data/unitdata.php"); -$id = $_POST['id']; +$id = (int)$_POST['id']; $village = $database->getVillage($id); -$user = $database->getUserArray($village['owner'],1); -$units=""; - $tribe = $user['tribe']; - if($tribe ==1){ $u = 0;} - if($tribe ==2){ $u = 10;} - if($tribe ==3){ $u = 20;} - if($tribe ==4){ $u = 30;} - if($tribe ==5){ $u = 40;} - if($tribe ==6){ $u = 50;} +$user = $database->getUserArray($village['owner'],1); +$units = ""; +$tribe = $user['tribe']; +$u = ($tribe - 1) * 10; -for($i=1; $i<11; $i++) { - $units.="u".($u+$i)."=".$database->escape($_POST['u'.($u+$i)].(($i < 10) ? ", " : "")); +for($i = 1; $i < 11; $i++) { + $units.="u".($u + $i)."=".$database->escape($_POST['u'.($u + $i)].(($i < 10) ? ", " : "")); } -$q = "UPDATE ".TB_PREFIX."units SET ".$units." WHERE vref = ".(int) $id; + +$q = "UPDATE ".TB_PREFIX."units SET ".$units." WHERE vref = ".$id; $database->query($q); $database->query("Insert into ".TB_PREFIX."admin_log values (0,".(int) $_SESSION['id'].",'Changed troop amounts in village $id ',".time().")"); - +$database->addStarvationData($id); header("Location: ../../../Admin/admin.php?p=village&did=".$id."&d"); ?> \ No newline at end of file diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php old mode 100755 new mode 100644 index e5680297..90804055 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -383,7 +383,7 @@ class Automation { } private function buildComplete() { - global $database, $bid18, $bid10, $bid11, $bid38, $bid39; + global $database, $technology, $bid18, $bid10, $bid11, $bid38, $bid39; $time = time(); // IDs of villages that were affected by this building completion update, @@ -476,7 +476,7 @@ class Automation { } //Update starvation data - $this->addStarvationData($indi['wid']); + $database->addStarvationData($indi['wid']); // update the requested fields, all at once $database->setVillageFields($indi['wid'], array_keys($fieldsToSet), array_values($fieldsToSet)); @@ -2488,7 +2488,7 @@ class Automation { } //Update starvation data - $this->addStarvationData($to['wref']); + $database->addStarvationData($to['wref']); //Returning units back to village is not necessary because it will be taken care when processing movement // Fix by AL-Kateb @@ -2579,7 +2579,7 @@ class Automation { } private function sendreinfunitsComplete() { - global $bid23, $database, $battle; + global $bid23, $database, $technology, $battle; $time = time(); $q = " @@ -2717,7 +2717,7 @@ class Automation { } //Update starvation data - $this->addStarvationData($data['to']); + $database->addStarvationData($data['to']); //check empty reinforcement in rally point $e_units = ''; @@ -2733,7 +2733,7 @@ class Automation { } private function returnunitsComplete() { - global $database; + global $database, $technology; $time = time(); $q = " @@ -2783,7 +2783,7 @@ class Automation { $movementProcIDs[] = $data['moveid']; //Update starvation data - $this->addStarvationData($data['to']); + $database->addStarvationData($data['to']); } $database->setMovementProc(implode(', ', $movementProcIDs)); @@ -3233,7 +3233,7 @@ class Automation { } private function trainingComplete() { - global $database; + global $database, $technology; $time = time(); $trainlist = $database->getTrainingList(); @@ -3287,7 +3287,7 @@ class Automation { if ($valuesUpdated) call_user_func(get_class($database).'::clearUnitsCache'); //Update starvation data - $this->addStarvationData($train['vref']); + $database->addStarvationData($train['vref']); } } } @@ -3677,30 +3677,6 @@ class Automation { } } } - - /** - * Adds the starvation data in villages with a negative value of crop - * - * @param int $wref The village ID where the crop is negative - */ - - private function addStarvationData($wref){ - global $database, $technology; - - $getVillage = $database->getVillage($wref); - - //Exlude Support, Nature, Natars, TaskMaster and Multihunter - if ($getVillage['owner'] > 5){ - $crop = $database->getCropProdstarv($wref, false); - $unitArrays = $this->getAllUnits($wref, false); - $villageUpkeep = $getVillage['pop'] + $technology->getUpkeep($unitArrays, 0, $wref); - $starv = $getVillage['starv']; - if ($crop < $villageUpkeep){ - //Add starvation data - $database->setVillageFields($wref, ['starv'], [$villageUpkeep]); - } - } - } /** * Function for starvation - by brainiacX and Shadow @@ -3712,23 +3688,23 @@ class Automation { private function starvation() { global $database, $technology; - //starvation is disabled during Easter/Holidays/Christmas + //Starvation is disabled during Easter/Holidays/Christmas if(PEACE) return; $time = time(); - //update starvation in every village + //Update starvation in every village $starvarray = $database->getProfileVillages(0, 7); - foreach($starvarray as $starv) $this->addStarvationData($starv['wref']); + foreach($starvarray as $starv) $database->addStarvationData($starv['wref']); - // load villages with minus prod + //Load villages with minus prod $starvarray = []; $starvarray = $database->getStarvation(); $vilIDs = []; foreach ($starvarray as $starv) $vilIDs[] = $starv['wref']; - // cache + //Cache $database->getEnforceVillage($vilIDs, 0); $database->getOasisEnforce($vilIDs, 2); $database->getOasisEnforce($vilIDs, 3); @@ -3758,7 +3734,7 @@ class Automation { $allTroopsArray = [$enforceArrays, $prisonerArrays, $unitArrays, $attackArrays]; - // find the first not-empty array + //Find the first not-empty array foreach($allTroopsArray as $type => $allTroops) { if(!empty($allTroops)){ @@ -3771,10 +3747,10 @@ class Automation { } } - // if the player has no troops, then skip the next instructions + //If the player has no troops, then skip the next instructions if(empty($starvingTroops)) continue; - // counting + //Counting $timedif = $time - $starv['starvupdate']; $cropProd = $database->getCropProdstarv($starv['wref']) - $starv['starv']; if($cropProd < 0){ @@ -3783,7 +3759,7 @@ class Automation { $newcrop = 0; $oldcrop = $database->getVillageField($starv['wref'], 'crop'); - //if the grain is then tries to send all + //If the grain is then tries to send all if ($oldcrop > 100){ $difcrop = $difcrop - $oldcrop; if($difcrop < 0){ @@ -3804,7 +3780,7 @@ class Automation { $counting = true; while($difcrop > 0) { - // search the highest troop + //S earch the highest troop $maxcount = $maxtype = 0; for($i = $start ; $i <= $end ; $i++) { @@ -3837,10 +3813,8 @@ class Automation { else if($maxtype == 0) $newCrop = 0; else $newCrop = $GLOBALS['u'.$maxtype]['crop']; - if($totalKilledUnits > 0) - { - switch($type) - { + if($totalKilledUnits > 0){ + switch($type){ case 0: if($totalKilledUnits < $totalUnits){ $database->modifyEnforce($starvingTroops['id'], array_keys($killedUnits), array_values($killedUnits), 0); diff --git a/GameEngine/Database.php b/GameEngine/Database.php index 5c92bb1c..6fe58eeb 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -7697,7 +7697,6 @@ References: User ID/Message ID, Mode foreach($detailsArray as $field => $value) $values[] = $field."=".$value; $q = "UPDATE ".TB_PREFIX."artefacts SET ".implode(",", $values)." WHERE id = $id"; - echo $q; return mysqli_query($this->dblink, $q); } @@ -7858,7 +7857,7 @@ References: User ID/Message ID, Mode case 9: case 10: case 11: - $cropo ++; + $cropo++; break; case 12: $cropo += 2; @@ -7883,6 +7882,41 @@ References: User ID/Message ID, Mode return self::$cropProductionStarvationValueCache[$wref]; } + /** + * Adds the starvation data in villages with a negative value of crop + * + * @param int $wref The village ID where the crop is negative + */ + + public function addStarvationData($wref){ + global $technology; + + $getVillage = $this->getVillage($wref); + + //Exlude Support, Nature, Natars, TaskMaster and Multihunter + if ($getVillage['owner'] > 5){ + $crop = $this->getCropProdstarv($wref, false); + $unitArrays = $technology->getAllUnits($wref, false, 0, false); + $villageUpkeep = $getVillage['pop'] + $technology->getUpkeep($unitArrays, 0, $wref); + $starv = $getVillage['starv']; + + if ($crop < $villageUpkeep){ + //Add starvation data + $fields = ['starv']; + $values = [$villageUpkeep]; + + //Update the starvupdate if it's set to 0 + if($getVillage['starvupdate'] == 0) { + $fields[] = 'starvupdate'; + $values[] = time(); + } + + //Update the starvation datas + $this->setVillageFields($wref, $fields, $values); + } + } + } + //general statistics function addGeneralAttack($casualties) { diff --git a/GameEngine/Technology.php b/GameEngine/Technology.php index 6c6fd9e6..de1d31c0 100755 --- a/GameEngine/Technology.php +++ b/GameEngine/Technology.php @@ -236,13 +236,13 @@ class Technology { return $ownunit; } - function getAllUnits($base, $InVillageOnly = false, $mode=0) { + function getAllUnits($base, $InVillageOnly = false, $mode = 0, $useCache = true) { global $database; - $ownunit = $database->getUnit($base); + $ownunit = $database->getUnit($base, $useCache); $ownunit['u99'] -= $ownunit['u99']; $ownunit['u99o'] -= $ownunit['u99o']; - $enforcementarray = $database->getEnforceVillage($base, 0); + $enforcementarray = $database->getEnforceVillage($base, 0, $useCache); if(count($enforcementarray) > 0){ foreach($enforcementarray as $enforce){ for($i = 1; $i <= 50; $i++){ @@ -252,7 +252,7 @@ class Technology { } } if($mode == 0){ - $enforceoasis = $database->getOasisEnforce($base, 0); + $enforceoasis = $database->getOasisEnforce($base, 0, $useCache); if(count($enforceoasis) > 0){ foreach($enforceoasis as $enforce){ for($i = 1; $i <= 50; $i++){ @@ -261,7 +261,7 @@ class Technology { $ownunit['hero'] += $enforce['hero']; } } - $enforceoasis1 = $database->getOasisEnforce($base, 1); + $enforceoasis1 = $database->getOasisEnforce($base, 1, $useCache); if(count($enforceoasis1) > 0){ foreach($enforceoasis1 as $enforce){ for($i = 1; $i <= 50; $i++){ @@ -271,7 +271,7 @@ class Technology { } } - $prisoners = $database->getPrisoners($base, 1); + $prisoners = $database->getPrisoners($base, 1, $useCache); if(!empty($prisoners)){ foreach($prisoners as $prisoner){ $owner = $database->getVillageField($base, "owner");