--[[ ----------------------------------------------------------------------------------------------
 File       : gulag_escape.script
 Description: Gulags ESCAPE
 Copyright  : 2013 © LA-team
 Authors    : gr1ph00n, loxotron, vintar
 Editors    : gr1ph00n(05.02.2011), vintar(12.02.2013), loxotron(23.02.2013)
 Last edit  : 27.05.2013 [...]
--]] ----------------------------------------------------------------------------------------------

--/ -----------------------------------------------------------------
local sModule = script_name()
--/ -----------------------------------------------------------------
local log = function(fmt,...) _G.log(sModule..":"..tostring(fmt),...) end
--/ -----------------------------------------------------------------------------------------------
--/ General VARIABLEs
--/ -----------------------------------------------------------------------------------------------
local gulags = {
	--/ for stalkers ------------------------------
	esc_village_lager    	= {comm = {"stalker"},  out_rest = "esc_village_lager_out_rest"},
	esc_bandit_factory  	= {comm = {"bandit"},   out_rest = "esc_bandit_factory_out_rest"},
	esc_bridge_blockpost	= {comm = {"military"}, out_rest = "cordon_bridge_zone_rest"},
	esc_fox_house        	= {comm = {"dark_stalker", "stalker"}, out_rest = "esc_fox_house_out_rest"},
	esc_assault          	= {comm = {"stalker"},  out_rest = "esc_assault_out_rest"},
	esc_blockpost        	= {comm = {"military"}, out_rest = "cordon_blockpost_zone", out_rest_patrol = "cordon_blockpost_patrolers_rest"},
	esc_exit_smart       	= {comm = {"military"}, out_rest = "esc_exit_smart_out_rest"},
	esc_stalker_factory  	= {comm = {"stalker"}},
	esc_wandering_terrain	= {comm = {"stalker"}},
	esc_wandering_terrain1	= {comm = {"stalker"}},
	esc_wandering_terrain2	= {comm = {"stalker"}},
	--/ for monsters ------------------------------
	esc_karlik_smart          = { comm = {"karlik"} },
	esc_bloodsucker_swamp     = { comm = {"bloodsucker"} },
	esc_boar_back             = { comm = {"boar"} },
	esc_boars_lair            = { comm = {"boar"} },
	esc_psevdo_lair           = { comm = {"pseudodog", "dog"} },
	esc_dog_gar               = { comm = {"dog"} },
	esc_dog_smart_1           = { comm = {"dog"} },
	esc_dog_back              = { comm = {"dog"} },
	esc_dog_lair_sm           = { comm = {"dog"} },
	esc_flesh_lair            = { comm = {"flesh"} },
	esc_fleshes_blockpost     = { comm = {"flesh"} },
	esc_poltergeist_terrain   = { comm = {"poltergeist"} },
	esc_mixed_lair            = { comm = {"dog", "pseudodog", "flesh"} },
	esc_rats_lair             = { comm = {"rat","tushkano"} },
	esc_tuishkano_lair        = { comm = {"tushkano"} },
	esc_tunnel_zombie_terrain = { comm = {"zombie"}},
	esc_ug_zombie_terrain     = { comm = {"zombie"}},
	esc_tutorial_flesh_terrain = { comm = {"flesh"}},
	esc_border_mutants		  = { comm = {"dog", "pseudodog", "boar"} },
	esc_tunnel_tushkano_terrain = { comm = {"tushkano"} },
	esc_tunnel_polter_terrain = { comm = {"poltergeist"} },
}
--/ ----------------------------------------------
local esc_mob_in_rest     = "cordon_space_resrictor_0001,esc_bloodsucker_restrictor"
local esc_mob_fox_in_rest = "cordon_space_resrictor_0001,cordon_fox_no_mutants"
--/ -----------------------------------------------------------------
--/ Process
--/ -----------------------------------------------------------------
function getGulag(gtype)
	return gulags[gtype] --/>
