Update Database.php

Fixed chieftain training issue: when player reinforced their chiefs to other villages they could train more so no more unlimited chieftains :)
This commit is contained in:
lietuvis10
2025-12-14 15:27:46 +02:00
committed by GitHub
parent 04061dc772
commit 038465fe9a
+80 -72
View File
@@ -7134,90 +7134,98 @@ References: User ID/Message ID, Mode
public function getAvailableExpansionTraining() { public function getAvailableExpansionTraining() {
global $building, $session, $technology, $village; global $building, $session, $technology, $village;
$vilData = $this->getVillage($village->wid); $vilData = $this->getVillage($village->wid);
$maxslots = (($vilData['exp1'] == 0 ? 1 : 0) + ($vilData['exp2'] == 0 ? 1 : 0) + ($vilData['exp3'] == 0 ? 1 : 0)); $maxslots = (($vilData['exp1'] == 0 ? 1 : 0) + ($vilData['exp2'] == 0 ? 1 : 0) + ($vilData['exp3'] == 0 ? 1 : 0));
$residence = $building->getTypeLevel(25); $residence = $building->getTypeLevel(25);
$palace = $building->getTypeLevel(26); $palace = $building->getTypeLevel(26);
if($residence > 0) { if($residence > 0) {
$maxslots -= (3 - floor($residence / 10)); $maxslots -= (3 - floor($residence / 10));
} }
if($palace > 0) { if($palace > 0) {
$maxslots -= (3 - floor(($palace - 5) / 5)); $maxslots -= (3 - floor(($palace - 5) / 5));
} }
$q = "SELECT (u10+u20+u30) as R1, (u9+u19+u29) as R2 FROM " . TB_PREFIX . "units WHERE vref = ". (int) $village->wid; // Units at home
$result = mysqli_query($this->dblink,$q); $q = "SELECT (u10+u20+u30) as R1, (u9+u19+u29) as R2
$row = mysqli_fetch_array($result, MYSQLI_ASSOC); FROM " . TB_PREFIX . "units
$settlers = $row['R1']; WHERE vref = " . (int)$village->wid;
$chiefs = $row['R2']; $result = mysqli_query($this->dblink,$q);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$settlers = (int)$row['R1'];
$chiefs = (int)$row['R2'];
$settlers += 3 * count($this->getMovement(5, $village->wid, 0)); // Movements
$settlers += 3 * count($this->getMovement(5, $village->wid, 0));
$current_movement = $this->getMovement(3, $village->wid, 0);
if(!empty($current_movement)) {
foreach($current_movement as $build) {
$settlers += $build['t10'];
$chiefs += $build['t9'];
}
}
$current_movement = $this->getMovement(4, $village->wid, 1); $current_movement = $this->getMovement(3, $village->wid, 0);
if(!empty($current_movement)) { if(!empty($current_movement)) {
foreach($current_movement as $build) { foreach($current_movement as $build) {
$settlers += $build['t10']; $settlers += (int)$build['t10'];
$chiefs += $build['t9']; $chiefs += (int)$build['t9'];
} }
} }
$q = "SELECT (u10+u20+u30) FROM " . TB_PREFIX . "enforcement WHERE `from` = ".(int) $village->wid; $current_movement = $this->getMovement(4, $village->wid, 1);
$result = mysqli_query($this->dblink,$q); if(!empty($current_movement)) {
$row = mysqli_fetch_row($result); foreach($current_movement as $build) {
if(!empty($row)) { $settlers += (int)$build['t10'];
foreach($row as $reinf) { $chiefs += (int)$build['t9'];
$settlers += $reinf[0]; }
} }
}
$q = "SELECT (u9+u19+u29) FROM " . TB_PREFIX . "enforcement WHERE `from` = ".(int) $village->wid; // FIX: Count ALL reinforcements properly (SUM over ALL rows)
$result = mysqli_query($this->dblink,$q); $q = "SELECT COALESCE(SUM(u10+u20+u30),0) AS s
$row = mysqli_fetch_row($result); FROM " . TB_PREFIX . "enforcement
if(!empty($row)) { WHERE `from` = " . (int)$village->wid;
foreach($row as $reinf) { $result = mysqli_query($this->dblink,$q);
$chiefs += $reinf[0]; $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
} $settlers += (int)$row['s'];
}
$trainlist = $technology->getTrainingList(4); $q = "SELECT COALESCE(SUM(u9+u19+u29),0) AS c
if(!empty($trainlist)) { FROM " . TB_PREFIX . "enforcement
foreach($trainlist as $train) { WHERE `from` = " . (int)$village->wid;
if($train['unit'] % 10 == 0) { $result = mysqli_query($this->dblink,$q);
$settlers += $train['amt']; $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
} $chiefs += (int)$row['c'];
if($train['unit'] % 10 == 9) {
$chiefs += $train['amt'];
}
}
}
$trappedTroops = $this->getPrisoners($village->wid, 1); // Training queue (your existing logic)
if(!empty($trappedTroops)){ $trainlist = $technology->getTrainingList(4);
foreach($trappedTroops as $trapped){ if(!empty($trainlist)) {
$settlers += $trapped['t10']; foreach($trainlist as $train) {
$chiefs += $trapped['t9']; if($train['unit'] % 10 == 0) {
} $settlers += (int)$train['amt'];
} }
if($train['unit'] % 10 == 9) {
$chiefs += (int)$train['amt'];
}
}
}
$settlerslots = ($maxslots * 3) - ($chiefs * 3) - $settlers; // Trapped troops
$chiefslots = $maxslots - $chiefs - floor(($settlers + 2) / 3); $trappedTroops = $this->getPrisoners($village->wid, 1);
if(!empty($trappedTroops)){
foreach($trappedTroops as $trapped){
$settlers += (int)$trapped['t10'];
$chiefs += (int)$trapped['t9'];
}
}
if(!$technology->getTech(($session->tribe - 1) * 10 + 9)) { // Slot math (unchanged, but clamp to 0 to avoid negatives)
$chiefslots = 0; $settlerslots = ($maxslots * 3) - ($chiefs * 3) - $settlers;
} $chiefslots = $maxslots - $chiefs - floor(($settlers + 2) / 3);
if(!$technology->getTech(($session->tribe - 1) * 10 + 9)) {
$chiefslots = 0;
}
if ($settlerslots < 0) $settlerslots = 0;
if ($chiefslots < 0) $chiefslots = 0;
return ["chiefs" => $chiefslots, "settlers" => $settlerslots];
}
return ["chiefs" => $chiefslots, "settlers" => $settlerslots];
}
/** /**
* Calculates how much artifacts affect troops speed, cranny efficency, etc. * Calculates how much artifacts affect troops speed, cranny efficency, etc.