local animal_kinds = {
	kind_nature = true,
	kind_mountain = true,
	kind_wild = true,
	kind_feral = true,
	kind_demon = true,
}
local undead_kinds = {
	kind_fresh = true,
	kind_rotten = true,
	kind_tormented = true,
	kind_soulless = true,
}
local mentalist_kinds = {
	kind_recruit = true,
	kind_mentalist = true,
	kind_master = true,
}

local monster_kinds = {
	kind_slobber = true,
	kind_growler = true,
	kind_engulfer = true,
}

local villager_kinds = {
	kind_villager = true,
	kind_townsfolk = true,
	kind_cityfolk = true,
	kind_heroes = true,
	kind_adventurers = true,
}


local RULE_ENTITYS = {
	categories = {
		hero = {
			actor_type = "player",
			inventory_type = "hero",
			unarmed_item = "punch",
			sprite_category = "creature",
			sprite_ids = {"44","45","46","47","48","49","50","51","52","53","54","55","56","57","58"},
		},

		
		--village
		villager = {
			actor_type = "monster",
			name = "Villager",
			inventory_type = "npc",
			unarmed_item = "punch",
			sprite_category = "creature",
			sprite_ids = {"44","45","46","47","48","49","50","51","52","53","54","55","56","57","58"},
			kinds = villager_kinds,
			stats = {
				melee = 0,
				ranged = 0,
				magic = 0,
				health = 3,
				stamina = 4,
				speed = 1,
				armor = 0,
				resistance = -1,
				size = 1,
				control = 2,
			},
		},
		stool = {
			actor_type = "static",
			name = "Stool",
			sprite_category = "world",
			sprite_id = "01",
			height = 2,
		},
		crate = {
			actor_type = "destructible",
			name = "Crate",
			container_type = "crate",
			sprite_category = "world",
			sprite_id = "02",
			height = 3,
		},
		barrel = {
			actor_type = "destructible",
			name = "Barrel",
			container_type = "barrel",
			sprite_category = "world",
			sprite_id = "04",
			height = 4,
		},

		--cart
		haybale = {
			actor_type = "destructible",
			name = "Haybale",
			container_type = "haybale",
			sprite_category = "world",
			sprite_ids = {"05","06"},
			height = 4,
		},
		cart = {
			actor_type = "static",
			name = "Cart",
			sprite_category = "world",
			sprite_id = "07",
			height = 6,
		},
		wheel_stack = {
			actor_type = "static",
			name = "Wheel stack",
			sprite_category = "world",
			sprite_id = "08",
			height = 6,
		},

		--well
		rope_coil = {
			actor_type = "destructible",
			name = "Rope coil",
			container_type = "rope_coil",
			sprite_category = "world",
			sprite_id = "10",
			height = 2,
		},
		bucket = {
			actor_type = "destructible",
			name = "Bucket",
			container_type = "bucket",
			sprite_category = "world",
			sprite_id = "09",
			height = 2,
		},
		well = {
			actor_type = "destructible",
			name = "Well",
			container_type = "well",
			sprite_category = "world",
			sprite_id = "11",
			height = 6,
		},
		
		--house
		mouse = {
			actor_type = "monster",
			name = "Mouse",
			unarmed_item = "bite",
			sprite_category = "creature",
			sprite_id = "05",
			kinds = villager_kinds,
			stats = {
				melee = 1,
				ranged = 0,
				magic = -3,
				health = -2,
				stamina = 6,
				speed = 5,
				armor = 0,
				resistance = 0,
				size = -1,
				control = 4,
			},
		},
		butterfly = {
			actor_type = "monster",
			name = "Butterfly",
			unarmed_item = "whip",
			sprite_category = "creature",
			sprite_id = "06",
			kinds = villager_kinds,
			stats = {
				melee = -2,
				ranged = 0,
				magic = 0,
				health = -2,
				stamina = -1,
				speed = 8,
				armor = 0,
				resistance = 2,
				size = -1,
				control = 6,
			},
		},
		house_shelf = {
			actor_type = "destructible",
			name = "House shelf",
			container_type = "house_shelf",
			sprite_category = "world",
			sprite_ids = {"45","46","47","48"},
			height = 7,
		},
		house_table = {
			actor_type = "static",
			name = "House table",
			sprite_category = "world",
			sprite_ids = {"12","13"},
			height = 4,
		},
		house_chair = {
			actor_type = "static",
			name = "House chair",
			sprite_category = "world",
			sprite_ids = {"13","14","15"},
			height = 2,
		},
		house_chest = {
			actor_type = "destructible",
			name = "House chest",
			container_type = "house_chest",
			sprite_category = "world",
			sprite_id = "17",
			height = 4,
		},


		--library
		moth = {
			actor_type = "monster",
			name = "Moth",
			unarmed_item = "whip",
			sprite_category = "creature",
			sprite_id = "07",
			kinds = villager_kinds,
			stats = {
				melee = -1,
				ranged = 0.5,
				magic = 0,
				health = -2,
				stamina = 1,
				speed = 6,
				armor = 0.5,
				resistance = 0,
				size = -1,
				control = 6,
			},
		},
		librarian = {
			actor_type = "monster",
			name = "Librarian",
			shop_type = "librarian",
			inventory_type = "npc",
			unarmed_item = "punch",
			sprite_category = "creature",
			sprite_id = "61",
			kinds = villager_kinds,
			stats = {
				melee = 1,
				ranged = 0,
				magic = 0,
				health = 2,
				stamina = 2,
				speed = 1,
				armor = 0,
				resistance = 2,
				size = 1,
				control = 1,
			},
		},
		library_table = {
			actor_type = "static",
			name = "Library table",
			sprite_category = "world",
			sprite_id = "44",
			height = 3,
		},
		library_chair = {
			actor_type = "static",
			name = "Library chair",
			sprite_category = "world",
			sprite_ids = {"41","42","43"},
			height = 2,
		},
		book_shelf = {
			actor_type = "destructible",
			name = "Book shelf",
			container_type = "book_shelf",
			sprite_category = "world",
			sprite_ids = {"32","33","34","35"},
			height = 6,
		},
		library_chest = {
			actor_type = "destructible",
			name = "Library chest",
			container_type = "library_chest",
			sprite_category = "world",
			sprite_id = "21",
			height = 3,
		},


		--kitchen
		cockroach = {
			actor_type = "monster",
			name = "Cockroach",
			unarmed_item = "bite",
			sprite_category = "creature",
			sprite_id = "08",
			kinds = villager_kinds,
			stats = {
				melee = 0,
				ranged = 0,
				magic = 0,
				health = 1,
				stamina = 4,
				speed = 2,
				armor = 1,
				resistance = 0,
				size = 0,
				control = 2,
			},
		},
		maggot = {
			actor_type = "monster",
			name = "Maggot",
			unarmed_item = "bite",
			sprite_category = "creature",
			sprite_id = "09",
			kinds = villager_kinds,
			stats = {
				melee = 1,
				ranged = 0,
				magic = 1,
				health = 0,
				stamina = 4,
				speed = -1,
				armor = 1,
				resistance = 1,
				size = 0,
				control = 3,
			},
		},
		chef = {
			actor_type = "monster",
			name = "Chef",
			shop_type = "chef",
			unarmed_item = "punch",
			inventory_type = "npc",
			sprite_category = "creature",
			sprite_id = "62",
			kinds = villager_kinds,
			stats = {
				melee = 4,
				ranged = 0,
				magic = 0,
				health = 4,
				stamina = 1,
				speed = 0,
				armor = 0,
				resistance = 0,
				size = 0,
				control = 1,
			},
		},
		kitchen_table = {
			actor_type = "static",
			name = "Kitchen table",
			sprite_category = "world",
			sprite_id = "19",
			height = 4,
		},
		kitchen_chair = {
			actor_type = "static",
			name = "Kitchen chair",
			sprite_category = "world",
			sprite_ids = {"22","23","24"},
			height = 2,
		},
		kitchen_chest = {
			actor_type = "destructible",
			name = "Kitchen chest",
			container_type = "kitchen_chest",
			sprite_category = "world",
			sprite_id = "25",
			height = 3,
		},
		kitchen_bin = {
			actor_type = "destructible",
			name = "Kitchen bin",
			container_type = "kitchen_bin",
			sprite_category = "world",
			sprite_id = "26",
			height = 2,
		},
		food_crate = {
			actor_type = "destructible",
			name = "Food crate",
			container_type = "food_crate",
			sprite_category = "world",
			sprite_ids = {"26","27","28"},
			height = 2,
		},
		food_basket = {
			actor_type = "destructible",
			name = "Food basket",
			container_type = "food_basket",
			sprite_category = "world",
			sprite_ids = {"29","30","31"},
			height = 2 ,
		},


		--graveyard
		bat = {
			actor_type = "monster",
			name = "Bat",
			unarmed_item = "bite",
			sprite_category = "creature",
			container_type = "bat",
			sprite_id = "01",			
			height = 2,
			level_offset = 0,
			kinds = undead_kinds,
			stats = {
				melee = 1,
				ranged = 0,
				magic = 0,
				health = -1,
				stamina = 1,
				speed = 3,
				armor = 0,
				resistance = 2,
				size = -1,
				control = 5,
			},
		},
		zombie = {
			actor_type = "monster",
			name = "Zombie",
			unarmed_item = "punch",			
			container_type = "zombie",
			sprite_category = "creature",
			sprite_id = "02",
			height = 2,
			level_offset = 1,
			kinds = undead_kinds,
			stats = {
				melee = 3,
				ranged = 0,
				magic = 0,
				health = 2,
				stamina = 2,
				speed = -1,
				armor = 0,
				resistance = 0,
				size = 1,
				control = 3,
			},
		},
		skeleton = {
			actor_type = "monster",
			name = "Skeleton",
			unarmed_item = "punch",
			inventory_type = "monster_melee",
			container_type = "skeleton",
			sprite_category = "creature",
			sprite_id = "03",
			height = 2,
			level_offset = 2,
			kinds = undead_kinds,
			stats = {
				melee = 4,
				ranged = 0,
				magic = 0,
				health = 2,
				stamina = -1,
				speed = 1,
				armor = 0,
				resistance = 0,
				size = 1,
				control = 3,
			},
		},
		skeleton_mage = {
			actor_type = "monster",
			name = "Skeleton_mage",
			unarmed_item = "punch",
			inventory_type = "monster_mage",
			container_type = "skeleton_mage",
			sprite_category = "creature",
			sprite_id = "03",
			height = 2,
			level_offset = 4,
			kinds = undead_kinds,
			stats = {
				melee = 0,
				ranged = 0,
				magic = 4,
				health = 1,
				stamina = 0,
				speed = 1,
				armor = 0,
				resistance = 1,
				size = 1,
				control = 2,
			},
		},
		mummy = {
			actor_type = "monster",
			name = "Mummy",
			unarmed_item = "punch",
			inventory_type = "monster_melee",
			container_type = "mummy",
			sprite_category = "creature",
			sprite_id = "04",
			height = 2,
			level_offset = 3,
			kinds = undead_kinds,
			stats = {
				melee = 2,
				ranged = -1,
				magic = -1,
				health = 3,
				stamina = 3,
				speed = 0,
				armor = -1,
				resistance = 2,
				size = 1,
				control = 2,
			},
		},
		graveyard_chest = {
			actor_type = "destructible",
			name = "Graveyard chest",
			container_type = "graveyard_chest",
			sprite_category = "world",
			sprite_ids = {"50","51"},
			height = 3,
		},
		small_urn = {
			actor_type = "destructible",
			name = "Small urn",
			container_type = "small_urn",
			sprite_category = "world",
			sprite_id = "52",
			height = 2,
		},
		big_urn = {
			actor_type = "destructible",
			name = "Big urn",
			container_type = "big_urn",
			sprite_category = "world",
			sprite_id = "53",
			height = ´3,
		},
		grave_mound = {
			actor_type = "static",
			name = "Grave mound",
			sprite_category = "world",
			sprite_ids = {"63","64","65","66"},
			height = 4,
		},
		grave_stone = {
			actor_type = "static",
			name = "Grave stone",
			sprite_category = "world",
			sprite_ids = {"54","55","56","57","58","59","60","61","62"},
			height = 2,
		},
		grave_statue = {
			actor_type = "static",
			name = "Grave statue",
			sprite_category = "world",
			sprite_ids = {"67","68","69"},
			height = 2,
		},

		--crypt
		vampire = {
			actor_type = "monster",
			name = "Vampire",
			unarmed_item = "punch",
			inventory_type = "monster_mage_boss",
			container_type = "vampire",
			sprite_category = "creature",
			sprite_id = "10",
			height = 2,
			level_offset = 5,
			kinds = undead_kinds,
			stats = {
				melee = 2,
				ranged = 2,
				magic = 0,
				health = 3,
				stamina = 3,
				speed = 2,
				armor = -2,
				resistance = -2,
				size = 1,
				control = 1,
			},
		},
		necromancer = {
			actor_type = "monster",
			name = "Necromancer",
			unarmed_item = "punch",
			inventory_type = "monster_mage_boss",
			container_type = "necromancer",
			sprite_category = "creature",
			sprite_id = "11",
			height = 2,
			level_offset = 6,
			kinds = undead_kinds,
			stats = {
				melee = 0,
				ranged = 1,
				magic = 2,
				health = 4,
				stamina = 2,
				speed = 0,
				armor = -2,
				resistance = 2,
				size = 1,
				control = 0,
			},
		},
		crypt_chest = {
			actor_type = "destructible",
			name = "Crypt chest",
			container_type = "crypt_chest",
			sprite_category = "world",
			sprite_ids = {"70","71"},
			height = 3,
		},


		--working
		work_chair = {
			actor_type = "static",
			name = "Work chair",
			sprite_category = "world",
			sprite_ids = {"75","76","77"},
			height =2,
		},
		work_table = {
			actor_type = "static",
			name = "Work table",
			sprite_category = "world",
			sprite_ids = {"72","73"},
			height = 3,
		},
		anvil = {
			actor_type = "static",
			name = "Anvil",
			sprite_category = "world",
			sprite_ids = {"77","78"},
			height = 3,
		},
		tool_box = {
			actor_type = "destructible",
			name = "Tool box",
			container_type = "tool_box",
			sprite_category = "world",
			sprite_id = "79",
			height = 1,
		},

		--armorer
		armorer = {
			actor_type = "monster",
			name = "Armorer",
			shop_type = "armorer",
			unarmed_item = "punch",
			inventory_type = "npc_armorer",
			sprite_category = "creature",
			sprite_id = "65",
			height = 2,
			kinds = villager_kinds,
			stats = {
				melee = 1,
				ranged = 0,
				magic = 0,
				health = 2,
				stamina = 2,
				speed = -2,
				armor = 3,
				resistance = 0,
				size = 1,
				control = 3,
			},
		},
		magpie = {
			actor_type = "monster",
			name = "Magpie",
			unarmed_item = "bite",
			sprite_category = "creature",
			sprite_id = "20",
			height = 2,
			kinds = villager_kinds,
			stats = {
				melee = 2,
				ranged = 0,
				magic = 0,
				health = 0,
				stamina = 1,
				speed = 6,
				armor = 0,
				resistance = 3,
				size = -1,
				control = -1,
			},
		},
		armorer_chest = {
			actor_type = "destructible",
			name = "Armorer chest",
			container_type = "armorer_chest",
			sprite_category = "world",
			sprite_ids = {"80","81"},
			height = 4,
		},
		armorer_cabinet = {
			actor_type = "destructible",
			name = "Armorer cabinet",
			container_type = "armorer_cabinet",
			sprite_category = "world",
			sprite_id = "82",
			height = 4,
		},
		armor_rack = {
			actor_type = "destructible",
			name = "Armor rack",
			container_type = "armor_rack",
			sprite_category = "world",
			sprite_id = "88",
			height = 4,
		},
		
	
	
		--smith
		smith = {
			actor_type = "monster",
			name = "Smith",
			shop_type = "smith",
			unarmed_item = "punch",
			inventory_type = "npc_smith",
			sprite_category = "creature",
			sprite_id = "64",
			height = 2,
			kinds = villager_kinds,
			stats = {
				melee = 5,
				ranged = 0,
				magic = 0,
				health = 2,
				stamina = 2,
				speed = -1,
				armor = 0,
				resistance = 0,
				size = 1,
				control = 1,
			},
		},
		firefly = {
			actor_type = "monster",
			name = "Firefly",
			unarmed_item = "thorn",
			sprite_category = "creature",
			sprite_id = "12",
			height = 2,
			kinds = villager_kinds,
			stats = {
				melee = 1,
				ranged = 1,
				magic = 3,
				health = -1,
				stamina = -1,
				speed = 0,
				armor = 0,
				resistance = 3,
				size = 1,
				control = 3,
			},
		},
		smith_chest = {
			actor_type = "destructible",
			name = "Smith chest",
			container_type = "smith_chest",
			sprite_category = "world",
			sprite_id = "83",
			height = 3,
		},
		smith_cabinet = {
			actor_type = "destructible",
			name = "Smith cabinet",
			container_type = "smith_cabinet",
			sprite_category = "world",
			sprite_id = "84",
			height = 4,
		},
		weapon_rack = {
			actor_type = "destructible",
			name = "Weapon rack",
			container_type = "weapon_rack",
			sprite_category = "world",
			sprite_ids = {"85","86","87","88"},
			height = 3,
		},
		


		--wizard
		wizard = {
			actor_type = "monster",
			name = "Wizard",
			shop_type = "wizard",
			unarmed_item = "punch",
			inventory_type = "npc_wizard",
			sprite_category = "creature",
			sprite_id = "13",
			height = 2,
			kinds = villager_kinds,
			stats = {
				melee = -1,
				ranged = -1,
				magic = 5,
				health = 2,
				stamina = 2,
				speed = 0,
				armor = 0,
				resistance = 2,
				size = 1,
				control = 0,
			},
		},
		lizard = {
			actor_type = "monster",
			name = "Lizard",
			unarmed_item = "bite",
			sprite_category = "creature",
			sprite_id = "14",
			height = 2,
			kinds = villager_kinds,
			stats = {
				melee = 1,
				ranged = 0,
				magic = 0,
				health = -1,
				stamina = 3,
				speed = 1,
				armor = 0,
				resistance = 4,
				size = -1,
				control = 3,
			},
		},
		owl = {
			actor_type = "monster",
			name = "Owl",
			unarmed_item = "pincer",
			sprite_category = "creature",
			sprite_id = "15",
			height = 2,
			kinds = villager_kinds,
			stats = {
				melee = 2,
				ranged = 1,
				magic = 0,
				health = 0,
				stamina = 1,
				speed = 4,
				armor = 0,
				resistance = 2,
				size = -1,
				control = 1,
			},
		},
		wizard_chest = {
			actor_type = "destructible",
			name = "Wizard chest",
			container_type = "wizard_chest",
			sprite_category = "world",
			sprite_ids = {"92","93"},
			height = 4,
		},
		robe_closet = {
			actor_type = "destructible",
			name = "Robe closet",
			container_type = "robe_closet",
			sprite_category = "world",
			sprite_id = "84",
			height = 4,
		},
		staff_rack = {
			actor_type = "destructible",
			name = "Staff rack",
			container_type = "staff_rack",
			sprite_category = "world",
			sprite_id = "88",
			height = 4,
		},
		jewlery_box = {
			actor_type = "destructible",
			name = "Jewlery box",
			container_type = "jewlery_box",
			sprite_category = "world",
			sprite_id = "25",
			height = 4,
		},

		

		--merchant
		merchant = {
			actor_type = "monster",
			name = "Merchant",
			shop_type = "merchant",
			unarmed_item = "punch",
			inventory_type = "npc_merchant",
			sprite_category = "creature",
			sprite_id = "63",
			height = 2,
			level_offset = 0,
			kinds = villager_kinds,
			stats = {
				melee = 1,
				ranged = 1,
				magic = 1,
				health = 2,
				stamina = 2,
				speed = -1,
				armor = 1,
				resistance = 1,
				size = 1,
				control = 1,
			},
		},
		dog = {
			actor_type = "monster",
			name = "Dog",
			unarmed_item = "bite",
			sprite_category = "creature",
			sprite_id = "16",
			height = 2,
			level_offset = 2,
			kinds = villager_kinds,
			stats = {
				melee = 3,
				ranged = 0,
				magic = 0,
				health = 0,
				stamina = 2,
				speed = 2,
				armor = 0,
				resistance = 0,
				size = 0,
				control = 3,
			},
		},
		hawk = {
			actor_type = "monster",
			name = "Hawk",
			unarmed_item = "pincer",
			sprite_category = "creature",
			sprite_id = "17",
			height = 2,
			level_offset = 4,
			kinds = villager_kinds,
			stats = {
				melee = 2,
				ranged = 1,
				magic = 0,
				health = -1,
				stamina = 1,
				speed = 5,
				armor = 0,
				resistance = 1,
				size = 0,
				control = 1,
			},
		},
		merchant_wagon = {
			actor_type = "destructible",
			name = "Merchant wagon",
			container_type = "merchant_wagon",
			sprite_category = "world",
			sprite_id = "89",
			height = 6,
		},
		merchant_knapsack = {
			actor_type = "destructible",
			name = "Merchant knapsack",
			container_type = "merchant_knapsack",
			sprite_category = "world",
			sprite_id = "90",
			height = 1,
		},
		merchant_crate = {
			actor_type = "destructible",
			name = "Merchant crate",
			container_type = "merchant_crate",
			sprite_category = "world",
			sprite_id = "91",
			height = 3,
		},


		--alchemist
		alchemist = {
			actor_type = "monster",
			name = "Alchemist",
			shop_type = "alchemist",
			unarmed_item = "punch",
			inventory_type = "npc_alchemist",
			sprite_category = "creature",
			sprite_id = "59",
			height = 2,
			kinds = villager_kinds,
			stats = {
				melee = 1,
				ranged = 0,
				magic = 0,
				health = 1,
				stamina = 1,
				speed = 0,
				armor = 0,
				resistance = 3,
				size = 1,
				control = 3,
			},
		},
		toad = {
			actor_type = "monster",
			name = "Toad",
			unarmed_item = "knock",
			sprite_category = "creature",
			sprite_id = "19",
			height = 2,
			kinds = villager_kinds,
			stats = {
				melee = 2,
				ranged = 0,
				magic = 1,
				health = -1,
				stamina = 3,
				speed = 0,
				armor = 0,
				resistance = 3,
				size = 0,
				control = 2,
			},
		},
		raven = {
			actor_type = "monster",
			name = "Raven",
			unarmed_item = "bite",
			sprite_category = "creature",
			sprite_id = "20",
			height = 2,
			kinds = villager_kinds,
			stats = {
				melee = 2,
				ranged = 0,
				magic = 1,
				health = -1,
				stamina = 2,
				speed = 4,
				armor = 0,
				resistance = 1,
				size = 0,
				control = 1,
			},
		},
		alchemist_chest = {
			actor_type = "destructible",
			name = "Alchemist chest",
			container_type = "alchemist_chest",
			sprite_category = "world",
			sprite_ids = {"92","93"},
			height = 4,
		},
		ingredient_crate = {
			actor_type = "destructible",
			name = "Ingredient crate",
			container_type = "ingredient_crate",
			sprite_category = "world",
			sprite_id = "94",
			height = 4,
		},
		potion_rack = {
			actor_type = "destructible",
			name = "Potion rack",
			container_type = "potion_rack",
			sprite_category = "world",
			sprite_ids = {"45", "46"},
			height = 4,
		},


		--ranger
		ranger = {
			actor_type = "monster",
			name = "Ranger",
			shop_type = "ranger",
			unarmed_item = "punch",
			inventory_type = "npc_ranger",
			sprite_category = "creature",
			sprite_id = "60",
			height = 2,
			kinds = villager_kinds,
			stats = {
				melee = 1,
				ranged = 4,
				magic = 0,
				health = 1,
				stamina = 2,
				speed = 1,
				armor = -1,
				resistance = 0,
				size = 1,
				control = 1,
			},
		},
		cat = {
			actor_type = "monster",
			name = "Cat",
			unarmed_item = "bite",
			sprite_category = "creature",
			sprite_id = "22",
			height = 2,
			kinds = villager_kinds,
			stats = {
				melee = 2,
				ranged = 0,
				magic = 0,
				health = 0,
				stamina = 3,
				speed = 3,
				armor = 0,
				resistance = 0,
				size = 0,
				control = 2,
			},
		},
		gecko = {
			actor_type = "monster",
			name = "Gecko",
			unarmed_item = "bite",
			sprite_category = "creature",
			sprite_id = "23",
			height = 2,
			kinds = villager_kinds,
			stats = {
				melee = 2,
				ranged = 0,
				magic = 0,
				health = 1,
				stamina = 2,
				speed = 3,
				armor = 0,
				resistance = 0,
				size = -1,
				control = 3,
			},
		},
		ranger_chest = {
			actor_type = "destructible",
			name = "Ranger chest",
			container_type = "ranger_chest",
			sprite_category = "world",
			sprite_id = "84",
			height = 4,
		},
		writing_desk = {
			actor_type = "destructible",
			name = "Writing desk",
			container_type = "writing_desk",
			sprite_category = "world",
			sprite_id = "72",
			height = 4,
		},
		pen_box = {
			actor_type = "destructible",
			name = "Pen box",
			container_type = "pen_box",
			sprite_category = "world",
			sprite_id = "79",
			height = 2,
		},


		--insane camp
		mentalist_striker = {
			actor_type = "monster",
			name = "Mentalist Striker",
			unarmed_item = "punch",
			container_type = "mentalist",
			inventory_type = "monster_melee",
			sprite_category = "creature",
			sprite_id = "24",
			height = 2,
			level_offset = 0,
			kinds = mentalist_kinds,
			stats = {
				melee = 4,
				ranged = 0,
				magic = 0,
				health = 1,
				stamina = 2,
				speed = 1,
				armor = 0,
				resistance = 0,
				size = 1,
				control = 1,
			},
		},
		mentalist_invoker = {
			actor_type = "monster",
			name = "Mentalist Invoker",
			unarmed_item = "punch",
			container_type = "mentalist",
			inventory_type = "monster_mage",
			sprite_category = "creature",
			sprite_id = "25",
			height = 2,
			level_offset = 3,
			kinds = mentalist_kinds,
			stats = {
				melee = 0,
				ranged = 0,
				magic = 4,
				health = 1,
				stamina = 2,
				speed = 0,
				armor = 0,
				resistance = 1,
				size = 1,
				control = 1,
			},
		},
		mentalist_strangler = {
			actor_type = "monster",
			name = "Mentalist Strangler",
			unarmed_item = "punch",
			container_type = "mentalist",
			inventory_type = "monster_natural",
			sprite_category = "creature",
			sprite_id = "26",
			height = 2,
			level_offset = 2,
			kinds = mentalist_kinds,
			stats = {
				melee = 4,
				ranged = 0,
				magic = 0,
				health = 1,
				stamina = 4,
				speed = 1,
				armor = 1,
				resistance = -2,
				size = 1,
				control = 0,
			},
		},
		mentalist_thrower = {
			actor_type = "monster",
			name = "Mentalist Thrower",
			unarmed_item = "punch",
			container_type = "mentalist",
			inventory_type = "monster_ranged",
			sprite_category = "creature",
			sprite_id = "27",
			height = 2,
			level_offset = 1,
			kinds = mentalist_kinds,
			stats = {
				melee = 0,
				ranged = 4,
				magic = 0,
				health = 2,
				stamina = 2,
				speed = 1,
				armor = 0,
				resistance = 0,
				size = 1,
				control = 0,
			},
		},
		weredog = {
			actor_type = "monster",
			name = "Weredog",
			unarmed_item = "bite",
			container_type = "mentalist_monster",
			inventory_type = "monster_natural",
			sprite_category = "creature",
			sprite_id = "28",
			height = 2,
			level_offset = 1,
			kinds = monster_kinds,
			stats = {
				melee = 4,
				ranged = 0,
				magic = 0,
				health = 1,
				stamina = 1,
				speed = 3,
				armor = -1,
				resistance = 0,
				size = 1,
				control = 1,
			},
		},
		murdercrow = {
			actor_type = "monster",
			name = "Murdercrow",
			unarmed_item = "bite",
			container_type = "mentalist_monster",
			inventory_type = "monster_natural",
			sprite_category = "creature",
			sprite_id = "29",
			height = 2,
			level_offset = 0,
			kinds = monster_kinds,
			stats = {
				melee = 3,
				ranged = 1,
				magic = 0,
				health = 1,
				stamina = 0,
				speed = 5,
				armor = 0,
				resistance = 0,
				size = 0,
				control = 0,
			},
		},
		arachnid_small = {
			actor_type = "monster",
			name = "Spider",
			unarmed_item = "sting",
			container_type = "mentalist_monster",
			inventory_type = "monster_natural",
			sprite_category = "creature",
			sprite_id = "30",
			height = 2,
			level_offset = 0,
			kinds = monster_kinds,
			stats = {
				melee = 3,
				ranged = 3,
				magic = 0,
				health = -1,
				stamina = 0,
				speed = 2,
				armor = 0,
				resistance = 2,
				size = -1,
				control = 2,
			},
		},
		arachnid_big = {
			actor_type = "monster",
			name = "Arachnid",
			unarmed_item = "sting",
			container_type = "mentalist_monster",
			inventory_type = "monster_natural",
			sprite_category = "creature",
			sprite_id = "31",
			height = 2,
			level_offset = 2,
			kinds = monster_kinds,
			stats = {
				melee = 4,
				ranged = 1,
				magic = 0,
				health = 1,
				stamina = 1,
				speed = 1,
				armor = 0,
				resistance = 1,
				size = 1,
				control = 0,
			},
		},
		mentalist_chest = {
			actor_type = "destructible",
			name = "Mentalist chest",
			container_type = "mentalist_chest",
			sprite_category = "world",
			sprite_id = "96",
		},
		mentalist_tent = {
			actor_type = "static",
			name = "Mentalist tent",
			sprite_category = "world",
			sprite_id = "97",
		},
		ritual_urn = {
			actor_type = "destructible",
			name = "Ritual urn",
			container_type = "ritual_urn",
			sprite_category = "world",
			sprite_id = "98",
		},
		ritual_stake = {
			actor_type = "static",
			name = "Ritual stake",
			sprite_category = "world",
			sprite_id = "99",
		},
		barbed_stake = {
			actor_type = "static",
			name = "Barbed stake",
			sprite_category = "world",
			sprite_id = "100",
		},
		mentalist_barrel = {
			actor_type = "destructible",
			name = "Mentalist barrel",
			container_type = "mentalist_barrel",
			sprite_category = "world",
			sprite_id = "95",
		},
		ritual_fire = {
			actor_type = "static",
			name = "Ritual fire",
			sprite_category = "world",
			sprite_id = "101",
		},
		camp_fire = {
			actor_type = "static",
			name = "Camp fire",
			sprite_category = "world",
			sprite_id = "102",
		},
		bed_roll = {
			actor_type = "static",
			name = "Bed roll",
			sprite_category = "world",
			sprite_id = "103",
		},
		animal_cage = {
			actor_type = "static",
			name = "Animal cage",
			sprite_category = "world",
			sprite_id = "104",
		},

		--animals
		possum = {
			actor_type = "monster",
			name = "Possum",
			unarmed_item = "bite",
			container_type = "animal_small",
			sprite_category = "creature",
			sprite_id = "32",
			height = 5,
			level_offset = 1,
			kinds = animal_kinds,
			stats = {
				melee = 1,
				ranged = 0,
				magic = 0,
				health = 0,
				stamina = 1,
				speed = 3,
				armor = 0,
				resistance = 0,
				size = 0,
				control = 5,
			},
		},
		bunny = {
			actor_type = "monster",
			name = "Bunny",
			unarmed_item = "bite",
			container_type = "animal_small",
			sprite_category = "creature",
			sprite_id = "33",
			height = 4,
			level_offset = 0,
			kinds = animal_kinds,
			stats = {
				melee = 1,
				ranged = 0,
				magic = 0,
				health = 0,
				stamina = 2,
				speed = 4,
				armor = 0,
				resistance = 0,
				size = -1,
				control = 4,
			},
		},
		turtle = {
			actor_type = "monster",
			name = "Turtle",
			unarmed_item = "bite",
			container_type = "animal_small",
			sprite_category = "creature",
			sprite_id = "34",
			height = 3,
			level_offset = 2,
			kinds = animal_kinds,
			stats = {
				melee = 3,
				ranged = 0,
				magic = 0,
				health = 1,
				stamina = 4,
				speed = -3,
				armor = 0,
				resistance = 0,
				size = 1,
				control = 4,
			},
		},
		snake = {
			actor_type = "monster",
			name = "Snake",
			unarmed_item = "bite",
			container_type = "animal_small",
			sprite_category = "creature",
			sprite_id = "35",
			height = 4,
			level_offset = 3,
			kinds = animal_kinds,
			stats = {
				melee = 3,
				ranged = 0,
				magic = 0,
				health = -1,
				stamina = 3,
				speed = 2,
				armor = 0,
				resistance = 1,
				size = 1,
				control = 1,
			},
		},
		nest_small = {
			actor_type = "destructible",
			name = "Nest small",
			container_type = "nest_small",
			sprite_category = "world",
			sprite_id = "105",
		},

		fox = {
			actor_type = "monster",
			name = "Fox",
			unarmed_item = "bite",
			container_type = "animal_medium",
			sprite_category = "creature",
			sprite_id = "36",
			height = 3,
			level_offset = 4,
			kinds = animal_kinds,
			stats = {
				melee = 2,
				ranged = 0,
				magic = 0,
				health = 0,
				stamina = 2,
				speed = 2,
				armor = 0,
				resistance = 0,
				size = 0,
				control = 4,
			},
		},
		wolf = {
			actor_type = "monster",
			name = "Wolf",
			unarmed_item = "bite",
			container_type = "animal_medium",
			sprite_category = "creature",
			sprite_id = "37",
			height = 5,
			level_offset = 5,
			kinds = animal_kinds,
			stats = {
				melee = 2,
				ranged = 0,
				magic = 0,
				health = 1,
				stamina = 3,
				speed = 2,
				armor = 0,
				resistance = 0,
				size = 0,
				control = 2,
			},
		},
		deer = {
			actor_type = "monster",
			name = "Deer",
			unarmed_item = "knock",
			container_type = "animal_medium",
			sprite_category = "creature",
			sprite_id = "38",
			height = 10,
			level_offset = 3,
			kinds = animal_kinds,
			stats = {
				melee = -2,
				ranged = 0,
				magic = 0,
				health = -1,
				stamina = 5,
				speed = 4,
				armor = 0,
				resistance = 0,
				size = 0,
				control = 4,
			},
		},
		wolverine = {
			actor_type = "monster",
			name = "Wolverine",
			unarmed_item = "bite",
			container_type = "animal_medium",
			sprite_category = "creature",
			sprite_id = "39",
			height = 8,
			level_offset = 4,
			kinds = animal_kinds,
			stats = {
				melee = 2,
				ranged = 0,
				magic = 0,
				health = 1,
				stamina = -1,
				speed = 3,
				armor = 0,
				resistance = 0,
				size = 1,
				control = 4,
			},
		},
		nest_medium = {
			actor_type = "destructible",
			name = "Nest medium",
			container_type = "nest_medium",
			sprite_category = "world",
			sprite_id = "106",
		},

		tiger = {
			actor_type = "monster",
			name = "Tiger",
			unarmed_item = "bite",
			container_type = "animal_big",
			sprite_category = "creature",
			sprite_id = "40",
			height = 8,
			level_offset = 5,
			kinds = animal_kinds,
			stats = {
				melee = 4,
				ranged = 0,
				magic = 0,
				health = 4,
				stamina = 3,
				speed = 2,
				armor = -2,
				resistance = -2,
				size = 2,
				control = -1,
			},
		},
		lion = {
			actor_type = "monster",
			name = "Lion",
			unarmed_item = "bite",
			container_type = "animal_big",
			sprite_category = "creature",
			sprite_id = "41",
			height = 10,
			level_offset = 6,
			kinds = animal_kinds,
			stats = {
				melee = 5,
				ranged = 0,
				magic = 0,
				health = 5,
				stamina = 4,
				speed = 1,
				armor = -3,
				resistance = -3,
				size = 2,
				control = -1,
			},
		},
		moose = {
			actor_type = "monster",
			name = "Moose",
			unarmed_item = "knock",
			container_type = "animal_big",
			sprite_category = "creature",
			sprite_id = "42",
			height = 12,
			level_offset = 2,
			kinds = animal_kinds,
			stats = {
				melee = -1,
				ranged = 0,
				magic = 0,
				health = 2,
				stamina = 5,
				speed = 2,
				armor = 0,
				resistance = 0,
				size = 2,
				control = 0,
			},
		},
		bear = {
			actor_type = "monster",
			name = "Bear",
			unarmed_item = "bite",
			container_type = "animal_big",
			sprite_category = "creature",
			sprite_id = "43",
			height = 11,
			level_offset = 3,
			kinds = animal_kinds,
			stats = {
				melee = 2,
				ranged = 0,
				magic = 0,
				health = 4,
				stamina = 5,
				speed = 4,
				armor = -1,
				resistance = -1,
				size = 2,
				control = -5,
			},
		},
		nest_big = {
			actor_type = "destructible",
			name = "Nest big",
			container_type = "nest_big",
			sprite_category = "world",
			sprite_id = "105",
		},


		--npcs
		kind_villager = {
			stat_bonus = 0,
			level_peak = 1,
			level_range = 30,
			kind_tint = FloatColor:new(1, 1, 1, 1),
		},
		kind_townsfolk = {
			stat_bonus = 2,
			level_peak = 20,
			level_range = 30,
			kind_tint = FloatColor:new(1, 1, 1, 0.95),
		},
		kind_cityfolk = {
			stat_bonus = 4,
			level_peak = 40,
			level_range = 30,
			kind_tint = FloatColor:new(1, 0.95, 1, 0.95),
		},
		kind_adventurers = {
			stat_bonus = 6,
			level_peak = 60,
			level_range = 30,
			kind_tint = FloatColor:new(1, 1, 0.95, 1),
		},
		kind_heroes = {
			stat_bonus = 8,
			level_peak = 80,
			level_range = 30,
			kind_tint = FloatColor:new(1, 0.95, 0.95, 1),
		},

		--animals
		kind_nature = {
			name = "Nature",
			prefix = "Forest",
			stat_bonus = 0,
			level_peak = 1,
			level_range = 20,
		},
		kind_mountain = {
			name = "Mountain",
			prefix = "Mountain",
			stat_bonus = 2,
			level_peak = 20,
			level_range = 20,
			kind_tint = FloatColor:new(1, 0.87, 0.73, 0.76),
		},
		kind_wild = {
			name = "Wild",
			prefix = "Wild",
			stat_bonus = 4,
			level_peak = 40,
			level_range = 30,
			kind_tint = FloatColor:new(1, 1, 0.77, 0.95),
		},
		kind_feral = {
			name = "Feral",
			prefix = "Feral",
			stat_bonus = 6,
			level_peak = 60,
			level_range = 40,
			kind_tint = FloatColor:new(1, 1, 0.93, 0.83),
		},
		kind_demon = {
			name = "Demon",
			prefix = "Demon",
			stat_bonus = 8,
			level_peak = 80,
			level_range = 60,
			kind_tint = FloatColor:new(1, 0.92, 0.74, 0.63),
		},

		--mentalists
		kind_recruit = {
			name = "Recruit",
			suffix = "Recruit",
			stat_bonus = 0,
			level_peak = 10,
			level_range = 30,
			kind_tint = FloatColor:new(1, 1, 0.95, 0.65),
		},
		kind_mentalist = {
			name = "Mentalist",
			stat_bonus = 5,
			level_peak = 50,
			level_range = 40,
			kind_tint = FloatColor:new(1, 0.81, 0.95, 1),
		},
		kind_master = {
			name = "Master",
			suffix = "Master",
			stat_bonus = 10,
			level_peak = 100,
			level_range = 75,
			kind_tint = FloatColor:new(1, 0.55, 0.45, 0.45),
		},

		--monsters
		kind_slobber = {
			name = "Slobber",
			suffix = "Slobber",
			level_peak = 10,
			level_range = 30,
			stat_bonus = 0,
			kind_tint = FloatColor:new(1, 0.85, 0.95, 0.85),
		},
		kind_growler = {
			name = "Growler",
			stat_bonus = 5,
			level_peak = 50,
			level_range = 40,
			kind_tint = FloatColor:new(1, 1, 0.9, 0.86),
		},
		kind_engulfer = {
			name = "Engulfer",
			suffix = "Engulfer",
			stat_bonus = 10,
			level_peak = 100,
			level_range = 75,
			kind_tint = FloatColor:new(1, 1, 0.75, 0.55),
		},

		--undead
		kind_fresh = {
			name = "Fresh",
			prefix = "Fresh",
			stat_bonus = 1,
			level_peak = 10,
			level_range = 25,
			kind_tint = FloatColor:new(1, 1, 1, 1),
		},
		kind_rotten = {
			name = "Rotten",
			prefix = "Rotten",
			stat_bonus = 3,
			level_peak = 30,
			level_range = 30,
			kind_tint = FloatColor:new(1, 0.8, 1, 1),
		},
		kind_tormented = {
			name = "Tormented",
			prefix = "Tormented",
			stat_bonus = 7,
			level_peak = 70,
			level_range = 30,
			kind_tint = FloatColor:new(1, 0.95, 1, 0.77),
		},
		kind_soulless = {
			name = "Soulless",
			prefix = "Soulless",
			stat_bonus = 9,
			level_peak = 90,
			level_range = 30,
			kind_tint = FloatColor:new(1, 0.55, 0.77, 1),
		},





		--nature
		plant_pretty = {
			actor_type = "static",
			name = "Plant pretty",
			-- container_type = "plant_pretty",
			sprite_category = "nature",
			sprite_id = "19",
			height = 0,
		},
		plant_potent = {
			actor_type = "destructible",
			name = "Plant potent",
			container_type = "plant_potent",
			sprite_category = "nature",
			sprite_id = "20",
			height = 0,
		},

		tree_small = {
			actor_type = "static",
			-- container_type = "tree_small",
			sprite_category = "nature",
			sprite_ids = {"01","02","03"},
			height = 6,
		},
		tree_big = {
			actor_type = "static",
			-- container_type = "tree_big",
			sprite_category = "nature",
			sprite_ids = {"04","05","06"},
			height = 6,
		},

		fruit_bush = {
			actor_type = "destructible",
			name = "Fruit bush",
			container_type = "fruit_bush",
			sprite_category = "nature",
			sprite_ids = {"07","08"},
			height = 3,
		},
		tangled_roots = {
			actor_type = "destructible",
			name = "Tangled roots",
			container_type = "tangled_roots",
			sprite_category = "nature",
			sprite_ids = {"21","22","23","24"},
			height = 0,
		},
		rock_loose = {
			actor_type = "destructible",
			name = "Rock loose",
			container_type = "rock_loose",
			sprite_category = "nature",
			sprite_ids = {"34","35","36"},
			height = 0,
		},

		
		grass = {
			actor_type = "bg",
			name = "Grass",
			sprite_category = "nature_bg",
			sprite_ids = {"06","07","08","09","10"},
			height = 0,
		},
		grass_tall = {
			actor_type = "bg",
			name = "Grass tall",
			sprite_category = "nature_bg",
			sprite_ids = {"11","12","13","14"},
			height = 0,
		},
		bush_small = {
			actor_type = "static",
			name = "Bush small",
			sprite_category = "nature",
			sprite_ids = {"11","12"},
			height = 0,
		},
		bush_big = {
			actor_type = "static",
			name = "Bush big",
			sprite_category = "nature",
			sprite_ids = {"09","10"},
			height = 0,
		},
		spiky_bush = {
			actor_type = "static",
			name = "Spiky bush",
			sprite_category = "nature",
			sprite_ids = {"13","14","15","16"},
			height = 0,
		},
		rotten_log = {
			actor_type = "static",
			name = "Rotten log",
			sprite_category = "nature",
			sprite_ids = {"17","18"},
			height = 0,
		},
		rock_big = {
			actor_type = "static",
			name = "Rock big",
			sprite_category = "nature",
			sprite_ids = {"25","26","27","28"},
			height = 0,
		},
		rock_small = {
			actor_type = "static",
			name = "Rock small",
			sprite_category = "nature",
			sprite_ids = {"29","30","31","32","33"},
			height = 0,
		},
		bog_puddle = {
			actor_type = "bg",
			name = "Bog puddle",
			sprite_category = "nature_bg",
			sprite_ids = {"01","02","03","04","05"},
			height = 0,
		},

		--Walls
		wall_house = {
			actor_type = "bg",
			name = "Wall House",
			sprite_category = "walls",
			sprite_ids = {"0001","0002","0003","0004","0005"},
			height = 0,
		},

		corner_house = {
			actor_type = "bg",
			name = "Corner House",
			sprite_category = "walls",
			sprite_ids = {"0006","0007","0008","0009","0010"},
			height = 0,
		},

		wall_alchemy = {
			actor_type = "bg",
			name = "Wall Alchemy",
			sprite_category = "walls",
			sprite_ids = {"0011","0012","0013","0014","0015"},
			height = 0,
		},

		corner_alchemy = {
			actor_type = "bg",
			name = "Corner Alchemy",
			sprite_category = "walls",
			sprite_ids = {"0016","0017","0018","0019","0020"},
			height = 0,
		},

		wall_necromancer_crypt = {
			actor_type = "bg",
			name = "Wall Alchemy",
			sprite_category = "walls",
			sprite_ids = {"0021","0022","0023","0024","0025"},
			height = 0,
		},

		corner_necromancer_crypt = {
			actor_type = "bg",
			name = "Corner Alchemy",
			sprite_category = "walls",
			sprite_ids = {"0026","0027","0028","0029","0030"},
			height = 0,
		},

		wall_graveyard = {
			actor_type = "bg",
			name = "Wall Graveyard",
			sprite_category = "walls",
			sprite_ids = {"0031","0032","0033","0034","0035"},
			height = 0,
		},

		corner_graveyard = {
			actor_type = "bg",
			name = "Corner Graveyard",
			sprite_category = "walls",
			sprite_ids = {"0036","0037","0038","0039","0040"},
			height = 0,
		},

		wall_library = {
			actor_type = "bg",
			name = "Wall Library",
			sprite_category = "walls",
			sprite_ids = {"0041","0042","0043","0044","0045"},
			height = 0,
		},

		corner_library = {
			actor_type = "bg",
			name = "Corner Library",
			sprite_category = "walls",
			sprite_ids = {"0046","0047","0048","0049","0050"},
			height = 0,
		},

		wall_kitchen = {
			actor_type = "bg",
			name = "Wall Kitchen",
			sprite_category = "walls",
			sprite_ids = {"0051","0052","0053","0054","0055"},
			height = 0,
		},

		corner_kitchen = {
			actor_type = "bg",
			name = "Corner Kitchen",
			sprite_category = "walls",
			sprite_ids = {"0056","0057","0058","0059","0060"},
			height = 0,
		},
	},
	generate = function(rules, def, level, index)

		if def.level then
			level = def.level
		end
		
		local ent = Entity:new(def.actor_type, 0, 0, 0)
		ent.char_index = index

		if def.height then
			ent.render_offset_z = def.height
			if ent.add_y_offset then
				ent:add_y_offset(def.height)
			end
		end

		if def.container_type then
			ent:set_container(rules:generate_instance("container", def.container_type, level))
		end

		if def.inventory_type then
			local inv = rules:generate_instance("inventory", def.inventory_type, level)			
			ent:set_inventory(inv)
		end

		if def.shop_type then
			ent:set_shop(rules:generate_instance("shop", def.shop_type, level))
		end

		if def.unarmed_item then
			local item = rules:generate_instance("item", def.unarmed_item, level)
			ent:set_unarmed_item(item)
		end

		if def.name and ent.aspects.named then			
			ent:set_name(def.name)
		end

		if ent.aspects.level then
			ent:set_level(level)
		end
		
		if def.stats then
			assert(ent.set_stats)
			ent:set_stats(def.stats)			
		end

		if def.outline_name or def.outline_names then
			if def.sprite_name then
				local spr, out = SPRITES[def.sprite_name], SPRITES[def.outline_name]
				assert(spr and spr >= 0, index)
				assert(out and out >= 0, index)
				ent:set_sprites(spr, out)
			elseif def.sprite_names then
				local var = math.random(1,def.sprite_variations)
				local spr, out = SPRITES[def.sprite_names[var]], SPRITES[def.outline_names[var]]
				assert(spr and spr >= 0, index)
				assert(out and out >= 0, index)
				ent:set_sprites(spr, out)
			end	
		else
			if def.sprite_name then
				local spr = SPRITES[def.sprite_name]
				assert (spr and spr >= 0, index)
				ent:set_sprites(spr)		
			elseif def.sprite_names then
				local var = math.random(1,def.sprite_variations)
				local spr = SPRITES[def.sprite_names[var]]
				assert(spr and spr >= 0, index)
				ent:set_sprites(spr)
			end	
		end
		
		return ent
	end,
}

