Skip to content

Commit 34818b5

Browse files
committed
Ensure binary stars are in sensible orbits
1 parent 1ddd315 commit 34818b5

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/galaxy/CustomSystem.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,30 @@ void CustomSystemsDatabase::RunLuaSystemSanityChecks(CustomSystem *csys)
11061106
body->bodyData.m_volatileGas = rand.NormFixed(fixed(1050, 1000), fixed(8000, 1000)).Abs();
11071107
body->bodyData.m_atmosOxidizing = rand.NormFixed(fixed(0, 1), fixed(300, 1000)).Abs();
11081108
}
1109+
}
1110+
1111+
// This loop runs after the one above, to ensure that system bodies are all set up first.
1112+
// Now we ensure that any binary star systems have orbits set correctly.
1113+
for (CustomSystemBody *body : csys->bodies) {
1114+
1115+
if ((body->bodyData.m_type == SystemBody::TYPE_GRAVPOINT) && (body->children.size() == 2)) {
1116+
SystemBodyData *star_A = &body->children[0]->bodyData;
1117+
SystemBodyData *star_B = &body->children[1]->bodyData;
1118+
1119+
if ((star_A->m_type >= SystemBodyType::TYPE_STAR_MIN) && (star_A->m_type <= SystemBodyType::TYPE_STAR_MAX) &&
1120+
(star_B->m_type >= SystemBodyType::TYPE_STAR_MIN) && (star_B->m_type <= SystemBodyType::TYPE_STAR_MAX)) {
11091121

1122+
// This is a binary star system. Ensure that the stars are opposite each other in their orbits
1123+
1124+
star_B->m_orbitalOffset = star_A->m_orbitalOffset;
1125+
star_B->m_inclination = star_A->m_inclination;
1126+
star_B->m_argOfPeriapsis = star_A->m_argOfPeriapsis;
1127+
1128+
star_B->m_orbitalPhaseAtStart = star_A->m_orbitalPhaseAtStart + FIXED_PI;
1129+
if (star_B->m_orbitalPhaseAtStart > fixed(2, 1) * FIXED_PI)
1130+
star_B->m_orbitalPhaseAtStart -= fixed(2, 1) * FIXED_PI;
1131+
}
1132+
}
11101133
}
11111134
}
11121135

0 commit comments

Comments
 (0)