diff --git a/act1.cpp b/act1.cpp index 0a066a3..4101f1f 100644 --- a/act1.cpp +++ b/act1.cpp @@ -21,12 +21,33 @@ namespace int hs = 0; const std::vector candle_ticks{ 20, 10, 5, 0 }; - const std::string cdimmer = "The candles grow shorter."; - const std::vector candle_tells{ cdimmer, cdimmer, "The candles are very short." }; + const char *cdimmer = "The candles grow shorter."; + const std::vector candle_tells{ cdimmer, cdimmer, "The candles are very short." }; const std::vector lamp_ticks{ 50, 30, 20, 10, 4, 0 }; - const std::string dimmer = "The lamp appears to be getting dimmer."; - const std::vector lamp_tells{ dimmer, dimmer, dimmer, dimmer, "The lamp is dying." }; + const char *dimmer = "The lamp appears to be getting dimmer."; + const std::vector lamp_tells{ dimmer, dimmer, dimmer, dimmer, "The lamp is dying." }; + + template + void light_int(const ObjectP &obj, const CEventP &cev, const std::vector &tick, const std::vector &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; @@ -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); @@ -988,26 +1009,6 @@ bool leaves_appear() return false; } -void light_int(ObjectP obj, CEventP cev, const std::vector &tick, const std::vector &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()) diff --git a/act1.h b/act1.h index 1659555..b38bf09 100644 --- a/act1.h +++ b/act1.h @@ -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 &tick, const std::vector &tell); bool locker(); bool look_inside(); bool look_under(); diff --git a/defs.cpp b/defs.cpp index 00249a8..0715621 100644 --- a/defs.cpp +++ b/defs.cpp @@ -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; }