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
+2 -2
View File
@@ -78,14 +78,14 @@ if(isset($_POST['ft'])=='check' && (($_POST['send3'] > 1 && $_POST['send3'] <= 3
$getvilowner = $database->getVillageField($getwref, "owner");
$getvilcoor['y'] = $_POST['y'];
$getvilcoor['x'] = $_POST['x'];
$time = $generator->procDistanceTime($getvilcoor,$village->coor,$session->tribe,0);
$time = $generator->procDistanceTime($getvilcoor, $village->coor, $session->tribe, 0);
}
else if(!empty($_POST['dname'])){
$getwref = $database->getVillageByName($_POST['dname']);
$getvilcoor = $database->getCoor($getwref);
$getvilname = $database->getVillageField($getwref, "name");
$getvilowner = $database->getVillageField($getwref, "owner");
$time = $generator->procDistanceTime($getvilcoor,$village->coor,$session->tribe,0);
$time = $generator->procDistanceTime($getvilcoor, $village->coor, $session->tribe, 0);
}
?>
<td><a href="karte.php?d=<?php echo $getwref; ?>&c=<?php echo $generator->getMapCheck($getwref); ?>"><?php echo $getvilname; ?>(<?php echo $getvilcoor['x']; ?>|<?php echo $getvilcoor['y']; ?>)<span class="clear"></span></a></td>
+2 -29
View File
@@ -283,35 +283,8 @@ $end = $tribe * 10;
<?php
$speeds = [];
$scout = 1;
//find slowest unit.
for($i = 1; $i <= 11; $i++)
{
if (isset($process['t'.$i]))
{
if(!empty($process['t'.$i]) && $process['t'.$i] > 0)
{
if ($i < 11) $speeds[] = ${'u'.(($session->tribe-1) * 10 + $i)}['speed'];
else
{
$hero_unit = $database->getHeroField($uid, 'unit');
$speeds[] = ${'u'.$hero_unit}['speed'];
}
if($i != 4) $scout = 0;
}
}
}
if($scout) $process['c'] = 1;
$ownVillage = $database->getCoor($village->wid);
$from = ['x' => $ownVillage['x'], 'y' => $ownVillage['y']];
$to = ['x' => $coor['x'], 'y' => $coor['y']];
$troopsTime = $generator->procDistanceTime($from, $to, min($speeds), 1);
<?php
$troopsTime = $units->getWalkingTroopsTime($village->wid, $process[0], $session->uid, $session->tribe, $process, 1, 't');
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
?>
+12 -19
View File
@@ -1,25 +1,19 @@
<?php
//-- Prevent user from founding a new village if there are not enough settlers or the player put an invalid village ID or an already occupied one
//-- fix by AL-Kateb - Semplified and additions by iopietro
if(($settlers = $village->unitarray['u'.$session->tribe.'0']) < 3 || !isset($_GET['id']) || ($newvillage = $database->getMInfo($_GET['id']))['id'] == 0 || $newvillage['occupied'] > 0 || $newvillage['oasistype'] > 0){
header("location: dorf1.php");
exit;
}
//--
$wood = round($village->awood);
$clay = round($village->aclay);
$iron = round($village->airon);
$crop = round($village->acrop);
$founder = $database->getVillage($village->wid);
$newvillage = $database->getMInfo($_GET['id']);
$eigen = $database->getCoor($village->wid);
$from = array('x'=>$eigen['x'], 'y'=>$eigen['y']);
$to = array('x'=>$newvillage['x'], 'y'=>$newvillage['y']);
$troopsTime = $generator->procDistanceTime($from, $to, 300, 0);
$troopsTime = $units->getWalkingTroopsTime($village->wid, $newvillage['id'], 0, 0, [300], 0);
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
//-- Prevent user from founding a new village if there are not enough settlers
//-- fix by AL-Kateb - Semplified by iopietro
if($village->unitarray['u'.$session->tribe.'0'] < 3){
header("location: dorf1.php");
exit;
}
//--
echo '<pre>';
echo '</pre>';
?>
@@ -29,23 +23,22 @@ echo '</pre>';
<input type="hidden" name="c" value="5" />
<input type="hidden" name="s" value="<?php echo $_GET['id']; ?>" />
<input type="hidden" name="id" value="39" />
<input type="hidden" name="timestamp" value="<?php echo $time; ?>" />
<table class="troop_details" cellpadding="1" cellspacing="1">
<thead>
<tr>
<td class="role"><a href="karte.php?d=<?php echo (isset($founder['0']) ? $founder['0'] : ''); ?>&c=<?php echo $generator->getMapCheck((isset($founder['0']) ? $founder['0'] : '')); ?>"><?php echo $session->username; ?></a></td><td colspan="10"><a href="karte.php?d=<?php echo $newvillage['id']; ?>&c=<?php echo $generator->getMapCheck($newvillage['0']) ?>">Found new village (<?php echo $newvillage['x']; ?>|<?php echo $newvillage['y']; ?>)</a></td>
<td class="role"><a href="spieler.php?uid=<?php echo $session->uid; ?>"><?php echo $session->username; ?></a></td><td colspan="10"><a href="karte.php?d=<?php echo $newvillage['id']; ?>&c=<?php echo $generator->getMapCheck($newvillage[0]) ?>">Found new village (<?php echo $newvillage['x']; ?>|<?php echo $newvillage['y']; ?>)</a></td>
</tr>
</thead>
<tbody class="units">
<tr>
<th>&nbsp;</th>
<?php for($i=($session->tribe-1)*10+1;$i<=$session->tribe*10;$i++) {
<?php for($i = ($session->tribe-1) * 10 + 1; $i <= $session->tribe * 10; $i++) {
echo "<td><img src=\"img/x.gif\" class=\"unit u".$i."\" title=\"".$technology->getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" /></td>";
} ?>
</tr>
<tr>
<th>Troops</th>
<?php for($i=1;$i<=9;$i++) {
<?php for($i = 1;$i <= 9; $i++) {
echo "<td class=\"none\">0</td>";
}
@@ -76,7 +69,7 @@ echo '</pre>';
</table>
<p class="btn">
<?php
if ($wood>749 && $clay>749 && $iron>749 && $crop>749) {
if ($wood >= 750 && $clay >= 750 && $iron >= 750 && $crop >= 750) {
?>
<input type="image" value="ok" name="s1" id="btn_ok" class="dynamic_img" alt="OK" src="img/x.gif" onclick="this.disabled=true;this.form.submit();"/>
<?php
+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);
?>
+3 -28
View File
@@ -60,33 +60,8 @@
$id = $database->addA2b( $ckey, $time_now, $wref, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, 4 );
$data = $database->getA2b( $ckey, $time_now );
$eigen = $database->getCoor( $getFLData['wref'] );
$from = array( 'x' => $eigen['x'], 'y' => $eigen['y'] );
$ander = $database->getCoor( $data['to_vid'] );
$to = array( 'x' => $ander['x'], 'y' => $ander['y'] );
$start = ( $tribe - 1 ) * 10 + 1;
$end = ( $tribe * 10 );
$speeds = array();
$scout = 1;
//find slowest unit.
for ( $i = 1; $i <= 10; $i ++ ) {
if ( $data[ 'u' . $i ] ) {
if ( $data[ 'u' . $i ] != '' && $data[ 'u' . $i ] > 0 ) {
if ( $unitarray ) {
reset( $unitarray );
}
$unitarray = $GLOBALS[ "u" . ( ( $tribe - 1 ) * 10 + $i ) ];
$speeds[] = $unitarray['speed'];
}
}
}
$troopsTime = $generator->procDistanceTime($from, $to, min($speeds), 1);
$troopsTime = $units->getWalkingTroopsTime($getFLData['wref'], $data['to_vid'], $session->uid, $session->tribe, $data, 1, 'u');
$time = $database->getArtifactsValueInfluence($getFLData['owner'], $getFLData['wref'], 2, $troopsTime);
$ctar1 = $ctar2 = 0;
@@ -114,8 +89,8 @@
$amounts[] = $data['u11'];
$modes[] = 0;
$database->modifyUnit( $getFLData['wref'], $units, $amounts, $modes );
$database->addMovement( 3, $getFLData['wref'], $data['to_vid'], $reference, time(), ( $time + time() ) );
$database->modifyUnit($getFLData['wref'], $units, $amounts, $modes);
$database->addMovement(3, $getFLData['wref'], $data['to_vid'], $reference, time(), ($time + time()));
// prevent re-use of the same attack via re-POSTing the same data
$database->remA2b( $id );
+31 -2
View File
@@ -10,7 +10,36 @@
#################################################################################
$txt="";
$txt="Construction plans
Countless days have passed since the first battles upon the walls of the cursed villages of the Dread Natars, many armies of both the free ones and the Natarian empire struggled and died before the walls of the many strongholds from which the Natars had once ruled all creation. Now with the dust settled and a relative calm having settled in, armies began to count their losses and collect their dead, the stench of combat still lingering in the night air, a smell of a slaughter unforgettable in its extent and brutality yet soon to be dwarfed by yet others. The largest armies of the free ones and the Dread Natars were marshalling for yet another renewed assault upon the coveted former strongholds of the Natarian Empire.
Soon scouts arrived telling of a most awesome sight and a chilling reminder, a dread army of an unfathomable size had been spotted marshalling at the end of the world, the Natarian capital, a force so great and unstoppable that the dust from their march would choke off all light, a force so brutal and ruthless that it would crush all hope. The free people knew that they had to race now, race against time and the endless hordes of the Natarian Empire to raise a Wonder of the World to restore the world to peace and vanquish the Natarian threat.
But to raise such a great Wonder would be no easy task, one would need construction plans created in the distant past, plans of such an arcane nature that even the very wisest of sages knew not their contents or locations.
Tens of thousands of scouts roamed across all existence searching in vain for these mystical plans, looking in all places but the dreaded Natarian Capital, yet could not find them. Today however, they return bearing good news, they return baring the locations of the plans, hidden by the armies of the Natars inside secret strongholds constructed to be hidden from the eyes of man.
Now begins the final stretch, when the greatest armies of the Free people and the Natars will clash across the world for the fate of all that lies under heaven. This is the war that will echo across the eons, this is your war, and here you shall etch your name across history, here you shall become legend.
Facts:
To steal one, the following things must happen:
You must attack the village (NO Raid!)
WIN the Attack
Destroy the treasury
An empty treasury lvl 10 MUST be in the village where that attack came from
Have a hero in an attack
If not, the next attack on that village, winning with a hero and empty treasury will take the building plan.
To build a WW, you must own a plan yourself (you = the WW village owner) from lvl 0 to 50, from 51 to 100 you need an additional plan in your alliance! Two plans in the WW village account would not work!
The construction plans are conquerable immediately when they appear to the server.
There will be a countdown in game, showing the exact time of the release, 5 days prior to the launch. ";
//bbcode = html code
$txt = preg_replace("/\[b\]/is",'<b>', $txt);
@@ -23,4 +52,4 @@ $txt = preg_replace("/\[\/u\]/is",'</u>', $txt);
//nl2br = enter
echo nl2br($txt);
?>
?>