From c2bbef21e3ac507a8f6ceea8662ec3f988e9a4d9 Mon Sep 17 00:00:00 2001 From: ClarkeCode Date: Fri, 23 Jun 2023 02:55:52 -0400 Subject: Fragile loading of goods, cascading wide string changes --- src/headless/main.cpp | 2 +- src/openvic/GameManager.cpp | 2 +- src/openvic/GameManager.hpp | 2 +- src/openvic/Simulation.hpp | 6 +- src/openvic/Types.cpp | 15 +-- src/openvic/Types.hpp | 29 +++--- src/openvic/dataloader/Dataloader.cpp | 187 ++++++++++++++++++++++++++++++++++ src/openvic/dataloader/Dataloader.hpp | 4 +- src/openvic/economy/Good.cpp | 12 +-- src/openvic/economy/Good.hpp | 8 +- src/openvic/map/Building.cpp | 6 +- src/openvic/map/Building.hpp | 6 +- src/openvic/map/Map.cpp | 82 +++++++-------- src/openvic/map/Map.hpp | 20 ++-- src/openvic/map/Province.cpp | 12 +-- src/openvic/map/Province.hpp | 8 +- src/openvic/map/Region.cpp | 2 +- src/openvic/map/Region.hpp | 2 +- 18 files changed, 301 insertions(+), 104 deletions(-) create mode 100644 src/openvic/dataloader/Dataloader.cpp diff --git a/src/headless/main.cpp b/src/headless/main.cpp index 70a57a9..0ce0eda 100644 --- a/src/headless/main.cpp +++ b/src/headless/main.cpp @@ -9,7 +9,7 @@ int main() { std::cout << "HEADLESS SIMULATION" << std::endl; - std::string vic2FolderLocation = ""; + std::string vic2FolderLocation = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Victoria 2"; if (vic2FolderLocation.length() <= 0) { std::cout << "Path to Victoria 2 folder not specified. Manually specify location: "; std::cin >> vic2FolderLocation; diff --git a/src/openvic/GameManager.cpp b/src/openvic/GameManager.cpp index b2a9c27..0be026d 100644 --- a/src/openvic/GameManager.cpp +++ b/src/openvic/GameManager.cpp @@ -42,7 +42,7 @@ Date const& GameManager::get_today() const { return today; } -return_t GameManager::expand_building(index_t province_index, std::string const& building_type_identifier) { +return_t GameManager::expand_building(index_t province_index, ovstring const& building_type_identifier) { set_needs_update(); Province* province = map.get_province_by_index(province_index); if (province == nullptr) return FAILURE; diff --git a/src/openvic/GameManager.hpp b/src/openvic/GameManager.hpp index b8dfbf6..913dc50 100644 --- a/src/openvic/GameManager.hpp +++ b/src/openvic/GameManager.hpp @@ -29,6 +29,6 @@ namespace OpenVic { return_t setup(); Date const& get_today() const; - return_t expand_building(index_t province_index, std::string const& building_type_identifier); + return_t expand_building(index_t province_index, ovstring const& building_type_identifier); }; } diff --git a/src/openvic/Simulation.hpp b/src/openvic/Simulation.hpp index b0c2a19..e03a1ca 100644 --- a/src/openvic/Simulation.hpp +++ b/src/openvic/Simulation.hpp @@ -1,5 +1,9 @@ #pragma once +#include "economy/Good.hpp" namespace OpenVic { - class Simulation {}; + class Simulation { + public: + GoodManager goodManager; + }; } \ No newline at end of file diff --git a/src/openvic/Types.cpp b/src/openvic/Types.cpp index ab5d12a..9ea9c47 100644 --- a/src/openvic/Types.cpp +++ b/src/openvic/Types.cpp @@ -6,26 +6,27 @@ using namespace OpenVic; -HasIdentifier::HasIdentifier(std::string const& new_identifier) : identifier { new_identifier } { +HasIdentifier::HasIdentifier(ovstring const& new_identifier) : identifier { new_identifier } { assert(!identifier.empty()); } -std::string const& HasIdentifier::get_identifier() const { +ovstring const& HasIdentifier::get_identifier() const { return identifier; } HasColour::HasColour(colour_t const new_colour, bool can_be_null) : colour(new_colour) { - assert((can_be_null || colour != NULL_COLOUR) && colour <= MAX_COLOUR_RGB); + // assert(colour <= MAX_COLOUR_RGB); + assert((can_be_null || colour != NULL_COLOUR)); } colour_t HasColour::get_colour() const { return colour; } -std::string HasColour::colour_to_hex_string(colour_t const colour) { - std::ostringstream stream; - stream << std::hex << std::setfill('0') << std::setw(6) << colour; +ovstring HasColour::colour_to_hex_string(colour_t const colour) { + std::wostringstream stream; + stream << std::hex << std::setfill(L'0') << std::setw(6) << colour; return stream.str(); } -std::string HasColour::colour_to_hex_string() const { +ovstring HasColour::colour_to_hex_string() const { return colour_to_hex_string(colour); } diff --git a/src/openvic/Types.hpp b/src/openvic/Types.hpp index fe22dc9..30c04ff 100644 --- a/src/openvic/Types.hpp +++ b/src/openvic/Types.hpp @@ -25,10 +25,15 @@ namespace OpenVic { constexpr colour_t float_to_alpha_value(float a) { return float_to_colour_byte(a) << 24; } + constexpr colour_t rgba_to_colour(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 0xFF) { + return (a << 24) | (r << 16) | (g << 8) | b; + } using index_t = uint16_t; static constexpr index_t NULL_INDEX = 0, MAX_INDEX = 0xFFFF; + using ovstring = std::wstring; + // TODO: price_t must be changed to a fixed-point numeric type before multiplayer using price_t = double; static constexpr price_t NULL_PRICE = 0.0; @@ -43,10 +48,10 @@ namespace OpenVic { * IdentifierRegistry instance. */ class HasIdentifier { - const std::string identifier; + const ovstring identifier; protected: - HasIdentifier(std::string const& new_identifier); + HasIdentifier(ovstring const& new_identifier); public: HasIdentifier(HasIdentifier const&) = delete; @@ -54,7 +59,7 @@ namespace OpenVic { HasIdentifier& operator=(HasIdentifier const&) = delete; HasIdentifier& operator=(HasIdentifier&&) = delete; - std::string const& get_identifier() const; + ovstring const& get_identifier() const; }; /* @@ -73,8 +78,8 @@ namespace OpenVic { HasColour& operator=(HasColour&&) = delete; colour_t get_colour() const; - std::string colour_to_hex_string() const; - static std::string colour_to_hex_string(colour_t const colour); + ovstring colour_to_hex_string() const; + static ovstring colour_to_hex_string(colour_t const colour); }; /* @@ -85,7 +90,7 @@ namespace OpenVic { */ template::value>::type* = nullptr> class IdentifierRegistry { - using identifier_index_map_t = std::map; + using identifier_index_map_t = std::map; const std::string name; std::vector items; @@ -96,12 +101,12 @@ namespace OpenVic { IdentifierRegistry(std::string const& new_name) : name(new_name) {} return_t add_item(T&& item) { if (locked) { - Logger::error("Cannot add item to the ", name, " registry - locked!"); + // Logger::error("Cannot add item to the ", name, " registry - locked!"); return FAILURE; } T const* old_item = get_item_by_identifier(item.get_identifier()); if (old_item != nullptr) { - Logger::error("Cannot add item to the ", name, " registry - an item with the identifier \"", item.get_identifier(), "\" already exists!"); + // Logger::error("Cannot add item to the ", name, " registry - an item with the identifier \"", item.get_identifier(), "\" already exists!"); return FAILURE; } identifier_index_map[item.get_identifier()] = items.size(); @@ -110,10 +115,10 @@ namespace OpenVic { } void lock(bool log = true) { if (locked) { - Logger::error("Failed to lock ", name, " registry - already locked!"); + // Logger::error("Failed to lock ", name, " registry - already locked!"); } else { locked = true; - if (log) Logger::info("Locked ", name, " registry after registering ", get_item_count(), " items"); + // if (log) Logger::info("Locked ", name, " registry after registering ", get_item_count(), " items"); } } bool is_locked() const { @@ -127,12 +132,12 @@ namespace OpenVic { size_t get_item_count() const { return items.size(); } - T* get_item_by_identifier(std::string const& identifier) { + T* get_item_by_identifier(ovstring const& identifier) { const identifier_index_map_t::const_iterator it = identifier_index_map.find(identifier); if (it != identifier_index_map.end()) return &items[it->second]; return nullptr; } - T const* get_item_by_identifier(std::string const& identifier) const { + T const* get_item_by_identifier(ovstring const& identifier) const { const identifier_index_map_t::const_iterator it = identifier_index_map.find(identifier); if (it != identifier_index_map.end()) return &items[it->second]; return nullptr; diff --git a/src/openvic/dataloader/Dataloader.cpp b/src/openvic/dataloader/Dataloader.cpp new file mode 100644 index 0000000..5c00e78 --- /dev/null +++ b/src/openvic/dataloader/Dataloader.cpp @@ -0,0 +1,187 @@ +#include "Dataloader.hpp" +#include +#include +#include +#include "../Types.hpp" + +using namespace std; +using namespace std::filesystem; +using namespace OpenVic; + + +#include +//WARNING!! +//The following functions are temporary and highly fragile +//If you have a weak constitution or have a heart condition, do not look at the following functions +namespace compatibility { + //Helper function + void eatWhitespaceComments(wifstream& stream) { + while (stream && ( + stream.peek() == L' ' || + stream.peek() == L'\t' || + stream.peek() == L'\r' || + stream.peek() == L'\n' || + stream.peek() == L'#')) { + + if (stream.peek() == L'#') { + stream.ignore(numeric_limits::max(), L'\n'); + } + else { + stream.ignore(1); + } + } + } + + //Helper function + wstring getNextWord(wifstream& stream) { + std::wstringstream ss; + wchar_t wc; + + eatWhitespaceComments(stream); + while (stream && + stream.peek() != L' ' && + stream.peek() != L'\t' && + stream.peek() != L'\r' && + stream.peek() != L'\n' && + stream.peek() != L'#') { + stream >> wc; + ss << wc; + } + + eatWhitespaceComments(stream); + return ss.str(); + } + + using MapDefinitions = map>; + MapDefinitions readMapDefinitions(path vic2folder) { + MapDefinitions mp; + wifstream ws = wifstream(vic2folder/path("map")/path("definition.csv"), ios::binary); + + ws.ignore(numeric_limits::max(), L'\n'); + while (ws) { + while (ws && ws.peek() == '#' || ws.peek() == ';' || ws.peek() == '\n' || ws.peek() == '\r') { + ws.ignore(numeric_limits::max(), L'\n'); + } + if (ws.eof()) break; + + int numericId; + int r, g, b; + wstring name; + + ws >> numericId; ws.ignore(); + ws >> r; ws.ignore(); + ws >> g; ws.ignore(); + ws >> b; ws.ignore(); + std::getline(ws, name, L';'); + ws.ignore(numeric_limits::max(), '\n'); + + mp[numericId] = pair(rgba_to_colour(r, g, b), name); + } + return mp; + } + + void readProvinceFile(path provinceFile) { + if (provinceFile.extension() != ".txt") { return; } + // cout << provinceFile.filename() << endl; + } + + void readProvinceFiles(path vic2folder) { + path provinceHistoryPath = vic2folder/path("history")/path("provinces"); + for (directory_entry const& di : recursive_directory_iterator(provinceHistoryPath)) { + if (di.is_directory()) { continue; } + // cout << di << endl; + readProvinceFile(di.path()); + } + } + + void loadGoodsFile(wifstream& file, OpenVic::Simulation& sim) { + while (file) { + wstring category = getNextWord(file); //Load a good category + if (category == L"military_goods") { + category = L"military"; + } + if (category == L"raw_material_goods") { + category = L"raw"; + } + if (category == L"industrial_goods") { + category = L"industrial"; + } + if (category == L"consumer_goods") { + category = L"consumer"; + } + getNextWord(file); //Eat = + getNextWord(file); //Eat { + while (file.peek() != L'}') { //Load a good + wstring goodid = getNextWord(file); + price_t price = 0.0; + bool availableAtStart = true; + bool tradeable = true; + bool currency = true; + bool overseasMaintenance = false; + colour_t colour; + getNextWord(file); //Eat = + getNextWord(file); //Eat { + while (file.peek() != L'}') { //Load good attributes + wstring attribute = getNextWord(file); + getNextWord(file); //Eat = + if (attribute == L"cost") { + file >> price; + } + else if (attribute == L"color") { + getNextWord(file); //Eat { + int r, g, b; + file >> r; + file >> g; + file >> b; + colour = rgba_to_colour(r, g, b); + + getNextWord(file); //Eat } + } + else if (attribute == L"available_from_start") { + availableAtStart = (getNextWord(file) == L"yes"); + } + else if (attribute == L"tradeable") { + tradeable = (getNextWord(file) == L"yes"); + } + else if (attribute == L"money") { + currency = (getNextWord(file) == L"yes"); + } + else if (attribute == L"overseas_penalty") { + overseasMaintenance = (getNextWord(file) == L"yes"); + } + } + getNextWord(file); //Eat } + wcout << goodid <<" "<< category <<" 0x"<< HasColour::colour_to_hex_string(colour) <<" "<< price <<" "<< availableAtStart <<" "<< tradeable <<" "<< currency <<" "<< overseasMaintenance << endl; + sim.goodManager.add_good(goodid, category, colour, price, availableAtStart, tradeable, currency, overseasMaintenance); + } + getNextWord(file); //Eat } + } + } +} + + + + +bool OpenVic::Dataloader::loadDir(std::filesystem::path rootDataFolder, Simulation& sim, LoadingMode loadMode) { + if (loadMode == LoadingMode::DL_COMPATABILITY) { + if (!is_directory(rootDataFolder)) { + return false; + } + + path goods = rootDataFolder/path("common")/path("goods.txt"); + if (!filesystem::exists(goods)) { + wcerr << (goods.c_str()) << " does not exist" << endl; + return false; + } + wifstream goodsf(goods); + cout << "Start loading..." << endl; + compatibility::loadGoodsFile(goodsf, sim); + compatibility::readMapDefinitions(rootDataFolder); + compatibility::readProvinceFiles(rootDataFolder); + cout << "Done loading" << endl; + + + return true; + } + return false; +} diff --git a/src/openvic/dataloader/Dataloader.hpp b/src/openvic/dataloader/Dataloader.hpp index 250d100..b0b756f 100644 --- a/src/openvic/dataloader/Dataloader.hpp +++ b/src/openvic/dataloader/Dataloader.hpp @@ -9,8 +9,6 @@ namespace OpenVic { DL_COMPATABILITY }; - static bool loadDir(std::filesystem::path p, Simulation& sim, LoadingMode loadMode = LoadingMode::DL_COMPATABILITY) { - return true; - } + static bool loadDir(std::filesystem::path p, Simulation& sim, LoadingMode loadMode = LoadingMode::DL_COMPATABILITY); }; } \ No newline at end of file diff --git a/src/openvic/economy/Good.cpp b/src/openvic/economy/Good.cpp index 6d515d5..52b908c 100644 --- a/src/openvic/economy/Good.cpp +++ b/src/openvic/economy/Good.cpp @@ -4,7 +4,7 @@ using namespace OpenVic; -Good::Good(std::string const& new_identifier, std::string const& new_category, colour_t new_colour, price_t new_base_price, +Good::Good(ovstring const& new_identifier, ovstring const& new_category, colour_t new_colour, price_t new_base_price, bool new_default_available, bool new_tradeable, bool new_currency, bool new_overseas_maintenance) : HasIdentifier { new_identifier }, HasColour { new_colour, true }, @@ -17,7 +17,7 @@ Good::Good(std::string const& new_identifier, std::string const& new_category, c assert(base_price > NULL_PRICE); } -std::string const& Good::get_category() const { +ovstring const& Good::get_category() const { return category; } @@ -44,18 +44,18 @@ void Good::reset_to_defaults() { GoodManager::GoodManager() : goods { "goods" } {} -return_t GoodManager::add_good(std::string const& identifier, std::string const& category, colour_t colour, +return_t GoodManager::add_good(ovstring const& identifier, ovstring const& category, colour_t colour, price_t base_price, bool default_available, bool tradeable, bool currency, bool overseas_maintenance) { if (identifier.empty()) { - Logger::error("Invalid good identifier - empty!"); + // Logger::error("Invalid good identifier - empty!"); return FAILURE; } if (category.empty()) { - Logger::error("Invalid good category - empty!"); + // Logger::error("Invalid good category - empty!"); return FAILURE; } if (base_price <= NULL_PRICE) { - Logger::error("Invalid base price for ", identifier, ": ", base_price); + // Logger::error("Invalid base price for ", identifier, ": ", base_price); return FAILURE; } return goods.add_item({ identifier, category, colour, base_price, default_available, tradeable, currency, overseas_maintenance }); diff --git a/src/openvic/economy/Good.hpp b/src/openvic/economy/Good.hpp index 577280d..b75e52c 100644 --- a/src/openvic/economy/Good.hpp +++ b/src/openvic/economy/Good.hpp @@ -19,19 +19,19 @@ namespace OpenVic { friend struct GoodManager; private: - const std::string category; + const ovstring category; const price_t base_price; price_t price; const bool default_available, tradeable, currency, overseas_maintenance; bool available; - Good(std::string const& new_identifier, std::string const& new_category, colour_t new_colour, price_t new_base_price, + Good(ovstring const& new_identifier, ovstring const& new_category, colour_t new_colour, price_t new_base_price, bool new_default_available, bool new_tradeable, bool new_currency, bool new_overseas_maintenance); public: Good(Good&&) = default; - std::string const& get_category() const; + ovstring const& get_category() const; price_t get_base_price() const; price_t get_price() const; bool is_default_available() const; @@ -46,7 +46,7 @@ namespace OpenVic { public: GoodManager(); - return_t add_good(std::string const& identifier, std::string const& category, colour_t colour, price_t base_price, + return_t add_good(ovstring const& identifier, ovstring const& category, colour_t colour, price_t base_price, bool default_available, bool tradeable, bool currency, bool overseas_maintenance); void lock_goods(); void reset_to_defaults(); diff --git a/src/openvic/map/Building.cpp b/src/openvic/map/Building.cpp index 317ccdf..f443286 100644 --- a/src/openvic/map/Building.cpp +++ b/src/openvic/map/Building.cpp @@ -76,7 +76,7 @@ void Building::tick(Date const& today) { } } -BuildingType::BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time) +BuildingType::BuildingType(ovstring const& new_identifier, Building::level_t new_max_level, Timespan new_build_time) : HasIdentifier { new_identifier }, max_level { new_max_level }, build_time { new_build_time } { @@ -94,7 +94,7 @@ Timespan BuildingType::get_build_time() const { BuildingManager::BuildingManager() : building_types { "building types" } {} -return_t BuildingManager::add_building_type(std::string const& identifier, Building::level_t max_level, Timespan build_time) { +return_t BuildingManager::add_building_type(ovstring const& identifier, Building::level_t max_level, Timespan build_time) { if (identifier.empty()) { Logger::error("Invalid building type identifier - empty!"); return FAILURE; @@ -114,7 +114,7 @@ void BuildingManager::lock_building_types() { building_types.lock(); } -BuildingType const* BuildingManager::get_building_type_by_identifier(std::string const& identifier) const { +BuildingType const* BuildingManager::get_building_type_by_identifier(ovstring const& identifier) const { return building_types.get_item_by_identifier(identifier); } diff --git a/src/openvic/map/Building.hpp b/src/openvic/map/Building.hpp index 98c3991..ba711eb 100644 --- a/src/openvic/map/Building.hpp +++ b/src/openvic/map/Building.hpp @@ -61,7 +61,7 @@ namespace OpenVic { const Building::level_t max_level; const Timespan build_time; - BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time); + BuildingType(ovstring const& new_identifier, Building::level_t new_max_level, Timespan new_build_time); public: BuildingType(BuildingType&&) = default; @@ -77,9 +77,9 @@ namespace OpenVic { public: BuildingManager(); - return_t add_building_type(std::string const& identifier, Building::level_t max_level, Timespan build_time); + return_t add_building_type(ovstring const& identifier, Building::level_t max_level, Timespan build_time); void lock_building_types(); - BuildingType const* get_building_type_by_identifier(std::string const& identifier) const; + BuildingType const* get_building_type_by_identifier(ovstring const& identifier) const; return_t generate_province_buildings(Province& province) const; }; } diff --git a/src/openvic/map/Map.cpp b/src/openvic/map/Map.cpp index 2efee32..c7e9693 100644 --- a/src/openvic/map/Map.cpp +++ b/src/openvic/map/Map.cpp @@ -8,14 +8,14 @@ using namespace OpenVic; -Mapmode::Mapmode(index_t new_index, std::string const& new_identifier, colour_func_t new_colour_func) +Mapmode::Mapmode(index_t new_index, ovstring const& new_identifier, colour_func_t new_colour_func) : HasIdentifier { new_identifier }, index { new_index }, colour_func { new_colour_func } { assert(colour_func != nullptr); } -const Mapmode Mapmode::ERROR_MAPMODE { 0, "mapmode_error", [](Map const& map, Province const& province) -> colour_t { return 0xFFFF0000; } }; +const Mapmode Mapmode::ERROR_MAPMODE { 0, L"mapmode_error", [](Map const& map, Province const& province) -> colour_t { return 0xFFFF0000; } }; Mapmode::index_t Mapmode::get_index() const { return index; @@ -29,23 +29,23 @@ Map::Map() : provinces { "provinces" }, regions { "regions" }, mapmodes { "mapmodes" } {} -return_t Map::add_province(std::string const& identifier, colour_t colour) { +return_t Map::add_province(ovstring const& identifier, colour_t colour) { if (provinces.get_item_count() >= MAX_INDEX) { - Logger::error("The map's province list is full - there can be at most ", MAX_INDEX, " provinces"); + // Logger::error("The map's province list is full - there can be at most ", MAX_INDEX, " provinces"); return FAILURE; } if (identifier.empty()) { - Logger::error("Invalid province identifier - empty!"); + // Logger::error("Invalid province identifier - empty!"); return FAILURE; } if (colour == NULL_COLOUR || colour > MAX_COLOUR_RGB) { - Logger::error("Invalid province colour: ", Province::colour_to_hex_string(colour)); + // Logger::error("Invalid province colour: ", Province::colour_to_hex_string(colour)); return FAILURE; } Province new_province { static_cast(provinces.get_item_count() + 1), identifier, colour }; const index_t index = get_index_from_colour(colour); if (index != NULL_INDEX) { - Logger::error("Duplicate province colours: ", get_province_by_index(index)->to_string(), " and ", new_province.to_string()); + // Logger::error("Duplicate province colours: ", get_province_by_index(index)->to_string(), " and ", new_province.to_string()); return FAILURE; } colour_index_map[new_province.get_colour()] = new_province.get_index(); @@ -56,18 +56,18 @@ void Map::lock_provinces() { provinces.lock(); } -return_t Map::set_water_province(std::string const& identifier) { +return_t Map::set_water_province(ovstring const& identifier) { if (water_provinces_locked) { - Logger::error("The map's water provinces have already been locked!"); + // Logger::error("The map's water provinces have already been locked!"); return FAILURE; } Province* province = get_province_by_identifier(identifier); if (province == nullptr) { - Logger::error("Unrecognised water province identifier: ", identifier); + // Logger::error("Unrecognised water province identifier: ", identifier); return FAILURE; } if (province->is_water()) { - Logger::error("Province ", identifier, " is already a water province!"); + // Logger::error("Province ", identifier, " is already a water province!"); return FAILURE; } province->water = true; @@ -77,40 +77,42 @@ return_t Map::set_water_province(std::string const& identifier) { void Map::lock_water_provinces() { water_provinces_locked = true; - Logger::info("Locked water provinces after registering ", water_province_count); + // Logger::info("Locked water provinces after registering ", water_province_count); } -return_t Map::add_region(std::string const& identifier, std::vector const& province_identifiers) { +return_t Map::add_region(ovstring const& identifier, std::vector const& province_identifiers) { if (identifier.empty()) { - Logger::error("Invalid region identifier - empty!"); + // Logger::error("Invalid region identifier - empty!"); return FAILURE; } Region new_region { identifier }; return_t ret = SUCCESS; - for (std::string const& province_identifier : province_identifiers) { + for (ovstring const& province_identifier : province_identifiers) { Province* province = get_province_by_identifier(province_identifier); if (province != nullptr) { if (new_region.contains_province(province)) { - Logger::error("Duplicate province identifier ", province_identifier); + // Logger::error("Duplicate province identifier ", province_identifier); ret = FAILURE; } else { size_t other_region_index = reinterpret_cast(province->get_region()); if (other_region_index != 0) { other_region_index--; - if (other_region_index < regions.get_item_count()) - Logger::error("Province ", province_identifier, " is already part of ", regions.get_item_by_index(other_region_index)->get_identifier()); - else - Logger::error("Province ", province_identifier, " is already part of an unknown region with index ", other_region_index); + if (other_region_index < regions.get_item_count()) { + // Logger::error("Province ", province_identifier, " is already part of ", regions.get_item_by_index(other_region_index)->get_identifier()); + } + else { + // Logger::error("Province ", province_identifier, " is already part of an unknown region with index ", other_region_index); + } ret = FAILURE; } else new_region.provinces.push_back(province); } } else { - Logger::error("Invalid province identifier ", province_identifier); + // Logger::error("Invalid province identifier ", province_identifier); ret = FAILURE; } } if (!new_region.get_province_count()) { - Logger::error("No valid provinces in region's list"); + // Logger::error("No valid provinces in region's list"); return FAILURE; } @@ -142,11 +144,11 @@ Province const* Map::get_province_by_index(index_t index) const { return index != NULL_INDEX ? provinces.get_item_by_index(index - 1) : nullptr; } -Province* Map::get_province_by_identifier(std::string const& identifier) { +Province* Map::get_province_by_identifier(ovstring const& identifier) { return provinces.get_item_by_identifier(identifier); } -Province const* Map::get_province_by_identifier(std::string const& identifier) const { +Province const* Map::get_province_by_identifier(ovstring const& identifier) const { return provinces.get_item_by_identifier(identifier); } @@ -173,11 +175,11 @@ Province const* Map::get_selected_province() const { return get_province_by_index(get_selected_province_index()); } -Region* Map::get_region_by_identifier(std::string const& identifier) { +Region* Map::get_region_by_identifier(ovstring const& identifier) { return regions.get_item_by_identifier(identifier); } -Region const* Map::get_region_by_identifier(std::string const& identifier) const { +Region const* Map::get_region_by_identifier(ovstring const& identifier) const { return regions.get_item_by_identifier(identifier); } @@ -189,23 +191,23 @@ static colour_t colour_at(uint8_t const* colour_data, int32_t idx) { return_t Map::generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data, uint8_t const* terrain_data, terrain_variant_map_t const& terrain_variant_map) { if (!province_shape_image.empty()) { - Logger::error("Province index image has already been generated!"); + // Logger::error("Province index image has already been generated!"); return FAILURE; } if (!provinces.is_locked()) { - Logger::error("Province index image cannot be generated until after provinces are locked!"); + // Logger::error("Province index image cannot be generated until after provinces are locked!"); return FAILURE; } if (new_width < 1 || new_height < 1) { - Logger::error("Invalid province image dimensions: ", new_width, "x", new_height); + // Logger::error("Invalid province image dimensions: ", new_width, "x", new_height); return FAILURE; } if (colour_data == nullptr) { - Logger::error("Province colour data pointer is null!"); + // Logger::error("Province colour data pointer is null!"); return FAILURE; } if (terrain_data == nullptr) { - Logger::error("Province terrain data pointer is null!"); + // Logger::error("Province terrain data pointer is null!"); return FAILURE; } width = new_width; @@ -226,7 +228,7 @@ return_t Map::generate_province_shape_image(size_t new_width, size_t new_height, else { if (unrecognised_terrain_colours.find(terrain_colour) == unrecognised_terrain_colours.end()) { unrecognised_terrain_colours.insert(terrain_colour); - Logger::error("Unrecognised terrain colour ", Province::colour_to_hex_string(terrain_colour), " at (", x, ", ", y, ")"); + // Logger::error("Unrecognised terrain colour ", Province::colour_to_hex_string(terrain_colour), " at (", x, ", ", y, ")"); ret = FAILURE; } province_shape_image[idx].terrain = 0; @@ -255,7 +257,7 @@ return_t Map::generate_province_shape_image(size_t new_width, size_t new_height, } if (unrecognised_province_colours.find(province_colour) == unrecognised_province_colours.end()) { unrecognised_province_colours.insert(province_colour); - Logger::error("Unrecognised province colour ", Province::colour_to_hex_string(province_colour), " at (", x, ", ", y, ")"); + // Logger::error("Unrecognised province colour ", Province::colour_to_hex_string(province_colour), " at (", x, ", ", y, ")"); ret = FAILURE; } province_shape_image[idx].index = NULL_INDEX; @@ -264,7 +266,7 @@ return_t Map::generate_province_shape_image(size_t new_width, size_t new_height, for (size_t idx = 0; idx < province_checklist.size(); ++idx) { if (!province_checklist[idx]) { - Logger::error("Province missing from shape image: ", provinces.get_item_by_index(idx)->to_string()); + // Logger::error("Province missing from shape image: ", provinces.get_item_by_index(idx)->to_string()); ret = FAILURE; } } @@ -283,13 +285,13 @@ std::vector const& Map::get_province_shape_image() const { return province_shape_image; } -return_t Map::add_mapmode(std::string const& identifier, Mapmode::colour_func_t colour_func) { +return_t Map::add_mapmode(ovstring const& identifier, Mapmode::colour_func_t colour_func) { if (identifier.empty()) { - Logger::error("Invalid mapmode identifier - empty!"); + // Logger::error("Invalid mapmode identifier - empty!"); return FAILURE; } if (colour_func == nullptr) { - Logger::error("Mapmode colour function is null for identifier: ", identifier); + // Logger::error("Mapmode colour function is null for identifier: ", identifier); return FAILURE; } return mapmodes.add_item({ mapmodes.get_item_count(), identifier, colour_func }); @@ -307,13 +309,13 @@ Mapmode const* Map::get_mapmode_by_index(size_t index) const { return mapmodes.get_item_by_index(index); } -Mapmode const* Map::get_mapmode_by_identifier(std::string const& identifier) const { +Mapmode const* Map::get_mapmode_by_identifier(ovstring const& identifier) const { return mapmodes.get_item_by_identifier(identifier); } return_t Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const { if (target == nullptr) { - Logger::error("Mapmode colour target pointer is null!"); + // Logger::error("Mapmode colour target pointer is null!"); return FAILURE; } return_t ret = SUCCESS; @@ -323,7 +325,7 @@ return_t Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) // e.g. if we want to allocate the province colour // texture before mapmodes are loaded. if (!(mapmodes.get_item_count() == 0 && index == 0)) { - Logger::error("Invalid mapmode index: ", index); + // Logger::error("Invalid mapmode index: ", index); ret = FAILURE; } mapmode = &Mapmode::ERROR_MAPMODE; diff --git a/src/openvic/map/Map.hpp b/src/openvic/map/Map.hpp index 3533a14..b945c7a 100644 --- a/src/openvic/map/Map.hpp +++ b/src/openvic/map/Map.hpp @@ -16,7 +16,7 @@ namespace OpenVic { const index_t index; const colour_func_t colour_func; - Mapmode(index_t new_index, std::string const& new_identifier, colour_func_t new_colour_func); + Mapmode(index_t new_index, ovstring const& new_identifier, colour_func_t new_colour_func); public: static const Mapmode ERROR_MAPMODE; @@ -59,25 +59,25 @@ namespace OpenVic { public: Map(); - return_t add_province(std::string const& identifier, colour_t colour); + return_t add_province(ovstring const& identifier, colour_t colour); void lock_provinces(); - return_t set_water_province(std::string const& identifier); + return_t set_water_province(ovstring const& identifier); void lock_water_provinces(); - return_t add_region(std::string const& identifier, std::vector const& province_identifiers); + return_t add_region(ovstring const& identifier, std::vector const& province_identifiers); void lock_regions(); size_t get_province_count() const; Province* get_province_by_index(index_t index); Province const* get_province_by_index(index_t index) const; - Province* get_province_by_identifier(std::string const& identifier); - Province const* get_province_by_identifier(std::string const& identifier) const; + Province* get_province_by_identifier(ovstring const& identifier); + Province const* get_province_by_identifier(ovstring const& identifier) const; index_t get_province_index_at(size_t x, size_t y) const; void set_selected_province(index_t index); index_t get_selected_province_index() const; Province const* get_selected_province() const; - Region* get_region_by_identifier(std::string const& identifier); - Region const* get_region_by_identifier(std::string const& identifier) const; + Region* get_region_by_identifier(ovstring const& identifier); + Region const* get_region_by_identifier(ovstring const& identifier) const; return_t generate_province_shape_image(size_t new_width, size_t new_height, uint8_t const* colour_data, uint8_t const* terrain_data, terrain_variant_map_t const& terrain_variant_map); @@ -85,11 +85,11 @@ namespace OpenVic { size_t get_height() const; std::vector const& get_province_shape_image() const; - return_t add_mapmode(std::string const& identifier, Mapmode::colour_func_t colour_func); + return_t add_mapmode(ovstring const& identifier, Mapmode::colour_func_t colour_func); void lock_mapmodes(); size_t get_mapmode_count() const; Mapmode const* get_mapmode_by_index(Mapmode::index_t index) const; - Mapmode const* get_mapmode_by_identifier(std::string const& identifier) const; + Mapmode const* get_mapmode_by_identifier(ovstring const& identifier) const; static constexpr size_t MAPMODE_COLOUR_SIZE = 4; return_t generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const; diff --git a/src/openvic/map/Province.cpp b/src/openvic/map/Province.cpp index d2a5ecf..8b37f43 100644 --- a/src/openvic/map/Province.cpp +++ b/src/openvic/map/Province.cpp @@ -6,7 +6,7 @@ using namespace OpenVic; -Province::Province(index_t new_index, std::string const& new_identifier, colour_t new_colour) +Province::Province(index_t new_index, ovstring const& new_identifier, colour_t new_colour) : HasIdentifier { new_identifier }, HasColour { new_colour }, index { new_index }, @@ -42,7 +42,7 @@ void Province::reset_buildings() { buildings.reset(); } -Building const* Province::get_building_by_identifier(std::string const& identifier) const { +Building const* Province::get_building_by_identifier(ovstring const& identifier) const { return buildings.get_item_by_identifier(identifier); } @@ -50,7 +50,7 @@ std::vector const& Province::get_buildings() const { return buildings.get_items(); } -return_t Province::expand_building(std::string const& building_type_identifier) { +return_t Province::expand_building(ovstring const& building_type_identifier) { Building* building = buildings.get_item_by_identifier(building_type_identifier); if (building == nullptr) return FAILURE; return building->expand(); @@ -60,9 +60,9 @@ Good const* Province::get_rgo() const { return rgo; } -std::string Province::to_string() const { - std::stringstream stream; - stream << "(#" << std::to_string(index) << ", " << get_identifier() << ", 0x" << colour_to_hex_string() << ")"; +ovstring Province::to_string() const { + std::wstringstream stream; + stream << "(#" << std::to_wstring(index) << ", " << get_identifier() << ", 0x" << colour_to_hex_string() << ")"; return stream.str(); } diff --git a/src/openvic/map/Province.hpp b/src/openvic/map/Province.hpp index f1f87a2..6b75876 100644 --- a/src/openvic/map/Province.hpp +++ b/src/openvic/map/Province.hpp @@ -24,7 +24,7 @@ namespace OpenVic { // TODO - change this into a factory-like structure Good const* rgo = nullptr; - Province(index_t new_index, std::string const& new_identifier, colour_t new_colour); + Province(index_t new_index, ovstring const& new_identifier, colour_t new_colour); public: Province(Province&&) = default; @@ -36,11 +36,11 @@ namespace OpenVic { return_t add_building(BuildingType const& type); void lock_buildings(); void reset_buildings(); - Building const* get_building_by_identifier(std::string const& identifier) const; + Building const* get_building_by_identifier(ovstring const& identifier) const; std::vector const& get_buildings() const; - return_t expand_building(std::string const& building_type_identifier); + return_t expand_building(ovstring const& building_type_identifier); Good const* get_rgo() const; - std::string to_string() const; + ovstring to_string() const; void update_state(Date const& today); void tick(Date const& today); diff --git a/src/openvic/map/Region.cpp b/src/openvic/map/Region.cpp index b83f556..6ea9906 100644 --- a/src/openvic/map/Region.cpp +++ b/src/openvic/map/Region.cpp @@ -16,7 +16,7 @@ std::vector const& ProvinceSet::get_provinces() const { return provinces; } -Region::Region(std::string const& new_identifier) : HasIdentifier { new_identifier } {} +Region::Region(ovstring const& new_identifier) : HasIdentifier { new_identifier } {} colour_t Region::get_colour() const { if (provinces.empty()) return FULL_COLOUR << 16; diff --git a/src/openvic/map/Region.hpp b/src/openvic/map/Region.hpp index 331d883..1799ed6 100644 --- a/src/openvic/map/Region.hpp +++ b/src/openvic/map/Region.hpp @@ -21,7 +21,7 @@ namespace OpenVic { friend struct Map; private: - Region(std::string const& new_identifier); + Region(ovstring const& new_identifier); public: Region(Region&&) = default; -- cgit v1.2.3-56-ga3b1