Merge pull request #4135 from Mughur/corp

CORPORATION: FIX #3880, #3876, #3322 and #3138 Bunch of corporation fixes
This commit is contained in:
hydroflame 2022-09-23 12:35:11 -03:00 committed by GitHub
commit cbe31fa63f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 23 deletions

@ -1,6 +1,8 @@
import { Player } from "../Player";
import { IPlayer } from "src/PersonObjects/IPlayer"; import { IPlayer } from "src/PersonObjects/IPlayer";
import { MaterialSizes } from "./MaterialSizes"; import { MaterialSizes } from "./MaterialSizes";
import { ICorporation } from "./ICorporation"; import { ICorporation } from "./ICorporation";
import { Corporation } from "./Corporation";
import { IIndustry } from "./IIndustry"; import { IIndustry } from "./IIndustry";
import { IndustryStartingCosts, IndustryResearchTrees } from "./IndustryData"; import { IndustryStartingCosts, IndustryResearchTrees } from "./IndustryData";
import { Industry } from "./Industry"; import { Industry } from "./Industry";
@ -463,6 +465,23 @@ export function Research(division: IIndustry, researchName: string): void {
// Get the Node from the Research Tree and set its 'researched' property // Get the Node from the Research Tree and set its 'researched' property
researchTree.research(researchName); researchTree.research(researchName);
division.researched[researchName] = true; division.researched[researchName] = true;
// I couldn't figure out where else to put this so that warehouse size would get updated instantly
// whether research is done by script or UI. All other stats gets calculated in every cycle
// Warehouse size gets updated only when something increases it.
if (researchName == "Drones - Transport") {
for (let i = 0; i < CorporationConstants.Cities.length; ++i) {
const city = CorporationConstants.Cities[i];
const warehouse = division.warehouses[city];
if (!(warehouse instanceof Warehouse)) {
continue;
}
if (Player.corporation instanceof Corporation) {
// Stores cycles in a "buffer". Processed separately using Engine Counters
warehouse.updateSize(Player.corporation, division);
}
}
}
} }
export function ExportMaterial( export function ExportMaterial(

@ -83,6 +83,10 @@ export class Corporation {
const gameCycles = marketCycles * CorporationConstants.CyclesPerIndustryStateCycle; const gameCycles = marketCycles * CorporationConstants.CyclesPerIndustryStateCycle;
this.storedCycles -= gameCycles; this.storedCycles -= gameCycles;
this.divisions.forEach((ind) => {
ind.resetImports(state);
});
this.divisions.forEach((ind) => { this.divisions.forEach((ind) => {
ind.process(marketCycles, state, this); ind.process(marketCycles, state, this);
}); });
@ -230,6 +234,7 @@ export class Corporation {
let sharePrice = this.sharePrice; let sharePrice = this.sharePrice;
let sharesSold = 0; let sharesSold = 0;
let profit = 0; let profit = 0;
let targetPrice = this.getTargetSharePrice();
const maxIterations = Math.ceil(numShares / CorporationConstants.SHARESPERPRICEUPDATE); const maxIterations = Math.ceil(numShares / CorporationConstants.SHARESPERPRICEUPDATE);
if (isNaN(maxIterations) || maxIterations > 10e6) { if (isNaN(maxIterations) || maxIterations > 10e6) {
@ -249,9 +254,13 @@ export class Corporation {
sharesUntilUpdate = CorporationConstants.SHARESPERPRICEUPDATE; sharesUntilUpdate = CorporationConstants.SHARESPERPRICEUPDATE;
sharesTracker -= sharesUntilUpdate; sharesTracker -= sharesUntilUpdate;
sharesSold += sharesUntilUpdate; sharesSold += sharesUntilUpdate;
targetPrice = this.valuation / (2 * (this.totalShares + sharesSold - this.numShares));
// Calculate what new share price would be // Calculate what new share price would be
sharePrice = this.valuation / (2 * (this.totalShares + sharesSold - this.numShares)); if (sharePrice <= targetPrice) {
sharePrice *= 1 + 0.5 * 0.01;
} else {
sharePrice *= 1 - 0.5 * 0.01;
}
} }
} }

@ -54,6 +54,7 @@ export interface IIndustry {
processMaterials(marketCycles: number, corporation: ICorporation): [number, number]; processMaterials(marketCycles: number, corporation: ICorporation): [number, number];
processProducts(marketCycles: number, corporation: ICorporation): [number, number]; processProducts(marketCycles: number, corporation: ICorporation): [number, number];
processProduct(marketCycles: number, product: Product, corporation: ICorporation): number; processProduct(marketCycles: number, product: Product, corporation: ICorporation): number;
resetImports(state: string): void;
discontinueProduct(product: Product): void; discontinueProduct(product: Product): void;
getAdVertCost(): number; getAdVertCost(): number;
applyAdVert(corporation: ICorporation): void; applyAdVert(corporation: ICorporation): void;

@ -523,24 +523,6 @@ export class Industry implements IIndustry {
expenses = 0; expenses = 0;
this.calculateProductionFactors(); this.calculateProductionFactors();
//At the start of the export state, set the imports of everything to 0
if (this.state === "EXPORT") {
for (let i = 0; i < CorporationConstants.Cities.length; ++i) {
const city = CorporationConstants.Cities[i];
if (!(this.warehouses[city] instanceof Warehouse)) {
continue;
}
const warehouse = this.warehouses[city];
if (warehouse === 0) continue;
for (const matName of Object.keys(warehouse.materials)) {
if (warehouse.materials.hasOwnProperty(matName)) {
const mat = warehouse.materials[matName];
mat.imp = 0;
}
}
}
}
for (let i = 0; i < CorporationConstants.Cities.length; ++i) { for (let i = 0; i < CorporationConstants.Cities.length; ++i) {
const city = CorporationConstants.Cities[i]; const city = CorporationConstants.Cities[i];
const office = this.offices[city]; const office = this.offices[city];
@ -1236,6 +1218,26 @@ export class Industry implements IIndustry {
return totalProfit; return totalProfit;
} }
resetImports(state: string): void {
//At the start of the export state, set the imports of everything to 0
if (state === "EXPORT") {
for (let i = 0; i < CorporationConstants.Cities.length; ++i) {
const city = CorporationConstants.Cities[i];
if (!(this.warehouses[city] instanceof Warehouse)) {
continue;
}
const warehouse = this.warehouses[city];
if (warehouse === 0) continue;
for (const matName of Object.keys(warehouse.materials)) {
if (warehouse.materials.hasOwnProperty(matName)) {
const mat = warehouse.materials[matName];
mat.imp = 0;
}
}
}
}
}
discontinueProduct(product: Product): void { discontinueProduct(product: Product): void {
for (const productName of Object.keys(this.products)) { for (const productName of Object.keys(this.products)) {
if (this.products.hasOwnProperty(productName)) { if (this.products.hasOwnProperty(productName)) {

@ -110,7 +110,7 @@ export function IssueNewSharesModal(props: IProps): React.ReactElement {
You can issue new equity shares (i.e. stocks) in order to raise capital for your corporation. You can issue new equity shares (i.e. stocks) in order to raise capital for your corporation.
<br /> <br />
<br /> <br />
&nbsp;* You can issue at most {numeralWrapper.formatMoney(maxNewShares)} new shares &nbsp;* You can issue at most {numeralWrapper.format(maxNewShares, "0.000a")} new shares
<br /> <br />
&nbsp;* New shares are sold at a 10% discount &nbsp;* New shares are sold at a 10% discount
<br /> <br />

@ -7140,7 +7140,7 @@ interface CorporationInfo {
numShares: number; numShares: number;
/** Cooldown until shares can be sold again */ /** Cooldown until shares can be sold again */
shareSaleCooldown: number; shareSaleCooldown: number;
/** Amount of shares issued */ /** Amount of aqcuirable shares. */
issuedShares: number; issuedShares: number;
/** Price of the shares */ /** Price of the shares */
sharePrice: number; sharePrice: number;

@ -125,7 +125,9 @@ export function TerminalRoot({ terminal, router, player }: IProps): React.ReactE
paragraph={false} paragraph={false}
onClick={() => terminal.connectToServer(player, item.hostname)} onClick={() => terminal.connectToServer(player, item.hostname)}
> >
<Typography sx={{ textDecoration: 'underline', "&:hover": { textDecoration: 'none'} }}>{item.hostname}</Typography> <Typography sx={{ textDecoration: "underline", "&:hover": { textDecoration: "none" } }}>
{item.hostname}
</Typography>
</MuiLink> </MuiLink>
</> </>
)} )}