#!/usr/bin/env bash
# Changelog:
# 2021-01-13
#   - Increase ffatiguespellbase and ffatiguespellmult to 0.5 to spend a bit more fatigue on magic cast
#   - Revert back to default Timescale - makes game world more vivid
#
# 2021-01-21
#   - Decrease fCombatDelayCreature, fCombatDelayNPC to make enemies slightly more aggresive in combat
#
# 2021-06-07
#   - Add GMSTs from BTBGI-NE v2.0.1: fholdbreathtime, fcombatcriticalstrikemult, ilevelupXXmult
#
# 2021-07-10
#   - Restructure patch, make it more modular
#   - Move NCGD values into Redundant - Special version just to avoid someone's problems with it without NCGD
#
# 2021-07-14
#   - Change funarmoredbase2 to 0.05 (default 0.065, btb - 0.1)
#
# 2021-09-18
#   - Change fEnchantmentChanceMult to 30000 in redundant version
#
# 2021-11-22
#   - Revert fprojectilethrownstorechance to default to synergize with encumbrance changes
#
# 2022-01-24
#   - Revert back ftravelmult to default value. Increased prices make game less enjoyable at low levels.
#
# 2022-08-01
#   - Add GMSTs to decrease control while jumping: fjumpmovebase, fjumpmovemult (Reduced Forward Jumping)
#   - Add GMSTs to decrease initial disposition: fdisppersonalitybase (PR Real Disposition Base)
#
# 2022-12-05
#   - Change GMSTs to decrease initial disposition to Light: fdisppersonalitybase (PR Real Disposition Light)
#
# vim: nowrap
# command used for formatting text: '<,'>EasyAlign 4/\-\-/r0 ; '<,'>EasyAlign / '/r0
source_morrowind="Morrowind.esm"
source_tribunal_="Tribunal.esm"
# files produced by this script will be a source for others
source_fast_walk="avp BTBGI-NE - Game Settings - 17 Percent Faster Walking.esp"
source_encumbran="avp BTBGI-NE - Game Settings - More Meaningful Encumbrance.esp"
source_btbadjust="avp BTBGI-NE - Game Settings - BTBGI Adjustments.esp"
source_suggested="avp BTBGI-NE - Game Settings - Suggested Tweaks.esp"
source_gmstmerge="avp BTBGI-NE - Game Settings - Merged.esp"
source_mergredun="avp BTBGI-NE - Game Settings - Merged - Redundant.esp"
tes3cmd="./tes3cmd"

# 1. Increase walk speed by 17%. It's not large enough value to break or unbalance something, though it's large enough to notice.

result="${source_fast_walk}"
$tes3cmd dump "${source_morrowind}" --raw-with-header "${result}" --type GMST \
 --exact-id "fbaserunmultiplier" \
 --exact-id "fathleticsrunbonus" \
 --exact-id "fminwalkspeed" \
 --exact-id "fmaxwalkspeed"

# Run multiplier default is 1.75, the minimum i'd like to go is 1.5. Let it be the desired value. That means i may up the walkspeed by 17% (rounded from 16.(6) - don't want to bother with fractionals as i don't know morrowind precision limits). More drastic changes to walk speed would require either changing EVERYTHING or at least run speed would differ from vanilla. So in total to make 17% increase in walk speed i'd have to change folllowing 4 gmsts: 
#
#   walkspeed = fminwalkspeed + ( speed * 0.01 * ( fmaxwalkspeed – fminwalkspeed ) )
#   runspeed = walkspeed * ( fbaserunmultiplier + ( athletics * 0.01 * fathleticsrunbonus ) )
#
#   fbaserunmultiplier          | 1.75 -> 1.5                                         | decrease speed difference between walk and run
#   fathleticsrunbonus          | 1 -> 0.85                                           | decrease athletics share in run speed equations
#   fminwalkspeed               | 100 -> 117                                          | increase min walk speed
#   fmaxwalkspeed               | 200 -> 234                                          | increase max walk speed

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fbaserunmultiplier"           --run "\$R->set({t=>'FLTV', f=>'Float'},    '1.5')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fathleticsrunbonus"           --run "\$R->set({t=>'FLTV', f=>'Float'},    '0.85')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fminwalkspeed"                --run "\$R->set({t=>'FLTV', f=>'Float'},    '117')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fmaxwalkspeed"                --run "\$R->set({t=>'FLTV', f=>'Float'},    '234')"

