fix: reverting possibility of settlers & chieftain creation side-by-side

Turns out we could conquer a village and then settle a new one without
having enough expansion slots. Thus this is a revert to original state,
where we can't train settlers with chieftain in village or chieftain
with settlers in village, if we don't have enough slots.

Closes #324
This commit is contained in:
Martin Ambrus
2017-11-09 00:08:40 +01:00
parent 50f0cae495
commit 0a541d5bd3
2 changed files with 55 additions and 25 deletions
+13 -1
View File
@@ -4668,12 +4668,24 @@ class MYSQLi_DB implements IDbConnection {
}
}
// TODO: trapped settlers/chiefs calculation required
$settlerslots = ($maxslots * 3) - $settlers;
$settlerslots = ($maxslots * 3) - $chiefs - $settlers;
// don't allow training of settlers if there is at least 1 chief in the village
if ($chiefs > 0) {
$settlerslots = 0;
}
$chiefslots = $maxslots - $chiefs - floor(($settlers + 2) / 3);
if(!$technology->getTech(($session->tribe - 1) * 10 + 9)) {
$chiefslots = 0;
}
// don't allow training of chieftains if there is at least 1 settler in the village
if ($settlers > 0) {
$chiefslots = 0;
}
$slots = array("chiefs" => $chiefslots, "settlers" => $settlerslots);
return $slots;
}
+42 -24
View File
@@ -411,30 +411,48 @@ class Technology {
private function procTrain($post,$great=false) {
global $session;
if($session->access != BANNED){
$start = ($session->tribe-1)*10+1;
$end = ($session->tribe*10);
for($i=$start;$i<=($end);$i++) {
if(isset($post['t'.$i]) && $post['t'.$i] != 0) {
$amt = $post['t'.$i];
$amt = intval($amt);
if ($amt < 0) $amt = 1;
$this->trainUnit($i,$amt,$great);
}
}
if($session->tribe == 3){
if(isset($post['t99']) && $post['t99'] != 0) {
$amt = $post['t99'];
$amt = intval($amt);
if ($amt < 0) $amt = 1;
$this->trainUnit(99,$amt,$great);
}
}
header("Location: build.php?id=".$post['id']);
exit;
}else{
header("Location: banned.php");
exit;
}
// first of all, check if we're not trying to train chieftain
// and settlers together - which we cannot, since that can result
// in 1 chieftain and 3 settlers, then conquering a village, then
// founding a new one, all with only 1 available slot
if (
!(
(!empty($post['t9']) && !empty($post['t10'])) ||
(!empty($post['t19']) && !empty($post['t20'])) ||
(!empty($post['t29']) && !empty($post['t30'])) ||
(!empty($post['t39']) && !empty($post['t40'])) ||
(!empty($post['t49']) && !empty($post['t50']))
)
) {
$start = ( $session->tribe - 1 ) * 10 + 1;
$end = ( $session->tribe * 10 );
for ( $i = $start; $i <= ( $end ); $i ++ ) {
if ( isset( $post[ 't' . $i ] ) && $post[ 't' . $i ] != 0 ) {
$amt = $post[ 't' . $i ];
$amt = intval( $amt );
if ( $amt < 0 ) {
$amt = 1;
}
$this->trainUnit( $i, $amt, $great );
}
}
if ( $session->tribe == 3 ) {
if ( isset( $post['t99'] ) && $post['t99'] != 0 ) {
$amt = $post['t99'];
$amt = intval( $amt );
if ( $amt < 0 ) {
$amt = 1;
}
$this->trainUnit( 99, $amt, $great );
}
}
header( "Location: build.php?id=" . $post['id'] );
exit;
}
}else{
header("Location: banned.php");
exit;
}
}
public function getUpkeep($array,$type,$vid=0,$prisoners=0) {