summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--src/gui/guildwindow.cpp4
-rw-r--r--src/localplayer.cpp62
-rw-r--r--src/localplayer.h31
-rw-r--r--src/net/guildhandler.cpp28
-rw-r--r--src/player.cpp45
-rw-r--r--src/player.h30
7 files changed, 100 insertions, 103 deletions
diff --git a/ChangeLog b/ChangeLog
index 0329d509..9479626b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,9 @@
* src/game.cpp, src/gui/guildwindow.cpp: Fixed key presses during
text dialog in guild window and changed license to standard GPL.
+ * src/localplayer.cpp, src/localplayer.h, src/player.cpp,
+ src/player.h, src/gui/guildwindow.cpp, src/net/guildhandler.cpp:
+ Fixed guild creation.
2008-03-04 Bjørn Lindeijer <bjorn@lindeijer.nl>
diff --git a/src/gui/guildwindow.cpp b/src/gui/guildwindow.cpp
index c7a828b9..30305ca4 100644
--- a/src/gui/guildwindow.cpp
+++ b/src/gui/guildwindow.cpp
@@ -153,7 +153,7 @@ void GuildWindow::newGuildTab(const std::string &guildName)
tab->setHeight(getHeight() - 2 * tab->getBorderSize());
tab->setOpaque(false);
ListBox *list = new ListBox();
- list->setListModel(player_node->findGuildByName(guildName));
+ list->setListModel(player_node->getGuild(guildName));
ScrollArea *sa = new ScrollArea(list);
sa->setDimension(gcn::Rectangle(5, 5, 135, 250));
tab->add(sa);
@@ -192,7 +192,7 @@ bool GuildWindow::isFocused()
short GuildWindow::getSelectedGuild()
{
- return mPlayer->findGuildByName(mGuildsContainer->getActiveWidget())->getId();
+ return mPlayer->getGuild(mGuildsContainer->getActiveWidget())->getId();
}
void GuildWindow::openAcceptDialog(const std::string &inviterName, const std::string &guildName)
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index f581db27..1614b7e7 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -26,6 +26,7 @@
#include "equipment.h"
#include "floor_item.h"
#include "game.h"
+#include "guild.h"
#include "inventory.h"
#include "item.h"
#include "main.h"
@@ -116,65 +117,14 @@ void LocalPlayer::nextStep()
Player::nextStep();
}
-void LocalPlayer::addGuild(short guildId, bool inviteRights)
-{
- Guild *guild = new Guild(guildId, inviteRights);
- mGuilds.push_back(guild);
-}
-
-void LocalPlayer::removeGuild(short guildId)
-{
- std::vector<Guild*>::iterator itr;
- for (itr = mGuilds.begin(); itr != mGuilds.end(); ++itr)
- {
- Guild *guild = (*itr);
- if (guild->getId() == guildId)
- {
- delete guild;
- mGuilds.erase(itr);
- return;
- }
- }
-}
-
-Guild* LocalPlayer::findGuildById(short guildId)
-{
- for (unsigned int i = 0; i < mGuilds.size(); ++i)
- {
- if (mGuilds[i]->getId() == guildId)
- {
- return mGuilds[i];
- }
- }
-
- // not found return NULL
- return NULL;
-}
-
-Guild* LocalPlayer::findGuildByName(const std::string &guildName)
+bool LocalPlayer::checkInviteRights(const std::string &guildName)
{
- for (unsigned int i = 0; i < mGuilds.size(); ++i)
+ Guild *guild = getGuild(guildName);
+ if (guild)
{
- if(mGuilds[i]->getName() == guildName)
- {
- return mGuilds[i];
- }
+ return guild->getInviteRights();
}
-
- // Not found, so return NULL
- return NULL;
-}
-short LocalPlayer::getNumberOfGuilds()
-{
- return mGuilds.size();
-}
-
-bool LocalPlayer::checkInviteRights(const std::string &guildName)
-{
- Guild *guild = findGuildByName(guildName);
- if(guild)
- return guild->getInviteRights();
return false;
}
@@ -446,7 +396,7 @@ void LocalPlayer::lowerAttribute(size_t attr)
const std::string& LocalPlayer::getSkillName(int skill)
{
static const std::string skills[CHAR_SKILL_NB + 1] =
- {
+ {
_("Unarmed"), // CHAR_SKILL_WEAPON_NONE
_("Knife"), // CHAR_SKILL_WEAPON_KNIFE
_("Sword"), // CHAR_SKILL_WEAPON_SWORD
diff --git a/src/localplayer.h b/src/localplayer.h
index 9b4c7eb3..9bad9436 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -24,7 +24,6 @@
#ifndef _TMW_LOCALPLAYER_H
#define _TMW_LOCALPLAYER_H
-#include "guild.h"
#include "player.h"
// TODO move into some sane place...
@@ -153,33 +152,6 @@ class LocalPlayer : public Player
drawName(Graphics *, int, int) {};
/**
- * Adds a guild to the local player.
- */
- void addGuild(short guildId, bool inviteRights);
-
- /**
- * Removers a guild from the local player.
- */
- void removeGuild(short guildId);
-
- /**
- * Finds a guild the local player belongs to, by the guildId
- * @return returns the guild associated with the guildId
- */
- Guild* findGuildById(short guildId);
-
- /**
- * Finds a guild the local player belongs to, by the guild's name.
- * @return returns the guild with that name
- */
- Guild* findGuildByName(const std::string &guildName);
-
- /**
- * Get number of guilds the player belongs to
- */
- short getNumberOfGuilds();
-
- /**
* Check the player has permission to invite users
*/
bool checkInviteRights(const std::string &guildName);
@@ -369,9 +341,6 @@ class LocalPlayer : public Player
protected:
void walk(unsigned char dir);
- // Character guild information
- std::vector<Guild*> mGuilds;
-
// Character status:
std::vector<int> mAttributeBase;
std::vector<int> mAttributeEffective;
diff --git a/src/net/guildhandler.cpp b/src/net/guildhandler.cpp
index 48d2e837..5bacaaa1 100644
--- a/src/net/guildhandler.cpp
+++ b/src/net/guildhandler.cpp
@@ -3,7 +3,7 @@
* A file part of The Mana World
*
* Created by David Athay on 01/03/2007.
- *
+ *
* Copyright (c) 2007, The Mana World Development Team
* All rights reserved.
*
@@ -27,7 +27,7 @@
*
* $Id$
*/
-
+#include <iostream>
#include "guildhandler.h"
#include "protocol.h"
@@ -55,7 +55,7 @@ GuildHandler::GuildHandler()
0
};
handledMessages = _messages;
-
+
}
void GuildHandler::handleMessage(MessageIn &msg)
@@ -73,7 +73,7 @@ void GuildHandler::handleMessage(MessageIn &msg)
joinedGuild(guildId, guildName, true);
}
} break;
-
+
case CPMSG_GUILD_INVITE_RESPONSE:
{
logger->log("Received CPMSG_GUILD_INVITE_RESPONSE");
@@ -82,7 +82,7 @@ void GuildHandler::handleMessage(MessageIn &msg)
// TODO - Acknowledge invite was sent
}
} break;
-
+
case CPMSG_GUILD_ACCEPT_RESPONSE:
{
logger->log("Received CPMSG_GUILD_ACCEPT_RESPONSE");
@@ -94,7 +94,7 @@ void GuildHandler::handleMessage(MessageIn &msg)
joinedGuild(guildId, guildName, false);
}
} break;
-
+
case CPMSG_GUILD_GET_MEMBERS_RESPONSE:
{
logger->log("Received CPMSG_GUILD_GET_MEMBERS_RESPONSE");
@@ -103,7 +103,9 @@ void GuildHandler::handleMessage(MessageIn &msg)
std::string guildMember;
Guild *guild;
short guildId = msg.readInt16();
- guild = player_node->findGuildById(guildId);
+ guild = player_node->getGuild(guildId);
+ if (!guild)
+ return;
while(msg.getUnreadLength())
{
guildMember = msg.readString();
@@ -115,24 +117,24 @@ void GuildHandler::handleMessage(MessageIn &msg)
guildWindow->updateTab();
}
} break;
-
+
case CPMSG_GUILD_INVITED:
{
logger->log("Received CPMSG_GUILD_INVITED");
std::string inviterName = msg.readString();
std::string guildName = msg.readString();
-
+
// Open a dialog asking if the player accepts joining the guild.
guildWindow->openAcceptDialog(inviterName, guildName);
} break;
-
+
case CPMSG_GUILD_REJOIN:
{
logger->log("Received CPMSG_GUILD_REJOIN");
std::string guildName = msg.readString();
short guildId = msg.readInt16();
bool leader = msg.readInt8();
-
+
joinedGuild(guildId, guildName, leader);
} break;
}
@@ -141,10 +143,8 @@ void GuildHandler::handleMessage(MessageIn &msg)
void GuildHandler::joinedGuild(short guildId, const std::string &guildName, bool leader)
{
// Add guild to player and create new guild tab
- player_node->addGuild(guildId, leader);
- Guild *guild = player_node->findGuildById(guildId);
+ Guild *guild = player_node->addGuild(guildId, leader);
guild->setName(guildName);
guildWindow->newGuildTab(guildName);
-
guildWindow->requestMemberList(guildId);
}
diff --git a/src/player.cpp b/src/player.cpp
index b8789256..2f1fc648 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -26,6 +26,7 @@
#include "animatedsprite.h"
#include "game.h"
#include "graphics.h"
+#include "guild.h"
#include "log.h"
#include "resources/itemdb.h"
@@ -146,3 +147,47 @@ void Player::setSprite(int slot, int id, const std::string &color)
Being::setSprite(slot, id, color);
}
+
+Guild* Player::addGuild(short guildId, bool inviteRights)
+{
+ Guild *guild = new Guild(guildId, inviteRights);
+ mGuilds.insert(std::pair<int, Guild*>(guildId, guild));
+ return guild;
+}
+
+void Player::removeGuild(int id)
+{
+ mGuilds.erase(id);
+}
+
+Guild* Player::getGuild(const std::string &guildName)
+{
+ std::map<int, Guild*>::iterator itr, itr_end = mGuilds.end();
+ for (itr = mGuilds.begin(); itr != itr_end; ++itr)
+ {
+ Guild *guild = itr->second;
+ if (guild->getName() == guildName)
+ {
+ return guild;
+ }
+ }
+
+ return NULL;
+}
+
+Guild* Player::getGuild(int id)
+{
+ std::map<int, Guild*>::iterator itr;
+ itr = mGuilds.find(id);
+ if (itr != mGuilds.end())
+ {
+ return itr->second;
+ }
+
+ return NULL;
+}
+
+short Player::getNumberOfGuilds()
+{
+ return mGuilds.size();
+}
diff --git a/src/player.h b/src/player.h
index f6ecbd59..aff75221 100644
--- a/src/player.h
+++ b/src/player.h
@@ -28,6 +28,7 @@
class Graphics;
class Map;
+class Guild;
enum Gender {
GENDER_MALE = 0,
@@ -87,6 +88,35 @@ class Player : public Being
virtual void
setSprite(int slot, int id, const std::string &color = "");
+ /**
+ * Adds a guild to the player.
+ */
+ Guild* addGuild(short guildId, bool inviteRights);
+
+ /**
+ * Removers a guild from the player.
+ */
+ void removeGuild(int id);
+
+ /**
+ * Returns a pointer to the specified guild
+ */
+ Guild* getGuild(const std::string &guildName);
+
+ /**
+ * Returns a pointer to the guild with matching id
+ */
+ Guild* getGuild(int id);
+
+ /**
+ * Get number of guilds the player belongs to
+ */
+ short getNumberOfGuilds();
+
+ protected:
+ // Character guild information
+ std::map<int, Guild*> mGuilds;
+
private:
Gender mGender;
Uint8 mHairStyle;