Skip to content

Commit

Permalink
Store the science data in a seperate science database, to allow for e…
Browse files Browse the repository at this point in the history
…asier customization.
  • Loading branch information
daid committed Feb 16, 2015
1 parent 46c826c commit fe38cd6
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 200 deletions.
2 changes: 2 additions & 0 deletions EmptyEpsilon.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@
<Unit filename="src/playerSpaceship.h" />
<Unit filename="src/repairCrew.cpp" />
<Unit filename="src/repairCrew.h" />
<Unit filename="src/scienceDatabase.cpp" />
<Unit filename="src/scienceDatabase.h" />
<Unit filename="src/serverCreationScreen.cpp" />
<Unit filename="src/serverCreationScreen.h" />
<Unit filename="src/shipSelectionScreen.cpp" />
Expand Down
37 changes: 37 additions & 0 deletions scripts/science_db.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--[[
Everything in the science database files is just readable data for the science officer.
This data does not effect the game in any other way and just contributes to the lore.
--]]
weapons = ScienceDatabase():setName('Weapons')
item = weapons:addEntry('Homing missile')
item:addKeyValue('Range', '6km')
item:addKeyValue('Damage', '30')
item:setLongDescription([[The standard homing missile is the default weapon of choice for many ships]])

item = weapons:addEntry('Nuke')
item:addKeyValue('Range', '4.8km')
item:addKeyValue('Blast radius', '1km')
item:addKeyValue('Damage at center', '160')
item:addKeyValue('Damage at edge', '30')
item:setLongDescription([[The heavy nuke is a fearsome weapon which is known to take out multiple ships in a single shot.
Some captains question the use of these weapons, due to the ease of friendly-fire incidents.
And unknown prolonged effect on the crew of using these weapons in space.]])

item = weapons:addEntry('Mine')
item:addKeyValue('Drop distance', '1.2km')
item:addKeyValue('Trigger distance', '600m')
item:addKeyValue('Blast radius', '1km')
item:addKeyValue('Damage at center', '160')
item:addKeyValue('Damage at edge', '30')
item:setLongDescription([[Mines are often placed in a defensive perimeter around stations.
There are also old mine fields scattered around the universe from older wars.
Some fearless captains have used mines as offensive weapons. But this is with great risk]])

