Assets = 
{
	Asset("IMAGE", "minimap/ancient_chest.tex"),
	Asset("ATLAS", "minimap/ancient_chest.xml"),
	Asset("IMAGE", "minimap/fortress.tex"),
	Asset("ATLAS", "minimap/fortress.xml"),
	Asset("ANIM", "anim/ui_chest_5x5.zip"),
	Asset("IMAGE", "images/ui_chest_5x5.tex"),
	Asset("ATLAS", "images/ui_chest_5x5.xml"),
	Asset("SOUND", "sound/epicworld.fsb"),
	Asset("SOUNDPACKAGE", "sound/epicworld.fev"),
}

PrefabFiles = 
{
	"giantwormhole",
	"infestpond",
	"infestmosquito",
	"alienship",
	"shadowfissure",
	"shadowmaxwell",
	"newghost",
	"beardlord",
	"fortress",
	"fortress_key",
	"ancient_chest",
	"lightninghound",
	"brampus",
}

AddMinimapAtlas("minimap/ancient_chest.xml")
AddMinimapAtlas("minimap/fortress.xml")

require = GLOBAL.require
local TUNING = GLOBAL.TUNING
local GetPlayer = GLOBAL.GetPlayer
local Combat = require "components/combat"
local follower = require "components/follower"
local harvestable = require "components/harvestable"
local ccanattack = Combat.CanAttack
local GetPlayer = GLOBAL.GetPlayer
local STRINGS = GLOBAL.STRINGS
local RECIPETABS = GLOBAL.RECIPETABS
local Recipe = GLOBAL.Recipe
local Ingredient = GLOBAL.Ingredient
local TECH = GLOBAL.TECH
local ACTIONS = GLOBAL.ACTIONS
local Vector3 = GLOBAL.Vector3
local distsq = GLOBAL.distsq
local GetWorld = GLOBAL.GetWorld
local Prefabs = GLOBAL.Prefabs
local Transform = GLOBAL.Transform
local Physics = GLOBAL.Physics
local AnimState = GLOBAL.AnimState
local FRAMES = GLOBAL.FRAMES
local DEGREES = GLOBAL.DEGREES
local SpawnPrefab = GLOBAL.SpawnPrefab
local TheCamera = GLOBAL.TheCamera
local seg_time = 30
local day_segs = 10
local dusk_segs = 4
local night_segs = 2
local day_time = seg_time * day_segs
local dusk_time = seg_time * dusk_segs
local night_time = seg_time * night_segs
local total_day_time = seg_time*16
local TheSim = GLOBAL.TheSim
local SpawnPrefab = GLOBAL.SpawnPrefab
local GetSeasonManager = GLOBAL.GetSeasonManager
local SEASONS = GLOBAL.SEASONS
local GetClock = GLOBAL.GetClock
local GetWorld = GLOBAL.GetWorld

function EpicWorldActive(inst)
	if not inst.components.epicworld then
		inst:AddComponent("epicworld")
	end
	if not inst.components.epicworldboss then
		inst:AddComponent("epicworldboss")
	end
	if not inst.components.epicworldfullmoon then
		inst:AddComponent("epicworldfullmoon")
	end
end

AddPrefabPostInit("forest", EpicWorldActive)

GLOBAL.TUNING.MAP_EVENT_DELAY = GetModConfigData("map_event_delay") * 35 * total_day_time
GLOBAL.TUNING.FORTRESS_SPAWN_DELAY = GetModConfigData("fortress_spawn_delay") * 35 * total_day_time
GLOBAL.TUNING.ACTIVE_MAXWELL = GetModConfigData("active_maxwell")

function LightningHound(self,inst)
	function self:SummonHound()
		local pt = Vector3(GetPlayer().Transform:GetWorldPosition())		
		local spawn_pt = self:GetSpawnPoint(pt)	
		if spawn_pt then	
			local prefab = "hound"
			local special_hound_chance = self:GetSpecialHoundChance()
			if math.random() < special_hound_chance then
				if GetSeasonManager():IsWinter() then
					prefab = "icehound"
				elseif GetSeasonManager():IsSpring() then
					prefab = "lightninghound"
				else
					prefab = "firehound"
				end
			end
			local hound = SpawnPrefab(prefab)
			if hound then
				hound.Physics:Teleport(spawn_pt:Get())
				hound:FacePoint(pt)
				hound.components.combat:SuggestTarget(GetPlayer())
				return hound
			end
		end
	end
	
	function self:ReleaseHound(dt)
		local pt = Vector3(GetPlayer().Transform:GetWorldPosition())	
		local spawn_pt = self:GetSpawnPoint(pt)
		if spawn_pt then
			self.houndstorelease = self.houndstorelease - 1
		
			local prefab = "hound"
			local day = GetClock().numcycles
			local special_hound_chance = self:GetSpecialHoundChance()
			if GetSeasonManager() and GetSeasonManager():IsSummer() then
				special_hound_chance = special_hound_chance * 1.5
			end
			if math.random() < special_hound_chance then
				if GetSeasonManager():IsWinter() then
					prefab = "icehound"
				elseif GetSeasonManager():IsSpring() then
					prefab = "lightninghound"
				else
					prefab = "firehound"
				end
			end	
			local hound = SpawnPrefab(prefab)
			if hound then
				hound.Physics:Teleport(spawn_pt:Get())
				hound:FacePoint(pt)
				hound.components.combat:SuggestTarget(GetPlayer())
			end
		end
	end		
end
AddComponentPostInit("hounded", LightningHound)



