yi12345 / TravianZ

travian t3.6 project (based on travianx v6.0.0)
185 stars 191 forks source link

Starvation #274

Closed Shadowss closed 11 years ago

Shadowss commented 11 years ago

Do you have a solution for make starvation work?

So tell me what is the rule for working this function .

Production: Lumber Lumber: 156250 per hour Clay Clay: 93750 per hour Iron Iron: 125000 per hour Crop Crop: -419664 per hour Troops: Legionnaire 20000 Legionnaire Praetorian 20000 Praetorian Imperian 20000 Imperian Equites Legati 20000 Equites Legati Equites Imperatoris 20000 Equites Imperatoris Equites Caesaris 20000 Equites Caesaris Battering Ram 20000 Battering Ram Fire Catapult 20000 Fire Catapult

None of my troops die ... and my granary is 0

It`s a function in automation.php , this function update in database starv and starvupdate but do nothing in website

private function starvation() {
if(file_exists("GameEngine/Prevention/starvation.txt")) {
        unlink("GameEngine/Prevention/starvation.txt");
    }
    global $database;
    $ourFileHandle = fopen("GameEngine/Prevention/starvation.txt", 'w');
    fclose($ourFileHandle);
    $starvupkeep = array(

        '1'=>1,
        '2'=>1,
        '3'=>1,
        '4'=>2,
        '5'=>3,
        '6'=>4,
        '7'=>3,
        '8'=>6,
        '9'=>5,
        '10'=>1,
        '11'=>1,
        '12'=>1,
        '13'=>1,
        '14'=>1,
        '15'=>2,
        '16'=>3,
        '17'=>6,
        '18'=>4,
        '19'=>1,
        '20'=>1,
        '21'=>1,
        '22'=>1,
        '23'=>2,
        '24'=>2,
        '25'=>2,
        '26'=>3,
        '27'=>3,
        '28'=>6,
        '29'=>4,
        '30'=>1,
        '31'=>1,
        '32'=>1,
        '33'=>1,
        '34'=>2,
        '35'=>2,
        '36'=>3,
        '37'=>3,
        '38'=>3,
        '39'=>3,
        '40'=>5,
        '41'=>1,
        '42'=>1,
        '43'=>1,
        '44'=>1,
        '45'=>2,
        '46'=>3,
        '47'=>6,
        '48'=>5,
        '49'=>1,
        '50'=>1,
        'hero'=>6
    );

    $time = time();

    // load villages with minus prod
    $starvarray = array();
    $starvarray = $database->getStarvation();
    foreach ($starvarray as $starv){
    $unitarrays = $this->getAllUnits($starv['wref']);
    $upkeep = $starv['pop'] + $this->getUpkeep($unitarrays, 0);
        if (($starv['starvupdate']+600) < $time){
            // get enforce
            $enforcearray = $database->getEnforceVillage($starv['wref'],0);
            $maxcount = 0;
            if(count($enforcearray)==0){
                // get units
                $unitarray = $database->getUnit($starv['wref']);
                for($i = 0 ; $i <= 50 ; $i++){
                    $units = $unitarray['u'.$i];
                    if($unitarray['u'.$i] > $maxcount){
                        $maxcount = $unitarray['u'.$i];
                        $maxtype = $i;
                    }
                    $totalunits += $unitarray['u'.$i];
                }
                if($totalunits == 0){
                $maxcount = $unitarray['hero'];
                $maxtype = "hero";
                }
            }else{
                foreach ($enforcearray as $enforce){
                    for($i = 0 ; $i <= 50 ; $i++){
                        $units = $enforce['u'.$i];
                        if($enforce['u'.$i] > $maxcount){
                            $maxcount = $enforce['u'.$i];
                            $maxtype = $i;
                            $enf = $enforce['id'];
                        }
                        $totalunits += $enforce['u'.$i];
                        }
                if($totalunits == 0){
                $maxcount = $enforce['hero'];
                $maxtype = "hero";
                }
                }
                }

            // counting

            $timedif = $time-$starv['starvupdate'];

            $starvsec = ($starv['starv']/3600);

            $difcrop = ($timedif*$starvsec);
            $newcrop = 0;
            $oldcrop = $database->getVillageField($starv['wref'], 'crop');
            if ($oldcrop > 100){
                $difcrop = $difcrop-$oldcrop;
                if($difcrop < 0){
                    $difcrop = 0;
                    $newcrop = $oldcrop-$difcrop;
                    $database->setVillageField($starv['wref'], 'crop', $newcrop);
                }
            }
            if($difcrop > 0){
                $killunits = floor($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'], 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'], array($maxtype), array($killunits), array(0));
                        $database->setVillageField($starv['wref'], 'starv', $upkeep);
                        $database->setVillageField($starv['wref'], 'starvupdate', $time);
                    }
                }
                }
            }
        }
            $crop = $database->getCropProdstarv($starv['wref']);
            if ($crop > $upkeep){
                $database->setVillageField($starv['wref'], 'starv', 0);
                $database->setVillageField($starv['wref'], 'starvupdate', 0);
            }

        unset ($starv,$unitarrays,$enforcearray,$enforce,$starvarray);
    }

    if(file_exists("GameEngine/Prevention/starvation.txt")) {
        unlink("GameEngine/Prevention/starvation.txt");
    }
}

Also in here we have a problem in my village my crop production is Crop: -419664 per hour so i look in Templates/Build/upgrade.tpl , we have in line 80 a code that say if not ehought resource will tell us when we can build and an else with this on line 85 : echo "<span class=\"none\">Your crop production is negative, you will never get the required resources.";

If my production is negative and i don`t have ehought resource in granary i must view : Your crop production is negative, you will never get the required resources. , but i view Enough resources today at 12:28:25 with 3 secounds before clicking my time when i press that is 12:28:27 and i cannot build , must fix this error