view ggrtf-misc.tf @ 654:4fc281dbe97b

Truncate reagent names with prsubstr() in reagent pouch mangler.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 25 Jul 2007 20:21:44 +0000
parents daa42c69dc35
children 4fe5988b7da2
line wrap: on
line source

;;
;; GgrTF::Misc - Additional macros/triggers (some modules require this)
;; (C) Copyright 2004-2007 Matti Hämäläinen (Ggr)
;;
;; This file (triggerset) is Free Software distributed under
;; GNU General Public License version 2.
;;
;; NOTICE! This file requires GgrTF (version 0.6.0 or later) to be loaded.
;;
/loaded GgrTF:Misc
/require map.tf

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Bindings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/if (opt_bindings=~"on")\
	/prdefgbind -s"cere"	-c"/ceremony"		-n%;\
	/prdefsbind -s"fire"	-c"Fire Building"	-n%;\
/endif


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Initialization and options
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/prdeftoggle -n"rmisc" -d"Miscellaneous reporting"
/set opt_rmisc=on

/prdeftoggle -n"rcda" -d"Combat Damage Analysis reporting"
/set opt_rcda=on


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Consider reporting
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/def -i -mregexp -t"^You take a close look at (.*) in comparison to yourself\.$" gconsider_rep0 =\
	/set cons_st=1%;/set cons_pr=%;/set cons_exp=%;/set cons_name=%{P1}

/def -i -Econs_st==1 -ag -mregexp -t"^You would get (.*) experience for " gconsider_rep1 =\
	/set cons_exp=%{P1}

/def -i gdefconspr =\
	/def -i -Econs_st==1 -ag -mregexp -t"^[A-Za-z<> ,.'-]+ %{2}$$" gconsider_pr%{1} =\
		/set cons_pr=%{3}

/test gdefconspr(1, "has a soft skin.", "soft", 0)
/test gdefconspr(2, "seems to have a bit hardened skin.", "bit hardened", 0)
/test gdefconspr(3, "has somewhat hardened skin.", "somewhat hardened", 0)
/test gdefconspr(4, "skin could fold up a rapier!", "could fold up a rapier!", 0)
/test gdefconspr(5, "skin seems to be virtually impenetrable!", "impenetrable!", 0)

/def -i -ag -mregexp -t"^The final estimation is that (.*)$" gconsider_final =\
	/if (cons_st) \
		/let cons_val=%{P1}%;\
		/if (regmatch("doesn't look", cons_val)) /set cons_opp=dlvd%;\
		/elseif (regmatch("fair opponent", cons_val)) /set cons_opp=fair%;\
		/elseif (regmatch("nearly equal", cons_val)) /set cons_opp=equal%;\
		/elseif (regmatch("quite skilled", cons_val)) /set cons_opp=skilled%;\
		/elseif (regmatch("much stronger", cons_val)) /set cons_opp=much stronger%;\
		/elseif (regmatch("has such bulging", cons_val)) /set cons_opp=DANGEROUS%;\
		/else /set cons_opp=%{cons_val}%;/endif%;\
		/if (cons_exp!~"") /let qtmps=%{cons_exp} exp%;/else /let qtmps=%;/endif%;\
		/if (cons_opp!~"")\
			/if (qtmps!~"")\
				/let qtmps=%{qtmps}, %{cons_opp}%;\
			/else \
				/let qtmps=%{cons_opp}%;\
			/endif%;\
		/endif%;\
		/if (cons_pr!~"") /let qtmps=%{qtmps} (PR: %{cons_pr})%;/endif%;\
		/msr [$[substr(cons_name,0,15)]]: %{qtmps}%;\
	/endif%;\
	/set cons_st=0


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Combat damage analysis
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/def -i gcda_report =\
	/if (opt_rcda=~"on")\
		/msr [%{1}]: %{2} resist against %{3}%;\
	/else \
		/msq [@{Cgreen}%{1}@{n}]: @{BCcyan}%{2}@{n} resist against @{BCyellow}%{3}@{n}%;\
	/endif