# 2. More meaningful encumbrance

result="${source_encumbran}"
$tes3cmd dump "${source_morrowind}" --raw-with-header "${result}" --type GMST \
 --exact-id "fjumpencumbrancebase" \
 --exact-id "fjumpencumbrancemultiplier" \
 --exact-id "ffatigueattackmult" \
 --exact-id "ffatigueblockmult" \
 --exact-id "ffatigueblockbase" \
 --exact-id "ffatiguerunmult" \
 --exact-id "ffatiguerunbase" \
 --exact-id "ffatiguejumpmult" \
 --exact-id "ffatiguejumpbase" \
 --exact-id "ffatigueswimrunmult" \
 --exact-id "ffatigueswimrunbase" \
 --exact-id "ffatigueswimwalkmult" \
 --exact-id "ffatigueswimwalkbase" \
 --exact-id "ffatiguesneakmult" \
 --exact-id "ffatiguespellmult" \
 --exact-id "ffatiguespellbase"

# 2.1. Jump height
# 
# Following two effectively make encumbered jumps a bit lower (i.e. with half encumbrance jump is 14% lower, with 3/4 it's 33% lower), though unencumbered jumps height stays the same.
# Didn't make "base" gmst to 0 to not totally nerf jump spells with high encumbrance.
#
#   jump heigh coefficient = fjumpencumbrancebase + fjumpencumbrancemultiplier * (1 - normalizedencumbrance)
#
#   fjumpencumbrancebase        | 0.5 -> 0.25                                         | make jump height more dependent on encumbrance
#   fjumpencumbrancemultiplier  | 1 -> 1.25                                           | keep the same max jump height with decreased minimal height 

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fjumpencumbrancebase"         --run "\$R->set({t=>'FLTV', f=>'Float'},    '0.25')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fjumpencumbrancemultiplier"   --run "\$R->set({t=>'FLTV', f=>'Float'},    '1.25')"

# 2.2. Jump fatigue
#
# This makes jumping depend on encumbrance. With < 25% load you'll spend less fatigue then with btb default settings, though much more when encumbered.
#
#   fatigue cost = ffatiguejumpbase + normalizedencumbrance * ffatiguejumpmult
#
#   ffatiguejumpmult            | 0 -> 20                                             | increase fatigue cost for jumping encumbered
#   ffatiguejumpbase            | 5 -> 10 (wakim) -> 20 (btb) -> 15                   | increase fatigue cost for jumping

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatiguejumpmult"             --run "\$R->set({t=>'FLTV', f=>'Float'},    '20')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatiguejumpbase"             --run "\$R->set({t=>'FLTV', f=>'Float'},    '15')"

# 2.3. Attack fatigue
#
# Attack fatigue base is not decreased as in other similar GMST changes because i think that 4 is not enough. So now with 25% encumbrance it's 5.
#
#   attack fatigue cost = (ffatigueattackbase + (enc% * ffatigueattackmult) + weapon weight * (fweaponfatiguemult * swing%))
#
#   ffatigueattackmult          | 0 -> 4                                              | increase fatigue cost of attacking based on encumbrance

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatigueattackmult"           --run "\$R->set({t=>'FLTV', f=>'Float'},    '4')"

# 2.4. Block fatigue
#
# Same as other changes, <25% encumbrance is now cheaper on fatigue, but overweight makes everything harder
#
#   ffatigueblockmult           | 0 -> 8                                              | increase fatigue cost of blocking based on encumbrance
#   ffatigueblockbase           | 4 -> 8 (btb) -> 6                                   | increase fatigue cost of block

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatigueblockmult"            --run "\$R->set({t=>'FLTV', f=>'Float'},    '8')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatigueblockbase"            --run "\$R->set({t=>'FLTV', f=>'Float'},    '6')"

