///////////////////////////////////////////////////////////////////////////////////////////////////
// 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.
///////////////////////////////////////////////////////////////////////////////////////////////////

include "gamelib.plh"
include "playtype.plh"
include "gen_images.plh"

predef new_Modifier, new_Armor_Chaps, new_Armor_ShamanHeaddress, new_Armor_TahnkuPants, new_Armor_TahnkuVest 
predef new_Weapon_Handgun, new_Weapon_SpiritBow, new_Weapon_SpiritBlade, calcPlayerArmor
predef new_Player_Hue_Hauser, new_Player_Mokahnu

word[] funcTbl = @new_Modifier, @new_Armor_Chaps, @new_Armor_ShamanHeaddress, @new_Armor_TahnkuPants, @new_Armor_TahnkuVest
word           = @new_Weapon_Handgun, @new_Weapon_SpiritBow, @new_Weapon_SpiritBlade, @calcPlayerArmor
word           = @new_Player_Hue_Hauser, @new_Player_Mokahnu

///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Modifier(kind, value)
  word p
  p = mmgr(HEAP_ALLOC, TYPE_MODIFIER)
  p->b_modKind = kind
  p->b_modValue = value
  return p
end

///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Armor_Chaps
  word p
  p = mmgr(HEAP_ALLOC, TYPE_ARMOR)
  p=>s_name = mmgr(HEAP_INTERN, "Chaps")
  p->b_itemKind = KIND_PANTS
  p=>w_cost = -99 // for now
  // no modifiers, max uses, etc. for now
  p->b_armorValue = 2
  return p
end

///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Armor_ShamanHeaddress()
  word p
  p = mmgr(HEAP_ALLOC, TYPE_ARMOR)
  p=>s_name = mmgr(HEAP_INTERN, "Shaman Headdress(es)")
  p->b_itemKind = KIND_HAT
  p=>w_cost = -99 // for now
  // no modifiers, max uses, etc. for now
  p->b_armorValue = 2
  return p
end

///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Armor_TahnkuPants()
  word p
  p = mmgr(HEAP_ALLOC, TYPE_ARMOR)
  p=>s_name = mmgr(HEAP_INTERN, "Tahnku Pants")
  p->b_itemKind = KIND_PANTS
  p=>w_cost = -99 // for now
  // no modifiers, max uses, etc. for now
  p->b_armorValue = 2
  return p
end

///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Armor_TahnkuVest()
  word p
  p = mmgr(HEAP_ALLOC, TYPE_ARMOR)
  p=>s_name = mmgr(HEAP_INTERN, "Tahnku Vest(s)")
  p->b_itemKind = KIND_SHIRT
  p=>w_cost = -99 // for now
  // no modifiers, max uses, etc. for now
  p->b_armorValue = 2
  return p
end

///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Weapon_Handgun
  word p
  p = mmgr(HEAP_ALLOC, TYPE_WEAPON)
  p=>s_name = mmgr(HEAP_INTERN, "Handgun")
  p->b_itemKind = KIND_HANDGUN
  p=>w_cost = -99 // for now
  // no modifiers, max uses, etc. for now
  p->b_ammoKind = KIND_BULLET
  p->b_clipSize = 6
  p->b_clipCurrent = p->b_clipSize
  p=>r_meleeDmg = encodeDice(1, 6, 0)  // 1d6
  p=>r_projectileDmg = encodeDice(1, 6, 0)  // 1d6
  p->ba_attacks[0] = 1  // single attack
  p->b_weaponRange = 40
  p=>s_combatText = mmgr(HEAP_INTERN, "shoots")
  return p
end

///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Weapon_SpiritBow
  word p
  p = mmgr(HEAP_ALLOC, TYPE_WEAPON)
  p=>s_name = mmgr(HEAP_INTERN, "Spirit Bow")
  p->b_itemKind = KIND_BOW
  p=>w_cost = -99 // for now
  // no modifiers, max uses, etc. for now
  p->b_ammoKind = KIND_ARROW
  p->b_clipSize = 12
  p->b_clipCurrent = p->b_clipSize
  p=>r_meleeDmg = encodeDice(3, 6, 0)  // 3d6
  p=>r_projectileDmg = encodeDice(2, 6, 5)  // 2d6+5
  p->ba_attacks[0] = 1  // single attack
  p->ba_attacks[1] = 3  // triple attack
  p->b_weaponRange = 100
  p=>s_combatText = mmgr(HEAP_INTERN, "shoots")
  return p
