From a83d09446463533ec68bc3a191edf80afc2aa975 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 24 Feb 2015 00:05:41 +0300 Subject: Split crazy move functions to smaller functions. --- src/being/crazymoves.cpp | 505 +++++++++++++++++++++++++---------------------- src/being/crazymoves.h | 9 + 2 files changed, 274 insertions(+), 240 deletions(-) (limited to 'src') diff --git a/src/being/crazymoves.cpp b/src/being/crazymoves.cpp index 0c98187d8..e5baaf76c 100644 --- a/src/being/crazymoves.cpp +++ b/src/being/crazymoves.cpp @@ -45,6 +45,7 @@ CrazyMoves *crazyMoves = nullptr; CrazyMoves::CrazyMoves() : + mMoveProgram(), mDisableCrazyMove(false) { } @@ -456,255 +457,302 @@ void CrazyMoves::crazyMove9() } } -void CrazyMoves::crazyMoveA() +void CrazyMoves::crazyMoveAm() { - const std::string mMoveProgram(config.getStringValue("crazyMoveProgram")); - - if (localPlayer->getCurrentAction() == BeingAction::MOVE) - return; - - if (mMoveProgram.empty()) - return; - - if (settings.crazyMoveState >= mMoveProgram.length()) - settings.crazyMoveState = 0; - - // move command - if (mMoveProgram[settings.crazyMoveState] == 'm') + settings.crazyMoveState ++; + if (settings.crazyMoveState < mMoveProgram.length()) { - settings.crazyMoveState ++; - if (settings.crazyMoveState < mMoveProgram.length()) - { - int dx = 0; - int dy = 0; + int dx = 0; + int dy = 0; - signed char param = mMoveProgram[settings.crazyMoveState++]; - if (param == '?') + signed char param = mMoveProgram[settings.crazyMoveState++]; + if (param == '?') + { + const char cmd[] = {'l', 'r', 'u', 'd', 'L', 'R', 'U', 'D'}; + srand(tick_time); + param = cmd[rand() % 8]; + } + switch (param) + { + case 'd': + localPlayer->move(0, 1); + break; + case 'u': + localPlayer->move(0, -1); + break; + case 'l': + localPlayer->move(-1, 0); + break; + case 'r': + localPlayer->move(1, 0); + break; + case 'D': + localPlayer->move(1, 1); + break; + case 'U': + localPlayer->move(-1, -1); + break; + case 'L': + localPlayer->move(-1, 1); + break; + case 'R': + localPlayer->move(1, -1); + break; + case 'f': { - const char cmd[] = {'l', 'r', 'u', 'd', 'L', 'R', 'U', 'D'}; - srand(tick_time); - param = cmd[rand() % 8]; + const uint8_t dir = localPlayer->getDirection(); + if (dir & BeingDirection::UP) + dy = -1; + else if (dir & BeingDirection::DOWN) + dy = 1; + if (dir & BeingDirection::LEFT) + dx = -1; + else if (dir & BeingDirection::RIGHT) + dx = 1; + localPlayer->move(dx, dy); + break; } - switch (param) + case 'b': { - case 'd': - localPlayer->move(0, 1); - break; - case 'u': - localPlayer->move(0, -1); - break; - case 'l': - localPlayer->move(-1, 0); - break; - case 'r': - localPlayer->move(1, 0); - break; - case 'D': - localPlayer->move(1, 1); - break; - case 'U': - localPlayer->move(-1, -1); - break; - case 'L': - localPlayer->move(-1, 1); - break; - case 'R': - localPlayer->move(1, -1); - break; - case 'f': - { - const uint8_t dir = localPlayer->getDirection(); - if (dir & BeingDirection::UP) - dy = -1; - else if (dir & BeingDirection::DOWN) - dy = 1; - if (dir & BeingDirection::LEFT) - dx = -1; - else if (dir & BeingDirection::RIGHT) - dx = 1; - localPlayer->move(dx, dy); - break; - } - case 'b': - { - const uint8_t dir = localPlayer->getDirection(); - if (dir & BeingDirection::UP) - dy = 1; - else if (dir & BeingDirection::DOWN) - dy = -1; - if (dir & BeingDirection::LEFT) - dx = 1; - else if (dir & BeingDirection::RIGHT) - dx = -1; - localPlayer->move(dx, dy); - break; - } - default: - break; + const uint8_t dir = localPlayer->getDirection(); + if (dir & BeingDirection::UP) + dy = 1; + else if (dir & BeingDirection::DOWN) + dy = -1; + if (dir & BeingDirection::LEFT) + dx = 1; + else if (dir & BeingDirection::RIGHT) + dx = -1; + localPlayer->move(dx, dy); + break; } + default: + break; } } - // direction command - else if (mMoveProgram[settings.crazyMoveState] == 'd') - { - settings.crazyMoveState ++; +} - if (settings.crazyMoveState < mMoveProgram.length()) - { - signed char param = mMoveProgram[settings.crazyMoveState++]; - if (param == '?') - { - const char cmd[] = {'l', 'r', 'u', 'd'}; - srand(tick_time); - param = cmd[rand() % 4]; - } - switch (param) - { - case 'd': +void CrazyMoves::crazyMoveAd() +{ + settings.crazyMoveState ++; + if (settings.crazyMoveState < mMoveProgram.length()) + { + signed char param = mMoveProgram[settings.crazyMoveState++]; + if (param == '?') + { + const char cmd[] = {'l', 'r', 'u', 'd'}; + srand(tick_time); + param = cmd[rand() % 4]; + } + switch (param) + { + case 'd': // if (PacketLimiter::limitPackets(PACKET_DIRECTION)) - { - localPlayer->setDirection(BeingDirection::DOWN); - playerHandler->setDirection( - BeingDirection::DOWN); - } - break; - case 'u': + { + localPlayer->setDirection(BeingDirection::DOWN); + playerHandler->setDirection( + BeingDirection::DOWN); + } + break; + case 'u': // if (PacketLimiter::limitPackets(PACKET_DIRECTION)) - { - localPlayer->setDirection(BeingDirection::UP); - playerHandler->setDirection( - BeingDirection::UP); - } - break; - case 'l': + { + localPlayer->setDirection(BeingDirection::UP); + playerHandler->setDirection( + BeingDirection::UP); + } + break; + case 'l': // if (PacketLimiter::limitPackets(PACKET_DIRECTION)) - { - localPlayer->setDirection(BeingDirection::LEFT); - playerHandler->setDirection( - BeingDirection::LEFT); - } - break; - case 'r': + { + localPlayer->setDirection(BeingDirection::LEFT); + playerHandler->setDirection( + BeingDirection::LEFT); + } + break; + case 'r': // if (PacketLimiter::limitPackets(PACKET_DIRECTION)) - { - localPlayer->setDirection(BeingDirection::RIGHT); - playerHandler->setDirection( - BeingDirection::RIGHT); - } - break; - case 'L': + { + localPlayer->setDirection(BeingDirection::RIGHT); + playerHandler->setDirection( + BeingDirection::RIGHT); + } + break; + case 'L': // if (PacketLimiter::limitPackets(PACKET_DIRECTION)) + { + uint8_t dir = 0; + switch (localPlayer->getDirection()) { - uint8_t dir = 0; - switch (localPlayer->getDirection()) - { - case BeingDirection::UP: - dir = BeingDirection::LEFT; - break; - case BeingDirection::DOWN: - dir = BeingDirection::RIGHT; - break; - case BeingDirection::LEFT: - dir = BeingDirection::DOWN; - break; - case BeingDirection::RIGHT: - dir = BeingDirection::UP; - break; - default: - break; - } - localPlayer->setDirection(dir); - playerHandler->setDirection(dir); + case BeingDirection::UP: + dir = BeingDirection::LEFT; + break; + case BeingDirection::DOWN: + dir = BeingDirection::RIGHT; + break; + case BeingDirection::LEFT: + dir = BeingDirection::DOWN; + break; + case BeingDirection::RIGHT: + dir = BeingDirection::UP; + break; + default: + break; } - break; - case 'R': + localPlayer->setDirection(dir); + playerHandler->setDirection(dir); + } + break; + case 'R': // if (PacketLimiter::limitPackets(PACKET_DIRECTION)) + { + uint8_t dir = 0; + switch (localPlayer->getDirection()) { - uint8_t dir = 0; - switch (localPlayer->getDirection()) - { - case BeingDirection::UP: - dir = BeingDirection::RIGHT; - break; - case BeingDirection::DOWN: - dir = BeingDirection::LEFT; - break; - case BeingDirection::LEFT: - dir = BeingDirection::UP; - break; - case BeingDirection::RIGHT: - dir = BeingDirection::DOWN; - break; - default: - break; - } - localPlayer->setDirection(dir); - playerHandler->setDirection(dir); + case BeingDirection::UP: + dir = BeingDirection::RIGHT; + break; + case BeingDirection::DOWN: + dir = BeingDirection::LEFT; + break; + case BeingDirection::LEFT: + dir = BeingDirection::UP; + break; + case BeingDirection::RIGHT: + dir = BeingDirection::DOWN; + break; + default: + break; } - break; - case 'b': + localPlayer->setDirection(dir); + playerHandler->setDirection(dir); + } + break; + case 'b': // if (PacketLimiter::limitPackets(PACKET_DIRECTION)) + { + uint8_t dir = 0; + switch (localPlayer->getDirection()) { - uint8_t dir = 0; - switch (localPlayer->getDirection()) - { - case BeingDirection::UP: - dir = BeingDirection::DOWN; - break; - case BeingDirection::DOWN: - dir = BeingDirection::UP; - break; - case BeingDirection::LEFT: - dir = BeingDirection::RIGHT; - break; - case BeingDirection::RIGHT: - dir = BeingDirection::LEFT; - break; - default: - break; - } - localPlayer->setDirection(dir); - playerHandler->setDirection(dir); + case BeingDirection::UP: + dir = BeingDirection::DOWN; + break; + case BeingDirection::DOWN: + dir = BeingDirection::UP; + break; + case BeingDirection::LEFT: + dir = BeingDirection::RIGHT; + break; + case BeingDirection::RIGHT: + dir = BeingDirection::LEFT; + break; + default: + break; } - break; - case '0': - dropShortcut->dropFirst(); - break; - case 'a': - dropShortcut->dropItems(); - break; - default: - break; - } + localPlayer->setDirection(dir); + playerHandler->setDirection(dir); + } + break; + case '0': + dropShortcut->dropFirst(); + break; + case 'a': + dropShortcut->dropItems(); + break; + default: + break; + } + } +} + +void CrazyMoves::crazyMoveAs() +{ + settings.crazyMoveState ++; + if (localPlayer->toggleSit()) + settings.crazyMoveState ++; +} + +void CrazyMoves::crazyMoveAo() +{ + settings.crazyMoveState ++; + if (settings.crazyMoveState < mMoveProgram.length()) + { + // wear next outfit + if (mMoveProgram[settings.crazyMoveState] == 'n') + { + settings.crazyMoveState ++; + outfitWindow->wearNextOutfit(); + } + // wear previous outfit + else if (mMoveProgram[settings.crazyMoveState] == 'p') + { + settings.crazyMoveState ++; + outfitWindow->wearPreviousOutfit(); } } +} + +void CrazyMoves::crazyMoveAe() +{ + settings.crazyMoveState ++; + const signed char emo = mMoveProgram[settings.crazyMoveState]; + unsigned char emoteId = 0; + if (emo == '?') + { + srand(tick_time); + emoteId = static_cast( + 1 + (rand() % EmoteDB::size())); + } + else + { + if (emo >= '0' && emo <= '9') + emoteId = static_cast(emo - '0' + 1); + else if (emo >= 'a' && emo <= 'z') + emoteId = static_cast(emo - 'a' + 11); + else if (emo >= 'A' && emo <= 'Z') + emoteId = static_cast(emo - 'A' + 37); + } + if (mMoveProgram[settings.crazyMoveState - 1] == 'e') + localPlayer->emote(emoteId); + else if (PacketLimiter::limitPackets(PACKET_CHAT)) + petHandler->emote(emoteId, 0); + + settings.crazyMoveState ++; +} + +void CrazyMoves::crazyMoveA() +{ + mMoveProgram = config.getStringValue("crazyMoveProgram"); + + if (localPlayer->getCurrentAction() == BeingAction::MOVE) + return; + + if (mMoveProgram.empty()) + return; + + if (settings.crazyMoveState >= mMoveProgram.length()) + settings.crazyMoveState = 0; + + // move command + if (mMoveProgram[settings.crazyMoveState] == 'm') + { + crazyMoveAm(); + } + // direction command + else if (mMoveProgram[settings.crazyMoveState] == 'd') + { + crazyMoveAd(); + } // sit command else if (mMoveProgram[settings.crazyMoveState] == 's') { - settings.crazyMoveState ++; - if (localPlayer->toggleSit()) - settings.crazyMoveState ++; + crazyMoveAs(); } // wear outfits else if (mMoveProgram[settings.crazyMoveState] == 'o') { - settings.crazyMoveState ++; - if (settings.crazyMoveState < mMoveProgram.length()) - { - // wear next outfit - if (mMoveProgram[settings.crazyMoveState] == 'n') - { - settings.crazyMoveState ++; - outfitWindow->wearNextOutfit(); - } - // wear previous outfit - else if (mMoveProgram[settings.crazyMoveState] == 'p') - { - settings.crazyMoveState ++; - outfitWindow->wearPreviousOutfit(); - } - } + crazyMoveAo(); } // pause else if (mMoveProgram[settings.crazyMoveState] == 'w') @@ -721,30 +769,7 @@ void CrazyMoves::crazyMoveA() else if (mMoveProgram[settings.crazyMoveState] == 'e' || mMoveProgram[settings.crazyMoveState] == 'E') { - settings.crazyMoveState ++; - const signed char emo = mMoveProgram[settings.crazyMoveState]; - unsigned char emoteId = 0; - if (emo == '?') - { - srand(tick_time); - emoteId = static_cast( - 1 + (rand() % EmoteDB::size())); - } - else - { - if (emo >= '0' && emo <= '9') - emoteId = static_cast(emo - '0' + 1); - else if (emo >= 'a' && emo <= 'z') - emoteId = static_cast(emo - 'a' + 11); - else if (emo >= 'A' && emo <= 'Z') - emoteId = static_cast(emo - 'A' + 37); - } - if (mMoveProgram[settings.crazyMoveState - 1] == 'e') - localPlayer->emote(emoteId); - else if (PacketLimiter::limitPackets(PACKET_CHAT)) - petHandler->emote(emoteId, 0); - - settings.crazyMoveState ++; + crazyMoveAe(); } else { diff --git a/src/being/crazymoves.h b/src/being/crazymoves.h index c97d8db45..d9edb7a2c 100644 --- a/src/being/crazymoves.h +++ b/src/being/crazymoves.h @@ -23,6 +23,8 @@ #ifndef BEING_CRAZYMOVES_H #define BEING_CRAZYMOVES_H +#include + #include "localconsts.h" class CrazyMoves final @@ -43,6 +45,13 @@ class CrazyMoves final void crazyMove8(); void crazyMove9(); void crazyMoveA(); + void crazyMoveAd(); + void crazyMoveAe(); + void crazyMoveAm(); + void crazyMoveAo(); + void crazyMoveAs(); + + std::string mMoveProgram; // temporary disable crazy moves in moves bool mDisableCrazyMove; -- cgit v1.2.3-60-g2f50