Allow unexplored systems to become explored in game.

master
Lars W. (lwho) 2014-01-18 19:51:22 +01:00
parent a88a040857
commit aa3604511c
14 changed files with 147 additions and 72 deletions

View File

@ -1919,6 +1919,10 @@
"description" : "",
"message" : "Unexplored System. Star information has been gathered by remote telescope, but no planetary information is available."
},
"RECENTLY_EXPLORED_SYSTEM" : {
"description" : "",
"message" : "This system was explored on %date."
},
"UNKNOWN" : {
"description" : "",
"message" : "<unknown>"

View File

@ -355,6 +355,7 @@ DECLARE_STRING(ORBITAL_STARPORT)
DECLARE_STRING(STARPORT)
DECLARE_STRING(UNKNOWN)
DECLARE_STRING(UNEXPLORED_SYSTEM_NO_DATA)
DECLARE_STRING(RECENTLY_EXPLORED_SYSTEM)
DECLARE_STRING(SMALL_SCALE_PROSPECTING_NO_SETTLEMENTS)
DECLARE_STRING(SMALL_INDUSTRIAL_OUTPOST)
DECLARE_STRING(SOME_ESTABLISHED_MINING)

View File

@ -23,6 +23,7 @@ SystemInfoView::SystemInfoView(Game* game) : UIView(), m_game(game)
{
SetTransparency(true);
m_refresh = REFRESH_NONE;
m_unexplored = true;
}
void SystemInfoView::OnBodySelected(SystemBody *b)
@ -336,7 +337,7 @@ void SystemInfoView::SystemChanged(const SystemPath &path)
return;
m_system = m_game->GetGalaxy()->GetStarSystem(path);
m_unexplored = m_system->GetUnexplored();
m_sbodyInfoTab = new Gui::Fixed(float(Gui::Screen::GetWidth()), float(Gui::Screen::GetHeight()-100));
if (m_system->GetUnexplored()) {
@ -510,6 +511,9 @@ SystemInfoView::RefreshType SystemInfoView::NeedsRefresh()
if (!m_system || !m_game->GetSectorView()->GetSelected().IsSameSystem(m_system->GetPath()))
return REFRESH_ALL;
if (m_system->GetUnexplored() != m_unexplored)
return REFRESH_ALL;
if (m_system->GetUnexplored())
return REFRESH_NONE; // Nothing can be selected and we reset in SystemChanged

View File

@ -70,6 +70,8 @@ private:
RefreshType m_refresh;
//map is not enough to associate icons as each tab has their own. First element is the body index of SystemPath (names are not unique)
std::vector<std::pair<Uint32, BodyIcon*> > m_bodyIcons;
bool m_unexplored;
Graphics::RenderState *m_solidState;
};

View File

@ -102,6 +102,7 @@ SystemView::SystemView(Game* game) : UIView(), m_game(game)
m_lineState = Pi::renderer->CreateRenderState(rsd); //m_renderer not set yet
m_realtime = true;
m_unexplored = true;
Gui::Screen::PushFont("OverlayFont");
m_objectLabels = new Gui::LabelSet();
@ -580,7 +581,7 @@ void SystemView::Draw3D()
SystemPath path = m_game->GetSectorView()->GetSelected().SystemOnly();
if (m_system) {
if (!m_system->GetPath().IsSameSystem(path)) {
if (m_system->GetUnexplored() != m_unexplored || !m_system->GetPath().IsSameSystem(path)) {
m_system.Reset();
ResetViewpoint();
}
@ -595,7 +596,10 @@ void SystemView::Draw3D()
std::string t = Lang::TIME_POINT+format_date(m_time);
m_timePoint->SetText(t);
if (!m_system) m_system = m_game->GetGalaxy()->GetStarSystem(path);
if (!m_system) {
m_system = m_game->GetGalaxy()->GetStarSystem(path);
m_unexplored = m_system->GetUnexplored();
}
matrix4x4f trans = matrix4x4f::Identity();
trans.Translate(0,0,-ROUGH_SIZE_OF_TURD);
@ -610,13 +614,16 @@ void SystemView::Draw3D()
m_objectLabels->Clear();
if (m_system->GetUnexplored())
m_infoLabel->SetText(Lang::UNEXPLORED_SYSTEM_NO_SYSTEM_VIEW);
else if (m_system->GetRootBody()) {
PutBody(m_system->GetRootBody().Get(), pos, trans);
if (m_game->GetSpace()->GetStarSystem() == m_system) {
const Body *navTarget = Pi::player->GetNavTarget();
const SystemBody *navTargetSystemBody = navTarget ? navTarget->GetSystemBody() : 0;
if (navTargetSystemBody)
PutSelectionBox(navTargetSystemBody, pos, Color::GREEN);
else {
m_infoLabel->SetText("");
if (m_system->GetRootBody()) {
PutBody(m_system->GetRootBody().Get(), pos, trans);
if (m_game->GetSpace()->GetStarSystem() == m_system) {
const Body *navTarget = Pi::player->GetNavTarget();
const SystemBody *navTargetSystemBody = navTarget ? navTarget->GetSystemBody() : 0;
if (navTargetSystemBody)
PutSelectionBox(navTargetSystemBody, pos, Color::GREEN);
}
}
}
glLineWidth(1);

View File

@ -74,6 +74,7 @@ private:
Game* m_game;
RefCountedPtr<StarSystem> m_system;
const SystemBody *m_selectedObject;
bool m_unexplored;
TransferPlanner *m_planner;
std::list<std::pair<Ship*, Orbit>> m_contacts;
Gui::LabelSet *m_shipLabels;

View File

@ -39,6 +39,7 @@ public:
CustomSystemsDatabase* GetCustomSystems() { return &m_customSystems; } // XXX const correctness
RefCountedPtr<const Sector> GetSector(const SystemPath& path) { return m_sectorCache.GetCached(path); }
RefCountedPtr<Sector> GetMutableSector(const SystemPath& path) { return m_sectorCache.GetCached(path); }
RefCountedPtr<SectorCache::Slave> NewSectorSlaveCache() { return m_sectorCache.NewSlaveCache(); }
RefCountedPtr<StarSystem> GetStarSystem(const SystemPath& path) { return m_starSystemCache.GetCached(path); }

View File

@ -55,6 +55,12 @@ bool Sector::Contains(const SystemPath &sysPath) const
return true;
}
void Sector::System::SetExplored(StarSystem::ExplorationState e, double time)
{
m_explored = e;
m_exploredTime = time;
}
void Sector::Dump(FILE* file, const char* indent) const
{
fprintf(file, "Sector(%d,%d,%d) {\n", sx, sy, sz);

View File

@ -38,7 +38,8 @@ public:
class System {
public:
System(Sector* sector, int x, int y, int z, Uint32 si) : sx(x), sy(y), sz(z), idx(si), m_sector(sector),
m_numStars(0), m_seed(0), m_customSys(nullptr), m_faction(nullptr), m_population(-1), m_explored(false) {}
m_numStars(0), m_seed(0), m_customSys(nullptr), m_faction(nullptr), m_population(-1),
m_explored(StarSystem::eUNEXPLORED), m_exploredTime(0.0) {}
static float DistanceBetween(const System* a, const System* b);
@ -54,7 +55,10 @@ public:
const Faction* GetFaction() const { if (!m_faction) AssignFaction(); return m_faction; }
fixed GetPopulation() const { return m_population; }
void SetPopulation(fixed pop) { m_population = pop; }
bool IsExplored() const { return m_explored; }
StarSystem::ExplorationState GetExplored() const { return m_explored; }
double GetExploredTime() const { return m_exploredTime; }
bool IsExplored() const { return m_explored != StarSystem::eUNEXPLORED; }
void SetExplored(StarSystem::ExplorationState e, double time);
bool IsSameSystem(const SystemPath &b) const {
return sx == b.sectorX && sy == b.sectorY && sz == b.sectorZ && idx == b.systemIndex;
@ -82,7 +86,8 @@ public:
const CustomSystem* m_customSys;
mutable const Faction* m_faction; // mutable because we only calculate on demand
fixed m_population;
bool m_explored;
StarSystem::ExplorationState m_explored;
double m_exploredTime;
};
std::vector<System> m_systems;
const int sx, sy, sz;

View File

@ -48,9 +48,15 @@ bool SectorCustomSystemsGenerator::Apply(Random& rng, RefCountedPtr<Galaxy> gala
* ~700ly+: unexplored
*/
int dist = isqrt(1 + sx*sx + sy*sy + sz*sz);
s.m_explored = ((dist <= 90) && ( dist <= 65 || rng.Int32(dist) <= 40)) || galaxy->GetFactions()->IsHomeSystem(SystemPath(sx, sy, sz, sysIdx));
if (((dist <= 90) && ( dist <= 65 || rng.Int32(dist) <= 40)) || galaxy->GetFactions()->IsHomeSystem(SystemPath(sx, sy, sz, sysIdx)))
s.m_explored = StarSystem::eEXPLORED_AT_START;
else
s.m_explored = StarSystem::eUNEXPLORED;
} else {
s.m_explored = cs->explored;
if (cs->explored)
s.m_explored = StarSystem::eEXPLORED_AT_START;
else
s.m_explored = StarSystem::eUNEXPLORED;
}
sector->m_systems.push_back(s);
}
@ -162,7 +168,10 @@ bool SectorRandomSystemsGenerator::Apply(Random& rng, RefCountedPtr<Galaxy> gala
* ~700ly+: unexplored
*/
int dist = isqrt(1 + sx*sx + sy*sy + sz*sz);
s.m_explored = ((dist <= 90) && ( dist <= 65 || rng.Int32(dist) <= 40)) || galaxy->GetFactions()->IsHomeSystem(SystemPath(sx, sy, sz, customCount + i));
if (((dist <= 90) && ( dist <= 65 || rng.Int32(dist) <= 40)) || galaxy->GetFactions()->IsHomeSystem(SystemPath(sx, sy, sz, customCount + i)))
s.m_explored = StarSystem::eEXPLORED_AT_START;
else
s.m_explored = StarSystem::eUNEXPLORED;
Uint32 weight = rng.Int32(1000000);

View File

@ -647,7 +647,7 @@ SystemBody::AtmosphereParameters SystemBody::CalcAtmosphereParams() const
*/
StarSystem::StarSystem(const SystemPath &path, RefCountedPtr<Galaxy> galaxy, StarSystemCache* cache, Random& rand)
: m_galaxy(galaxy), m_path(path.SystemOnly()), m_numStars(0), m_isCustom(false),
m_faction(nullptr), m_unexplored(false), m_econType(GalacticEconomy::ECON_MINING), m_seed(0),
m_faction(nullptr), m_explored(eEXPLORED_AT_START), m_exploredTime(0.0), m_econType(GalacticEconomy::ECON_MINING), m_seed(0),
m_commodityLegal(unsigned(GalacticEconomy::Commodity::COMMODITY_COUNT), true), m_cache(cache)
{
PROFILE_SCOPED()
@ -715,6 +715,58 @@ void StarSystem::Dump()
}
#endif /* DEBUG_DUMP */
void StarSystem::MakeShortDescription()
{
PROFILE_SCOPED()
if (GetExplored() == StarSystem::eUNEXPLORED)
SetShortDesc(Lang::UNEXPLORED_SYSTEM_NO_DATA);
else if (GetExplored() == StarSystem::eEXPLORED_BY_PLAYER)
SetShortDesc(stringf(Lang::RECENTLY_EXPLORED_SYSTEM, formatarg("date", format_date_only(GetExploredTime()))));
/* Total population is in billions */
else if(GetTotalPop() == 0) {
SetShortDesc(Lang::SMALL_SCALE_PROSPECTING_NO_SETTLEMENTS);
} else if (GetTotalPop() < fixed(1,10)) {
switch (GetEconType()) {
case GalacticEconomy::ECON_INDUSTRY: SetShortDesc(Lang::SMALL_INDUSTRIAL_OUTPOST); break;
case GalacticEconomy::ECON_MINING: SetShortDesc(Lang::SOME_ESTABLISHED_MINING); break;
case GalacticEconomy::ECON_AGRICULTURE: SetShortDesc(Lang::YOUNG_FARMING_COLONY); break;
}
} else if (GetTotalPop() < fixed(1,2)) {
switch (GetEconType()) {
case GalacticEconomy::ECON_INDUSTRY: SetShortDesc(Lang::INDUSTRIAL_COLONY); break;
case GalacticEconomy::ECON_MINING: SetShortDesc(Lang::MINING_COLONY); break;
case GalacticEconomy::ECON_AGRICULTURE: SetShortDesc(Lang::OUTDOOR_AGRICULTURAL_WORLD); break;
}
} else if (GetTotalPop() < fixed(5,1)) {
switch (GetEconType()) {
case GalacticEconomy::ECON_INDUSTRY: SetShortDesc(Lang::HEAVY_INDUSTRY); break;
case GalacticEconomy::ECON_MINING: SetShortDesc(Lang::EXTENSIVE_MINING); break;
case GalacticEconomy::ECON_AGRICULTURE: SetShortDesc(Lang::THRIVING_OUTDOOR_WORLD); break;
}
} else {
switch (GetEconType()) {
case GalacticEconomy::ECON_INDUSTRY: SetShortDesc(Lang::INDUSTRIAL_HUB_SYSTEM); break;
case GalacticEconomy::ECON_MINING: SetShortDesc(Lang::VAST_STRIP_MINE); break;
case GalacticEconomy::ECON_AGRICULTURE: SetShortDesc(Lang::HIGH_POPULATION_OUTDOOR_WORLD); break;
}
}
}
void StarSystem::ExploreSystem(double time)
{
if (m_explored != eUNEXPLORED)
return;
m_explored = eEXPLORED_BY_PLAYER;
m_exploredTime = time;
RefCountedPtr<Sector> sec = m_galaxy->GetMutableSector(m_path);
Sector::System& secsys = sec->m_systems[m_path.systemIndex];
secsys.SetExplored(m_explored, m_exploredTime);
MakeShortDescription();
}
void SystemBody::Dump(FILE* file, const char* indent) const
{
fprintf(file, "%sSystemBody(%d,%d,%d,%u,%u) : %s/%s %s{\n", indent, m_path.sectorX, m_path.sectorY, m_path.sectorZ, m_path.systemIndex,
@ -963,7 +1015,7 @@ void StarSystem::Dump(FILE* file, const char* indent, bool suppressSectorData) c
} else {
fprintf(file, "%sStarSystem(%d,%d,%d,%u) {\n", indent, m_path.sectorX, m_path.sectorY, m_path.sectorZ, m_path.systemIndex);
fprintf(file, "%s\t\"%s\"\n", indent, m_name.c_str());
fprintf(file, "%s\t%sEXPLORED%s\n", indent, m_unexplored ? "UN" : "", m_hasCustomBodies ? ", CUSTOM-ONLY" : m_isCustom ? ", CUSTOM" : "");
fprintf(file, "%s\t%sEXPLORED%s\n", indent, GetUnexplored() ? "UN" : "", m_hasCustomBodies ? ", CUSTOM-ONLY" : m_isCustom ? ", CUSTOM" : "");
fprintf(file, "%s\tfaction %s%s%s\n", indent, m_faction ? "\"" : "NONE", m_faction ? m_faction->name.c_str() : "", m_faction ? "\"" : "");
fprintf(file, "%s\tseed %u\n", indent, static_cast<Uint32>(m_seed));
fprintf(file, "%s\t%u stars%s\n", indent, m_numStars, m_numStars > 0 ? " {" : "");

View File

@ -289,6 +289,12 @@ public:
friend class GalaxyObjectCache<StarSystem, SystemPath::LessSystemOnly>;
class GeneratorAPI; // Complete definition below
enum ExplorationState {
eUNEXPLORED = 0,
eEXPLORED_BY_PLAYER = 1,
eEXPLORED_AT_START = 2
};
void ExportToLua(const char *filename);
const std::string &GetName() const { return m_name; }
@ -328,7 +334,11 @@ public:
}
const Faction* GetFaction() const { return m_faction; }
bool GetUnexplored() const { return m_unexplored; }
bool GetUnexplored() const { return m_explored == eUNEXPLORED; }
ExplorationState GetExplored() const { return m_explored; }
double GetExploredTime() const { return m_exploredTime; }
void ExploreSystem(double time);
fixed GetMetallicity() const { return m_metallicity; }
fixed GetIndustrial() const { return m_industrial; }
fixed GetAgricultural() const { return m_agricultural; }
@ -354,6 +364,9 @@ protected:
private:
void SetCache(StarSystemCache* cache) { assert(!m_cache); m_cache = cache; }
void MakeShortDescription();
void SetShortDesc(const std::string& desc) { m_shortDesc = desc; }
std::string ExportBodyToLua(FILE *f, SystemBody *body);
std::string GetStarTypes(SystemBody *body);
@ -368,7 +381,8 @@ private:
bool m_hasCustomBodies;
const Faction* m_faction;
bool m_unexplored;
ExplorationState m_explored;
double m_exploredTime;
fixed m_metallicity;
fixed m_industrial;
GalacticEconomy::EconType m_econType;
@ -404,9 +418,8 @@ public:
void SetRootBody(RefCountedPtr<SystemBody> rootBody) { m_rootBody = rootBody; }
void SetRootBody(SystemBody* rootBody) { m_rootBody.Reset(rootBody); }
void SetName(const std::string& name) { m_name = name; }
void SetShortDesc(const std::string& desc) { m_shortDesc = desc; }
void SetLongDesc(const std::string& desc) { m_longDesc = desc; }
void SetUnexplored(bool unexplored) { m_unexplored = unexplored; }
void SetExplored(ExplorationState explored, double time) { m_explored = explored; m_exploredTime = time; }
void SetSeed(Uint32 seed) { m_seed = seed; }
void SetFaction(const Faction* faction) { m_faction = faction; }
void SetEconType(GalacticEconomy::EconType econType) { m_econType = econType; }
@ -424,6 +437,8 @@ public:
void AddSpaceStation(SystemBody* station) { assert(station->GetSuperType() == SystemBody::SUPERTYPE_STARPORT); m_spaceStations.push_back(station); }
void AddStar(SystemBody* star) { assert(star->GetSuperType() == SystemBody::SUPERTYPE_STAR); m_stars.push_back(star);}
using StarSystem::NewBody;
using StarSystem::MakeShortDescription;
using StarSystem::SetShortDesc;
};
#endif /* _STARSYSTEM_H */

View File

@ -289,7 +289,7 @@ bool StarSystemFromSectorGenerator::Apply(Random& rng, RefCountedPtr<Galaxy> gal
system->SetFaction(galaxy->GetFactions()->GetNearestFaction(&secSys));
system->SetSeed(secSys.GetSeed());
system->SetName(secSys.GetName());
system->SetUnexplored(!secSys.IsExplored());
system->SetExplored(secSys.GetExplored(), secSys.GetExploredTime());
return true;
}
@ -1382,7 +1382,7 @@ void PopulateStarSystemGenerator::PopulateStage1(SystemBody* sbody, StarSystem::
}
// unexplored systems have no population (that we know about)
if (system->GetUnexplored()) {
if (system->GetExplored() != StarSystem::eEXPLORED_AT_START) {
sbody->m_population = outTotalPop = fixed();
return;
}
@ -1625,51 +1625,6 @@ void PopulateStarSystemGenerator::PopulateAddStations(SystemBody* sbody, StarSys
}
}
void PopulateStarSystemGenerator::MakeShortDescription(RefCountedPtr<StarSystem::GeneratorAPI> system, Random &rand)
{
PROFILE_SCOPED()
if ((system->GetIndustrial() > system->GetMetallicity()) && (system->GetIndustrial() > system->GetAgricultural())) {
system->SetEconType(GalacticEconomy::ECON_INDUSTRY);
} else if (system->GetMetallicity() > system->GetAgricultural()) {
system->SetEconType(GalacticEconomy::ECON_MINING);
} else {
system->SetEconType(GalacticEconomy::ECON_AGRICULTURE);
}
if (system->GetUnexplored()) {
system->SetShortDesc(Lang::UNEXPLORED_SYSTEM_NO_DATA);
}
/* Total population is in billions */
else if(system->GetTotalPop() == 0) {
system->SetShortDesc(Lang::SMALL_SCALE_PROSPECTING_NO_SETTLEMENTS);
} else if (system->GetTotalPop() < fixed(1,10)) {
switch (system->GetEconType()) {
case GalacticEconomy::ECON_INDUSTRY: system->SetShortDesc(Lang::SMALL_INDUSTRIAL_OUTPOST); break;
case GalacticEconomy::ECON_MINING: system->SetShortDesc(Lang::SOME_ESTABLISHED_MINING); break;
case GalacticEconomy::ECON_AGRICULTURE: system->SetShortDesc(Lang::YOUNG_FARMING_COLONY); break;
}
} else if (system->GetTotalPop() < fixed(1,2)) {
switch (system->GetEconType()) {
case GalacticEconomy::ECON_INDUSTRY: system->SetShortDesc(Lang::INDUSTRIAL_COLONY); break;
case GalacticEconomy::ECON_MINING: system->SetShortDesc(Lang::MINING_COLONY); break;
case GalacticEconomy::ECON_AGRICULTURE: system->SetShortDesc(Lang::OUTDOOR_AGRICULTURAL_WORLD); break;
}
} else if (system->GetTotalPop() < fixed(5,1)) {
switch (system->GetEconType()) {
case GalacticEconomy::ECON_INDUSTRY: system->SetShortDesc(Lang::HEAVY_INDUSTRY); break;
case GalacticEconomy::ECON_MINING: system->SetShortDesc(Lang::EXTENSIVE_MINING); break;
case GalacticEconomy::ECON_AGRICULTURE: system->SetShortDesc(Lang::THRIVING_OUTDOOR_WORLD); break;
}
} else {
switch (system->GetEconType()) {
case GalacticEconomy::ECON_INDUSTRY: system->SetShortDesc(Lang::INDUSTRIAL_HUB_SYSTEM); break;
case GalacticEconomy::ECON_MINING: system->SetShortDesc(Lang::VAST_STRIP_MINE); break;
case GalacticEconomy::ECON_AGRICULTURE: system->SetShortDesc(Lang::HIGH_POPULATION_OUTDOOR_WORLD); break;
}
}
}
void PopulateStarSystemGenerator::SetSysPolit(RefCountedPtr<Galaxy> galaxy, RefCountedPtr<StarSystem::GeneratorAPI> system, const fixed &human_infestedness)
{
SystemPath path = system->GetPath();
@ -1730,6 +1685,17 @@ void PopulateStarSystemGenerator::SetCommodityLegality(RefCountedPtr<StarSystem:
}
}
void PopulateStarSystemGenerator::SetEconType(RefCountedPtr<StarSystem::GeneratorAPI> system)
{
if ((system->GetIndustrial() > system->GetMetallicity()) && (system->GetIndustrial() > system->GetAgricultural())) {
system->SetEconType(GalacticEconomy::ECON_INDUSTRY);
} else if (system->GetMetallicity() > system->GetAgricultural()) {
system->SetEconType(GalacticEconomy::ECON_MINING);
} else {
system->SetEconType(GalacticEconomy::ECON_AGRICULTURE);
}
}
/* percent */
static const int MAX_COMMODITY_BASE_PRICE_ADJUSTMENT = 25;
@ -1783,8 +1749,10 @@ bool PopulateStarSystemGenerator::Apply(Random& rng, RefCountedPtr<Galaxy> galax
PopulateAddStations(system->GetRootBody().Get(), system.Get());
}
if (!system->GetShortDescription().size())
MakeShortDescription(system, rand);
if (!system->GetShortDescription().size()) {
SetEconType(system);
system->MakeShortDescription();
}
return true;
}

View File

@ -57,9 +57,9 @@ public:
virtual bool Apply(Random& rng, RefCountedPtr<Galaxy> galaxy, RefCountedPtr<StarSystem::GeneratorAPI> system, GalaxyGenerator::StarSystemConfig* config);
private:
void MakeShortDescription(RefCountedPtr<StarSystem::GeneratorAPI> system, Random &rand);
void SetSysPolit(RefCountedPtr<Galaxy> galaxy, RefCountedPtr<StarSystem::GeneratorAPI> system, const fixed &human_infestedness);
void SetCommodityLegality(RefCountedPtr<StarSystem::GeneratorAPI> system);
void SetEconType(RefCountedPtr<StarSystem::GeneratorAPI> system);
void PopulateAddStations(SystemBody* sbody, StarSystem::GeneratorAPI* system);
void PositionSettlementOnPlanet(SystemBody* sbody);