/def -i -p9999 -ag -mregexp -t"^([A-Za-z ,.'-]+) is defenseless against ([a-zA-Z]+) damage\.$" cda_resist0 =\
	/test gcda_report({P1},0,{P2})

/def -i -p9999 -ag -mregexp -t"^([A-Za-z ,.'-]+) seems to be almost defenseless against ([a-zA-Z]+) damage\.$" cda_resist20 =\
	/test gcda_report({P1},20,{P2})

/def -i -p9999 -ag -mregexp -t"^([A-Za-z ,.'-]+) has some resistance against ([a-zA-Z]+) damage\.$" cda_resist40 =\
	/test gcda_report({P1},40,{P2})

/def -i -p9999 -ag -mregexp -t"^([A-Za-z ,.'-]+) seems to be moderately resistant against ([a-zA-Z]+) damage." cda_resist60 =\
	/test gcda_report({P1},60,{P2})

/def -i -p9999 -ag -mregexp -t"^([A-Za-z ,.'-]+) has good resistance against ([a-zA-Z]+) damage\.$" cda_resist80 =\
	/test gcda_report({P1},80,{P2})

/def -i -p9999 -ag -mregexp -t"^([A-Za-z ,.'-]+) seems almost immune against ([a-zA-Z]+) damage\.$" cda_resist100 =\
	/test gcda_report({P1},100,{P2})


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Some special hilites and miscellaneous
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/def -i msm = /if (opt_rmisc=~"on") /msr %*%;/endif

;; Highlite plants and mineral deposits
/def -i -F -p9999 -aCgreen -mregexp -t"(plant stands|plant lies|growing|grows here|is starting to grow|tree stands|bush is here|oak tree)" glite_plant1
/def -i -F -p9999 -aCyellow -mregexp -t"in the ground" glite_mineral1

;; Highlite open containers, doors etc.
/def -i -F -p9999 -P2BCred -mregexp -t" (safe|chest|crate|vault|box|closet|money-box).* (\(open\))" glite_open
/def -i -F -p9999 -P2BCgreen -mregexp -t" (safe|chest|crate|vault|box|closet|money-box).* (\(closed\))" glite_closed


;; Lite skills/spells you can train with current exp
/def -i -F -p9999 -mregexp -t"^\| ([A-Z][A-Za-z ]+) +\| +([0-9]+) \| +([0-9]+) \| +([0-9]+) \| +([0-9]+) \|$" glite_trainexp =\
	/if ({P5} <= status_qexp)\
		/let _tcs=Cgreen%;\
	/else \
		/let _tcs=n%;\
	/endif%;\
	/substitute -p | @{%{_tcs}}%{P1}@{n} | @{%{_tcs}}$[pad({P2},3)]@{n} | @{%{_tcs}}$[pad({P3},3)]@{n} | @{%{_tcs}}$[pad({P4},3)]@{n} | @{%{_tcs}}$[pad({P5},8)]@{n} |


;; Ambush
/set ambush_t=0
/def -i -p9999 -aCred -msimple -t"You cannot leave, you have been AMBUSHED." gmisc_ambush1 =\
	/if (time()-ambush_t > 5)\
		/set ambush_t=$[time()]%;\
		/msm AMBUSHED!%;\
	/endif

;; Gained percentage in skill
/def -i -p9999 -aCgreen -mregexp -t"^You feel like you just got slightly better in (.*)$" gmisc_improved =\
	/mse improved in %{P1}

;; Floating disc
/def -i -p9999 -msimple -t"Your disc wavers dangerously." gmisc_fdweak =\
	/msm Disc falling!

/def -i -p9999 -msimple -t"You reload magical energy to the disc that is floating in the air." gmisc_fdreload =\
	/msm Disc reloaded.

;; Party leadership
/def -i -F -p9999 -aCred -msimple -t"You are the new leader of the party." gmisc_pleader =\
	@@party forcefollow all%;/msm Leading!

;; Poison removed
/def -i -F -p9999 -aCred -msimple -t"You feel the poison leaving your veins!" gmisc_poisonrm =\
	/msm Poison removed!

