This commit is contained in:
2026-04-28 23:08:35 +03:00
parent 53f1176ef8
commit 76ab83620b
4 changed files with 48 additions and 15 deletions

View File

@@ -74,16 +74,43 @@ function gatherState() {
} catch (e) { log(`storage capacity lookup failed: ${e}`); } } catch (e) { log(`storage capacity lookup failed: ${e}`); }
// ---- Market / Trade capacity ----------------------------------------- // ---- Market / Trade capacity -----------------------------------------
// Uses multiple fallback paths to robustly read capacity across game versions.
let marketCapacity = 0; let marketCapacity = 0;
let availableTradeCapacity = 0; let availableTradeCapacity = 0;
try { try {
const marketLevel = buildings.market ?? 0; const marketLevel = buildings.market ?? 0;
const gd = uw.GameData?.buildingData?.market; const gd = uw.GameData?.buildingData?.market;
marketCapacity = gd?.capacity_per_level?.[marketLevel] || 0; if (gd) {
if (buildings.trade_office && buildings.trade_office > 0) { // Try various key names the game uses across versions
marketCapacity += (uw.GameData?.buildingData?.trade_office?.capacity_extra_per_level || 500) * marketLevel; marketCapacity =
gd?.capacity_per_level?.[marketLevel] ||
gd?.max_capacity?.[marketLevel] ||
gd?.merchant_count?.[marketLevel] ||
gd?.merchants?.[marketLevel] ||
0;
}
// Try the town object's built-in method first (most accurate)
if (town.getTradeCapacity) {
marketCapacity = town.getTradeCapacity() || marketCapacity;
}
// Available = total minus what is already used by pending trades
if (town.getAvailableTradeCapacity) {
availableTradeCapacity = town.getAvailableTradeCapacity() ?? marketCapacity;
} else {
// Fallback: read from trade collection
let usedCapacity = 0;
try {
const tradeColl = uw.MM.getOnlyCollectionByName('Trade');
if (tradeColl) {
tradeColl.models.forEach(m => {
if (String(m.attributes?.town_id) === String(town.id)) {
usedCapacity += (m.attributes?.capacity || 0);
}
});
}
} catch (e2) {}
availableTradeCapacity = Math.max(0, marketCapacity - usedCapacity);
} }
availableTradeCapacity = town.getAvailableTradeCapacity?.() ?? marketCapacity;
} catch (e) { log(`market capacity lookup failed: ${e}`); } } catch (e) { log(`market capacity lookup failed: ${e}`); }
// ---- Coordinates & sea zone ----------------------------------------- // ---- Coordinates & sea zone -----------------------------------------

View File

@@ -9,6 +9,11 @@ window.onCmdTypeChange = function() {
document.getElementById('amount-group').style.display = type === 'recruit' ? '' : 'none'; document.getElementById('amount-group').style.display = type === 'recruit' ? '' : 'none';
document.getElementById('market-options').style.display = type === 'market_offer' ? '' : 'none'; document.getElementById('market-options').style.display = type === 'market_offer' ? '' : 'none';
document.getElementById('research-options').style.display = type === 'research' ? '' : 'none'; document.getElementById('research-options').style.display = type === 'research' ? '' : 'none';
// Refresh market capacity label whenever market tab is opened
if (type === 'market_offer' && window.renderTownDetails) {
window.renderTownDetails();
}
}; };
// Building emoji icons for the visual grid // Building emoji icons for the visual grid

View File

@@ -167,18 +167,19 @@ window.renderTownDetails = function() {
const mCap = resObj.market_capacity || 0; const mCap = resObj.market_capacity || 0;
const aCap = resObj.available_trade_capacity != null ? resObj.available_trade_capacity : mCap; const aCap = resObj.available_trade_capacity != null ? resObj.available_trade_capacity : mCap;
console.log("Town:", t.town_name, "MarketCap:", mCap, "AvailCap:", aCap, "ResObj:", resObj);
// Always update td-market in the details panel
document.getElementById('td-market').innerHTML = mCap > 0 document.getElementById('td-market').innerHTML = mCap > 0
? `📦 Εμπορική Χωρητικότητα: <strong style="color:#6fcfcf">${window.fmt(aCap)}</strong> / <strong>${window.fmt(mCap)}</strong>` ? `📦 Εμπορική Χωρητικότητα: <strong style="color:#6fcfcf">${window.fmt(aCap)}</strong> / <strong>${window.fmt(mCap)}</strong>`
: ''; : `📦 Εμπορική Χωρητικότητα: <span style="color:#555">Χωρίς Αγορά (Επ.0)</span>`;
// Always update the label inside the market command form
const mCapLabel = document.getElementById('market-capacity-label'); const mCapLabel = document.getElementById('market-capacity-label');
if (mCapLabel) { if (mCapLabel) {
if (mCap > 0) { if (mCap > 0) {
mCapLabel.innerHTML = `Χωρητικότητα: <strong style="color:#6fcfcf">${window.fmt(aCap)}</strong> / ${window.fmt(mCap)}`; mCapLabel.innerHTML = `🏪 Διαθέσιμη Χωρητικότητα: <strong style="color:#6fcfcf">${window.fmt(aCap)}</strong> / <span style="color:#aaa">${window.fmt(mCap)} max</span>`;
} else { } else {
mCapLabel.textContent = ''; mCapLabel.innerHTML = `<span style="color:#ff6666">⚠️ Αυτή η πόλη δεν έχει Αγορά</span>`;
} }
} }

View File

@@ -258,11 +258,11 @@
<script> <script>
window.PLAYER_ID = "{{ player_id }}"; window.PLAYER_ID = "{{ player_id }}";
</script> </script>
<script src="/static/js/state.js?v=3"></script> <script src="/static/js/state.js?v=4"></script>
<script src="/static/js/components/townViewer.js?v=3"></script> <script src="/static/js/components/townViewer.js?v=4"></script>
<script src="/static/js/components/commandForm.js?v=3"></script> <script src="/static/js/components/commandForm.js?v=4"></script>
<script src="/static/js/components/commandLog.js?v=3"></script> <script src="/static/js/components/commandLog.js?v=4"></script>
<script src="/static/js/api.js?v=3"></script> <script src="/static/js/api.js?v=4"></script>
<script src="/static/js/app.js?v=3"></script> <script src="/static/js/app.js?v=4"></script>
</body> </body>
</html> </html>