'use strict';

/* ────────────────────────────────────────────────────────────────
   Phase 6 Sprint 6.5 — Strategy & Simulation Templates
   
   Tower Defense, RTS, Turn-based Tactics, City Builder, Idle/Clicker
──────────────────────────────────────────────────────────────── */
const DEFAULT_TOWER_DEFENSE_CONFIG = {
    tileSize: 32,
    gridWidth: 20,
    gridHeight: 15,
    startGold: 500,
    startLives: 20,
    waveCount: 30,
    waveInterval: 0.6,
    interWaveDelay: 15,
    sellRefundRate: 0.7,
    maxTowersPerType: 0, // 0 = unlimited
    speedMultipliers: [1, 2, 4],
};
function createTDState(config) {
    return {
        gold: config.startGold, lives: config.startLives,
        wave: 0, score: 0, towers: [], inWave: false, speed: 1,
    };
}
const DEFAULT_RTS_CONFIG = {
    mapWidth: 200,
    mapHeight: 200,
    maxPopulation: 200,
    startResources: { gold: 500, wood: 300, food: 200, stone: 100 },
    buildSpeed: 1,
    gatherRate: 1,
    fogOfWar: true,
    maxSelectCount: 50,
    controlGroups: 10,
};
function createRTSState(config) {
    return {
        resources: { ...config.startResources },
        population: 0, maxPopulation: 10,
        selectedUnits: [],
        controlGroups: new Map(),
    };
}
const DEFAULT_TACTICS_CONFIG = {
    gridWidth: 16,
    gridHeight: 12,
    maxUnitsPerSide: 8,
    movementType: 'manhattan',
    heightLevels: 3,
    heightAdvantageBonus: 0.15,
    coverBonus: 0.3,
    flanking: true,
    flankingBonus: 0.25,
    criticalHitChance: 0.1,
    initiativeSystem: true,
    undoMoves: true,
    turnTimeLimit: 0,
};
function createTurnOrder(units) {
    const sorted = units.slice().sort((a, b) => b.initiative - a.initiative);
    return {
        units: sorted.map(u => ({ ...u, acted: false })),
        currentIndex: 0,
        turnNumber: 1,
    };
}
function nextUnit(order) {
    while (order.currentIndex < order.units.length) {
        const u = order.units[order.currentIndex];
        if (!u.acted) {
            u.acted = true;
            order.currentIndex++;
            return u.entityId;
        }
        order.currentIndex++;
    }
    // New turn
    order.turnNumber++;
    order.currentIndex = 0;
    for (const u of order.units)
        u.acted = false;
    return order.units.length > 0 ? (order.units[0].acted = true, order.currentIndex++, order.units[0].entityId) : null;
}
const DEFAULT_CITY_BUILDER_CONFIG = {
    gridWidth: 64,
    gridHeight: 64,
    startMoney: 10000,
    taxRate: 0.08,
    populationGrowthRate: 0.02,
    demandCycle: 60,
    buildingCategories: ['residential', 'commercial', 'industrial', 'service', 'park', 'infrastructure'],
    happinessFactors: ['services', 'parks', 'pollution', 'traffic', 'taxes'],
    pollutionDecay: 0.01,
};
function createCityState(config) {
    return {
        money: config.startMoney,
        population: 0, happiness: 0.5,
        demand: { residential: 0.5, commercial: 0.3, industrial: 0.2 },
        buildings: [], totalIncome: 0, totalUpkeep: 0,
    };
}
function updateCity(state, config, dt) {
    state.money += (state.totalIncome - state.totalUpkeep) * dt;
    // Population growth based on demand and happiness
    const growthRate = config.populationGrowthRate * state.happiness * state.demand.residential;
    state.population = Math.max(0, state.population + growthRate * dt);
}
const DEFAULT_IDLE_CONFIG = {
    baseClickValue: 1,
    offlineProgressRate: 0.5,
    maxOfflineHours: 24,
    prestigeThreshold: 1e12,
    prestigeMultiplier: 1.5,
    autoSaveInterval: 30,
    notationStyle: 'standard',
};
function createIdleState() {
    return {
        currency: 0, totalEarned: 0, clickValue: 1,
        generators: new Map(), upgrades: new Set(),
        prestigeCount: 0, prestigeMultiplier: 1, lastSave: Date.now(),
    };
}
function getGeneratorCost(def, owned) {
    return Math.floor(def.baseCost * Math.pow(def.costMultiplier, owned));
}
function getIdleIncome(state, defs) {
    var _a;
    let income = 0;
    for (const def of defs) {
        const count = (_a = state.generators.get(def.id)) !== null && _a !== void 0 ? _a : 0;
        income += def.baseOutput * count;
    }
    return income * state.prestigeMultiplier;
}
function formatNumber(n, style = 'standard') {
    if (style === 'scientific')
        return n.toExponential(2);
    if (style === 'engineering') {
        const exp = Math.floor(Math.log10(Math.abs(n)) / 3) * 3;
        if (exp < 3)
            return n.toFixed(0);
        return `${(n / Math.pow(10, exp)).toFixed(2)}e${exp}`;
    }
    // Standard notation with suffixes
    const suffixes = ['', 'K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'Oc', 'No', 'Dc'];
    const tier = Math.max(0, Math.floor(Math.log10(Math.abs(n)) / 3));
    if (tier === 0)
        return n.toFixed(0);
    if (tier >= suffixes.length)
        return n.toExponential(2);
    return `${(n / Math.pow(10, tier * 3)).toFixed(2)}${suffixes[tier]}`;
}

exports.DEFAULT_CITY_BUILDER_CONFIG = DEFAULT_CITY_BUILDER_CONFIG;
exports.DEFAULT_IDLE_CONFIG = DEFAULT_IDLE_CONFIG;
exports.DEFAULT_RTS_CONFIG = DEFAULT_RTS_CONFIG;
exports.DEFAULT_TACTICS_CONFIG = DEFAULT_TACTICS_CONFIG;
exports.DEFAULT_TOWER_DEFENSE_CONFIG = DEFAULT_TOWER_DEFENSE_CONFIG;
exports.createCityState = createCityState;
exports.createIdleState = createIdleState;
exports.createRTSState = createRTSState;
exports.createTDState = createTDState;
exports.createTurnOrder = createTurnOrder;
exports.formatNumber = formatNumber;
exports.getGeneratorCost = getGeneratorCost;
exports.getIdleIncome = getIdleIncome;
exports.nextUnit = nextUnit;
exports.updateCity = updateCity;
//# sourceMappingURL=StrategyTemplates.js.map