;; Uncon
/def -i -p9999 -ag -mregexp -t"^([A-Z][A-Za-z]+) lapses into unconsciousness from severe loss of blood.$" gmisc_uncon =\
	/msq @{BCred}!!!@{n} @{BCwhite}%{P1}@{n} is @{BCgreen}UNCON@{n} @{BCred}!!!@{n}%;\
	/msm %{P1} is UNCON!


;; Warn about changes in party formation
/def -i -p9999 -ag -mregexp -t"^([A-Z][a-z]+) is now in the 1st row.$" gmisc_firstrow =\
	/msq @{BCred}!!!@{n} @{BCwhite}%{P1}@{n} @{BCyellow}is now in 1st row@{n} @{BCred}!!!@{n}%;\
	/if ({P1}=~set_plrname) /msm %{P1} is now in 1st row!%;/endif


;; Multicolored Demons (event)
/def -i -F -p9999 -aCred -msimple -t"A Nasty Multicolored Demon arrives with puff of red smoke." gmisc_mcdemon =\
	/msq @{BCwhite}*@{n} @{BCgreen}---@{n} @{BCred}MC DEMONS  EVENT!@{n} @{BCgreen}---@{n} @{BCwhite}*@{n}

;; Robin Hood
; Robin Hood took Ring of the Medusa labeled as (Ggr) <red glow> from Ggr.
/def -i -F -p9999 -aCred -mregexp -t"^Robin Hood arrives from " gmisc_robin1 =\
	/msq @{BCwhite}*@{n} @{BCgreen}---@{n} @{BCred}ROBIN HOOD EVENT!@{n} @{BCgreen}---@{n} @{BCwhite}*@{n}


;; Warn about invis tells and emotes
/def -i -p9999 -aCgreen -mregexp -t"^You tell ([^']*)" gmisc_invtell =\
	/if (opt_rmisc=~"on" & prot_invis > 0 & !regmatch("(monster)", {P1}))\
		/gwarning You are using 'tell' while INVISIBLE!%;\
	/endif

/def -i -p9999 -aCgreen -mregexp -t"^You emote to " gmisc_invemote =\
	/if (opt_rmisc=~"on" & prot_invis > 0)\
		/gwarning You are using 'emote' while INVISIBLE!%;\
	/endif

;; Etc
/prdeffail -k -f    -t"You fail to start the fire."

/def -i -ag -mregexp -t"^Your ([A-Za-z ]+) gets damaged; it's now in ([a-z]+) condition.$" gmisc_eqdamage =\
	/msq @{BCred}!!!@{n} @{BCwhite}%{P1}@{n} @{BCyellow}got damaged!@{n} (@{BCgreen}%{P2}@{n}) @{BCred}!!!@{n}%;\
	/msm NOTICE! %{P1} got damaged! (%{P2})

;; Resist curses and drains
/def -i -p1 -aCred -mregexp -t"^You (are not affected by|successfully resist a|successfully resist the) ([a-z ]+)\.$" gmisc_curseres =\
	/msm Resisted %{P2}!

;; Resist poison
/def -i -p1 -aCred -msimple -t"You SAVE against POISON." gmisc_poisonres =\
	/msm Saved against poison!

;; Psi scanning warnings
/def -i -ag -msimple -t"You get the feeling that someone is looking over your shoulder." gmisc_mglance =\
	/gwarning @{BCwhite}Mental Glance@{n} detected!

;; All-seeing eye
/def -i -ag -msimple -t"You have a feeling that somebody is watching you." gmisc_alleye =\
	/gwarning @{BCwhite}All-seeing eye@{n} detected!


;; Banishment
/def -i -aBCred -mregexp -t"^You feel that (.+) doesn\'t enjoy your presence\.$" gmisc_banish0 =\
	/set mbanish_st=1

