From 0bdafe7e15a6371deb043cdaa6232719e8b74ae8 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Wed, 21 Jan 2015 05:19:02 +1100 Subject: [PATCH] minor file shuffling --- ...d_entities.cpp => in_world_characters.cpp} | 80 ------------- client/gameplay_scenes/in_world_monsters.cpp | 108 ++++++++++++++++++ server/server_logic.cpp | 32 +++--- server/server_monster_methods.cpp | 23 ++++ 4 files changed, 148 insertions(+), 95 deletions(-) rename client/gameplay_scenes/{in_world_entities.cpp => in_world_characters.cpp} (73%) create mode 100644 client/gameplay_scenes/in_world_monsters.cpp create mode 100644 server/server_monster_methods.cpp diff --git a/client/gameplay_scenes/in_world_entities.cpp b/client/gameplay_scenes/in_world_characters.cpp similarity index 73% rename from client/gameplay_scenes/in_world_entities.cpp rename to client/gameplay_scenes/in_world_characters.cpp index c1df09a..8002814 100644 --- a/client/gameplay_scenes/in_world_entities.cpp +++ b/client/gameplay_scenes/in_world_characters.cpp @@ -147,86 +147,6 @@ void InWorld::HandleCharacterAttack(CharacterPacket* const argPacket) { //TODO: attack animation } -//------------------------- -//monster management -//------------------------- - -void InWorld::HandleMonsterCreate(MonsterPacket* const argPacket) { - //check for logic errors - if (monsterMap.find(argPacket->monsterIndex) != monsterMap.end()) { - std::ostringstream msg; - msg << "Double monster creation event; "; - msg << "Index: " << argPacket->monsterIndex << "; "; - msg << "Handle: " << argPacket->handle; - throw(std::runtime_error(msg.str())); - } - - //ignore monsters from other rooms - if (roomIndex != argPacket->roomIndex) { - //temporary error checking - std::ostringstream msg; - msg << "Monster from the wrong room received: "; - msg << "monsterIndex: " << argPacket->monsterIndex << ", roomIndex: " << argPacket->roomIndex; - throw(std::runtime_error(msg.str())); - } - - //implicitly create the element - BaseMonster* monster = &monsterMap[argPacket->monsterIndex]; - - //fill the monster's info - monster->SetHandle(argPacket->handle); - monster->SetAvatar(argPacket->avatar); - monster->SetBounds(argPacket->bounds); - monster->SetOrigin(argPacket->origin); - monster->SetMotion(argPacket->motion); - - //debug - std::cout << "Monster Create, total: " << monsterMap.size() << std::endl; -} - -void InWorld::HandleMonsterDelete(MonsterPacket* const argPacket) { - //ignore if this monster doesn't exist - std::map::iterator monsterIt = monsterMap.find(argPacket->monsterIndex); - if (monsterIt == monsterMap.end()) { - return; - } - - - //remove this monster - monsterMap.erase(monsterIt); - - //debug - std::cout << "Monster Delete, total: " << monsterMap.size() << std::endl; -} - -void InWorld::HandleMonsterQueryExists(MonsterPacket* const argPacket) { - //ignore monsters in a different room (sub-optimal) - if (argPacket->roomIndex != roomIndex) { - return; - } - - //implicitly create the element - BaseMonster* monster = &monsterMap[argPacket->monsterIndex]; - - //fill the monster's info - monster->SetHandle(argPacket->handle); - monster->SetAvatar(argPacket->avatar); - monster->SetBounds(argPacket->bounds); - monster->SetOrigin(argPacket->origin); - monster->SetMotion(argPacket->motion); - - //debug - std::cout << "Monster Query, total: " << monsterMap.size() << std::endl; -} - -void InWorld::HandleMonsterMovement(MonsterPacket* const argPacket) { - //TODO -} - -void InWorld::HandleMonsterAttack(MonsterPacket* const argPacket) { - //TODO -} - //------------------------- //player movement //------------------------- diff --git a/client/gameplay_scenes/in_world_monsters.cpp b/client/gameplay_scenes/in_world_monsters.cpp new file mode 100644 index 0000000..689b588 --- /dev/null +++ b/client/gameplay_scenes/in_world_monsters.cpp @@ -0,0 +1,108 @@ +/* Copyright: (c) Kayne Ruse 2013-2015 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#include "in_world.hpp" + +#include "channels.hpp" + +#include +#include +#include + +//------------------------- +//monster management +//------------------------- + +void InWorld::HandleMonsterCreate(MonsterPacket* const argPacket) { + //check for logic errors + if (monsterMap.find(argPacket->monsterIndex) != monsterMap.end()) { + std::ostringstream msg; + msg << "Double monster creation event; "; + msg << "Index: " << argPacket->monsterIndex << "; "; + msg << "Handle: " << argPacket->handle; + throw(std::runtime_error(msg.str())); + } + + //ignore monsters from other rooms + if (roomIndex != argPacket->roomIndex) { + //temporary error checking + std::ostringstream msg; + msg << "Monster from the wrong room received: "; + msg << "monsterIndex: " << argPacket->monsterIndex << ", roomIndex: " << argPacket->roomIndex; + throw(std::runtime_error(msg.str())); + } + + //implicitly create the element + BaseMonster* monster = &monsterMap[argPacket->monsterIndex]; + + //fill the monster's info + monster->SetHandle(argPacket->handle); + monster->SetAvatar(argPacket->avatar); + monster->SetBounds(argPacket->bounds); + monster->SetOrigin(argPacket->origin); + monster->SetMotion(argPacket->motion); + + //debug + std::cout << "Monster Create, total: " << monsterMap.size() << std::endl; +} + +void InWorld::HandleMonsterDelete(MonsterPacket* const argPacket) { + //ignore if this monster doesn't exist + std::map::iterator monsterIt = monsterMap.find(argPacket->monsterIndex); + if (monsterIt == monsterMap.end()) { + return; + } + + + //remove this monster + monsterMap.erase(monsterIt); + + //debug + std::cout << "Monster Delete, total: " << monsterMap.size() << std::endl; +} + +void InWorld::HandleMonsterQueryExists(MonsterPacket* const argPacket) { + //ignore monsters in a different room (sub-optimal) + if (argPacket->roomIndex != roomIndex) { + return; + } + + //implicitly create the element + BaseMonster* monster = &monsterMap[argPacket->monsterIndex]; + + //fill the monster's info + monster->SetHandle(argPacket->handle); + monster->SetAvatar(argPacket->avatar); + monster->SetBounds(argPacket->bounds); + monster->SetOrigin(argPacket->origin); + monster->SetMotion(argPacket->motion); + + //debug + std::cout << "Monster Query, total: " << monsterMap.size() << std::endl; +} + +void InWorld::HandleMonsterMovement(MonsterPacket* const argPacket) { + //TODO +} + +void InWorld::HandleMonsterAttack(MonsterPacket* const argPacket) { + //TODO +} \ No newline at end of file diff --git a/server/server_logic.cpp b/server/server_logic.cpp index 24192f2..23a94d1 100644 --- a/server/server_logic.cpp +++ b/server/server_logic.cpp @@ -261,6 +261,9 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { case SerialPacketType::QUERY_CHARACTER_EXISTS: HandleCharacterExists(static_cast(argPacket)); break; + case SerialPacketType::QUERY_MONSTER_EXISTS: +// HandleMonsterExists(static_cast(argPacket)); + break; //character management case SerialPacketType::CHARACTER_CREATE: @@ -276,16 +279,6 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { HandleCharacterUnload(static_cast(argPacket)); break; -/* case SerialPacketType::QUERY_CHARACTER_EXISTS: - // - break; - case SerialPacketType::QUERY_CHARACTER_STATS: - // - break; - case SerialPacketType::QUERY_CHARACTER_LOCATION: - // - break; -*/ //character movement case SerialPacketType::CHARACTER_MOVEMENT: HandleCharacterMovement(static_cast(argPacket)); @@ -293,12 +286,21 @@ void ServerApplication::HandlePacket(SerialPacket* const argPacket) { case SerialPacketType::CHARACTER_ATTACK: HandleCharacterAttack(static_cast(argPacket)); break; -/* - //enemy management - //TODO: enemy management - //TODO: text -*/ + //monster management + case SerialPacketType::MONSTER_CREATE: +// HandleMonsterCreate(static_cast(argPacket)); + break; + case SerialPacketType::MONSTER_DELETE: +// HandleMonsterDelete(static_cast(argPacket)); + break; + case SerialPacketType::MONSTER_MOVEMENT: +// HandleMonsterMovement(static_cast(argPacket)); + break; + case SerialPacketType::MONSTER_ATTACK: +// HandleMonsterAttack(static_cast(argPacket)); + break; + //handle errors default: { std::ostringstream msg; diff --git a/server/server_monster_methods.cpp b/server/server_monster_methods.cpp new file mode 100644 index 0000000..3079d7a --- /dev/null +++ b/server/server_monster_methods.cpp @@ -0,0 +1,23 @@ +/* Copyright: (c) Kayne Ruse 2013-2015 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. +*/ +#include "server_application.hpp" +