// rpg specific cfg stuff goes here -- see rpg.html for more clarity

// for the rpg, almost all gameplay is defined _per map_ as opposed to globally for the game
// but for now a lot of stuff goes here for testing

playasong = []

// these are the log curve settings for computing efficiency based on points. do not modify if you don't know what these do.

r_def_logscale_x = 10
r_def_logscale_y = 25

r_def_melee       $r_def_logscale_x $r_def_logscale_y
r_def_ranged      $r_def_logscale_x $r_def_logscale_y
r_def_magic       $r_def_logscale_x $r_def_logscale_y

r_def_hpregen     $r_def_logscale_x $r_def_logscale_y
r_def_manaregen   $r_def_logscale_x $r_def_logscale_y

r_def_maxhp       $r_def_logscale_x $r_def_logscale_y
r_def_maxmana     $r_def_logscale_x $r_def_logscale_y

r_def_attackspeed $r_def_logscale_x $r_def_logscale_y
r_def_movespeed   $r_def_logscale_x $r_def_logscale_y
r_def_jumpheight  $r_def_logscale_x $r_def_logscale_y
r_def_tradeskill  $r_def_logscale_x $r_def_logscale_y
r_def_feared      $r_def_logscale_x $r_def_logscale_y
r_def_stealth     $r_def_logscale_x $r_def_logscale_y
r_def_hostility   $r_def_logscale_x $r_def_logscale_y

r_def_stata       $r_def_logscale_x $r_def_logscale_y
r_def_statb       $r_def_logscale_x $r_def_logscale_y
r_def_statc       $r_def_logscale_x $r_def_logscale_y

//showcharacterboundingbox 1


// some useful functions...

newrpgspawn = [ newent spawn; spawnname $arg1; ]

r_inventory = [ r_spawn $arg1; r_contain 1; r_pop ]
r_loot      = [ r_spawn $arg1; r_contain 2; r_pop ]
r_fortrade  = [ r_spawn $arg1; r_contain 4; r_pop ]

r_sound = [ r_usesound (registersound $arg1) ]


// all the objects in the game:

// that's us
spawn_player = [
    r_inventory apple
    r_inventory power_gem
    r_inventory fist        // starting weapon
    r_inventory sword
    r_inventory fireball
    r_inventory iceball
    r_inventory healing
    r_inventory crossbow
    r_gold 10               // give us some starting money, woo
    r_ai 1                  // just so it is in the same group as the npcs for attacks etc
]

r_meleeweapon = [
    r_usetype 1
    r_damage $arg1
    r_attackrate $arg2
    r_maxrange $arg3
    r_maxangle $arg4
    r_action_use [ r_dodamage (r_eff_melee) ]
]

r_rangedweapon = [
    r_usetype 2
    r_damage $arg1
    r_attackrate $arg2
    r_maxrange $arg3
    r_useamount 10		// comes with arrows included
    r_action_use [ r_dodamage (r_eff_ranged) ]
    r_sound "free/tick"
]

r_spell = [
	r_usetype 3
	r_damage $arg1
    r_attackrate $arg2
    r_manacost $arg3
    r_maxrange $arg4
    r_effectparticle (at $arg5 0)
    r_effectcolor (at $arg5 1)
    r_effectsize (at $arg5 2)
    r_sound $arg6
    r_action_use $arg7
]

// weapons
spawn_fist   = [ r_meleeweapon 10  500 20 30; r_sound "free/punch1"; r_use ]           // this will be equipped when we start
spawn_sword  = [ r_meleeweapon 15  750 30 30; r_sound "free/tick" ]
spawn_hammer = [ r_meleeweapon  5  250 20 20; r_sound "free/tick"; r_model "tentus/hammer" ]
spawn_bomb   = [ r_meleeweapon 30 1000 90 90; r_sound "free/tick"; r_model "tentus/bombs" ]
spawn_spear  = [ r_meleeweapon 10 1000 60 60; r_sound "free/tick"; r_model "tentus/spear" ]

spawn_crossbow    = [ r_rangedweapon 5 1000 256 ]

r_dodamage = [
	damage = (r_get_damage)
	r_pop
	r_applydamage (div (* $damage $arg1) 100)
]

r_givehealth = [
	r_pop
	r_hp (+ (r_get_hp) $arg1)	// temp, needs to be capped
]

r_givemana = [
	r_pop
	r_mana (+ (r_get_mana) $arg1)	
]

// spells, can be used as weapons

spawn_fireball = [ r_spell  7  500 10 256 [0 0xFFC8C8 480] "awesund/flaunch" [ r_dodamage (r_eff_magic) ] ]
spawn_iceball  = [ r_spell 10  400 20 256 [1 0xFFFFFF 480] "awesund/flaunch" [ r_dodamage (r_eff_magic) ] ]
spawn_healing  = [ r_spell  0 1000 25   0 [] "free/itempick"   [ r_givehealth 20 ] ]

// single-use spells, activated in inventory, or in the gameworld:

