void Player::onAlarmEvent(const Level* l, Vec2 pos) { if (pos == creature->getPosition()) privateMessage("An alarm sounds near you."); else privateMessage("An alarm sounds in the " + getCardinalName((pos - creature->getPosition()).getBearing().getCardinalDir())); }
void testVec2() { CHECK(Vec2(5, 0).shorten() == Vec2(1, 0)); CHECK(Vec2(-7, 0).shorten() == Vec2(-1, 0)); CHECK(Vec2(0, 4).shorten() == Vec2(0, 1)); CHECK(Vec2(0, -3).shorten() == Vec2(0, -1)); CHECK(Vec2(5, 5).shorten() == Vec2(1, 1)); CHECK(Vec2(-7, -7).shorten() == Vec2(-1, -1)); CHECK(Vec2(-3, 3).shorten() == Vec2(-1, 1)); CHECK(Vec2(4, -4).shorten() == Vec2(1, -1)); checkEqual(Vec2(3, 0).approxL1(), make_pair(Vec2(1, 0), Vec2(1, 0))); checkEqual(Vec2(3, -1).approxL1(), make_pair(Vec2(1, 0), Vec2(1, -1))); checkEqual(Vec2(3, -3).approxL1(), make_pair(Vec2(1, -1), Vec2(1, -1))); checkEqual(Vec2(1, -3).approxL1(), make_pair(Vec2(0, -1), Vec2(1, -1))); checkEqual(Vec2(0, -3).approxL1(), make_pair(Vec2(0, -1), Vec2(0, -1))); checkEqual(Vec2(-1, -3).approxL1(), make_pair(Vec2(0, -1), Vec2(-1, -1))); checkEqual(Vec2(-3, -3).approxL1(), make_pair(Vec2(-1, -1), Vec2(-1, -1))); checkEqual(Vec2(-3, -1).approxL1(), make_pair(Vec2(-1, 0), Vec2(-1, -1))); checkEqual(Vec2(-3, 0).approxL1(), make_pair(Vec2(-1, 0), Vec2(-1, 0))); checkEqual(Vec2(-3, 1).approxL1(), make_pair(Vec2(-1, 0), Vec2(-1, 1))); checkEqual(Vec2(-3, 3).approxL1(), make_pair(Vec2(-1, 1), Vec2(-1, 1))); checkEqual(Vec2(-1, 3).approxL1(), make_pair(Vec2(0, 1), Vec2(-1, 1))); checkEqual(Vec2(0, 3).approxL1(), make_pair(Vec2(0, 1), Vec2(0, 1))); checkEqual(Vec2(1, 3).approxL1(), make_pair(Vec2(0, 1), Vec2(1, 1))); checkEqual(Vec2(3, 3).approxL1(), make_pair(Vec2(1, 1), Vec2(1, 1))); checkEqual(Vec2(3, 1).approxL1(), make_pair(Vec2(1, 1), Vec2(1, 0))); CHECKEQ(getCardinalName(Vec2(1, 0).getBearing().getCardinalDir()), "east"); CHECKEQ(getCardinalName(Vec2(3, 1).getBearing().getCardinalDir()), "east"); CHECKEQ(getCardinalName(Vec2(1, 1).getBearing().getCardinalDir()), "south-east"); CHECKEQ(getCardinalName(Vec2(2, 1).getBearing().getCardinalDir()), "south-east"); CHECKEQ(getCardinalName(Vec2(0, 1).getBearing().getCardinalDir()), "south"); CHECKEQ(getCardinalName(Vec2(-1, 3).getBearing().getCardinalDir()), "south"); CHECKEQ(getCardinalName(Vec2(-1, 1).getBearing().getCardinalDir()), "south-west"); CHECKEQ(getCardinalName(Vec2(-1, 0).getBearing().getCardinalDir()), "west"); CHECKEQ(getCardinalName(Vec2(-1, -1).getBearing().getCardinalDir()), "north-west"); CHECKEQ(getCardinalName(Vec2(0, -1).getBearing().getCardinalDir()), "north"); CHECKEQ(getCardinalName(Vec2(1, -1).getBearing().getCardinalDir()), "north-east"); }