end
--/ ----------------------------------------------
local is_online = "{=xr_gulag.actor_on_gulag_level()}"
--/ ----------------------------------------------
local on_level_pred = function(info,gulag) return xr_gulag.is_on_gulag_level(info.se_obj,gulag) end
local available_time_1 = function(info,gulag) return xr_conditions.is_time1() end
--/ -----------------------------------------------------------------------------------------------
--/ Gulags
--/ -----------------------------------------------------------------------------------------------
--/ esc_village_lager
--/ ---------------------------------------------
gulags.esc_village_lager.guard_pred  = function(info) return info.profile_name == "esc_fixer_guard" end
--gulags.esc_village_lager.fanat_pred = function(info) return info.profile_name == "esc_fanat" end --/#+# (name == "esc_fanatic")
gulags.esc_village_lager.wolf_pred   = function(info) return info.story_id == 6027 end
gulags.esc_village_lager.fox_pred    = function(info) return info.story_id == 6025 end
gulags.esc_village_lager.proverb_pred    = function(info) return info.story_id == 10000 end

gulags.esc_village_lager.jobs = function(sj, gname, type, squad, groups)
	table.insert(sj, gulag_tasks.getJob("wolf",        0, 7,   {0,1,2,3}, squad, groups[1], "", gulags.esc_village_lager.out_rest, nil, type, gulags.esc_village_lager.wolf_pred))
	table.insert(sj, gulag_tasks.getJob("wolf",        0, 7,       {4,5}, squad, groups[1], "", "", nil, type, gulags.esc_village_lager.wolf_pred))
	table.insert(sj, gulag_tasks.getJob("fox",         0, 7, {0,1,2,3,4,5}, squad, groups[1], "", gulags.esc_village_lager.out_rest, nil, type, gulags.esc_village_lager.fox_pred))
	table.insert(sj, gulag_tasks.getJob("fixer_guard", 0, 6, {0,2,4}, squad, groups[1], "", gulags.esc_village_lager.out_rest, nil, type))
	table.insert(sj, gulag_tasks.getJob("sleep_guard", 0, 6, {1,3,5}, squad, groups[1], "", gulags.esc_village_lager.out_rest, nil, type))
	for i = 1, 4 do
		table.insert(sj, gulag_tasks.getJob("novice"..i, 0, 5,     {0,2,4}, squad, groups[1], "", gulags.esc_village_lager.out_rest, nil, type))
		table.insert(sj, gulag_tasks.getJob("sleeper"..i,0, 5,     {1,3,5}, squad, groups[1], "", gulags.esc_village_lager.out_rest, nil, type))
	end
	for i = 1, 3 do
		table.insert(sj, gulag_tasks.getJob("novice_add"..i, 0, 3,     {0,2,4}, squad, groups[1], "", gulags.esc_village_lager.out_rest, nil, type))
		table.insert(sj, gulag_tasks.getJob("sleeper_add"..i,0, 3,     {1,3,5}, squad, groups[1], "", gulags.esc_village_lager.out_rest, nil, type))
	end
	table.insert(sj, gulag_tasks.getJob("proverb",        0, 7,   {0,1,2,3,4,5}, squad, groups[1], "", "", nil, type, gulags.esc_village_lager.proverb_pred))
end

gulags.esc_village_lager.state = function(gulag)
	if has_info("esc_fixer_working") then
		if xr_conditions.is_day() then
			return 2
		end
		return 3
	elseif has_info("esc_actor_wolf_reward") then
		if xr_conditions.is_day() then
			return 4
		end
		return 5
	else
		if xr_conditions.is_day() then
			return 0
		end
		return 1
	end
end

--/ ---------------------------------------------
--/ esc_bandit_factory
--/ ---------------------------------------------
gulags.esc_bandit_factory.boss_pred = function(info) return parser.section_exists(info.se_obj:spawn_ini(), "boss") end
gulags.esc_bandit_factory.up_pred   = function(info) return parser.section_exists(info.se_obj:spawn_ini(), "upstairs") end