item = weapons:addEntry('EMP')
item:addKeyValue('Range', '4.8km')
item:addKeyValue('Blast radius', '1km')
item:addKeyValue('Damage at center', '160')
item:addKeyValue('Damage at edge', '30')
item:setLongDescription([[The EMP is a shield-only damaging weapon It matches the heavy nuke in damage but does no hull damage.
The EMP missile is smaller and easier to storage then the heavy nuke.
And thus many captains preferer it's use over nukes.]])
220 changes: 29 additions & 191 deletions src/crewScienceUI.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "crewScienceUI.h"
#include "scienceDatabase.h"
#include "gameGlobalInfo.h"

CrewScienceUI::CrewScienceUI()
{
science_radar_zoom = 1;
science_show_radar = true;
science_database_type = SDT_None;
science_database_selection = -1;
science_sub_selection = -1;
science_description_line_nr = 0;
}
Expand Down Expand Up @@ -55,33 +56,6 @@ void CrewScienceUI::onCrewUI()
if (scan_ghost[n].object == scienceTarget)
target_position = scan_ghost[n].position;
drawUILine(radar_center + (target_position - my_spaceship->getPosition()) / radarDistance * 400.0f + sf::Vector2f(16.0f, 0), sf::Vector2f(getWindowSize().x - 270, 215), getWindowSize().x - 320);
/*
sf::Vector2f end_point_1(getWindowSize().x - 300, 215);
sf::Vector2f end_point_2(getWindowSize().x - 270, 215);
sf::Vector2f start_point = radar_center + (target_position - my_spaceship->getPosition()) / radarDistance * 400.0f;
start_point.x += 16;
if (end_point_1.x - fabs(start_point.y - end_point_1.y) > start_point.x + 16)
{
sf::VertexArray target_line(sf::LinesStrip, 4);
target_line[0].position = start_point;
target_line[1].position = sf::Vector2f(end_point_1.x - fabs(start_point.y - end_point_1.y), start_point.y);
target_line[2].position = end_point_1;
target_line[3].position = end_point_2;
target_line[0].color = target_line[1].color = target_line[2].color = target_line[3].color = sf::Color(255, 255, 255, 128);
getRenderTarget()->draw(target_line);
}else{
sf::VertexArray target_line(sf::LinesStrip, 6);
target_line[0].position = start_point;
target_line[1].position = start_point + sf::Vector2f(16, 0);
target_line[2].position = sf::Vector2f(end_point_1.x - 16, start_point.y - (end_point_1.x - 16 - start_point.x - 16));
target_line[3].position = end_point_1 + sf::Vector2f(-16, 16);
target_line[4].position = end_point_1;
target_line[5].position = end_point_2;
target_line[0].color = target_line[1].color = target_line[2].color = target_line[3].color = target_line[4].color = target_line[5].color = sf::Color(255, 255, 255, 128);
getRenderTarget()->draw(target_line);
}
*/
}

if (my_spaceship->scanning_delay > 0.0)
Expand Down Expand Up @@ -173,183 +147,47 @@ void CrewScienceUI::onCrewUI()
else if (science_radar_zoom == 10 && button(sf::FloatRect(getWindowSize().x - 490, 820, 200, 50), "Zoom: 10x", 30))
science_radar_zoom = 1;
} else {
if (toggleButton(sf::FloatRect(20, 100, 200, 50), science_database_type == SDT_Factions, "Factions", 30))
{
science_database_type = SDT_Factions;
science_sub_selection = -1;
}
if (toggleButton(sf::FloatRect(20, 150, 200, 50), science_database_type == SDT_Ships, "Ship types", 30))
{
science_database_type = SDT_Ships;
science_sub_selection = -1;
}
if (toggleButton(sf::FloatRect(20, 200, 200, 50), science_database_type == SDT_Weapons, "Weapons", 30))
float y = 100;
int idx = 0;
foreach(ScienceDatabase, sd, ScienceDatabase::scienceDatabaseList)
{
science_database_type = SDT_Weapons;
science_sub_selection = -1;
if (toggleButton(sf::FloatRect(20, y, 200, 50), science_database_selection == idx, sd->name, 30))
{
science_database_selection = idx;
science_sub_selection = -1;
}
idx++;
y += 50;
}
switch(science_database_type)
if (science_database_selection > -1 && science_database_selection < int(ScienceDatabase::scienceDatabaseList.size()))
{
case SDT_None:
break;
case SDT_Factions:
for(unsigned int n = 0; n < factionInfo.size(); n++)
P<ScienceDatabase> database = ScienceDatabase::scienceDatabaseList[science_database_selection];
y = 100;
idx = 0;
foreach(ScienceDatabaseEntry, entry, database->items)
{
if (toggleButton(sf::FloatRect(240, 100 + n * 50, 250, 50), science_sub_selection == int(n), factionInfo[n]->name, 30))
if (toggleButton(sf::FloatRect(240, y, 250, 50), science_sub_selection == idx, entry->name, 30))
{
science_sub_selection = n;
science_sub_selection = idx;
science_description_line_nr = 0;
}
idx++;
y += 50;
}
if (science_sub_selection > -1)
if (science_sub_selection > -1 && science_sub_selection < int(database->items.size()))
{
float y = 100;
for(unsigned int n=0; n < factionInfo.size(); n++)
P<ScienceDatabaseEntry> entry = database->items[science_sub_selection];
y = 100;
for(unsigned int n=0; n<entry->keyValuePairs.size(); n++)
{
if (int(n) == science_sub_selection) continue;

string stance = "Neutral";
switch(factionInfo[science_sub_selection]->states[n])
{
case FVF_Neutral: stance = "Neutral"; break;
case FVF_Enemy: stance = "Enemy"; break;
case FVF_Friendly: stance = "Friendly"; break;
}
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, factionInfo[n]->name, stance, 20);
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, entry->keyValuePairs[n].key, entry->keyValuePairs[n].value, 20);
y += 40;
}

science_description_line_nr = scrolltextbox(sf::FloatRect(500, y, 600, 550), factionInfo[science_sub_selection]->description, science_description_line_nr, AlignTopLeft, 20);
}
break;
case SDT_Ships:
{
float y = 100;
P<ShipTemplate> ship_template;
std::vector<string> template_names = ShipTemplate::getPlayerTemplateNameList();
std::sort(template_names.begin(), template_names.end());
int nr = 0;
for(unsigned int n=0; n<template_names.size(); n++)
{
if (toggleButton(sf::FloatRect(240, y, 250, 50), science_sub_selection == nr, template_names[n], 30))
science_sub_selection = nr;
if (science_sub_selection == nr)
ship_template = ShipTemplate::getTemplate(template_names[n]);
y += 50;
nr ++;
}
template_names = ShipTemplate::getTemplateNameList();
std::sort(template_names.begin(), template_names.end());
for(unsigned int n=0; n<template_names.size(); n++)
{
if (toggleButton(sf::FloatRect(240, y, 250, 50), science_sub_selection == nr, template_names[n], 30))
science_sub_selection = nr;
if (science_sub_selection == nr)
ship_template = ShipTemplate::getTemplate(template_names[n]);
y += 50;
nr ++;
}
if (ship_template)
{
y = 100;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Size", string(int(ship_template->radius)), 20); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Shield", string(int(ship_template->frontShields)) + "/" + string(int(ship_template->rearShields)), 20); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Hull", string(int(ship_template->hull)), 20); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Move speed", string(int(ship_template->impulseSpeed)), 20); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Turn speed", string(int(ship_template->turnSpeed)), 20); y += 40;
if (ship_template->warpSpeed > 0.0)
{
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Has warp drive", "True", 20); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Warp speed", string(int(ship_template->warpSpeed)), 20); y += 40;
}
if (ship_template->jumpDrive)
{
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Has jump drive", "True", 20); y += 40;
}
for(int n=0; n<maxBeamWeapons; n++)
{
if (ship_template->beams[n].range > 0)
{
string name = "?";
if (ship_template->beams[n].direction < 45 || ship_template->beams[n].direction > 315)
name = "Front";
else if (ship_template->beams[n].direction > 45 && ship_template->beams[n].direction < 135)
name = "Right";
else if (ship_template->beams[n].direction > 135 && ship_template->beams[n].direction < 225)
name = "Rear";
else if (ship_template->beams[n].direction > 225 && ship_template->beams[n].direction < 315)
name = "Left";
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, name + " beam weapon", string(ship_template->beams[n].damage / ship_template->beams[n].cycle_time, 2) + " DPS", 20); y += 40;
}
}
if (ship_template->weapon_tubes > 0)
{
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Missile tubes", string(ship_template->weapon_tubes), 20); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Missile load time", string(int(ship_template->tube_load_time)), 20); y += 40;
}
for(int n=0; n < MW_Count; n++)
{
if (ship_template->weapon_storage[n] > 0)
{
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Storage " + getMissileWeaponName(EMissileWeapons(n)), string(ship_template->weapon_storage[n]), 20); y += 40;
}
}
}
}
break;
case SDT_Weapons:
{
float y = 100;
int nr = 0;
if (toggleButton(sf::FloatRect(240, y, 250, 50), science_sub_selection == nr, "Homing missile", 30))
science_sub_selection = nr;
y += 50; nr ++;

if (toggleButton(sf::FloatRect(240, y, 250, 50), science_sub_selection == nr, "Nuke", 30))
science_sub_selection = nr;
y += 50; nr ++;

if (toggleButton(sf::FloatRect(240, y, 250, 50), science_sub_selection == nr, "Mine", 30))
science_sub_selection = nr;
y += 50; nr ++;

if (toggleButton(sf::FloatRect(240, y, 250, 50), science_sub_selection == nr, "EMP", 30))
science_sub_selection = nr;
y += 50; nr ++;

y = 100;
switch(science_sub_selection)
if (entry->longDescription.length() > 0)
{
case 0://Homing missile
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Range", "6km", 20.0f); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Damage", "30", 20.0f); y += 40;
textbox(sf::FloatRect(500, y, 400, 400), "The standard homing missile is the\ndefault weapon of choice for many ships", AlignTopLeft, 20);
break;
case 1://Nuke
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Range", "4.8km", 20.0f); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Blast radius", "1km", 20.0f); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Maximal Damage", "160", 20.0f); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Minimal Damage", "30", 20.0f); y += 40;
textbox(sf::FloatRect(500, y, 400, 400), "The heavy nuke is a fearsome weapon\nwhich is known to take out multiple\nships in a single shot.\n\nSome captains question the use of these\nweapons, due to the ease of friendly-fire\nincidents. And unknown prolonged\neffect on the crew of using these\nweapons in space.", AlignTopLeft, 20);
break;
case 2://Mine
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Drop distance", "1.2km", 20.0f); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Trigger distance", "0.6km", 20.0f); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Blast radius", "1km", 20.0f); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Maximal Damage", "160", 20.0f); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Minimal Damage", "30", 20.0f); y += 40;
textbox(sf::FloatRect(500, y, 400, 400), "Mines are often placed in a defensive\nperimeter around stations\n\nThere are also old mine fields scattered\naround the universe from older wars.\n\nSome fearless captains have used mines\nas offensive weapons.\nBut this is with great risk.", AlignTopLeft, 20);
break;
case 3://EMP
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Range", "4.8km", 20.0f); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Blast radius", "1km", 20.0f); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Maximal Damage", "160", 20.0f); y += 40;
keyValueDisplay(sf::FloatRect(500, y, 400, 40), 0.7, "Minimal Damage", "30", 20.0f); y += 40;
textbox(sf::FloatRect(500, y, 400, 400), "The EMP is a shield-only damaging\nweapon It matches the heavy nuke in\ndamage but does no hull damage.\n\nThe EMP missile is smaller and easier\nto storage then the heavy nuke.\nAnd thus many captains preferer it's use\nover nukes.", AlignTopLeft, 20);
break;
science_description_line_nr = scrolltextbox(sf::FloatRect(500, y, 600, 800 - y), entry->longDescription, science_description_line_nr, AlignTopLeft, 20);
}
}
break;
}
}

