1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063 |
- #include "director.h"
- #include <boost/format.hpp>
- #include <cctype>
- #include "boxes.h"
- #include "galaxy.h"
- #include "logging.h"
- #include "scripts.h"
- #include "utils.h"
- Director::Director() {
- BUGZ_LOG(warning) << "Director::Director()";
-
- game = 0;
- galaxy.reset();
-
-
- active = false;
-
- talk_direct = true;
- show_client = true;
- count = 0;
-
- SF_cimline = [this](const std::string &s) { this->SL_cimline(s); };
- SF_sectorline = [this](const std::string &s) { this->SL_sectorline(s); };
- SF_portline = [this](const std::string &s) { this->SL_portline(s); };
- SF_warpline = [this](const std::string &s) { this->SL_warpline(s); };
- SF_infoline = [this](const std::string &s) { this->SL_infoline(s); };
- SF_densityline = [this](const std::string &s) { this->SL_densityline(s); };
- build_menu();
- }
- Director::~Director() { BUGZ_LOG(warning) << "Director::~Director()"; }
- void Director::client_input(const std::string &input) {
-
- if (chain) {
- chain->client_input(input);
- return;
- }
- if (active) {
- if (input == "Q" || input == "q")
- proxy_deactivate();
- return;
- } else if (input == "\x1b" || input == "~") {
- std::string &prompt = current_prompt;
- BUGZ_LOG(trace) << "ACTIVATE prompt shows: [" << prompt << "]";
- if (prompt == "Selection (? for menu): ") {
- to_client("\n\rThere's not much we can do here. Activate in-game at a "
- "Command prompt.\n\r");
- to_client(current_raw_prompt);
- return;
- }
-
- if (prompt == "Enter your choice: ") {
- to_client("\n\r\x1b[1;36mI'd choose \x1b[1;37m`T`\x1b[1;36m, but "
- "that's how I was coded.\n\r");
- to_client(current_raw_prompt);
- return;
- }
-
- if (prompt == "[Pause]") {
- to_client(" \x1b[1;36mPAWS\x1b[0m\n\r");
- to_client(current_raw_prompt);
- return;
- }
- if (at_planet_prompt(prompt)) {
-
-
- to_client("\n\r\x1b[0mFUTURE: Activate the planet upgrade script.\n\r");
- to_client(current_raw_prompt);
- return;
- }
-
-
-
-
-
-
- if (at_command_prompt(prompt)) {
- proxy_activate();
- return;
- }
- }
-
- if (talk_direct)
- to_server(input);
-
- }
- void Director::server_line(const std::string &line,
- const std::string &raw_line) {
-
- if (line.find("TradeWars Game Server ") != std::string::npos) {
- to_client("\rTradeWars Proxy v2++ READY (~ or ESC to activate)\n\r");
-
-
- }
- if (line.find("Selection (? for menu): ") != std::string::npos) {
- char ch = line[line.length() - 1];
- if (ch >= 'A' && ch < 'Q') {
- if ((game) && (game != ch)) {
- galaxy.save();
- }
- game = ch;
- BUGZ_LOG(warning) << "GAME " << game << " activated!";
-
- galaxy.game = game;
- galaxy.username = username;
- galaxy.load();
-
- if (!galaxy.config["display_lines"]) {
- galaxy.config["display_lines"] = 20;
- }
- galaxy.meta["help"]["display_lines"] =
- "Number of report lines to display";
- if (!galaxy.config["burnt_percent"]) {
- galaxy.config["burnt_percent"] = 40;
- }
- galaxy.meta["help"]["burnt_percent"] = "Ignore ports below this percent";
- }
-
- if (ch == 'Q') {
- if (game) {
-
- galaxy.save();
- }
- game = 0;
- galaxy.reset();
- }
- }
- if (game) {
-
-
- if (line == "<Port>") {
- SL_parser = SF_portline;
- }
-
- if (in(line, "==>"))
- SL_parser = SF_densityline;
- if (startswith(line, "Sector : "))
- SL_parser = SF_sectorline;
- if (line == ": ")
- SL_parser = SF_cimline;
- if (line == "<Info>")
- SL_parser = SF_infoline;
- }
- if (SL_parser) {
- SL_parser(line);
- }
-
- if (chain) {
- chain->server_line(line, raw_line);
- }
- }
- void Director::server_prompt(const std::string &prompt,
- const std::string &raw_prompt) {
- current_prompt = prompt;
- current_raw_prompt = raw_prompt;
- if (game) {
- if (prompt == "Selection (? for menu): ") {
- galaxy.save();
- game = 0;
- galaxy.reset();
- }
-
- if (startswith(prompt, "Command [") && endswith(prompt, "] (?=Help)? : ")) {
- std::string sector_text;
- size_t before, after;
- before = prompt.find("]:[") + 3;
- after = prompt.find("] (?=Help)");
- sector_text = prompt.substr(before, after - before);
- current_sector = stoi(sector_text);
- BUGZ_LOG(fatal) << "Sector: " << sector_text;
- }
- }
-
- if (chain)
- chain->server_prompt(prompt);
- }
- void Director::build_menu(void) {
- main_menu = std::make_shared<MenuDispatch>(*this);
- MenuDispatch *md = static_cast<MenuDispatch *>(&(*main_menu));
- md->menu_box_color = "\x1b[1;33;44m";
- md->menu_text_color = "\x1b[1;37;44m";
- md->menu_title = "Proxy Menu";
- md->menu_options_color = "\x1b[1;36;40m";
- md->menu_prompt = "\x1b[0;31;40m\xdb\xb2\xb1\xb0 \x1b[31;40mRED "
- "\x1b[32;40mGREEN\x1b[30;42m\xdb\xb2\xb1\xb0 \x1b[0m : ";
- md->lazy = true;
- md->menu = {{"C", "Configure"},
- {"D", "Display Report"},
- {"E", "Export Data/Save"},
- {"I", "Information"},
- {"P", "Port CIM"},
- {"W", "Warp CIM"},
- {"T", "Trading Report (same as D)"},
- {"S", "Scripts"},
- {"X", "eXit"}};
- md->setNotify([this]() { this->menu_choice(); });
- cim = std::make_shared<CIMDispatch>(*this);
- cim->setNotify([this]() { this->cim_done(); });
- }
- void Director::proxy_activate(void) {
- active = true;
- to_server(" ");
-
- talk_direct = false;
- show_client = false;
-
- old_prompt = current_prompt;
- old_raw_prompt = current_raw_prompt;
- to_client("\x1b[0m\n\r");
-
- Boxes box(30, 1, true);
- box.boxcolor = "\x1b[1;33;44m";
- box.textcolor = "\x1b[1;33;44m";
- to_client(box.top());
- std::string output = " TradeWars Proxy \x1b[5mActive\x1b[0;1;33;44m ";
- to_client(box.row(output));
- to_client(box.bottom());
- chain = main_menu;
- main_menu->activate();
-
- }
- void Director::menu_choice(void) {
- MenuDispatch *md = dynamic_cast<MenuDispatch *>(&(*chain));
- if (md) {
- if (md->input.empty()) {
- to_client("Menu aborted.\n\r");
- proxy_deactivate();
- return;
- } else {
- switch (md->input[0]) {
- case 'C':
- config_edit();
- return;
- break;
- case 'D':
- case 'T':
- {
- auto pptv = galaxy.find_best_trades();
- std::string output;
- galaxy.sort_port_pair_type(pptv);
- int max_display = 20;
- if (galaxy.config["display_lines"])
- max_display = galaxy.config["display_lines"].as<int>();
- else
- galaxy.config["display_lines"] = max_display;
- if ((max_display <= 0) || (max_display > 255)) {
- max_display = 255;
- galaxy.config["display_lines"] = 255;
- }
- const int per_line = 5;
- int count = 0;
- int line = 0;
- for (auto const &ppt : pptv) {
- output = str(boost::format("%1$5d:%2$-5d(%3$d) ") % ppt.s1 % ppt.s2 %
- ppt.type);
- to_client(output);
- ++count;
- if (count == per_line) {
- count = 0;
- to_client("\n\r");
- ++line;
- }
- if (line == max_display)
- break;
- }
- if (count != 0)
- to_client("\n\r");
-
- if ((line < 5) && (max_display > 5)) {
-
- to_client(
- "HINT: For more lines, try reducing the burnt_percent?\n\r");
- }
- } break;
- case 'E':
- to_client("Saving...");
- galaxy.save();
- to_client("\rSaved....\n\r");
- break;
- case 'I':
- information();
- break;
- case 'P':
-
-
- chain = cim;
- to_server("^RQ");
- {
- std::string text = str(boost::format("Port CIM Report (%1%)\n\r") %
- galaxy.ports.size());
-
- to_client(text);
- }
- chain->activate();
- return;
- break;
- case 'W':
- chain = cim;
- to_server("^IQ");
- {
- std::string text = str(boost::format("Warp CIM Report (%1%)\n\r") %
- galaxy.warps.size());
-
- to_client(text);
- }
- chain->activate();
- return;
- break;
-
-
- case 'S':
- {
- init_scripts_menu();
- chain = scripts_menu;
- chain->activate();
- return;
- } break;
- case 'X':
- proxy_deactivate();
- return;
- }
-
- md->activate();
- }
- }
- }
- MenuDispatch *Director::init_scripts_menu(void) {
- MenuDispatch *md;
- if (scripts_menu) {
- md = dynamic_cast<MenuDispatch *>(&(*scripts_menu));
- return md;
- } else {
- scripts_menu = std::make_shared<MenuDispatch>(*this);
- md = static_cast<MenuDispatch *>(&(*scripts_menu));
- md->menu_box_color = "\x1b[0;32;40m";
- md->menu_text_color = "\x1b[1;32;40m";
- md->menu_title = "Scripts Menu";
- md->menu_options_color = "\x1b[1;32;40m";
- md->lazy = false;
- md->menu_prompt = " SCRIPT : ";
- md->menu = {{"!", "Terror"}, {"T", "Trade"}, {"U", "Upgrade Planet Pants"}};
- md->setNotify([this]() { this->scripts_done(); });
- return md;
- }
- }
- void Director::scripts_done(void) {
-
-
- MenuDispatch *md = dynamic_cast<MenuDispatch *>(&(*scripts_menu));
- if (md) {
- if (md->input.empty()) {
- to_client("Scripts aborted.\n\r");
- scripts_menu.reset();
- proxy_deactivate();
- return;
- } else {
- switch (md->input[0]) {
- case 'T':
- {
- script = std::make_shared<ScriptTrader>(*this);
- ScriptTrader *ts = static_cast<ScriptTrader *>(&((*script)));
- ts->setNotify([this]() { this->proxy_deactivate(); });
-
- auto found = galaxy.find_trades(current_sector, false);
- if (found.empty()) {
- to_client(
- "No Trades found. Port burnt (CONFIG: lower burnt_percent?) "
- "or no ports around.\n\r");
- proxy_deactivate();
- return;
- }
-
- galaxy.sort_port_pair_type(found);
- BUGZ_LOG(fatal) << "Found " << found.size() << " possible trade(s).";
- BUGZ_LOG(fatal) << found[0].s1 << "," << found[0].s2 << " : "
- << found[0].type;
- ts->port[0] = found[0].s1;
- ts->port[1] = found[0].s2;
- ts->type = found[0].type;
- chain = script;
- chain->activate();
- return;
- } break;
- case '!': {
- auto best = galaxy.find_closest(current_sector);
- if (best.type != 0) {
- std::string text =
- str(boost::format("Best/Closest: %1% with %2% & %3%\n\r") %
- best.type % best.s1 % best.s2);
- to_client(text);
- } else {
- to_client("I don't see any best trades.\n\r");
- }
- } break;
- }
- }
- }
- proxy_activate();
-
-
-
-
-
- }
- InputDispatch *Director::init_config_input(void) {
- InputDispatch *id;
- if (config_input) {
-
- id = dynamic_cast<InputDispatch *>(&(*config_input));
- id->prompt = "Config => ";
- id->max_length = 3;
- config_item.clear();
- return id;
- } else {
-
- config_input = std::make_shared<InputDispatch>(*this);
- id = static_cast<InputDispatch *>(&(*config_input));
- id->prompt = "Config => ";
- id->max_length = 3;
- id->setNotify([this]() { this->config_have_input(); });
- config_item.clear();
- return id;
- }
- }
- void Director::config_edit(void) {
-
- std::string menu_box_color = "\x1b[1;33;44m";
- std::string menu_text_color = "\x1b[1;37;44m";
- auto abox = Boxes::alert(" Configuration: ", menu_box_color,
- menu_text_color, 20, 1, true);
- for (auto line : abox) {
- to_client(line);
- }
-
- int item = 1;
- for (auto const &cfg : galaxy.config) {
- std::string output = str(boost::format("%1$2d %2$20s: %3$s\n\r") % item %
- cfg.first % cfg.second);
- to_client(output);
- ++item;
- }
- to_client("Enter number to edit, blank to exit.\n\r");
-
- InputDispatch *id = init_config_input();
- chain = config_input;
- id->activate();
-
-
-
- }
- void Director::config_have_input(void) {
- InputDispatch *id = dynamic_cast<InputDispatch *>(&(*config_input));
- if (config_item.empty()) {
-
- if (id->input.empty()) {
-
- chain = main_menu;
- MenuDispatch *md = dynamic_cast<MenuDispatch *>(&(*chain));
- md->activate();
-
- config_input.reset();
- return;
- } else {
- int item;
- try {
- item = stoi(id->input);
- } catch (const std::invalid_argument &e) {
- BUGZ_LOG(fatal) << e.what();
- item = 0;
- } catch (const std::out_of_range &e) {
- BUGZ_LOG(fatal) << e.what();
- item = 0;
- }
- if ((item < 1) || (item > (int)galaxy.config.size())) {
-
- config_edit();
- return;
- } else {
- int pos = 1;
- const YAML::Node &config = galaxy.config;
- for (auto const &c : config) {
- if (pos == item) {
-
- config_item = c.first.as<std::string>();
- std::string output =
- str(boost::format("%1% : %2%\n\r") % config_item %
- galaxy.meta["help"][config_item]);
- to_client(output);
- id->max_length = 30;
- id->prompt = "Change to => ";
- id->activate();
- return;
- };
- ++pos;
- }
- to_client("What? I didn't find that item?\n\r");
- config_edit();
- return;
- }
- }
- } else {
-
- if (id->input.empty()) {
- to_client("No change.\n\r");
- config_edit();
- return;
- } else {
- BUGZ_LOG(fatal) << "Config EDIT: " << config_item << " = " << id->input;
- galaxy.config[config_item] = id->input;
- config_edit();
- return;
- }
- }
- }
- void Director::have_input(void) {
- ++count;
- InputDispatch *id = dynamic_cast<InputDispatch *>(&(*chain));
- if (id) {
- std::string output =
- str(boost::format("Your Input (%2%): [%1%]\n\r") % id->input % count);
- to_client("\x1b[0m");
- to_client(output);
- } else {
- proxy_deactivate();
- return;
- }
- if (count > 3) {
- proxy_deactivate();
- } else {
- chain->activate();
- }
- }
- void Director::cim_done(void) {
- BUGZ_LOG(info) << "CIM done";
- chain = main_menu;
- main_menu->activate();
- }
- void Director::information(void) {
- std::string output;
- to_client("I currently know the following:\n\r");
- output = str(
- boost::format("Ports: %1%, Sectors: %2%, Config: %3%, Meta: %4%\n\r") %
- galaxy.ports.size() % galaxy.warps.size() % galaxy.config.size() %
- galaxy.meta.size());
- to_client(output);
- }
- void Director::proxy_deactivate(void) {
- active = false;
-
- talk_direct = true;
- show_client = true;
- chain.reset();
- to_client("\n\r");
- to_client(current_raw_prompt);
- }
- void Director::SL_cimline(const std::string &line) {
- if (line == ": ENDINTERROG") {
- SL_parser = nullptr;
- return;
- }
- if (line == ": ") {
-
-
-
-
- return;
- }
- if (line.empty()) {
- SL_parser = nullptr;
- return;
- }
-
-
-
-
- if (in(line, "%")) {
-
- struct port p = parse_portcim(line);
- if (p.sector == 0)
- BUGZ_LOG(fatal) << "portcim: FAIL [" << line << "]";
- else
- BUGZ_LOG(trace) << "portcim: " << p;
- galaxy.add_port(p);
- } else {
-
-
- auto warps = split(line);
- sector_warps sw;
- for (auto const &w : warps) {
- if (sw.sector == 0) {
- sw.sector = stoi(w);
- } else {
- sw.add(stoi(w));
- }
- }
- BUGZ_LOG(trace) << "warpcim: " << sw;
- galaxy.add_warp(sw);
- }
- }
- void Director::SL_thiefline(const std::string &line) {
- size_t pos = line.find("Suddenly you're Busted!");
- bool busted = pos != line.npos;
- if (busted) {
- BUGZ_LOG(fatal) << "set bust";
- SL_parser = nullptr;
- } else {
- pos = line.find("(You realize the guards saw you last time!)");
- if (pos != line.npos)
- SL_parser = nullptr;
- }
-
- }
- void Director::SL_sectorline(const std::string &line) {
- BUGZ_LOG(fatal) << "sectorline: [" << line << "]";
- if (line.empty()) {
- SL_parser = nullptr;
- } else {
-
- if (in(line, "Sector :")) {
- current_sector = stoi(line.substr(10));
- BUGZ_LOG(warning) << "SECTOR: " << current_sector;
- }
- if (in(line, "Ports :")) {
- std::string port_class;
- size_t pos = line.find(", Class ");
- if (pos != std::string::npos) {
- pos += 8;
- int class_ = stoi(line.substr(pos));
- BUGZ_LOG(fatal) << "PORT: " << class_;
- galaxy.add_port(current_sector, class_);
- }
- }
- if (in(line, "Warps to Sector(s) :")) {
- std::string temp = line.substr(20);
- replace(temp, " - ", " ");
-
-
- replace(temp, "(", "");
- replace(temp, ")", "");
- sector_warps sw;
- auto warps = split(temp);
- sw.sector = current_sector;
- for (auto const &w : warps) {
- sw.add(stoi(w));
- }
- BUGZ_LOG(fatal) << "WARPS: " << sw;
- galaxy.add_warp(sw);
- }
- }
- }
- void Director::SL_densityline(const std::string &line) {
- BUGZ_LOG(fatal) << "densityline: [" << line << "]";
- if (line.empty()) {
- SL_parser = nullptr;
- return;
- }
-
- if (!in(line, "Sector") || !in(line, "Warps") ||
- !in(line, "NavHaz") || !in(line, "Anom")) {
- BUGZ_LOG(fatal) << "densityline: Invalid line.";
- SL_parser = nullptr;
- return;
- }
- if (not galaxy.meta["density"]) {
- galaxy.meta["density"] = YAML::Node();
- }
-
- std::string work = line;
- replace(work, ":", "");
- bool known = !in(work, "(");
- replace(work, "(", "");
- replace(work, ")", "");
- replace(work, "%", "");
- std::vector<std::string> dense = split(work);
-
- int sector = std::stoi(dense.at(1));
- int density = std::stoi(dense.at(3));
- int warps = std::stoi(dense.at(5));
- int navhaz = std::stoi(dense.at(7));
- bool anom = in(dense.at(9), "Yes");
-
- BUGZ_LOG(warning) << "densityline: {sector=" << sector
- << " density=" << density << " warps=" << warps
- << " navhaz=" << navhaz << " anom=" << anom
- << " known=" << known << "}";
- if (galaxy.meta["density"][sector]) {
- galaxy.meta["density"][sector] = YAML::Node();
- }
- galaxy.meta["density"][sector]["density"] = density;
- galaxy.meta["density"][sector]["warps"] = warps;
- galaxy.meta["density"][sector]["navhaz"] = navhaz;
- galaxy.meta["density"][sector]["anom"] = anom;
- galaxy.meta["density"][sector]["known"] = known;
-
-
- }
- void Director::SL_portline(const std::string &line) {
-
-
-
- if (in(line, "%")) {
-
-
-
- std::string work = line;
- replace(work, "Fuel Ore", "Fuel");
- auto parts = split(work);
- if (parts[0] == "Items")
- return;
- char c = tolower(parts[0][0]);
- int pos;
- char foe[4] = "foe";
- for (pos = 0; pos < 3; ++pos) {
- if (c == foe[pos])
- break;
- }
- int amount = stoi(parts[2]);
- int percent = stoi(parts[3]);
-
- auto port = galaxy.ports.find(current_sector);
- if (port != galaxy.ports.end()) {
- port->second.amount[pos] = amount;
- port->second.percent[pos] = percent;
- }
-
-
- if (parts[0] == "Equipment")
- SL_parser = nullptr;
-
- }
- }
- void Director::SL_warpline(const std::string &line) {
- if (line.empty()) {
- SL_parser = nullptr;
- return;
- }
-
- BUGZ_LOG(fatal) << "warpline: [" << line << "]";
- }
- void Director::SL_infoline(const std::string &line) {
- static int state;
- if (line == "<Info>") {
- state = 0;
- galaxy.meta["info"] = YAML::Node();
- }
- if (line.empty()) {
- ++state;
- if (state == 2) {
- SL_parser = nullptr;
-
- galaxy.meta["ship"] = YAML::Node();
-
- if (galaxy.meta["info"]["Total Holds"]) {
- std::string work = galaxy.meta["info"]["Total Holds"].as<std::string>();
- replace(work, "Fuel Ore", "Fuel");
- auto parts = split(work, " - ");
- int total_holds = stoi(parts[0]);
- BUGZ_LOG(fatal) << "total holds: " << total_holds;
- auto contents = split(parts[1]);
- for (auto const &hold : contents) {
- auto hold_amount = split(hold, "=");
- BUGZ_LOG(fatal) << hold_amount[0] << " with " << hold_amount[1];
- std::string key = hold_amount[0];
- str_tolower(key);
-
-
-
-
-
- if (key != "empty") {
- key = key[0];
- }
- galaxy.meta["ship"]["holds"][key] = stoi(hold_amount[1]);
- }
- galaxy.meta["ship"]["holds"]["total"] = total_holds;
- }
- if (galaxy.meta["info"]["Turns to Warp"]) {
- int warp_turns = galaxy.meta["info"]["Turns to Warp"].as<int>();
- BUGZ_LOG(fatal) << "Turns to Warp: " << warp_turns;
- galaxy.meta["ship"]["warp_turns"] = warp_turns;
- }
- if (galaxy.meta["info"]["LongRange Scan"]) {
- std::string scanner_text =
- galaxy.meta["info"]["LongRange Scan"].as<std::string>();
- char scanner = scanner_text[0];
- BUGZ_LOG(fatal) << "Scanner: " << scanner;
- galaxy.meta["ship"]["scanner"] = scanner;
- }
-
- if (galaxy.meta["info"]["Turns left"]) {
-
- std::string text = galaxy.meta["info"]["Turns left"].as<std::string>();
- if (text == "Unlimited") {
- galaxy.meta["turns"] = -1;
- } else {
- int turns =
- stoi(text);
- BUGZ_LOG(fatal) << "Turns left: " << turns;
- galaxy.meta["turns"] = turns;
- }
- }
- if (galaxy.meta["info"]["Current Sector"]) {
- int sector = galaxy.meta["info"]["Current Sector"].as<int>();
- BUGZ_LOG(fatal) << "Sector: " << sector;
-
- current_sector = sector;
- }
- if (galaxy.meta["info"]["Credits"]) {
- std::string credit_text =
- galaxy.meta["info"]["Credits"].as<std::string>();
- replace(credit_text, ",", "");
- int credits = stoi(credit_text);
- galaxy.meta["credits"] = credits;
- BUGZ_LOG(fatal) << "Credits: " << credits;
- }
- }
- return;
- }
-
- size_t pos = line.find(" : ");
- if ((!endswith(line, " : ")) && (pos != line.npos)) {
- std::string key = line.substr(0, pos);
-
- std::string value = line.substr(pos + 3);
- trim(key);
- trim(value);
- galaxy.meta["info"][key] = value;
- BUGZ_LOG(fatal) << "Info: " << key << " : " << value;
- }
- }
|