mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-08-14 07:11:02 +00:00
fix starvation
This commit is contained in:
+43
-75
@@ -3797,59 +3797,6 @@ $crannyimg = "<img src=\"".GP_LOCATE."img/g/g23.gif\" height=\"20\" width=\"15\"
|
|||||||
global $database;
|
global $database;
|
||||||
$ourFileHandle = fopen("GameEngine/Prevention/starvation.txt", 'w');
|
$ourFileHandle = fopen("GameEngine/Prevention/starvation.txt", 'w');
|
||||||
fclose($ourFileHandle);
|
fclose($ourFileHandle);
|
||||||
$starvcost = array(
|
|
||||||
|
|
||||||
'1'=>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(
|
$starvupkeep = array(
|
||||||
|
|
||||||
'1'=>1,
|
'1'=>1,
|
||||||
@@ -3901,7 +3848,8 @@ $crannyimg = "<img src=\"".GP_LOCATE."img/g/g23.gif\" height=\"20\" width=\"15\"
|
|||||||
'47'=>6,
|
'47'=>6,
|
||||||
'48'=>5,
|
'48'=>5,
|
||||||
'49'=>1,
|
'49'=>1,
|
||||||
'50'=>1
|
'50'=>1,
|
||||||
|
'hero'=>6
|
||||||
);
|
);
|
||||||
|
|
||||||
$time = time();
|
$time = time();
|
||||||
@@ -3910,7 +3858,7 @@ $crannyimg = "<img src=\"".GP_LOCATE."img/g/g23.gif\" height=\"20\" width=\"15\"
|
|||||||
$starvarray = array();
|
$starvarray = array();
|
||||||
$starvarray = $database->getStarvation();
|
$starvarray = $database->getStarvation();
|
||||||
foreach ($starvarray as $starv){
|
foreach ($starvarray as $starv){
|
||||||
if (($starv['starvupdate']+60) < $time){
|
if (($starv['starvupdate']+600) < $time){
|
||||||
// get enforce
|
// get enforce
|
||||||
$enforcearray = $database->getEnforceVillage($starv['wref'],0);
|
$enforcearray = $database->getEnforceVillage($starv['wref'],0);
|
||||||
$maxcount = 0;
|
$maxcount = 0;
|
||||||
@@ -3923,6 +3871,11 @@ $crannyimg = "<img src=\"".GP_LOCATE."img/g/g23.gif\" height=\"20\" width=\"15\"
|
|||||||
$maxcount = $unitarray['u'.$i];
|
$maxcount = $unitarray['u'.$i];
|
||||||
$maxtype = $i;
|
$maxtype = $i;
|
||||||
}
|
}
|
||||||
|
$totalunits += $unitarray['u'.$i];
|
||||||
|
}
|
||||||
|
if($totalunits == 0){
|
||||||
|
$maxcount = $unitarray['hero'];
|
||||||
|
$maxtype = "hero";
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
foreach ($enforcearray as $enforce){
|
foreach ($enforcearray as $enforce){
|
||||||
@@ -3933,9 +3886,14 @@ $crannyimg = "<img src=\"".GP_LOCATE."img/g/g23.gif\" height=\"20\" width=\"15\"
|
|||||||
$maxtype = $i;
|
$maxtype = $i;
|
||||||
$enf = $enforce['id'];
|
$enf = $enforce['id'];
|
||||||
}
|
}
|
||||||
}
|
$totalunits += $enforce['u'.$i];
|
||||||
|
}
|
||||||
|
if($totalunits == 0){
|
||||||
|
$maxcount = $enforce['hero'];
|
||||||
|
$maxtype = "hero";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// counting
|
// counting
|
||||||
|
|
||||||
@@ -3951,48 +3909,58 @@ $crannyimg = "<img src=\"".GP_LOCATE."img/g/g23.gif\" height=\"20\" width=\"15\"
|
|||||||
if($difcrop < 0){
|
if($difcrop < 0){
|
||||||
$difcrop = 0;
|
$difcrop = 0;
|
||||||
$newcrop = $oldcrop-$difcrop;
|
$newcrop = $oldcrop-$difcrop;
|
||||||
}else{
|
$database->setVillageField($starv['wref'], 'crop', $newcrop);
|
||||||
$newcrop = $starvcost[$maxtype];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$upkeep = $starv['pop'] + $this->getUpkeep($unitarrays, 0);
|
||||||
if($difcrop > 0){
|
if($difcrop > 0){
|
||||||
$killunits = round(($difcrop/$starvcost[$maxtype]));
|
$killunits = round($difcrop/18000);
|
||||||
|
if($killunits > 0){
|
||||||
if (isset($enf)){
|
if (isset($enf)){
|
||||||
if($killunits < $maxcount){
|
if($killunits < $maxcount){
|
||||||
$database->modifyEnforce($enf, $maxtype, $killunits, 0);
|
$database->modifyEnforce($enf, $maxtype, $killunits, 0);
|
||||||
|
$database->setVillageField($starv['wref'], 'starv', $upkeep);
|
||||||
|
$database->setVillageField($starv['wref'], 'starvupdate', $time);
|
||||||
}else{
|
}else{
|
||||||
$database->deleteReinf($enf);
|
$database->deleteReinf($enf);
|
||||||
|
$database->setVillageField($starv['wref'], 'starv', $upkeep);
|
||||||
|
$database->setVillageField($starv['wref'], 'starvupdate', $time);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if($killunits < $maxcount){
|
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){
|
}elseif($killunits > $maxcount){
|
||||||
$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']);
|
$crop = $database->getCropProdstarv($starv['wref']);
|
||||||
$unitarrays = $this->getAllUnits($starv['wref']);
|
if ($crop > $upkeep){
|
||||||
$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{
|
|
||||||
$database->setVillageField($starv['wref'], 'starv', 0);
|
$database->setVillageField($starv['wref'], 'starv', 0);
|
||||||
$database->setVillageField($starv['wref'], 'starvupdate', 0);
|
$database->setVillageField($starv['wref'], 'starvupdate', 0);
|
||||||
$database->setVillageField($starv['wref'], 'crop', $newcrop);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset ($starv,$unitarray,$enforcearray,$enforce,$starvarray);
|
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")) {
|
if(file_exists("GameEngine/Prevention/starvation.txt")) {
|
||||||
unlink("GameEngine/Prevention/starvation.txt");
|
unlink("GameEngine/Prevention/starvation.txt");
|
||||||
|
|||||||
@@ -164,6 +164,12 @@ class MYSQL_DB {
|
|||||||
$result = mysql_query($q, $this->connection);
|
$result = mysql_query($q, $this->connection);
|
||||||
return $this->mysql_fetch_all($result);
|
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) {
|
function getActivateField($ref, $field, $mode) {
|
||||||
if(!$mode) {
|
if(!$mode) {
|
||||||
@@ -3123,8 +3129,7 @@ class MYSQL_DB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$q = "SELECT type FROM `" . TB_PREFIX . "odata` WHERE conqured = $wref";
|
$q = "SELECT type FROM `" . TB_PREFIX . "odata` WHERE conqured = $wref";
|
||||||
$result = mysql_query($q, $this->connection) or die(mysql_error());
|
$oasis = $this->query_return($q);
|
||||||
$oasis = mysql_fetch_array($result);
|
|
||||||
foreach($oasis as $oa){
|
foreach($oasis as $oa){
|
||||||
switch($oa['type']) {
|
switch($oa['type']) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|||||||
@@ -1475,6 +1475,7 @@ CREATE TABLE IF NOT EXISTS `%PREFIX%vdata` (
|
|||||||
`created` int(11) NOT NULL,
|
`created` int(11) NOT NULL,
|
||||||
`natar` tinyint(1) unsigned NOT NULL,
|
`natar` tinyint(1) unsigned NOT NULL,
|
||||||
`starv` int(11) unsigned NOT NULL,
|
`starv` int(11) unsigned NOT NULL,
|
||||||
|
`starvupdate` int(11) unsigned NOT NULL,
|
||||||
`evasion` tinyint(1) unsigned NOT NULL,
|
`evasion` tinyint(1) unsigned NOT NULL,
|
||||||
PRIMARY KEY (`wref`)
|
PRIMARY KEY (`wref`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
|
||||||
|
|||||||
Reference in New Issue
Block a user