Example #1
0
/*
 * Function: New
 *
 * Creates a new <SystemPath> object
 *
 * > path = SystemPath.New(sectorX, sectorY, sectorZ, systemIndex, bodyIndex)
 *
 * Parameters:
 *
 *   sectorX - galactic sector X coordinate
 *
 *   sectorY - galactic sector Y coordinate
 *
 *   sectorZ - galactic sector Z coordinate
 *
 *   systemIndex - optional. the numeric index of the system within the sector
 *
 *   bodyIndex - optional. the numeric index of a specific body within the
 *               system. Defaults to 0, which typically corresponds to the
 *               primary star.
 *
 * Availability:
 *
 *   alpha 10, alpha 13 (updated)
 *
 * Status:
 *
 *   stable
 */
static int l_sbodypath_new(lua_State *l)
{
	Sint32 sector_x = luaL_checkinteger(l, 1);
	Sint32 sector_y = luaL_checkinteger(l, 2);
	Sint32 sector_z = luaL_checkinteger(l, 3);

	SystemPath path(sector_x, sector_y, sector_z);

	if (lua_gettop(l) > 3) {
		path.systemIndex = luaL_checkinteger(l, 4);

		if (Pi::game) {
			// if this is a system path, then check that the system exists
			RefCountedPtr<const Sector> s = Pi::game->GetGalaxy()->GetSector(path);
			if (size_t(path.systemIndex) >= s->m_systems.size())
				luaL_error(l, "System %d in sector <%d,%d,%d> does not exist", path.systemIndex, sector_x, sector_y, sector_z);
		}
		if (lua_gettop(l) > 4) {
			path.bodyIndex = luaL_checkinteger(l, 5);

			if (Pi::game) {
				// and if it's a body path, check that the body exists
				RefCountedPtr<StarSystem> sys = Pi::game->GetGalaxy()->GetStarSystem(path);
				if (path.bodyIndex >= sys->GetNumBodies()) {
					luaL_error(l, "Body %d in system <%d,%d,%d : %d ('%s')> does not exist",
						path.bodyIndex, sector_x, sector_y, sector_z, path.systemIndex, sys->GetName().c_str());
				}
			}
		}
	}
	LuaObject<SystemPath>::PushToLua(path);
	return 1;
}
Example #2
0
/*
 * Function: New
 *
 * Creates a new <SystemPath> object
 *
 * > path = SystemPath.New(sectorX, sectorY, sectorZ, systemIndex, bodyIndex)
 *
 * Parameters:
 *
 *   sectorX - galactic sector X coordinate
 *
 *   sectorY - galactic sector Y coordinate
 *
 *   sectorZ - galactic sector Z coordinate
 *
 *   systemIndex - optional. the numeric index of the system within the sector
 *
 *   bodyIndex - optional. the numeric index of a specific body within the
 *               system. Defaults to 0, which typically corresponds to the
 *               primary star.
 *
 * Availability:
 *
 *   alpha 10, alpha 13 (updated)
 *
 * Status:
 *
 *   stable
 */
static int l_sbodypath_new(lua_State *l)
{
	Sint32 sector_x = luaL_checkinteger(l, 1);
	Sint32 sector_y = luaL_checkinteger(l, 2);
	Sint32 sector_z = luaL_checkinteger(l, 3);

	SystemPath path(sector_x, sector_y, sector_z);

	if (lua_gettop(l) > 3) {
		path.systemIndex = luaL_checkinteger(l, 4);

		// if this is a system path, then check that the system exists
		Sector s(sector_x, sector_y, sector_z);
		if (size_t(path.systemIndex) >= s.m_systems.size())
			luaL_error(l, "System %d in sector <%d,%d,%d> does not exist", path.systemIndex, sector_x, sector_y, sector_z);

		if (lua_gettop(l) > 4) {
			path.bodyIndex = luaL_checkinteger(l, 5);

			// and if it's a body path, check that the body exists
			RefCountedPtr<StarSystem> sys = StarSystem::GetCached(path);
			if (size_t(path.bodyIndex) >= sys->m_bodies.size()) {
				luaL_error(l, "Body %d in system <%d,%d,%d : %d ('%s')> does not exist",
					path.bodyIndex, sector_x, sector_y, sector_z, path.systemIndex, sys->GetName().c_str());
			}
		}
	}
	LuaSystemPath::PushToLua(&path);
	return 1;
}
Example #3
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;
}
Example #4
0
	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);
	}
