Distance calculation optimization and bug fixing

-Removed a lot of redundant code and put into a function
+Fixed a bug that permitted to found a new village in already founded
village
+Fixed a bug that permitted to found in an oasis
+Fixed a bug that permitted to hack the time you need to found a new
village
+Fixed a bug that permitted to found a new village to an inexistent one
This commit is contained in:
iopietro
2018-04-29 00:49:24 +02:00
parent 48410e960b
commit a40accc101
11 changed files with 201 additions and 454 deletions
+1 -25
View File
@@ -3,9 +3,6 @@ $to = $database->getVillage($enforce['from']);
$fromcoor = $database->getCoor($enforce['from']);
$tocoor = $database->getCoor($enforce['vref']);
$fromCor = ['x'=>$tocoor['x'], 'y'=>$tocoor['y']];
$toCor = ['x'=>$fromcoor['x'], 'y'=>$fromcoor['y']];
$att_tribe = $database->getUserField($to['owner'],'tribe',0);
$start = ($att_tribe - 1) * 10 + 1;
$end = $att_tribe * 10;
@@ -124,28 +121,7 @@ $end = $att_tribe * 10;
<th>Arrived:</th>
<?php
$speeds = [];
//find slowest unit.
for($i = $start; $i <= $end; $i++)
{
if (isset($enforce['u'.$i]))
{
if(!empty($enforce['u'.$i]) && $enforce['u'.$i] > 0)
{
$speeds[] = ${'u'.$i}['speed'];
}
}
}
if ($enforce['hero']>0){
$qh = "SELECT unit FROM ".TB_PREFIX."hero WHERE uid = ".(int) $to['owner']." AND dead = 0";
$resulth = mysqli_query($database->dblink,$qh);
$hero_f=mysqli_fetch_array($resulth);
$hero_unit=$hero_f['unit'];
$speeds[] = $GLOBALS['u'.$hero_unit]['speed'];
}
$troopsTime = $generator->procDistanceTime($fromCor, $toCor, min($speeds), 1);
$troopsTime = $units->getWalkingTroopsTime($enforce['from'], $enforce['vref'], $to['owner'], $att_tribe, $enforce, 1);
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
?>