mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-08-18 01:01:01 +00:00
General fixes
+Fixed a bug that would have killed all troops by starvation, if added through the admin panel
This commit is contained in:
+14
-64
@@ -12,6 +12,7 @@
|
|||||||
#################################################################################
|
#################################################################################
|
||||||
|
|
||||||
include_once("../../Account.php");
|
include_once("../../Account.php");
|
||||||
|
include_once("../../Technology.php");
|
||||||
|
|
||||||
if (!isset($_SESSION)) session_start();
|
if (!isset($_SESSION)) session_start();
|
||||||
if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
|
if($_SESSION['access'] < ADMIN) die("Access Denied: You are not Admin!");
|
||||||
@@ -29,80 +30,29 @@ foreach ($_POST as $key => $value) {
|
|||||||
$_POST[$key] = (int) $value;
|
$_POST[$key] = (int) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$u1 = $_POST['u1'];
|
for($i = 1; $i <= 50; $i++) ${"u".$i} = $_POST['u'.$i];
|
||||||
$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'];
|
|
||||||
|
|
||||||
if($user['tribe'] == 1){
|
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";
|
$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);
|
mysqli_query($GLOBALS["link"], $q);
|
||||||
} else if($user['tribe'] == 2){
|
} 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";
|
$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);
|
mysqli_query($GLOBALS["link"], $q);
|
||||||
} else if($user['tribe'] == 3){
|
} 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";
|
$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);
|
mysqli_query($GLOBALS["link"], $q);
|
||||||
} else if($user['tribe'] == 4){
|
} 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";
|
$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);
|
mysqli_query($GLOBALS["link"], $q);
|
||||||
} else if($user['tribe'] == 5){
|
} 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";
|
$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"], $q);
|
||||||
}
|
}
|
||||||
|
|
||||||
mysqli_query($GLOBALS["link"], "Insert into ".TB_PREFIX."admin_log values (0,".(int) $_SESSION['id'].",'Changed troop anmount in village <a href=\'admin.php?p=village&did=$id\'>$id</a> ',".time().")");
|
mysqli_query($GLOBALS["link"], "Insert into ".TB_PREFIX."admin_log values (0,".(int) $_SESSION['id'].",'Changed troop anmount in village <a href=\'admin.php?p=village&did=$id\'>$id</a> ',".time().")");
|
||||||
|
|
||||||
|
$database->addStarvationData($village['wref']);
|
||||||
|
|
||||||
header("Location: ../../../Admin/admin.php?p=addTroops&did=".$id."&d");
|
header("Location: ../../../Admin/admin.php?p=addTroops&did=".$id."&d");
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
## Copyright: TravianZ (c) 2010-2014. All rights reserved. ##
|
## 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);
|
if($_SESSION['access'] < 9) die(ACCESS_DENIED_ADMIN);
|
||||||
$id = $_GET['did'];
|
$id = $_GET['did'];
|
||||||
if(isset($id))
|
if(isset($id))
|
||||||
@@ -17,12 +17,8 @@ if(isset($id))
|
|||||||
$units = $database->getUnit($village['wref']);
|
$units = $database->getUnit($village['wref']);
|
||||||
$coor = $database->getCoor($village['wref']);
|
$coor = $database->getCoor($village['wref']);
|
||||||
$tribe = $user['tribe'];
|
$tribe = $user['tribe'];
|
||||||
if($tribe ==1){ $img = 0;}
|
$img = ($tribe - 1) * 10;
|
||||||
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;}
|
|
||||||
include("search2.tpl");
|
include("search2.tpl");
|
||||||
?>
|
?>
|
||||||
<form action="../GameEngine/Admin/Mods/addTroops.php" method="POST">
|
<form action="../GameEngine/Admin/Mods/addTroops.php" method="POST">
|
||||||
@@ -34,7 +30,7 @@ if(isset($id))
|
|||||||
<th colspan="2">Edit troops</th>
|
<th colspan="2">Edit troops</th>
|
||||||
</tr></thead><tbody>
|
</tr></thead><tbody>
|
||||||
<?php
|
<?php
|
||||||
for($i=1; $i<11; $i++) {
|
for($i = 1; $i < 11; $i++) {
|
||||||
echo '<tr>
|
echo '<tr>
|
||||||
<td class="addTroops"><img src="../img/un/u/'.($img+$i).'.gif"></img> '.$unarray[$img+$i].'</td>
|
<td class="addTroops"><img src="../img/un/u/'.($img+$i).'.gif"></img> '.$unarray[$img+$i].'</td>
|
||||||
<td class="addTroops"><input class="addTroops" name="u'.($img+$i).'" id="u'.($img+$i).'" value="'.$units["u".($img+$i)].'" maxlength="10">
|
<td class="addTroops"><input class="addTroops" name="u'.($img+$i).'" id="u'.($img+$i).'" value="'.$units["u".($img+$i)].'" maxlength="10">
|
||||||
|
|||||||
@@ -13,25 +13,23 @@
|
|||||||
if(!isset($_SESSION)) session_start();
|
if(!isset($_SESSION)) session_start();
|
||||||
if($_SESSION['access'] < 9) die(ACCESS_DENIED_ADMIN);
|
if($_SESSION['access'] < 9) die(ACCESS_DENIED_ADMIN);
|
||||||
include_once("../../Database.php");
|
include_once("../../Database.php");
|
||||||
|
include_once("../../Technology.php");
|
||||||
|
include_once("../../Data/unitdata.php");
|
||||||
|
|
||||||
$id = $_POST['id'];
|
$id = (int)$_POST['id'];
|
||||||
$village = $database->getVillage($id);
|
$village = $database->getVillage($id);
|
||||||
$user = $database->getUserArray($village['owner'],1);
|
$user = $database->getUserArray($village['owner'],1);
|
||||||
$units="";
|
$units = "";
|
||||||
$tribe = $user['tribe'];
|
$tribe = $user['tribe'];
|
||||||
if($tribe ==1){ $u = 0;}
|
$u = ($tribe - 1) * 10;
|
||||||
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;}
|
|
||||||
|
|
||||||
for($i=1; $i<11; $i++) {
|
for($i = 1; $i < 11; $i++) {
|
||||||
$units.="u".($u+$i)."=".$database->escape($_POST['u'.($u+$i)].(($i < 10) ? ", " : ""));
|
$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($q);
|
||||||
$database->query("Insert into ".TB_PREFIX."admin_log values (0,".(int) $_SESSION['id'].",'Changed troop amounts in village <a href=\'admin.php?p=village&did=$id\'>$id</a> ',".time().")");
|
$database->query("Insert into ".TB_PREFIX."admin_log values (0,".(int) $_SESSION['id'].",'Changed troop amounts in village <a href=\'admin.php?p=village&did=$id\'>$id</a> ',".time().")");
|
||||||
|
$database->addStarvationData($id);
|
||||||
header("Location: ../../../Admin/admin.php?p=village&did=".$id."&d");
|
header("Location: ../../../Admin/admin.php?p=village&did=".$id."&d");
|
||||||
?>
|
?>
|
||||||
Executable → Regular
+21
-47
@@ -383,7 +383,7 @@ class Automation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function buildComplete() {
|
private function buildComplete() {
|
||||||
global $database, $bid18, $bid10, $bid11, $bid38, $bid39;
|
global $database, $technology, $bid18, $bid10, $bid11, $bid38, $bid39;
|
||||||
|
|
||||||
$time = time();
|
$time = time();
|
||||||
// IDs of villages that were affected by this building completion update,
|
// IDs of villages that were affected by this building completion update,
|
||||||
@@ -476,7 +476,7 @@ class Automation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Update starvation data
|
//Update starvation data
|
||||||
$this->addStarvationData($indi['wid']);
|
$database->addStarvationData($indi['wid']);
|
||||||
|
|
||||||
// update the requested fields, all at once
|
// update the requested fields, all at once
|
||||||
$database->setVillageFields($indi['wid'], array_keys($fieldsToSet), array_values($fieldsToSet));
|
$database->setVillageFields($indi['wid'], array_keys($fieldsToSet), array_values($fieldsToSet));
|
||||||
@@ -2488,7 +2488,7 @@ class Automation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Update starvation data
|
//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
|
//Returning units back to village is not necessary because it will be taken care when processing movement
|
||||||
// Fix by AL-Kateb
|
// Fix by AL-Kateb
|
||||||
@@ -2579,7 +2579,7 @@ class Automation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function sendreinfunitsComplete() {
|
private function sendreinfunitsComplete() {
|
||||||
global $bid23, $database, $battle;
|
global $bid23, $database, $technology, $battle;
|
||||||
|
|
||||||
$time = time();
|
$time = time();
|
||||||
$q = "
|
$q = "
|
||||||
@@ -2717,7 +2717,7 @@ class Automation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Update starvation data
|
//Update starvation data
|
||||||
$this->addStarvationData($data['to']);
|
$database->addStarvationData($data['to']);
|
||||||
|
|
||||||
//check empty reinforcement in rally point
|
//check empty reinforcement in rally point
|
||||||
$e_units = '';
|
$e_units = '';
|
||||||
@@ -2733,7 +2733,7 @@ class Automation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function returnunitsComplete() {
|
private function returnunitsComplete() {
|
||||||
global $database;
|
global $database, $technology;
|
||||||
|
|
||||||
$time = time();
|
$time = time();
|
||||||
$q = "
|
$q = "
|
||||||
@@ -2783,7 +2783,7 @@ class Automation {
|
|||||||
$movementProcIDs[] = $data['moveid'];
|
$movementProcIDs[] = $data['moveid'];
|
||||||
|
|
||||||
//Update starvation data
|
//Update starvation data
|
||||||
$this->addStarvationData($data['to']);
|
$database->addStarvationData($data['to']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$database->setMovementProc(implode(', ', $movementProcIDs));
|
$database->setMovementProc(implode(', ', $movementProcIDs));
|
||||||
@@ -3233,7 +3233,7 @@ class Automation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function trainingComplete() {
|
private function trainingComplete() {
|
||||||
global $database;
|
global $database, $technology;
|
||||||
|
|
||||||
$time = time();
|
$time = time();
|
||||||
$trainlist = $database->getTrainingList();
|
$trainlist = $database->getTrainingList();
|
||||||
@@ -3287,7 +3287,7 @@ class Automation {
|
|||||||
if ($valuesUpdated) call_user_func(get_class($database).'::clearUnitsCache');
|
if ($valuesUpdated) call_user_func(get_class($database).'::clearUnitsCache');
|
||||||
|
|
||||||
//Update starvation data
|
//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
|
* Function for starvation - by brainiacX and Shadow
|
||||||
@@ -3712,23 +3688,23 @@ class Automation {
|
|||||||
private function starvation() {
|
private function starvation() {
|
||||||
global $database, $technology;
|
global $database, $technology;
|
||||||
|
|
||||||
//starvation is disabled during Easter/Holidays/Christmas
|
//Starvation is disabled during Easter/Holidays/Christmas
|
||||||
if(PEACE) return;
|
if(PEACE) return;
|
||||||
|
|
||||||
$time = time();
|
$time = time();
|
||||||
|
|
||||||
//update starvation in every village
|
//Update starvation in every village
|
||||||
$starvarray = $database->getProfileVillages(0, 7);
|
$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 = [];
|
||||||
$starvarray = $database->getStarvation();
|
$starvarray = $database->getStarvation();
|
||||||
|
|
||||||
$vilIDs = [];
|
$vilIDs = [];
|
||||||
foreach ($starvarray as $starv) $vilIDs[] = $starv['wref'];
|
foreach ($starvarray as $starv) $vilIDs[] = $starv['wref'];
|
||||||
|
|
||||||
// cache
|
//Cache
|
||||||
$database->getEnforceVillage($vilIDs, 0);
|
$database->getEnforceVillage($vilIDs, 0);
|
||||||
$database->getOasisEnforce($vilIDs, 2);
|
$database->getOasisEnforce($vilIDs, 2);
|
||||||
$database->getOasisEnforce($vilIDs, 3);
|
$database->getOasisEnforce($vilIDs, 3);
|
||||||
@@ -3758,7 +3734,7 @@ class Automation {
|
|||||||
|
|
||||||
$allTroopsArray = [$enforceArrays, $prisonerArrays, $unitArrays, $attackArrays];
|
$allTroopsArray = [$enforceArrays, $prisonerArrays, $unitArrays, $attackArrays];
|
||||||
|
|
||||||
// find the first not-empty array
|
//Find the first not-empty array
|
||||||
foreach($allTroopsArray as $type => $allTroops)
|
foreach($allTroopsArray as $type => $allTroops)
|
||||||
{
|
{
|
||||||
if(!empty($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;
|
if(empty($starvingTroops)) continue;
|
||||||
|
|
||||||
// counting
|
//Counting
|
||||||
$timedif = $time - $starv['starvupdate'];
|
$timedif = $time - $starv['starvupdate'];
|
||||||
$cropProd = $database->getCropProdstarv($starv['wref']) - $starv['starv'];
|
$cropProd = $database->getCropProdstarv($starv['wref']) - $starv['starv'];
|
||||||
if($cropProd < 0){
|
if($cropProd < 0){
|
||||||
@@ -3783,7 +3759,7 @@ class Automation {
|
|||||||
$newcrop = 0;
|
$newcrop = 0;
|
||||||
$oldcrop = $database->getVillageField($starv['wref'], 'crop');
|
$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){
|
if ($oldcrop > 100){
|
||||||
$difcrop = $difcrop - $oldcrop;
|
$difcrop = $difcrop - $oldcrop;
|
||||||
if($difcrop < 0){
|
if($difcrop < 0){
|
||||||
@@ -3804,7 +3780,7 @@ class Automation {
|
|||||||
$counting = true;
|
$counting = true;
|
||||||
while($difcrop > 0)
|
while($difcrop > 0)
|
||||||
{
|
{
|
||||||
// search the highest troop
|
//S earch the highest troop
|
||||||
$maxcount = $maxtype = 0;
|
$maxcount = $maxtype = 0;
|
||||||
for($i = $start ; $i <= $end ; $i++)
|
for($i = $start ; $i <= $end ; $i++)
|
||||||
{
|
{
|
||||||
@@ -3837,10 +3813,8 @@ class Automation {
|
|||||||
else if($maxtype == 0) $newCrop = 0;
|
else if($maxtype == 0) $newCrop = 0;
|
||||||
else $newCrop = $GLOBALS['u'.$maxtype]['crop'];
|
else $newCrop = $GLOBALS['u'.$maxtype]['crop'];
|
||||||
|
|
||||||
if($totalKilledUnits > 0)
|
if($totalKilledUnits > 0){
|
||||||
{
|
switch($type){
|
||||||
switch($type)
|
|
||||||
{
|
|
||||||
case 0:
|
case 0:
|
||||||
if($totalKilledUnits < $totalUnits){
|
if($totalKilledUnits < $totalUnits){
|
||||||
$database->modifyEnforce($starvingTroops['id'], array_keys($killedUnits), array_values($killedUnits), 0);
|
$database->modifyEnforce($starvingTroops['id'], array_keys($killedUnits), array_values($killedUnits), 0);
|
||||||
|
|||||||
+36
-2
@@ -7697,7 +7697,6 @@ References: User ID/Message ID, Mode
|
|||||||
foreach($detailsArray as $field => $value) $values[] = $field."=".$value;
|
foreach($detailsArray as $field => $value) $values[] = $field."=".$value;
|
||||||
|
|
||||||
$q = "UPDATE ".TB_PREFIX."artefacts SET ".implode(",", $values)." WHERE id = $id";
|
$q = "UPDATE ".TB_PREFIX."artefacts SET ".implode(",", $values)." WHERE id = $id";
|
||||||
echo $q;
|
|
||||||
return mysqli_query($this->dblink, $q);
|
return mysqli_query($this->dblink, $q);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7858,7 +7857,7 @@ References: User ID/Message ID, Mode
|
|||||||
case 9:
|
case 9:
|
||||||
case 10:
|
case 10:
|
||||||
case 11:
|
case 11:
|
||||||
$cropo ++;
|
$cropo++;
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
$cropo += 2;
|
$cropo += 2;
|
||||||
@@ -7883,6 +7882,41 @@ References: User ID/Message ID, Mode
|
|||||||
return self::$cropProductionStarvationValueCache[$wref];
|
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
|
//general statistics
|
||||||
|
|
||||||
function addGeneralAttack($casualties) {
|
function addGeneralAttack($casualties) {
|
||||||
|
|||||||
@@ -236,13 +236,13 @@ class Technology {
|
|||||||
return $ownunit;
|
return $ownunit;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllUnits($base, $InVillageOnly = false, $mode=0) {
|
function getAllUnits($base, $InVillageOnly = false, $mode = 0, $useCache = true) {
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
$ownunit = $database->getUnit($base);
|
$ownunit = $database->getUnit($base, $useCache);
|
||||||
$ownunit['u99'] -= $ownunit['u99'];
|
$ownunit['u99'] -= $ownunit['u99'];
|
||||||
$ownunit['u99o'] -= $ownunit['u99o'];
|
$ownunit['u99o'] -= $ownunit['u99o'];
|
||||||
$enforcementarray = $database->getEnforceVillage($base, 0);
|
$enforcementarray = $database->getEnforceVillage($base, 0, $useCache);
|
||||||
if(count($enforcementarray) > 0){
|
if(count($enforcementarray) > 0){
|
||||||
foreach($enforcementarray as $enforce){
|
foreach($enforcementarray as $enforce){
|
||||||
for($i = 1; $i <= 50; $i++){
|
for($i = 1; $i <= 50; $i++){
|
||||||
@@ -252,7 +252,7 @@ class Technology {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($mode == 0){
|
if($mode == 0){
|
||||||
$enforceoasis = $database->getOasisEnforce($base, 0);
|
$enforceoasis = $database->getOasisEnforce($base, 0, $useCache);
|
||||||
if(count($enforceoasis) > 0){
|
if(count($enforceoasis) > 0){
|
||||||
foreach($enforceoasis as $enforce){
|
foreach($enforceoasis as $enforce){
|
||||||
for($i = 1; $i <= 50; $i++){
|
for($i = 1; $i <= 50; $i++){
|
||||||
@@ -261,7 +261,7 @@ class Technology {
|
|||||||
$ownunit['hero'] += $enforce['hero'];
|
$ownunit['hero'] += $enforce['hero'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$enforceoasis1 = $database->getOasisEnforce($base, 1);
|
$enforceoasis1 = $database->getOasisEnforce($base, 1, $useCache);
|
||||||
if(count($enforceoasis1) > 0){
|
if(count($enforceoasis1) > 0){
|
||||||
foreach($enforceoasis1 as $enforce){
|
foreach($enforceoasis1 as $enforce){
|
||||||
for($i = 1; $i <= 50; $i++){
|
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)){
|
if(!empty($prisoners)){
|
||||||
foreach($prisoners as $prisoner){
|
foreach($prisoners as $prisoner){
|
||||||
$owner = $database->getVillageField($base, "owner");
|
$owner = $database->getVillageField($base, "owner");
|
||||||
|
|||||||
Reference in New Issue
Block a user