Skip to content

Commit

Permalink
Merge pull request pioneerspacesim#5794 from Web-eWorks/microfixes
Browse files Browse the repository at this point in the history
Fix invalid binary orbits, hyperjump streaks falling down, negative commodity demand
  • Loading branch information
Webster Sheets authored Mar 14, 2024
2 parents 0dd3e4e + a509330 commit f62b38d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
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

0 comments on commit f62b38d

Please sign in to comment.