Expand All @@ -359,6 +197,6 @@ void CrewScienceUI::onCrewUI()
if (toggleButton(sf::FloatRect(20, 820, 200, 50), !science_show_radar, "Database", 30))
{
science_show_radar = false;
science_database_type = SDT_None;
science_database_selection = -1;
}
}
10 changes: 1 addition & 9 deletions src/crewScienceUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@

#include "crewUI.h"

enum ScienceDatabaseType
{
SDT_None,
SDT_Factions,
SDT_Ships,
SDT_Weapons
};

class CrewScienceUI : public CrewUI
{
P<SpaceObject> scienceTarget;
int science_radar_zoom;
bool science_show_radar;
ScienceDatabaseType science_database_type;
int science_database_selection;
int science_sub_selection;
int science_description_line_nr;

Expand Down
7 changes: 7 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "factionInfo.h"
#include "spaceObject.h"
#include "packResourceProvider.h"
#include "scienceDatabase.h"
#include "main.h"

#ifdef __APPLE__
Expand Down Expand Up @@ -157,6 +158,12 @@ int main(int argc, char** argv)
P<ScriptObject> factionInfoScript = new ScriptObject("factionInfo.lua");
if (factionInfoScript)
factionInfoScript->destroy();

fillDefaultDatabaseData();

P<ScriptObject> scienceInfoScript = new ScriptObject("science_db.lua");
if (scienceInfoScript)
scienceInfoScript->destroy();

returnToMainMenu();

Expand Down

0 comments on commit fe38cd6

Please sign in to comment.