From a2aeeab6e856d75f831b74be6ee448bd27328a2a Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Jul 2012 19:12:54 +0300 Subject: [PATCH] fix starvation --- GameEngine/Automation.php | 118 +++++++++++-------------------- GameEngine/Database/db_MYSQL.php | 9 ++- install/data/sql.sql | 1 + 3 files changed, 51 insertions(+), 77 deletions(-) diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index 6661454e..9c414ecf 100644 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -3797,59 +3797,6 @@ $crannyimg = "30, - '2'=>70, - '3'=>80, - '4'=>40, - '5'=>100, - '6'=>180, - '7'=>70, - '8'=>90, - '9'=>37500, - '10'=>5500, - '11'=>40, - '12'=>40, - '13'=>70, - '14'=>50, - '15'=>75, - '16'=>80, - '17'=>70, - '18'=>60, - '19'=>27200, - '20'=>6500, - '21'=>30, - '22'=>60, - '23'=>40, - '24'=>60, - '25'=>120, - '26'=>170, - '27'=>75, - '28'=>90, - '29'=>37500, - '30'=>4900, - '31'=>100, - '32'=>100, - '33'=>100, - '34'=>100, - '35'=>100, - '36'=>100, - '37'=>100, - '38'=>100, - '39'=>100, - '40'=>100, - '41'=>100, - '42'=>100, - '43'=>100, - '44'=>100, - '45'=>100, - '46'=>100, - '47'=>100, - '48'=>100, - '49'=>100, - '50'=>100 - ); $starvupkeep = array( '1'=>1, @@ -3901,7 +3848,8 @@ $crannyimg = "6, '48'=>5, '49'=>1, - '50'=>1 + '50'=>1, + 'hero'=>6 ); $time = time(); @@ -3910,7 +3858,7 @@ $crannyimg = "getStarvation(); foreach ($starvarray as $starv){ - if (($starv['starvupdate']+60) < $time){ + if (($starv['starvupdate']+600) < $time){ // get enforce $enforcearray = $database->getEnforceVillage($starv['wref'],0); $maxcount = 0; @@ -3923,6 +3871,11 @@ $crannyimg = "setVillageField($starv['wref'], 'crop', $newcrop); } } + $upkeep = $starv['pop'] + $this->getUpkeep($unitarrays, 0); if($difcrop > 0){ - $killunits = round(($difcrop/$starvcost[$maxtype])); + $killunits = round($difcrop/18000); + if($killunits > 0){ if (isset($enf)){ if($killunits < $maxcount){ $database->modifyEnforce($enf, $maxtype, $killunits, 0); + $database->setVillageField($starv['wref'], 'starv', $upkeep); + $database->setVillageField($starv['wref'], 'starvupdate', $time); }else{ $database->deleteReinf($enf); + $database->setVillageField($starv['wref'], 'starv', $upkeep); + $database->setVillageField($starv['wref'], 'starvupdate', $time); } }else{ if($killunits < $maxcount){ - $database->modifyUnit($starv['wref'], $maxtype, $killunits, 0); + $database->modifyUnit($starv['wref'], array($maxtype), array($killunits), array(0)); + $database->setVillageField($starv['wref'], 'starv', $upkeep); + $database->setVillageField($starv['wref'], 'starvupdate', $time); }elseif($killunits > $maxcount){ $killunits = $maxcount; - $database->modifyUnit($starv['wref'], $maxtype, $killunits, 0); + $database->modifyUnit($starv['wref'], array($maxtype), array($killunits), array(0)); + $database->setVillageField($starv['wref'], 'starv', $upkeep); + $database->setVillageField($starv['wref'], 'starvupdate', $time); } } + } } - $upkeep = $starv['starv']-($killunits*$starvupkeep[$maxtype]); - - $time = time(); - $crop = $database->getCropProdstarv($starv['wref']); - $unitarrays = $this->getAllUnits($starv['wref']); - $upkeep = $this->getUpkeep($unitarrays, 0) ; - if ($crop < $upkeep){ - // add starv data - $database->setVillageField($starv['wref'], 'starv', $upkeep); - $database->setVillageField($starv['wref'], 'starvupdate', $time); - $database->setVillageField($starv['wref'], 'crop', $newcrop); - }else{ + if ($crop > $upkeep){ $database->setVillageField($starv['wref'], 'starv', 0); $database->setVillageField($starv['wref'], 'starvupdate', 0); - $database->setVillageField($starv['wref'], 'crop', $newcrop); } } unset ($starv,$unitarray,$enforcearray,$enforce,$starvarray); } + $getvillage = $database->getUnstarvation(); + foreach($getvillage as $village){ + $time2 = time(); + $crop2 = $database->getCropProdstarv($village['wref']); + $unitarrays2 = $this->getAllUnits($village['wref']); + $upkeep2 = $village['pop'] + $this->getUpkeep($unitarrays2, 0); + if ($crop2 < $upkeep2){ + // add starv data + $database->setVillageField($village['wref'], 'starv', $upkeep2); + $database->setVillageField($village['wref'], 'starvupdate', $time2); + } + } if(file_exists("GameEngine/Prevention/starvation.txt")) { unlink("GameEngine/Prevention/starvation.txt"); diff --git a/GameEngine/Database/db_MYSQL.php b/GameEngine/Database/db_MYSQL.php index b3ef59ed..850df6cf 100644 --- a/GameEngine/Database/db_MYSQL.php +++ b/GameEngine/Database/db_MYSQL.php @@ -164,6 +164,12 @@ class MYSQL_DB { $result = mysql_query($q, $this->connection); return $this->mysql_fetch_all($result); } + + function getUnstarvation(){ + $q = "SELECT * FROM " . TB_PREFIX . "vdata where starv = 0 and starvupdate = 0"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } function getActivateField($ref, $field, $mode) { if(!$mode) { @@ -3123,8 +3129,7 @@ class MYSQL_DB { } } $q = "SELECT type FROM `" . TB_PREFIX . "odata` WHERE conqured = $wref"; - $result = mysql_query($q, $this->connection) or die(mysql_error()); - $oasis = mysql_fetch_array($result); + $oasis = $this->query_return($q); foreach($oasis as $oa){ switch($oa['type']) { case 1: diff --git a/install/data/sql.sql b/install/data/sql.sql index 5d541afd..9574c92b 100644 --- a/install/data/sql.sql +++ b/install/data/sql.sql @@ -1475,6 +1475,7 @@ CREATE TABLE IF NOT EXISTS `%PREFIX%vdata` ( `created` int(11) NOT NULL, `natar` tinyint(1) unsigned NOT NULL, `starv` int(11) unsigned NOT NULL, +`starvupdate` int(11) unsigned NOT NULL, `evasion` tinyint(1) unsigned NOT NULL, PRIMARY KEY (`wref`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;