本文整理汇总了C++中StarSystem::GetPath方法的典型用法代码示例。如果您正苦于以下问题:C++ StarSystem::GetPath方法的具体用法?C++ StarSystem::GetPath怎么用?C++ StarSystem::GetPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StarSystem
的用法示例。
在下文中一共展示了StarSystem::GetPath方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: l_starsystem_attr_path
/*
* Attribute: path
*
* The <SystemPath> to the system
*
* Availability:
*
* alpha 10
*
* Status:
*
* stable
*/
static int l_starsystem_attr_path(lua_State *l)
{
StarSystem *s = LuaStarSystem::CheckFromLua(1);
SystemPath path = s->GetPath();
LuaSystemPath::PushToLua(&path);
return 1;
}
示例2: l_starsystem_attr_path
/*
* Attribute: path
*
* The <SystemPath> to the system
*
* Availability:
*
* alpha 10
*
* Status:
*
* stable
*/
static int l_starsystem_attr_path(lua_State *l)
{
PROFILE_SCOPED()
StarSystem *s = LuaObject<StarSystem>::CheckFromLua(1);
SystemPath path = s->GetPath();
LuaObject<SystemPath>::PushToLua(&path);
return 1;
}
示例3: InitiateHyperjumpTo
Ship::HyperjumpStatus Ship::InitiateHyperjumpTo(const SystemPath &dest, int warmup_time, double duration, LuaRef checks) {
if (!dest.HasValidSystem() || GetFlightState() != FLYING || warmup_time < 1)
return HYPERJUMP_SAFETY_LOCKOUT;
StarSystem *s = Pi::game->GetSpace()->GetStarSystem().Get();
if (s && s->GetPath().IsSameSystem(dest))
return HYPERJUMP_CURRENT_SYSTEM;
m_hyperspace.dest = dest;
m_hyperspace.countdown = warmup_time;
m_hyperspace.now = false;
m_hyperspace.duration = duration;
m_hyperspace.checks = checks;
return Ship::HYPERJUMP_OK;
}
示例4: GetHyperspaceDetails
Ship::HyperjumpStatus Ship::GetHyperspaceDetails(const SystemPath &dest, int &outFuelRequired, double &outDurationSecs)
{
assert(dest.HasValidSystem());
outFuelRequired = 0;
outDurationSecs = 0.0;
UpdateStats();
if (GetFlightState() == HYPERSPACE)
return HYPERJUMP_DRIVE_ACTIVE;
Equip::Type t = m_equipment.Get(Equip::SLOT_ENGINE);
Equip::Type fuelType = GetHyperdriveFuelType();
int hyperclass = Equip::types[t].pval;
int fuel = m_equipment.Count(Equip::SLOT_CARGO, fuelType);
if (hyperclass == 0)
return HYPERJUMP_NO_DRIVE;
StarSystem *s = Pi::game->GetSpace()->GetStarSystem().Get();
if (s && s->GetPath().IsSameSystem(dest))
return HYPERJUMP_CURRENT_SYSTEM;
float dist = distance_to_system(dest);
outFuelRequired = Pi::CalcHyperspaceFuelOut(hyperclass, dist, m_stats.hyperspace_range_max);
double m_totalmass = GetMass()/1000;
if (dist > m_stats.hyperspace_range_max) {
outFuelRequired = 0;
return HYPERJUMP_OUT_OF_RANGE;
} else if (fuel < outFuelRequired) {
return HYPERJUMP_INSUFFICIENT_FUEL;
} else {
outDurationSecs = Pi::CalcHyperspaceDuration(hyperclass, m_totalmass, dist);
if (outFuelRequired <= fuel) {
return HYPERJUMP_OK;
} else {
return HYPERJUMP_INSUFFICIENT_FUEL;
}
}
}
示例5: l_starsystem_distance_to
/*
* Method: DistanceTo
*
* Calculate the distance between this and another system
*
* > dist = system:DistanceTo(system)
*
* Parameters:
*
* system - a <SystemPath> or <StarSystem> to calculate the distance to
*
* Return:
*
* dist - the distance, in light years
*
* Availability:
*
* alpha 10
*
* Status:
*
* stable
*/
static int l_starsystem_distance_to(lua_State *l)
{
LUA_DEBUG_START(l);
StarSystem *s = LuaStarSystem::CheckFromLua(1);
const SystemPath *loc1 = &(s->GetPath());
const SystemPath *loc2 = LuaSystemPath::GetFromLua(2);
if (!loc2) {
StarSystem *s2 = LuaStarSystem::CheckFromLua(2);
loc2 = &(s2->GetPath());
}
Sector sec1(loc1->sectorX, loc1->sectorY, loc1->sectorZ);
Sector sec2(loc2->sectorX, loc2->sectorY, loc2->sectorZ);
double dist = Sector::DistanceBetween(&sec1, loc1->systemIndex, &sec2, loc2->systemIndex);
lua_pushnumber(l, dist);
LUA_DEBUG_END(l, 1);
return 1;
}
示例6: l_starsystem_distance_to
/*
* Method: DistanceTo
*
* Calculate the distance between this and another system
*
* > dist = system:DistanceTo(system)
*
* Parameters:
*
* system - a <SystemPath> or <StarSystem> to calculate the distance to
*
* Return:
*
* dist - the distance, in light years
*
* Availability:
*
* alpha 10
*
* Status:
*
* stable
*/
static int l_starsystem_distance_to(lua_State *l)
{
PROFILE_SCOPED()
LUA_DEBUG_START(l);
StarSystem *s = LuaObject<StarSystem>::CheckFromLua(1);
const SystemPath *loc1 = &(s->GetPath());
const SystemPath *loc2 = LuaObject<SystemPath>::GetFromLua(2);
if (!loc2) {
StarSystem *s2 = LuaObject<StarSystem>::CheckFromLua(2);
loc2 = &(s2->GetPath());
}
RefCountedPtr<const Sector> sec1 = Pi::GetGalaxy()->GetSector(*loc1);
RefCountedPtr<const Sector> sec2 = Pi::GetGalaxy()->GetSector(*loc2);
double dist = Sector::DistanceBetween(sec1, loc1->systemIndex, sec2, loc2->systemIndex);
lua_pushnumber(l, dist);
LUA_DEBUG_END(l, 1);
return 1;
}
示例7: l_starsystem_get_nearby_systems
/*
* Method: GetNearbySystems
*
* Get a list of nearby <StarSystems> that match some criteria
*
* > systems = system:GetNearbySystems(range, filter)
*
* Parameters:
*
* range - distance from this system to search, in light years
*
* filter - an optional function. If specified the function will be called
* once for each candidate system with the <StarSystem> object
* passed as the only parameter. If the filter function returns
* true then the system will be included in the array returned by
* <GetNearbySystems>, otherwise it will be omitted. If no filter
* function is specified then all systems in range are returned.
*
* Return:
*
* systems - an array of systems in range that matched the filter
*
* Availability:
*
* alpha 10
*
* Status:
*
* experimental
*/
static int l_starsystem_get_nearby_systems(lua_State *l)
{
LUA_DEBUG_START(l);
StarSystem *s = LuaStarSystem::CheckFromLua(1);
double dist_ly = luaL_checknumber(l, 2);
bool filter = false;
if (lua_gettop(l) >= 3) {
luaL_checktype(l, 3, LUA_TFUNCTION); // any type of function
filter = true;
}
lua_newtable(l);
SystemPath here = s->GetPath();
int here_x = here.sectorX;
int here_y = here.sectorY;
int here_z = here.sectorZ;
Uint32 here_idx = here.systemIndex;
Sector here_sec(here_x, here_y, here_z);
int diff_sec = int(ceil(dist_ly/Sector::SIZE));
for (int x = here_x-diff_sec; x <= here_x+diff_sec; x++) {
for (int y = here_y-diff_sec; y <= here_y+diff_sec; y++) {
for (int z = here_z-diff_sec; z <= here_z+diff_sec; z++) {
Sector sec(x, y, z);
for (unsigned int idx = 0; idx < sec.m_systems.size(); idx++) {
if (x == here_x && y == here_y && z == here_z && idx == here_idx)
continue;
if (Sector::DistanceBetween(&here_sec, here_idx, &sec, idx) > dist_ly)
continue;
RefCountedPtr<StarSystem> sys = StarSystem::GetCached(SystemPath(x, y, z, idx));
if (filter) {
lua_pushvalue(l, 3);
LuaStarSystem::PushToLua(sys.Get());
lua_call(l, 1, 1);
if (!lua_toboolean(l, -1)) {
lua_pop(l, 1);
continue;
}
lua_pop(l, 1);
}
lua_pushinteger(l, lua_rawlen(l, -1)+1);
LuaStarSystem::PushToLua(sys.Get());
lua_rawset(l, -3);
}
}
}
}
LUA_DEBUG_END(l, 1);
return 1;
}