diff --git a/rogueviz/ru/classes.cpp b/rogueviz/ru/classes.cpp index f8a4271f..927d995e 100644 --- a/rogueviz/ru/classes.cpp +++ b/rogueviz/ru/classes.cpp @@ -210,7 +210,7 @@ struct stater { }; struct entity { - string name; + string id; virtual ~entity() {} virtual xy siz() = 0; xy where, vel; @@ -456,7 +456,7 @@ struct timed_orb : public located_entity { }; struct npc_or_trader : public located_entity { - string text; + string text, name; int talk_on; xy siz() override { return {12, 12}; } void act() override; @@ -718,7 +718,7 @@ struct item : public located_entity { if(intersect(get_pixel_bbox(), m.get_pixel_bbox())) { addMessage(pickup_message); add_revert(death_revert, {"ITEM", p->name, its(p->qty_filled), its(p->qty_owned)}); - add_revert(death_revert, {"EXIST", name}); + add_revert(death_revert, {"EXIST", id}); p->picked_up(qty); existing = false; } diff --git a/rogueviz/ru/load-world.cpp b/rogueviz/ru/load-world.cpp index 9728de06..413365b8 100644 --- a/rogueviz/ru/load-world.cpp +++ b/rogueviz/ru/load-world.cpp @@ -10,6 +10,12 @@ void visit(cell *c, int d) { q.push(c); } +string unspace(string s) { + string t; + for(char c: s) if(c == ' ') t += "_"; else t += c; + return t; + } + void save_map(string fname) { in_queue.clear(); q = {}; @@ -142,7 +148,7 @@ void load_room(fhstream& f, cell *c) { pos = param.find(" "); auto res = param.substr(0, pos); param = param.substr(pos + 1); return res; }; - auto nam = [&] (entity& b) { b.name = cutoff("NOTHING"); }; + auto nam = [&] (entity& b) { b.id = cutoff("NOTHING"); }; auto get_ld = [&] () { return atof(cutoff("0").c_str()); }; auto get_int = [&] () { return atoi(cutoff("0").c_str()); }; auto get_color = [&] () { color_t col; sscanf(cutoff("0").c_str(), "%08x", &col); return col; }; @@ -159,7 +165,7 @@ void load_room(fhstream& f, cell *c) { b->qty = param == "" ? 1 : get_int(); println(hlog, "qty is ", b->qty); b->p = &find_power(scanline_noblank(f)); - b->name = b->pickup_message = scanline_noblank(f); + b->id = unspace(b->pickup_message = scanline_noblank(f)); r.entities.emplace_back(std::move(b)); } else if(cap == "LOOT") { @@ -167,7 +173,7 @@ void load_room(fhstream& f, cell *c) { b->owner = &*r.entities.back(); b->qty = param == "" ? 1 : get_int(); b->p = &find_power(scanline_noblank(f)); - b->name = b->pickup_message = scanline_noblank(f); + b->id = unspace(b->pickup_message = scanline_noblank(f)); r.entities.emplace_back(std::move(b)); } else if(cap == "SHOPITEM") { @@ -177,7 +183,7 @@ void load_room(fhstream& f, cell *c) { b->qty = param == "" ? 1 : get_int(); b->qty1 = param == "" ? 0 : get_int(); b->p = &find_power(scanline_noblank(f)); - b->name = b->pickup_message = scanline_noblank(f); + b->id = unspace(b->pickup_message = scanline_noblank(f)); r.entities.emplace_back(std::move(b)); } else if(cap == "NPC") { @@ -187,6 +193,7 @@ void load_room(fhstream& f, cell *c) { s = scanline_noblank(f); b->sglyph = s[0]; b->name = s.substr(1); + b->id = unspace(b->name); b->text = scanline_noblank(f); r.entities.emplace_back(std::move(b)); } @@ -195,6 +202,7 @@ void load_room(fhstream& f, cell *c) { b->respawn = get_xy(); b->name = scanline_noblank(f); b->text = scanline_noblank(f); + b->id = unspace(b->name); r.entities.emplace_back(std::move(b)); } else if(cap == "BOAR") { @@ -299,7 +307,7 @@ void load_room(fhstream& f, cell *c) { } } -map entity_by_name; +map entity_by_id; void load_map(string fname) { fhstream f(fname, "r"); @@ -317,12 +325,12 @@ void load_map(string fname) { for(auto& [c,r]: rooms) { for(auto& e: r.entities) { e->hs(resetter); - if(e->name != "") { - while(entity_by_name.count(e->name)) { - println(hlog, "error: double entity name: ", e->name); - e->name += "'"; + if(e->id != "") { + while(entity_by_id.count(e->id)) { + println(hlog, "error: double entity name: ", e->id); + e->id += "'"; } - entity_by_name[e->name] = &*e; + entity_by_id[e->id] = &*e; } } } diff --git a/rogueviz/ru/powers.cpp b/rogueviz/ru/powers.cpp index 6edb2833..51537689 100644 --- a/rogueviz/ru/powers.cpp +++ b/rogueviz/ru/powers.cpp @@ -515,7 +515,7 @@ void gen_powers() { addMessage(si->pickup_message); power_death_revert(*si->p); si->p->qty_owned += si->qty; si->p->qty_filled += si->qty1; - add_revert(death_revert, {"EXIST", si->name}); + add_revert(death_revert, {"EXIST", si->id}); si->existing = false; } else if(it == 0 && on && si->existing && si->bought) { @@ -523,7 +523,7 @@ void gen_powers() { addMessage("You get some gold."); power_death_revert(*si->p); powers[gold_id].qty_owned += si->price; powers[gold_id].qty_filled += si->price; - add_revert(death_revert, {"EXIST", si->name}); + add_revert(death_revert, {"EXIST", si->id}); si->existing = false; } else if((it ? !done_something : on) && !si->existing && !si->bought) { @@ -531,7 +531,7 @@ void gen_powers() { addMessage("You rethink your purchase."); power_death_revert(*si->p); si->p->qty_owned -= si->qty; si->p->qty_filled -= si->qty1; - add_revert(death_revert, {"UNEXIST", si->name}); + add_revert(death_revert, {"UNEXIST", si->id}); si->existing = true; } else if((it ? !done_something : on) && !si->existing && si->bought) { @@ -539,7 +539,7 @@ void gen_powers() { addMessage("You rethink your actions."); power_death_revert(*si->p); powers[gold_id].qty_owned -= si->price; powers[gold_id].qty_filled -= si->price; - add_revert(death_revert, {"UNEXIST", si->name}); + add_revert(death_revert, {"UNEXIST", si->id}); si->existing = true; } else if(it == 0 && on_trader && !si->existing && d.p->qty_owned >= si->price) { @@ -548,7 +548,7 @@ void gen_powers() { power_death_revert(*si->p); powers[gold_id].qty_owned -= si->price; powers[gold_id].qty_filled -= si->price; si->existing = true; si->bought = true; - add_revert(death_revert, {"UNBOUGHT", si->name}); + add_revert(death_revert, {"UNBOUGHT", si->id}); } else if(it == 0 && on_trader && !si->existing && !si->bought) { done_something = true; diff --git a/rogueviz/ru/reverts.cpp b/rogueviz/ru/reverts.cpp index 2c98c8c7..0e27b3c3 100644 --- a/rogueviz/ru/reverts.cpp +++ b/rogueviz/ru/reverts.cpp @@ -8,7 +8,7 @@ room *find_room(string s) { } entity* find_entity(string s) { - auto e = entity_by_name[s]; + auto e = entity_by_id[s]; if(!e) throw hr_name_error("find_entity"); return e; }