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

Econ 2.0 Buildings #572

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open

Conversation

gawquon
Copy link
Member

@gawquon gawquon commented Aug 17, 2024


Demand Building Component

  • Load employment from PMs (Already did, thanks past me.)
  • Load input/output goods from PMs
  • Use average weight of PMs from EconManager config file. (Country by country basis)
  • Predict ownership PMs based on country laws.
  • Track available workers and Subsistence space.
  • Track Jobs% and Culture% when building.
  • Resolves a building's PMGroups to building's average net input/output/jobs.
  • Add in supply created/lost by subsistence building.

Balancing - Next PR

- [ ] Have demand be primary factor, but allow the other weights to punch through at times.
- [ ] Add function to generate extra arable land for extra pop.
- [ ] Check additional bureaucracy cost incurred by nationalization, supplementary admin round if needed.

Jobs

  • Use working ratios to hire/fire the right number of workers + dependents
  • Initialize the starting jobs in a country substate by substate. Subsistence Buildings, Manor Houses, and unemployed.
  • Predict PM's based on laws. (Serfdom vs Homesteading, etc.)
  • Peg loss of peasants to subsequent job loss in Manor Houses (Send them to unemployed)

Buildings

  • Track Economies of scale for everything except subsistence, capped by tech.
  • Load State modifiers from State traits. Match the building to a trait.
  • Match Output Goods to any state trait
  • Add Urban Centers alongside ownership calcs
  • Integrate Hardcoded buildings (Ports and Gov. Admins) into the market.
  • (Optional): Use ownership estimations to modify the throughput Economies of scale

Debug

  • Make a formatted table output for the Market
  • Make a formatted table output for Culture and Job maps.

Ownership

  • Resolve ownership rules to estimates on the number of Manor Houses / Financial Districts

@gawquon gawquon changed the title Estimate PM prevalences Econ 2.0 Buildings Aug 17, 2024
@gawquon gawquon marked this pull request as ready for review October 21, 2024 22:05
@gawquon gawquon requested a review from Zemurin as a code owner October 21, 2024 22:05
Copy link
Member

@Zemurin Zemurin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly semantics, looks very very good overall. I'm sure Idhrendur will find tons more though.

}
for (const auto& type: investorWeights | std::views::keys)
{
investorWeights[type] /= totalWeight;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a recognized country starting with no investors thus totalWeight = 0? Maybe some peasant republic going full communist or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those would be "national" or "local" investors. Also this function is turning the weights from configurbales/economy/ownership.txt into fractions on a country by country basis. I've refactored a couple things to hopefully paint a clearer picture there.

Copy link
Member

@Idhrendur Idhrendur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm about 29% through, will continue in the coming days. For the future, when you've got bits fairly stable, it doesn't hurt to spin them off into smaller PRs so we can review and approve faster.

Copy link
Member

@Idhrendur Idhrendur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

86% reviewed

Copy link
Member

@Idhrendur Idhrendur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the pause, 90% reviewed.

@Idhrendur Idhrendur self-requested a review November 13, 2024 16:17
auto sub0 = std::make_shared<V3::SubState>();
auto sub1 = std::make_shared<V3::SubState>();

V3::Pop pop0, pop1, pop2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more clear (and fewer lines) to use the constructor:

Suggested change
V3::Pop pop0, pop1, pop2;
V3:Pop pop0("english", "", "", 1000);
V3:Pop pop1("german", "", "", 500);
V3:Pop pop1("english", "", "", 500);

@@ -333,4 +366,106 @@ TEST(V3World_CountryTests, YearCapFactorHitsCurve)
EXPECT_NEAR(0.3, V3::Country::yearCapFactor(date("1650.1.1")), 0.015);
EXPECT_NEAR(0.2, V3::Country::yearCapFactor(date("1490.1.1")), 0.01);
EXPECT_NEAR(0.15, V3::Country::yearCapFactor(date("1350.1.1")), 0.01);
}