# 2.5. Run fatigue
#
# This makes running with less than 25% encumbrance less tiring than with btb. Though with more than 50% encumbrance it becomse more tiring than in vanilla.
#
#   ffatiguerunmult             | 2 -> 4                                              | increase fatigue cost of running with encumbrance
#   ffatiguerunbase             | 5 -> 4 (btb) -> 3.5                                 | decrease fatigue cost of running

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatiguerunmult"              --run "\$R->set({t=>'FLTV', f=>'Float'},    '4')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatiguerunbase"              --run "\$R->set({t=>'FLTV', f=>'Float'},    '3.5')"

# 2.6. Swim "run" fatigue
#
# This makes fast swimming depend on encumbrance. With < 25% load you'll spend less fatigue then with btb default settings, though more when encumbered.
#
#   ffatigueswimrunmult         | 0 -> 6                                              | increase fatigue cost for fast swimming while encumbered
#   ffatigueswimrunbase         | 7 -> 5.5                                            | decrease fatigue cost for fast swimming

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatigueswimrunmult"          --run "\$R->set({t=>'FLTV', f=>'Float'},    '6')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatigueswimrunbase"          --run "\$R->set({t=>'FLTV', f=>'Float'},    '5.5')"

# 2.7. Swim "walk" fatigue
#
# This makes swimming depend on encumbrance. With < 25% load you'll spend less fatigue then with btb default settings, though more when encumbered.
#
#   ffatigueswimwalkmult        | 0 -> 2                                              | increase fatigue cost for swimming while encumbered
#   ffatigueswimwalkbase        | 2.5 -> 2                                            | decrease fatigue cost for swimming

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatigueswimwalkmult"         --run "\$R->set({t=>'FLTV', f=>'Float'},    '2')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatigueswimwalkbase"         --run "\$R->set({t=>'FLTV', f=>'Float'},    '2')"

# 2.8. Sneak fatigue
#
# Slightly increase fatigue cost of sneaking when encumbered.
#
#   ffatiguesneakmult           | 1.5 -> 3                                            | increase fatigue cost for sneaking just a bit when encumbered

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatiguesneakmult"            --run "\$R->set({t=>'FLTV', f=>'Float'},    '3')"

# 2.9. Spell fatigue
#
# Make spells cost fatigue as a fraction of magicka. Doesn't matter at all when light on foot.
#
#   fatigue loss = magickacost * (ffatiguespellbase + normalizedencumbrance * ffatiguespellmult)
#
#   ffatiguespellmult           | 0 -> 0.5                                            | add fraction of spell magicka cost as fatigue cost
#   ffatiguespellbase           | 0 -> 0.5                                            | increase fatigue cost of spellcase with encumbrance

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatiguespellmult"            --run "\$R->set({t=>'FLTV', f=>'Float'},    '0.5')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatiguespellbase"            --run "\$R->set({t=>'FLTV', f=>'Float'},    '0.5')"

# 3. Arguable tweaks of some BTBGI's values

result="${source_btbadjust}"
$tes3cmd dump "${source_morrowind}" --raw-with-header "${result}" --type GMST \
 --exact-id "fbartergoldresetdelay" \
 --exact-id "igreetdistancemultiplier" \
 --exact-id "funarmoredbase2" \
 --exact-id "fprojectilethrownstorechance" \
 --exact-id "fpicklockmult" \
 --exact-id "ftrapcostmult" \
 --exact-id "fdispweapondrawn" \
 --exact-id "faifleehealthmult"

