Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shopkeeper racial price adjustment code refactor #16

Merged
merged 4 commits into from
Apr 19, 2020

Conversation

copperwater
Copy link
Contributor

This is mostly that refactor, though another code-quality fix on this branch is also in here, as well as a bugfix.

This gets rid of the two mostly-duplicate blocks that controlled how
much of a price adjustment the shopkeeper gives the player based on the
shopkeeper's race, encapsulating most of that code in a new function
shk_racial_adjustments. This function computes a fraction representing
how much of a markup they will decide to give you, and it is more robust
than the original code; it uses the various is_race() macros rather than
enumerating all the possible species of a shopkeeper.

Rather than making a separate function for sell price racial
adjustments, the sell code now calls shk_racial_adjustments and applies
the reciprocal of the fraction it computes as a multiplier to sell cost:
if a given shopkeeper charges you a 4/3 markup on everything you buy,
they will cut their offer price to 3/4 for everything you sell. In most
cases, this makes the sell prices less harsh than they used to be. Here
is a summary (for sell prices; buy prices aren't changed, and not
accounting for any additional same-race bonuses):

Shk race | Player        | Old multiplier | New multiplier
Human    | Orc           |            2/3 |            3/4
Human    | Gnome         |            2/3 |            3/4
Human    | Centaur       |            1/2 |            2/3
Elf      | Dwarf         |            2/3 |            3/4
Dwarf    | Elf           |            2/3 |            3/4
Dwarf    | Giant         |            1/2 |            2/3
Orc      | Dwarf         |            1/3 |            3/5
Orc      | Human         |            2/3 |            3/4
Orc      | Orc           |            4/3 |            3/2
Gnome    | Int <= 14     |            1/2 |            2/3
Gnome    | 14 < Int < 18 |            2/3 |            3/4
Centaur  | Human         |            1/2 |            2/3
Centaur  | Gnome         |            1/2 |            2/3
Centaur  | Dwarf         |            1/2 |            2/3
Centaur  | Orc           |            1/2 |            2/3
Centaur  | Illithid      |            1/2 |            2/3
Nymph    | Cha > 14      |    1/3, 1/6, 0 |  3/4, 2/3, 3/5
Nymph    | Cha <= 14     |    1/2, 1/4, 0 |  3/5, 1/2, 3/7
Giant    | Human         |            2/3 |            3/4
Giant    | Dwarf         |            1/2 |            2/3

I also made an exception for selling things to illithid shopkeepers; to
prevent them from buying items from the player at a piddly 1/10 price,
they're excluded from this calculation and will buy items at regular
price. (They still charge a 10x or 20x markup on items they own.)
Due to bad string comparison logic attempting to compare the name of the
shopkeeper to Izchak (at that point in the function, the shopkeeper is
not yet named anyway). Make it so that every lighting store shopkeeper
in the Mines must be human; Izchak's is the only such shop.
@k21971 k21971 merged commit 368d669 into k21971:master Apr 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants