var/const
	TREE_LAYER=14

var
	trees_made=0
proc
	make_all_trees()
		if(trees_made==1) return
		trees_made=1
		for(var/obj/placeable/trees/X in world)
			X.generate()

mob
	var
		tmp
			list/tree_track=list()

obj
	placeable
		crow
			name="Crow"
			icon='crow.dmi'
			layer=15
			up
				pixel_y=6
			right
				pixel_x=6
			left
				pixel_x=-6
			down
				pixel_y=-6
			New()
				..()
				icon_state=pick("","anim","anim 2","anim 3")
				pixel_x+=rand(-2,2)
				pixel_y+=rand(-2,2)
				transform=matrix()
				transform*=0.7
				dir=pick(EAST,WEST)

obj
	placeable
		trees
			layer=TREE_LAYER
			density=1
			mouse_opacity=0
			var
				tile_wide // How many tiles wide this is
				tile_high // How many tiles high this is
				start_x=-1 // How many X tiles to offset at start

				active=1 // If the tree is active/it hasn't been chopped down.


				tmp
					old_istate
					list
						fade_spots=list()
/*			verb
				test_matrix_edit(a as num,b as num,c as num,d as num,e as num,f as num)
					set src in view()
					transform=matrix(a,b,c,d,e,f)
				test_matrix_translate(xs as num,ys as num)
					set src in view()
					var/matrix/M=matrix()
					M.Translate(xs,ys)
					transform=M
			verb
				test_chop_down()
					set src in view()
					chop_down()
			verb
				test_generate()
					set src in view()
					generate()
				test_fading()
					set src in view()
					fade_out()
					sleep(30)
					fade_in()*/
			proc

				refresh_tree()


					chop_down(1)
				chop_down(set_to)
					if(active==set_to) return
					if(active==1)
						old_istate=icon_state
						icon_state="stump [icon_state]"
						generate("stump ")
					else
						icon_state=old_istate
						generate()
						old_istate=null
					if(set_to)
						active=set_to
					else
						active=!active
				check_me()
					var/is=0
					for(var/mob/Z in view(tile_high,src))
						if(active==1)
							if(Z.loc in fade_spots)
								is=1
								fade_out()
								break
					if(is==0) fade_in()
				fade_out()
					if(alpha!=120)
						animate(src,alpha=120,time=10)
				fade_in()
					if(alpha!=255)
						animate(src,alpha=255,time=10)
				generate(istate_pre)
					var/list/X=icon_states(icon)
					var/count_wide=0
					var/count_high=0
					overlays=list()
					while(count_high<tile_high)
						var/state=X[1]
						X-=state
						if(state!=icon_state)
							var/obj/placeable/trees/Z=new
							Z.icon=icon
							Z.icon_state="[istate_pre][state]"
							Z.pixel_x=(count_wide+start_x)*32
							Z.pixel_y=count_high*32
							overlays+=Z
						if(count_high!=0)
							var/x_mod=(count_wide+start_x)
							var/y_mod=count_high
							var/turf/T=locate(x+x_mod,y+y_mod,z)
							fade_spots+=T
						count_wide++
						if(count_wide>=tile_wide)
							count_wide=0
							count_high++


			tree_1
				icon='fade_tree1.dmi'
				icon_state="1,0"
				tile_wide=3
				tile_high=4

			tree_2
				icon='fade_tree2.dmi'
				icon_state="2,0"
				tile_wide=5
				tile_high=4
				start_x=-2

			tree_3
				icon='fade_tree3.dmi'
				icon_state="1,0"
				tile_wide=3
				tile_high=4


			tree_4
				icon='fade_tree4.dmi'
				icon_state="1,0"
				tile_wide=3
				tile_high=3


			tree_5
				icon='fade_tree5.dmi'
				icon_state="1,0"
				tile_wide=3
				tile_high=3

			tree_6
				icon='fade_tree6.dmi'
				icon_state="2,0"
				tile_wide=5
				tile_high=6
				start_x=-2

			tree_7
				icon='fade_tree7.dmi'
				icon_state="2,0"
				tile_wide=5
				tile_high=6
				start_x=-2


			tree_8
				icon='fade_tree8.dmi'
				icon_state="2,0"
				tile_wide=5
				tile_high=6
				start_x=-2


			tree_9
				icon='fade_tree9.dmi'
				icon_state="2,0"
				tile_wide=5
				tile_high=6
				start_x=-2



			snow_tree1
				icon='snow_tree1.dmi'
				icon_state="0,0"
				tile_wide=2
				tile_high=3
				pixel_x=-16
				start_x=0

			snow_tree2
				icon='snow_tree2.dmi'
				icon_state="0,0"
				tile_wide=2
				tile_high=3
				pixel_x=-16
				start_x=0

			snow_tree3
				icon='snow_tree3.dmi'
				icon_state="0,0"
				tile_wide=2
				tile_high=3
				pixel_x=-16
				start_x=0

			snow_tree4
				icon='snow_tree4.dmi'
				icon_state="0,0"
				tile_wide=2
				tile_high=3
				start_x=0
