diff --git a/EmptyEpsilon.cbp b/EmptyEpsilon.cbp index b60696b428..50477a3246 100644 --- a/EmptyEpsilon.cbp +++ b/EmptyEpsilon.cbp @@ -462,6 +462,8 @@ + + diff --git a/scripts/science_db.lua b/scripts/science_db.lua new file mode 100644 index 0000000000..aa38e2ce3d --- /dev/null +++ b/scripts/science_db.lua @@ -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.]]) diff --git a/src/crewScienceUI.cpp b/src/crewScienceUI.cpp index 0c4930664f..a48a2566fb 100644 --- a/src/crewScienceUI.cpp +++ b/src/crewScienceUI.cpp @@ -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; } @@ -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) @@ -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 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 entry = database->items[science_sub_selection]; + y = 100; + for(unsigned int n=0; nkeyValuePairs.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 ship_template; - std::vector template_names = ShipTemplate::getPlayerTemplateNameList(); - std::sort(template_names.begin(), template_names.end()); - int nr = 0; - for(unsigned int n=0; nradius)), 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; nbeams[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; } } @@ -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; } } diff --git a/src/crewScienceUI.h b/src/crewScienceUI.h index 1e00b4eddd..df6ca4ed82 100644 --- a/src/crewScienceUI.h +++ b/src/crewScienceUI.h @@ -3,20 +3,12 @@ #include "crewUI.h" -enum ScienceDatabaseType -{ - SDT_None, - SDT_Factions, - SDT_Ships, - SDT_Weapons -}; - class CrewScienceUI : public CrewUI { P 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; diff --git a/src/main.cpp b/src/main.cpp index df84259adf..0469a45a14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "factionInfo.h" #include "spaceObject.h" #include "packResourceProvider.h" +#include "scienceDatabase.h" #include "main.h" #ifdef __APPLE__ @@ -157,6 +158,12 @@ int main(int argc, char** argv) P factionInfoScript = new ScriptObject("factionInfo.lua"); if (factionInfoScript) factionInfoScript->destroy(); + + fillDefaultDatabaseData(); + + P scienceInfoScript = new ScriptObject("science_db.lua"); + if (scienceInfoScript) + scienceInfoScript->destroy(); returnToMainMenu();