# These values were simply reverted to Morrowind's default values:
#
#   fbartergoldresetdelay       | 24 -> 1 (btb) -> 24                                 | don't change time to reset trader gold
#   igreetdistancemultiplier    | 6 -> 2 (btb) -> 6                                   | don't change greeting distance to hear all the insults :-)
#   funarmoredbase2             | 0.065 -> 0.1 (btb) -> 0.05                          | decrease unarmored rating for everyone
#   fprojectilethrownstorechance| 25 -> 50 (btb) -> 25                                | don't change arrow recovery chance, encumbrance overhaul
#
# These 4 were changed:
#
#   fpicklockmult               | -1 -> -1.25 (btb) -> -1.3 (thief overhaul) -> -1.3  | increase lock pick difficulty
#   ftrapcostmult               | 0 -> -0.5 (btb) -> -1 (thief overhaul) -> -1        | increase lock open with spell difficulty
#   fdispweapondrawn            | -5 -> -10 (btb) -> -15 (wakim) -> -15               | decrease disposition with weapon drawn
#   faifleehealthmult           | 7 -> 45 (btb) -> 56 (wakim) -> 56                   | increase flee chance
#
# Few values were changed in another module and are not included here:
#
#   ffatigueblockbase           | 4 -> 8 (btb) -> 6                                   | "More meaningful encumbrance"
#   ffatiguerunbase             | 5 -> 4 (btb) -> 3.5                                 | "More meaningful encumbrance"
#   ffatiguejumpbase            | 5 -> 10 (wakim) -> 20 (btb) -> 15                   | "More meaningful encumbrance"

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "funarmoredbase2"              --run "\$R->set({t=>'FLTV', f=>'Float'},    '0.05')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fpicklockmult"                --run "\$R->set({t=>'FLTV', f=>'Float'},    '-1.3')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ftrapcostmult"                --run "\$R->set({t=>'FLTV', f=>'Float'},    '-1')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fdispweapondrawn"             --run "\$R->set({t=>'FLTV', f=>'Float'},    '-15')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "faifleehealthmult"            --run "\$R->set({t=>'FLTV', f=>'Float'},    '56')"

# 4. Suggested tweaks

result="${source_suggested}"
$tes3cmd dump "${source_morrowind}" --raw-with-header "${result}" --type GMST \
 --exact-id "i1stpersonsneakdelta" \
 --exact-id "fprojectileminspeed" \
 --exact-id "fprojectilemaxspeed" \
 --exact-id "fthrownweaponminspeed" \
 --exact-id "fthrownweaponmaxspeed" \
 --exact-id "fmagesguildtravel" \
 --exact-id "srestillegal" \
 --exact-id "skilledessential" \
 --exact-id "strapimpossible" \
 --exact-id "fhandtohandreach" \
 --exact-id "fCombatDelayCreature" \
 --exact-id "fCombatDelayNPC" \
 --exact-id "fjumpmovebase" \
 --exact-id "fjumpmovemult" \
 --exact-id "fdisppersonalitybase"
 # --exact-id "ftravelmult" \
$tes3cmd dump "${source_tribunal_}" --raw "${result}" --type GMST \
 --exact-id "ffleedistance"
$tes3cmd header "${result}" --hide-backups --update-record-count

