diff options
author | Aaron Marks <nymacro@gmail.com> | 2005-11-21 09:02:43 +0000 |
---|---|---|
committer | Aaron Marks <nymacro@gmail.com> | 2005-11-21 09:02:43 +0000 |
commit | 73495c824375268df060e792a44a631443268b98 (patch) | |
tree | a5608abc930b6e523e18dc57eb083e6671fc54e6 /src | |
parent | 3d5bcc32ea4ac19e8da7bcf4a59443f3a013ba6d (diff) | |
download | manaserv-73495c824375268df060e792a44a631443268b98.tar.gz manaserv-73495c824375268df060e792a44a631443268b98.tar.bz2 manaserv-73495c824375268df060e792a44a631443268b98.tar.xz manaserv-73495c824375268df060e792a44a631443268b98.zip |
Did some initial work for map loading & adding beings to game world.
Diffstat (limited to 'src')
-rw-r--r-- | src/accounthandler.cpp | 4 | ||||
-rw-r--r-- | src/being.h | 3 | ||||
-rw-r--r-- | src/dalstorage.cpp | 10 | ||||
-rw-r--r-- | src/object.cpp | 9 | ||||
-rw-r--r-- | src/object.h | 16 | ||||
-rw-r--r-- | src/state.cpp | 53 | ||||
-rw-r--r-- | src/state.h | 56 |
7 files changed, 111 insertions, 40 deletions
diff --git a/src/accounthandler.cpp b/src/accounthandler.cpp index 91276404..30e726d5 100644 --- a/src/accounthandler.cpp +++ b/src/accounthandler.cpp @@ -158,8 +158,8 @@ void AccountHandler::receiveMessage(NetComputer &computer, MessageIn &message) computer.setCharacter(chars[charNum].get()); // place in world - //tmwserv::State &state = tmwserv::State::instance(); - //state.beings["start.tmx"].push_back(tmwserv::BeingPtr(computer.getCharacter())); + tmwserv::State &state = tmwserv::State::instance(); + state.addBeing(computer.getCharacter(), computer.getCharacter()->getMap()); result.writeByte(SELECT_OK); } diff --git a/src/being.h b/src/being.h index bbb86346..b68f1c5f 100644 --- a/src/being.h +++ b/src/being.h @@ -290,7 +290,7 @@ class Being: public Object /** * Un-equips item. * - * bool Un-equip success/failure + * @return Un-equip success/failure */ bool unequip(unsigned char slot); @@ -307,7 +307,6 @@ class Being: public Object Being& operator=(const Being& rhs); - private: std::string mName; /**< name of the being */ Genders mGender; /**< gender of the being */ unsigned short mLevel; /**< level of the being */ diff --git a/src/dalstorage.cpp b/src/dalstorage.cpp index bc166358..45468f86 100644 --- a/src/dalstorage.cpp +++ b/src/dalstorage.cpp @@ -204,7 +204,7 @@ DALStorage::getAccount(const std::string& userName) // load the characters associated with the account. sql = "select * from "; sql += CHARACTERS_TBL_NAME; - sql += " where id = '"; + sql += " where user_id = '"; sql += accountInfo(0, 0); sql += "';"; const RecordSet& charInfo = mDb->execSql(sql); @@ -233,6 +233,14 @@ DALStorage::getAccount(const std::string& userName) stats )); + std::stringstream ss; + ss << "select map from " + MAPS_TBL_NAME + " where id = " + << toUint(charInfo(i, 8)) << ";"; + sql = ss.str(); + // should be impossible for this to fail due to db referential integrity + const RecordSet& mapInfo = mDb->execSql(sql); + being.get()->setMap(mapInfo(0, 0)); + mCharacters.push_back(being); beings.push_back(being); } diff --git a/src/object.cpp b/src/object.cpp index ce1b2bc1..75ce0bec 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -139,5 +139,14 @@ Object::getStatistics(void) return mStats; } +const std::string & +Object::getMap() { + return mMap; +} + +void +Object::setMap(const std::string &map) { + mMap = map; +} } // namespace tmwserv diff --git a/src/object.h b/src/object.h index 3f913b20..a00b81ec 100644 --- a/src/object.h +++ b/src/object.h @@ -26,6 +26,7 @@ #include <utility> +#include <string> namespace tmwserv @@ -152,6 +153,19 @@ class Object virtual void update(void) = 0; + /** + * Get map name where being is + * + * @return Name of map being is located. + */ + const std::string & + getMap(); + + /** + * Set map being is located + */ + void + setMap(const std::string &map); protected: Statistics mStats; /**< stats modifiers or computed stats */ @@ -161,6 +175,8 @@ class Object private: unsigned int mX; /**< x coordinate */ unsigned int mY; /**< y coordinate */ + + std::string mMap; /**< name of the map being is on */ }; diff --git a/src/state.cpp b/src/state.cpp index 919f1817..ec027531 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -25,10 +25,22 @@ #include <iostream> #include "messageout.h" #include "utils/logger.h" +#include "mapreader.h" namespace tmwserv { +State::State() throw() { +} + +State::~State() throw() { + for (std::map<std::string, MapComposite>::iterator i = maps.begin(); + i != maps.end(); + i++) { + delete i->second.map; + } +} + void State::update(ConnectionHandler &connectionHandler) { // update game state (update AI, etc.) @@ -71,11 +83,13 @@ void State::update(ConnectionHandler &connectionHandler) } void State::addBeing(Being *being, const std::string &map) { - if (!mapExists(map)) - return; + if (!beingExists(being)) { + if (!mapExists(map)) + if (!loadMap(map)) + return; - if (!beingExists(being)) maps[map].beings.push_back(tmwserv::BeingPtr(being)); + } } void State::removeBeing(Being *being) { @@ -114,17 +128,42 @@ bool State::beingExists(Being *being) { return false; } -void State::loadMap(const std::string &map) { - // load map +bool State::loadMap(const std::string &map) { + // load map (FAILS) + Map *tmp = NULL; //MapReader::readMap("maps/" + map); + //if (!tmp) + // return false; + maps[map] = MapComposite(); + maps[map].map = tmp; + + // will need to load extra map related resources here also + + return true; } void State::addObject(Object *object, const std::string &map) { - // + if (!objectExists(object)) { + if (!mapExists(map)) + if (!loadMap(map)) + return; + maps[map].objects.push_back(object); + } } void State::removeObject(Object *object) { - // + for (std::map<std::string, MapComposite>::iterator i = maps.begin(); + i != maps.end(); + i++) { + for (std::vector<Object*>::iterator b = i->second.objects.begin(); + b != i->second.objects.end(); + b++) { + if (*b == object) { + i->second.objects.erase(b); + return; + } + } + } } bool State::objectExists(Object *object) { diff --git a/src/state.h b/src/state.h index 4d1c9a37..5599e36e 100644 --- a/src/state.h +++ b/src/state.h @@ -35,6 +35,31 @@ namespace tmwserv { /** + * Combined map/entity structure + */ +struct MapComposite { + /** + * Default constructor + */ + MapComposite() : map(NULL) { } + + /** + * Actual map + */ + Map *map; + + /** + * Beings located on the map + */ + Beings beings; + + /** + * Items located on the map + */ + std::vector<Object*> objects; +}; + +/** * State class contains all information/procedures associated with the game * world's state. */ @@ -42,33 +67,8 @@ class State : public utils::Singleton<State> { friend class utils::Singleton<State>; - State() throw() { } - ~State() throw() { } - - /** - * Combined map/entity structure - */ - struct MapComposite { - /** - * Default constructor - */ - MapComposite() : map(NULL) { } - - /** - * Actual map - */ - Map *map; - - /** - * Beings located on the map - */ - Beings beings; - - /** - * Items located on the map - */ - std::vector<Object*> objects; - }; + State() throw(); + ~State() throw(); /** * List of maps @@ -105,7 +105,7 @@ class State : public utils::Singleton<State> /** * Load map into game world */ - void loadMap(const std::string &map); + bool loadMap(const std::string &map); /** * Add object to the map |