/def -i -ag -msimple -E(mbanish_st==1) -t"Suddenly your eyes close and when you open them you see:" gmisc_banish1 =\
	/msr Got banished!%;/set mbanish_st=0


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helper for money purse
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/def -i gpurse_add =\
	/if (regmatch(strcat("([0-9]+) ",{1}),gpursec_match))\
		/set gpursec_total=$[gpursec_total + ({P1} * {2})]%;\
		/let mptmp=@{BCwhite}$[prprettyvalstr({P1})]@{n} @{%{3}}%{1}@{n}%;\
		/if (gpursec_str!~"")\
			/set gpursec_str=%{gpursec_str}, %{mptmp}%;\
		/else \
			/set gpursec_str=%{mptmp}%;\
		/endif%;\
	/endif

/def -i gpurse_report =\
	/set gpursec_str=%;/set gpursec_total=0%;\
	/test gpurse_add("mithril",	500,	"BCgreen")%;\
	/test gpurse_add("batium",	100,	"Cgreen")%;\
	/test gpurse_add("anipium",	50,	"BCyellow")%;\
	/test gpurse_add("platinum",	10,	"Cyellow")%;\
	/test gpurse_add("gold",	1,	"Cwhite")%;\
	/test gpurse_add("silver",	0.6,	"BCcyan")%;\
	/test gpurse_add("bronze",	0.4,	"Ccyan")%;\
	/test gpurse_add("copper",	0.2,	"BCmagenta")%;\
	/test gpurse_add("tin",		0.1,	"Cmagenta")%;\
	/test gpurse_add("zinc",	0.05,	"Cred")%;\
	/test gpurse_add("mowgles",	0.01,	"BCred")%;\
	/msw It contains %{gpursec_str} (Total: @{BCwhite}$[prprettyvalstr(gpursec_total)]@{n} in @{BCyellow}gold@{n})

/def -i -ag -mregexp -t"^It contains ([a-z0-9 ,]+) coins\.$" gpurse_rep1 =\
	/set gpursec_match=%{P1}%;/gpurse_report

/def -i -ag -mregexp -t"^It contains ([a-z0-9 ,]+)$" gpurse_rep2 =\
	/set gpursec_st=1%;/set gpursec_match=%{P1}

/def -i -ag -E(gpursec_st==1) -mregexp -t"^([a-z0-9 ,]*)coins\.$" gpurse_rep3 =\
	/set gpursec_st=0%;/set gpursec_match=%{gpursec_match} %{P1}%;/gpurse_report


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helper for reagent pouch
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/def -i grpouch_report =\
	/substitute -p @{BCyellow}$[pad({1},5)]@{n} | @{BCgreen}$[pad({6},-25)]@{n} (@{BCred}$[pad({2},4)]@{n},@{Cgreen}$[pad({3},4)]@{n},@{Cyellow}$[pad({4},4)]@{n}) @{BCgray}($[prsubstr({5},25)])@{n}

/def -i gdefrpouch =\
	/let _tmps=$[replace(" ","_", tolower({2}))]%;\
	/def -i -p9999 -mregexp -t"^(One|Two|Three|Four|Five|Six|Seven|Eight|Nine|[0-9]+) (%{1}) \\(([0-9]+) power, ([0-9]+) standard, ([0-9]+) poor\\)$$" grpouch_%{_tmps} =\
		/test grpouch_report({P1},{P3},{P4},{P5},{P2},"%{2}")

