///////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2015 The 8-Bit Bunch. Licensed under the Apache License, Version 1.1
// (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at <http://www.apache.org/licenses/LICENSE-1.1>.
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.
///////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////
// Structures for the heap

const TYPE_GLOBAL = $80
struc TGlobal
  byte t_type
  word p_players
  word p_benched
  word p_enemyGroups
  word p_combatFirst
  word p_encounterZones
  word w_combatPauseCt

  // Map position
  byte b_mapIs3D
  byte b_mapNum
  word w_mapX
  word w_mapY
  byte b_mapDir
  word s_mapName

  // Shared player gold amount
  word w_gold

  // Heap size for restoring saved game, and hash of type table to check compatibility of old saves.
  word w_heapSize
  word w_typeHash

  byte[32] ba_gameFlags // General flags maintained by scripts (array of 256 bits = 32 bytes)
  byte b_curAvatar

  // god mode flag
  byte b_godmode

  // current time of day
  byte b_hour
  byte b_minute
  byte b_second

  // move mode (1=normal, 2=fast, 4=classic)
  byte b_moveMode

  word w_bankBal
end

const PLAYER_FLAG_NPC  = $01

const TYPE_PLAYER = $81
struc TPlayer
  byte t_type
  word p_nextObj
  word s_name
  byte b_combatOrder
  word p_combatNext
  word w_health

  // Innate attributes
  byte c_gender
  byte b_intelligence
  byte b_strength
  byte b_agility
  byte b_stamina
  byte b_charisma
  byte b_spirit
  byte b_luck

  // Calculated attributes
  byte b_armor

  // Basic skills (much like attributes)
  byte b_aiming
  byte b_handToHand
  byte b_dodging

  // Status
  word w_maxHealth
  byte b_combatChoice
  byte b_shotChoice
  byte b_gangChoice
  byte b_playerFlags
  byte b_level
  word w_curXP
  word w_nextXP
  byte b_skillPoints
  byte b_packSize

  // Lists
  word p_skills  // list:Modifier
  word p_items   // list:Item
end

// Combat skills, weapon modifiers, etc.
const TYPE_MODIFIER = $82
struc TModifier
  byte t_type
  word p_nextObj
  word s_name
  word w_modValue
end

// Plain items are for things that don't stack or have stat effects,
// but may have meaning to scenario logic (e.g. keys, tokens, etc.)
const TYPE_PLAIN_ITEM = $83
struc TPlainItem
  byte t_type
  word p_nextObj
  word s_name
  word w_price
end

const TYPE_FANCY_ITEM = $84
struc TFancyItem
  // Plain item properties
  byte t_type
  word p_nextObj
  word s_name
  word w_price
  // Fancy properties
  word s_itemKind   // for ammo
  word p_modifiers  // list:modifier, e.g. boost health, etc.
  word w_count      // zero for singular items, 1+ for countables
  word w_storeAmount
  word r_lootAmount
end

const ITEM_FLAG_EQUIP         = $80 // only one weapon/armor equipped (in use) at a time

const WEAPON_FLAG_SINGLE_USE  = $01

const TYPE_WEAPON = $85
struc TWeapon
  // Plain item properties
  byte t_type
  word p_nextObj
  word s_name
  word w_price
  // Weapon properties
  word s_itemKind       // for skill matching
  word p_modifiers      // list:modifier
  byte b_flags          // WEAPON_FLAG_* above
  word s_ammoKind       // for matching to Stackable ammo
  byte b_clipSize
  byte b_clipCurrent
  word r_meleeDmg       // 3 hex digits: num dice, die size, add. E.g. $361 = 3d6+1
  word r_projectileDmg  // ditto
  byte ba_attacks[3]    // each is: 0=none, 1=single, 2=double, 3+ = multi-shot
  byte b_weaponRange
  word s_combatText
end

const TYPE_ARMOR = $86
struc TArmor
  // Plain item properties
  byte t_type
  word p_nextObj
  word s_name
  word w_price
  // Armor properties
  word s_itemKind
  word p_modifiers  // list:modifier
  byte b_flags // ARMOR_FLAG_* above
  byte b_armorValue
end

const TYPE_ENEMY = $87
struc TEnemy
  byte t_type
  word p_nextObj
  word s_name
  byte b_combatOrder
  word p_combatNext
  word w_health

  byte b_image
  byte b_hitBonus
  byte b_attackType   // 1=melee, 2=projectile
  word s_attackText
  byte b_enemyAttackRange
  byte b_chanceToHit
  word r_enemyDmg     // 3 hex digits: num dice, die size, add. E.g. $361 = 3d6+1
  word r_enemyXP      // 3 hex digits: num dice, die size, add. E.g. $361 = 3d6+1
  word r_groupSize    // number encountered, as 3 hex digits for dice
  byte b_lootChance0  // % chance for first loot item
  byte b_lootChance1  // % chance for second loot item
  byte b_lootCode0    // code in loot table for first loot item
  byte b_lootCode1    // code in loot table for second loot item
  word r_goldLoot     // monetary loot when killed, as 3 hex digits for dice
end

const TYPE_ENEMY_GROUP = $88
struc TEnemyGroup
  byte t_type
  word p_nextObj
  word p_enemies
  byte b_enemyNum
end

const TYPE_ENCOUNTER_ZONE = $89
struc TEncounterZone
  byte t_type
  word p_nextObj
  word s_name   // enemy code
  word w_encX
  word w_encY
  word w_encMaxDist
  word w_encChance
end
