local lib = starlit.mod.lib
local fab = starlit.type.fab

local facDescs = {
	commune = {
		survival = {
			suit = 'A light, simple, bare-bones environment suit that will provide heating, cooling, and nanide support to a stranded cosmonaut';
			cc = 'The Survival Suit uses compact thermoelectrics to keep the wearer perfectly comfortable in extremes of heat or cold. It makes up for its heavy power usage with effective insulation that substantially reduces any need for climate control.';
		};
		engineer = {
			suit = 'A lightweight environment suit designed for indoor work, the Commune\'s Engineer Suit boasts advanced nanotech capable of constructing objects in place.';
			cc = 'The Engineer Suit is designed for indoor work. Consequently, it features only a low-power thermoelectric cooler meant to keep its wearer comfortable during strenuous work.';
		};
		combat = {
			suit = 'A military-grade suit with the latest Commune technology. Designed for maximum force multiplication, the suit has dual weapon hardpoints and supports a gargantuan power reserve. Its nanotech systems are specialized for tearing through obstacles, but can also be used to manufacturer ammunition in a pinch.';
			cc = 'This Combat Suit uses electrothermal cooling to keep an active soldier comfortable and effective, as well as conventional heating coils to enable operation in hostile atmospheres.';
		};
	};

}


starlit.world.tier.foreach('starlit:suit-gen', {}, function(tid, t)
	local function hasTech(tech)
		return starlit.world.tier.tech(tid, tech)
	end
	if not hasTech 'suit' then return end
	-- TODO tier customization
	--
	local function fabsum(f)
		return starlit.world.tier.fabsum(tid, 'suit')
	end
	local function fabReq(sz, days)
		local tierMatBase = (
			(fabsum 'electric' * 4) +
			(fabsum 'basis' + fabsum 'suit') * sz
		)
		local b = tierMatBase + fab {
			-- universal suit requirements
			time = { print    = 60*60*24 * days };
			size = { printBay = sz              };
		}
		b.flag = lib.tbl.set('print');
		return b
	end
	local function facDesc(s, t)
		local default = 'A protective nanosuit' -- FIXME
		if not facDescs[tid] then return default end
		if not facDescs[tid][s] then return default end
		if not facDescs[tid][s][t] then return default end
		return facDescs[tid][s][t]
	end
	starlit.item.suit.link('starlit_suit:suit_survival_' .. tid, {
		name = t.name .. ' Survival Suit';
		desc = facDesc('survival','suit');
		fab = fabReq(1, 2.2) + fab { };
		tex = {
			plate = {
				id = 'starlit-suit-survival-plate';
				tint = lib.color {hue = 210, sat = .5, lum = .5};
			};
			lining = {
				id = 'starlit-suit-survival-lining';
				tint = lib.color {hue = 180, sat = .2, lum = .7};
			};
		};
		tints = {'suit_plate', 'suit_lining'};
		temp = {
			desc = facDesc('survival','cc');
			maxHeat = 0.7; -- can produce a half-degree Δ per second
			maxCool = 0.5;
			heatPower = 50; -- 50W
			coolPower = 50/t.efficiency;
			insulation = 0.5; -- prevent half of heat loss
		};
		protection = {
			rad = 0.7; -- blocks 70% of ionizing radiation
		};
		slots = {
			canisters = 1;
			batteries = math.ceil(math.max(1, t.power/2));
			chips = 3;
			guns = 0;
			ammo = 0;
		};
		nano = {
			compileSpeed = 0.1 * t.efficiency;
			shredSpeed = 0.1 * t.power;
			fabSizeLimit = 0.6; -- 60cm
		};
	})

	starlit.item.suit.link('starlit_suit:suit_engineer_' .. tid, {
		name = t.name .. ' Engineer Suit';
		desc = facDesc('engineer','suit');
		tex = {
			plate = {
				id = 'starlit-suit-survival-plate';
				tint = lib.color {hue = 0, sat = .5, lum = .7};
			};
		};
		tints = {'suit_plate', 'suit_lining'};
		fab = fabReq(.8, 7) + fab { };
		temp = {
			desc = facDesc('engineer','cc');
			maxHeat = 0;
			maxCool = 0.2;
			heatPower = 0;
			coolPower = 10 / t.efficiency;
			insulation = 0.1; -- no lining
		};
		slots = {
			canisters = 2;
			batteries = 2;
			chips = 6;
			guns = 0;
			ammo = 0;
		};
		compat = {
			maxBatterySize = 0.10 * t.power; -- 10cm
		};
		protection = {
			rad = 0.1; -- blocks 10% of ionizing radiation
		};
		nano = {
			compileSpeed = 1 * t.efficiency;
			shredSpeed = 0.7 * t.power;
			fabSizeLimit = 1.5; -- 1.5m (enables node compilation)
		};
	})

	if hasTech 'suitCombat' then
		starlit.item.suit.link('starlit_suit:suit_combat_' .. tid, {
			name = t.name .. ' Combat Suit';
			desc = facDesc('combat','suit');
			fab = fabReq(1.5, 14) + fab {
				metal = {iridium = 1e3};
			};
			tex = {
				plate = {
					id = 'starlit-suit-survival-plate';
					tint = lib.color {hue = 0, sat = 0, lum = 0};
				};
				lining = {
					id = 'starlit-suit-survival-lining';
					tint = lib.color {hue = 180, sat = .5, lum = .3};
				};
			};
			tints = {'suit_plate', 'suit_lining'};
			slots = {
				canisters = 1;
				batteries = math.ceil(math.max(3, 8*(t.power/2)));
				chips = 5;
				guns = 2;
				ammo = 1;
			};
			compat = {
				maxBatterySize = 0.10 * t.power; -- 10cm
			};
			temp = {
				desc = facDesc('combat','cc');
				maxHeat = 0.3; 
				maxCool = 0.6;
				heatPower = 20 / t.efficiency; 
				coolPower = 40 / t.efficiency;
				insulation = 0.2; 
			};
			protection = {
				rad = 0.9; -- blocks 90% of ionizing radiation
			};
			nano = {
				compileSpeed = 0.05;
				shredSpeed = 2 * t.power;
				fabSizeLimit = 0.3; -- 30cm
			};
		})
	end
end)


