Skip to content

Commit 18545d0

Browse files
committed
document selling price
1 parent aba8311 commit 18545d0

File tree

8 files changed

+342
-31
lines changed

8 files changed

+342
-31
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [Base Price](./towns/ware-prices/base-price.md)
2424
- [Thresholds](./towns/ware-prices/thresholds.md)
2525
- [Buying Price](./towns/ware-prices/buying-price.md)
26+
- [Selling Price](./towns/ware-prices/selling-price.md)
2627
- [Shipyard](./towns/shipyard.md)
2728
- [Taxes](./towns/taxes.md)
2829
- [Tavern](./towns/tavern.md)
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
# Base Price
22
The `ware_base_prices` table at `0x00673A18` defines the following *base prices*:
33

4-
|Ware|Base Price|
5-
|-|-|
6-
|Grain|0.055000003|
7-
|Meat|0.47855002|
8-
|Fish|0.22005001|
9-
|Beer|0.17399999|
10-
|Salt|0.1425|
11-
|Honey|0.55000001|
12-
|Spices|1.4|
13-
|Wine|1.1|
14-
|Cloth|1.034|
15-
|Skins|3.3824999|
16-
|WhaleOil|0.41249999|
17-
|Timber|0.027500002|
18-
|IronGoods|1.278|
19-
|Leather|1.12|
20-
|Wool|0.44000003|
21-
|Pitch|0.278|
22-
|PigIron|0.44000003|
23-
|Hemp|0.22000001|
24-
|Pottery|0.85499996|
25-
|Bricks|0.039900005|
4+
|Ware|Base Price|Base Price per Barrel/Bundle|
5+
|-|-|-|
6+
|Grain|0.055000003|110.0|
7+
|Meat|0.47855002|957.1|
8+
|Fish|0.22005001|440.1|
9+
|Beer|0.17399999|34.8|
10+
|Salt|0.1425|28.45|
11+
|Honey|0.55000001|110.0|
12+
|Spices|1.4|280.0|
13+
|Wine|1.1|220.0|
14+
|Cloth|1.034|206.8|
15+
|Skins|3.3824999|676.5|
16+
|WhaleOil|0.41249999|82.5|
17+
|Timber|0.027500002|55.0|
18+
|IronGoods|1.278|255.6|
19+
|Leather|1.12|224.0|
20+
|Wool|0.44000003|880.0|
21+
|Pitch|0.278|55.6|
22+
|PigIron|0.44000003|880.0|
23+
|Hemp|0.22000001|440.0|
24+
|Pottery|0.85499996|171.0|
25+
|Bricks|0.039900005|79.8|
30.6 KB
Loading

src/towns/ware-prices/buying-price.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The price formula operates on 5 intervals, and the 4 price thresholds specify th
1010
|1|[\\(t\_0\\); \\(t\_1\\)]|
1111
|2|[\\(t\_1\\); \\(t\_2\\)]|
1212
|3|[\\(t\_2\\); \\(t\_3\\)]|
13-
|4|[\\(t\_3\\); \\(\inf\\)]|
13+
|4|[\\(t\_3\\); \\(\infty\\)]|
1414

1515
Within every interval \\(i\\) the price \\(p\_i\\) is defined as:
1616
\\[
@@ -27,8 +27,7 @@ where \\(w\_i\\) is the amount being bought from \\(i\\) and \\(f\\) is defined
2727
\end{aligned}
2828
\\]
2929

30-
where \\(w\_{relative\\_stock}\\) and \\(w\_{relative\\_remain}\\) are the stock's and remainder's offsets in the interval
31-
and \\(m\_i\\) and \\(v\_i\\) are defined as:
30+
where \\(w\_{relative\\_stock}\\) and \\(w\_{relative\\_remain}\\) are the stock's and remainder's offsets in the interval and \\(m\_i\\) and \\(v\_i\\) are defined as:
3231

3332
|Bracket|\\(m\_i\\)|\\(v\_i\\)|
3433
|-|-|-|
@@ -38,11 +37,10 @@ and \\(m\_i\\) and \\(v\_i\\) are defined as:
3837
|3|0.8|0.2|
3938

4039
## Example
41-
Let's assume we buy pig iron from a town with the following stock and thresholds:
40+
Let's assume we buy pig iron from a town with the following thresholds:
4241

4342
|Threshold|Value|
4443
|-|-|
45-
|Stock|110000|
4644
|t0|20000|
4745
|t1|60000|
4846
|t2|70000|

src/towns/ware-prices/buying-price.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,51 @@ def plot_example1():
110110
plt.savefig("buying-price-pigiron.png", dpi=150)
111111

112112

