Exemple #1
0
/*
 * Method: SectorOnly
 *
 * Derive a SystemPath that points to the whole sector.
 *
 * > sector_path = path:SectorOnly()
 *
 * Return:
 *
 *   sector_path - the SystemPath that represents just the sector
 *
 * Availability:
 *
 *   alpha 17
 *
 * Status:
 *
 *   stable
 */
static int l_sbodypath_sector_only(lua_State *l)
{
	SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1);
	if (path->IsSectorPath()) { return 1; }
	LuaObject<SystemPath>::PushToLua(path->SectorOnly());
	return 1;
}
Exemple #2
0
/*
 * Attribute: systemIndex
 *
 * The system index component of the path, or nil if the SystemPath does
 * not point to a system.
 *
 * Availability:
 *
 *   alpha 10
 *
 * Status:
 *
 *   stable
 */
static int l_sbodypath_attr_system_index(lua_State *l)
{
	SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1);
	if (!path->IsSectorPath())
		lua_pushinteger(l, path->systemIndex);
	else
		lua_pushnil(l);
	return 1;
}
Exemple #3
0
/*
 * Method: GetStarSystem
 *
 * Get a <StarSystem> object for the system that this path points to
 *
 * > system = path:GetStarSystem()
 *
 * Return:
 *
 *   system - the <StarSystem>
 *
 * Availability:
 *
 *   alpha 10
 *
 * Status:
 *
 *   stable
 */
static int l_sbodypath_get_star_system(lua_State *l)
{
	SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1);

	if (path->IsSectorPath())
		return luaL_error(l, "SystemPath:GetStarSystem() self argument does not refer to a system");

	RefCountedPtr<StarSystem> s = Pi::game->GetGalaxy()->GetStarSystem(path);
	// LuaObject<StarSystem> shares ownership of the StarSystem,
	// because LuaAcquirer<LuaObject<StarSystem>> uses IncRefCount and DecRefCount
	LuaObject<StarSystem>::PushToLua(s.Get());
	return 1;
}
Exemple #4
0
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;
}
Exemple #5
0
/*
 * Method: GetSystemBody
 *
 * Get a <SystemBody> object for the body that this path points to
 *
 * > body = path:GetSystemBody()
 *
 * Return:
 *
 *   body - the <SystemBody>
 *
 * Availability:
 *
 *   alpha 10
 *
 * Status:
 *
 *   stable
 */
static int l_sbodypath_get_system_body(lua_State *l)
{
	SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1);

	if (path->IsSectorPath()) {
		luaL_error(l, "Path <%d,%d,%d> does not name a system or body", path->sectorX, path->sectorY, path->sectorZ);
		return 0;
	}

	RefCountedPtr<StarSystem> sys = Pi::game->GetGalaxy()->GetStarSystem(path);
	if (path->IsSystemPath()) {
		luaL_error(l, "Path <%d,%d,%d : %d ('%s')> does not name a body", path->sectorX, path->sectorY, path->sectorZ, path->systemIndex, sys->GetName().c_str());
		return 0;
	}

	// 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);
	LuaObject<SystemBody>::PushToLua(sbody);
	return 1;
}
Exemple #6
0
static int l_sbodypath_is_sector_path(lua_State *l)
{
	SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1);
	LuaPush(l, path->IsSectorPath());
	return 1;
}