TILE_SIZE = 16
BW = 240
BH = 160

-- Milestones
MS_OPENING_SCENE = 1
MS_CELL_SCENE = 2
MS_REMOVED_SQUEEKY_BOARDS = 3
MS_KEEP_CHEST_0 = 4
MS_UNDERGROUND_CHEST_0 = 5
MS_UNDERGROUND_CHEST_1 = 6
MS_UNDERGROUND_CHEST_2 = 7
MS_UNDERGROUND_CHEST_3 = 8
MS_UNDERGROUND_CHEST_4 = 9
MS_ITEM_CHOOSER_HELP = 10
MS_SAVE_SPOT_HELP = 11
MS_UNDERGROUND_0_CHEST = 12
MS_UNDERGROUND_0_CHEST_2 = 13
MS_RIDER_APPEARED = 14
MS_RIDER_JOINED = 15
MS_UNDERGROUND_1_CHEST_0 = 16
MS_UNDERGROUND_1_CHEST_1 = 17
MS_UNDERGROUND_1_CHEST_2 = 18
MS_UNDERGROUND_2_CHEST_1 = 19
MS_DEFEATED_MONSTER = 20
MS_ENCOUNTERED_MONSTER = 21
MS_UNDERGROUND_2_CHEST_2 = 22
MS_UNDERGROUND_2_CHEST_3 = 23
MS_MET_HORSE = 24
MS_SEASIDE_REPAIRED = 25
MS_GOT_BADGE = 26
MS_BURNED_SEASIDE_CHEST_0 = 27
MS_BURNED_SEASIDE_CHEST_1 = 28
MS_BURNED_SEASIDE_CHEST_2 = 29
MS_RIOS_JOINED = 30
MS_ACTIVATED_RIOS = 31
MS_TALKED_TO_RIOS = 32
MS_TALKED_TO_CAPTAIN = 33
MS_LEFT_SEASIDE_BY_BOAT = 34
MS_LEFT_EAST_BY_BOAT = 35
MS_GOT_FRUIT = 36
MS_GOT_FRUIT_JUICE = 37
MS_SAILORS_WORD = 38
MS_SAILED_PERIOD = 39 -- sailed at least once to eastern dock
MS_GUNNAR_JOINED = 40
MS_STARTED_THRONE_SCENE = 41
MS_ENDED_THRONE_SCENE = 42
MS_GOT_RING = 43
MS_CASTLE_TOWER1_CHEST0 = 44
MS_CASTLE_TOWER3_CHEST0 = 45
MS_CASTLE_CHEST0 = 46
MS_CASTLE_SLEEP_HINT = 47
MS_BEAT_WITCH = 48
MS_MOUNTAIN_CHEST_0 = 49
MS_MOUNTAIN_CHEST_1 = 50
MS_MOUNTAIN_CHEST_2 = 51 
MS_MOUNTAIN_CHEST_3 = 52
MS_MOUNTAIN_CHEST_4 = 53
MS_UNLOCKED_FLOWEY = 54
MS_GOLEM_TIMER_STARTED = 55
MS_KILLED_GOLEMS = 56
MS_KILLED_1_GOLEM = 57
MS_FLOWEY_WALLS_FIXED = 58
MS_GOT_KEY = 59
MS_INN1_CHEST = 60
MS_RIOS_TALKED_TO_LIBRARIAN = 61
MS_RIOS_LEFT = 62
MS_GUARDS_CHEST = 63
MS_TAVERN_JUICE = 64
MS_GOT_MEDALLION = 65
MS_BEACH_INTRO = 66
MS_BEACH_BATTLE_DONE = 67
MS_FARMERS_POT1 = 68
MS_FARMERS_POT2 = 69
MS_COW1 = 70
MS_COW2 = 71
MS_COW3 = 72
MS_COW4 = 73
MS_GOT_MILK = 74
MS_GUNNAR_LEFT = 75
MS_SUB_SCENE_DONE = 76
MS_DOCK_TO_FORT = 77
MS_FORT_TO_DOCK = 78
MS_CHEST_FLINT1 = 79
MS_CHEST_FLINT2 = 80
MS_CHEST_FLINT3 = 81
MS_CHEST_FLINT4 = 82
MS_LIT_ALTER1 = 83
MS_LIT_ALTER2 = 84
MS_LIT_ALTER3 = 85
MS_LIT_ALTER4 = 86
MS_DRAINED_POOL = 87
MS_GOT_KEY2 = 88
MS_GOT_LOOKING_SCOPE = 89
MS_DROPPED_MEDALLION = 90
MS_FORT_TRAPPED_CHEST1 = 91
MS_FORT_TRAPPED_CHEST2 = 92
MS_FORT_TRAPPED_CHEST3 = 93
MS_CASTLE_TOWER3_CHEST1 = 94
MS_UNUSED__ = 95
MS_BEAT_TIGGY = 96
MS_GONE_TO_ARCHERY_TOWER = 97
MS_BEAT_ARCHERY = 98
MS_BEAT_KEEP_DOOR_GUARDS = 99
MS_KEEP_1_CHEST_0 = 100
MS_KEEP_1_CHEST_1 = 101
MS_FREED_PRISONER = 102
MS_KEEP_1_CHEST_2 = 103
MS_KEEP_1_CHEST_3 = 104
MS_HELPED_GOBLIN = 105
MS_KEEP_1_FIGHT = 106
MS_KEEP_2_CHEST_0 = 107
MS_KEEP_2_CHEST_1 = 108
MS_GONE_TO_TROLL_TOWER = 109
MS_BEAT_TROLL = 110
MS_KEEP_3_CHEST_0 = 111
MS_KEEP_3_CHEST_1 = 112
MS_KEEP_3_CHEST_2 = 113
MS_KEEP_3_CHEST_3 = 114
MS_KILLED_NANNER = 115
MS_NANNER_CHEST = 116
MS_KEEP_TOWER1_CHEST = 117
MS_KEEP_TOWER2_CHEST = 118
MS_KEEP_TOWER3_CHEST = 119
MS_KEEP_TOWER4_CHEST = 120
MS_KEEP_4_GOBLINS = 121
MS_BEAT_RIDER = 122
MS_GOT_STAFF = 123
MS_TALKED_TO_HELPED_GOBLIN = 124
MS_TIGGY_SEASIDE_SCENE = 125
MS_SPOKE_TO_KING_ABOUT_STAFF = 126
MS_JUNGLE_CHEST_1 = 127
MS_JUNGLE_CHEST_2 = 128
MS_JUNGLE_CHEST_3 = 129
MS_JUNGLE_CHEST_4 = 130
MS_JUNGLE_CHEST_5 = 131
MS_JUNGLE_CHEST_6 = 132
MS_JUNGLE_CHEST_7 = 133
MS_JUNGLE_CHEST_8 = 134
MS_BEAT_TREE = 135
MS_TREE_CHEST = 136
MS_PASSED_JUNGLE = 137
MS_JUNGLE_VILLAGE_CHEST = 138
MS_UNLOCKED_VOLCANO = 139
MS_VOLCANO_BRIDGE_LOWERED = 140
MS_VOLCANO_CHEST_0 = 141
MS_VOLCANO_CHEST_1 = 142
MS_VOLCANO_CHEST_2 = 143
MS_VOLCANO_CHEST_3 = 144
MS_VOLCANO_CHEST_4 = 145
MS_VOLCANO_CHEST_5 = 146
MS_VOLCANO_CHEST_6 = 147
MS_VOLCANO_CHEST_7 = 148
MS_BEAT_GIRL_DRAGON = 149
MS_FARMER_GONE_TO_GATE = 150
MS_FARMER_AT_LAUNCHPAD = 151
MS_ROCKET_LAUNCHED = 152
MS_ON_MOON = 153
MS_TIPPER_JOINED = 154
MS_SHYZU_CHEST_1 = 155
MS_SHYZU_CHEST_2 = 156
MS_MOON_VALLEY_CHEST_1 = 157
MS_MOON_VALLEY_CHEST_2 = 158
MS_MOON_VALLEY_CHEST_3 = 159
MS_MOON_VALLEY_CHEST_4 = 160
MS_PAST_MOON_VALLEY = 161
MS_MUTTRACE_LOWERED = 162
MS_MUTTRACE_CHEST_1 = 163
MS_MUTTRACE_CHEST_2 = 164
MS_MUTTRACE_CHEST_3 = 165
MS_MUTTRACE_CHEST_4 = 166
MS_GOT_ORB = 167
MS_MRBIG_CHEST = 168
MS_MUTTRACE_SCENE = 169
MS_LANDER_LAUNCHED = 170
MS_BEAT_TODE = 171
MS_DARKSIDE_CHEST_1 = 172
MS_DARKSIDE_CHEST_2 = 173
MS_DARKSIDE_CHEST_3 = 174
MS_DARKSIDE_CHEST_4 = 175
MS_SUN_SCENE = 176
MS_DONE_CREDITS = 177
MS_FIRST_POISON = 178
MS_SLEPT_IN_INN = 179
MS_FOREST_GOLD = 180
MS_VOLCANO_SAVE_CHEST = 181
MS_LOOKED_FROM_KEEP = 182
MS_ENY_CELL_OPENED = 183
MS_MATE_GAVE_ADVICE = 184
MS_FORT_UNDER_CHEST_1 = 185
MS_FORT_UNDER_CHEST_2 = 186
MS_FORT_UNDER_CHEST_3 = 187
MS_FORT_UNDER_CHEST_4 = 188
MS_MUTTRACE_ELIXIR = 189
MS_JUNGLE_JUICE_CHEST = 190
MS_SWIPE_TO_ATTACK = 191
MS_DRAG_TO_USE = 192
MS_GUARDS_LEFT_BEACH = 193
MS_CELL2_OPENED = 194