# 4.1. Values suggested by other mods that IMO make game better
#
#   i1stpersonsneakdelta        | 10 -> 25 (lower first person sneak)                 | lowers view point in sneak mode
#   fprojectileminspeed         | 400 -> 960 (projectile overhaul) -> 800             | increase min arrow movement speed
#   fprojectilemaxspeed         | 3000 -> 7200 (projectile overhaul) -> 6000          | increase max arrow movement speed
#   fthrownweaponminspeed       | 300 -> 360 (projectile overhaul) -> 360             | increase min thrown movement speed
#   fthrownweaponmaxspeed       | 1000 -> 1200 (projectile overhaul) 1200             | increase max thrown movement speed
# Change: 2022-01-24 - Revert back ftravelmult to default value. Increased prices make game less enjoyable at low levels.
#   ftravelmult                 | 4000 -> 1000 (price balance) -> 1000                | increase travel price
#   fmagesguildtravel           | 10 -> 40 (price balance) -> 40                      | increase guild guide travel price
#   srestillegal                | "Resting" -> "Camping" (wakim) -> <wakim's version> | change message to better one IMO
#   skilledessential            | "prophecy is severed" -> "weakened"(WGI) -> <WGI>   | change message to better one IMO
#   strapimpossible             | "your chance to disarm" -> "" (thief overhaul)      | change message to better one IMO
# Change: 2022-08-01 - Add GMSTs to decrease control while jumping: fjumpmovebase, fjumpmovemult (Reduced Forward Jumping)
#   fjumpmovebase               | 0.5 -> 0.3(Reduced Forward Jumping) -> 0.25         | less "control" during jump
#   fjumpmovemult               | 0.5 -> 0.0(Reduced Forward Jumping) -> 0.25         | less "control" during jump
# Change: 2022-08-01 - Add GMSTs to decrease initial disposition: fdisppersonalitybase (PR Real Disposition Base)
# Change: 2022-12-05 - Change GMSTs to decrease initial disposition to Light: fdisppersonalitybase (PR Real Disposition Light)
#   fdisppersonalitybase        | 50 -> 70(PR Real Disposition Light) -> 70           | decreaase initial disposition

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "i1stpersonsneakdelta"         --run "\$R->set({t=>'INTV', f=>'Integer'},  '25')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fprojectileminspeed"          --run "\$R->set({t=>'FLTV', f=>'Float'},    '800')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fprojectilemaxspeed"          --run "\$R->set({t=>'FLTV', f=>'Float'},    '6000')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fthrownweaponminspeed"        --run "\$R->set({t=>'FLTV', f=>'Float'},    '360')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fthrownweaponmaxspeed"        --run "\$R->set({t=>'FLTV', f=>'Float'},    '1200')"
# Change: 2022-01-24 - Revert back ftravelmult to default value. Increased prices make game less enjoyable at low levels.
# $tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ftravelmult"                  --run "\$R->set({t=>'FLTV', f=>'Float'},    '1000')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fmagesguildtravel"            --run "\$R->set({t=>'FLTV', f=>'Float'},    '40')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "srestillegal"                 --run "\$R->set({t=>'STRV', f=>'String'},   'Camping here is illegal. You\'ll need to find a bed.')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "skilledessential"             --run "\$R->set({t=>'STRV', f=>'String'},   'With this character\'s death, the thread of prophecy is severely weakened. Load a saved game to restore the weave of fate, or remain and face the new challenges in the world you have created.')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "strapimpossible"              --run "\$R->set({t=>'STRV', f=>'String'},   'Trap too complex.')"
# Change: 2022-08-01 - Add GMSTs to decrease control while jumping: fjumpmovebase, fjumpmovemult (Reduced Forward Jumping)
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fjumpmovebase"                --run "\$R->set({t=>'FLTV', f=>'Float'},    '0.25')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fjumpmovemult"                --run "\$R->set({t=>'FLTV', f=>'Float'},    '0.25')"
# Change: 2022-08-01 - Add GMSTs to decrease initial disposition: fdisppersonalitybase (PR Real Disposition Base)
# Change: 2022-12-05 - Change GMSTs to decrease initial disposition to Light: fdisppersonalitybase (PR Real Disposition Light)
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fdisppersonalitybase"         --run "\$R->set({t=>'FLTV', f=>'Float'},    '70')"

# 4.2. Values I've changed that IMO make game better
#
# Change: 2021-01-21 - Decrease fCombatDelayCreature, fCombatDelayNPC to make enemies slightly more aggresive in combat
#
#   ffleedistance               | 3000 -> 4500                                        | increase flee distance
#   fhandtohandreach            | 1 -> 0.67                                           | decrease hand to hand reach 
#   fcombatdelaycreature        | 0.1 -> 0                                            | make creatures less restrained
#   fcombatdelaynpc             | 0.1 -> 0                                            | make NPCs less restrained

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffleedistance"                --run "\$R->set({t=>'FLTV', f=>'Float'},    '4500')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fhandtohandreach"             --run "\$R->set({t=>'FLTV', f=>'Float'},    '0.67')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fcombatdelaycreature"         --run "\$R->set({t=>'FLTV', f=>'Float'},    '0')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fcombatdelaynpc"              --run "\$R->set({t=>'FLTV', f=>'Float'},    '0')"

# 5. Previous modules merged into one

