From 50f46449cc04e085b3fbbc821f9108be5e23f715 Mon Sep 17 00:00:00 2001 From: Eugenio Favalli Date: Thu, 12 Jan 2006 14:50:39 +0000 Subject: Fixed default map definition for a new created character, enabled loading of map when a character is on it, fixed inconsistency in getter/setter for map id. --- src/accounthandler.cpp | 1 + src/client.cpp | 3 +++ src/dalstorage.cpp | 10 +++++----- src/main.cpp | 6 ------ src/mapmanager.cpp | 22 ++++++++++++++++++++-- src/mapmanager.h | 7 ++++++- src/netcomputer.cpp | 2 +- src/object.cpp | 2 +- src/object.h | 2 +- src/state.cpp | 14 +++++++++----- 10 files changed, 47 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp index 1d1aef31..70021793 100644 --- a/src/accounthandler.cpp +++ b/src/accounthandler.cpp @@ -510,6 +510,7 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message) rawStats[3], rawStats[4], rawStats[5]}; tmwserv::BeingPtr newCharacter(new tmwserv::Being(name, gender, hairStyle, hairColor, 1 /* level */, 0 /* Money */, stats)); + newCharacter->setMap(DEFAULT_MAP_ID); computer.getAccount()->addCharacter(newCharacter); LOG_INFO("Character " << name << " was created for " diff --git a/src/client.cpp b/src/client.cpp index 8c14e8b4..c1f968ba 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -346,6 +346,9 @@ int main(int argc, char *argv[]) case REGISTER_INVALID_EMAIL: std::cout << "Account registering: Invalid Email." << std::endl; break; + case REGISTER_INVALID_VERSION: + std::cout << "Account registering: Invalid version." << std::endl; + break; case REGISTER_EXISTS_USERNAME: std::cout << "Account registering: Username already exists." << std::endl; break; diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp index fc168925..539d5ac1 100644 --- a/src/dalstorage.cpp +++ b/src/dalstorage.cpp @@ -269,13 +269,13 @@ DALStorage::getAccount(const std::string& userName) ssMapId >> mapId; if ( mapId > 0 ) { - being.get()->setMap(mapId); + being->setMap(mapId); } else { // Set player to default map and one of the default location // Default map is to be 1, as not found return value will be 0. - being.get()->setMap(DEFAULT_MAP_ID); + being->setMap(DEFAULT_MAP_ID); } mCharacters.push_back(being); @@ -653,7 +653,7 @@ DALStorage::_addAccount(const AccountPtr& account) << (*it)->getMoney() << ", " << (*it)->getX() << ", " << (*it)->getY() << ", " - << (int)(*it)->getMapId() << ", " + << (int)(*it)->getMap() << ", " << stats.strength << ", " << stats.agility << ", " << stats.vitality << ", " @@ -750,7 +750,7 @@ DALStorage::_updAccount(const AccountPtr& account) << (*it)->getMoney() << ", " << (*it)->getX() << ", " << (*it)->getY() << ", " - << (*it)->getMapId() << ", " + << (*it)->getMap() << ", " << stats.strength << ", " << stats.agility << ", " << stats.vitality << ", " @@ -768,7 +768,7 @@ DALStorage::_updAccount(const AccountPtr& account) << " money = " << (*it)->getMoney() << ", " << " x = " << (*it)->getX() << ", " << " y = " << (*it)->getY() << ", " - << " map_id = " << (*it)->getMapId() << ", " + << " map_id = " << (*it)->getMap() << ", " << " str = " << stats.strength << ", " << " agi = " << stats.agility << ", " << " vit = " << stats.vitality << ", " diff --git a/src/main.cpp b/src/main.cpp index b915b4d9..cb261b7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,7 +37,6 @@ #include "configuration.h" #include "connectionhandler.h" #include "gamehandler.h" -#include "mapmanager.h" #include "netsession.h" #include "resourcemanager.h" #include "skill.h" @@ -237,11 +236,6 @@ void initialize() // Initialize PhysicsFS PHYSFS_init(""); - - // TODO: only a test, maps should be loaded as they are needed - tmwserv::MapManager::instance().loadMap(1); - tmwserv::MapManager::instance().reloadMap(1); - tmwserv::MapManager::instance().unloadMap(1); } diff --git a/src/mapmanager.cpp b/src/mapmanager.cpp index be208838..360503f9 100644 --- a/src/mapmanager.cpp +++ b/src/mapmanager.cpp @@ -35,7 +35,7 @@ MapManager::~MapManager() { } -void MapManager::loadMap(const unsigned int mapId) +Map *MapManager::loadMap(const unsigned int mapId) { Storage &store = Storage::instance("tmw"); std::string mapFile = store.getMapNameFromId(mapId); @@ -46,9 +46,10 @@ void MapManager::loadMap(const unsigned int mapId) } else { - LOG_INFO("Loaded map " << maps.size() << " (" << mapFile << ")", 0); + LOG_INFO("Loaded map " << mapId << " (" << mapFile << ")", 0); maps[mapId] = map; } + return map; } void MapManager::unloadMap(const unsigned int mapId) @@ -84,8 +85,25 @@ Map *MapManager::getMap(const unsigned int mapId) { result = i->second; } + else + { + result = loadMap(mapId); + } return result; } +bool MapManager::isLoaded(const unsigned int mapId) +{ + bool ret = false; + std::map::iterator i; + + i = maps.find(mapId); + if (i != maps.end()) + { + ret = true; + } + return ret; +} + } // namespace tmwserv diff --git a/src/mapmanager.h b/src/mapmanager.h index be166881..ede3ec6f 100644 --- a/src/mapmanager.h +++ b/src/mapmanager.h @@ -46,7 +46,7 @@ class MapManager: public utils::Singleton /** * Load the specified map */ - void loadMap(const unsigned int mapId); + Map *loadMap(const unsigned int mapId); /** * Unload the specified map @@ -62,6 +62,11 @@ class MapManager: public utils::Singleton * Return the requested map */ Map *getMap(const unsigned int mapId); + + /** + * Check if a map was already loaded. + */ + bool isLoaded(const unsigned int mapId); protected: /** diff --git a/src/netcomputer.cpp b/src/netcomputer.cpp index 40685b51..2bf04db8 100644 --- a/src/netcomputer.cpp +++ b/src/netcomputer.cpp @@ -64,7 +64,7 @@ void NetComputer::setCharacter(tmwserv::BeingPtr ch) state.removeBeing(characterPtr); } characterPtr = ch; - state.addBeing(characterPtr, characterPtr->getMapId()); + state.addBeing(characterPtr, characterPtr->getMap()); } void NetComputer::unsetAccount() diff --git a/src/object.cpp b/src/object.cpp index fc156e7e..571f48de 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -140,7 +140,7 @@ Object::getStatistics(void) } const unsigned int -Object::getMapId() { +Object::getMap() { return mMapId; } diff --git a/src/object.h b/src/object.h index 26edf884..f4d7a319 100644 --- a/src/object.h +++ b/src/object.h @@ -159,7 +159,7 @@ class Object * @return Name of map being is located. */ const unsigned int - getMapId(); + getMap(); /** * Set map being is located diff --git a/src/state.cpp b/src/state.cpp index 1fbbb189..d49bf407 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -22,10 +22,13 @@ */ #include "state.h" + #include + +#include "mapmanager.h" #include "messageout.h" + #include "utils/logger.h" -#include "mapreader.h" namespace tmwserv { @@ -131,10 +134,11 @@ bool State::beingExists(BeingPtr beingPtr) { } bool State::loadMap(const unsigned int mapId) { - // load map (FAILS) - Map *tmp = NULL; //MapReader::readMap("maps/" + map); - //if (!tmp) - // return false; + Map *tmp = MapManager::instance().loadMap(mapId); + if (!tmp) + { + return false; + } maps[mapId] = MapComposite(); maps[mapId].map = tmp; -- cgit v1.2.3-60-g2f50