From 4a8080dcf73dab2b6e62b8500fec3bb996bcbf17 Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Tue, 2 Apr 2013 22:25:24 +0200 Subject: Fixed multiple warnings and errors that blocked c++0x This allows the server to compile with c++0x (and enables it). This also includes some coding style / readabillity fixes. --- src/CMakeLists.txt | 2 ++ src/chat-server/chathandler.cpp | 2 +- src/common/permissionmanager.cpp | 2 +- src/game-server/buysell.cpp | 26 +++++++++++++--------- src/game-server/buysell.h | 8 ++++--- src/game-server/character.cpp | 3 ++- src/game-server/commandhandler.cpp | 8 +++---- src/game-server/inventory.cpp | 3 +-- src/game-server/itemmanager.cpp | 3 +-- src/game-server/mapcomposite.cpp | 3 ++- src/game-server/skillmanager.cpp | 3 +-- src/game-server/state.cpp | 38 +++++++++++++++++++------------- src/game-server/state.h | 4 ++-- src/game-server/trade.cpp | 7 ++++-- src/game-server/trade.h | 5 +++-- src/game-server/triggerareacomponent.cpp | 2 +- src/game-server/triggerareacomponent.h | 6 ++--- src/scripting/lua.cpp | 2 +- 18 files changed, 74 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c88d716..85d6b6d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,6 +41,8 @@ SET(FLAGS "${FLAGS} -DPACKAGE_VERSION=\\\"${VERSION}\\\"") SET(FLAGS "${FLAGS} -DPKG_DATADIR=\\\"${PKG_DATADIR}/\\\"") SET(FLAGS "${FLAGS} -DLOCALEDIR=\\\"${LOCALEDIR}/\\\"") +SET(FLAGS "${FLAGS} -std=c++0x") + # If the Sqlite option is enabled... IF (WITH_SQLITE) FIND_PACKAGE(Sqlite3 REQUIRED) diff --git a/src/chat-server/chathandler.cpp b/src/chat-server/chathandler.cpp index 63aaa43a..93b1af43 100644 --- a/src/chat-server/chathandler.cpp +++ b/src/chat-server/chathandler.cpp @@ -443,7 +443,7 @@ void ChatHandler::handleModeChangeMessage(ChatClient &client, MessageIn &msg) trans.mCharacterId = client.characterId; trans.mAction = TRANS_CHANNEL_MODE; trans.mMessage = "User mode "; - trans.mMessage.append(mode + " set on " + user); + trans.mMessage.append(utils::toString(mode) + " set on " + user); storage->addTransaction(trans); } diff --git a/src/common/permissionmanager.cpp b/src/common/permissionmanager.cpp index 573e1d26..5510fd7c 100644 --- a/src/common/permissionmanager.cpp +++ b/src/common/permissionmanager.cpp @@ -37,7 +37,7 @@ void addPermission(std::string permission, char mask) std::map::iterator i = permissions.find(permission); if (i == permissions.end()) { - permissions.insert(std::make_pair(permission, mask)); + permissions.insert(std::make_pair(permission, mask)); } else { i->second |= mask; } diff --git a/src/game-server/buysell.cpp b/src/game-server/buysell.cpp index ed6d92e4..1e63d523 100644 --- a/src/game-server/buysell.cpp +++ b/src/game-server/buysell.cpp @@ -46,7 +46,7 @@ void BuySell::cancel() delete this; } -bool BuySell::registerItem(int id, int amount, int cost) +bool BuySell::registerItem(unsigned id, int amount, int cost) { if (mSell) { @@ -57,8 +57,11 @@ bool BuySell::registerItem(int id, int amount, int cost) amount = nb; } - TradedItem it = { id, amount, cost }; - mItems.push_back(it); + TradedItem item; + item.itemId = id; + item.amount = amount; + item.cost = cost; + mItems.push_back(item); return true; } @@ -76,11 +79,11 @@ int BuySell::registerPlayerItems() for (InventoryData::const_iterator it = inventoryData.begin(), it_end = inventoryData.end(); it != it_end; ++it) { - unsigned nb = it->second.amount; - if (!nb) + unsigned amount = it->second.amount; + if (!amount) continue; - int id = it->second.itemId; + unsigned id = it->second.itemId; int cost = -1; if (itemManager->getItem(id)) { @@ -106,15 +109,18 @@ int BuySell::registerPlayerItems() if (i->itemId == id) { itemAlreadyAdded = true; - i->amount += nb; + i->amount += amount; break; } } if (!itemAlreadyAdded) { - TradedItem itTrade = { id, nb, cost }; - mItems.push_back(itTrade); + TradedItem tradeItem; + tradeItem.itemId = id; + tradeItem.amount = amount; + tradeItem.cost = cost; + mItems.push_back(tradeItem); nbItemsToSell++; } } @@ -142,7 +148,7 @@ bool BuySell::start(Actor *actor) return true; } -void BuySell::perform(int id, int amount) +void BuySell::perform(unsigned id, int amount) { Inventory inv(mChar); for (TradedItems::iterator i = mItems.begin(), diff --git a/src/game-server/buysell.h b/src/game-server/buysell.h index 38566005..72da2ce6 100644 --- a/src/game-server/buysell.h +++ b/src/game-server/buysell.h @@ -45,7 +45,7 @@ class BuySell * and how much it will cost. * @return true if at least one item was registered. */ - bool registerItem(int id, int amount, int cost); + bool registerItem(unsigned id, int amount, int cost); /** * Registers every player's item at an average cost given by the ItemDB. @@ -62,7 +62,7 @@ class BuySell /** * Performs the trade. */ - void perform(int id, int amount); + void perform(unsigned id, int amount); private: @@ -70,7 +70,9 @@ class BuySell struct TradedItem { - unsigned short itemId, amount, cost; + unsigned itemId; + int amount; + int cost; }; typedef std::vector< TradedItem > TradedItems; diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 994e3311..e52747fd 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -223,7 +223,8 @@ void Character::respawn() int spawnX = Configuration::getValue("char_respawnX", 1024); int spawnY = Configuration::getValue("char_respawnY", 1024); - GameState::enqueueWarp(this, MapManager::getMap(spawnMap), spawnX, spawnY); + GameState::enqueueWarp(this, MapManager::getMap(spawnMap), + Point(spawnX, spawnY)); } bool Character::specialUseCheck(SpecialMap::iterator it) diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 353c3ef0..68899e3c 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -377,7 +377,7 @@ static void handleWarp(Character *player, std::string &args) y = utils::stringToInt(ystr); // now warp the player - GameState::warp(player, map, x, y); + GameState::warp(player, map, Point(x, y)); // log transaction std::stringstream ss; @@ -479,7 +479,7 @@ static void handleCharWarp(Character *player, std::string &args) y = utils::stringToInt(ystr); // now warp the player - GameState::warp(other, map, x, y); + GameState::warp(other, map, Point(x, y)); // log transaction std::stringstream ss; @@ -774,7 +774,7 @@ static void handleGoto(Character *player, std::string &args) // move the player to where the other player is MapComposite *map = other->getMap(); const Point &pos = other->getPosition(); - GameState::warp(player, map, pos.x, pos.y); + GameState::warp(player, map, pos); // log transaction std::stringstream msg; @@ -808,7 +808,7 @@ static void handleRecall(Character *player, std::string &args) // move the other player to where the player is MapComposite *map = player->getMap(); const Point &pos = player->getPosition(); - GameState::warp(other, map, pos.x, pos.y); + GameState::warp(other, map, pos); } static void handleReload(Character *, std::string &) diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp index 1fe09001..e14a36af 100644 --- a/src/game-server/inventory.cpp +++ b/src/game-server/inventory.cpp @@ -715,8 +715,7 @@ bool Inventory::equip(int inventorySlot) { EquipmentItem equipItem(it->second.itemId, itemInstance); mPoss->equipSlots.insert( - std::make_pair - (equipReq.equipSlotId, equipItem)); + std::make_pair(equipReq.equipSlotId, equipItem)); --capacityLeft; } } diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index 4837ce98..504ba127 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -159,8 +159,7 @@ void ItemManager::readEquipSlotsFile() << ", capacity: " << capacity << ", visible? " << visible); EquipSlotInfo *equipSlotInfo = new EquipSlotInfo(slotId, name, capacity, visible); - mEquipSlotsInfo.insert( - std::make_pair(slotId, equipSlotInfo)); + mEquipSlotsInfo.insert(std::make_pair(slotId, equipSlotInfo)); mNamedEquipSlotsInfo.insert(name, equipSlotInfo); totalCapacity += capacity; diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp index f1b545ec..bb7093b2 100644 --- a/src/game-server/mapcomposite.cpp +++ b/src/game-server/mapcomposite.cpp @@ -802,7 +802,8 @@ void MapComposite::initializeContent() if (destMap && destX && destY) { Entity *entity = new Entity(OBJECT_OTHER, this); - WarpAction *action = new WarpAction(destMap, destX, destY); + const Point warpTarget(destX, destY); + WarpAction *action = new WarpAction(destMap, warpTarget); entity->addComponent( new TriggerAreaComponent(object->getBounds(), action, false)); diff --git a/src/game-server/skillmanager.cpp b/src/game-server/skillmanager.cpp index 2e78194c..69a875e6 100644 --- a/src/game-server/skillmanager.cpp +++ b/src/game-server/skillmanager.cpp @@ -130,8 +130,7 @@ void SkillManager::readSkillNode(xmlNodePtr skillNode, mDefaultSkillId = skillInfo->id; } - mSkillsInfo.insert( - std::make_pair(skillInfo->id, skillInfo)); + mSkillsInfo.insert(std::make_pair(skillInfo->id, skillInfo)); std::string keyName = setName + "_" + skillInfo->skillName; mNamedSkillsInfo.insert(keyName, skillInfo); diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp index eaffe772..d3a29860 100644 --- a/src/game-server/state.cpp +++ b/src/game-server/state.cpp @@ -54,7 +54,8 @@ enum */ struct DelayedEvent { - unsigned short type, x, y; + unsigned short type; + Point point; MapComposite *map; }; @@ -104,9 +105,7 @@ static void serializeLooks(Character *ch, MessageOut &msg) // When the insertion succeeds, its the first time // we encounter the item, so we can send the look change. // We also send empty slots for unequipment handling. - lookChanges.insert( - std::make_pair(it->first, - it->second.itemId)); + lookChanges.insert(std::make_pair(it->first, it->second.itemId)); } } @@ -500,7 +499,7 @@ void GameState::update(int tick) case EVENT_WARP: assert(o->getType() == OBJECT_CHARACTER); - warp(static_cast< Character * >(o), e.map, e.x, e.y); + warp(static_cast< Character * >(o), e.map, e.point); break; } } @@ -700,11 +699,11 @@ void GameState::remove(Entity *ptr) map->remove(ptr); } -void GameState::warp(Character *ptr, MapComposite *map, int x, int y) +void GameState::warp(Character *ptr, MapComposite *map, const Point &point) { remove(ptr); ptr->setMap(map); - ptr->setPosition(Point(x, y)); + ptr->setPosition(point); ptr->clearDestination(); /* Force update of persistent data on map change, so that characters can respawn at the start of the map after a death or @@ -750,28 +749,37 @@ static void enqueueEvent(Actor *ptr, const DelayedEvent &e) void GameState::enqueueInsert(Actor *ptr) { - DelayedEvent e = { EVENT_INSERT, 0, 0, 0 }; - enqueueEvent(ptr, e); + DelayedEvent event; + event.type = EVENT_INSERT; + event.map = 0; + enqueueEvent(ptr, event); } void GameState::enqueueRemove(Actor *ptr) { - DelayedEvent e = { EVENT_REMOVE, 0, 0, 0 }; - enqueueEvent(ptr, e); + DelayedEvent event; + event.type = EVENT_REMOVE; + event.map = 0; + enqueueEvent(ptr, event); } -void GameState::enqueueWarp(Character *ptr, MapComposite *m, int x, int y) +void GameState::enqueueWarp(Character *ptr, + MapComposite *map, + const Point &point) { // When the player has just disconnected, better not wait for the pointer // to become invalid. if (!ptr->isConnected()) { - warp(ptr, m, x, y); + warp(ptr, map, point); return; } - DelayedEvent e = { EVENT_WARP, x, y, m }; - enqueueEvent(ptr, e); + DelayedEvent event; + event.type = EVENT_WARP; + event.point = point; + event.map = map; + enqueueEvent(ptr, event); } void GameState::sayAround(Actor *obj, const std::string &text) diff --git a/src/game-server/state.h b/src/game-server/state.h index c518972f..e8ed30a8 100644 --- a/src/game-server/state.h +++ b/src/game-server/state.h @@ -71,7 +71,7 @@ namespace GameState * @note No update may be in progress. * @note The character is destroyed, if needed. */ - void warp(Character *, MapComposite *, int x, int y); + void warp(Character *, MapComposite *, const Point &point); /** * Enqueues an insert event. @@ -90,7 +90,7 @@ namespace GameState * Enqueues a warp event. * @note The event will be executed at end of update. */ - void enqueueWarp(Character *, MapComposite *, int x, int y); + void enqueueWarp(Character *, MapComposite *, const Point &point); /** * Says something to an actor. diff --git a/src/game-server/trade.cpp b/src/game-server/trade.cpp index 0b906b1f..042719b2 100644 --- a/src/game-server/trade.cpp +++ b/src/game-server/trade.cpp @@ -249,8 +249,11 @@ void Trade::addItem(Character *c, int slot, int amount) later on. At worst, the transaction will be canceled at the end if the client lied. */ - TradedItem ti = { id, slot, amount }; - items->push_back(ti); + TradedItem tradedItem; + tradedItem.id = id; + tradedItem.slot = slot; + tradedItem.amount = amount; + items->push_back(tradedItem); MessageOut msg(GPMSG_TRADE_ADD_ITEM); msg.writeInt16(id); diff --git a/src/game-server/trade.h b/src/game-server/trade.h index 43b674fb..3e5fb3a3 100644 --- a/src/game-server/trade.h +++ b/src/game-server/trade.h @@ -77,8 +77,9 @@ class Trade struct TradedItem { - unsigned short id; - unsigned char slot, amount; + unsigned id; + unsigned slot; + int amount; }; typedef std::vector< TradedItem > TradedItems; diff --git a/src/game-server/triggerareacomponent.cpp b/src/game-server/triggerareacomponent.cpp index ebfe8580..7c32f097 100644 --- a/src/game-server/triggerareacomponent.cpp +++ b/src/game-server/triggerareacomponent.cpp @@ -34,7 +34,7 @@ void WarpAction::process(Actor *obj) { if (obj->getType() == OBJECT_CHARACTER) { - GameState::enqueueWarp(static_cast< Character * >(obj), mMap, mX, mY); + GameState::enqueueWarp(static_cast< Character * >(obj), mMap, mTargetPoint); } } diff --git a/src/game-server/triggerareacomponent.h b/src/game-server/triggerareacomponent.h index f766c815..6c2df7d1 100644 --- a/src/game-server/triggerareacomponent.h +++ b/src/game-server/triggerareacomponent.h @@ -40,14 +40,14 @@ class TriggerAction class WarpAction : public TriggerAction { public: - WarpAction(MapComposite *m, int x, int y) - : mMap(m), mX(x), mY(y) {} + WarpAction(MapComposite *m, const Point &point) + : mMap(m), mTargetPoint(point) {} virtual void process(Actor *obj); private: MapComposite *mMap; - unsigned short mX, mY; + Point mTargetPoint; }; class ScriptAction : public TriggerAction diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index cbdb088c..a02f84e4 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -1650,7 +1650,7 @@ static int chr_warp(lua_State *s) x *= map->getTileWidth(); y *= map->getTileHeight(); } - GameState::enqueueWarp(q, m, x, y); + GameState::enqueueWarp(q, m, Point(x, y)); return 0; } -- cgit v1.2.3-70-g09d2