gulags.esc_bandit_factory.jobs = function(sj, gname, type, squad, groups)
	table.insert(sj, gulag_tasks.getJob("bandit_boss",   0, 7, {0}, squad, groups[1], "", gulags.esc_bandit_factory.out_rest, nil, type, gulags.esc_bandit_factory.boss_pred))
	table.insert(sj, gulag_tasks.getJob("bandit_up",     0, 6, {0}, squad, groups[1], "", gulags.esc_bandit_factory.out_rest, nil, type, gulags.esc_bandit_factory.up_pred))
	for i = 1, 4 do
		table.insert(sj, gulag_tasks.getJob("bandit" .. i, 0, 5, {0}, squad, groups[1], "", gulags.esc_bandit_factory.out_rest, nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ esc_stalker_factory - active only after cleaning factory from bandits!
--/ ---------------------------------------------
gulags.esc_stalker_factory.wolf_pred = function(info) return (has_info("esc_factory_cleaned") and info.story_id == 6027) end
gulags.esc_stalker_factory.common_pred = function(info)	return (has_info("esc_factory_cleaned") and on_level_pred) end

gulags.esc_stalker_factory.jobs = function(sj, gname, type, squad, groups)
	table.insert(sj, gulag_tasks.getJob("wolf",  0, 7, {0,1}, squad, groups[1], "", "", nil, type, gulags.esc_stalker_factory.wolf_pred))
--	table.insert(sj, gulag_tasks.getJob("wolf_sleep",  0, 7, {1}, squad, groups[1], "", "", nil, type, gulags.esc_stalker_factory.wolf_pred))
	table.insert(sj, gulag_tasks.getJob("guard", 0, 6, {0,1}, squad, groups[1], "", "", nil, type, gulags.esc_stalker_factory.common_pred))
	for i = 1, 3 do
		table.insert(sj, gulag_tasks.getJob("walker" .. i , 0, 5, {0}, squad, groups[1], "", "", nil, type, gulags.esc_stalker_factory.common_pred))
	end
	for i = 1, 3 do
		table.insert(sj, gulag_tasks.getJob("kamper" .. i , 0, 5, {0}, squad, groups[1], "", "", nil, type, gulags.esc_stalker_factory.common_pred))
	end
	for i = 1, 6 do
		table.insert(sj, gulag_tasks.getJob("sleeper" .. i , 0, 4, {1}, squad, groups[1], "", "", nil, type, gulags.esc_stalker_factory.common_pred))
	end
end

gulags.esc_stalker_factory.state = function(gulag)
	if not xr_conditions.is_day() then
		return 1
	end
	return 0
end

--/ ---------------------------------------------
--/ esc_bridge_blockpost
--/ ---------------------------------------------
gulags.esc_bridge_blockpost.pred_commander = function(info) return info.story_id == 6026 end
gulags.esc_bridge_blockpost.pred_sniper    = function(info) return info.profile_name == "esc_soldier_bridge_sniper" end

gulags.esc_bridge_blockpost.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 4 do
		table.insert(sj, gulag_tasks.getJob("soldier" .. i, 0, 5, {0}, squad, groups[1], "", gulags.esc_bridge_blockpost.out_rest, nil, type, on_level_pred))
	end
	table.insert(sj, gulag_tasks.getJob("commander", 0, 7, {0}, squad, groups[1], "", gulags.esc_bridge_blockpost.out_rest, nil, type, gulags.esc_bridge_blockpost.pred_commander))
	table.insert(sj, gulag_tasks.getJob("sniper",    0, 6, {0}, squad, groups[1], "", "", is_online, type, gulags.esc_bridge_blockpost.pred_sniper))
end

--/ ---------------------------------------------
--/ esc_fox_house
--/ ---------------------------------------------
gulags.esc_fox_house.pred_leader = function(info) return info.profile_name == "esc_dstalker_leader" end
gulags.esc_fox_house.pred_any    = function(info) return info.community == "dark_stalker" end
gulags.esc_fox_house.pred_fox    = function(info)
	return info.story_id == 6025
end

gulags.esc_fox_house.jobs = function(sj, gname, type, squad, groups)
	table.insert(sj, gulag_tasks.getJob("dstalker_leader_off", 0, 7, {0}, squad, groups[1], "", gulags.esc_fox_house.out_rest, false, type, gulags.esc_fox_house.pred_leader))
	table.insert(sj, gulag_tasks.getJob("dstalker_leader",     0, 7, {1,2}, squad, groups[1], "", gulags.esc_fox_house.out_rest,   nil, type, gulags.esc_fox_house.pred_leader))
	for i = 1, 4 do
		table.insert(sj, gulag_tasks.getJob("off_dstalker" .. i, 0, 5, {0}, squad, groups[1], "", gulags.esc_fox_house.out_rest, false, type, gulags.esc_fox_house.pred_any))
		table.insert(sj, gulag_tasks.getJob("dstalker" .. i,     0, 5, {1,2}, squad, groups[1], "", gulags.esc_fox_house.out_rest,   nil, type, gulags.esc_fox_house.pred_any))
	end
	table.insert(sj, gulag_tasks.getJob("fox_off", 0, 9, {0,2}, squad, groups[1], "", "", false, type, gulags.esc_fox_house.pred_fox))
	table.insert(sj, gulag_tasks.getJob("fox",     0, 9, {1}, squad, groups[1], "", "",   is_online, type, gulags.esc_fox_house.pred_fox))
end

gulags.esc_fox_house.state = function(gulag)
	if has_info("esc_rescue_fox_start") then
		if has_info("esc_fixer_teleported") then
			return 2
		end
		return 1 --/> online
	end
	return 0 --/> offline
end

--/ ---------------------------------------------
-- esc_assault
--/ ---------------------------------------------
gulags.esc_assault.pred_petruha = function(info) return info.story_id == 6014      end
gulags.esc_assault.pred_ranger1 = function(info) return info.name == "esc_ranger1" end
gulags.esc_assault.pred_ranger2 = function(info) return info.name == "esc_ranger2" end
gulags.esc_assault.pred_nimble = function(info) return info.story_id == 10017      end

gulags.esc_assault.jobs = function(sj, gname, type, squad, groups)
	table.insert(sj, gulag_tasks.getJob("petruha_wait",        0, 6, {0}, squad, groups[1], "", "",   nil, type, gulags.esc_assault.pred_petruha))
	table.insert(sj, gulag_tasks.getJob("ranger1_wait",        0, 5, {0}, squad, groups[1], "", "",   nil, type, gulags.esc_assault.pred_ranger1))
	table.insert(sj, gulag_tasks.getJob("ranger2_wait",        0, 5, {0}, squad, groups[1], "", "",   nil, type, gulags.esc_assault.pred_ranger2))
	table.insert(sj, gulag_tasks.getJob("petruha_approaching", 0, 6, {1}, squad, groups[1], "", "",   nil, type, gulags.esc_assault.pred_petruha))
	table.insert(sj, gulag_tasks.getJob("ranger1_approaching", 0, 5, {1}, squad, groups[1], "", "",   nil, type, gulags.esc_assault.pred_ranger1))
	table.insert(sj, gulag_tasks.getJob("ranger2_approaching", 0, 5, {1}, squad, groups[1], "", "",   nil, type, gulags.esc_assault.pred_ranger2))
	table.insert(sj, gulag_tasks.getJob("petruha_fight",       0, 6, {2}, squad, groups[1], "", gulags.esc_assault.out_rest, nil, type, gulags.esc_assault.pred_petruha))
	table.insert(sj, gulag_tasks.getJob("ranger1_fight",       0, 5, {2}, squad, groups[1], "", gulags.esc_assault.out_rest, nil, type, gulags.esc_assault.pred_ranger1))
	table.insert(sj, gulag_tasks.getJob("ranger2_fight",       0, 5, {2}, squad, groups[1], "", gulags.esc_assault.out_rest, nil, type, gulags.esc_assault.pred_ranger2))
	table.insert(sj, gulag_tasks.getJob("nimble",        0, 7,   {0,1,2}, squad, groups[1], "", "", nil, type, gulags.esc_assault.pred_nimble))
end

gulags.esc_assault.state = function(gulag)
	if has_info("scene_end") and not has_info("esc_assault_factory_alone") then
		return 2
	elseif has_info("esc_assault_factory_alone") and has_info("esc_factory_cleaned") then
		return 2
	elseif has_info("esc_assault_go1") and has_info("esc_assault_talked_petruha") then
		return 1
	end
	return 0
end

--[[
	if has_info("esc_assault_go2") then
		if has_info("esc_assault_factory_alone") then
			zeturn 1
		end
		if has_info("scene_end") then
				return 3
		end
		if not has_info("esc_assault_go1") then
			return 3
		end
		return 2
		
	elseif has_info("esc_assault_go1") and has_info("esc_assault_talked_petruha") then
		return 2
	elseif has_info("esc_talked_with_wolf") then
		return 1
	end
		return 0
	end
--]]

--/ ---------------------------------------------
--/ esc_blockpost
--/ ---------------------------------------------
--gulags.esc_blockpost.patrol_leader_pred = function(info) return info.name == "esc_blokpost_patrol_leader" end
--gulags.esc_blockpost.soldier1_pred      = function(info) return info.name == "esc_blokpost_soldier1" end
--gulags.esc_blockpost.soldier2_pred      = function(info) return info.name == "esc_blokpost_soldier2" end

gulags.esc_blockpost.pred_commander = function(info) return info.profile_name == "esc_soldier_blockpost_commander" end
gulags.esc_blockpost.pred_guard     = function(info) return info.name == "cordon_blockpost_soldier_guardhouse" end
gulags.esc_blockpost.pred_tower1    = function(info) return info.name == "cordon_blockpost_soldier_tower1" end
gulags.esc_blockpost.pred_tower2    = function(info) return info.name == "cordon_blockpost_soldier_tower2" end

gulags.esc_blockpost.jobs = function(sj, gname, type, squad, groups)
	table.insert(sj, gulag_tasks.getJob("commander",       0, 7, {0}, squad, groups[1], "", gulags.esc_blockpost.out_rest,  nil, type, gulags.esc_blockpost.pred_commander))
	table.insert(sj, gulag_tasks.getJob("guardhouse",      0, 6, {0}, squad, groups[1], "", gulags.esc_blockpost.out_rest,  nil, type, gulags.esc_blockpost.pred_guard))
	table.insert(sj, gulag_tasks.getJob("soldier_tower1",  0, 6, {0}, squad, groups[1], "", gulags.esc_blockpost.out_rest,  nil, type, gulags.esc_blockpost.pred_tower1))
	table.insert(sj, gulag_tasks.getJob("soldier_tower2",  0, 6, {0}, squad, groups[1], "", gulags.esc_blockpost.out_rest,  nil, type, gulags.esc_blockpost.pred_tower2))
	table.insert(sj, gulag_tasks.getJob("soldier_mgunner", 0, 6, {0}, squad, groups[1], "", gulags.esc_blockpost.out_rest,  false, type, on_level_pred))
	for i = 3, 6 do
		table.insert(sj, gulag_tasks.getJob("soldier" .. i,  0, 5, {0}, squad, groups[1], "", gulags.esc_blockpost.out_rest,  nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ esc_exit_smart
--/ ---------------------------------------------
gulags.esc_exit_smart.jobs = function(sj, gname, type, squad, groups)
	table.insert(sj, gulag_tasks.getJob("walking1",      0, 5, {0}, squad, groups[1], "", gulags.esc_exit_smart.out_rest, nil, type, on_level_pred))
	for i = 1, 3 do
		table.insert(sj, gulag_tasks.getJob("patrol" .. i, 0, 5, {0}, squad, groups[1], "", gulags.esc_exit_smart.out_rest, nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ karlik_smart
--/ ---------------------------------------------
gulags.esc_karlik_smart.jobs = function(sj, gname, type, squad, groups)
	table.insert(sj, gulag_tasks.getJob("camp", 0, 5, {0}, squad, groups[1], esc_mob_in_rest, "", nil, type, on_level_pred))
end

--/ ---------------------------------------------
--/ esc_bloodsucker_swamp
--/ ---------------------------------------------
gulags.esc_bloodsucker_swamp.jobs = function(sj, gname, type, squad, groups)
	gulags.esc_bloodsucker_swamp.ltx = smart_dyn_ltx.add_mob_home(type, 1, 15, 25, nil, nil, true)
	
	table.insert(sj, gulag_tasks.getJob("home_off1", 0, 5, {0}, squad, groups[1], "", "", false, type, on_level_pred))
	table.insert(sj, gulag_tasks.getJob("home1", 	 0, 5, {1}, squad, groups[1], "", "", nil, type, on_level_pred))
end

gulags.esc_bloodsucker_swamp.state = function(gulag)
	if has_info("esc_assault_bandit_factory_done") then
		return 1
	end
	return 0
end

--/ ---------------------------------------------
--/ esc_boar_back
--/ ---------------------------------------------
gulags.esc_boar_back.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 5 do
		table.insert(sj, gulag_tasks.getJob("boar" .. i, 0, 5, {0}, squad, groups[1], "esc_bandit_factory_out_rest,cordon_space_resrictor_0001", "", nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ esc_boars_lair
--/ ---------------------------------------------
gulags.esc_boars_lair.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 6 do
		table.insert(sj, gulag_tasks.getJob("boar" .. i,      0, 5, {0}, squad, groups[1], "esc_bandit_factory_out_rest,esc_petruha_in_rest,cordon_space_resrictor_0001", "", nil, type, on_level_pred))
	end
end
--/ ---------------------------------------------
--/ esc_psevdo_lair
--/ ---------------------------------------------
gulags.esc_psevdo_lair.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 3 do
		table.insert(sj, gulag_tasks.getJob("mut" .. i,      0, 5, {0}, squad, groups[1], esc_mob_fox_in_rest, "", nil, type, on_level_pred))
		table.insert(sj, gulag_tasks.getJob("raid_mut" .. i, 0, 5, {1}, squad, groups[1], esc_mob_fox_in_rest, "", nil, type, on_level_pred))
	end
end

gulags.esc_psevdo_lair.state = function(gulag)
	if has_info("gar_meet_seriy_start") then
		return 1
	end
	return 0
end

--/ ---------------------------------------------
--/ esc_dog_gar
--/ ---------------------------------------------
gulags.esc_dog_gar.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 3 do
		table.insert(sj, gulag_tasks.getJob("dog" .. i, 0, 5, {0}, squad, groups[1], esc_mob_fox_in_rest, "", nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ esc_dog_back
--/ ---------------------------------------------
gulags.esc_dog_back.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 2 do
		table.insert(sj, gulag_tasks.getJob("dog" .. i, 0, 5, {0}, squad, groups[1], esc_mob_fox_in_rest, "", nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ esc_dog_lair_sm
--/ ---------------------------------------------
gulags.esc_dog_lair_sm.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 3 do
		table.insert(sj, gulag_tasks.getJob("dog" .. i, 0, 5, {0}, squad, groups[1], esc_mob_fox_in_rest, "", nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ esc_dog_smart_1
--/ ---------------------------------------------
gulags.esc_dog_smart_1.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 3 do
		table.insert(sj, gulag_tasks.getJob("off_dog" .. i, 0, 5, {0}, squad, groups[1], "", "", false, type, on_level_pred))
		table.insert(sj, gulag_tasks.getJob("dog" .. i,     0, 5, {1}, squad, groups[1], esc_mob_fox_in_rest, "", nil, type, on_level_pred))
	end
end

gulags.esc_dog_smart_1.state = function(gulag)
	if has_info("esc_assault_bandit_factory_done") then
		return 1
	end
	return 0
end

--/ ---------------------------------------------
--/ esc_flesh_lair
--/ ---------------------------------------------
gulags.esc_flesh_lair.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 6 do
		table.insert(sj, gulag_tasks.getJob("flesh" .. i, 0, 5, {0}, squad, groups[1], esc_mob_fox_in_rest, "", nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ esc_fleshes_blockpost
--/ ---------------------------------------------
gulags.esc_fleshes_blockpost.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 3 do
		table.insert(sj, gulag_tasks.getJob("flesh" .. i, 0, 5, {0}, squad, groups[1], esc_mob_fox_in_rest, "", nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ esc_poltergeist_terrain
--/ ---------------------------------------------
gulags.esc_poltergeist_terrain.jobs = function(sj, gname, type, squad, groups)
	table.insert(sj, gulag_tasks.getJob("poltergeist1", 0, 5, {0}, squad, groups[1], esc_mob_in_rest, "", nil, type, on_level_pred))
end

--/ ---------------------------------------------
--/ esc_mixed_lair
--/ ---------------------------------------------
gulags.esc_mixed_lair.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 4 do
		table.insert(sj, gulag_tasks.getJob("mut" .. i, 0, 5, {0}, squad, groups[1], esc_mob_fox_in_rest, "", nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ esc_rats_lair
--/ ---------------------------------------------
gulags.esc_rats_lair.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 14 do
		table.insert(sj, gulag_tasks.getJob("off_rat" .. i, 0, 5, {0}, squad, groups[1], "", "", false, type, on_level_pred))
		table.insert(sj, gulag_tasks.getJob("rat" .. i,     0, 5, {1}, squad, groups[1], esc_mob_fox_in_rest, "", nil, type, on_level_pred))
	end
end

gulags.esc_rats_lair.state = function(gulag)
	if has_info("esc_fox_rescued") then
		return 1
	end
	return 0
end

--/ ---------------------------------------------
--/ esc_tuishkano_lair
--/ ---------------------------------------------
gulags.esc_tuishkano_lair.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 4 do
		table.insert(sj, gulag_tasks.getJob("tushkano" .. i, 0, 5, {0}, squad, groups[1], esc_mob_fox_in_rest, "", nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ esc_tunnel_zombie_terrain
--/ ---------------------------------------------
gulags.esc_tunnel_zombie_terrain.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 5 do
		table.insert(sj, gulag_tasks.getJob("zombie" .. i, 0, 5, {0}, squad, groups[1], "esc_zombie_restrictor", "esc_tunnel_zombie_restrictor", nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ esc_ug_zombie_terrain
--/ ---------------------------------------------

gulags.esc_ug_zombie_terrain.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 6 do
		table.insert(sj, gulag_tasks.getJob("zombie" .. i, 0, 5, {0}, squad, groups[1], "", "esc_ug_zombie_restrictor", nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ esc_tutorial_flesh_terrain
--/ ---------------------------------------------
gulags.esc_tutorial_flesh_terrain.flesh_pred = function(info) return info.name == "esc_tutorial_flesh" end

gulags.esc_tutorial_flesh_terrain.jobs = function(sj, gname, type, squad, groups)
	table.insert(sj, gulag_tasks.getJob("flesh_off", 0, 9, {0}, squad, groups[1], "", "", false, type, gulags.esc_tutorial_flesh_terrain.flesh_pred))
	table.insert(sj, gulag_tasks.getJob("flesh",     0, 9, {1}, squad, groups[1], "", "", is_online, type, gulags.esc_tutorial_flesh_terrain.flesh_pred))
	table.insert(sj, gulag_tasks.getJob("suicide",   0, 9, {2}, squad, groups[1], "", "", is_online, type, gulags.esc_tutorial_flesh_terrain.flesh_pred))
end

gulags.esc_tutorial_flesh_terrain.state = function(gulag)
	if has_info("esc_tut_flesh_dead") then
		return 0
	elseif has_info("esc_got_novice_drive") then
		if has_info("esc_tutorial_flesh_trigger") then
			return 2
		end
		return 1
	end
	return 0
end

--/ ---------------------------------------------
--/ esc_border_mutants
--/ ---------------------------------------------
gulags.esc_border_mutants.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 6 do
		table.insert(sj, gulag_tasks.getJob("mob" .. i, 0, 5, {0}, squad, groups[1], "cordon_space_restrictor_0004,esc_village_lager_out_rest", "esc_border_restrictor", nil, type, on_level_pred))
	end
end

--/ ---------------------------------------------
--/ esc_wandering_terrain
--/ ---------------------------------------------
gulags.esc_wandering_terrain.pred = function(info) return info.name:match("esc_wandering_terrain") end

gulags.esc_wandering_terrain.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 5 do
		table.insert(sj, gulag_tasks.getJob("kamper" .. i, 0, 5, {0}, squad, groups[1], "", "", nil, type, gulags.esc_wandering_terrain.pred))
	end
end

--/ ---------------------------------------------
--/ esc_wandering_terrain1
--/ ---------------------------------------------
gulags.esc_wandering_terrain1.pred = function(info) return info.name:match("esc_wandering_terrain") end

gulags.esc_wandering_terrain1.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 5 do
		table.insert(sj, gulag_tasks.getJob("kamper" .. i, 0, 5, {0}, squad, groups[1], "", "", nil, type, gulags.esc_wandering_terrain1.pred))
	end
end

--/ ---------------------------------------------
--/ esc_wandering_terrain2
--/ ---------------------------------------------
gulags.esc_wandering_terrain2.pred = function(info) return info.name:match("esc_wandering_terrain") end

gulags.esc_wandering_terrain2.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 5 do
		table.insert(sj, gulag_tasks.getJob("kamper" .. i, 0, 5, {0}, squad, groups[1], "", "", nil, type, gulags.esc_wandering_terrain2.pred))
	end
end

--/ ---------------------------------------------
--/ esc_tunnel_tushkano_terrain
--/ ---------------------------------------------
gulags.esc_tunnel_tushkano_terrain.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 6 do
		table.insert(sj, gulag_tasks.getJob("off_tushkano" .. i, 0, 5, {0}, squad, groups[1], "", "esc_tunnel_tushkano_terrain_restrictor", false, type, on_level_pred))
		table.insert(sj, gulag_tasks.getJob("tushkano" .. i, 0, 5, {1}, squad, groups[1], "", "esc_tunnel_tushkano_terrain_restrictor", nil, type, on_level_pred))
	end
end

gulags.esc_tunnel_tushkano_terrain.state = function(gulag)
	if has_info("esc_start_wagon_task") then
		return 1
	end
	return 0
end
--/ -----------------------------------------------------------------------------------------------

--/ ---------------------------------------------
--/ esc_tunnel_polter_terrain
--/ ---------------------------------------------
gulags.esc_tunnel_polter_terrain.jobs = function(sj, gname, type, squad, groups)
	for i = 1, 8 do
		table.insert(sj, gulag_tasks.getJob("poltergeist" .. i, 0, 5, {0}, squad, groups[1], "esc_petruha_in_rest", "esc_tunnel_polter_terrain_restrictor", nil, type, on_level_pred))
	end
end
--/ -----------------------------------------------------------------------------------------------