Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP lore/worldbuilding/station lobby #5283

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions data/lang/lore/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"SOL_MARS_CYDONIA" : {
"description" : "",
"message" : "Home of the core systems number one gravball team, the Little Green Men."
}
}
4 changes: 2 additions & 2 deletions data/lang/ui-core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,7 @@
},
"STATION_DOCKS": {
"description": "Information shown in the station lobby, for total number of docking pads",
"message": "Our total capacity is {total_docking_pads} docking pads."
"message": "Your ship is docked on pad {shipbay} out of {bays} docking pads."
Copy link
Contributor

@bszlrd bszlrd Sep 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea! Is the "out of bays" part necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know but see the diff, how many bays there are in the station was all there was before, I only added the shipbay

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, then I realized that you replace the line, not adding another about the pads. Sorry

},
"STATION_LOCAL_GRAVITY": {
"description": "",
Expand Down Expand Up @@ -1925,7 +1925,7 @@
},
"TECH_CERTIFIED_MILITARY": {
"description": "Lobby screen shows the tech level of the station",
"message": "This installation holds a military technology clearance."
"message": "This installation holds a military technology certificate."
},
"TEXTURE_COMPRESSION": {
"description": "",
Expand Down
17 changes: 16 additions & 1 deletion data/libs/SpaceStation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,23 @@ function SpaceStation:Constructor()
-- Use a variation of the space station seed itself to ensure consistency
local rand = Rand.New(self.seed .. '-techLevel')
local techLevel = rand:Integer(1, 6) + rand:Integer(0,6)
if Game.system.faction ~= nil and Game.system.faction.hasHomeworld and Game.system.faction.homeworld == self.path:GetSystemBody().parent.path then
local isHomeworld = 0
if Game.system.faction ~= nil and Game.system.faction.hasHomeworld and self.path:IsSameSystem(Game.system.faction.homeworld) then
techLevel = math.max(techLevel, 6) -- bump it upto at least 6 if it's a homeworld like Earth
isHomeworld = 1
end
-- cap the techlevel lower end based on the planets population
techLevel = math.max(techLevel, math.min(math.floor(self.path:GetSystemBody().parent.population * 0.5), 11))
self:setprop("techLevel", techLevel)
self:setprop("isHomeworld", isHomeworld)
local props = self:GetPropertyDefaults()
if props then
for k,v in pairs(props) do
if k and v then
self:setprop(k, v)
end
end
end
end

local equipmentStock = {}
Expand Down Expand Up @@ -141,6 +152,10 @@ end
--
function SpaceStation:GetEquipmentStock (e)
assert(self:exists())
if not equipmentStock or not equipmentStock[self] or not equipmentStock[self][e] then
print("equipmentStock is incomplete/missing")
return 0
end
return equipmentStock[self][e] or 0
end

Expand Down
50 changes: 26 additions & 24 deletions data/pigui/modules/station-view/01-lobby.lua
Original file line number Diff line number Diff line change
Expand Up @@ -228,28 +228,24 @@ end

local function drawPlayerInfo()
local station = Game.player:GetDockedWith()
if not station or not shipDef then return end

if(not (station and shipDef)) then return end

local tech_certified

if station.techLevel == 11 then
tech_certified = l.TECH_CERTIFIED_MILITARY
else
tech_certified = string.interp(l.TECH_CERTIFIED, { tech_level = station.techLevel})
end

local station_docks = string.interp(l.STATION_DOCKS, { total_docking_pads = string.format("%d", station.numDocks),})
local substrings = { shipbay = station:GetAssignedBayNumber(Game.player),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bays go from 1 up so I think this should probably be:
shipbay = station:GetAssignedBayNumber(Game.player) + 1

bays = string.format("%d", station.numDocks),
tech_level = station.techLevel }

local tech_certified = (station.techLevel >= 11) and l.TECH_CERTIFIED_MILITARY or string.interp(l.TECH_CERTIFIED, substrings)
local station_docks = string.interp(l.STATION_DOCKS, substrings)
local orbit_period = station.path:GetSystemBody().orbitPeriod

local station_frameBody = Space.GetBody(station.path:GetSystemBody().parent.index)
local local_gravity_pressure = ""
if station.type == "STARPORT_SURFACE" then
if station.path:GetSystemBody().parent.hasAtmosphere then
local_gravity_pressure = string.format(l.STATION_LOCAL_GRAVITY_PRESSURE, (station.path:GetSystemBody().parent.gravity/9.8), station_frameBody:GetAtmosphericState(station))
local local_conditions = ""
if station.isGroundStation then
local myBody = station.path:GetSystemBody()
if myBody.parent.hasAtmosphere then
local parentBody = Space.GetBody(myBody.parent.index)
local_conditions = string.format(l.STATION_LOCAL_GRAVITY_PRESSURE, (myBody.parent.gravity/9.8), parentBody:GetAtmosphericState(station))
else
local_gravity_pressure = string.format(l.STATION_LOCAL_GRAVITY, (station.path:GetSystemBody().parent.gravity/9.8))
local_conditions = string.format(l.STATION_LOCAL_GRAVITY, (myBody.parent.gravity/9.8))
end
end

Expand All @@ -266,16 +262,22 @@ local function drawPlayerInfo()
local infoColumnWidth = conReg.x - widgetSizes.faceSize.x - widgetSizes.windowPadding.x*3
local lobbyMenuHeight = widgetSizes.buttonSizeBase.y*3 + widgetSizes.itemSpacing.y*3 + widgetSizes.windowPadding.y*2
local lobbyMenuAtBottom = (conReg.y - widgetSizes.faceSize.y > lobbyMenuHeight + widgetSizes.windowPadding.x*2)

local tabLines = { { tech_certified, "" }, { station_docks, "" } }
if station_orbit_info ~= "" then
table.insert(tabLines, { station_orbit_info, "" })
end
if local_conditions ~= "" then
table.insert(tabLines, { local_conditions, "" })
end
ui.child("Wrapper", Vector2(0, lobbyMenuAtBottom and -lobbyMenuHeight or 0), {}, function()
ui.child("PlayerShipFuel", Vector2(infoColumnWidth, 0), {"AlwaysUseWindowPadding"}, function()
local curPos = ui.getCursorPos()
textTable.withHeading(station.label, orbiteer.xlarge, {
{ tech_certified, "" },
{ station_docks, "" },
{ station_orbit_info, "" },
{ local_gravity_pressure, ""},
})
textTable.withHeading(station.label, orbiteer.xlarge, tabLines )
if station.lore then
local lorelang = Lang.GetResource("lore")
ui.separator()
ui.text(lorelang[station.lore])
end

if not lobbyMenuAtBottom then
lobbyMenu(Vector2(curPos.x, conReg.y - lobbyMenuHeight))
Expand Down
8 changes: 8 additions & 0 deletions data/world/stations/SCC#0000000012.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"techLevel" : {
"value" : "10"
},
"lore" : {
"value" : "SOL_MARS_CYDONIA"
}
}
71 changes: 68 additions & 3 deletions src/lua/LuaSpaceStation.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

#include "Json.h"
#include "LuaConstants.h"
#include "LuaObject.h"
#include "LuaUtils.h"
#include "Ship.h"
#include "SpaceStation.h"
#include "galaxy/SystemBody.h"

/*
* Class: SpaceStation
Expand Down Expand Up @@ -149,6 +151,68 @@ static int l_spacestation_get_nearby_traffic(lua_State *l)
return 1;
}

/*
* Method: GetPropertyDefaults
*
* Set properties that should exist for spacestations to defaults or
* values loaded from json files
*
* > station:GetPropertyDefaults()
*
* Returns:
* table of properties
*
* Availability:
*
* Sept 2021
*
* Status:
*
* experimental
*/
static int l_spacestation_get_property_defaults(lua_State *l)
{
SpaceStation *station = static_cast<SpaceStation *>(LuaObject<Body>::CheckFromLua(1));
const SystemBody *body = station->GetSystemBody();
const SystemPath sp = body->GetPath();

lua_newtable(l);

/* No known (or licensed) human settlements further out than 100 sectors outwards,
a single byte (or hex FF) for each dimension is enough for a license number */
std::string stationID(100, '\0');
std::snprintf(&stationID[0], 100, "SCC#%02X%02X%02X%02X%02X", sp.sectorX, sp.sectorY, sp.sectorZ, sp.systemIndex, sp.bodyIndex);

pi_lua_settable(l, "stationID", stationID.c_str());
pi_lua_settable(l, "visualID", stationID.c_str());

/* try to load moar attributes from world station predefinitions
values from json may override default values */
std::string propFile(100, '\0');
std::snprintf(&propFile[0], 100, "world/stations/%s.json", stationID.c_str());
Output("Looking for station presets for '%s' in '%s'\n", station->GetLabel().c_str(), propFile.c_str());
Json preset = JsonUtils::LoadJsonDataFile(propFile);

for (Json::iterator prop = preset.begin(); prop != preset.end(); ++prop) {
const std::string token = prop.key();
if (token.empty()) {
continue;
}
/* if (!valid_token(token)) { continue; } */

Json val = prop.value()["value"];
if (val.is_null()) {
continue;
}
if (!val.is_string()) {
continue;
}

pi_lua_settable(l, token.c_str(), std::string(val).c_str());
}
return 1;
}

/*
* Attribute: numDocks
*
Expand Down Expand Up @@ -218,17 +282,18 @@ void LuaObject<SpaceStation>::RegisterClass()
const char *l_parent = "ModelBody";

static const luaL_Reg l_methods[] = {
{ "GetGroundPosition", l_spacestation_get_ground_position },
{ "RequestDockingClearance", l_spacestation_request_docking_clearance },
{ "GetAssignedBayNumber", l_spacestation_get_assigned_bay_number },
{ "GetGroundPosition", l_spacestation_get_ground_position },
{ "GetNearbyTraffic", l_spacestation_get_nearby_traffic },
{ "GetPropertyDefaults", l_spacestation_get_property_defaults },
{ "RequestDockingClearance", l_spacestation_request_docking_clearance },

{ 0, 0 }
};

static luaL_Reg l_attrs[] = {
{ "numDocks", l_spacestation_attr_num_docks },
{ "isGroundStation", l_spacestation_attr_is_ground_station },
{ "numDocks", l_spacestation_attr_num_docks },
{ "numShipsDocked", l_spacestation_attr_num_ships_docked },

{ 0, 0 }
Expand Down