Example #5
0
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));
	}

	CreateViews();

	EmitPauseState(IsPaused());
}
Example #6
0
void SectorView::UpdateSystemLabels(SystemLabels &labels, const SystemPath &path)
{
    PROFILE_SCOPED()
    Sector *sec = GetCached(path.sectorX, path.sectorY, path.sectorZ);
    Sector *playerSec = GetCached(m_current.sectorX, m_current.sectorY, m_current.sectorZ);

    char format[256];

    if (m_inSystem) {
        const float dist = Sector::DistanceBetween(sec, path.systemIndex, playerSec, m_current.systemIndex);

        int fuelRequired;
        double dur;
        enum Ship::HyperjumpStatus jumpStatus
            = Pi::player->GetHyperspaceDetails(&path, fuelRequired, dur);
        const double DaysNeeded = dur*(1.0 / (24*60*60));
        const double HoursNeeded = (DaysNeeded - floor(DaysNeeded))*24;

        switch (jumpStatus) {
        case Ship::HYPERJUMP_OK:
            snprintf(format, sizeof(format), "[ %s | %s | %s, %s ]", Lang::NUMBER_LY, Lang::NUMBER_TONNES, Lang::NUMBER_DAYS, Lang::NUMBER_HOURS);
            labels.distance->SetText(stringf(format,
                                             formatarg("distance", dist), formatarg("mass", fuelRequired), formatarg("days", floor(DaysNeeded)), formatarg("hours", HoursNeeded)));
            labels.distance->Color(0, 255, 51);
            m_jumpLine.SetColor(Color(0, 255, 51, 255));
            break;
        case Ship::HYPERJUMP_INSUFFICIENT_FUEL:
            snprintf(format, sizeof(format), "[ %s | %s ]", Lang::NUMBER_LY, Lang::NUMBER_TONNES);
            labels.distance->SetText(stringf(format,
                                             formatarg("distance", dist), formatarg("mass", fuelRequired)));
            labels.distance->Color(255, 255, 0);
            m_jumpLine.SetColor(Color::YELLOW);
            break;
        case Ship::HYPERJUMP_OUT_OF_RANGE:
            snprintf(format, sizeof(format), "[ %s ]", Lang::NUMBER_LY);
            labels.distance->SetText(stringf(format,
                                             formatarg("distance", dist)));
            labels.distance->Color(255, 0, 0);
            m_jumpLine.SetColor(Color::RED);
            break;
        default:
            labels.distance->SetText("");
            break;
        }
    }

    else if (path.IsSameSystem(Pi::player->GetHyperspaceDest())) {
        snprintf(format, sizeof(format), "[ %s ]", Lang::IN_TRANSIT);
        labels.distance->SetText(format);
        labels.distance->Color(102, 102, 255);
    }

    else
        labels.distance->SetText("");

    RefCountedPtr<StarSystem> sys = StarSystem::GetCached(path);

    std::string desc;
    if (sys->GetNumStars() == 4) {
        desc = Lang::QUADRUPLE_SYSTEM;
    } else if (sys->GetNumStars() == 3) {
        desc = Lang::TRIPLE_SYSTEM;
    } else if (sys->GetNumStars() == 2) {
        desc = Lang::BINARY_SYSTEM;
    } else {
        desc = sys->rootBody->GetAstroDescription();
    }
    labels.starType->SetText(desc);

    labels.systemName->SetText(sys->GetName());
    labels.shortDesc->SetText(sys->GetShortDescription());

    if (m_detailBoxVisible == DETAILBOX_INFO) m_infoBox->ShowAll();
}