Skip to content

Commit

Permalink
Fixed flaming, refactored light_int
Browse files Browse the repository at this point in the history
  • Loading branch information
jclaar4 committed Mar 1, 2019
1 parent 4c39eae commit f03c1a7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
51 changes: 26 additions & 25 deletions act1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,33 @@ namespace
int hs = 0;

const std::vector<int> candle_ticks{ 20, 10, 5, 0 };
const std::string cdimmer = "The candles grow shorter.";
const std::vector<std::string> candle_tells{ cdimmer, cdimmer, "The candles are very short." };
const char *cdimmer = "The candles grow shorter.";
const std::vector<const char *> candle_tells{ cdimmer, cdimmer, "The candles are very short." };

const std::vector<int> lamp_ticks{ 50, 30, 20, 10, 4, 0 };
const std::string dimmer = "The lamp appears to be getting dimmer.";
const std::vector<std::string> lamp_tells{ dimmer, dimmer, dimmer, dimmer, "The lamp is dying." };
const char *dimmer = "The lamp appears to be getting dimmer.";
const std::vector<const char *> lamp_tells{ dimmer, dimmer, dimmer, dimmer, "The lamp is dying." };

template <typename T>
void light_int(const ObjectP &obj, const CEventP &cev, const std::vector<int> &tick, const std::vector<T> &tell)
{
const OlintP &foo = obj->olint();
int cnt, tim;
foo->val(cnt = (foo->val() + 1));
clock_int(cev, tim = tick[size_t(cnt) - 1]);
if (tim < 0)
{
if (!obj->oroom() || obj->oroom() == here)
{
::tell("I hope you have more light than from a " + obj->odesc2() + ".");
}
trz(obj, { lightbit, onbit });
}
else if (!obj->oroom() || obj->oroom() == here)
{
::tell(tell[size_t(cnt) - 1]);
}
}
}

int water_level = 0;
Expand Down Expand Up @@ -116,7 +137,7 @@ bool robber(const HackP &hack)
if (!winning(hobj, win))
{
tell("Your opponent, determining discretion to be the better part of\n"
"valor, decides to terminate this little contretemps.With a rueful\n"
"valor, decides to terminate this little contretemps. With a rueful\n"
"nod of his head, he steps backward into the gloom and disappears.", long_tell1);
remove_object(hobj);
trz(hobj, fightbit);
Expand Down Expand Up @@ -988,26 +1009,6 @@ bool leaves_appear()
return false;
}

void light_int(ObjectP obj, CEventP cev, const std::vector<int> &tick, const std::vector<std::string> &tell)
{
OlintP foo = obj->olint();
int cnt, tim;
foo->val(cnt = (foo->val() + 1));
clock_int(cev, tim = tick[size_t(cnt) - 1]);
if (tim < 0)
{
if (!obj->oroom() || obj->oroom() == here)
{
::tell("I hope you have more light than from a " + obj->odesc2() + ".");
}
trz(obj, { lightbit, onbit });
}
else if (!obj->oroom() || obj->oroom() == here)
{
::tell(tell[size_t(cnt) - 1]);
}
}

bool locker()
{
if (object_action())
Expand Down
1 change: 0 additions & 1 deletion act1.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ inline bool killer() { return killer("kill"); }
bool leaper();
bool leave();
bool leaves_appear();
void light_int(ObjectP obj, CEventP cev, const std::vector<int> &tick, const std::vector<std::string> &tell);
bool locker();
bool look_inside();
bool look_under();
Expand Down
10 changes: 8 additions & 2 deletions defs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ void rtrc(const RoomP &p, Bits b)

bool flaming(const ObjectP &obj)
{
// True if any of the light-giving bits are set.
return trnn(obj, { flamebit, onbit, lightbit });
// True if all of the light-giving bits are set.
const Bits f[] = { flamebit, onbit, lightbit };
for (Bits b : f)
{
if (!obj->oflags().test(b))
return false;
}
return true;
}

0 comments on commit f03c1a7

Please sign in to comment.