DIRECTION_NORTH = 1
DIRECTION_EAST = 2
DIRECTION_SOUTH = 3
DIRECTION_WEST = 4


ITEM_GOLD = -1
ITEM_BONE_BLADE = 0
ITEM_BONE_HELMET = 1
ITEM_CURE = 2
ITEM_LETTER = 3
ITEM_BONE_MAIL = 4
ITEM_WOOD_STAFF = 5
ITEM_HOLY_WATER = 6
ITEM_HEAL = 7
ITEM_IRON_BLADE = 8
ITEM_ELIXIR = 9
ITEM_BADGE = 10
ITEM_IRON_STAFF = 11
ITEM_CLOTH_ROBE = 12
ITEM_SANDALS = 13
ITEM_FRUIT = 14
ITEM_JUICE = 15
ITEM_PISTOL = 16
ITEM_ROUNDS = 17
ITEM_LEATHER_VEST = 18
ITEM_LEATHER_CAP = 19
ITEM_RING = 20
ITEM_CURE2 = 21
ITEM_KEY = 22
ITEM_GUARD_SWORD = 23
ITEM_BAMBOO_STAFF = 24
ITEM_MYSTIC_ROBE = 25
ITEM_MAIL = 26
ITEM_MEDALLION = 27
ITEM_STEEL_HELMET = 28
ITEM_SOLDIER_SWORD = 29
ITEM_SOLDIER_HELMET = 30
ITEM_SOLDIER_BOOTS = 31
ITEM_MAGE_STAFF = 32
ITEM_MAGE_ROBE = 33
ITEM_TOPHAT = 34
ITEM_FLINT = 35
ITEM_KEY2 = 36
ITEM_LOOKING_SCOPE = 37
ITEM_MYSTIC_BLADE = 38
ITEM_MYSTIC_HELMET = 39
ITEM_MYSTIC_BOOTS = 40
ITEM_KEEP_KEY_OUT = 41
ITEM_KEEP_KEY_UP = 42
ITEM_CURE3 = 43
ITEM_EMERALD_STAFF = 44
ITEM_EMERALD_ROBE = 45
ITEM_MYSTIC_MAIL = 46
ITEM_STAFF = 47
ITEM_JADE_BLADE = 48
ITEM_JADE_STAFF = 49
ITEM_JADE_CHEST_ARMOR = 50
ITEM_JADE_HELMET = 51
-- 52 unused
ITEM_ONYX_SWORD = 53
ITEM_ONYX_STAFF = 54
ITEM_ONYX_CAP = 55
ITEM_ONYX_ARMOR = 56
ITEM_ONYX_ROBE = 57
ITEM_ONYX_SHOES = 58
ITEM_MEATBALLS = 59
ITEM_ALIEN_STAFF = 60
ITEM_ALIEN_ROBE = 61
ITEM_ALIEN_CAP = 62
ITEM_ALIEN_SWORD = 63
ITEM_LIGHT_STAFF = 64
ITEM_LIGHT_ARMOR = 65
ITEM_LIGHT_HELMET = 66
ITEM_LIGHT_SWORD = 67
ITEM_LIGHT_BOOTS = 68
ITEM_LIGHT_ORB = 69


