Repository Public License
1// ORIX Arcade2// File: Games/DigToCore/DigModel.swift3// Description: Dig to Core — core data model: tuning constants, tile kinds, biomes, upgrades, derived drill stats and skins.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import Foundation89nonisolated enum DigConfig {10 static let cols = 1111 static let chunkRows = 2412 /// Row at which the planet core begins. One row is one metre.13 static let coreRow = 100014 /// Half the drill's width, in tiles (terrain carving and pickups).15 static let halfWidth = 0.3916 /// Half-width of the forgiving hazard hitbox (lava, gas).17 static let hazardHalf = 0.2518 static let bodyHeight = 0.919 /// Descent speed in tiles per second when drill power equals material hardness.20 static let baseDrillSpeed = 5.221 static let milestoneEvery = 10022 static let coreBonus = 100023 static let fossilValue = 3024 static let fuelCellFraction = 0.1825 static let milestoneFuelFraction = 0.0826 static let repairAmount = 40.027}2829nonisolated enum DigTile: UInt8, Sendable, CaseIterable {30 case air = 0, ground, hardRock, boulder31 case coal, copper, iron, quartz, gold, amethyst, ruby, diamond32 case fossil, lava, gas, fuelCell, repairKit, chest, core3334 static let ores: [DigTile] = [.coal, .copper, .iron, .quartz, .gold, .amethyst, .ruby, .diamond]3536 /// Credits for one unit of ore; `nil` for everything else.37 var oreValue: Int? {38 switch self {39 case .coal: 240 case .copper: 441 case .iron: 742 case .quartz: 1043 case .gold: 1644 case .amethyst: 2445 case .ruby: 3646 case .diamond: 5547 default: nil48 }49 }5051 var isOre: Bool { oreValue != nil }52 /// Terrain that must be drilled through (slows the drill).53 var isSolid: Bool {54 switch self {55 case .ground, .hardRock, .boulder, .fossil, .core: true56 default: isOre57 }58 }59 /// Cannot be drilled: the drill has to steer around it.60 var isUnbreakable: Bool { self == .boulder }61 var isHazard: Bool { self == .lava || self == .gas }62 var isPickup: Bool { self == .fuelCell || self == .repairKit || self == .chest }63 /// Blocks the guaranteed route (used by generation validation).64 var blocksRoute: Bool { isUnbreakable || isHazard }6566 /// Drilling resistance relative to a drill of power 1.67 func hardness(in biome: DigBiome) -> Double {68 switch self {69 case .ground: biome.hardness70 case .hardRock: biome.hardness * 2.671 case .fossil: biome.hardness * 1.372 case .boulder: .infinity73 case .core: 174 default: isOre ? biome.hardness * 1.15 : 075 }76 }7778 var title: String {79 switch self {80 case .coal: "Coal"81 case .copper: "Copper"82 case .iron: "Iron"83 case .quartz: "Quartz"84 case .gold: "Gold"85 case .amethyst: "Amethyst"86 case .ruby: "Ruby"87 case .diamond: "Diamond"88 case .fossil: "Fossil"89 case .chest: "Treasure"90 default: ""91 }92 }9394 var colorHex: UInt32 {95 switch self {96 case .coal: 0x3A3A4697 case .copper: 0xE8925A98 case .iron: 0xCDD3DE99 case .quartz: 0xFFE9F4100 case .gold: 0xFFC94D101 case .amethyst: 0xB57BFF102 case .ruby: 0xFF4D6D103 case .diamond: 0x7DF3FF104 case .fossil: 0xEFE3C2105 case .lava: 0xFF7A2E106 case .gas: 0x9CFF6B107 case .fuelCell: 0x4DD8FF108 case .repairKit: 0x4DE3A1109 case .chest: 0xFFC94D110 case .core: 0xFFF2B0111 default: 0x808080112 }113 }114}115116nonisolated enum DigBiome: Int, Sendable, CaseIterable, Codable {117 case loam, crystal, shale, magma, mantle118119 static let startRows = [0, 120, 300, 540, 800]120121 var startRow: Int { Self.startRows[rawValue] }122123 static func at(row: Int) -> DigBiome {124 var result = DigBiome.loam125 for biome in allCases where row >= biome.startRow { result = biome }126 return result127 }128129 var title: String { ["Loam Gardens", "Crystal Caverns", "Bone Shale", "Magma Veins", "Core Mantle"][rawValue] }130 var hardness: Double { [1.0, 1.6, 2.4, 3.4, 4.6][rawValue] }131 /// Two alternating strata colours for ordinary ground.132 var tileHex: (UInt32, UInt32) {133 [(0x94603F, 0x7F5136), (0x55639E, 0x48558C), (0x8A8468, 0x777159), (0x6B2F30, 0x57262C), (0x47327A, 0x3A2866)][rawValue]134 }135 /// Colour of carved tunnels and open caves.136 var backHex: UInt32 { [0x1F140E, 0x0D1126, 0x17150F, 0x1B0808, 0x0D0619][rawValue] }137 var accentHex: UInt32 { [0x8BE07A, 0x9FD3FF, 0xEFE3C2, 0xFF7A3D, 0xFFD66B][rawValue] }138139 /// Ore kinds and their relative weights.140 var oreTable: [(DigTile, Double)] {141 switch self {142 case .loam: [(.coal, 5), (.copper, 3), (.iron, 1)]143 case .crystal: [(.copper, 2), (.iron, 3), (.quartz, 4), (.amethyst, 1.2), (.gold, 0.6)]144 case .shale: [(.iron, 3), (.quartz, 2), (.gold, 3), (.amethyst, 1.5)]145 case .magma: [(.gold, 3), (.amethyst, 2), (.ruby, 3), (.diamond, 0.4)]146 case .mantle: [(.ruby, 3), (.diamond, 2.2), (.gold, 2), (.amethyst, 1)]147 }148 }149150 // Average feature counts per 24-row chunk.151 var caves: Double { [0.5, 2.2, 1.0, 1.2, 1.4][rawValue] }152 var hardVeins: Double { [0.6, 1.5, 2.6, 2.2, 2.8][rawValue] }153 var boulderRows: Double { [0, 0.5, 2.0, 1.6, 2.2][rawValue] }154 var orePockets: Double { [3.2, 3.2, 3.0, 3.0, 3.4][rawValue] }155 var lavaPools: Double { [0, 0, 0.35, 2.4, 3.4][rawValue] }156 var gasPockets: Double { [0, 1.2, 1.0, 1.6, 2.0][rawValue] }157 var fossilChance: Double { [0.10, 0.12, 0.55, 0.15, 0.10][rawValue] }158 var repairChance: Double { [0, 0.14, 0.22, 0.32, 0.36][rawValue] }159}160161// MARK: - Upgrades162163nonisolated struct DigUpgrade: Identifiable, Sendable, Equatable {164 let id: String165 let title: String166 let detail: String167 let symbol: String168 let maxLevel: Int169 let baseCost: Int170171 func cost(atLevel level: Int) -> Int? {172 guard level < maxLevel else { return nil }173 return Int((Double(baseCost) * pow(2.5, Double(level)) / 5).rounded()) * 5174 }175176 static let drill = DigUpgrade(id: "drill", title: "Drill Bit", detail: "Cuts through every material faster.", symbol: "tornado", maxLevel: 5, baseCost: 70)177 static let engine = DigUpgrade(id: "engine", title: "Thrusters", detail: "Quicker steering and faster free fall.", symbol: "arrow.left.and.right", maxLevel: 5, baseCost: 50)178 static let tank = DigUpgrade(id: "tank", title: "Fuel Tank", detail: "Carries more fuel for longer dives.", symbol: "fuelpump.fill", maxLevel: 5, baseCost: 60)179 static let economy = DigUpgrade(id: "economy", title: "Fuel Economy", detail: "Burns fuel more slowly.", symbol: "leaf.fill", maxLevel: 5, baseCost: 75)180 static let hull = DigUpgrade(id: "hull", title: "Hull Plating", detail: "More hull to survive hazards.", symbol: "shield.fill", maxLevel: 5, baseCost: 60)181 static let cooling = DigUpgrade(id: "cooling", title: "Heat Shield", detail: "Reduces damage from lava.", symbol: "snowflake", maxLevel: 5, baseCost: 105)182 static let dampers = DigUpgrade(id: "dampers", title: "Blast Dampers", detail: "Reduces damage from gas explosions.", symbol: "burst.fill", maxLevel: 3, baseCost: 90)183 static let cargo = DigUpgrade(id: "cargo", title: "Cargo Hold", detail: "Hauls more ore back to the surface.", symbol: "shippingbox.fill", maxLevel: 5, baseCost: 50)184 static let scanner = DigUpgrade(id: "scanner", title: "Scanner", detail: "Marks gems, fuel and treasure below the screen.", symbol: "dot.radiowaves.up.forward", maxLevel: 4, baseCost: 80)185 static let magnet = DigUpgrade(id: "magnet", title: "Ore Magnet", detail: "Pulls in ore from neighbouring tiles.", symbol: "bolt.horizontal.circle.fill", maxLevel: 3, baseCost: 135)186 static let refinery = DigUpgrade(id: "refinery", title: "Refinery", detail: "Sells ore for more credits.", symbol: "sparkles", maxLevel: 5, baseCost: 120)187 static let winch = DigUpgrade(id: "winch", title: "Rescue Winch", detail: "Saves more cargo when the drill is wrecked.", symbol: "lifepreserver.fill", maxLevel: 5, baseCost: 90)188189 static let all: [DigUpgrade] = [drill, engine, tank, economy, hull, cooling, dampers, cargo, scanner, magnet, refinery, winch]190 static func find(_ id: String) -> DigUpgrade? { all.first { $0.id == id } }191192 /// Human-readable effect at a given level, for the shop ("5.2 → 6.4").193 func effectLabel(level: Int) -> String {194 let stats = DigStats(levels: [id: level])195 switch id {196 case "drill": return "Power ×\(Self.f(stats.drillPower))"197 case "engine": return "Steer \(Self.f(stats.lateralSpeed)) t/s"198 case "tank": return "\(Int(stats.fuelMax)) fuel"199 case "economy": return "Burn \(Int((stats.fuelDrain * 100).rounded()))%"200 case "hull": return "\(Int(stats.hullMax)) hull"201 case "cooling": return "Lava −\(Int(stats.lavaDamage.rounded()))"202 case "dampers": return "Blast −\(Int(stats.gasDamage.rounded()))"203 case "cargo": return "\(stats.cargoCap) slots"204 case "scanner": return stats.scannerRows == 0 ? "Off" : "\(stats.scannerRows) m ahead"205 case "magnet": return stats.magnetRange == 0 ? "Off" : "Reach \(stats.magnetRange)"206 case "refinery": return "Value +\(Int(((stats.valueMultiplier - 1) * 100).rounded()))%"207 case "winch": return "Keeps \(Int((stats.wreckKeep * 100).rounded()))%"208 default: return ""209 }210 }211212 private static func f(_ value: Double) -> String { String(format: "%.1f", value) }213}214215/// Drill capabilities derived from owned upgrade levels.216nonisolated struct DigStats: Sendable, Equatable {217 var drillPower: Double218 var airSpeed: Double219 var lateralSpeed: Double220 var fuelMax: Double221 /// Fuel units burned per second.222 var fuelDrain: Double223 var hullMax: Double224 var lavaDamage: Double225 var gasDamage: Double226 var cargoCap: Int227 var scannerRows: Int228 var magnetRange: Int229 var valueMultiplier: Double230 /// Fraction of ore value kept when the drill is wrecked.231 var wreckKeep: Double232233 init(levels: [String: Int] = [:]) {234 func level(_ upgrade: DigUpgrade) -> Double { Double(min(max(levels[upgrade.id] ?? 0, 0), upgrade.maxLevel)) }235 drillPower = 1 + 0.24 * level(.drill)236 airSpeed = 8.5 + 0.6 * level(.engine)237 lateralSpeed = 7 + 1.1 * level(.engine)238 fuelMax = 20 * (1 + 0.24 * level(.tank))239 fuelDrain = 1 - 0.09 * level(.economy)240 hullMax = 100 + 25 * level(.hull)241 lavaDamage = 22 * (1 - 0.14 * level(.cooling))242 gasDamage = 16 * (1 - 0.2 * level(.dampers))243 cargoCap = 10 + 4 * Int(level(.cargo))244 scannerRows = [0, 6, 10, 14, 18][Int(level(.scanner))]245 magnetRange = Int(level(.magnet))246 valueMultiplier = 1 + 0.1 * level(.refinery)247 wreckKeep = 0.5 + 0.1 * level(.winch)248 }249250 init(save: DigSave) { self.init(levels: save.upgrades) }251}252253// MARK: - Skins254255nonisolated struct DigSkin: Identifiable, Sendable, Equatable {256 let id: String257 let title: String258 let requirement: String259 let bodyHex: UInt32260 let trimHex: UInt32261 let glassHex: UInt32262263 static let rookie = DigSkin(id: "rookie", title: "Rookie", requirement: "Starter drill", bodyHex: 0xFFC83D, trimHex: 0x3A3F55, glassHex: 0x7DE8FF)264 static let copperhead = DigSkin(id: "copperhead", title: "Copperhead", requirement: "Reach the Crystal Caverns", bodyHex: 0xE8825A, trimHex: 0x40302C, glassHex: 0xA8F0FF)265 static let amethyst = DigSkin(id: "amethyst", title: "Geode", requirement: "Reach the Bone Shale", bodyHex: 0xA97BFF, trimHex: 0x2C2748, glassHex: 0xFFD6F5)266 static let bonehunter = DigSkin(id: "bonehunter", title: "Bonehunter", requirement: "Find 5 fossils", bodyHex: 0xEFE3C2, trimHex: 0x5B5343, glassHex: 0x8BE07A)267 static let magma = DigSkin(id: "magma", title: "Emberjack", requirement: "Reach the Magma Veins", bodyHex: 0xFF5A3D, trimHex: 0x2B1414, glassHex: 0xFFD66B)268 static let tycoon = DigSkin(id: "tycoon", title: "Tycoon", requirement: "Earn 5,000 credits in total", bodyHex: 0x3DE8C5, trimHex: 0x123A36, glassHex: 0xFFC94D)269 static let corebreaker = DigSkin(id: "corebreaker", title: "Corebreaker", requirement: "Reach the core", bodyHex: 0xF4F5FF, trimHex: 0x5B4BC8, glassHex: 0xFFD66B)270271 static let all: [DigSkin] = [rookie, copperhead, amethyst, bonehunter, magma, tycoon, corebreaker]272 static func find(_ id: String) -> DigSkin { all.first { $0.id == id } ?? rookie }273274 func isEarned(by save: DigSave) -> Bool {275 switch id {276 case "copperhead": save.bestDepth >= DigBiome.crystal.startRow277 case "amethyst": save.bestDepth >= DigBiome.shale.startRow278 case "bonehunter": save.fossils >= 5279 case "magma": save.bestDepth >= DigBiome.magma.startRow280 case "tycoon": save.totalBanked >= 5000281 case "corebreaker": save.coreReached > 0282 default: true283 }284 }285}286