From 29b8e919683f382bc2de6b3d06468e9797efdd35 Mon Sep 17 00:00:00 2001 From: novgorodschi catalin Date: Thu, 21 May 2026 14:46:43 +0300 Subject: [PATCH] Last incremental refactor for Template/a2b Last incremental refactor for Template/a2b --- Templates/a2b/attack.tpl | 431 +++++++++++++++---------------------- Templates/a2b/newdorf.tpl | 149 +++++++------ Templates/a2b/search.tpl | 137 ++++++------ Templates/a2b/sendback.tpl | 222 ++++++++----------- 4 files changed, 418 insertions(+), 521 deletions(-) diff --git a/Templates/a2b/attack.tpl b/Templates/a2b/attack.tpl index 34c7b09e..658838f8 100644 --- a/Templates/a2b/attack.tpl +++ b/Templates/a2b/attack.tpl @@ -1,203 +1,117 @@ 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; -?> -

+$hasHero = !empty($process['t11']); +$colspan = $hasHero ? 11 : 10; +$kata = !empty($process['t8']); +?> +

+ + + + + + + + + + + +
Destination: (|)
Owner:getUserField($process['2'], 'username', 0); ?>
- +
+ + + + + + + + + + ' . $technology->getUnitName($i) . ''; + } + if ($hasHero) { + echo ''; + } + ?> + + + + + + + ' . $process['t11'] . ''; } ?> + + - + + + + + + + + - - - - - - - - - - - - - - - - - - -
Hero
Troops0'; } else { echo '>' . $process['t'.$i]; } ?>
Options + Scout resources and troops
+ Scout defences and troops +
Destination: (|)
Owner:getUserField($process['2'],'username',0); ?>
- - - - - - - - - - - - - - - - - - - - - - - getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" />"; - } if (!empty($process['t11'])){ - echo ""; - - }?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - ".$process['t11']."";} ?> - - - - - - - - - - - - - - - - - + + + - + getTypeLevel(16) == 20 && $process['t8'] >= 20): ?> + + + (will be attacked by catapult(s)) + - - - - + + + + + + + - echo"Warning: Catapult will ONLY shoot with a normal attack (they dont shoot with raids!)"; + + + + getWalkingTroopsTime($village->wid, $process[0], $session->uid, $session->tribe, $process, 1, 't'); + $time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime); ?> - - - + + + +
">
\"Hero\"
Troops0"; }else{ echo ">".$process['t1'];} ?>0"; }else{ echo ">".$process['t2'];} ?>0"; }else{ echo ">".$process['t3'];} ?>0"; }else{ echo ">".$process['t4'];} ?>0"; }else{ echo ">".$process['t5'];} ?>0"; }else{ echo ">".$process['t6'];} ?>0"; }else{ echo ">".$process['t7'];} ?>0"; }else{ $kata='1'; echo ">".$process['t8'];} ?>0"; }else{ echo ">".$process['t9'];} ?>0"; }else{ echo ">".$process['t10'];} ?>
Options">Scout resources and troops
- Scout defences and troops
Destination: - + - - getTypeLevel(16) == 20 && $process['t8'] >= 20) { ?> - - - (will be attacked by catapult(s)) -
Destination: - + +
Destination:Warning: Catapult will ONLY shoot with a normal attack (they dont shoot with raids!)
Arrived:
+
in getTimeFormat($time); ?>
+
at procMtime(date('U') + $time, 9) ?> hours
+
- + + + + + + - - - - - - Arrived: - - - - getWalkingTroopsTime($village->wid, $process[0], $session->uid, $session->tribe, $process, 1, 't'); - $time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime); - ?> - - - -
in getTimeFormat($time); ?>
- -
at procMtime(date('U') + $time, 9)?> hours
- - - - - - - - - - - - - - - - - - - - -hasBeginnerProtection($village->wid) == 1 && $database->hasBeginnerProtection($process['0']) == 0){ - echo"Caution: Attacking a player will lose the protection!"; + hasBeginnerProtection($village->wid) == 1 && $database->hasBeginnerProtection($process['0']) == 0) { + echo 'Caution: Attacking a player will lose the protection!'; } - if($database->hasBeginnerProtection($process['0']) == 1) { - echo"User presently has beginners protection"; + if ($database->hasBeginnerProtection($process['0']) == 1) { + echo 'User presently has beginners protection'; } else { -?> -

- - + ?> +

+
diff --git a/Templates/a2b/newdorf.tpl b/Templates/a2b/newdorf.tpl index 3f88903d..cac6fdaa 100644 --- a/Templates/a2b/newdorf.tpl +++ b/Templates/a2b/newdorf.tpl @@ -1,84 +1,97 @@ 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 '
';
-echo '
'; +$startUnit = ($session->tribe - 1) * 10 + 1; +$endUnit = $session->tribe * 10; +$hasResources = ($wood >= 750 && $clay >= 750 && $iron >= 750 && $crop >= 750); ?>

Found new village

-
- - - - - - - - - - - - - - tribe-1) * 10 + 1; $i <= $session->tribe * 10; $i++) { - echo ""; - } ?> - - - - 0"; - } + + + + + - if($settlers >= 3){ - echo ""; - }else{ - echo ""; - } - ?> - - - - - - - - - - - - - - -
username; ?>Found new village (|)
 getUnitName($i)."\" alt=\"".$technology->getUnitName($i)."\" />
