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

Fix invalid binary orbits, hyperjump streaks falling down, negative commodity demand #5794

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions data/libs/SpaceStation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,11 @@ function SpaceStation:AddCommodityStock(itemType, amount)
local market = self:GetCommodityMarket(itemType)

if amount < 0 then
market[1] = market[1] + amount
-- Buying from market - reduce commodity stock
market[1] = math.max(market[1] + amount, 0)
else
market[2] = market[2] - amount
-- Selling to market - reduce commodity demand
market[2] = math.max(market[2] - amount, 0)
end

Economy.UpdateCommodityPriceMod(assert(self:GetSystemBody()), itemType.name, market)
Expand Down
4 changes: 3 additions & 1 deletion src/Background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,9 @@ namespace Background {

const Sint32 numStars = buffer->GetDesc().numVertices / 2;

const vector3d pz = Pi::player->GetOrient().VectorZ(); //back vector
const vector3d oz = Pi::player->GetOrient().VectorZ(); //back vector in Y-up space
const vector3d pz = vector3d(oz.z, oz.x, oz.y); // back vector rotated into Z-up space

for (int i = 0; i < numStars; i++) {
vector3f v = m_hyperVtx[numStars * 2 + i] + vector3f(pz * hyperspaceProgress * mult);
const Color &c = m_hyperCol[numStars * 2 + i];
Expand Down
20 changes: 11 additions & 9 deletions src/galaxy/StarSystemGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,26 +391,28 @@ void StarSystemCustomGenerator::CustomGetKidsOf(RefCountedPtr<StarSystem::Genera
PROFILE_SCOPED()

// gravpoints have no mass, but we sum the masses of its children instead
if (parent->GetType() == SystemBody::TYPE_GRAVPOINT)
if (parent->GetType() == SystemBody::TYPE_GRAVPOINT) {
parent->m_mass = fixed(0);

// parent gravpoint mass = sum of masses of its children
for (const auto *child : children) {
if (child->bodyData.m_type > SystemBody::TYPE_GRAVPOINT && child->bodyData.m_type <= SystemBody::TYPE_STAR_MAX)
parent->m_mass += child->bodyData.m_mass;
else
parent->m_mass += child->bodyData.m_mass / SUN_MASS_TO_EARTH_MASS;
}
}

for (std::vector<CustomSystemBody *>::const_iterator i = children.begin(); i != children.end(); ++i) {
const CustomSystemBody *csbody = *i;

SystemBody *kid = system->NewBody();
kid->m_parent = parent;
kid->m_isCustomBody = true;

// Copy all system body parameters from the custom system body
*kid = csbody->bodyData;

// parent gravpoint mass = sum of masses of its children
if (parent->GetType() == SystemBody::TYPE_GRAVPOINT) {
if (kid->GetSuperType() == SystemBody::SUPERTYPE_STAR)
parent->m_mass += kid->m_mass;
else
parent->m_mass += kid->m_mass / SUN_MASS_TO_EARTH_MASS;
}

kid->SetOrbitFromParameters();
kid->SetAtmFromParameters();

Expand Down