{
id: "aiming_cannon",
has_feet: false,
vars: {
	load: 0,
},
on_shoot_horz: "[
	   spawn('cannon.missile', midpoint_x + facing*20, img_mid_y, facing,
	         [set(velocity_x, 800*facing)]),
	spawn('explosion_spark', midpoint_x + facing*40, img_mid_y+10*up, facing)]",
on_shoot_diag: "[
	    spawn('cannon.missile', midpoint_x + facing*20, img_mid_y + 20*up, facing,
		      [set(velocity_x, 500*facing),
			   set(velocity_y, 500*up),
			   set(rotate, facing*45*up),set(upside_down, upside_down)]),
	spawn('explosion_spark', midpoint_x + facing*30, img_mid_y+40*up, facing)]",
on_shoot_vert: "[spawn('cannon.missile', midpoint_x, img_mid_y + 20*up, facing,
	                [set(velocity_y, 800*up), set(rotate, -90*up)]),
	spawn('explosion_spark', midpoint_x, img_mid_y+40*up, facing)]",
on_end_anim: "switch(animation,
		'fire_horz', animation('aim_horz'),
		'fire_diag', animation('aim_diag'),
	    'fire_vert', animation('aim_vert'),
	
	    [if(preferred_aim = current_aim, [animation(animation)],
	         switch(if(preferred_aim < current_aim, current_aim - 1,
			                                        current_aim + 1),
					0, [facing(-1), animation('aim_horz')],
					1, [facing(-1), animation('aim_diag')],
					2, [facing(-1), animation('aim_vert')],
					3, [facing(1), animation('aim_diag')],
					4, [facing(1), animation('aim_horz')])),
	              if(vars.load >= vars.loading_time, [set_var('load', 0),
				      animation(switch(animation,
					                   'aim_horz', 'fire_horz',
					                   'aim_diag', 'fire_diag',
					                   'aim_vert', 'fire_vert'))
				                    ],
				                    set_var('load', vars.load + 1))]
								)
	   where preferred_aim =
	     if( if(upside_down > 0, level.player.y < y2, level.player.y2 > y),
	     		 if(level.player.x < x, 0, 4),
		    if(level.player.x2 > x and level.player.x < x2, 2,
			     if(level.player.x < x, 1, 3))),
		     current_aim = switch(animation,
			   'aim_vert', 2,
			   'aim_diag', if(facing < 0, 1, 3),
			   'aim_horz', if(facing < 0, 0, 4))",
solid_area: [9,10,24,31],
editor_info: {
	category: "enemies, milgramen",
	var: [
		{
			name: "loading_time",
			value: 10,
			min_value: 1,
			max_value: 10
		},
	],
},
animation: [
	{
		"@base": true,
		palettes: "@include data/palettes.cfg:dungeon_palettes",
		no_remove_alpha_borders: true,
		image: "enemies/cannon.png",
	},
	{
		id: "aim_horz",
		rect: [3,77,36,110],
		duration: 10,
	},
	{
		id: "aim_diag",
		rect: [40,77,73,110],
		duration: 10,
	},
	{
		id: "aim_vert",
		rect: [77,77,110,110],
		duration: 10,
	},
	{
		id: "fire_horz",
		rect: [3,3,36,36],
		duration: 6,
		pad: 3,
		frames: 2,
		frames_per_row: 1,
		events: "5:shoot_horz",
		sound: "cannon.ogg",
	},
	{
		id: "fire_diag",
		rect: [40,3,73,36],
		duration: 6,
		pad: 3,
		frames: 2,
		frames_per_row: 1,
		events: "5:shoot_diag",
		sound: "cannon.ogg",
	},
	{
		id: "fire_vert",
		rect: [77,3,110,36],
		duration: 6,
		pad: 3,
		frames: 2,
		frames_per_row: 1,
		events: "5:shoot_vert",
		sound: "cannon.ogg",
	},
],
}