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']);
+?>
+
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
-
-
-
-
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'];
}
- }
-?>
+
- Ok
-
-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