TEST(V3World_CountryTests, HasAnyOfLawUnlockingPositiveCase)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TEST(V3World_CountryTests, HasAnyOfLawUnlockingPositiveCase)
TEST(V3World_CountryTests, HasAnyOfLawUnlockingIsTrueIfAnyOfLawsArePresent)

EXPECT_TRUE(country.hasAnyOfLawUnlocking({"law_2", "law_3"}));
}

TEST(V3World_CountryTests, HasAnyOfLawUnlockingNegativeCase)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TEST(V3World_CountryTests, HasAnyOfLawUnlockingNegativeCase)
TEST(V3World_CountryTests, HasAnyOfLawUnlockingFalseIfNoneOfLawsPresent)

EXPECT_FALSE(country.hasAnyOfLawUnlocking({"law_1", "law_5"}));
}

TEST(V3World_CountryTests, HasAnyOfLawBlockingPositiveCase)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TEST(V3World_CountryTests, HasAnyOfLawBlockingPositiveCase)
TEST(V3World_CountryTests, HasAnyOfLawBlockingTrueIfAnyOfLawsArePresent)

EXPECT_TRUE(country.hasAnyOfLawBlocking({"law_2", "law_3"}));
}

TEST(V3World_CountryTests, HasAnyOfLawBlockingNegativeCase)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TEST(V3World_CountryTests, HasAnyOfLawBlockingNegativeCase)
TEST(V3World_CountryTests, HasAnyOfLawBlockingFalseIfNoneOfLawsPresent)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to write tests here, as much as possible.

@@ -89,34 +94,44 @@ class EconomyManager
[[nodiscard]] double calculateStateTraitMultiplier(const std::shared_ptr<SubState>& subState) const;
[[nodiscard]] double getDensityFactor(double perCapitaDev) const;

void establishBureaucracy(const std::shared_ptr<Country>& country, const std::map<std::string, Law>& lawsMap, const Vic3DefinesLoader& defines) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void establishBureaucracy(const std::shared_ptr<Country>& country, const std::map<std::string, Law>& lawsMap, const Vic3DefinesLoader& defines) const;
void establishBureaucracy(const Country& country, const std::map<std::string, Law>& lawsMap, const Vic3DefinesLoader& defines) const;

You're not taking (shared) ownership of the country, so just take a reference to it.

@@ -89,34 +94,44 @@ class EconomyManager
[[nodiscard]] double calculateStateTraitMultiplier(const std::shared_ptr<SubState>& subState) const;
[[nodiscard]] double getDensityFactor(double perCapitaDev) const;

void establishBureaucracy(const std::shared_ptr<Country>& country, const std::map<std::string, Law>& lawsMap, const Vic3DefinesLoader& defines) const;
void hardcodePorts(const std::shared_ptr<Country>& country) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void hardcodePorts(const std::shared_ptr<Country>& country) const;
void hardcodePorts(const Country& country) const;

Ditto.

{
for (const auto& subState: country->getSubStates())
{
for (const auto& building: subState->getBuildings())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you getting a shared_ptr to a building? Maybe see if you can dereference it immediately in the loop construct.

@@ -89,34 +94,44 @@ class EconomyManager
[[nodiscard]] double calculateStateTraitMultiplier(const std::shared_ptr<SubState>& subState) const;
[[nodiscard]] double getDensityFactor(double perCapitaDev) const;

void establishBureaucracy(const std::shared_ptr<Country>& country, const std::map<std::string, Law>& lawsMap, const Vic3DefinesLoader& defines) const;
void hardcodePorts(const std::shared_ptr<Country>& country) const;
void integrateHardcodedBuildings(const std::shared_ptr<Country>& country,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void integrateHardcodedBuildings(const std::shared_ptr<Country>& country,
void integrateHardcodedBuildings(const Country& country,

Ditto

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.

3 participants