113+
def plot_factor():
114+
plt.clf()
115+
params = {"mathtext.default": "regular"}
116+
plt.rcParams.update(params)
117+
fig, (ax1) = plt.subplots(1, 1)
118+
119+
# Intervals
120+
left = 0
121+
for i in range(0, len(SAMPLE_THRESHOLDS)):
122+
t = SAMPLE_THRESHOLDS[i]
123+
bar = ax1.barh(0, t - left, 1, left=left, label=f"Interval {i}")
124+
left += t - left
125+
126+
# Stock
127+
stock = 50_000
128+
ax1.barh(-1, stock, 1, label=f"Stock")
129+
130+
# Buying
131+
buy = 20_000
132+
ax1.barh(-2, buy, 1, left=stock - buy, label=f"Buy")
133+
134+
ax1.barh(
135+
-3,
136+
stock - SAMPLE_THRESHOLDS[0],
137+
1,
138+
left=SAMPLE_THRESHOLDS[0],
139+
label=f"Relative Stock",
140+
)
141+
ax1.barh(
142+
-4,
143+
stock - buy - SAMPLE_THRESHOLDS[0],
144+
1,
145+
left=SAMPLE_THRESHOLDS[0],
146+
label=f"Relative Remain",
147+
)
148+
149+
ax1.set_yticks(
150+
[0, -1, -2, -3, -4],
151+
labels=["Intervals", "Stock", "Buy", "Relative Stock", "Relative Remain"],
152+
)
153+
ax1.set_ylim([-10, 1.5])
154+
plt.tight_layout()
155+
plt.savefig("buying-price-factor.png", dpi=200)
156+
157+
113158
def tests():
114159
stock = 2_000
115160
buy_amount = 1 * 2000
@@ -158,10 +203,14 @@ def tests():
158203

159204

160205
logging.basicConfig()
161-
tests()
162206
logging.getLogger().setLevel(logging.INFO)
207+
tests()
163208
plot_example1()
164-
logging.getLogger().setLevel(logging.DEBUG)
165-
LOGGER.info("success!")
209+
plot_factor()
210+
166211

167-
LOGGER.debug(get_price(22_000, 2_000, SAMPLE_THRESHOLDS, PIG_IRON_BASE_PRICE))
212+
stock = 6600
213+
buy_amount = 1 * 200
214+
t2 = [1000, 2000, 3000, 4000]
215+
price = get_price(stock, buy_amount, t2, 1.4)
216+
print(price)
56 KB
Loading
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Selling Price
2+
The `get_sell_price` function at `0x0052E1D0` takes a pointer to a class containing the mapped trade difficulty setting, a ware, town, and sell amount and returns the transaction price.
3+
4+
## Formula
5+
The price formula operates on 5 intervals, and the 4 price thresholds specify the bounds.
6+
7+
|Interval|Bounds|
8+
|-|-|
9+
|0|[0; \\(t\_0\\)]|
10+
|1|[\\(t\_0\\); \\(t\_1\\)]|
11+
|2|[\\(t\_1\\); \\(t\_2\\)]|
12+
|3|[\\(t\_2\\); \\(t\_3\\)]|
13+
|4|[\\(t\_3\\); \\(\infty\\)]|
14+
15+
Within every interval \\(i\\) the price \\(p\_i\\) is defined as:
16+
\\[
17+
\begin{aligned}
18+
p\_{i} &= p\_{base} * w\_{i} * f\_{i}
19+
\end{aligned}
20+
\\]
21+
22+
where \\(w\_i\\) is the amount being sold to \\(i\\) and \\(f\\) is defined as:
23+
\\[
24+
\begin{aligned}
25+
f\_4 &= 0.5\\\\
26+
f\_{i} &= m_i - v_i \underbrace{\frac{w\_{relative\\_stock} + w\_{relative\\_new\\_stock}}{2 * \text{interval_width}}}\_{\in [0; 1]}\\\\
27+
f\_0 &= d\_{trade\\_difficulty} - (v\_i - d\_{trade\\_difficulty}) \underbrace{\frac{w\_{relative\\_stock} + w\_{relative\\_new\\_stock}}{2 * \text{interval_width}}}\_{\in [0; 1]}
28+
\end{aligned}
29+
\\]
30+
31+
where \\(w\_{relative\\_stock}\\) and \\(w\_{relative\\_new\\_stock}\\) are the stock's and new stock's offsets in the interval and \\(m\_i\\) and \\(v\_i\\) are defined as:
32+
33+
|Bracket|\\(m\_i\\)|\\(v\_i\\)|
34+
|-|-|-|
35+
|0|NaN|1.4|
36+
|1|1.4|0.4|
37+
|2|1.0|0.3|
38+
|3|0.7|0.2|
39+
40+
and \\(d\_{trade\\_difficulty}\\) is defined as:
41+
42+
|Difficulty|Value|
43+
|-|-|
44+
|0 (low)|2.2|
45+
|1 (normal)|2.0|
46+
|2 (high)|1.8|
47+
48+
49+
## Example
50+
Let's assume we sell pig iron to a town with the following thresholds:
51+
52+
|Threshold|Value|
53+
|-|-|
54+
|t0|20000|
55+
|t1|60000|
56+
|t2|70000|
57+
|t3|80000|
58+
59+
If we sell one bundle (2000), the resulting prices at different stock levels would be:
60+
![image](selling-price-pigiron.png)

0 commit comments

Comments
 (0)