tasklist =
{
	IDLE = {
		name = "Idling",
	},
	DISPOSAL = {
		name = "Disposal",
		defaultsubtask = "FINDTRASH",
		subtasks =
		{
			FINDTRASH =
			{
				func = 
					function(unit)
						local trash = goget_item(unit,"POOP",false)
						
						if (trash == false) then
							trash = goget_item(unit,"GEM",false)
							
							if (trash == false) then
								goget_item(unit,"TRASH")
							end
						end
					end,
				nexttask = "DISPOSE",
				finish =
					function(unit)
						pickup(unit,MF_getvalue(unit.id,TARGET))
					end,
			},
			DISPOSE =
			{
				func = 
					function(unit)
						goget_struct(unit,"DISPOSAL")
					end,
				nexttask = "",
				finish =
					function(unit)
						local itemid = MF_getvalue(unit.id,CARRY)
						
						unit.wait = 10
						
						local style = MF_getstring(itemid,TYPE)
						
						if (style == "POOP") then
							MF_setvalue(GDATA,MATERIAL,MF_getvalue(GDATA,MATERIAL) + math.random(2,4))
						elseif (style == "TRASH") then
							MF_setvalue(GDATA,MATERIAL,MF_getvalue(GDATA,MATERIAL) + math.random(8,12))
						elseif (style == "GEM") then
							MF_setvalue(GDATA,ORE,MF_getvalue(GDATA,ORE) + math.random(1,2))
						end
						delete(itemid)
					end,
			},
		},
	},
	BUILD = {
		name = "Build",
		defaultsubtask = "FINDBUILDING",
		subtasks =
		{
			FINDBUILDING =
			{
				func = 
					function(unit)
						goget_struct(unit,"UNFINISHED",true)
					end,
				nexttask = "BUILD",
				finish =
					function(unit)
						reserve(unit,MF_getvalue(unit.id,TARGET))
						
						local structid = MF_getvalue(unit.id,TARGET)
						local style = MF_getvalue(structid,D_STYLE) + 1
						local data = roomlist[style]
						
						unit.work = data.work_needed
					end,
			},
			BUILD =
			{
				func = 
					function(unit)
					end,
				nexttask = "",
				finish =
					function(unit)
						local structid = MF_getvalue(unit.id,TARGET)
						release(unit)
						buildroom(structid)
						unit.wait = 50
					end,
			},
		},
	},
	REPAIR = {
		name = "Repair",
		defaultsubtask = "FINDDAMAGE",
		subtasks =
		{
			FINDDAMAGE =
			{
				func = 
					function(unit)
						goget_damaged(unit)
					end,
				nexttask = "REPAIR",
				finish =
					function(unit)
						unit.work = 90
					end,
			},
			REPAIR =
			{
				func = 
					function(unit)
					end,
				nexttask = "",
				finish =
					function(unit)
						local roomid = MF_getvalue(unit.id,TARGET)
						release(unit)
						MF_setvalue(roomid,HP,math.max(MF_getvalue(roomid,HP) - 20, 0))
						unit.wait = 10
					end,
			},
		},
	},
	DEFEND = {
		name = "Defend",
		defaultsubtask = "FINDGUARD",
		subtasks =
		{
			FINDGUARD =
			{
				func = 
					function(unit)
						goget_struct(unit,"GUARD",true)
					end,
				nexttask = "SHOOT",
				finish =
					function(unit)
						reserve(unit,MF_getvalue(unit.id,TARGET))
						
						unit.work = 60
					end,
			},
			SHOOT =
			{
				func = 
					function(unit)
					end,
				nexttask = "",
				finish =
					function(unit)
						local target = findfoe(unit)
						release(unit)
						unit.wait = 30
						
						if (target ~= nil) and (MF_getvalue(GDATA,ENERGY) >= 10) then
							MF_setvalue(GDATA,ENERGY,MF_getvalue(GDATA,ENERGY) - 10)
							fireat(unit,target)
						end
					end,
			},
		},
	},
	HARVEST = {
		name = "Harvest",
		defaultsubtask = "FINDPLANT",
		subtasks =
		{
			FINDPLANT =
			{
				func = 
					function(unit)
						local i = goget_item(unit,"PLANT",false)
						
						if (i == false) then
							goget_struct(unit,"GARDEN",true,2400)
						else
							MF_setstring(unit.id,SUBTASK,"GETPLANT")
							unit.nexttask = "BRINGPLANT"
						end
					end,
				nexttask = "PICK",
				finish =
					function(unit)
						reserve(unit,MF_getvalue(unit.id,TARGET))
						
						unit.work = 50
					end,
			},
			PICK =
			{
				func = 
					function(unit)
					end,
				nexttask = "BRINGPLANT",
				finish =
					function(unit)
						local structid = MF_getvalue(unit.id,TARGET)
						for i,v in ipairs(structs) do
							if (v.id == structid) then
								v.status = 0
								MF_setframe(structid,0)
								break
							end
						end
						release(unit)
						local x,y = MF_getvalue(unit.id,XTILE),MF_getvalue(unit.id,YTILE)
						local itemid = create_item("PLANT",x,y)
						pickup(unit,itemid)
					end,
			},
			BRINGPLANT =
			{
				func = 
					function(unit)
						goget_struct(unit,"TABLE",true)
					end,
				nexttask = "FOOD",
				finish =
					function(unit)
						reserve(unit,MF_getvalue(unit.id,TARGET))
						
						unit.work = 50
					end,
			},
			FOOD =
			{
				func = 
					function(unit)
					end,
				nexttask = "",
				finish =
					function(unit)
						local itemid = MF_getvalue(unit.id,CARRY)
						release(unit)
						drop(unit)
						delete(itemid)
						unit.wait = 50
						
						MF_setvalue(GDATA,FOOD,MF_getvalue(GDATA,FOOD) + 1)
					end,
			},
			GETPLANT =
			{
				func = 
					function(unit)
						local trash = goget_item(unit,"PLANT",false)
					end,
				nexttask = "BRINGPLANT",
				finish =
					function(unit)
						pickup(unit,MF_getvalue(unit.id,TARGET))
					end,
			},
		},
	},
	ENERGY = {
		name = "Recharge",
		defaultsubtask = "FINDGENERATOR",
		subtasks =
		{
			FINDGENERATOR =
			{
				func = 
					function(unit)
						local i = goget_item(unit,"BATTERY",false)
						
						if (i == false) then
							goget_struct(unit,"GENERATOR",true,200)
						else
							MF_setstring(unit.id,SUBTASK,"GETBATTERY")
							unit.nexttask = "BRINGBATTERY"
						end
					end,
				nexttask = "PICK",
				finish =
					function(unit)
						reserve(unit,MF_getvalue(unit.id,TARGET))
						
						unit.work = 50
					end,
			},
			PICK =
			{
				func = 
					function(unit)
					end,
				nexttask = "BRINGBATTERY",
				finish =
					function(unit)
						local structid = MF_getvalue(unit.id,TARGET)
						for i,v in ipairs(structs) do
							if (v.id == structid) then
								v.status = 0
								break
							end
						end
						release(unit)
						local x,y = MF_getvalue(unit.id,XTILE),MF_getvalue(unit.id,YTILE)
						local itemid = create_item("BATTERY",x,y)
						pickup(unit,itemid)
					end,
			},
			BRINGBATTERY =
			{
				func = 
					function(unit)
						goget_struct(unit,"ENGINE",true)
					end,
				nexttask = "PROCESS",
				finish =
					function(unit)
						reserve(unit,MF_getvalue(unit.id,TARGET))
						
						unit.work = 50
					end,
			},
			PROCESS =
			{
				func = 
					function(unit)
					end,
				nexttask = "",
				finish =
					function(unit)
						local itemid = MF_getvalue(unit.id,CARRY)
						release(unit)
						drop(unit)
						delete(itemid)
						unit.wait = 20
						
						MF_setvalue(GDATA,ENERGY,MF_getvalue(GDATA,ENERGY) + 800)
					end,
			},
			GETBATTERY =
			{
				func = 
					function(unit)
						local trash = goget_item(unit,"BATTERY",false)
					end,
				nexttask = "BRINGBATTERY",
				finish =
					function(unit)
						pickup(unit,MF_getvalue(unit.id,TARGET))
					end,
			},
		},
	},
	SLEEP = {
		unlisted = true,
		name = "Sleep",
		defaultsubtask = "FINDBED",
		subtasks =
		{
			FINDBED =
			{
				func = 
					function(unit)
						goget_struct(unit,"BED",true)
					end,
				nexttask = "SLEEP",
				finish =
					function(unit)
						reserve(unit,MF_getvalue(unit.id,TARGET))
						unit.work = 180
					end,
			},
			SLEEP =
			{
				func = 
					function(unit)
					end,
				nexttask = "",
				finish =
					function(unit)
						release(unit)
						unit.sleep = math.random(-300,300)
						unit.wait = 10
						
						returntotask(unit)
					end,
			},
		},
	},
	EAT = {
		unlisted = true,
		name = "Eat",
		defaultsubtask = "FINDTABLE",
		subtasks =
		{
			FINDTABLE =
			{
				func = 
					function(unit)
						goget_struct(unit,"TABLE",true)
					end,
				nexttask = "EAT",
				finish =
					function(unit)
						reserve(unit,MF_getvalue(unit.id,TARGET))
						unit.work = 40
					end,
			},
			EAT =
			{
				func = 
					function(unit)
					end,
				nexttask = "",
				finish =
					function(unit)
						release(unit)
						local x,y = MF_getvalue(unit.id,XTILE),MF_getvalue(unit.id,YTILE)
						create_item("POOP",x,y)
						unit.food = math.random(-200,200)
						unit.wait = 10
						
						returntotask(unit)
						
						MF_setvalue(GDATA,FOOD,MF_getvalue(GDATA,FOOD) - 1)
					end,
			},
		},
	},
	GEAR = {
		unlisted = true,
		name = "Get diving gear",
		defaultsubtask = "GETGEAR",
		subtasks =
		{
			GETGEAR =
			{
				func = 
					function(unit)
						goget_item(unit,"GEAR")
					end,
				nexttask = "",
				finish =
					function(unit)
						equip(unit,MF_getvalue(unit.id,TARGET))
						returntotask(unit)
						unit.work = 10
					end,
			},
			RETURNGEAR =
			{
				func = 
					function(unit)
						goget_struct(unit,"STAND")
					end,
				nexttask = "",
				finish =
					function(unit)
						unequip(unit)
						unit.wait = 10
						
						returntotask(unit)
					end,
			},
		},
	},
}