local sprite_bases = {
	creature = {
		sprite_prefix = "creatures_",
		outline = "creatures_outline_",
	},
	world = {
		sprite_prefix = "world_",
		outline = "world_outliner_",
	},
	nature = {
		sprite_prefix = "nature_",
		outline = "nature_outline_",
	},
	nature_bg = {
		sprite_prefix = "nature_bg_",
	},
	walls = {
		sprite_suffix = "-walls",
	}
}

local KIND_BONUS_MUL = 5
local LEVEL_OFFSET_STAT_BONUS_FACTOR = 0.1
local STAT_BONUS_FACTOR = {
	health = 0.1,
	stamina = 0.1,
	speed = 0.01,
	armor = 0.1,
	resistance = 0.1,
	size = 0.05,
	control = 0.05,
}

rule_entities = {}
function rule_entities.init()
	local new_defs = {}
	for index, def in pairs(RULE_ENTITYS.categories) do
		if def.sprite_id then
			local base = sprite_bases[def.sprite_category]			
			def.sprite_name = (base.sprite_prefix or "")..def.sprite_id..(base.sprite_suffix or "")
			if base.outline then
				def.outline_name = base.outline..def.sprite_id
			end
		end
		if def.sprite_ids then
			local base = sprite_bases[def.sprite_category]
			def.sprite_names = {}
			if base.outline then
				def.outline_names = {}
			end
			def.sprite_variations = #def.sprite_ids
			for index, id in pairs(def.sprite_ids) do
				def.sprite_names[index] = (base.sprite_prefix or "")..id..(base.sprite_suffix or "")
				if base.outline then
					def.outline_names[index] = base.outline..id
				end
			end
		end

		if def.stats then
			local tot = 0
			for index, v in pairs(def.stats) do
				tot = tot + v
			end
			if tot ~= 10 then
				print(index, tot)
			end
		end

		if def.kinds then
			local filters = {}
			filters[index] = true				
			for kind,_ in pairs(def.kinds) do
				local new_index = kind.."_"..index
				local new_def = table.shallowCopy(def)
				new_def.filters = filters
				assert(new_def.filters, index)
				local kind_def = RULE_ENTITYS.categories[kind]
				assert(kind_def, kind)
				local name = def.name
				if kind_def.prefix then
					name = kind_def.prefix.." "..name
				end
				if kind_def.suffix then
					name = name.." "..kind_def.suffix
				end
				new_def.name = name
				local level_offset = (def.level_offset or 0)
				local level_peak = kind_def.level_peak + level_offset
				new_def.level_peak = level_peak
				new_def.level = level_peak
				new_def.level_range = kind_def.level_range*(def.level_range_factor or 1)
				new_def.level_peak_factor = (kind_def.level_peak_factor or 1)* (def.level_peak_factor or 1)
				new_def.kinds = nil
				new_def.kind = kind
				
				if def.stats then
					local stats = {}
					local stat_bonus = kind_def.stat_bonus + level_offset*LEVEL_OFFSET_STAT_BONUS_FACTOR
					for stat, amt in pairs(def.stats) do
						local bonus_factor = (STAT_BONUS_FACTOR[stat] or 0)
						local new_amt = amt
						if bonus_factor ~= 0 then
							new_amt = new_amt + math.abs(amt)*bonus_factor*stat_bonus*KIND_BONUS_MUL
						end
						stats[stat] = math.round(new_amt*10)/10
						--print("STATS", stat, stats[stat])
					end
					new_def.stats = stats
				end

				new_def.tint = kind_def.kind_tint
				new_defs[new_index] = new_def
				
				--print("generated", new_index," at level peak", new_def.level_peak)
			end
			RULE_ENTITYS.categories[index] = nil
		end
	end

	for index, new_def in pairs(new_defs) do
		RULE_ENTITYS.categories[index] = new_def
	end

end

return RULE_ENTITYS