item_resale_values = {
	15, --bone blade
	10, --bone helmet
	5, --cure
	0, --letter
	20, --bone mail
	10, --wood staff
	25, --holy water
	10, --heal
	20, --iron blade
	20, --elixir
	0, --badge 10
	20,--iron staff
	15,--cloth robe
	15,--sandals
	1,--fruit
	1,--juice
	50,--pistol
	1,--rounds
	30,--leather vest
	20,--leather cap
	0,--ring 20
	20,--cure2
	0,--KEY
	100,--Guard sword
	25,--Bamboo staff
	25,--Mystic robe
	40,--Mail
	0,--Medallion
	100,--Steel helmet
	150,--soldier sword
	100,--soldier helmet 30
	100,--soldier boots
	100,--mage staff
	50,--mage robe
	25,--top hat
	0,--flint
	0,--key2
	0,--looking scope
	200,--mystic blade
	100,--mystic helmet
	80,--mystic boots 40
	0,--keep key out
	0,--keep key up
	50,--cure3
	250,--emerald staff
	250,--emerald robe
	250,--mystic mail
	0,--staff
	250,--jade blade
	250,--jade staff
	250,--jade chest armor 50
	250,--jade helmet
	0,--crystal
	300,--onyx sword
	300,--onyx staff
	200,--onyx cap
	300,--onyx armor
	200,--onyx robe
	200,--onyx shoes
	1,--meatballs 59
	400,--alien staff 60
	300,--alien robe
	300,--alien cap
	400,--alien sword
	0,-- light staff
	0,--light armor
	0,--light helmet
	0,--light sword
	0,--light boots
	0,--light orb
}

