Skip to content

Commit

Permalink
Mostly minor tweaks. One fix for the cretin being referred to incorre…
Browse files Browse the repository at this point in the history
…ctly by two different objects.
  • Loading branch information
jclaar4 committed Jan 14, 2021
1 parent 76a9b44 commit 670d038
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 105 deletions.
4 changes: 2 additions & 2 deletions act2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{
Expand All @@ -735,8 +737,6 @@ namespace obj_funcs
else
rv = false;
return rv;

return rv;
}

bool bcontents()
Expand Down
2 changes: 1 addition & 1 deletion act3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
62 changes: 24 additions & 38 deletions act4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ Iterator<std::array<QuestionP, 3>> 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)
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand All @@ -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();
Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -722,25 +708,25 @@ bool mirmove(bool northq, RoomP rm)

RoomP mirns(bool northq, bool exitq)
{
RoomP mloc = ::mloc;
RoomP rv;
const std::vector<Ex> &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<CExitPtr>(&exit))
return (*cep)->cxroom();
rv = (*cep)->cxroom();
else if (auto roomp = std::get_if<RoomP>(&exit))
return *roomp;
rv = *roomp;
else if (auto sp = std::get_if<std::string>(&exit))
return sfind_room(*sp);
rv = sfind_room(*sp);
}
return nullptr;
return rv;
}

bool mirblock(direction dir, int mdir)
Expand Down
2 changes: 1 addition & 1 deletion act4.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> mirror_here(RoomP rm);
bool start_end();
Expand Down
8 changes: 4 additions & 4 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#include <list>
#include <any>
#include <optional>
#include <sstream>
#include <string_view>

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
Expand Down
42 changes: 26 additions & 16 deletions dung.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VerbP> init_actions(const StringList &il)
Expand Down Expand Up @@ -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<ObjVector> bunuvec(bunuvec_cont, bunuvec_cont.end());
Iterator<ObjVector> bunch(bunuvec);
ObjVector bunuvec_cont;
Iterator<ObjVector> bunuvec;
Iterator<ObjVector> bunch;

void init_bunch()
{
bunuvec_cont = bunch_cont();
bunuvec = Iterator<ObjVector>(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<attack_state> def1 = { missed, missed, missed, missed,
stagger, stagger,
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion gobject.h
Original file line number Diff line number Diff line change
@@ -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 } },
Expand Down
2 changes: 1 addition & 1 deletion info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 4 additions & 5 deletions melee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion objdefs.h
Original file line number Diff line number Diff line change
@@ -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" }, { }, "", { }},
Expand Down
3 changes: 2 additions & 1 deletion object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char *> &syns, const std::initializer_list<const char *> &adj, const char *description,
const std::initializer_list<Bits> &bits, rapplic objfun, const StringList &cntnts,
Expand Down Expand Up @@ -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();
}

Expand Down
8 changes: 5 additions & 3 deletions room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#define notree_FORE5 notree_FORE1
#define kitchen_window_EHOUS std::make_shared<DoorExit>("WINDO", "KITCH", "EHOUS")
#define kitchen_window_KITCH kitchen_window_EHOUS
#define magcmach_MAGNE std::make_shared<CExit>(frobozz, "cmach", "", false, exit_funcs::magnet_room_exit)
#define magalice_MAGNE std::make_shared<CExit>(frobozz, "cmach", "", false, exit_funcs::magnet_room_exit)
#define magcmach_MAGNE std::make_shared<CExit>(frobozz, "CMACH", "", false, exit_funcs::magnet_room_exit)
#define magalice_MAGNE std::make_shared<CExit>(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
Expand Down Expand Up @@ -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;
}

Loading

0 comments on commit 670d038

Please sign in to comment.