mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-12 07:36:07 +00:00
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:
+26
-4
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user