result="${source_gmstmerge}"
$tes3cmd dump "${source_fast_walk}" --raw-with-header "${result}" --type GMST
$tes3cmd dump "${source_encumbran}" --raw "${result}" --type GMST
$tes3cmd dump "${source_btbadjust}" --raw "${result}" --type GMST
$tes3cmd dump "${source_suggested}" --raw "${result}" --type GMST
$tes3cmd header "${result}" --hide-backups --update-record-count

# 6. Merged version with redundant (unchanged) values just to keep them all in one place - personal preference

result="${source_mergredun}"
# First dump all the previous changed from merged patch
$tes3cmd dump "${source_gmstmerge}" --raw-with-header "${result}" --type GMST
# Now dump all unchanged values from BTBGI
$tes3cmd dump "${source_morrowind}" --raw "${result}" --type GMST \
 --exact-id "faifleefleemult" \
 --exact-id "fbribe1000mod" \
 --exact-id "fbribe100mod" \
 --exact-id "fbribe10mod" \
 --exact-id "fdiseasexferchance" \
 --exact-id "fdispracemod" \
 --exact-id "felementalshieldmult" \
 --exact-id "fenchantmentchancemult" \
 --exact-id "fenchantmentvaluemult" \
 --exact-id "ffatigueattackbase" \
 --exact-id "fmagicitemoncemult" \
 --exact-id "fmagicitemrechargepersecond" \
 --exact-id "fnpcbasemagickamult" \
 --exact-id "frepairamountmult" \
 --exact-id "frepairmult" \
 --exact-id "fsneakviewmult" \
 --exact-id "fsoulgemmult" \
 --exact-id "fsuffocationdamage" \
 --exact-id "ftargetspellmaxspeed" \
 --exact-id "ialchemymod" \
 --exact-id "ibartersuccessdisposition" \
 --exact-id "isoulamountforconstanteffect" \
 --exact-id "itrainingmod" \
 --exact-id "fholdbreathtime" \
 --exact-id "fcombatcriticalstrikemult" \
 --exact-id "ilevelup01mult" \
 --exact-id "ilevelup02mult" \
 --exact-id "ilevelup03mult" \
 --exact-id "ilevelup04mult" \
 --exact-id "ilevelup08mult" \
 --exact-id "ilevelup09mult" \
 --exact-id "ilevelup10mult"
# REVERTED
#  --exact-id "fprojectilethrownstorechance" \
# Finally all the rest GMSTs not found in BTBGI
$tes3cmd dump "${source_morrowind}" --raw "${result}" --type GMST \
 --exact-id "fpcbasemagickamult" \
 --exact-id "ffatiguesneakbase" \
 --exact-id "fenchantmentconstantdurationmult" \
 --exact-id "ftravelmult"
$tes3cmd header "${result}" --hide-backups --update-record-count

