mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-06-28 00:24:23 +00:00
General fixes
+Fixed a little mistake in the starvation it works properly now +A reinforced hero is now reassigned if his main village is conquered +Population will now recount after a conquering
This commit is contained in:
+23
-24
@@ -129,15 +129,14 @@ class Automation {
|
||||
for ($i = 1; $i <= 40; $i++) {
|
||||
$lvl = $fdata["f".$i];
|
||||
$building = $fdata["f".$i."t"];
|
||||
if($building){
|
||||
$popTot += $this->buildingPOP($building,$lvl);
|
||||
}
|
||||
if($building) $popTot += $this->buildingPOP($building, $lvl);
|
||||
}
|
||||
|
||||
$this->recountCP($vid);
|
||||
$q = "UPDATE ".TB_PREFIX."vdata set pop = $popTot where wref = $vid";
|
||||
mysqli_query($database->dblink,$q);
|
||||
$owner = $database->getVillageField($vid,"owner");
|
||||
$this->procClimbers($owner);
|
||||
$q = "UPDATE ".TB_PREFIX."vdata set pop = $popTot where wref = $vid";
|
||||
mysqli_query($database->dblink, $q);
|
||||
$owner = $database->getVillageField($vid, "owner");
|
||||
$this->procClimbers($owner);
|
||||
|
||||
return $popTot;
|
||||
}
|
||||
@@ -552,9 +551,7 @@ class Automation {
|
||||
}
|
||||
|
||||
// update statistical data for affected villages
|
||||
foreach ($villagesAffected as $affected_id) {
|
||||
$this->recountPop( $affected_id );
|
||||
}
|
||||
foreach ($villagesAffected as $affected_id) $this->recountPop($affected_id);
|
||||
|
||||
// update data that can be done in one swoop instead of using multiple update queries
|
||||
// no special checks for Romans
|
||||
@@ -2182,27 +2179,31 @@ class Automation {
|
||||
if($exp1 == 0){
|
||||
$exp = 'exp1';
|
||||
$value = $data['to'];
|
||||
}
|
||||
elseif($exp2 == 0){
|
||||
}elseif($exp2 == 0){
|
||||
$exp = 'exp2';
|
||||
$value = $data['to'];
|
||||
}
|
||||
else{
|
||||
}else{
|
||||
$exp = 'exp3';
|
||||
$value = $data['to'];
|
||||
}
|
||||
|
||||
$database->setVillageField($data['from'], $exp, $value);
|
||||
|
||||
//remove oasis related to village
|
||||
//Remove oasis related to village
|
||||
$units->returnTroops($data['to'], 1);
|
||||
$chiefing_village = 1;
|
||||
|
||||
//Remove trade routes related to village
|
||||
$database->deleteTradeRoutesByVillage($data['to']);
|
||||
|
||||
// update data in the database
|
||||
//Update data in the database
|
||||
$database->setVillageLevel($data['to'], $newLevels_fieldNames, $newLevels_fieldValues);
|
||||
|
||||
//Recount the population
|
||||
$pop = $this->recountPop($data['to'], false);
|
||||
|
||||
//Kill and reassign the hero to the capital village, if registered in the conquered one
|
||||
$database->reassignHero($data['to']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3973,11 +3974,9 @@ class Automation {
|
||||
$unitArrays = $this->getAllUnits($wref, false);
|
||||
$villageUpkeep = $getVillage['pop'] + $technology->getUpkeep($unitArrays, 0, $wref);
|
||||
$starv = $getVillage['starv'];
|
||||
|
||||
|
||||
if ($crop < $villageUpkeep){
|
||||
|
||||
//Add starvation data
|
||||
$database->setVillageField($wref, 'starv', $villageUpkeep);
|
||||
$database->setVillageFields($wref, ['starv', 'starvupdate'], [$villageUpkeep, time()]);
|
||||
}
|
||||
}
|
||||
@@ -4059,10 +4058,10 @@ class Automation {
|
||||
}
|
||||
|
||||
// if the player has no troops, then skip the next instructions
|
||||
if(empty($starvingTroops)) continue;
|
||||
|
||||
// counting
|
||||
$timedif = $time-$starv['starvupdate'];
|
||||
if(empty($starvingTroops)) continue;
|
||||
|
||||
// counting
|
||||
$timedif = $time - $starv['starvupdate'];
|
||||
$cropProd = $database->getCropProdstarv($starv['wref']) - $starv['starv'];
|
||||
if($cropProd < 0){
|
||||
$starvsec = (abs($cropProd) / 3600);
|
||||
@@ -4164,7 +4163,7 @@ class Automation {
|
||||
}
|
||||
|
||||
$crop = $database->getCropProdstarv($starv['wref'], false);
|
||||
if ($crop > 0) $database->setVillageField($starv['wref'], ['starv', 'starvupdate'], [0, 0]);
|
||||
if ($crop > $upkeep) $database->setVillageFields($starv['wref'], ['starv', 'starvupdate'], [0, 0]);
|
||||
|
||||
unset ($unitarrays, $type, $subtype);
|
||||
}
|
||||
|
||||
+28
-51
@@ -7399,7 +7399,7 @@ References: User ID/Message ID, Mode
|
||||
}
|
||||
|
||||
function getCropProdstarv($wref, $use_cache = true) {
|
||||
global $bid4,$bid8,$bid9,$sesion,$technology;
|
||||
global $bid4, $bid8, $bid9, $sesion, $technology;
|
||||
|
||||
// first of all, check if we should be using cache and whether the field
|
||||
// required is already cached
|
||||
@@ -7407,75 +7407,48 @@ References: User ID/Message ID, Mode
|
||||
return $cachedValue;
|
||||
}
|
||||
|
||||
$wood = 0;
|
||||
$cropo = 0;
|
||||
$clay = 0;
|
||||
$iron = 0;
|
||||
$wood = $cropo = $clay = $iron = 0;
|
||||
$basecrop = $grainmill = $bakery = 0;
|
||||
$owner = $this->getVrefField($wref, 'owner', $use_cache);
|
||||
$bonus = $this->getUserField($owner, 'b4', 0);
|
||||
|
||||
$buildarray = $this->getResourceLevel($wref);
|
||||
$cropholder = array();
|
||||
for($i=1;$i<=38;$i++) {
|
||||
if($buildarray['f'.$i.'t'] == 4) {
|
||||
array_push($cropholder,'f'.$i);
|
||||
}
|
||||
if($buildarray['f'.$i.'t'] == 8) {
|
||||
$grainmill = $buildarray['f'.$i];
|
||||
}
|
||||
if($buildarray['f'.$i.'t'] == 9) {
|
||||
$bakery = $buildarray['f'.$i];
|
||||
}
|
||||
$cropholder = [];
|
||||
for($i = 1; $i <= 38; $i++){
|
||||
if($buildarray['f'.$i.'t'] == 4) array_push($cropholder, 'f' . $i);
|
||||
if($buildarray['f'.$i.'t'] == 8) $grainmill = $buildarray['f' . $i];
|
||||
if($buildarray['f'.$i.'t'] == 9) $bakery = $buildarray['f' . $i];
|
||||
}
|
||||
|
||||
$q = "SELECT type FROM `" . TB_PREFIX . "odata` WHERE conqured = ".(int) $wref;
|
||||
$oasis = $this->query_return($q);
|
||||
foreach($oasis as $oa){
|
||||
switch($oa['type']) {
|
||||
case 1:
|
||||
case 2:
|
||||
$wood += 1;
|
||||
break;
|
||||
case 3:
|
||||
$wood += 1;
|
||||
$cropo += 1;
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
$clay += 1;
|
||||
break;
|
||||
case 6:
|
||||
$clay += 1;
|
||||
$cropo += 1;
|
||||
break;
|
||||
case 7:
|
||||
case 8:
|
||||
$iron += 1;
|
||||
break;
|
||||
case 9:
|
||||
$iron += 1;
|
||||
$cropo += 1;
|
||||
break;
|
||||
case 10:
|
||||
case 11:
|
||||
$cropo += 1;
|
||||
$cropo ++;
|
||||
break;
|
||||
case 12:
|
||||
$cropo += 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for ( $i = 0; $i <= count( $cropholder ) - 1; $i ++ ) {
|
||||
$basecrop += $bid4[ $buildarray[ $cropholder[ $i ] ] ]['prod'];
|
||||
}
|
||||
$crop = $basecrop + $basecrop * 0.25 * $cropo;
|
||||
if ( $grainmill >= 1 || $bakery >= 1 ) {
|
||||
$crop += $basecrop / 100 * ( ( isset( $bid8[ $grainmill ]['attri'] ) ? $bid8[ $grainmill ]['attri'] : 0 ) + ( isset( $bid9[ $bakery ]['attri'] ) ? $bid9[ $bakery ]['attri'] : 0 ) );
|
||||
}
|
||||
if ( $bonus > time() ) {
|
||||
$crop *= 1.25;
|
||||
}
|
||||
$crop *= SPEED;
|
||||
|
||||
for($i = 0; $i <= count($cropholder) - 1; $i++){
|
||||
$basecrop += $bid4[$buildarray[$cropholder[$i]]]['prod'];
|
||||
}
|
||||
$crop = $basecrop + $basecrop * 0.25 * $cropo;
|
||||
|
||||
if($grainmill >= 1 || $bakery >= 1){
|
||||
$crop += $basecrop / 100 * ((isset($bid8[$grainmill]['attri']) ? $bid8[$grainmill]['attri'] : 0) + (isset($bid9[$bakery]['attri']) ? $bid9[$bakery]['attri'] : 0));
|
||||
}
|
||||
if($bonus > time()){
|
||||
$crop *= 1.25;
|
||||
}
|
||||
$crop *= SPEED;
|
||||
|
||||
self::$cropProductionStarvationValueCache[$wref] = $crop;
|
||||
return self::$cropProductionStarvationValueCache[$wref];
|
||||
@@ -7944,6 +7917,8 @@ References:
|
||||
*/
|
||||
|
||||
function reassignHero($wref){
|
||||
list($wref) = $this->escape_input($wref);
|
||||
|
||||
$q = "UPDATE
|
||||
".TB_PREFIX."hero AS hero
|
||||
INNER JOIN ".TB_PREFIX."vdata AS vdata
|
||||
@@ -7962,8 +7937,10 @@ References:
|
||||
* @return bool Return true if the query was successful, false otherwise
|
||||
*/
|
||||
|
||||
function changeCapital($wref){
|
||||
$q = "UPDATE ".TB_PREFIX."vdata SET capital = 1 WHERE wref = $wref";
|
||||
function changeCapital($wref, $mode = 1){
|
||||
list($wref, $mode) = $this->escape_input($wref, $mode);
|
||||
|
||||
$q = "UPDATE ".TB_PREFIX."vdata SET capital = ".$mode." WHERE wref = $wref";
|
||||
return mysqli_query($this->dblink, $q);
|
||||
}
|
||||
};
|
||||
|
||||
+48
-55
@@ -1,44 +1,45 @@
|
||||
<?php
|
||||
if(time() - (!empty($_SESSION['time_p']) ? $_SESSION['time_p'] : 0) > 5) {
|
||||
$_SESSION['time_p'] = '';
|
||||
$_SESSION['error_p'] = '';
|
||||
if(time() - (!empty($_SESSION['time_p']) ? $_SESSION['time_p'] : 0) > 5){
|
||||
$_SESSION['time_p'] = '';
|
||||
$_SESSION['error_p'] = '';
|
||||
}
|
||||
|
||||
if($_POST AND $_GET['action'] == 'change_capital') {
|
||||
$pass = mysqli_escape_string($database->dblink,$_POST['pass']);
|
||||
$query = mysqli_query($database->dblink,'SELECT password FROM `' . TB_PREFIX . 'users` WHERE `id` = ' . (int) $session->uid);
|
||||
$data = mysqli_fetch_assoc($query);
|
||||
if(password_verify($pass, $data['password'])) {
|
||||
$query1 = mysqli_query($database->dblink,'SELECT wref FROM `' . TB_PREFIX . 'vdata` WHERE `owner` = ' .(int) $session->uid . ' AND `capital` = 1');
|
||||
$data1 = mysqli_fetch_assoc($query1);
|
||||
$query2 = mysqli_query($database->dblink,'SELECT * FROM `' . TB_PREFIX . 'fdata` WHERE `vref` = ' . (int) $data1['wref']);
|
||||
$data2 = mysqli_fetch_assoc($query2);
|
||||
if($data2['vref'] != $village->wid) {
|
||||
for($i = 1; $i<=18; ++$i) {
|
||||
if($data2['f' . $i] > 10) {
|
||||
$query2 = mysqli_query($database->dblink,'UPDATE `' . TB_PREFIX . 'fdata` SET `f' . $i . '` = 10 WHERE `vref` = ' . (int) $data2['vref']) or die(mysqli_error($database->dblink));
|
||||
}
|
||||
}
|
||||
for($i=19; $i<=40; ++$i) {
|
||||
if($data2['f' . $i . 't'] == 34) {
|
||||
$query3 = mysqli_query($database->dblink,'UPDATE `' . TB_PREFIX . 'fdata` SET `f' . $i . 't` = 0, `f' . $i . '` = 0 WHERE `vref` = ' . (int) $data2['vref']) or die(mysqli_error($database->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
for($i=19; $i<=40; ++$i) {
|
||||
if($data2['f' . $i . 't'] == 29 or $data2['f' . $i . 't'] == 30 or $data2['f' . $i . 't'] == 38 or $data2['f' . $i . 't'] == 39 or $data2['f' . $i . 't'] == 42) {
|
||||
$query3 = mysqli_query($database->dblink,'UPDATE `' . TB_PREFIX . 'fdata` SET `f' . $i . 't` = 0, `f' . $i . '` = 0 WHERE `vref` = ' . (int) $village->wid) or die(mysqli_error($database->dblink));
|
||||
}
|
||||
}
|
||||
$query3 = mysqli_query($database->dblink,'UPDATE `' . TB_PREFIX . 'vdata` SET `capital` = 0 WHERE `wref` = ' . (int) $data1['wref']);
|
||||
$query4 = mysqli_query($database->dblink,'UPDATE `' . TB_PREFIX . 'vdata` SET `capital` = 1 WHERE `wref` = ' . (int) $village->wid);
|
||||
}
|
||||
} else {
|
||||
$error = '<br /><font color="red">'.LOGIN_PW_ERROR.'</font><br />';
|
||||
$_SESSION['error_p'] = $error;
|
||||
$_SESSION['time_p'] = time();
|
||||
print '<script language="javascript">location.href="build.php?id=' . $building->getTypeField(26) . '&confirm=yes";</script>';
|
||||
}
|
||||
if($_POST and $_GET['action'] == 'change_capital'){
|
||||
$pass = mysqli_escape_string($database->dblink, $_POST['pass']);
|
||||
$query = mysqli_query($database->dblink, 'SELECT password FROM `'.TB_PREFIX.'users` WHERE `id` = '.(int)$session->uid);
|
||||
$data = mysqli_fetch_assoc($query);
|
||||
if(password_verify($pass, $data['password'])){
|
||||
$query1 = mysqli_query($database->dblink, 'SELECT wref FROM `'.TB_PREFIX.'vdata` WHERE `owner` = '.(int)$session->uid.' AND `capital` = 1');
|
||||
$data1 = mysqli_fetch_assoc($query1);
|
||||
$query2 = mysqli_query($database->dblink, 'SELECT * FROM `'.TB_PREFIX.'fdata` WHERE `vref` = '.(int)$data1['wref']);
|
||||
$data2 = mysqli_fetch_assoc($query2);
|
||||
if($data2['vref'] != $village->wid){
|
||||
for($i = 1; $i <= 18; ++$i){
|
||||
if($data2['f'.$i] > 10){
|
||||
$query2 = mysqli_query($database->dblink, 'UPDATE `'.TB_PREFIX.'fdata` SET `f'.$i.'` = 10 WHERE `vref` = '.(int)$data2['vref']) or die(mysqli_error($database->dblink));
|
||||
}
|
||||
}
|
||||
for($i = 19; $i <= 40; ++$i){
|
||||
if($data2['f'.$i.'t'] == 34){
|
||||
$query3 = mysqli_query($database->dblink, 'UPDATE `'.TB_PREFIX.'fdata` SET `f'.$i.'t` = 0, `f'.$i.'` = 0 WHERE `vref` = '.(int)$data2['vref']) or die(mysqli_error($database->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
for($i = 19; $i <= 40; ++$i){
|
||||
if($data2['f'.$i.'t'] == 29 || $data2['f'.$i.'t'] == 30 || $data2['f'.$i.'t'] == 38 || $data2['f'.$i.'t'] == 39 || $data2['f'.$i.'t'] == 42){
|
||||
$query3 = mysqli_query($database->dblink, 'UPDATE `'.TB_PREFIX.'fdata` SET `f'.$i.'t` = 0, `f'.$i.'` = 0 WHERE `vref` = '.(int)$village->wid) or die(mysqli_error($database->dblink));
|
||||
}
|
||||
}
|
||||
|
||||
$database->changeCapital((int)$data1['wref'], 0);
|
||||
$database->changeCapital($village->wid);
|
||||
}
|
||||
}else{
|
||||
$error = '<br /><font color="red">'.LOGIN_PW_ERROR.'</font><br />';
|
||||
$_SESSION['error_p'] = $error;
|
||||
$_SESSION['time_p'] = time();
|
||||
print '<script language="javascript">location.href="build.php?id='.$building->getTypeField(26).'&confirm=yes";</script>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<div id="build" class="gid26"><h1><?php echo PALACE; ?> <span class="level"><?php echo LEVEL; ?> <?php echo $village->resarray['f'.$id]; ?></span></h1>
|
||||
@@ -55,40 +56,32 @@ if ($building->getTypeLevel(26) > 0) {
|
||||
|
||||
include("26_menu.tpl");
|
||||
|
||||
$test=$database->getAvailableExpansionTraining();
|
||||
|
||||
if($village->resarray['f'.$id] >= 10){
|
||||
include ("26_train.tpl");
|
||||
}
|
||||
else{
|
||||
echo '<div class="c">'.PALACE_TRAIN_DESC.'</div>';
|
||||
}
|
||||
if($village->resarray['f'.$id] >= 10) include ("26_train.tpl");
|
||||
else echo '<div class="c">'.PALACE_TRAIN_DESC.'</div>';
|
||||
|
||||
?>
|
||||
|
||||
<?php
|
||||
$query = mysqli_query($database->dblink,'SELECT wref FROM `' . TB_PREFIX . 'vdata` WHERE `owner` = ' . (int) $session->uid . ' AND `capital` = 1');
|
||||
$data = mysqli_fetch_assoc($query);
|
||||
if($data['wref'] == $village->wid) {
|
||||
if($village->capital == $village->wid) {
|
||||
?>
|
||||
<p class="none"><?php echo CAPITAL; ?></p>
|
||||
<?php
|
||||
} else {
|
||||
if(empty($_GET['confirm'])) {
|
||||
print '<p><a href="?id=' . $building->getTypeField(26) . '&confirm=yes">» '.CHANGE_CAPITAL.'</a></p>';
|
||||
print '<p><a href="?id='.$building->getTypeField(26).'&confirm=yes">» '.CHANGE_CAPITAL.'</a></p>';
|
||||
} else {
|
||||
print '<p>Are you sure, that you want to change your capital?<br /><b>You can\'t undo this!</b><br />For security you must enter your password to confirm:<br />
|
||||
<form method="post" action="build.php?id=' . $building->getTypeField(26) . '&action=change_capital">
|
||||
' . $_SESSION['error_p'] . '
|
||||
<form method="post" action="build.php?id='.$building->getTypeField(26).'&action=change_capital">
|
||||
'.$_SESSION['error_p'].'
|
||||
'.PASSWORD.': <input type="password" name="pass" /><br />
|
||||
<input type="image" id="btn_ok" class="dynamic_img" value="ok" name="s1" src="img/x.gif" alt="train" />
|
||||
</form>
|
||||
</p>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo "<b><?php echo PALACE_CONSTRUCTION; ?></b>";
|
||||
}
|
||||
}
|
||||
else echo "<b><?php echo PALACE_CONSTRUCTION; ?></b>";
|
||||
|
||||
include("upgrade.tpl");
|
||||
?>
|
||||
</div>
|
||||
Reference in New Issue
Block a user