General fixes

+Fixed an exploit that permitted to starts other players' farm lists
+Fixed an exploit that permitted to save our raids to other players'
farm lists
+Fixed an exploit that permitted to edit other players' farm lists
+Fixed a rounding upkeep bug
+Moved the whole startRaid.tpl to a new method in Units.php
+A lot of clean-up
+Improoved indentation
+In the raid list, the "carry" image will now show to the left of an
attack
+Fixed a bug that displayed the wrong loot to returning troops released
by traps
+General minor bug fixing and improovements
-Deleted a lot of redundant code
This commit is contained in:
iopietro
2018-05-04 22:12:18 +02:00
parent 49bc3c5073
commit cf74514451
17 changed files with 762 additions and 1274 deletions
+145 -363
View File
@@ -18,17 +18,21 @@
class Automation {
private $bountyresarray = array();
private $bountyinfoarray = array();
private $bountyproduction = array();
private $bountyocounter = array();
private $bountyunitall = array();
private $bountyresarray = [];
private $bountyinfoarray = [];
private $bountyproduction = [];
private $bountyocounter = [];
private $bountyunitall = [];
private $bountypop;
private $bountyOresarray = array();
private $bountyOinfoarray = array();
private $bountyOproduction = array();
private $bountyOresarray = [];
private $bountyOinfoarray = [];
private $bountyOproduction = [];
private $bountyOpop = 1;
const bountyOWoodProd = 40 * SPEED;
const bountyOClayProd = 40 * SPEED;
const bountyOIronProd = 40 * SPEED;
const bountyOCropProd = 40 * SPEED;
public function __construct() {
$this->procNewClimbers();
@@ -38,55 +42,54 @@ class Automation {
$this->pruneResource();
$this->pruneOResource();
$this->checkWWAttacks();
if(!file_exists("GameEngine/Prevention/culturepoints.txt") or time()-filemtime("GameEngine/Prevention/culturepoints.txt")>50) {
if(!file_exists("GameEngine/Prevention/culturepoints.txt") or time() - filemtime("GameEngine/Prevention/culturepoints.txt") > 50) {
$this->culturePoints();
}
if(!file_exists("GameEngine/Prevention/updatehero.txt") or time()-filemtime("GameEngine/Prevention/updatehero.txt")>50) {
if(!file_exists("GameEngine/Prevention/updatehero.txt") or time() - filemtime("GameEngine/Prevention/updatehero.txt") > 50) {
$this->updateHero();
}
if(!file_exists("GameEngine/Prevention/cleardeleting.txt") or time()-filemtime("GameEngine/Prevention/cleardeleting.txt")>50) {
if(!file_exists("GameEngine/Prevention/cleardeleting.txt") or time() - filemtime("GameEngine/Prevention/cleardeleting.txt") > 50) {
$this->clearDeleting();
}
if(!file_exists("GameEngine/Prevention/build.txt") or time() - filemtime("GameEngine/Prevention/build.txt")>50)
if(!file_exists("GameEngine/Prevention/build.txt") or time() - filemtime("GameEngine/Prevention/build.txt") > 50)
{
$this->buildComplete();
}
$this->MasterBuilder();
if(!file_exists("GameEngine/Prevention/demolition.txt") or time() - filemtime("GameEngine/Prevention/demolition.txt")>50)
if(!file_exists("GameEngine/Prevention/demolition.txt") or time() - filemtime("GameEngine/Prevention/demolition.txt") > 50)
{
$this->demolitionComplete();
}
$this->delTradeRoute();
$this->TradeRoute();
if(!file_exists("GameEngine/Prevention/market.txt") or time()-filemtime("GameEngine/Prevention/market.txt")>50) {
if(!file_exists("GameEngine/Prevention/market.txt") or time() - filemtime("GameEngine/Prevention/market.txt") > 50) {
$this->marketComplete();
}
if(!file_exists("GameEngine/Prevention/research.txt") or time()-filemtime("GameEngine/Prevention/research.txt")>50) {
if(!file_exists("GameEngine/Prevention/research.txt") or time() - filemtime("GameEngine/Prevention/research.txt") > 50) {
$this->researchComplete();
}
if(!file_exists("GameEngine/Prevention/training.txt") or time()-filemtime("GameEngine/Prevention/training.txt")>50) {
if(!file_exists("GameEngine/Prevention/training.txt") or time() - filemtime("GameEngine/Prevention/training.txt") > 50) {
$this->trainingComplete();
}
if(!file_exists("GameEngine/Prevention/starvation.txt") or time()-filemtime("GameEngine/Prevention/starvation.txt")>50) {
if(!file_exists("GameEngine/Prevention/starvation.txt") or time() - filemtime("GameEngine/Prevention/starvation.txt") > 50) {
$this->starvation();
}
if(!file_exists("GameEngine/Prevention/celebration.txt") or time()-filemtime("GameEngine/Prevention/celebration.txt")>50) {
if(!file_exists("GameEngine/Prevention/celebration.txt") or time() - filemtime("GameEngine/Prevention/celebration.txt") > 50) {
$this->celebrationComplete();
}
if(!file_exists("GameEngine/Prevention/sendunits.txt") or time()-filemtime("GameEngine/Prevention/sendunits.txt")>50) {
if(!file_exists("GameEngine/Prevention/sendunits.txt") or time() - filemtime("GameEngine/Prevention/sendunits.txt") > 50) {
$this->sendunitsComplete();
}
if(!file_exists("GameEngine/Prevention/loyalty.txt") or time()-filemtime("GameEngine/Prevention/loyalty.txt")>60) {
if(!file_exists("GameEngine/Prevention/loyalty.txt") or time() - filemtime("GameEngine/Prevention/loyalty.txt") > 60) {
$this->loyaltyRegeneration();
}
if(!file_exists("GameEngine/Prevention/sendreinfunits.txt") or time()-filemtime("GameEngine/Prevention/sendreinfunits.txt")>50) {
if(!file_exists("GameEngine/Prevention/sendreinfunits.txt") or time() - filemtime("GameEngine/Prevention/sendreinfunits.txt") > 50) {
$this->sendreinfunitsComplete();
}
if(!file_exists("GameEngine/Prevention/returnunits.txt") or time()-filemtime("GameEngine/Prevention/returnunits.txt")>50) {
if(!file_exists("GameEngine/Prevention/returnunits.txt") or time() - filemtime("GameEngine/Prevention/returnunits.txt") > 50) {
$this->returnunitsComplete();
}
if(!file_exists("GameEngine/Prevention/settlers.txt") or time()-filemtime("GameEngine/Prevention/settlers.txt")>50) {
if(!file_exists("GameEngine/Prevention/settlers.txt") or time() - filemtime("GameEngine/Prevention/settlers.txt") > 50) {
$this->sendSettlersComplete();
}
if(!file_exists("GameEngine/Prevention/artifacts.txt") or time() - filemtime("GameEngine/Prevention/artifacts.txt") > 60) {
@@ -261,7 +264,7 @@ class Automation {
$element = count($keyholder);
if($element >= 2) {
if($tid <= 4) {
$temparray = array();
$temparray = [];
for($i = 0; $i <= $element - 1; $i++) {
array_push($temparray,$resourcearray['f'.$keyholder[$i]]);
}
@@ -349,24 +352,28 @@ class Automation {
private function ClearUser() {
global $database;
if(AUTO_DEL_INACTIVE) {
$time = time()-UN_ACT_TIME;
$time = time() - UN_ACT_TIME;
$q = "INSERT INTO ".TB_PREFIX."deleting SELECT id, UNIX_TIMESTAMP() FROM ".TB_PREFIX."users WHERE timestamp < $time AND tribe IN(1,2,3)";
$q = "INSERT INTO ".TB_PREFIX."deleting SELECT id, UNIX_TIMESTAMP() FROM ".TB_PREFIX."users WHERE timestamp < $time AND tribe IN(1, 2, 3)";
$database->query($q);
}
}
private function ClearInactive() {
global $database;
if(TRACK_USR) {
$timeout = time()-USER_TIMEOUT*60;
$timeout = time()-USER_TIMEOUT * 60;
$q = "DELETE FROM ".TB_PREFIX."active WHERE timestamp < $timeout";
$database->query($q);
}
}
private function pruneOResource() {
global $database;
if(!ALLOW_BURST) {
$database->query("UPDATE
".TB_PREFIX."odata
@@ -388,6 +395,7 @@ class Automation {
}
private function pruneResource() {
global $database;
if(!ALLOW_BURST) {
$database->query("UPDATE
".TB_PREFIX."vdata
@@ -491,13 +499,9 @@ class Automation {
$fieldDbName = (in_array($indi['type'], [10, 38]) ? 'maxstore' : 'maxcrop');
$max = $villageData[$fieldDbName];
if($level == 1 && $max == STORAGE_BASE) {
$max=STORAGE_BASE;
}
if ($level != 1) {
$max -= ${'bid'.$indi['type']}[$level-1]['attri'] * STORAGE_MULTIPLIER;
}
if($level == 1 && $max == STORAGE_BASE) $max = STORAGE_BASE;
if ($level != 1) $max -= ${'bid'.$indi['type']}[$level-1]['attri'] * STORAGE_MULTIPLIER;
$max += ${'bid'.$indi['type']}[$level]['attri'] * STORAGE_MULTIPLIER;
@@ -583,141 +587,42 @@ class Automation {
// bad, but should work :D
// I took the data from my first ww (first .org world)
// todo: get the algo from the real travian with the 100 biggest
// offs and so on
$troops = array(
5 => array(
array(3412, 2814, 4156, 3553, 9, 0),
array(35, 0, 77, 33, 17, 10)
),
// TODO: get the algo from the real travian with the 100 biggest offs
10 => array(
array(4314, 3688, 5265, 4621, 13, 0),
array(65, 0, 175, 77, 28, 17)
),
15 => array(
array(4645, 4267, 5659, 5272, 15, 0),
array(99, 0, 305, 134, 40, 25)
),
20 => array(
array(6207, 5881, 7625, 7225, 22, 0),
array(144, 0, 456, 201, 56, 36)
),
25 => array(
array(6004, 5977, 7400, 7277, 23, 0),
array(152, 0, 499, 220, 58, 37)
),
30 => array(
array(7073, 7181, 8730, 8713, 27, 0),
array(183, 0, 607, 268, 69, 45)
),
35 => array(
array(7090, 7320, 8762, 8856, 28, 0),
array(186, 0, 620, 278, 70, 45)
),
40 => array(
array(7852, 6967, 9606, 8667, 25, 0),
array(146, 0, 431, 190, 60, 37)
),
45 => array(
array(8480, 8883, 10490, 10719, 35, 0),
array(223, 0, 750, 331, 83, 54)
),
50 => array(
array(8522, 9038, 10551, 10883, 35, 0),
array(224, 0, 757, 335, 83, 54)
),
55 => array(
array(8931, 8690, 10992, 10624, 32, 0),
array(219, 0, 707, 312, 84, 54)
),
60 => array(
array(12138, 13013, 15040, 15642, 51, 0),
array(318, 0, 1079, 477, 118, 76)
),
65 => array(
array(13397, 14619, 16622, 17521, 58, 0),
array(345, 0, 1182, 522, 127, 83)
),
70 => array(
array(16323, 17665, 20240, 21201, 70, 0),
array(424, 0, 1447, 640, 157, 102)
),
75 => array(
array(20739, 22796, 25746, 27288, 91, 0),
array(529, 0, 1816, 803, 194, 127)
),
80 => array(
array(21857, 24180, 27147, 28914, 97, 0),
array(551, 0, 1898, 839, 202, 132)
),
85 => array(
array(22476, 25007, 27928, 29876, 100, 0),
array(560, 0, 1933, 855, 205, 134)
),
90 => array(
array(31345, 35053, 38963, 41843, 141, 0),
array(771, 0, 2668, 1180, 281, 184)
),
95 => array(
array(31720, 35635, 39443, 42506, 144, 0),
array(771, 0, 2671, 1181, 281, 184)
),
96 => array(
array(32885, 37007, 40897, 44130, 150, 0),
array(795, 0, 2757, 1219, 289, 190)
),
97 => array(
array(32940, 37099, 40968, 44235, 150, 0),
array(794, 0, 2755, 1219, 289, 190)
),
98 => array(
array(33521, 37691, 41686, 44953, 152, 0),
array(812, 0, 2816, 1246, 296, 194)
),
99 => array(
array(36251, 40861, 45089, 48714, 165, 0),
array(872, 0, 3025, 1338, 317, 208)
)
);
$troops = [5 => [[3412, 2814, 4156, 3553, 9, 0], [35, 0, 77, 33, 17, 10]],
10 => [[4314, 3688, 5265, 4621, 13, 0], [65, 0, 175, 77, 28, 17]],
15 => [[4645, 4267, 5659, 5272, 15, 0], [99, 0, 305, 134, 40, 25]],
20 => [[6207, 5881, 7625, 7225, 22, 0], [144, 0, 456, 201, 56, 36]],
25 => [[6004, 5977, 7400, 7277, 23, 0], [152, 0, 499, 220, 58, 37]],
30 => [[7073, 7181, 8730, 8713, 27, 0], [183, 0, 607, 268, 69, 45]],
35 => [[7090, 7320, 8762, 8856, 28, 0], [186, 0, 620, 278, 70, 45]],
40 => [[7852, 6967, 9606, 8667, 25, 0], [146, 0, 431, 190, 60, 37]],
45 => [[8480, 8883, 10490, 10719, 35, 0], [223, 0, 750, 331, 83, 54]],
50 => [[8522, 9038, 10551, 10883, 35, 0], [224, 0, 757, 335, 83, 54]],
55 => [[8931, 8690, 10992, 10624, 32, 0], [219, 0, 707, 312, 84, 54]],
60 => [[12138, 13013, 15040, 15642, 51, 0], [318, 0, 1079, 477, 118, 76]],
65 => [[13397, 14619, 16622, 17521, 58, 0], [345, 0, 1182, 522, 127, 83]],
70 => [[16323, 17665, 20240, 21201, 70, 0], [424, 0, 1447, 640, 157, 102]],
75 => [[20739, 22796, 25746, 27288, 91, 0], [529, 0, 1816, 803, 194, 127]],
80 => [[21857, 24180, 27147, 28914, 97, 0], [551, 0, 1898, 839, 202, 132]],
85 => [[22476, 25007, 27928, 29876, 100, 0], [560, 0, 1933, 855, 205, 134]],
90 => [[31345, 35053, 38963, 41843, 141, 0], [771, 0, 2668, 1180, 281, 184]],
95 => [[31720, 35635, 39443, 42506, 144, 0], [771, 0, 2671, 1181, 281, 184]],
96 => [[32885, 37007, 40897, 44130, 150, 0], [795, 0, 2757, 1219, 289, 190]],
97 => [[32940, 37099, 40968, 44235, 150, 0], [794, 0, 2755, 1219, 289, 190]],
98 => [[33521, 37691, 41686, 44953, 152, 0], [812, 0, 2816, 1246, 296, 194]],
99 => [[36251, 40861, 45089, 48714, 165, 0], [872, 0, 3025, 1338, 317, 208]]];
// select the troops^^
if (isset($troops[$level]))
{
$units = $troops[$level];
}
else
{
return false;
}
if (isset($troops[$level])) $units = $troops[$level];
else return false;
// get the capital village from the natars
$query = mysqli_query($database->dblink,'SELECT `wref` FROM `' . TB_PREFIX . 'vdata` WHERE `owner` = 3 and `capital` = 1 LIMIT 1') or die(mysqli_error($database->dblink));
$row = mysqli_fetch_assoc($query);
// start the attacks
$endtime = $time + round((60 * 60 * 24) / INCREASE_SPEED);
$endtime = $time + round(86400 / INCREASE_SPEED);
// -.-
$vid = (int) $vid;
@@ -729,7 +634,7 @@ class Automation {
$database->addMovement(3, $row['wref'], $vid, $ref, $time, $endtime);
// wave 2
$ref2 = $database->addAttack($row['wref'], 0, $units[1][0], $units[1][1], 0, $units[1][2], $units[1][3], $units[1][4], $units[1][5], 0, 0, 0, 3, 40, 0, 0, 0, 20, 20, 0, 20, 20, 20, 20, array('vid' => $vid, 'endtime' => ($endtime + 1)));
$ref2 = $database->addAttack($row['wref'], 0, $units[1][0], $units[1][1], 0, $units[1][2], $units[1][3], $units[1][4], $units[1][5], 0, 0, 0, 3, 40, 0, 0, 0, 20, 20, 0, 20, 20, 20, 20, ['vid' => $vid, 'endtime' => ($endtime + 1)]);
$database->addMovement(3, $row['wref'], $vid, $ref2, $time, $endtime + 1);
}
@@ -744,20 +649,20 @@ class Automation {
}
}
private function getPop($tid,$level) {
private function getPop($tid, $level) {
$name = "bid".$tid;
global $$name,$village;
global $$name;
$dataarray = $$name;
$pop = $dataarray[($level+1)]['pop'];
$cp = $dataarray[($level+1)]['cp'];
return array($pop,$cp);
$pop = $dataarray[($level + 1)]['pop'];
$cp = $dataarray[($level + 1)]['cp'];
return [$pop, $cp];
}
private function delTradeRoute() {
global $database;
$time = time();
$q = "DELETE from ".TB_PREFIX."route where timeleft < $time";
$database->query($q);
$database->delTradeRoute();
}
private function TradeRoute() {
@@ -868,17 +773,17 @@ class Automation {
$maxcarry2 *= $bid28[$this->getTypeLevel(28, $from)]['attri'] / 100;
}
$resource = array($wtrans,$ctrans,$itrans,$crtrans);
$reqMerc = ceil((array_sum($resource)-0.1)/$maxcarry2);
$resource = [$wtrans, $ctrans, $itrans, $crtrans];
$reqMerc = ceil((array_sum($resource) - 0.1) / $maxcarry2);
if($merchantAvail2 != 0 && $reqMerc <= $merchantAvail2) {
if($merchantAvail2 > 0 && $reqMerc <= $merchantAvail2) {
if($database->getVillageState($to)) {
$timetaken = $units->getWalkingTroopsTime($from, $to, 0, 0, [$tribe], 0);
$res = $resource[0]+$resource[1]+$resource[2]+$resource[3];
if($res!=0){
$reference = $database->sendResource($resource[0],$resource[1],$resource[2],$resource[3],$reqMerc,0);
$database->modifyResource($from,$resource[0],$resource[1],$resource[2],$resource[3],0);
$database->addMovement(0,$from,$to,$reference,microtime(true),microtime(true)+$timetaken,$send);
$res = $resource[0] + $resource[1] + $resource[2] + $resource[3];
if($res > 0){
$reference = $database->sendResource($resource[0], $resource[1], $resource[2], $resource[3], $reqMerc, 0);
$database->modifyResource($from, $resource[0], $resource[1], $resource[2], $resource[3], 0);
$database->addMovement(0, $from, $to, $reference, microtime(true), microtime(true) + $timetaken, $send);
}
}
}
@@ -931,11 +836,9 @@ class Automation {
}
// oasis cannot be destroyed
$pop=$this->recountPop($data['to'], false);
$pop = $this->recountPop($data['to'], false);
if ($isoasis == 0) {
if($pop==0 && $can_destroy==1){
$village_destroyed = 1;
}
if($pop == 0 && $can_destroy == 1) $village_destroyed = 1;
}
if ($isSecondRow) {
@@ -1000,9 +903,7 @@ class Automation {
// recalculate population and check if the village shouldn't be destroyed at this point
$pop = $this->recountPop($data['to'], false);
if ($isoasis == 0) {
if($pop==0 && $can_destroy==1) {
$village_destroyed = 1;
}
if($pop == 0 && $can_destroy == 1) $village_destroyed = 1;
}
if ($isSecondRow) {
@@ -1063,8 +964,7 @@ class Automation {
endtime < $time
ORDER BY endtime ASC";
$dataarray = $database->query_return($q);
$totalattackdead = 0;
$data_num = 0;
$totalattackdead = $data_num = 0;
if ($dataarray && count($dataarray)) {
// preload village data
@@ -1108,7 +1008,7 @@ class Automation {
$NatarCapital= ($toF['owner'] == 3 && $toF['capital']==1);
if(!isset($to['name']) || $to['name']=='') $to['name']="??";
$DefenderUnit = array();
$DefenderUnit = [];
$DefenderUnit = $database->getUnit($data['to']);
$evasion = $toF["evasion"];
$maxevasion = $DefenderUserData["maxevasion"];
@@ -1159,7 +1059,7 @@ class Automation {
$database->modifyUnit($data['to'], $evasionUnitModifications_units, $evasionUnitModifications_amounts, $evasionUnitModifications_modes);
}
//get defence units
$enforDefender = array();
$enforDefender = [];
$rom = $ger = $gal = $nat = $natar = 0;
$Defender = $database->getUnit($data['to'], false);
$enforcementarray = $database->getEnforceVillage($data['to'], 0);
@@ -1192,22 +1092,22 @@ class Automation {
}
//get attack units
$Attacker = array();
$start = ($owntribe-1)*10+1;
$end = ($owntribe*10);
$u = (($owntribe-1)*10);
$catapult = array(8,18,28,48);
$ram = array(7,17,27,47);
$chief = array(9,19,29,49);
$spys = array(4,14,23,44);
$Attacker = [];
$start = ($owntribe - 1) * 10 + 1;
$end = $owntribe * 10;
$u = ($owntribe - 1) * 10;
$catapult = [8, 18, 28, 48];
$ram = [7, 17, 27, 47];
$chief = [9, 19, 29, 49];
$spys = [4, 14, 23, 44];
for($i = $start; $i <= $end; $i++) {
$y = $i - $u;
$Attacker['u'.$i] = $dataarray[$data_num]['t'.$y];
//there are catas
if(in_array($i,$catapult)) $catp_pic = $i;
if(in_array($i,$ram)) $ram_pic = $i;
if(in_array($i,$chief)) $chief_pic = $i;
if(in_array($i,$spys)) $spy_pic = $i;
if(in_array($i, $catapult)) $catp_pic = $i;
if(in_array($i, $ram)) $ram_pic = $i;
if(in_array($i, $chief)) $chief_pic = $i;
if(in_array($i, $spys)) $spy_pic = $i;
}
$Attacker['uhero'] = $dataarray[$data_num]['t11'];
$hero_pic = "hero";
@@ -1298,30 +1198,22 @@ class Automation {
}
//get attack units
$Attacker = array();
$start = ($owntribe-1)*10+1;
$end = ($owntribe*10);
$u = (($owntribe-1)*10);
$catapult = array(8,18,28,38,48);
$ram = array(7,17,27,37,47);
$chief = array(9,19,29,39,49);
$spys = array(4,14,23,44);
for($i=$start;$i<=$end;$i++) {
$y = $i-$u;
$Attacker = [];
$start = ($owntribe - 1) * 10 + 1;
$end = $owntribe * 10;
$u = ($owntribe - 1) * 10;
$catapult = [8, 18, 28, 38, 48];
$ram = [7, 17, 27, 37, 47];
$chief = [9, 19, 29, 39, 49];
$spys = [4, 14, 23, 44];
for($i = $start; $i <= $end; $i++) {
$y = $i - $u;
$Attacker['u'.$i] = $dataarray[$data_num]['t'.$y];
//there are catas
if(in_array($i,$catapult)) {
$catp_pic = $i;
}
if(in_array($i,$ram)) {
$ram_pic = $i;
}
if(in_array($i,$chief)) {
$chief_pic = $i;
}
if(in_array($i,$spys)) {
$spy_pic = $i;
}
if(in_array($i, $catapult)) $catp_pic = $i;
if(in_array($i, $ram)) $ram_pic = $i;
if(in_array($i, $chief)) $chief_pic = $i;
if(in_array($i, $spys)) $spy_pic = $i;
}
$Attacker['uhero'] = $dataarray[$data_num]['t11'];
$hero_pic = "hero";
@@ -1993,8 +1885,8 @@ class Automation {
// we're manually targetting 1st and/or 2nd row of catapults
if (!$catapults1TargetRandom)
{
$_catapultsTarget1Levels=array();
$__catapultsTarget1AltTargets=array();
$_catapultsTarget1Levels = [];
$__catapultsTarget1AltTargets = [];
// calculate targets for 1st rows of catapults
$j = 0;
@@ -2030,7 +1922,7 @@ class Automation {
// 1st row of catapults set to target randomly
if ($catapults1TargetRandom)
{
$list=array();
$list = [];
for ($i = 1; $i <= 41; $i++)
{
if ($i == 41) $i = 99;
@@ -2052,8 +1944,8 @@ class Automation {
// we're manually targetting 2nd row of catapults
if (!$catapults2TargetRandom)
{
$_catapultsTarget2Levels=array();
$__catapultsTarget2AltTargets=array();
$_catapultsTarget2Levels = [];
$__catapultsTarget2AltTargets = [];
// calculate targets for 2nd rows of catapults
$j = 0;
@@ -3065,12 +2957,12 @@ class Automation {
if (!isset($wavesData[$data['from'].$data['to'].$data['starttime'].$data['endtime']])) {
$tribe = $database->getUserField($database->getVillageField($data['to'],"owner"),"tribe",0);
if($tribe == 1){ $u = ""; } elseif($tribe == 2){ $u = "1"; } elseif($tribe == 3){ $u = "2"; } elseif($tribe == 4){ $u = "3"; } else{ $u = "4"; }
$u = $tribe == 1 ? "" : $tribe - 1;
$database->modifyUnit(
$data['to'],
array($u."1",$u."2",$u."3",$u."4",$u."5",$u."6",$u."7",$u."8",$u."9",$tribe."0","hero"),
array($data['t1'],$data['t2'],$data['t3'],$data['t4'],$data['t5'],$data['t6'],$data['t7'],$data['t8'],$data['t9'],$data['t10'],$data['t11']),
array(1,1,1,1,1,1,1,1,1,1,1)
[$u."1", $u."2", $u."3", $u."4", $u."5", $u."6", $u."7", $u."8", $u."9", $tribe."0", "hero"],
[$data['t1'], $data['t2'], $data['t3'], $data['t4'], $data['t5'], $data['t6'], $data['t7'], $data['t8'], $data['t9'], $data['t10'], $data['t11']],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
);
$movementProcIDs[] = $data['moveid'];
@@ -3080,12 +2972,9 @@ class Automation {
// make sure we don't process duplicate movements until the big bad bug which inserts them into DB is fixed
$wavesData[$data['from'].$data['to'].$data['starttime'].$data['endtime']] = true;
} else {
// duplicate record, just mark it as processed
$movementProcIDs[] = $data['moveid'];
}
} // duplicate record, just mark it as processed
else $movementProcIDs[] = $data['moveid'];
}
$database->setMovementProc(implode(', ', $movementProcIDs));
}
@@ -3098,10 +2987,10 @@ class Automation {
foreach($dataarray as $data) {
if($data['wood'] >= $data['clay'] && $data['wood'] >= $data['iron'] && $data['wood'] >= $data['crop']){ $sort_type = "10"; }
elseif($data['clay'] >= $data['wood'] && $data['clay'] >= $data['iron'] && $data['clay'] >= $data['crop']){ $sort_type = "11"; }
elseif($data['iron'] >= $data['wood'] && $data['iron'] >= $data['clay'] && $data['iron'] >= $data['crop']){ $sort_type = "12"; }
elseif($data['crop'] >= $data['wood'] && $data['crop'] >= $data['clay'] && $data['crop'] >= $data['iron']){ $sort_type = "13"; }
if($data['wood'] >= $data['clay'] && $data['wood'] >= $data['iron'] && $data['wood'] >= $data['crop']) $sort_type = 10;
elseif($data['clay'] >= $data['wood'] && $data['clay'] >= $data['iron'] && $data['clay'] >= $data['crop']) $sort_type = 11;
elseif($data['iron'] >= $data['wood'] && $data['iron'] >= $data['clay'] && $data['iron'] >= $data['crop']) $sort_type = 12;
elseif($data['crop'] >= $data['wood'] && $data['crop'] >= $data['clay'] && $data['crop'] >= $data['iron']) $sort_type = 13;
$to = $database->getMInfo($data['to']);
$from = $database->getMInfo($data['from']);
@@ -3117,7 +3006,6 @@ class Automation {
$this->pruneResource();
// Settlers
$q = "SELECT `to`, moveid FROM ".TB_PREFIX."movement where ref = 0 and proc = '0' and sort_type = '4' and endtime < $time";
$dataarray = $database->query_return($q);
@@ -3129,7 +3017,6 @@ class Automation {
$database->modifyUnit($data['to'],array($tribe."0"),array(3),array(1));
$movementProcIDs[] = $data['moveid'];
}
$database->setMovementProc(implode(', ', $movementProcIDs));
}
@@ -3487,108 +3374,17 @@ class Automation {
return $ownunit;
}
public function getUpkeep($array,$type,$vid=0,$prisoners=0) {
global $database, $session, $village;
if ( $vid == 0 ) {
$vid = $village->wid;
}
$buildarray = array();
if ( $vid != 0 ) {
$buildarray = $database->getResourceLevel( $vid );
}
$upkeep = 0;
switch ( $type ) {
case 0:
$start = 1;
$end = 50;
break;
case 1:
$start = 1;
$end = 10;
break;
case 2:
$start = 11;
$end = 20;
break;
case 3:
$start = 21;
$end = 30;
break;
case 4:
$start = 31;
$end = 40;
break;
case 5:
$start = 41;
$end = 50;
break;
}
for ( $i = $start; $i <= $end; $i ++ ) {
$k = $i - $start + 1;
$unit = "u" . $i;
$unit2 = "t" . $k;
global $$unit;
$dataarray = $$unit;
for ( $j = 19; $j <= 38; $j ++ ) {
if ( $buildarray[ 'f' . $j . 't' ] == 41 ) {
$horsedrinking = $j;
}
}
if ( $prisoners == 0 ) {
if ( isset( $horsedrinking ) ) {
if ( ( $i == 4 && $buildarray[ 'f' . $horsedrinking ] >= 10 )
|| ( $i == 5 && $buildarray[ 'f' . $horsedrinking ] >= 15 )
|| ( $i == 6 && $buildarray[ 'f' . $horsedrinking ] == 20 ) ) {
$upkeep += ( $dataarray['pop'] - 1 ) * $array[ $unit ];
} else {
$upkeep += $dataarray['pop'] * $array[ $unit ];
}
} else {
$upkeep += $dataarray['pop'] * $array[ $unit ];
}
} else {
if ( isset( $horsedrinking ) ) {
if ( ( $i == 4 && $buildarray[ 'f' . $horsedrinking ] >= 10 )
|| ( $i == 5 && $buildarray[ 'f' . $horsedrinking ] >= 15 )
|| ( $i == 6 && $buildarray[ 'f' . $horsedrinking ] == 20 ) ) {
$upkeep += ( $dataarray['pop'] - 1 ) * $array[ $unit2 ];
} else {
$upkeep += $dataarray['pop'] * $array[ $unit2 ];
}
} else {
$upkeep += $dataarray['pop'] * $array[ $unit2 ];
}
}
}
$unit = ($prisoners > 0) ? 't11' : 'hero';
if(!isset($array[$unit])) $array[$unit] = 0;
$upkeep += $array[$unit] * 6;
$who = $database->getVillageField($vid, "owner");
return $database->getArtifactsValueInfluence($who, $vid, 4, $upkeep);
}
private function bountycalculateOProduction($bountywid) {
$this->bountyOproduction['wood'] = $this->bountyGetOWoodProd();
$this->bountyOproduction['clay'] = $this->bountyGetOClayProd();
$this->bountyOproduction['iron'] = $this->bountyGetOIronProd();
$this->bountyOproduction['crop'] = $this->bountyGetOCropProd();
$this->bountyOproduction['wood'] = self::bountyOWoodProd;
$this->bountyOproduction['clay'] = self::bountyOClayProd;
$this->bountyOproduction['iron'] = self::bountyOIronProd;
$this->bountyOproduction['crop'] = self::bountyOCropProd;
}
private function bountycalculateProduction($bountywid, $uid) {
$upkeep = $this->getUpkeep($this->getAllUnits($bountywid), 0);
global $technology;
$upkeep = $technology->getUpkeep($this->getAllUnits($bountywid), 0, $bountywid);
$this->bountyproduction['wood'] = $this->bountyGetWoodProd();
$this->bountyproduction['clay'] = $this->bountyGetClayProd();
$this->bountyproduction['iron'] = $this->bountyGetIronProd();
@@ -3597,6 +3393,7 @@ class Automation {
private function bountyprocessProduction($bountywid) {
global $database;
$timepast = time() - $this->bountyinfoarray['lastupdate'];
$nwood = ($this->bountyproduction['wood'] / 3600) * $timepast;
$nclay = ($this->bountyproduction['clay'] / 3600) * $timepast;
@@ -3607,6 +3404,7 @@ class Automation {
}
private function bountyprocessOProduction($bountywid) {
global $database;
$timepast = time() - $this->bountyinfoarray['lastupdated'];
$nwood = ($this->bountyOproduction['wood'] / 3600) * $timepast;
$nclay = ($this->bountyOproduction['clay'] / 3600) * $timepast;
@@ -3616,22 +3414,6 @@ class Automation {
$database->updateOasis($bountywid);
}
private function bountyGetOWoodProd() {
return round(SPEED * 40);
}
private function bountyGetOClayProd() {
return round(SPEED * 40);
}
private function bountyGetOIronProd() {
return round(SPEED * 40);
}
private function bountyGetOCropProd() {
return round(SPEED * 40);
}
private function bountyGetWoodProd() {
global $bid1, $bid5;
@@ -3672,7 +3454,7 @@ class Automation {
global $bid3, $bid7;
$iron = $foundry = 0;
$ironholder = array();
$ironholder = [];
for($i = 1; $i <= 38; $i++) {
if($this->bountyresarray['f'.$i.'t'] == 3) array_push($ironholder,'f'.$i);
if($this->bountyresarray['f'.$i.'t'] == 7) $foundry = $this->bountyresarray['f'.$i];
@@ -4205,7 +3987,7 @@ class Automation {
*/
private function addStarvationData($wref){
global $database;
global $database, $technology;
$getVillage = $database->getVillage($wref);
@@ -4213,7 +3995,7 @@ class Automation {
if ($getVillage['owner'] > 5){
$crop = $database->getCropProdstarv($wref, false);
$unitArrays = $this->getAllUnits($wref, false);
$villageUpkeep = $getVillage['pop'] + $this->getUpkeep($unitArrays, 0);
$villageUpkeep = $getVillage['pop'] + $technology->getUpkeep($unitArrays, 0, $wref);
$starv = $getVillage['starv'];
if ($crop < $villageUpkeep){
@@ -4233,7 +4015,7 @@ class Automation {
//TODO: This function needs to be splitted in many subfunctions (for TravianZ refactor)
private function starvation() {
global $database, $autoprefix;
global $database, $technology, $autoprefix;
if(file_exists($autoprefix."GameEngine/Prevention/starvation.txt")) {
unlink($autoprefix."GameEngine/Prevention/starvation.txt");
@@ -4269,7 +4051,7 @@ class Automation {
{
$unitarrays = $this->getAllUnits($starv['wref']);
$upkeep = $starv['pop'] + $this->getUpkeep($unitarrays, 0, $starv['wref']);
$upkeep = $starv['pop'] + $technology->getUpkeep($unitarrays, 0, $starv['wref']);
$enforceArrays = $prisonerArrays = $unitArrays = $attackArrays = $allTroopsArray = $starvingTroops = $killedUnits = [];