require "VehicleZoneDefinition"

-- Spawn chance multiplier from sandbox options (default 1.0 if not yet set)
local function getMilMult()
   local sv = SandboxVars and SandboxVars.rSemiTruck
   if sv and sv.MilSpawnMultiplier then
      return sv.MilSpawnMultiplier
   end
   return 1.0
end

local function milChance(base)
   return base * getMilMult()
end

-- Tread's Military Vehicle Zone Defs --
-- https://steamcommunity.com/sharedfiles/filedetails/?id=2739565754
VehicleZoneDistribution.military_heavy_trailers = VehicleZoneDistribution.military_heavy_trailers or {}
VehicleZoneDistribution.military_heavy_trailers.vehicles = VehicleZoneDistribution.military_heavy_trailers.vehicles or {}
VehicleZoneDistribution.military_heavy_trailers.vehicles["SemiTruck_mil"] = {index = -1, spawnChance = milChance(15)};
VehicleZoneDistribution.military_heavy_trailers.vehicles["SemiTruckBox_mil"] = {index = -1, spawnChance = milChance(12)};
VehicleZoneDistribution.military_heavy_trailers.vehicles["SemiTrailerVan_mil"] = {index = -1, spawnChance = milChance(10)};

-- Military zones (vanilla)
VehicleZoneDistribution.military = VehicleZoneDistribution.military or {}
VehicleZoneDistribution.military.vehicles = VehicleZoneDistribution.military.vehicles or {}
VehicleZoneDistribution.military.vehicles["SemiTruck_mil"] = {index = -1, spawnChance = milChance(8)};
VehicleZoneDistribution.military.vehicles["SemiTruckBox_mil"] = {index = -1, spawnChance = milChance(6)};
VehicleZoneDistribution.military.vehicles["SemiTrailerVan_mil"] = {index = -1, spawnChance = milChance(5)};

-- Police stations (confiscated military equipment)
VehicleZoneDistribution.police.vehicles["SemiTruck_mil"] = {index = -1, spawnChance = milChance(0.5)};
VehicleZoneDistribution.police.vehicles["SemiTruckBox_mil"] = {index = -1, spawnChance = milChance(0.3)};

-- Fire stations (emergency response)
VehicleZoneDistribution.fire.vehicles["SemiTruck_mil"] = {index = -1, spawnChance = milChance(0.3)};

-- Ranger stations (National Guard)
VehicleZoneDistribution.ranger.vehicles["SemiTruck_mil"] = {index = -1, spawnChance = milChance(1)};
VehicleZoneDistribution.ranger.vehicles["SemiTruckBox_mil"] = {index = -1, spawnChance = milChance(0.8)};
VehicleZoneDistribution.ranger.vehicles["SemiTrailerVan_mil"] = {index = -1, spawnChance = milChance(0.5)};

-- Junkyard (decommissioned military surplus)
VehicleZoneDistribution.junkyard.vehicles["SemiTruck_mil"] = {index = -1, spawnChance = milChance(0.35)};
VehicleZoneDistribution.junkyard.vehicles["SemiTruckBox_mil"] = {index = -1, spawnChance = milChance(0.35)};
VehicleZoneDistribution.junkyard.vehicles["SemiTrailerVan_mil"] = {index = -1, spawnChance = milChance(0.2)};

-- Truck parking lots (military contractors or supply depots)
VehicleZoneDistribution.parkingstall = VehicleZoneDistribution.parkingstall or {}
VehicleZoneDistribution.parkingstall.vehicles = VehicleZoneDistribution.parkingstall.vehicles or {}
VehicleZoneDistribution.truckparkinglot.vehicles["SemiTruck_mil"] = {index = -1, spawnChance = milChance(1)};
VehicleZoneDistribution.truckparkinglot.vehicles["SemiTruckBox_mil"] = {index = -1, spawnChance = milChance(1)};
VehicleZoneDistribution.truckparkinglot.vehicles["SemiTrailerVan_mil"] = {index = -1, spawnChance = milChance(1)};

-- Parking stalls (random spawns in parking lots)
VehicleZoneDistribution.parkingstall = VehicleZoneDistribution.parkingstall or {}
VehicleZoneDistribution.parkingstall.vehicles = VehicleZoneDistribution.parkingstall.vehicles or {}
VehicleZoneDistribution.parkingstall.vehicles["SemiTruck_mil"] = {index = -1, spawnChance = milChance(0.45)};
VehicleZoneDistribution.parkingstall.vehicles["SemiTruckBox_mil"] = {index = -1, spawnChance = milChance(0.45)};
VehicleZoneDistribution.parkingstall.vehicles["SemiTrailerVan_mil"] = {index = -1, spawnChance = milChance(0.45)};

-- Big Trailer Parking Lot (added by rSemiTruck mod)
VehicleZoneDistribution.bigtrailerparkinglot = VehicleZoneDistribution.bigtrailerparkinglot or {}
VehicleZoneDistribution.bigtrailerparkinglot.vehicles = VehicleZoneDistribution.bigtrailerparkinglot.vehicles or {}
VehicleZoneDistribution.bigtrailerparkinglot.vehicles["SemiTruck_mil"] = {index = -1, spawnChance = milChance(3)};
VehicleZoneDistribution.bigtrailerparkinglot.vehicles["SemiTruckBox_mil"] = {index = -1, spawnChance = milChance(2)};
VehicleZoneDistribution.bigtrailerparkinglot.vehicles["SemiTrailerVan_mil"] = {index = -1, spawnChance = milChance(1)};