# 6.1. All unchanged values from BTBGI
#
#   faifleefleemult             | 0.3 -> 1.5 (btb) -> 1.5                             | increase flee chance
#   fbribe1000mod               | 150 -> 60 (btb) -> 60                               | decrease chance to bribe
#   fbribe100mod                | 75 -> 40 (btb) -> 40                                | decrease chance to bribe 
#   fbribe10mod                 | 35 -> 20 (btb) -> 20                                | decrease chance to bribe
#   fdiseasexferchance          | 2.5 -> 3.75 (wakim) -> 5 (btb) -> 5                 | increase chance to catch disease
#   fdispracemod                | 5 -> 10 (btb) -> 10                                 | increase npc xenophobia
#   felementalshieldmult        | 0.1 -> 1 (btb) -> 1                                 | increase effectiveness of elemental shield
#   fenchantmentchancemult      | 3 -> 30 (btb) -> 30000 (necro) -> 30000             | decrease self-enchant chance (effectively disable)
#   fenchantmentvaluemult       | 1000 -> 100 (btb) -> 100                            | decrease enchantment price
#   ffatigueattackbase          | 2 -> 4 (btb) -> 4                                   | increase fatigue cost of attack
#   fmagicitemoncemult          | 1 -> 0.05 (btb) -> 0.05                             | decrease disposable items enchantment price (scrolls)
#   fmagicitemrechargepersecond | 0.05 -> 0.02 (wakim) -> 0 (btb) -> 0                | remove enchanted items self-recharge
#   fnpcbasemagickamult         | 2 -> 3 (btb) -> 3.5 (wakim) -> 3                    | increase npc magicka pool
#   REVERTED
#   fprojectilethrownstorechance| 25 -> 50 (btb) -> 80 (projectile overhaul) -> 50    | increase arrow recovery chance
#   frepairamountmult           | 3 -> 1.5 (btb) -> 1.5                               | decrease repair amount
#   frepairmult                 | 1 -> 0.5 (btb) -> 0.5                               | decrease repair cost
#   fsneakviewmult              | 1.5 -> 2 (btb) -> 2                                 | decrease chance to sneak in view of npc
#   fsoulgemmult                | 3 -> 2 (btb) -> 2                                   | decrease soulgem capacity
#   fsuffocationdamage          | 3 -> 9 (btb) -> 9                                   | increase suffocation damage
#   ftargetspellmaxspeed        | 1000 -> 1200 (proj overhaul) -> 4000 (btb) -> 4000  | increase spell movement speed
#   fialchemymod                | 2 -> 0 (btb) -> 0                                   | remove price for self-made potions
#   ibartersuccessdisposition   | 1 -> 0 (btb) -> 0                                   | disable disposition increase on successfull barter
#   isoulamountforconstanteffect| 400 -> 2000 (btb) -> 2000                           | decrease chance to create constant-effect enchantment (effectively disable)
#   itrainingmod                | 10 -> 20 (btb) -> 20                                | increase training prices

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "faifleefleemult"              --run "\$R->set({t=>'FLTV', f=>'Float'},    '1.5')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fbribe1000mod"                --run "\$R->set({t=>'FLTV', f=>'Float'},    '60')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fbribe100mod"                 --run "\$R->set({t=>'FLTV', f=>'Float'},    '40')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fbribe10mod"                  --run "\$R->set({t=>'FLTV', f=>'Float'},    '20')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fdiseasexferchance"           --run "\$R->set({t=>'FLTV', f=>'Float'},    '5')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fdispracemod"                 --run "\$R->set({t=>'FLTV', f=>'Float'},    '10')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "felementalshieldmult"         --run "\$R->set({t=>'FLTV', f=>'Float'},    '1')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fenchantmentchancemult"       --run "\$R->set({t=>'FLTV', f=>'Float'},    '30000')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fenchantmentvaluemult"        --run "\$R->set({t=>'FLTV', f=>'Float'},    '100')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ffatigueattackbase"           --run "\$R->set({t=>'FLTV', f=>'Float'},    '4')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fmagicitemoncemult"           --run "\$R->set({t=>'FLTV', f=>'Float'},    '0.05')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fmagicitemrechargepersecond"  --run "\$R->set({t=>'FLTV', f=>'Float'},    '0')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fnpcbasemagickamult"          --run "\$R->set({t=>'FLTV', f=>'Float'},    '3')"
# $tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fprojectilethrownstorechance" --run "\$R->set({t=>'FLTV', f=>'Float'},    '50')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "frepairamountmult"            --run "\$R->set({t=>'FLTV', f=>'Float'},    '1.5')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "frepairmult"                  --run "\$R->set({t=>'FLTV', f=>'Float'},    '0.5')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fsneakviewmult"               --run "\$R->set({t=>'FLTV', f=>'Float'},    '2')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fsoulgemmult"                 --run "\$R->set({t=>'FLTV', f=>'Float'},    '2')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fsuffocationdamage"           --run "\$R->set({t=>'FLTV', f=>'Float'},    '9')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ftargetspellmaxspeed"         --run "\$R->set({t=>'FLTV', f=>'Float'},    '4000')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ialchemymod"                  --run "\$R->set({t=>'INTV', f=>'Integer'},  '0')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ibartersuccessdisposition"    --run "\$R->set({t=>'INTV', f=>'Integer'},  '0')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "isoulamountforconstanteffect" --run "\$R->set({t=>'INTV', f=>'Integer'},  '2000')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "itrainingmod"                 --run "\$R->set({t=>'INTV', f=>'Integer'},  '20')"

