CORPORATION: Refactor markup multiplier (#1362)

This commit is contained in:
catloversg 2024-06-07 13:10:16 +07:00 committed by GitHub
parent 481938a2fb
commit 7b3cf48453
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 30 deletions

@ -15,6 +15,7 @@ import { JSONMap, JSONSet } from "../Types/Jsonable";
import { PartialRecord, getRecordEntries, getRecordKeys, getRecordValues } from "../Types/Record"; import { PartialRecord, getRecordEntries, getRecordKeys, getRecordValues } from "../Types/Record";
import { Material } from "./Material"; import { Material } from "./Material";
import { getKeyList } from "../utils/helpers/getKeyList"; import { getKeyList } from "../utils/helpers/getKeyList";
import { calculateMarkupMultiplier } from "./helpers";
interface DivisionParams { interface DivisionParams {
name: string; name: string;
@ -582,26 +583,13 @@ export class Division {
} }
mat.uiMarketPrice = sCost; mat.uiMarketPrice = sCost;
// Calculate how much of the material sells (per second) const markupMultiplier = calculateMarkupMultiplier(sCost, mat.marketPrice, markupLimit);
let markup = 1;
if (sCost > mat.marketPrice) {
//Penalty if difference between sCost and bCost is greater than markup limit
if (sCost - mat.marketPrice > markupLimit) {
markup = Math.pow(markupLimit / (sCost - mat.marketPrice), 2);
}
} else if (sCost < mat.marketPrice) {
if (sCost <= 0) {
markup = 1e12; //Sell everything, essentially discard
} else {
//Lower prices than market increases sales
markup = mat.marketPrice / sCost;
}
}
// Calculate how much of the material sells (per second)
mat.maxSellPerCycle = mat.maxSellPerCycle =
(mat.quality + 0.001) * (mat.quality + 0.001) *
marketFactor * marketFactor *
markup * markupMultiplier *
businessFactor * businessFactor *
corporation.getSalesMult() * corporation.getSalesMult() *
advertisingFactor * advertisingFactor *
@ -920,21 +908,15 @@ export class Division {
sCost = sellPrice; sCost = sellPrice;
} }
product.uiMarketPrice[city] = sCost; product.uiMarketPrice[city] = sCost;
let markup = 1;
if (sCost > product.cityData[city].productionCost) { const markupMultiplier = calculateMarkupMultiplier(sCost, product.cityData[city].productionCost, markupLimit);
if (sCost - product.cityData[city].productionCost > markupLimit) {
markup = markupLimit / (sCost - product.cityData[city].productionCost);
}
} else if (sCost <= 0) {
markup = 1e12; //Sell everything, essentially discard - as materials
}
product.maxSellAmount = product.maxSellAmount =
0.5 * 0.5 *
Math.pow(product.cityData[city].effectiveRating, 0.65) * Math.pow(product.cityData[city].effectiveRating, 0.65) *
marketFactor * marketFactor *
corporation.getSalesMult() * corporation.getSalesMult() *
Math.pow(markup, 2) * markupMultiplier *
businessFactor * businessFactor *
advertisingFactor * advertisingFactor *
this.getSalesMultiplier(); this.getSalesMultiplier();

@ -88,3 +88,26 @@ export function issueNewSharesFailureReason(corp: Corporation, numShares: number
return ""; return "";
} }
export function calculateMarkupMultiplier(sellingPrice: number, marketPrice: number, markupLimit: number): number {
// Sanitize sellingPrice
if (!Number.isFinite(sellingPrice)) {
return 1;
}
let markupMultiplier = 1;
if (sellingPrice > marketPrice) {
// markupMultiplier is a penalty modifier if sellingPrice is greater than the sum of marketPrice and markupLimit.
if (sellingPrice > marketPrice + markupLimit) {
markupMultiplier = Math.pow(markupLimit / (sellingPrice - marketPrice), 2);
}
} else {
if (sellingPrice <= 0) {
// Discard
markupMultiplier = 1e12;
} else {
// markupMultiplier is a bonus modifier if sellingPrice is less than marketPrice.
markupMultiplier = marketPrice / sellingPrice;
}
}
return markupMultiplier;
}

@ -63,12 +63,13 @@ $$MarketFactor = Max\left(0.1,{Demand\ast(100 - Competition)}\ast{0.01}\right)$$
- Division's research bonus: this is always 1. Currently there is not any research that increases the sales bonus. - Division's research bonus: this is always 1. Currently there is not any research that increases the sales bonus.
- `MarkupMultiplier`: initialize with 1. - `MarkupMultiplier`: initialize with 1.
- `SellingPrice` is the selling price that you set. - `SellingPrice` is the selling price that you set.
- With materials, if we set `SellingPrice` to 0, `MarkupMultiplier` is $10^{12}$ (check the formula below). Extremely high `MarkupMultiplier` means that we can sell all units, regardless of other factors. This is the fastest way to discard materials. - If we set `SellingPrice` to 0 or a negative number, `MarkupMultiplier` is $10^{12}$ (check the formula below). With an extremely high `MarkupMultiplier`, we can sell all units, regardless of other factors. This is the fastest way to discard stored units.
- If `(SellingPrice > MarketPrice + MarkupLimit)`: - If `(SellingPrice > MarketPrice)`:
$$MarkupMultiplier = \left(\frac{MarkupLimit}{SellingPrice - MarketPrice}\right)^{2}$$ - If `(SellingPrice > MarketPrice + MarkupLimit)`:
- If item is material and `SellingPrice` is less than `MarketPrice`: $$MarkupMultiplier = \left(\frac{MarkupLimit}{SellingPrice - MarketPrice}\right)^{2}$$
- If `(SellingPrice <= MarketPrice)`:
$$MarkupMultiplier = \begin{cases}\frac{MarketPrice}{SellingPrice}, & SellingPrice > 0 \land SellingPrice < MarketPrice \newline 10^{12}, & SellingPrice \leq 0 \end{cases}$$ $$MarkupMultiplier = \begin{cases}\frac{MarketPrice}{SellingPrice}, & SellingPrice > 0 \newline 10^{12}, & SellingPrice \leq 0 \end{cases}$$
## Optimal selling price ## Optimal selling price