rename GetPositionAfterHyperspace to GetHyperspaceExitPoint and make it use the current space as the dest

master
Robert Norris 2011-11-16 09:02:05 +11:00
parent 9b54a32f01
commit 701040bd85
4 changed files with 21 additions and 12 deletions

View File

@ -133,7 +133,9 @@ static int l_space_spawn_ship(lua_State *l)
if (path == NULL)
thing->SetPosition(MathUtil::RandomPointOnSphere(min_dist, max_dist)*AU);
else
thing->SetPosition(Space::GetPositionAfterHyperspace(path, &(Pi::spaceManager->GetSpace()->GetStarSystem()->GetPath())));
// XXX broken. this is ignoring min_dist & max_dist. otoh, what's the
// correct behaviour given there's now a fixed hyperspace exit point?
thing->SetPosition(Pi::spaceManager->GetSpace()->GetHyperspaceExitPoint(*path));
thing->SetVelocity(vector3d(0,0,0));
Pi::spaceManager->GetSpace()->AddBody(thing);

View File

@ -112,14 +112,22 @@ void Space::DoECM(const Frame *f, const vector3d &pos, int power_val)
}
}
vector3d Space::GetPositionAfterHyperspace(const SystemPath *source, const SystemPath *dest)
vector3d Space::GetHyperspaceExitPoint(const SystemPath &source)
{
Sector source_sec(source->sectorX,source->sectorY,source->sectorZ);
Sector dest_sec(dest->sectorX,dest->sectorY,dest->sectorZ);
Sector::System source_sys = source_sec.m_systems[source->systemIndex];
Sector::System dest_sys = dest_sec.m_systems[dest->systemIndex];
const vector3d sourcePos = vector3d(source_sys.p) + vector3d(source->sectorX, source->sectorY, source->sectorZ);
const vector3d destPos = vector3d(dest_sys.p) + vector3d(dest->sectorX, dest->sectorY, dest->sectorZ);
assert(m_starSystem);
assert(source.IsSystemPath());
const SystemPath &dest = m_starSystem->GetPath();
Sector source_sec(source.sectorX, source.sectorY, source.sectorZ);
Sector dest_sec(dest.sectorX, dest.sectorY, dest.sectorZ);
Sector::System source_sys = source_sec.m_systems[source.systemIndex];
Sector::System dest_sys = dest_sec.m_systems[dest.systemIndex];
const vector3d sourcePos = vector3d(source_sys.p) + vector3d(source.sectorX, source.sectorY, source.sectorZ);
const vector3d destPos = vector3d(dest_sys.p) + vector3d(dest.sectorX, dest.sectorY, dest.sectorZ);
return (sourcePos - destPos).Normalized() * 11.0*AU + MathUtil::RandomPointOnSphere(5.0,20.0)*1000.0; // "hyperspace zone": 11 AU from primary
}

View File

@ -37,8 +37,7 @@ public:
void TimeStep(float step);
// XXX these do not belong here
static vector3d GetPositionAfterHyperspace(const SystemPath *source, const SystemPath *dest);
vector3d GetHyperspaceExitPoint(const SystemPath &source);
// XXX these may belong elsewhere
void RadiusDamage(Body *attacker, Frame *f, const vector3d &pos, double radius, double kgDamage);

View File

@ -200,7 +200,7 @@ void SpaceManager::SwitchToNormalSpace()
m_space->AddBody(m_player);
// place it
m_player->SetPosition(m_space->GetPositionAfterHyperspace(&m_hyperspaceSource, &dest));
m_player->SetPosition(m_space->GetHyperspaceExitPoint(m_hyperspaceSource));
m_player->SetVelocity(vector3d(0,0,-100.0));
m_player->SetRotMatrix(matrix4x4d::Identity());
@ -214,7 +214,7 @@ void SpaceManager::SwitchToNormalSpace()
cloud = *i;
cloud->SetFrame(m_space->GetRootFrame());
cloud->SetPosition(m_space->GetPositionAfterHyperspace(&m_hyperspaceSource, &dest));
cloud->SetPosition(m_space->GetHyperspaceExitPoint(m_hyperspaceSource));
m_space->AddBody(cloud);