# 6.2. All the rest GMSTs not found in BTBGI
#
#   fpcbasemagickamult          | 1 -> 1.5 (wakim) -> 1                               | don't change player magicka pool
#   ffatiguesneakbase           | 1.5 -> 1.5                                          | don't change
#   fenchantmentconstantdurationmult | 100 -> 110 (wakim) -> 100                      | useless because of btb's isoulamountforconstanteffect changes

# 7. Redundant version with NCGD values and Speechcraft Rebalance values reverted in case some mod will try to change them - personal preference

result="avp BTBGI-NE - Game Settings - Merged - Redundant - Special.esp"
# First dump all the previous changed from merged patch
$tes3cmd dump "${source_mergredun}" --raw-with-header "${result}" --type GMST
# NCGD values just to have everything in one place
$tes3cmd dump "${source_morrowind}" --raw "${result}" --type GMST \
 --exact-id "fminorskillbonus" \
 --exact-id "ilevelupmajormult" \
 --exact-id "ilevelupminormult" \
 --exact-id "fleveluphealthendmult" \
 --exact-id "fspecialskillbonus" \
 --exact-id "fmajorskillbonus" \
 --exact-id "fmiscskillbonus"
# Just control freaking
$tes3cmd dump "${source_morrowind}" --raw "${result}" --type GMST \
 --exact-id "fperdierollmult" \
 --exact-id "iperminchance" \
 --exact-id "iperminchange"
$tes3cmd header "${result}" --hide-backups --update-record-count

# 7.1. NCGD values
#
#   fminorskillbonus            | 1 -> 1.25 (btb) -> 1                                | ncgd
#   ilevelupmajormult           | 1 -> 0 (ncgd) -> 0                                  | ncgd
#   ilevelupminormult           | 1 -> 0 (ncgd) -> 0                                  | ncgd
#   fleveluphealthendmult       | 0.1 -> 0 (ncgd) -> 0                                | ncgd
#   fspecialskillbonus          | 0.8 -> 1 (ncgd) -> 1                                | ncgd
#   fmajorskillbonus            | 0.75 -> 1 (ncgd) -> 1                               | ncgd
#   fmiscskillbonus             | 1.25 -> 1 (ncgd) -> 30000 (btb) -> 1                | ncgd

$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ilevelupmajormult"            --run "\$R->set({t=>'INTV', f=>'Integer'},  '0')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "ilevelupminormult"            --run "\$R->set({t=>'INTV', f=>'Integer'},  '0')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fleveluphealthendmult"        --run "\$R->set({t=>'FLTV', f=>'Float'},    '0')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fspecialskillbonus"           --run "\$R->set({t=>'FLTV', f=>'Float'},    '1')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fmajorskillbonus"             --run "\$R->set({t=>'FLTV', f=>'Float'},    '1')"
$tes3cmd modify "${result}" --hide-backups --type GMST --exact-id "fmiscskillbonus"              --run "\$R->set({t=>'FLTV', f=>'Float'},    '1')"

# 7.2. Speechcraft Rebalance values
#
#   fperdierollmult             | 0.3 -> 0.2 (speechcraft rebalance) -> 0.3           | don't change persuasion multiplier
#   iperminchance               | 5 -> 50 (speechcraft rebalance) -> 5                | don't change success chance of persuasion
#   iperminchange               | 10 -> 1 (speechcraft rebalance) -> 10               | don't change minimal change value of persuasion

# Create dirs and move files there
mkdir -v "07 Game Settings - Modular"
mv -v\
  "${source_fast_walk}"\
  "${source_encumbran}"\
  "${source_btbadjust}"\
  "${source_suggested}"\
  "07 Game Settings - Modular"/
mkdir -v "07 Game Settings - Merged"
mv -v\
  "${source_gmstmerge}"\
  "07 Game Settings - Merged"/
mkdir -v "97 Game Settings - Merged"
mv -v\
  "${result}"\
  "97 Game Settings - Merged"/