/test gdefrpouch("handfuls? of olivine powder",		"Acid Blast")
/test gdefrpouch("stone cubes?",			"Acid Shield")
/test gdefrpouch("pairs? of interlocked bloodstone rings", "Acid Storm")
/test gdefrpouch("small highsteel discs?",		"Armour of Aether")
/test gdefrpouch("tiny leather bags? \(empty\)",	"Aura of Wind")
/test gdefrpouch("bronze marbles?",			"Blast Vacuum")
/test gdefrpouch("steel arrowheads?",			"Cold Ray")
/test gdefrpouch("small pieces? of electrum wire",	"Electrocution")
/test gdefrpouch("small glass cones?",			"Flame Shield")
/test gdefrpouch("grey fur triangles?",			"Frost Shield")
/test gdefrpouch("copper rods?",			"Golden Arrow")
/test gdefrpouch("handfuls? of onyx gravel",		"Hailstorm")
/test gdefrpouch("ebony tubes?",			"Killing Cloud")
/test gdefrpouch("granite spheres?",			"Lava Blast")
/test gdefrpouch("blue cobalt cups? \(empty\)",		"Lava Storm")
/test gdefrpouch("small iron rods?",			"Lightning Shield")
/test gdefrpouch("clusters? of tungsten wires",		"Lightning Storm")
/test gdefrpouch("tiny platinum hammers?",		"Magic Eruption")
/test gdefrpouch("quartz prisms?",			"Repulsor Aura")
/test gdefrpouch("tiny amethyst crystals?",		"Shield of Detoxification")
/test gdefrpouch("silvery bark chips?",			"Summon Carnal Spores")
/test gdefrpouch("small brass fans?",			"Vacuum Globe")


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Camping / lullaby / etc.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/def -i -p9999 -aCgreen -mregexp -t"^You (stretch yourself and consider about camping|feel a bit tired|feel like camping a little)" gcamp_ready =\
	/set camp_st=1%;\
	/gstatus_update%;\
	/msr Can camp again

/def -i gcamp_start =\
	/set camp_st=2%;\
	/gstatus_update%;\
	/set camp_hp=%{status_hp}%;\
	/set camp_sp=%{status_sp}%;\
	/set camp_ep=%{status_ep}%;\
	/set camp_time=$[time()]

/def -i -p9999 -aCgreen -msimple -t"You lie down and begin to rest for a while." gcamp_start1 =\
	/gcamp_start

/def -i -p9999 -aCgreen -mregexp -t"^You lie down for a short rest, soothed by the lullaby sung by " gcamp_start2 =\
	/gcamp_start

/def -i -p9999 -aCgreen -msimple -t"You awaken from your short rest, and feel slightly better." gcamp_end =\
	/if (camp_st == 2)\
		/set camp_st=0%;\
		/gstatus_update%;\
		@@sc%;\
		/def -p1 -n1 -mregexp -t"^H:" gcamp_awake =\
		/msr Awake - $$[status_hp - camp_hp]hp, $$[status_sp - camp_sp]sp, $$[status_ep - camp_ep]ep $[prgetstime(camp_time)]%%;\
		/gmsg_empty_que%;\
	/endif

/def -i -p9999 -aCgreen -msimple -t"You wake up!" gcamp_interrupt =\
	/if (camp_st == 2)\
		/set camp_st=0%;\
		/gstatus_update%;\
		/msr Camping interrupted!%;\
	/endif


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Ceremony
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/def -i -p9999 -msimple -t"You perform the ceremony." gceremony_on =\
	/if (skill_st2=~"on")\
		/set skill_st2=off%;\
		/set ceremony_st=on%;\
	/endif

/def -i -p9999 -ag -msimple -t"You have an unusual feeling as you cast the spell." gceremony_off =\
	/set ceremony_st=off

/def -i ceremony =\
	/if (ceremony_st=~"on")\
		/msq @{BCwhite}Ceremony@{n} @{Cyellow}already in effect!@{n}%;\
	/else \
		@@use ceremony%;\
	/endif


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Path compression
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/def -i prcomptoken =\
	/if ({1} > 1)\
		/let _qa=%{1} %{2}%;\
	/else \
		/let _qa=%{2}%;\
	/endif%;\
	/if (qtzst=~"")\
		/set qtzst=%{_qa}%;\
	/else \
		/set qtzst=%{qtzst};%{_qa}%;\
	/endif