end

///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Weapon_SpiritBlade
  word p
  p = mmgr(HEAP_ALLOC, TYPE_WEAPON)
  p=>s_name = mmgr(HEAP_INTERN, "Spirit Blade")
  p->b_itemKind = KIND_BOW
  p=>w_cost = -99 // for now
  // no modifiers, max uses, etc. for now
  p->b_ammoKind = 0
  p->b_clipSize = 0
  p->b_clipCurrent = p->b_clipSize
  p=>r_meleeDmg = encodeDice(7, 6, 0)  // 7d6
  p=>r_projectileDmg = 0
  p->ba_attacks[0] = 1  // single attack
  p->b_weaponRange = 10
  p=>s_combatText = mmgr(HEAP_INTERN, "slices")
  return p
end

///////////////////////////////////////////////////////////////////////////////////////////////////
def calcPlayerArmor(player)
  word pItem
  player->b_armor = 0
  pItem = player=>p_items
  while pItem
    if pItem->t_type == TYPE_ARMOR
      player->b_armor = player->b_armor + pItem->b_armorValue
    fin
    pItem = pItem=>p_nextObj
  loop
end

///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Player_Hue_Hauser
  word p, pItem
  p = mmgr(HEAP_ALLOC, TYPE_PLAYER)
  p=>s_name = mmgr(HEAP_INTERN, "Hue Hauser")
  p->b_intelligence = 5
  p->b_strength = 6
  p->b_agility = 3
  p->b_bravery = 6
  p->b_stamina = 4
  p->b_charisma = 7
  p->b_spirit = 5

  p=>w_maxHealth = 12
  p=>w_health = 12

  // Basic skills
  p->b_aiming = 2
  p->b_dodging = 3
  p->b_wilderness = 5

  // Skills
  addToList(p + p_skills, new_Modifier(KIND_MINING, 0))
  addToList(p + p_skills, new_Modifier(KIND_NATIVE_BOND, 0))
  addToList(p + p_skills, new_Modifier(KIND_PYRE_WARE, 0))
  addToList(p + p_skills, new_Modifier(KIND_HANDGUN, 1))

  // Items
  addToList(p + p_items, new_Armor_Chaps())
  addToList(p + p_items, new_Weapon_Handgun())

  // Calculated attributes
  calcPlayerArmor(p)

  // (No buffs or debuffs to start with.)

  // All done with the player.
  return p
end

///////////////////////////////////////////////////////////////////////////////////////////////////
def new_Player_Mokahnu
  word p, pItem
  p = mmgr(HEAP_ALLOC, TYPE_PLAYER)
  p=>s_name = mmgr(HEAP_INTERN, "Mokahnu")
  p->b_intelligence = 7
  p->b_strength = 4
  p->b_agility = 6
  p->b_bravery = 7
  p->b_stamina = 6
  p->b_charisma = 7
  p->b_spirit = 10

  p=>w_maxHealth = 40
  p=>w_health = 40

  p->b_playerFlags = PLAYER_FLAG_NPC

  // Basic skills
  p->b_aiming = 4
  p->b_dodging = 3
  p->b_wilderness = 5

  // Skills
  addToList(p + p_skills, new_Modifier(KIND_MINING, 0))
  addToList(p + p_skills, new_Modifier(KIND_NATIVE_BOND, 10))
  addToList(p + p_skills, new_Modifier(KIND_PYRE_WARE, 0))
  addToList(p + p_skills, new_Modifier(KIND_BLADE, 3))
  addToList(p + p_skills, new_Modifier(KIND_BOW, 3))
  addToList(p + p_skills, new_Modifier(KIND_RIFLE, 3))
  addToList(p + p_skills, new_Modifier(KIND_BLADE, 3))

  // Items
  addToList(p + p_items, new_Armor_ShamanHeaddress())
  addToList(p + p_items, new_Armor_TahnkuPants())
  addToList(p + p_items, new_Armor_TahnkuVest())
  addToList(p + p_items, new_Weapon_SpiritBow())
  addToList(p + p_items, new_Weapon_SpiritBlade())

  // Calculated attributes
  calcPlayerArmor(p)

  // (No buffs or debuffs to start with.)

  // All done with the player.
  return p
end

return @funcTbl
done