Last incremental refactor for Template/a2b

Last incremental refactor for Template/a2b
This commit is contained in:
novgorodschi catalin
2026-05-21 14:46:43 +03:00
parent dd64b1e6c7
commit 29b8e91968
4 changed files with 418 additions and 521 deletions
+172 -259
View File
@@ -1,203 +1,117 @@
<?php
$ckey = $generator->generateRandStr(6);
if (!isset($process['t1']) || $process['t1'] == ''){ $t1 = 0; }else{ $t1 = $process['t1']; }
if (!isset($process['t2']) || $process['t2'] == ''){ $t2 = 0; }else{ $t2 = $process['t2']; }
if (!isset($process['t3']) || $process['t3'] == ''){ $t3 = 0; }else{ $t3 = $process['t3']; if ($session->tribe == 3) $scout=1; }
if (!isset($process['t4']) || $process['t4'] == ''){ $t4 = 0; }else{ $t4 = $process['t4']; if ($session->tribe == 1 || $session->tribe == 2 || $session->tribe == 4 || $session->tribe == 5) $scout=1; }
if (!isset($process['t5']) || $process['t5'] == ''){ $t5 = 0; }else{ $t5 = $process['t5']; }
if (!isset($process['t6']) || $process['t6'] == ''){ $t6 = 0; }else{ $t6 = $process['t6']; }
if (!isset($process['t7']) || $process['t7'] == ''){ $t7 = 0; }else{ $t7 = $process['t7']; }
if (!isset($process['t8']) || $process['t8'] == ''){ $t8 = 0; }else{ $t8 = $process['t8']; }
if (!isset($process['t9']) || $process['t9'] == ''){ $t9 = 0; }else{ $t9 = $process['t9']; }
if (!isset($process['t10']) || $process['t10'] == ''){ $t10 = 0; }else{ $t10 = $process['t10']; }
if (!isset($process['t11']) || $process['t11'] == ''){ $t11 = 0; }else{ $t11 = $process['t11']; $showhero=1; }
$totalunits = 0;
for($i = 1; $i <= 11; $i++){
$totalunits += (($i != 3 && $session->tribe == 3) ||
($i != 4 && $session->tribe != 3)) ? (!empty($process['t'.$i]) ? $process['t'.$i] : 0) : 0;
// --- 1. Normalizare trupe t1..t11 (păstrăm exact logica originală) ---
$t = [];
for ($i = 1; $i <= 11; $i++) {
$key = 't' . $i;
$t[$i] = (isset($process[$key]) && $process[$key] !== '') ? $process[$key] : 0;
}
if (isset($scout) && $scout == 1 && isset($totalunits) && $totalunits == 0 && $process['c'] != 2) {
// --- 2. Detectare scout / hero (exact ca originalul) ---
$scout = 0;
if (!empty($t[3]) && $session->tribe == 3) { $scout = 1; }
if (!empty($t[4]) && in_array($session->tribe, [1,2,4,5])) { $scout = 1; }
$showhero = !empty($t[11]) ? 1 : 0;
// --- 3. Total unități fără cercetași (pentru forțarea tipului de atac) ---
$totalunits = 0;
for ($i = 1; $i <= 11; $i++) {
$isScout = ($session->tribe == 3 && $i == 3) || ($session->tribe != 3 && $i == 4);
if (!$isScout) {
$totalunits += (!empty($process['t'.$i]) ? (int)$process['t'.$i] : 0);
}
}
// Dacă sunt doar cercetași și nu e întărire, forțează c=1 (Scout)
if ($scout == 1 && $totalunits == 0 && $process['c'] != 2) {
$process['c'] = 1;
}
$id = $database->addA2b($ckey, time(), $process['0'], $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $process['c']);
$actionType = (["Scout", "Reinforcement", "Normal attack", "Raid"])[$process['c'] - 1];
// --- 4. Salvare în a2b (aceeași ordine de parametri) ---
$id = $database->addA2b(
$ckey, time(), $process['0'],
$t[1], $t[2], $t[3], $t[4], $t[5], $t[6], $t[7], $t[8], $t[9], $t[10], $t[11],
$process['c']
);
$actionTypes = [1 => 'Scout', 2 => 'Reinforcement', 3 => 'Normal attack', 4 => 'Raid'];
$actionType = $actionTypes[(int)$process['c']] ?? 'Normal attack';
$uid = $session->uid;
$tribe = $session->tribe;
$start = ($tribe - 1) * 10 + 1;
$end = $tribe * 10;
?>
<h1><?php echo $actionType." to ".$process[1]; ?></h1>
$hasHero = !empty($process['t11']);
$colspan = $hasHero ? 11 : 10;
$kata = !empty($process['t8']);
?>
<h1><?php echo $actionType . " to " . $process[1]; ?></h1>
<form method="post" action="a2b.php">
<table id="short_info" cellpadding="1" cellspacing="1">
<tbody>
<tr>
<th>Destination:</th>
<td><a href="karte.php?d=<?php echo $process[0]; ?>&c=<?php echo $generator->getMapCheck($process[0]); ?>"><?php echo $process[1]; ?> (<?php echo $coor['x']; ?>|<?php echo $coor['y']; ?>)</a></td>
</tr>
<tr>
<th>Owner:</th>
<td><a href="spieler.php?uid=<?php echo $process['2']; ?>"><?php echo $database->getUserField($process['2'], 'username', 0); ?></a></td>
</tr>
</tbody>
</table>
<table id="short_info" cellpadding="1" cellspacing="1">
<table class="troop_details" cellpadding="1" cellspacing="1">
<thead>
<tr>
<td><?php echo $process[1]; ?></td>
<td colspan="<?php echo $colspan; ?>"><?php echo $actionType . " to " . $process['1']; ?></td>
</tr>
</thead>
<tbody class="units">
<tr>
<td></td>
<?php
for ($i = $start; $i <= $end; $i++) {
echo '<td><img src="img/x.gif" class="unit u' . $i . '" title="' . $technology->getUnitName($i) . '" alt="' . $technology->getUnitName($i) . '" /></td>';
}
if ($hasHero) {
echo '<td><img src="img/x.gif" class="unit uhero" title="Hero" alt="Hero" /></td>';
}
?>
</tr>
<tr>
<th>Troops</th>
<?php for ($i = 1; $i <= 10; $i++): ?>
<td <?php if (!isset($process['t'.$i]) || $process['t'.$i] == '') { echo 'class="none">0'; } else { echo '>' . $process['t'.$i]; } ?></td>
<?php endfor; ?>
<?php if ($hasHero) { echo '<td>' . $process['t11'] . '</td>'; } ?>
</tr>
</tbody>
<tbody>
<?php if ($process['c'] == 1): ?>
<tbody class="options">
<tr>
<th>Options</th>
<td colspan="<?php echo $colspan; ?>">
<input class="radio" name="spy" value="1" checked="checked" type="radio">Scout resources and troops<br>
<input class="radio" name="spy" value="2" type="radio">Scout defences and troops
</td>
</tr>
</tbody>
<?php endif; ?>
<tr>
<th>Destination:</th>
<td><a href="karte.php?d=<?php echo $process[0]; ?>&c=<?php echo $generator->getMapCheck($process[0]); ?>"><?php echo $process[1]; ?> (<?php echo $coor['x']; ?>|<?php echo $coor['y']; ?>)</a></td>
</tr>
<tr>
<th>Owner:</th>
<td><a href="spieler.php?uid=<?php echo $process['2']; ?>"><?php echo $database->getUserField($process['2'],'username',0); ?></a></td>
</tr>
</tbody>
</table>
<table class="troop_details" cellpadding="1" cellspacing="1">
<thead>
<tr>
<td><?php echo $process[1]; ?></td>
<td colspan="<?php if(!empty($process['t11'])){ echo"11"; }else{ echo"10"; } ?>"><?php echo $actionType." to ".$process['1']; ?></td>
</tr>
</thead>
<tbody class="units">
<tr>
<td></td>
<?php
for($i=$start;$i<=($end);$i++) {
echo "<td><img src=\"img/x.gif\" class=\"unit u$i\" title=\"".$technology->getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" /></td>";
} if (!empty($process['t11'])){
echo "<td><img src=\"img/x.gif\" class=\"unit uhero\" title=\"Hero\" alt=\"Hero\" /></td>";
}?>
</tr>
<tr>
<th>Troops</th>
<td <?php if (!isset($process['t1']) || $process['t1'] == ''){ echo "class=\"none\">0"; }else{ echo ">".$process['t1'];} ?></td>
<td <?php if (!isset($process['t2']) || $process['t2'] == ''){ echo "class=\"none\">0"; }else{ echo ">".$process['t2'];} ?></td>
<td <?php if (!isset($process['t3']) || $process['t3'] == ''){ echo "class=\"none\">0"; }else{ echo ">".$process['t3'];} ?></td>
<td <?php if (!isset($process['t4']) || $process['t4'] == ''){ echo "class=\"none\">0"; }else{ echo ">".$process['t4'];} ?></td>
<td <?php if (!isset($process['t5']) || $process['t5'] == ''){ echo "class=\"none\">0"; }else{ echo ">".$process['t5'];} ?></td>
<td <?php if (!isset($process['t6']) || $process['t6'] == ''){ echo "class=\"none\">0"; }else{ echo ">".$process['t6'];} ?></td>
<td <?php if (!isset($process['t7']) || $process['t7'] == ''){ echo "class=\"none\">0"; }else{ echo ">".$process['t7'];} ?></td>
<td <?php if (!isset($process['t8']) || $process['t8'] == ''){ echo "class=\"none\">0"; }else{ $kata='1'; echo ">".$process['t8'];} ?></td>
<td <?php if (!isset($process['t9']) || $process['t9'] == ''){ echo "class=\"none\">0"; }else{ echo ">".$process['t9'];} ?></td>
<td <?php if (!isset($process['t10']) || $process['t10'] == ''){ echo "class=\"none\">0"; }else{ echo ">".$process['t10'];} ?></td>
<?php if (!isset($process['t11']) || $process['t11'] == ''){ echo ""; }else{ echo "<td>".$process['t11']."</td>";} ?>
</tr>
</tbody>
<?php if ($process['c']==1){
?>
<tbody class="options">
<tr>
<th>Options</th>
<td colspan="<?php if(!empty($process['t11'])){ echo"11"; }else{ echo"10"; } ?>"><input class="radio" name="spy" value="1" checked="checked" type="radio">Scout resources and troops<br>
<input class="radio" name="spy" value="2" type="radio">Scout defences and troops </td>
</tr>
</tbody>
<?php } ?>
<?php if(isset($kata) && $process['c'] != 2){?><tr>
<?php if($process['c']== 3){ ?><tbody class="cata">
<?php if ($kata && $process['c'] != 2): ?>
<?php if ($process['c'] == 3): ?>
<tbody class="cata">
<tr>
<th>Destination:</th>
<td colspan="<?php echo !empty($process['t11']) ? 11 : 10; ?>">
<td colspan="<?php echo $colspan; ?>">
<select name="ctar1" class="dropdown">
<option value="0">Random</option>
<?php if($building->getTypeLevel(16) >= 5) { ?>
<optgroup label="Resources">
<option value="1">Woodcutter</option>
<option value="2">Clay Pit</option>
<option value="3">Iron Mine</option>
<option value="4">Cropland</option>
<option value="5">Sawmill</option>
<option value="6">Brickyard</option>
<option value="7">Iron Foundry</option>
<option value="8">Grain Mill</option>
<option value="9">Bakery</option>
</optgroup>
<?php } ?>
<?php if($building->getTypeLevel(16) >= 3) { ?>
<optgroup label="Infrastructure">
<option value="10">Warehouse</option>
<option value="11">Granary</option>
<?php if($building->getTypeLevel(16) >= 10) { ?>
<option value="15">Main building</option>
<option value="17">Marketplace</option>
<option value="18">Embassy</option>
<option value="24">Townhall</option>
<option value="25">Residence</option>
<option value="26">Palace</option>
<option value="27">Treasury</option>
<option value="28">Trade office</option>
<option value="35">Brewery</option>
<?php } ?>
<option value="38">Great warehouse</option>
<option value="39">Great granary</option>
<option value="40">Wonder of the World</option>
</optgroup>
<?php } ?>
<?php if($building->getTypeLevel(16) >= 10) { ?>
<optgroup label="Military">
<option value="12">Blacksmith</option>
<option value="13">Armoury</option>
<option value="14">Tournament square</option>
<option value="16">Rally point</option>
<option value="19">Barracks</option>
<option value="20">Stable</option>
<option value="21">Workshop</option>
<option value="22">Academy</option>
<option value="29">Great barracks</option>
<option value="30">Great stable</option>
<option value="37">Hero's mansion</option>
</optgroup>
<?php } ?>
</select>
<?php if($building->getTypeLevel(16) == 20 && $process['t8'] >= 20) { ?>
<select name="ctar2" class="dropdown">
<option value="0">-</option>
<option value="99">Random</option>
<?php if($building->getTypeLevel(16) >= 5) { ?>
<?php if ($building->getTypeLevel(16) >= 5): ?>
<optgroup label="Resources">
<option value="1">Woodcutter</option>
<option value="2">Clay Pit</option>
@@ -205,34 +119,32 @@ $end = $tribe * 10;
<option value="4">Cropland</option>
<option value="5">Sawmill</option>
<option value="6">Brickyard</option>
<option value="7">Iron Foundry</option>
<option value="8">Grain Mill</option>
<option value="9">Bakery</option>
</optgroup>
<?php } ?>
<?php if($building->getTypeLevel(16) >= 3) { ?>
<?php endif; ?>
<?php if ($building->getTypeLevel(16) >= 3): ?>
<optgroup label="Infrastructure">
<option value="10">Warehouse</option>
<option value="11">Granary</option>
<?php if($building->getTypeLevel(16) >= 10) { ?>
<?php if ($building->getTypeLevel(16) >= 10): ?>
<option value="15">Main building</option>
<option value="17">Marketplace</option>
<option value="18">Embassy</option>
<option value="24">Townhall</option>
<option value="25">Residence</option>
<option value="26">Palace</option>
<option value="27">Treasury</option>
<option value="28">Trade office</option>
<option value="35">Brewery</option>
<?php } ?>
<?php endif; ?>
<option value="38">Great warehouse</option>
<option value="39">Great granary</option>
<option value="40">Wonder of the World</option>
<option value="40">Wonder of the World</option>
</optgroup>
<?php } ?>
<?php if($building->getTypeLevel(16) >= 10) { ?>
<?php endif; ?>
<?php if ($building->getTypeLevel(16) >= 10): ?>
<optgroup label="Military">
<option value="12">Blacksmith</option>
<option value="13">Armoury</option>
@@ -241,90 +153,91 @@ $end = $tribe * 10;
<option value="19">Barracks</option>
<option value="20">Stable</option>
<option value="21">Workshop</option>
<option value="22">Academy</option>
<option value="29">Great barracks</option>
<option value="30">Great stable</option>
<option value="37">Hero's mansion</option>
</optgroup>
<?php } ?>
<?php endif; ?>
</select>
<?php }?>
<span class="info">(will be attacked by catapult(s))</span>
</td>
<?php if ($building->getTypeLevel(16) == 20 && $process['t8'] >= 20): ?>
<select name="ctar2" class="dropdown">
<option value="0">-</option>
<option value="99">Random</option>
<?php if ($building->getTypeLevel(16) >= 5): ?>
<optgroup label="Resources">
<option value="1">Woodcutter</option><option value="2">Clay Pit</option><option value="3">Iron Mine</option>
<option value="4">Cropland</option><option value="5">Sawmill</option><option value="6">Brickyard</option>
<option value="7">Iron Foundry</option><option value="8">Grain Mill</option><option value="9">Bakery</option>
</optgroup>
<?php endif; ?>
<?php if ($building->getTypeLevel(16) >= 3): ?>
<optgroup label="Infrastructure">
<option value="10">Warehouse</option><option value="11">Granary</option>
<?php if ($building->getTypeLevel(16) >= 10): ?>
<option value="15">Main building</option><option value="17">Marketplace</option><option value="18">Embassy</option>
<option value="24">Townhall</option><option value="25">Residence</option><option value="26">Palace</option>
<option value="27">Treasury</option><option value="28">Trade office</option><option value="35">Brewery</option>
<?php endif; ?>
<option value="38">Great warehouse</option><option value="39">Great granary</option><option value="40">Wonder of the World</option>
</optgroup>
<?php endif; ?>
<?php if ($building->getTypeLevel(16) >= 10): ?>
<optgroup label="Military">
<option value="12">Blacksmith</option><option value="13">Armoury</option><option value="14">Tournament square</option>
<option value="16">Rally point</option><option value="19">Barracks</option><option value="20">Stable</option>
<option value="21">Workshop</option><option value="22">Academy</option><option value="29">Great barracks</option>
<option value="30">Great stable</option><option value="37">Hero's mansion</option>
</optgroup>
<?php endif; ?>
</select>
<?php endif; ?>
<span class="info">(will be attacked by catapult(s))</span>
</td>
</tr>
</tbody><?PHP
}
else if($process['c']=='4')
{
?><tbody class="infos">
<tr>
<th>Destination:</th>
<td colspan="<?php echo !empty($process['t11']) ? 11 : 10; ?>">
<?php
</tbody>
<?php elseif ($process['c'] == '4'): ?>
<tbody class="infos">
<tr>
<th>Destination:</th>
<td colspan="<?php echo $colspan; ?>">Warning: Catapult will <b>ONLY</b> shoot with a normal attack (they dont shoot with raids!)</td>
</tr>
</tbody>
<?php endif; ?>
<?php endif; ?>
echo"Warning: Catapult will <b>ONLY</b> shoot with a normal attack (they dont shoot with raids!)";
<tbody class="infos">
<tr>
<th>Arrived:</th>
<?php
$troopsTime = $units->getWalkingTroopsTime($village->wid, $process[0], $session->uid, $session->tribe, $process, 1, 't');
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
?>
</td>
</tr>
<?php
}
?>
<td colspan="<?php echo $colspan; ?>">
<div class="in">in <?php echo $generator->getTimeFormat($time); ?></div>
<div class="at">at <span id="tp2"><?php echo $generator->procMtime(date('U') + $time, 9) ?></span><span> hours</span></div>
</td>
</tr>
</tbody>
</table>
<?php } ?>
<input name="timestamp" value="<?php echo time(); ?>" type="hidden">
<input name="timestamp_checksum" value="<?php echo $ckey; ?>" type="hidden">
<input name="ckey" value="<?php echo $id; ?>" type="hidden">
<input name="id" value="39" type="hidden">
<input name="a" value="533374" type="hidden">
<input name="c" value="3" type="hidden">
<tbody class="infos">
<tr>
<th>Arrived:</th>
<?php
$troopsTime = $units->getWalkingTroopsTime($village->wid, $process[0], $session->uid, $session->tribe, $process, 1, 't');
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
?>
<td colspan="<?php echo !empty($process['t11']) ? 11 : 10; ?>">
<div class="in">in <?php echo $generator->getTimeFormat($time); ?></div>
<div class="at">at <span id="tp2"> <?php echo $generator->procMtime(date('U') + $time, 9)?></span><span> hours</span></div>
</td>
</tr>
</tbody>
</table>
<input name="timestamp" value="<?php echo time(); ?>" type="hidden">
<input name="timestamp_checksum" value="<?php echo $ckey; ?>" type="hidden">
<input name="ckey" value="<?php echo $id; ?>" type="hidden">
<input name="id" value="39" type="hidden">
<input name="a" value="533374" type="hidden">
<input name="c" value="3" type="hidden">
<?php
if($database->hasBeginnerProtection($village->wid) == 1 && $database->hasBeginnerProtection($process['0']) == 0){
echo"<span style=\"color: #DD0000\"><b>Caution:</b> Attacking a player will lose the protection!</span>";
<?php
if ($database->hasBeginnerProtection($village->wid) == 1 && $database->hasBeginnerProtection($process['0']) == 0) {
echo '<span style="color: #DD0000"><b>Caution:</b> Attacking a player will lose the protection!</span>';
}
if($database->hasBeginnerProtection($process['0']) == 1) {
echo"<b>User presently has beginners protection</b>";
if ($database->hasBeginnerProtection($process['0']) == 1) {
echo '<b>User presently has beginners protection</b>';
} else {
?>
<p class="btn"><input value="ok" name="s1" id="btn_ok"
class="dynamic_img " src="img/x.gif" alt="OK" type="image" onclick="if (this.disabled==false) {document.getElementsByTagName('form')[0].submit();} this.disabled=true;" onLoad="this.disabled=false;"></p>
<?php } ?>
?>
<p class="btn"><input value="ok" name="s1" id="btn_ok" class="dynamic_img " src="img/x.gif" alt="OK" type="image" onclick="if (this.disabled==false) {document.getElementsByTagName('form')[0].submit();} this.disabled=true;" onLoad="this.disabled=false;"></p>
<?php } ?>
</form>
</div>
+81 -68
View File
@@ -1,84 +1,97 @@
<?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){
//-- Prevent founding if not enough settlers or invalid/occupied tile
//-- fix by AL-Kateb - Simplified by iopietro
$settlers = (int)($village->unitarray['u' . $session->tribe . '0'] ?? 0);
if ($settlers < 3 || !isset($_GET['id']) || !is_numeric($_GET['id'])) {
header("location: dorf1.php");
exit;
}
//--
$newvillage = $database->getMInfo((int)$_GET['id']);
// păstrăm exact verificările originale
if (!$newvillage || $newvillage['id'] == 0 || $newvillage['occupied'] > 0 || $newvillage['oasistype'] > 0) {
header("location: dorf1.php");
exit;
}
// resurse rotunjite
$wood = round($village->awood);
$clay = round($village->aclay);
$iron = round($village->airon);
$crop = round($village->acrop);
// timp de mers pentru coloniști (3 settlers = unitatea 10 a tribului)
$troopsTime = $units->getWalkingTroopsTime($village->wid, $newvillage['id'], 0, 0, [300], 0);
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
echo '<pre>';
echo '</pre>';
$startUnit = ($session->tribe - 1) * 10 + 1;
$endUnit = $session->tribe * 10;
$hasResources = ($wood >= 750 && $clay >= 750 && $iron >= 750 && $crop >= 750);
?>
<h1>Found new village</h1>
<form method="POST" action="build.php">
<input type="hidden" name="a" value="new" />
<input type="hidden" name="c" value="5" />
<input type="hidden" name="s" value="<?php echo $_GET['id']; ?>" />
<input type="hidden" name="id" value="39" />
<table class="troop_details" cellpadding="1" cellspacing="1">
<thead>
<tr>
<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++) {
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++) {
echo "<td class=\"none\">0</td>";
}
<form method="POST" action="build.php">
<input type="hidden" name="a" value="new" />
<input type="hidden" name="c" value="5" />
<input type="hidden" name="s" value="<?php echo (int)$_GET['id']; ?>" />
<input type="hidden" name="id" value="39" />
if($settlers >= 3){
echo "<td>3</td>";
}else{
echo "<td class=\"none\">0</td>";
}
?>
</tr>
</tbody>
<tbody class="infos">
<tr>
<th>Duration</th>
<td colspan="10"><img class="clock" src="img/x.gif" alt="Duration" title="Duration" /> <?php echo $generator->getTimeFormat($time); ?></td>
</tr>
</tbody>
<tbody class="infos">
<tr>
<th>Resources</th>
<td colspan="10">
<img class="r1" src="img/x.gif" alt="Lumber" title="Wood" />750 |
<img class="r2" src="img/x.gif" alt="Clay" title="Clay" />750 |
<img class="r3" src="img/x.gif" alt="Iron" title="Iron" />750 |
<img class="r4" src="img/x.gif" alt="Crop" title="Crop" />750</td>
</tr>
</tbody>
</table>
<p class="btn">
<?php
if ($wood >= 750 && $clay >= 750 && $iron >= 750 && $crop >= 750) {
?>
<button value="ok" name="s1" id="btn_ok" class="trav_buttons" alt="OK" onclick="this.disabled=true;this.form.submit();" /> Ok </button>
<?php
} else {
echo "<span class=\"c2\"><b>Not enough resource</b></span>";
}
?>
<table class="troop_details" cellpadding="1" cellspacing="1">
<thead>
<tr>
<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 = $startUnit; $i <= $endUnit; $i++): ?>
<td><img src="img/x.gif" class="unit u<?php echo $i; ?>" title="<?php echo $technology->getUnitName($i); ?>" alt="<?php echo $technology->getUnitName($i); ?>" /></td>
<?php endfor; ?>
</tr>
<tr>
<th>Troops</th>
<?php
// primele 9 unități = 0
for ($i = 1; $i <= 9; $i++) {
echo '<td class="none">0</td>';
}
// a 10-a = coloniștii
echo $settlers >= 3 ? '<td>3</td>' : '<td class="none">0</td>';
?>
</tr>
</tbody>
<tbody class="infos">
<tr>
<th>Duration</th>
<td colspan="10"><img class="clock" src="img/x.gif" alt="Duration" title="Duration" /> <?php echo $generator->getTimeFormat($time); ?></td>
</tr>
</tbody>
<tbody class="infos">
<tr>
<th>Resources</th>
<td colspan="10">
<img class="r1" src="img/x.gif" alt="Lumber" title="Wood" />750 |
<img class="r2" src="img/x.gif" alt="Clay" title="Clay" />750 |
<img class="r3" src="img/x.gif" alt="Iron" title="Iron" />750 |
<img class="r4" src="img/x.gif" alt="Crop" title="Crop" />750
</td>
</tr>
</tbody>
</table>
<p class="btn">
<?php if ($hasResources): ?>
<button value="ok" name="s1" id="btn_ok" class="trav_buttons" alt="OK" onclick="this.disabled=true;this.form.submit();">Ok</button>
<?php else: ?>
<span class="c2"><b>Not enough resource</b></span>
<?php endif; ?>
</p>
</form>
</p>
</div>
+72 -65
View File
@@ -1,73 +1,80 @@
<?php
if ( !empty( $form ) && $form->valuearray ) {
if ( !empty( $form->valuearray['disabled'] ) ) {
$disabled = $form->valuearray['disabled'];
// -- preluăm stările disabled din form (păstrăm exact valorile originale)
$disabled = '';
$disabledr = '';
if (!empty($form) && !empty($form->valuearray)) {
if (!empty($form->valuearray['disabled'])) {
$disabled = $form->valuearray['disabled'];
}
if ( !empty( $form->valuearray['disabledr'] ) ) {
$disabledr = $form->valuearray['disabledr'];
if (!empty($form->valuearray['disabledr'])) {
$disabledr = $form->valuearray['disabledr'];
}
}
?><table id="coords" cellpadding="1" cellspacing="1">
<input type="hidden" name="disabledr" value="<?php echo (isset($disabledr) ? $disabledr : ''); ?>">
<input type="hidden" name="disabled" value="<?php echo (isset($disabled) ? $disabled : ''); ?>">
<tbody><tr>
<td class="sel">
<label>
<input class="radio" name="c" <?php if ( ( !isset($disabledr) || !$disabledr ) && ( !isset($checked) || !$checked ) ) {?> checked=checked <?php }?>value="2" type="radio" <?php echo (isset($disabledr) ? $disabledr : ''); ?>>
Reinforcement
</label>
</td>
<td class="vil">
<span>Village:</span>
<input class="text" name="dname" value="<?php echo $form->getValue('dname');?>" maxlength="20" type="text" >
</td>
</tr>
<tr>
<td class="sel">
<label>
<input class="radio" name="c" value="3" type="radio" <?php echo $disabled; ?>>
Normal attack
</label>
</td>
<td class="or">
or </td>
</tr>
<tr>
<td class="sel">
<label>
<input class="radio" name="c" <?php
if ( ( isset($disabledr) && $disabledr ) && ( isset($disabled) && $disabled ) ) {
$checked = ' checked="checked"';
}
echo ( ( isset($checked) ? $checked : '' ) );
?> value="4" type="radio">
Raid
</label>
</td>
<?php
if(isset($_GET['z'])){
$coor = $database->getCoor($_GET['z']);
}
else{
$coor['x']=$form->getValue("x");
$coor['y']=$form->getValue("y");
// logica originală pentru checked
$reinforcementChecked = (empty($disabledr));
$raidChecked = (!empty($disabledr) && !empty($disabled));
// dacă ambele sunt disabled, reinforcement nu mai e checked (ca în original)
if ($raidChecked) {
$reinforcementChecked = false;
}
// coordonate
if (isset($_GET['z'])) {
$coor = $database->getCoor($_GET['z']);
} else {
$coor['x'] = $form->getValue('x');
$coor['y'] = $form->getValue('y');
}
?>
<td class="target">
<span>x:</span>
<input class="text" name="x" value="<?php echo $coor['x']; ?>" maxlength="4" type="text">
<span>y:</span>
<input class="text" name="y" value="<?php echo $coor['y']; ?>" maxlength="4" type="text">
</td>
</tr>
</tbody></table>
<table id="coords" cellpadding="1" cellspacing="1">
<input type="hidden" name="disabledr" value="<?php echo htmlspecialchars($disabledr ?? '', ENT_QUOTES); ?>">
<input type="hidden" name="disabled" value="<?php echo htmlspecialchars($disabled ?? '', ENT_QUOTES); ?>">
<tbody>
<tr>
<td class="sel">
<label>
<input class="radio" name="c" value="2" type="radio"
<?php if ($reinforcementChecked) echo 'checked="checked"'; ?>
<?php echo $disabledr; ?>>
Reinforcement
</label>
</td>
<td class="vil">
<span>Village:</span>
<input class="text" name="dname" value="<?php echo htmlspecialchars($form->getValue('dname'), ENT_QUOTES); ?>" maxlength="20" type="text">
</td>
</tr>
<tr>
<td class="sel">
<label>
<input class="radio" name="c" value="3" type="radio" <?php echo $disabled; ?>>
Normal attack
</label>
</td>
<td class="or">or</td>
</tr>
<tr>
<td class="sel">
<label>
<input class="radio" name="c" value="4" type="radio"
<?php if ($raidChecked) echo 'checked="checked"'; ?>>
Raid
</label>
</td>
<td class="target">
<span>x:</span>
<input class="text" name="x" value="<?php echo htmlspecialchars($coor['x'] ?? '', ENT_QUOTES); ?>" maxlength="4" type="text">
<span>y:</span>
<input class="text" name="y" value="<?php echo htmlspecialchars($coor['y'] ?? '', ENT_QUOTES); ?>" maxlength="4" type="text">
</td>
</tr>
</tbody>
</table>
<button value="ok" name="s1" id="btn_ok" class="trav_buttons" alt="OK" onclick="this.disabled=true;this.form.submit();" /> Ok </button>
</form>
<p class="error"><?php echo $form->getError("error"); ?></p>
<button value="ok" name="s1" id="btn_ok" class="trav_buttons" alt="OK" onclick="this.disabled=true;this.form.submit();">Ok</button>
</form>
<p class="error"><?php echo $form->getError('error'); ?></p>
</div>
+93 -129
View File
@@ -3,144 +3,108 @@ $to = $database->getVillage($enforce['from']);
$fromcoor = $database->getCoor($enforce['from']);
$tocoor = $database->getCoor($enforce['vref']);
$att_tribe = $database->getUserField($to['owner'],'tribe',0);
$att_tribe = (int)$database->getUserField($to['owner'], 'tribe', 0);
$start = ($att_tribe - 1) * 10 + 1;
$end = $att_tribe * 10;
$toBaseId = $generator->getBaseID($fromcoor['x'], $fromcoor['y']);
$toMapCheck = $generator->getMapCheck($toBaseId);
// layout exact ca în original (pentru CSS)
$layout = [
[
['o' => 0, 't' => 1, 'class' => 'line-first column-first large'],
['o' => 3, 't' => 4, 'class' => 'line-first large'],
['o' => 6, 't' => 7, 'class' => 'line-first regular'],
['o' => 8, 't' => 9, 'class' => 'line-first column-last small'],
],
[
['o' => 1, 't' => 2, 'class' => 'column-first large'],
['o' => 4, 't' => 5, 'class' => 'large'],
['o' => 7, 't' => 8, 'class' => 'regular'],
['o' => 9, 't' => 10, 'class' => 'column-last small'],
],
[
['o' => 2, 't' => 3, 'class' => 'line-last column-first large'],
['o' => 5, 't' => 6, 'class' => 'line-last large'],
],
];
?>
<h1>Send units back</h1>
<h1>Send units back</h1>
<form method="POST" name="snd" action="a2b.php">
<table id="short_info" cellpadding="1" cellspacing="1">
<tbody>
<tr>
<th>Destination:</th>
<td><a href="karte.php?d=<?php echo $toBaseId; ?>&amp;c=<?php echo $toMapCheck; ?>"><?php echo htmlspecialchars($to['name']); ?> (<?php echo $fromcoor['x']; ?>|<?php echo $fromcoor['y']; ?>)</a></td>
</tr>
<tr>
<th>Owner:</th>
<td><a href="spieler.php?uid=<?php echo $to['owner']; ?>"><?php echo htmlspecialchars($database->getUserField($to['owner'], 'username', 0)); ?></a></td>
</tr>
</tbody>
</table>
<table id="short_info" cellpadding="1" cellspacing="1">
<table class="troop_details" cellpadding="1" cellspacing="1">
<thead>
<tr><td colspan="10">Send units back to <?php echo htmlspecialchars($to['name']); ?></td></tr>
</thead>
</table>
<tbody>
<table id="troops" cellpadding="1" cellspacing="1">
<tbody>
<?php foreach ($layout as $rowIndex => $row): ?>
<tr>
<?php foreach ($row as $cell):
$unitId = $start + $cell['o'];
$tName = 't' . $cell['t'];
$value = (int)($enforce['u' . $unitId] ?? 0);
$disabled = $value <= 0 ? ' disabled="disabled"' : '';
?>
<td class="<?php echo $cell['class']; ?>">
<img class="unit u<?php echo $unitId; ?>" src="img/x.gif" title="<?php echo $technology->getUnitName($unitId); ?>" alt="<?php echo $technology->getUnitName($unitId); ?>">
<input class="text"<?php echo $disabled; ?> name="<?php echo $tName; ?>" value="<?php echo $value; ?>" maxlength="6" type="text">
<span class="none">(<?php echo $value; ?>)</span>
</td>
<?php endforeach; ?>
<tr>
<?php if ($rowIndex === 2): // rândul 3 ?>
<?php if (!empty($enforce['hero'])): ?>
<td class="line-last large">
<img class="unit uhero" src="img/x.gif" title="Hero" alt="Hero">
<input class="text" name="t11" value="<?php echo (int)$enforce['hero']; ?>" maxlength="6" type="text">
<span class="none">(<?php echo (int)$enforce['hero']; ?>)</span>
</td>
<?php endif; ?>
<td class="line-last regular"></td>
<td class="line-last column-last"></td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<th>Destination:</th>
<table class="troop_details" cellpadding="1" cellspacing="1">
<tbody class="infos">
<tr>
<th>Arrived:</th>
<?php
$troopsTime = $units->getWalkingTroopsTime($enforce['from'], $enforce['vref'], $to['owner'], $att_tribe, $enforce, 1);
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
?>
<td colspan="10">
<div class="in">in <?php echo $generator->getTimeFormat($time); ?></div>
<div class="at">at <span id="tp2"><?php echo date("H:i:s", time() + $time); ?></span><span> hours</span></div>
</td>
</tr>
</tbody>
</table>
<td><a href="karte.php?d=<?php echo $generator->getBaseID($fromcoor['x'],$fromcoor['y']); ?>&amp;c=<?php echo $generator->getMapCheck($generator->getBaseID($fromcoor['x'],$fromcoor['y'])); ?>"><?php echo $to['name']; ?> (<?php echo $fromcoor['x']; ?>|<?php echo $fromcoor['y']; ?>)</a></td>
</tr>
<tr>
<th>Owner:</th>
<td><a href="spieler.php?uid=<?php echo $to['owner']; ?>"><?php echo $database->getUserField($to['owner'],'username',0); ?></a></td>
</tr>
</tbody>
</table>
<table class="troop_details" cellpadding="1" cellspacing="1">
<thead>
<tr>
<td colspan="10">Send units back to <?php echo $to['name']; ?></td>
</tr>
</thead>
</table>
<table id="troops" cellpadding="1" cellspacing="1">
<tbody><tr>
<td class="line-first column-first large"><img class="unit u<?php echo $start; ?>" src="img/x.gif" title="<?php echo $technology->getUnitName($start); ?>" alt="<?php echo $technology->getUnitName($start); ?>"> <input class="text" <?php if ($enforce['u'.$start] <= 0) {echo ' disabled="disabled"';}?> name="t1" value="<?php echo $enforce['u'.$start]; ?>" maxlength="6" type="text">
<?php
echo"<span class=\"none\">(".$enforce['u'.$start].")</span></td>";
?>
<td class="line-first large"><img class="unit u<?php echo $start + 3; ?>" src="img/x.gif" title="<?php echo $technology->getUnitName($start + 3); ?>" alt="<?php echo $technology->getUnitName($start + 3); ?>"> <input class="text" <?php if ($enforce['u'.($start + 3)] <= 0) {echo ' disabled="disabled"';}?> name="t4" value="<?php echo $enforce['u'.($start + 3)]; ?>" maxlength="6" type="text">
<?php
echo"<span class=\"none\">(".$enforce['u'.($start + 3)].")</span></td>";
?>
<td class="line-first regular"><img class="unit u<?php echo $start + 6; ?>" src="img/x.gif" title="<?php echo $technology->getUnitName($start + 6); ?>" alt="<?php echo $technology->getUnitName($start + 6); ?>"> <input class="text" <?php if ($enforce['u'.($start + 6)] <= 0) {echo ' disabled="disabled"';}?> name="t7" value="<?php echo $enforce['u'.($start + 6)]; ?>" maxlength="6" type="text">
<?php
echo"<span class=\"none\">(".$enforce['u'.($start + 6)].")</span></td>";
?>
<td class="line-first column-last small"><img class="unit u<?php echo $start + 8; ?>" src="img/x.gif" title="<?php echo $technology->getUnitName($start + 8); ?>" alt="<?php echo $technology->getUnitName($start + 8); ?>"> <input class="text" <?php if ($enforce['u'.($start + 8)] <= 0) {echo ' disabled="disabled"';}?> name="t9" value="<?php echo $enforce['u'.($start + 8)]; ?>" maxlength="6" type="text">
<?php
echo"<span class=\"none\">(".$enforce['u'.($start + 8)].")</span></td>";
?>
</tr>
<tr>
<td class="column-first large"><img class="unit u<?php echo $start + 1; ?>" src="img/x.gif" title="<?php echo $technology->getUnitName($start + 1); ?>" alt="<?php echo $technology->getUnitName($start + 1); ?>"> <input class="text" <?php if ($enforce['u'.($start + 1)] <= 0) {echo ' disabled="disabled"';}?> name="t2" value="<?php echo $enforce['u'.($start + 1)]; ?>" maxlength="6" type="text">
<?php
echo"<span class=\"none\">(".$enforce['u'.($start + 1)].")</span></td>";
?>
<td class="large"><img class="unit u<?php echo $start + 4; ?>" src="img/x.gif" title="<?php echo $technology->getUnitName($start + 4); ?>" alt="<?php echo $technology->getUnitName($start + 4); ?>"> <input class="text" <?php if ($enforce['u'.($start + 4)] <= 0) {echo ' disabled="disabled"';}?> name="t5" value="<?php echo $enforce['u'.($start + 4)]; ?>" maxlength="6" type="text">
<?php
echo"<span class=\"none\">(".$enforce['u'.($start + 4)].")</span></td>";
?>
<td class="regular"><img class="unit u<?php echo $start + 7; ?>" src="img/x.gif" title="<?php echo $technology->getUnitName($start + 7); ?>" alt="<?php echo $technology->getUnitName($start + 7); ?>"> <input class="text" <?php if ($enforce['u'.($start + 7)] <= 0) {echo ' disabled="disabled"';}?> name="t8" value="<?php echo $enforce['u'.($start + 7)]; ?>" maxlength="6" type="text">
<?php
echo"<span class=\"none\">(".$enforce['u'.($start + 7)].")</span></td>";
?>
<td class="column-last small"><img class="unit u<?php echo $start + 9; ?>" src="img/x.gif" title="<?php echo $technology->getUnitName($start + 9); ?>" alt="<?php echo $technology->getUnitName($start + 9); ?>"> <input class="text" <?php if ($enforce['u'.($start + 9)] <= 0) {echo ' disabled="disabled"';}?> name="t10" value="<?php echo $enforce['u'.($start + 9)]; ?>" maxlength="6" type="text">
<?php
echo"<span class=\"none\">(".$enforce['u'.($start + 9)].")</span></td>";
?>
</tr>
<tr>
<td class="line-last column-first large"><img class="unit u<?php echo $start + 2; ?>" src="img/x.gif" title="<?php echo $technology->getUnitName($start + 2); ?>" alt="<?php echo $technology->getUnitName($start + 2); ?>"> <input class="text" <?php if ($enforce['u'.($start + 2)] <= 0) {echo ' disabled="disabled"';}?> name="t3" value="<?php echo $enforce['u'.($start + 2)]; ?>" maxlength="6" type="text">
<?php
echo"<span class=\"none\">(".$enforce['u'.($start + 2)].")</span></td>";
?>
<td class="line-last large"><img class="unit u<?php echo $start + 5; ?>" src="img/x.gif" title="<?php echo $technology->getUnitName($start + 5); ?>" alt="<?php echo $technology->getUnitName($start + 5); ?>"> <input class="text" <?php if ($enforce['u'.($start + 5)] <= 0) {echo ' disabled="disabled"';}?> name="t6" value="<?php echo $enforce['u'.($start + 5)]; ?>" maxlength="6" type="text">
<?php
echo"<span class=\"none\">(".$enforce['u'.($start + 5)].")</span></td>";
if($enforce['hero']>0){
?>
<td class="line-last large"><img class="unit uhero" src="img/x.gif" title="Hero" alt="Hero"> <input class="text" name="t11" value="<?php echo $enforce['hero']; ?>" maxlength="6" type="text">
<?php
echo"<span class=\"none\">(".$enforce['hero'].")</span></td>";
}
?>
<td class="line-last regular"></td>
<td class="line-last column-last"></td> </tr>
</tbody></table>
<table class="troop_details" cellpadding="1" cellspacing="1">
<tbody class="infos">
<tr>
<th>Arrived:</th>
<?php
$troopsTime = $units->getWalkingTroopsTime($enforce['from'], $enforce['vref'], $to['owner'], $att_tribe, $enforce, 1);
$time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime);
?>
<td colspan="10">
<div class="in">in <?php echo $generator->getTimeFormat($time); ?></div>
<div class="at">at <span id="tp2"> <?php echo date("H:i:s",time() + $time)?></span><span> hours</span></div>
</td>
</tr>
</tbody>
</table>
<input name="ckey" value="<?php echo $ckey; ?>" type="hidden">
<input name="id" value="39" type="hidden">
<input name="a" value="533374" type="hidden">
<input name="c" value="8" type="hidden">
<p class="btn"><input value="ok" name="s1" id="btn_ok" class="dynamic_img " src="img/x.gif" alt="OK" type="image" onclick="if (this.disabled==false) {document.getElementsByTagName('form')[0].submit();} this.disabled=true;" onLoad="this.disabled=false;"></p>
<input name="ckey" value="<?php echo $ckey; ?>" type="hidden">
<input name="id" value="39" type="hidden">
<input name="a" value="533374" type="hidden">
<input name="c" value="8" type="hidden">
<p class="btn"><input value="ok" name="s1" id="btn_ok" class="dynamic_img " src="img/x.gif" alt="OK" type="image" onclick="if (this.disabled==false) {document.getElementsByTagName('form')[0].submit();} this.disabled=true;" onLoad="this.disabled=false;"></p>
</form>
</div>