Troops30
DurationDuration getTimeFormat($time); ?>
Resources - Lumber750 | - Clay750 | - Iron750 | - Crop750
-

-= 750 && $clay >= 750 && $iron >= 750 && $crop >= 750) { -?> - -Not enough resource"; -} -?> + + + + + + + + + + + + + + + + + 0'; + } + // a 10-a = coloniștii + echo $settlers >= 3 ? '' : ''; + ?> + + + + + + + + + + + + + + +
username; ?> + + Found new village (|) + +
 <?php echo $technology->getUnitName($i); ?>
Troops30
DurationDuration getTimeFormat($time); ?>
Resources + Lumber750 | + Clay750 | + Iron750 | + Crop750 +
+ +

+ + + + Not enough resource + +

-

- - diff --git a/Templates/a2b/search.tpl b/Templates/a2b/search.tpl index faffccb6..a0b1ee8c 100644 --- a/Templates/a2b/search.tpl +++ b/Templates/a2b/search.tpl @@ -1,73 +1,80 @@ 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']; } - } -?> - - - - - - - - - - - - - - -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'); } ?> - - -
- - - - Village: - -
- - - - or
- - - x: - - y: - -
+ + + + + + + + + + + + + + + + + +
+ + + Village: + +
+ + or
+ + + x: + + y: + +
- - -

getError("error"); ?>

+ + +

getError('error'); ?>

diff --git a/Templates/a2b/sendback.tpl b/Templates/a2b/sendback.tpl index e259ec03..715249e4 100644 --- a/Templates/a2b/sendback.tpl +++ b/Templates/a2b/sendback.tpl @@ -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'], + ], +]; ?> - -

Send units back

- +

Send units back

+ + + + + + + + + + + +
Destination: (|)
Owner:getUserField($to['owner'], 'username', 0)); ?>
- +
+ + + +
Send units back to
- + + + $row): ?> + + + + - + + + + + + + + + + +
+ <?php echo $technology->getUnitName($unitId); ?> + name="" value="" maxlength="6" type="text"> + () +
+ Hero + + () +
- Destination: + + + + + getWalkingTroopsTime($enforce['from'], $enforce['vref'], $to['owner'], $att_tribe, $enforce, 1); + $time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime); + ?> + + + +
Arrived: +
in getTimeFormat($time); ?>
+
at hours
+
- (|) - - - - - - Owner: - - getUserField($to['owner'],'username',0); ?> - - - - - - - - - - - - - - - - -
Send units back to
- - - "; - - ?> - - "; - - ?> - "; - - ?> - - - "; - - ?> - - - "; - - ?> - - "; - - ?> - "; - - ?> - "; - - ?> - - - "; - - ?> - "; - if($enforce['hero']>0){ - ?> - "; - } - ?> - - -
<?php echo $technology->getUnitName($start); ?> name="t1" value="" maxlength="6" type="text"> - (".$enforce['u'.$start].")<?php echo $technology->getUnitName($start + 3); ?> name="t4" value="" maxlength="6" type="text"> - (".$enforce['u'.($start + 3)].")<?php echo $technology->getUnitName($start + 6); ?> name="t7" value="" maxlength="6" type="text"> - (".$enforce['u'.($start + 6)].")<?php echo $technology->getUnitName($start + 8); ?> name="t9" value="" maxlength="6" type="text"> - (".$enforce['u'.($start + 8)].")
<?php echo $technology->getUnitName($start + 1); ?> name="t2" value="" maxlength="6" type="text"> - (".$enforce['u'.($start + 1)].")<?php echo $technology->getUnitName($start + 4); ?> name="t5" value="" maxlength="6" type="text"> - (".$enforce['u'.($start + 4)].")<?php echo $technology->getUnitName($start + 7); ?> name="t8" value="" maxlength="6" type="text"> - (".$enforce['u'.($start + 7)].")<?php echo $technology->getUnitName($start + 9); ?> name="t10" value="" maxlength="6" type="text"> - (".$enforce['u'.($start + 9)].")
<?php echo $technology->getUnitName($start + 2); ?> name="t3" value="" maxlength="6" type="text"> - (".$enforce['u'.($start + 2)].")<?php echo $technology->getUnitName($start + 5); ?> name="t6" value="" maxlength="6" type="text"> - (".$enforce['u'.($start + 5)].")Hero - (".$enforce['hero'].")
- - - - - - - getWalkingTroopsTime($enforce['from'], $enforce['vref'], $to['owner'], $att_tribe, $enforce, 1); - $time = $database->getArtifactsValueInfluence($session->uid, $village->wid, 2, $troopsTime); - ?> - - - - -
Arrived: -
in getTimeFormat($time); ?>
-
at hours
-
- - - - - - - - -

+ + + + +