diff --git a/act2.cpp b/act2.cpp index 721cc40..fda22b4 100644 --- a/act2.cpp +++ b/act2.cpp @@ -717,6 +717,8 @@ namespace obj_funcs clock_disable(bint); tell("The balloon is fastened to the hook."); } + else + rv = false; } else if (verbq("UNTIE") && prso == sfind_obj("BROPE")) { @@ -735,8 +737,6 @@ namespace obj_funcs else rv = false; return rv; - - return rv; } bool bcontents() diff --git a/act3.cpp b/act3.cpp index 61a69d3..0c19693 100644 --- a/act3.cpp +++ b/act3.cpp @@ -606,8 +606,8 @@ ScolWalls get_wall(const RoomP &rm) bool pass_the_bucket(const RoomP &r, const ObjectP &b) { const AdvP &winner = *::winner; - auto prso = ::prso(); auto oldprsvec1 = prsvec[1]; + prsvec[1] = std::monostate(); remove_object(b); insert_object(b, r); if (winner->avehicle() == b) diff --git a/act4.cpp b/act4.cpp index 203d7af..1f1f257 100644 --- a/act4.cpp +++ b/act4.cpp @@ -33,8 +33,8 @@ Iterator> nqvec(nqvecb); namespace { - const std::string mrestr(" E"); - const std::string mrwstr("MBRW"); + const std::string_view mrestr(" E"); + const std::string_view mrwstr("MBRW"); } bool eg_infested(const RoomP &r) @@ -105,11 +105,7 @@ bool follow() const RoomP &go_e_w(const RoomP &rm, direction dir) { const std::string &spr = rm->rid(); - std::string str = mrestr; - if (dir != Ne && dir != Se) - { - str = mrwstr; - } + std::string str = std::string((dir != Ne && dir != Se) ? mrwstr : mrestr); return find_room(substruc(spr, 0, 3, str)); } @@ -240,11 +236,11 @@ bool enter_end_game() robber_demon->haction(nullptr); // Disable all active events in the adventurer's possession. - std::for_each(w->aobjs().begin(), w->aobjs().end(), [](const ObjectP &o) + for (const ObjectP& o : w->aobjs()) { if (o->olint()) clock_disable(o->olint()->ev()); - }); + } tro(lamp, touchbit); tro(sword, touchbit); @@ -286,35 +282,21 @@ ObjList movies(const RoomP &rm) return list; } -void stuff(const RoomP &r, ObjList l1, ObjList l2) +void stuff(const RoomP &r, const ObjList &l1, const ObjList &l2) { - if (empty(l1)) - { - l1 = l2; - } - else if (empty(l2)) - { - - } - else - { - l1.splice(l1.end(), l2); - } - for (const ObjectP &o : l1) + r->robjs() = l1; + r->robjs().insert(r->robjs().end(), l2.begin(), l2.end()); + for (const ObjectP &o : r->robjs()) { o->oroom(r); } - r->robjs() = l1; } void cell_move() { int new_ = pnumb; int old = lcell; - RoomP cell = sfind_room("CELL"); - RoomP ncell = sfind_room("NCELL"); - RoomP pcell = sfind_room("PCELL"); - ObjectP d = sfind_obj("ODOOR"); + const ObjectP &d = sfind_obj("ODOOR"); ObjList po; const AdvP &me = player(); @@ -323,6 +305,9 @@ void cell_move() if (new_ != old) { + const RoomP& cell = sfind_room("CELL"); + const RoomP& ncell = sfind_room("NCELL"); + const RoomP& pcell = sfind_room("PCELL"); cells[old-1] = po = movies(cell); stuff(cell, cells[new_ - 1], cobjs); cells[new_-1].clear(); @@ -684,16 +669,17 @@ bool look_to(std::string_view nstr, RoomP mirew() { - std::string new_rm = mdir == 0 ? mrwstr : mrestr; + std::string new_rm = std::string(mdir == 0 ? mrwstr : mrestr); new_rm.replace(0, 3, mloc->rid()); return find_room(new_rm); } -bool mirmove(bool northq, RoomP rm) +bool mirmove(bool northq, const RoomP &rm) { - RoomP mrg = sfind_room("MRG"); + using namespace std::string_view_literals; + const RoomP &mrg = sfind_room("MRG"); bool pu = poleup != 0; - tell((pu ? "The structure wobbles " : "The structure slides ") + std::string(northq ? "north" : "south") + + tell((pu ? "The structure wobbles " : "The structure slides ") + (northq ? "north"sv : "south"sv) + " and stops over another compass rose."); mloc = rm; if (rm == mrg && @@ -722,25 +708,25 @@ bool mirmove(bool northq, RoomP rm) RoomP mirns(bool northq, bool exitq) { - RoomP mloc = ::mloc; + RoomP rv; const std::vector &rex = mloc->rexits(); const Ex *m; if (!exitq && ((northq && mloc == northend) || (!northq && mloc == southend))) { - return RoomP(); + // Do nothing } else if (m = memq(northq ? North : South, rex)) { ExitType exit = std::get<1>(*m); if (auto cep = std::get_if(&exit)) - return (*cep)->cxroom(); + rv = (*cep)->cxroom(); else if (auto roomp = std::get_if(&exit)) - return *roomp; + rv = *roomp; else if (auto sp = std::get_if(&exit)) - return sfind_room(*sp); + rv = sfind_room(*sp); } - return nullptr; + return rv; } bool mirblock(direction dir, int mdir) diff --git a/act4.h b/act4.h index 1c10a33..31c101c 100644 --- a/act4.h +++ b/act4.h @@ -30,7 +30,7 @@ bool look_to(std::string_view nstr, bool htell = true); bool mirblock(direction dir, int mdir); RoomP mirew(); -bool mirmove(bool northq, RoomP rm); +bool mirmove(bool northq, const RoomP &rm); RoomP mirns(bool northq = (mdir < 180), bool exitq = false); std::optional mirror_here(RoomP rm); bool start_end(); diff --git a/defs.h b/defs.h index 8541dd9..fd4c6a1 100644 --- a/defs.h +++ b/defs.h @@ -9,14 +9,14 @@ #include #include #include +#include #include inline std::string operator+(std::string_view s1, std::string_view s2) { - std::string rv; - rv.reserve(s1.size() + s2.size()); - std::copy(s2.begin(), s2.end(), std::copy(s1.begin(), s1.end(), std::back_inserter(rv))); - return rv; + std::stringstream ss; + ss << s1 << s2; + return ss.str(); } enum e_oactor diff --git a/dung.cpp b/dung.cpp index 6886552..184e73e 100644 --- a/dung.cpp +++ b/dung.cpp @@ -21,9 +21,9 @@ namespace void init_actors() { // Dungeon master - add_actor(oa_master, get_room("BDOOR"), {}, 0, nullptr, get_obj("MASTE"), actor_funcs::master_actor, 30); - add_actor(oa_player, get_room("WHOUS"), {}, 0, nullptr, get_obj("#####"), actor_funcs::dead_function, 0); - add_actor(oa_robot, get_room("MAGNE"), {}, 0, nullptr, get_obj("ROBOT"), actor_funcs::robot_actor, 3); + add_actor(oa_master, sfind_room("BDOOR"), {}, 0, nullptr, sfind_obj("MASTE"), actor_funcs::master_actor, 30); + add_actor(oa_player, sfind_room("WHOUS"), {}, 0, nullptr, sfind_obj("#####"), actor_funcs::dead_function, 0); + add_actor(oa_robot, sfind_room("MAGNE"), {}, 0, nullptr, sfind_obj("ROBOT"), actor_funcs::robot_actor, 3); } std::vector init_actions(const StringList &il) @@ -51,29 +51,35 @@ namespace // Bunch vector. ObjVector bunch_cont() { - ObjVector ov(8, get_obj("#####")); + ObjVector ov(8, sfind_obj("#####")); return ov; } -ObjVector bunuvec_cont = bunch_cont(); -Iterator bunuvec(bunuvec_cont, bunuvec_cont.end()); -Iterator bunch(bunuvec); +ObjVector bunuvec_cont; +Iterator bunuvec; +Iterator bunch; + +void init_bunch() +{ + bunuvec_cont = bunch_cont(); + bunuvec = Iterator(bunuvec_cont, bunuvec_cont.end()); + bunch = bunuvec; +} WordsPobl words_pobl; // Globals from dung.mud appear here. -PhraseVecV make_prepvec() +PhraseVecV prepvecb; +PrepVec prepvec; + +void init_prepvec() { auto with_prep = find_prep("WITH"); - auto cretin = get_obj("#####"); - PhraseVecV pvv; - std::generate_n(std::back_inserter(pvv), 5, [&with_prep, &cretin]() { return make_phrase(with_prep, cretin); }); - return pvv; + auto cretin = sfind_obj("#####"); + prepvecb.clear(); + std::generate_n(std::back_inserter(prepvecb), 5, [&with_prep, &cretin]() { return make_phrase(with_prep, cretin); }); + prepvec = prepvecb; } -PhraseVecV prepvecb = make_prepvec(); - -PrepVec prepvec(prepvecb); - // Attacking things... const std::vector def1 = { missed, missed, missed, missed, stagger, stagger, @@ -966,6 +972,10 @@ void init_dung() dir_syns(); init_objects(); + // Some objects that were initialized globally, but need to be done after init_objects(). + last_it = sfind_obj("#####"); + init_bunch(); + init_prepvec(); init_synonyms(); init_rooms(); init_actors(); diff --git a/gobject.h b/gobject.h index 794f665..75b6e1b 100644 --- a/gobject.h +++ b/gobject.h @@ -1,4 +1,4 @@ -// Generated at 12-28-19 16:06:15 +// Generated at 01-14-21 13:45:01 #pragma once const GObjectDefinition gobjects[] = { {numbits, { "IT", "THAT", "THIS", "HIM" }, { }, "random object", { ovison, ndescbit } }, diff --git a/info.cpp b/info.cpp index d06ba87..199b7c8 100644 --- a/info.cpp +++ b/info.cpp @@ -82,7 +82,7 @@ const std::string_view help_str = "Command parser:\n\n" " A command is one line of text terminated by a carriage return.\n" "For reasons of simplicity, all words are distinguished by their\n" -"first six letters. All others are ignored. For example, typing\n" +"first five letters. All others are ignored. For example, typing\n" "'DISASSEMBLE THE ENCYCLOPEDIA' is not only meaningless, it also\n" "creates excess effort for your fingers. Note that this trunca-\n" "tion may produce ambiguities in the interpretation of longer words.\n\n" diff --git a/melee.cpp b/melee.cpp index 66de36f..4d90ec0 100644 --- a/melee.cpp +++ b/melee.cpp @@ -20,11 +20,10 @@ namespace int fight_strength(const AdvP &hero, bool adjust) { int s, smax = strength_max, smin = strength_min; - float f = float(hero->ascore()) / float(score_max()); - f *= (smax - smin); - f += 0.5f; - s = (int)f + smin; - + int pct = hero->ascore() * 100 / score_max(); + pct *= (smax - smin); + pct += 50; + s = (pct / 100) + smin; return adjust ? (s + hero->astrength()) : s; } diff --git a/objdefs.h b/objdefs.h index 92701b6..05de9aa 100644 --- a/objdefs.h +++ b/objdefs.h @@ -1,4 +1,4 @@ -// Generated at 12-28-19 16:06:15 +// Generated at 01-14-21 13:45:01 #pragma once const ObjectDefinition objects[] = { {{ "BUTTO" }, { }, "", { }}, diff --git a/object.cpp b/object.cpp index b6a85b0..34cadbb 100644 --- a/object.cpp +++ b/object.cpp @@ -112,7 +112,7 @@ namespace } // last_it must be defined after Objects. -ObjectP last_it(get_obj("#####")); +ObjectP last_it; Object::Object(const std::initializer_list &syns, const std::initializer_list &adj, const char *description, const std::initializer_list &bits, rapplic objfun, const StringList &cntnts, @@ -492,6 +492,7 @@ const ObjectP &find_obj(std::string_view name) { _ASSERT(name.size() <= 5); // To catch typos auto iter = Objects().find(name); + _ASSERT(iter != Objects().end()); return iter->second.front(); } diff --git a/room.cpp b/room.cpp index cac46da..f67dc96 100644 --- a/room.cpp +++ b/room.cpp @@ -15,8 +15,8 @@ #define notree_FORE5 notree_FORE1 #define kitchen_window_EHOUS std::make_shared("WINDO", "KITCH", "EHOUS") #define kitchen_window_KITCH kitchen_window_EHOUS -#define magcmach_MAGNE std::make_shared(frobozz, "cmach", "", false, exit_funcs::magnet_room_exit) -#define magalice_MAGNE std::make_shared(frobozz, "cmach", "", false, exit_funcs::magnet_room_exit) +#define magcmach_MAGNE std::make_shared(frobozz, "CMACH", "", false, exit_funcs::magnet_room_exit) +#define magalice_MAGNE std::make_shared(frobozz, "CMACH", "", false, exit_funcs::magnet_room_exit) #define current_RIVR1 NExit("You cannot go upstream due to strong currents.") #define current_RIVR2 current_RIVR1 #define current_RIVR3 current_RIVR1 @@ -227,6 +227,8 @@ void init_rooms() const RoomP &find_room(std::string_view rid) { - return room_map().find(rid)->second; + auto iter = room_map().find(rid); + _ASSERT(iter != room_map().end()); + return iter->second; } diff --git a/rooms.cpp b/rooms.cpp index b65ec53..f6786bf 100644 --- a/rooms.cpp +++ b/rooms.cpp @@ -51,12 +51,9 @@ void excruciatingly_untasteful_code() // ??? } -std::string remarkably_disgusting_code() +const char *remarkably_disgusting_code() { - std::string s = "This Zork created "; - s += __DATE__; - s += "."; - return s; + return "This Zork created " __DATE__ "."; } std::string unspeakable_code() @@ -65,10 +62,11 @@ std::string unspeakable_code() const std::string &oread = O->oread(); auto pos = oread.find_first_of('/'); pos -= (oread[pos - 2] == '1' ? 2 : 1); - std::string s = "There is an issue of US NEWS & DUNGEON REPORT dated "; - s += oread.substr(pos, oread.find_first_of(' ', pos) - pos); - s += " here."; - return s; + std::stringstream ss; + ss << "There is an issue of US NEWS & DUNGEON REPORT dated "; + ss << std::string_view(&oread[pos], oread.find_first_of(' ', pos) - pos); + ss << " here."; + return ss.str(); } void contin(bool foo) @@ -82,7 +80,6 @@ int score(bool ask) { bool eg = flags[end_game_flag]; int scor, smax; - float pct; flags[tell_flag] = true; princ("Your score "); if (eg) @@ -106,27 +103,27 @@ int score(bool ask) princ(" moves."); crlf(); princ("This score gives you the rank of "); - pct = (float)scor / (float)smax; + int pct = (scor * 100) / smax; if (eg) { - princ((pct == 1.0) ? "Dungeon Master" : - (pct > 0.75) ? "Super Cheater" : - (pct > 0.50) ? "Master Cheater" : - (pct > 0.25) ? "Advanced Cheater" : + princ((pct == 100) ? "Dungeon Master" : + (pct > 75) ? "Super Cheater" : + (pct > 50) ? "Master Cheater" : + (pct > 25) ? "Advanced Cheater" : "Cheater"); } else { - princ((pct == 1.0) ? "Cheater" : - (pct > 0.95) ? "Wizard" : - (pct > 0.8999999) ? "Master" : - (pct > 0.7999999) ? "Winner" : - (pct > 0.6000000) ? "Hacker" : - (pct > 0.3999999) ? "Adventurer" : - (pct > 0.1999999) ? "Junior Adventurer" : - (pct > 0.0999999) ? "Novice Adventurer" : - (pct > 0.0499999) ? "Amateur Adventurer" : - (pct >= 0.0) ? "Beginner" : + princ((pct == 100) ? "Cheater" : + (pct > 95) ? "Wizard" : + (pct > 89) ? "Master" : + (pct > 79) ? "Winner" : + (pct > 60) ? "Hacker" : + (pct > 39) ? "Adventurer" : + (pct > 19) ? "Junior Adventurer" : + (pct > 9) ? "Novice Adventurer" : + (pct > 4) ? "Amateur Adventurer" : + (pct >= 0) ? "Beginner" : "Incompetent"); } princ("."); @@ -201,7 +198,7 @@ void score_room(const RoomP &rm) } } -void start(const std::string &rm, const std::string &st) +void start(std::string_view rm, std::string_view st) { here = find_room(rm); (*winner)->aroom(here); @@ -213,7 +210,6 @@ void start(const std::string &rm, const std::string &st) void save_it(bool strt) { - std::string st = remarkably_disgusting_code(); sfind_obj("PAPER")->odesc1(unspeakable_code()); dead_player = player()->aaction(); player()->aaction(nullptr); @@ -222,7 +218,7 @@ void save_it(bool strt) moves = 0; winner = &player(); srand((unsigned int)time(NULL)); - start("WHOUS", st); + start("WHOUS", remarkably_disgusting_code()); } bool object_action() @@ -381,7 +377,7 @@ bool room_info(std::optional full) } else if (!full && !flags[no_obj_print] || full && !((full.value() & 1) == 0)) { - for (ObjectP x : rm->robjs()) + for (auto &x : rm->robjs()) { if (trnn(x, ovison) && ( (full && (full.value() == 1)) || describable(x))) diff --git a/rooms.h b/rooms.h index 40230ea..41db716 100644 --- a/rooms.h +++ b/rooms.h @@ -59,8 +59,8 @@ typedef std::array ParseContV; extern Iterator parse_cont; std::string unspeakable_code(); -std::string remarkably_disgusting_code(); -void start(const std::string &rm, const std::string &st = std::string()); +const char *remarkably_disgusting_code(); +void start(std::string_view &rm, std::string_view st = std::string()); void save_it(bool start = true); void contin(bool foo = false); bool goto_(const RoomP &rm, const AdvP &win = *winner);