/def -i prcomppath =\
	/set qtzst=%;/let _qp=%;/let _qi=1%;/let _qc=1%;\
	/while ({#})\
		/if ({1}=~_qp & _qc < 15)\
			/let _qc=$[_qc+1]%;\
		/else \
			/prcomptoken %{_qc} %{_qp}%;\
			/let _qc=1%;\
		/endif%;\
		/let _qp=%{1}%;\
		/shift%;\
	/done%;\
	/prcomptoken %{_qc} %{_qp}

/def -i prreversepath =\
	/set qtzst=%;\
	/while ({#})\
		/if	({1}=~"n")	/let _qp=s%;\
		/elseif ({1}=~"s")	/let _qp=n%;\
		/elseif ({1}=~"w")	/let _qp=e%;\
		/elseif ({1}=~"e")	/let _qp=w%;\
		/elseif ({1}=~"nw")	/let _qp=se%;\
		/elseif ({1}=~"ne")	/let _qp=sw%;\
		/elseif ({1}=~"sw")	/let _qp=ne%;\
		/elseif ({1}=~"se")	/let _qp=nw%;\
		/elseif ({1}=~"u")	/let _qp=d%;\
		/elseif ({1}=~"d")	/let _qp=u%;\
		/elseif	({1}=~"N")	/let _qp=S%;\
		/elseif ({1}=~"S")	/let _qp=N%;\
		/elseif ({1}=~"W")	/let _qp=E%;\
		/elseif ({1}=~"E")	/let _qp=W%;\
		/elseif ({1}=~"NW")	/let _qp=SE%;\
		/elseif ({1}=~"NE")	/let _qp=SW%;\
		/elseif ({1}=~"SW")	/let _qp=NE%;\
		/elseif ({1}=~"SE")	/let _qp=NW%;\
		/elseif ({1}=~"U")	/let _qp=D%;\
		/elseif ({1}=~"D")	/let _qp=U%;/endif%;\
		/set qtzst=%{_qp} %{qtzst}%;\
		/shift%;\
	/done

/def comppath = /prcomppath %{path}%;/echo Compressed Path: %{qtzst}
/def csavepath = /prcomppath %{path}%;@command %1 %{qtzst}
/def reversepath = /prreversepath %{path}%;/echo Reversed Path: %{qtzst}


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Hit stats
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; TODO: make the stats general (ggrtf-fighter.tf) or something
/set hst_total=0
/set hst_misses=0
/set hst_crits=0
/set hst_crithit=0
/set lst_hits=
/set lst_crits=
/set hst_special=0

/def -i prdefhitspec =\
	/if (!getopts("n:t:r", "")) /gerror Invalid prdefhitspec definition!%;/break%;/endif%;\
	/if (opt_n=~""|opt_t=~"") /gerror Required arguments not specified!%;/break%;/endif%;\
	/if (opt_r) /let _ttype=regexp%;/else /let _ttype=simple%;/endif%;\
	/set hst_%{opt_n}=0%;\
	/def -i -aCblue -m%{_ttype} -t"%{opt_t}" ghitstats_%{opt_n} =\
		/set hst_special=$$[hst_special+1]%%;\
		/set hst_%{opt_n}=$$[hst_%{opt_n}+1]

/def -i -aCblue -mregexp -t"^You score a \*?CRITICAL\*? hit!$" ghitstats_crit =\
	/set hst_crithit=1

/def -i prdefhit =\
	/let _hname=%{1}_%{2}%;\
	/set lst_hits=%{lst_hits} %{_hname}%;\
	/set lst_crits=%{lst_crits} %{_hname}%;\
	/set hst_%{_hname}=0%;\
	/set hst_c%{_hname}=0%;\
	/set hst_name_%{_hname}=%{3}%;\
	/set hst_name_c%{_hname}=%{3}%;\
	/def -i -aCblue -mregexp -t"^(You|(Cackling|Smiling|Grinning) (demonically|devilishly|diabolically) you) %{3} " ghitstats_%{_hname} =\
		/set hst_total=$$[hst_total+1]%%;\
		/if (hst_crithit==1) \
			/set hst_crithit=0%%;\
			/set hst_crits=$$[hst_crits+1]%%;\
			/set hst_c%{_hname}=$$[hst_c%{_hname}+1]%%;\
		/else \
			/set hst_%{_hname}=$$[hst_%{_hname}+1]%%;\
		/endif

;; Specials
/prdefhitspec -n"misses" -t"You miss."
/prdefhitspec -n"dodges" -t"You dodge."
/prdefhitspec -n"parries" -t"You parry."
/prdefhitspec -n"ripostes" -t"...AND riposte."
/prdefhitspec -n"tumbles" -t"^You tumble .+'s dodge\.$" -r
/prdefhitspec -n"stuns" -t"^You STUN " -r


;; Non-weapon
/test prdefhit("brawl", 01, "spank")

/test prdefhit("brawl", 02, "smack")


;; Slashing weapons (axes and long blades)
/test prdefhit("axes", 01, "solidly slash")
/test prdefhit("axes", 02, "gash")
/test prdefhit("axes", 03, "lightly cut")
/test prdefhit("axes", 04, "cut")
/test prdefhit("axes", 05, "tear")
/test prdefhit("axes", 06, "incise")
/test prdefhit("axes", 07, "shred")
/test prdefhit("axes", 08, "horribly shred")
/test prdefhit("axes", 09, "slash")
/test prdefhit("axes", 10, "incisively cut")
/test prdefhit("axes", 11, "pierce")
/test prdefhit("axes", 12, "slit")
/test prdefhit("axes", 13, "cruelly tatter")
/test prdefhit("axes", 14, "rive")
/test prdefhit("axes", 15, "savagely shave")
/test prdefhit("axes", 16, "cruelly slash")
/test prdefhit("axes", 17, "uncontrollably slash")
/test prdefhit("axes", 18, "quickly cut")
/test prdefhit("axes", 19, "savagely rip")
/test prdefhit("axes", 20, "BRUTALLY TEAR")
/test prdefhit("axes", 21, "SAVAGELY SHRED")
/test prdefhit("axes", 22, "CRUELLY REND")
/test prdefhit("axes", 23, "DISMEMBER")


;; Bludgeons
/test prdefhit("blud", 01, "jostle")
/test prdefhit("blud", 02, "butt")
/test prdefhit("blud", 03, "bump")
/test prdefhit("blud", 04, "thump")
/test prdefhit("blud", 05, "stroke")
/test prdefhit("blud", 06, "thrust")
/test prdefhit("blud", 07, "jab")
/test prdefhit("blud", 08, "bash")
/test prdefhit("blud", 09, "strike")
/test prdefhit("blud", 10, "sock")
/test prdefhit("blud", 11, "cuff")
/test prdefhit("blud", 12, "knock")
/test prdefhit("blud", 13, "flail")
/test prdefhit("blud", 14, "whack")
/test prdefhit("blud", 15, "beat")
/test prdefhit("blud", 16, "smash")
/test prdefhit("blud", 17, "cruelly beat")
/test prdefhit("blud", 18, "badly smash")
/test prdefhit("blud", 19, "horribly thrust")
/test prdefhit("blud", 20, "savagely sock")
/test prdefhit("blud", 21, "savagely strike")
/test prdefhit("blud", 22, "REALLY WHACK")
/test prdefhit("blud", 23, "BRUTALLY BEAT")
/test prdefhit("blud", 24, "CRUELLY CUFF")
/test prdefhit("blud", 25, "BARBARICALLY BASH")


;; Output
/def -i ghitstats_print =\
	/eval /set cnttmp=$$[hst_%{1}]%;\
	/if (cnttmp > 0) \
		/set hst_count=$[hst_count + 1]%;\
		/if (hst_total > 0) \
			/eval /set cnttmp=$$[trunc((cnttmp * 100) / hst_total)]%;\
		/else \
			/set cnttmp=0%;\
		/endif%;\
		/eval /msw | $$[pad(hst_name_%{1},-30)] - $$[pad(hst_%{1},8)] / $$[pad(cnttmp,4)]%%% |%;\
	/endif

/def -i ghitstats_dolist1 = /while ({#}) /ghitstats_print %{1}%;/shift%;/done
/def -i ghitstats_dolist2 = /while ({#}) /ghitstats_print c%{1}%;/shift%;/done

/def -i hstats =\
/set hst_count=0%;\
/msw ,-----------------.%;\
/msw | @{BCgreen}GgrTF@{n} @{Cyellow}Hit Stats@{n} |%;\
/msw +-| @{BCgreen}Normal@{n} |------+---------------------------------.%;\
/ghitstats_dolist1 %{lst_hits}%;\
/msw +-| @{BCred}Critical@{n} |--------------------------------------+%;\
/ghitstats_dolist2 %{lst_crits}%;\
/msw +---------------------------------------------------+%;\
/let _qtmp=$[hst_total + hst_misses]%;\
/if (_qtmp != 0) \
	/let _qtmp1=$[trunc((100 * hst_total) / _qtmp)]%;\
	/let _qtmp2=$[trunc((100 * hst_misses) / _qtmp)]%;\
	/let _qtmp3=$[trunc((100 * hst_crits)  / _qtmp)]%;\
/else \
	/let _qtmp1=0%;\
	/let _qtmp2=0%;\
	/let _qtmp3=0%;\
/endif%;\
/msw | Hits..: @{Cgreen}$[pad(hst_total,-8)]@{n} (@{BCgreen}$[pad(_qtmp1,3)]\%@{n}) | Crits.: @{Cred}$[pad(hst_crits,-8)]@{n} (@{BCred}$[pad(_qtmp3,3)]\%@{n}) |%;\
/msw | Misses: @{Cyellow}$[pad(hst_misses,-8)]@{n} (@{BCyellow}$[pad(_qtmp2,3)]\%@{n}) | Total Hit Types: @{BCwhite}$[pad(hst_count,-6)]@{n} |%;\
/msw +---------------------------------------+-----------'%;\
/msw | Dodges.: @{BCmagenta}$[pad(hst_dodges,-8)]@{n} | Parries: @{BCyellow}$[pad(hst_parries,-8)]@{n} |%;\
/msw | Tumbles: @{BCgreen}$[pad(hst_tumbles,-8)]@{n} | Stuns..: @{BCred}$[pad(hst_parries,-8)]@{n} |%;\
/msw `---------------------------------------'


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Slots mangler
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; FIXME: What if torso is not the last slot listed? How to elegantly print
;; the bottom of the table?

/def -i -ag -p9999 -msimple -t"Your current armour status is:" gslots_mangle1 =\
	/set slots_st=1%;\
	/set slots_ftotal=0%;\
	/msw ,--------------------.%;\
	/msw | Free  | Slot       |%;\
	/msw +-------+------------+

/def -i -E(slots_st==1) -ag -p9999 -mregexp -t"^  You have (.*) free ([a-z]*) slots?\.$" gslots_mangle2 =\
	/let _tslot=%{P2}%;\
	/if     ({P1}=~"no")	/let _tnum=0%;\
	/elseif ({P1}=~"one")	/let _tnum=1%;\
	/elseif ({P1}=~"two")	/let _tnum=2%;\
	/elseif ({P1}=~"three")	/let _tnum=3%;\
	/elseif ({P1}=~"four")	/let _tnum=4%;\
	/elseif ({P1}=~"five")	/let _tnum=5%;\
	/else			/let _tnum=-1%;\
	/endif%;\
	/if (_tnum < 0)\
		/let _tcol=Cyellow%;/let _tnum=%{P1}%;\
	/elseif (_tnum > 0)\
		/set slots_ftotal=$[slots_ftotal+_tnum]%;\
		/if (_tnum > 1)\
			/let _tcol=BCgreen%;\
		/else \
			/let _tcol=Cgreen%;\
		/endif%;\
	/else \
		/let _tcol=BCred%;\
	/endif%;\
	/msw | @{%{_tcol}}$[pad(_tnum,5)]@{n} | $[pad(_tslot,-10)] |%;\
	/if (_tslot=~"torso")\
		/set slots_st=0%;\
		/msw +--------------------+%;\
		/msw | Total free: @{BCgreen}$[pad(slots_ftotal,-6)]@{n} |%;\
		/msw `--------------------'%;\
	/endif