本文整理汇总了C++中SystemPath::IsBodyPath方法的典型用法代码示例。如果您正苦于以下问题:C++ SystemPath::IsBodyPath方法的具体用法?C++ SystemPath::IsBodyPath怎么用?C++ SystemPath::IsBodyPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SystemPath
的用法示例。
在下文中一共展示了SystemPath::IsBodyPath方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: l_sbodypath_attr_body_index
/*
* Attribute: bodyIndex
*
* The body index component of the path, or nil if the SystemPath does
* not point to a body.
*
* Availability:
*
* alpha 10
*
* Status:
*
* stable
*/
static int l_sbodypath_attr_body_index(lua_State *l)
{
SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1);
if (path->IsBodyPath())
lua_pushinteger(l, path->bodyIndex);
else
lua_pushnil(l);
return 1;
}
示例2: InvalidGameStartLocation
Game::Game(const SystemPath &path, double time) :
m_galaxy(GalaxyGenerator::Create()),
m_time(time),
m_state(STATE_NORMAL),
m_wantHyperspace(false),
m_timeAccel(TIMEACCEL_1X),
m_requestedTimeAccel(TIMEACCEL_1X),
m_forceTimeAccel(false)
{
// Now that we have a Galaxy, check the starting location
if (!path.IsBodyPath())
throw InvalidGameStartLocation("SystemPath is not a body path");
RefCountedPtr<const Sector> s = m_galaxy->GetSector(path);
if (size_t(path.systemIndex) >= s->m_systems.size()) {
char buf[128];
std::sprintf(buf, "System %u in sector <%d,%d,%d> does not exist",
unsigned(path.systemIndex), int(path.sectorX), int(path.sectorY), int(path.sectorZ));
throw InvalidGameStartLocation(std::string(buf));
}
RefCountedPtr<StarSystem> sys = m_galaxy->GetStarSystem(path);
if (path.bodyIndex >= sys->GetNumBodies()) {
char buf[256];
std::sprintf(buf, "Body %d in system <%d,%d,%d : %d ('%s')> does not exist", unsigned(path.bodyIndex),
int(path.sectorX), int(path.sectorY), int(path.sectorZ), unsigned(path.systemIndex), sys->GetName().c_str());
throw InvalidGameStartLocation(std::string(buf));
}
m_space.reset(new Space(this, m_galaxy, path));
Body *b = m_space->FindBodyForPath(&path);
assert(b);
m_player.reset(new Player("kanara"));
m_space->AddBody(m_player.get());
m_player->SetFrame(b->GetFrame());
if (b->GetType() == Object::SPACESTATION) {
m_player->SetDockedWith(static_cast<SpaceStation*>(b), 0);
} else {
const SystemBody *sbody = b->GetSystemBody();
m_player->SetPosition(vector3d(0, 1.5*sbody->GetRadius(), 0));
m_player->SetVelocity(vector3d(0,0,0));
}
Polit::Init(m_galaxy);
CreateViews();
EmitPauseState(IsPaused());
}
示例3: l_sbodypath_meta_tostring
static int l_sbodypath_meta_tostring(lua_State *l)
{
SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1);
if (path->IsSectorPath()) {
lua_pushfstring(l, "<%d,%d,%d>", path->sectorX, path->sectorY, path->sectorZ);
} else if (path->IsSystemPath()) {
lua_pushfstring(l, "<%d,%d,%d : %d>",
path->sectorX, path->sectorY, path->sectorZ,
path->systemIndex);
} else {
assert(path->IsBodyPath());
lua_pushfstring(l, "<%d,%d,%d : %d, %d>",
path->sectorX, path->sectorY, path->sectorZ,
path->systemIndex, path->bodyIndex);
}
return 1;
}
示例4: GetHyperspaceExitPoint
vector3d Space::GetHyperspaceExitPoint(const SystemPath &source, const SystemPath &dest) const
{
assert(m_starSystem);
assert(source.IsSystemPath());
assert(dest.IsSameSystem(m_starSystem->GetPath()));
RefCountedPtr<const Sector> source_sec = m_sectorCache->GetCached(source);
RefCountedPtr<const Sector> dest_sec = m_sectorCache->GetCached(dest);
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.GetPosition()) + vector3d(source.sectorX, source.sectorY, source.sectorZ);
const vector3d destPos = vector3d(dest_sys.GetPosition()) + vector3d(dest.sectorX, dest.sectorY, dest.sectorZ);
Body *primary = 0;
if (dest.IsBodyPath()) {
assert(dest.bodyIndex < m_starSystem->GetNumBodies());
primary = FindBodyForPath(&dest);
while (primary && primary->GetSystemBody()->GetSuperType() != SystemBody::SUPERTYPE_STAR) {
SystemBody* parent = primary->GetSystemBody()->GetParent();
primary = parent ? FindBodyForPath(&parent->GetPath()) : 0;
}
}
if (!primary) {
// find the first non-gravpoint. should be the primary star
for (Body* b : GetBodies())
if (b->GetSystemBody()->GetType() != SystemBody::TYPE_GRAVPOINT) {
primary = b;
break;
}
}
assert(primary);
// point along the line between source and dest, a reasonable distance
// away based on the radius (don't want to end up inside black holes, and
// then mix it up so that ships don't end up on top of each other
vector3d pos = (sourcePos - destPos).Normalized() * (primary->GetSystemBody()->GetRadius()/AU+1.0)*11.0*AU*Pi::rng.Double(0.95,1.2) + MathUtil::RandomPointOnSphere(5.0,20.0)*1000.0;
assert(pos.Length() > primary->GetSystemBody()->GetRadius());
return pos + primary->GetPositionRelTo(GetRootFrame());
}
示例5: l_set_hyperspace_target
static int l_set_hyperspace_target(lua_State *l)
{
LuaObject<Player>::CheckFromLua(1);
if (Pi::game->IsNormalSpace()) {
const SystemPath path = *LuaObject<SystemPath>::CheckFromLua(2);
if (!path.IsSystemPath()) {
if (!path.IsBodyPath()) {
return luaL_error(l, "Player:SetHyperspaceTarget() -- second parameter is not a system path or the path of a star");
}
RefCountedPtr<StarSystem> sys = Pi::game->GetGalaxy()->GetStarSystem(path);
// Lua should never be able to get an invalid SystemPath
// (note: this may change if it becomes possible to remove systems during the game)
assert(path.bodyIndex < sys->GetNumBodies());
SystemBody *sbody = sys->GetBodyByPath(path);
if (!sbody->GetSuperType() == SystemBody::SUPERTYPE_STAR)
return luaL_error(l, "Player:SetHyperspaceTarget() -- second parameter is not a system path or the path of a star");
}
Pi::game->GetSectorView()->SetHyperspaceTarget(path);
return 0;
} else
return luaL_error(l, "Player:SetHyperspaceTarget() cannot be used while in hyperspace");
}
示例6: l_sbodypath_is_body_path
static int l_sbodypath_is_body_path(lua_State *l)
{
SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1);
LuaPush(l, path->IsBodyPath());
return 1;
}
示例7: UpdateInfo
virtual void UpdateInfo() {
const float YSEP = Gui::Screen::GetFontHeight() * 1.5f;
DeleteAllChildren();
Gui::Label *l = new Gui::Label(Lang::MISSIONS);
Add(l, 20, 20);
l = new Gui::Label(Lang::TYPE);
Add(l, 20, 20+YSEP*2);
l = new Gui::Label(Lang::CLIENT);
Add(l, 100, 20+YSEP*2);
l = new Gui::Label(Lang::LOCATION);
Add(l, 260, 20+YSEP*2);
l = new Gui::Label(Lang::DUE);
Add(l, 420, 20+YSEP*2);
l = new Gui::Label(Lang::REWARD);
Add(l, 580, 20+YSEP*2);
l = new Gui::Label(Lang::STATUS);
Add(l, 680, 20+YSEP*2);
ShowChildren();
Gui::VScrollBar *scroll = new Gui::VScrollBar();
Gui::VScrollPortal *portal = new Gui::VScrollPortal(760);
scroll->SetAdjustment(&portal->vscrollAdjust);
const std::list<const Mission*> &missions = Pi::player->missions.GetAll();
Gui::Fixed *innerbox = new Gui::Fixed(760, missions.size());
float ypos = 0;
for (std::list<const Mission*>::const_iterator i = missions.begin(); i != missions.end(); ++i) {
SystemPath path = (*i)->location;
RefCountedPtr<StarSystem> s = StarSystem::GetCached(path);
l = new Gui::Label((*i)->type);
innerbox->Add(l, 0, ypos);
l = new Gui::Label((*i)->client);
innerbox->Add(l, 80, ypos);
if (!path.IsBodyPath())
l = new Gui::Label(stringf("%0 [%1{d},%2{d},%3{d}]", s->GetName().c_str(), path.sectorX, path.sectorY, path.sectorZ));
else
l = new Gui::Label(stringf("%0\n%1 [%2{d},%3{d},%4{d}]", s->GetBodyByPath(&path)->name.c_str(), s->GetName().c_str(), path.sectorX, path.sectorY, path.sectorZ));
innerbox->Add(l, 240, ypos);
l = new Gui::Label(format_date((*i)->due));
innerbox->Add(l, 400, ypos);
l = new Gui::Label(format_money((*i)->reward));
innerbox->Add(l, 560, ypos);
switch ((*i)->status) {
case Mission::FAILED: l = new Gui::Label(std::string("#f00")+std::string(Lang::FAILED)); break;
case Mission::COMPLETED: l = new Gui::Label(std::string("#ff0")+std::string(Lang::COMPLETED)); break;
default:
case Mission::ACTIVE: l = new Gui::Label(std::string("#0f0")+std::string(Lang::ACTIVE)); break;
}
innerbox->Add(l, 660, ypos);
ypos += YSEP*3;
}
portal->Add(innerbox);
Gui::HBox *body = new Gui::HBox();
body->PackEnd(portal);
body->PackEnd(scroll);
body->ShowAll();
Add(body, 20, 20+YSEP*3);
}