Starvation refactor

Refactor part 2 of the "Starvation" function:
+Trapped troops in other villages will die of starvation
+Returning troops will die of starvaton

Database.php:
+Added "modifyPrisoners" function
This commit is contained in:
iopietro
2018-04-11 00:16:39 +02:00
parent 01e1df7493
commit 8b3a387cd5
2 changed files with 134 additions and 166 deletions
+26 -4
View File
@@ -5786,17 +5786,18 @@ References: User ID/Message ID, Mode
}
// no need to cache this method
function getUnitsNumber($vid, $use_cache = false) {
function getUnitsNumber($vid, $mode = 1, $use_cache = false) {
list( $vid ) = $this->escape_input( (int) $vid );
$dbarray = $this->getUnit( $vid );
$totalunits = 0;
$movingunits = $this->getVillageMovement( $vid );
for ( $i = 1; $i <= 50; $i ++ ) {
$totalunits += $dbarray[ 'u' . $i ];
}
$totalunits += $dbarray['hero'];
$totalunits += $dbarray['hero'];
if(!$mode) return $totalunits;
$movingunits = $this->getVillageMovement( $vid );
$reinforcingunits = $this->getEnforceArray( $vid, 1 );
$owner = $this->getVillageField( $vid, "owner" );
@@ -7560,6 +7561,27 @@ References: User ID/Message ID, Mode
return $res;
}
/**
* Used to modify prisoners through the inserted id
*
* @param int $id The id where prisoners are in the database
* @param int $unit The type of the unit
* @param int $amount The amount of the unit you want to sum/subtract
* @param int $mode 0 for subtracting the inserted amount, 1 for adding it
* @return bool Returns false on failure and true on success
*/
function modifyPrisoners($id, $unit, $amount, $mode) {
list($id, $unit, $amount, $mode) = $this->escape_input((int) $id,(int) $unit,(int) $amount,(int) $mode);
$unit = 't'.$unit;
$prisoners = $unit." = ".$unit.(!$mode ? " - " : " + ").$amount;
$q = "UPDATE " . TB_PREFIX . "prisoners set $prisoners WHERE id = $id";
$res = mysqli_query($this->dblink,$q);
return $res;
}
function getPrisoners($wid,$mode=0, $use_cache = true) {
$array_passed = is_array($wid);
$mode = (int) $mode;