function get_item_resale_value(index)
	return item_resale_values[index+1]
end

item_descs = {
	"Blade made from whale bone", -- 0
	"Helmet made from whale bone", -- 1
	"Cures 50 HP", -- 2
	"An old letter", -- 3
	"Mail made from whale bone", -- 4
	"A strong wooden staff", -- 5
	"Revives unconsciousness", -- 6
	"Heals status conditions", -- 7
	"A heavy iron blade", -- 8
	"Restores 100 MP", -- 9
	"A rusty badge from Seaside", -- 10
	"A heavy iron staff",
	"A cloth robe",
	"Leather sandals",
	"Exotic fruit",
	"A very potent fruit cocktail",
	"A pistol",
	"Gun rounds",
	"A thick leather vest",
	"A thick leather cap",
	"A shiny silver man's ring", -- 20
	"Cures 250 HP",
	"An important looking key",
	"A well crafted blade",
	"A sturdy bamboo rod",
	"Robe with magic protection",
	"Chain mail",
	"A glowing old medallion",
	"A strong steel helmet",
	"Hardened blade",
	"Hardened helmet", -- 30
	"Protective boots",
	"Old staff",
	"Old robe",
	"Classy top hat",
	"Good way to start a fire",
	"A large golden key",
	"A scope with a perfect lens",
	"An important blade...",
	"Protects from magic attacks",
	"Protects from magic attacks", -- 40
	"Key for an unknown door",
	"Key for an unknown door",
	"Cures 2000 HP",
	"Emerald staff",
	"Emerald robe",
	"Lightweight but strong armor",
	"An immensely powerful staff",
	"A fortified jade blade",
	"A fortified jade staff",
	"A breastplate made of jade",
	"A jade helmet",
	"A glowing crystal", -- 52
	"A dark blade",
	"A dark staff",
	"A dark cap",
	"Dark armor",
	"A dark robe",
	"Dark shoes",
	"Spicy meatballs",
	"A strange staff",-- 60
	"A strange robe",
	"A strange cap",
	"A strange sword",
	"A bright staff",
	"Bright armor",
	"A bright cap",
	"A bright sword",
	"Bright boots",
	"A glowing orb",
}


function get_item_description(index)
	return item_descs[index+1]
end


CONDITION_NORMAL = -1
CONDITION_POISONED = 0
CONDITION_PARALYZED = 1
CONDITION_STONED = 2
CONDITION_SLOW = 3
CONDITION_QUICK = 4
CONDITION_CHARMED = 5
CONDITION_MUSHROOM = 6
CONDITION_SHADOW = 7
CONDITION_WEBBED = 8
CONDITION_SWALLOWED = 9


Object = {}


function randint(max)
	return getRandomNumber(max)
end


-- Battle messages
MESSAGE_LEFT = 0
MESSAGE_TOP = 1
MESSAGE_RIGHT = 2

-- Battle formations
FORMATION_FRONT = 0
FORMATION_BACK = 1
	
DPAD_NONE = 0
DPAD_HYBRID_1 = 1
DPAD_HYBRID_2 = 2
DPAD_TOTAL_1 = 3
DPAD_TOTAL_2 = 4