spawn_healthpotion = [ r_useamount 1; r_action_use [ r_givehealth 20 ]; r_sound "free/itempick"; r_model "tentus/food-drink/winebottle" ] 
spawn_manapotion   = [ r_useamount 1; r_action_use [ r_givemana   20 ]; r_sound "free/itempick"; r_model "tentus/food-drink/winebottle" ] 


// defensive
spawn_green_shield = [ r_worth  500; r_hpregen 20; r_model "tentus/greenshield" ]
spawn_red_shield   = [ r_worth 1000; r_hpregen 50; r_model "tentus/redshield" ]

// food/drink
spawn_apple        = [ r_worth   10; r_model "tentus/food-drink/apple" ]
spawn_apple_slice  = [ r_worth    1; r_model "tentus/food-drink/appleslice" ]
spawn_carrot       = [ r_worth    1; r_model "carrot" ]
spawn_pear         = [ r_worth   15; r_model "tentus/food-drink/pear" ]
spawn_pie          = [ r_worth   20; r_model "tentus/food-drink/pie" ]
spawn_pie_slice    = [ r_worth    5; r_model "tentus/food-drink/pieslice" ]
spawn_mushroom     = [ r_worth    5; r_model "dcp/mushroom" ]
spawn_wolfmeat     = [ r_worth    4; r_model "tentus/food-drink/meat" ]
spawn_wine         = [ r_worth   30; r_model "tentus/food-drink/winebottle" ]

// valuables
spawn_power_gem    = [ r_worth  100; r_melee 100; r_model "checkpoint" ]
spawn_coin         = [ r_worth   10; r_model "rpg/objects/coin" ]
spawn_key          = [ r_worth   10; r_model "tentus/key" ]
spawn_loot         = [ r_worth  100; r_model "tentus/moneybag" ]

// misc
spawn_anvil        = [ r_worth   20; r_model "tentus/anvil" ]
spawn_books        = [ r_worth    5; r_model "tentus/books" ]
spawn_bowl         = [ r_worth    5; r_model "tentus/food-drink/bowl" ]
spawn_goblet       = [ r_worth   10; r_model "tentus/food-drink/goblet" ]
spawn_mug          = [ r_worth    5; r_model "tentus/food-drink/mug" ]
spawn_candle       = [ r_worth    2; r_model "dcp/candle" ]
spawn_cask         = [ r_worth   30; r_model "dcp/cask" ]
spawn_rope         = [ r_worth   10; r_model "dcp/rope" ]
spawn_sack         = [ r_worth   10; r_model "dcp/sack" ]
spawn_wolfskin     = [ r_worth   15 ]
spawn_vase         = [ r_worth   20; r_model "dcp/vase" ]

// stats
spawn_fountainofmana = [ r_manaregen 10000 ]

// npcs
spawn_mman = [
    r_friendly_creature "rpg/characters/mman"
    
    r_gold 1000               // rich bastard
    
    r_inventory red_shield    // he's going to be hard to kill
    
    r_inventory iceball       // better not aggrevate him
    r_inventory fountainofmana

    r_fortrade apple          // ooh the guy carries an apple. Maybe we can trade?
    r_fortrade apple
    
    r_action "hi" [ r_say "hey, how are you!" ]
    r_action "I'm hungry" [
		r_say "kill a wolf for me, and I will give you an apple"
		r_quest "I killed a wolf" [
			r_take wolfskin [
				r_say "thanks for the wolf's skin, here's your apple"
				r_give apple
			] [
				r_say "go kill a wolf first!"
			]
		]
	]
]

r_friendly_creature = [
    r_model $arg1
    r_ai 1
]

r_hostile_creature = [
    r_model $arg1
    r_ai 2
    r_meleeweapon $arg2 1000 $arg3 30   // this creature is itself a melee weapon
]

spawn_npcman  = [ r_friendly_creature "rpg/characters/npcman"; r_inventory sword ]
spawn_horse   = [ r_friendly_creature "rpg/characters/horse"  ]

spawn_dragon  = [ r_hostile_creature "rpg/characters/dragon"  80 100 ]
spawn_wolf    = [ r_hostile_creature "rpg/characters/wolf"    10 30; r_loot wolfskin; r_loot wolfmeat ]
spawn_rat     = [ r_hostile_creature "rpg/characters/rat"      2 25 ]
spawn_grizzly = [ r_hostile_creature "rpg/characters/grizzly" 20 40 ]

// temp: override main menu for rpg

bind I   "showplayergui 1; cleargui 1"
bind TAB "showplayergui 2; cleargui 1"
bind L   "showplayergui 3; cleargui 1"
bind ESCAPE [if (cleargui 1) [] [showgui main; showplayergui 0]]   

newgui main [
    guibutton "inventory (I)"       "showplayergui 1"        "chest"
    guibutton "player stats (TAB)"  "showplayergui 2"        "info"
    guibutton "quest log (L)"       "showplayergui 3"        "info"
    guibar
    guibutton "map k_rpg1"
    guibutton "map rpg_01"
    guibar
    guibutton "load fps map.."   "showgui maps"
    guibutton "editing.."        "showgui editing"
    guibutton "options.."        "showgui options"
    guibutton "about.."          "showgui about"
    guibar
    guibutton "quit"             "quit"                 "exit"
]

