summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-10-09 03:34:45 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-10-09 03:34:45 +0000
commit8bde9095c5840b8d62ebafe11beaed98877d6ac2 (patch)
tree537f717a339d1247cae222eb7a354ea5dbe8babf /src
parenta246c08cef5e4d598fc07a681eb971bfbcf01519 (diff)
downloadmana-client-8bde9095c5840b8d62ebafe11beaed98877d6ac2.tar.gz
mana-client-8bde9095c5840b8d62ebafe11beaed98877d6ac2.tar.bz2
mana-client-8bde9095c5840b8d62ebafe11beaed98877d6ac2.tar.xz
mana-client-8bde9095c5840b8d62ebafe11beaed98877d6ac2.zip
* Made Sprite into an interface implemented by both FloorItem and Being, which
hook themselves into the map on construction. The improved fringe layer is working as expected now. * Made sure TMW compiles without warnings even when using "-Wconversion -Wshadow -Wcast-qual -Wwrite-strings -ansi -pedantic", lots of cleanups. * Added two new small tilesets that contain the desert tiles that are twice and three times the height of a normal tile. One well in new_3-1 has been converted to use the new double tiles for testing purposes.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/being.cpp345
-rw-r--r--src/being.h149
-rw-r--r--src/engine.cpp197
-rw-r--r--src/engine.h1
-rw-r--r--src/equipment.cpp27
-rw-r--r--src/equipment.h94
-rwxr-xr-xsrc/floor_item.cpp13
-rwxr-xr-xsrc/floor_item.h43
-rw-r--r--src/game.cpp90
-rw-r--r--src/game.h2
-rw-r--r--src/graphics.cpp28
-rw-r--r--src/gui/chargedialog.cpp5
-rw-r--r--src/gui/chargedialog.h8
-rw-r--r--src/gui/chat.cpp20
-rw-r--r--src/gui/chat.h3
-rw-r--r--src/gui/equipmentwindow.cpp5
-rw-r--r--src/gui/equipmentwindow.h8
-rw-r--r--src/gui/gui.cpp7
-rw-r--r--src/gui/help.cpp9
-rw-r--r--src/gui/inventorywindow.cpp2
-rw-r--r--src/gui/item_amount.cpp2
-rw-r--r--src/gui/itemcontainer.cpp10
-rw-r--r--src/gui/itemcontainer.h2
-rw-r--r--src/gui/linkhandler.h8
-rw-r--r--src/gui/login.cpp64
-rw-r--r--src/gui/menuwindow.cpp9
-rw-r--r--src/gui/newskill.cpp3
-rw-r--r--src/gui/npc_text.cpp15
-rw-r--r--src/gui/popupmenu.cpp78
-rw-r--r--src/gui/popupmenu.h7
-rw-r--r--src/gui/progressbar.cpp73
-rw-r--r--src/gui/progressbar.h38
-rw-r--r--src/gui/scrollarea.cpp21
-rw-r--r--src/gui/scrollarea.h10
-rw-r--r--src/gui/skill.cpp2
-rw-r--r--src/gui/status.cpp7
-rw-r--r--src/gui/trade.h3
-rw-r--r--src/gui/window.cpp40
-rw-r--r--src/gui/window.h11
-rw-r--r--src/guichanfwd.h2
-rw-r--r--src/inventory.h2
-rw-r--r--src/map.cpp18
-rw-r--r--src/map.h1
-rw-r--r--src/net/messagein.cpp5
-rw-r--r--src/net/packet.cpp8
-rw-r--r--src/net/packet.h4
-rw-r--r--src/openglgraphics.cpp10
-rw-r--r--src/resources/image.cpp75
-rw-r--r--src/resources/image.h15
-rw-r--r--src/resources/iteminfo.cpp115
-rw-r--r--src/resources/iteminfo.h96
-rw-r--r--src/resources/music.cpp41
-rw-r--r--src/resources/music.h16
-rw-r--r--src/resources/soundeffect.cpp22
-rw-r--r--src/resources/soundeffect.h12
-rw-r--r--src/sound.cpp2
-rw-r--r--src/sprite.h39
58 files changed, 985 insertions, 958 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 25f60cf7..bef31080 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -123,7 +123,6 @@ tmw_SOURCES = graphic/spriteset.cpp \
resources/image.h \
resources/imagewriter.cpp \
resources/imagewriter.h \
- resources/iteminfo.cpp \
resources/iteminfo.h \
resources/itemmanager.cpp \
resources/itemmanager.h \
diff --git a/src/being.cpp b/src/being.cpp
index 5cdd8c01..9f9c7834 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -45,12 +45,41 @@
extern Being* autoTarget;
extern std::map<int, Spriteset*> monsterset;
+// From main.cpp
+extern Spriteset *hairset;
+extern Spriteset *playerset;
+
+// From engine.cpp
+extern Spriteset *emotionset;
+extern Spriteset *npcset;
+extern Spriteset *weaponset;
+
Being *player_node = NULL;
std::list<Being*> beings;
-PATH_NODE::PATH_NODE(Uint16 x, Uint16 y):
- x(x), y(y)
+char hairtable[16][4][2] = {
+ // S(x,y) W(x,y) N(x,y) E(x,y)
+ { { 0, 0}, {-1, 2}, {-1, 2}, { 0, 2} }, // STAND
+ { { 0, 2}, {-2, 3}, {-1, 2}, { 1, 3} }, // WALK 1st frame
+ { { 0, 3}, {-2, 4}, {-1, 3}, { 1, 4} }, // WALK 2nd frame
+ { { 0, 1}, {-2, 2}, {-1, 2}, { 1, 2} }, // WALK 3rd frame
+ { { 0, 2}, {-2, 3}, {-1, 2}, { 1, 3} }, // WALK 4th frame
+ { { 0, 1}, { 1, 2}, {-1, 3}, {-2, 2} }, // ATTACK 1st frame
+ { { 0, 1}, {-1, 2}, {-1, 3}, { 0, 2} }, // ATTACK 2nd frame
+ { { 0, 2}, {-4, 3}, { 0, 4}, { 3, 3} }, // ATTACK 3rd frame
+ { { 0, 2}, {-4, 3}, { 0, 4}, { 3, 3} }, // ATTACK 4th frame
+ { { 0, 0}, {-1, 2}, {-1, 2}, {-1, 2} }, // BOW_ATTACK 1st frame
+ { { 0, 0}, {-1, 2}, {-1, 2}, {-1, 2} }, // BOW_ATTACK 2nd frame
+ { { 0, 0}, {-1, 2}, {-1, 2}, {-1, 2} }, // BOW_ATTACK 3rd frame
+ { { 0, 0}, {-1, 2}, {-1, 2}, {-1, 2} }, // BOW_ATTACK 4th frame
+ { { 0, 4}, {-1, 6}, {-1, 6}, { 0, 6} }, // SIT
+ { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, // ?? HIT
+ { { 0, 16}, {-1, 6}, {-1, 6}, { 0, 6} } // DEAD
+};
+
+PATH_NODE::PATH_NODE(Uint16 iX, Uint16 iY):
+ x(iX), y(iY)
{
}
@@ -161,16 +190,15 @@ void sort() {
Being::Being():
job(0),
x(0), y(0), direction(SOUTH),
- action(0), frame(0),
+ action(0), mFrame(0),
speech_color(0),
walk_time(0),
speed(150),
emotion(0), emotion_time(0),
- text_x(0), text_y(0),
aspd(350),
- m_weapon(0),
- m_id(0),
- map(0),
+ mWeapon(0),
+ mId(0),
+ mMap(NULL),
hairStyle(1), hairColor(1),
speech_time(0),
damage_time(0),
@@ -181,24 +209,25 @@ Being::Being():
Being::~Being()
{
clearPath();
+ setMap(NULL);
}
void Being::setDestination(Uint16 destX, Uint16 destY)
{
- if (!map)
- return;
-
- setPath(map->findPath(x, y, destX, destY));
+ if (mMap)
+ {
+ setPath(mMap->findPath(x, y, destX, destY));
+ }
}
void Being::clearPath()
{
- path.clear();
+ mPath.clear();
}
void Being::setPath(std::list<PATH_NODE> path)
{
- this->path = path;
+ mPath = path;
if (action != WALK && action != DEAD)
{
@@ -257,21 +286,33 @@ void Being::setDamage(Sint16 amount, Uint32 time)
void Being::setMap(Map *map)
{
- this->map = map;
+ // Remove sprite from potential previous map
+ if (mMap != NULL)
+ {
+ mMap->removeSprite(mSpriteIterator);
+ }
+
+ mMap = map;
+
+ // Add sprite to potential new map
+ if (mMap != NULL)
+ {
+ mSpriteIterator = mMap->addSprite(this);
+ }
}
void Being::nextStep()
{
- frame = 0;
+ mFrame = 0;
- if (path.empty())
+ if (mPath.empty())
{
action = STAND;
return;
}
- PATH_NODE node = path.front();
- path.pop_front();
+ PATH_NODE node = mPath.front();
+ mPath.pop_front();
if (node.x > x) {
if (node.y > y) direction = SE;
@@ -296,57 +337,74 @@ void Being::nextStep()
void Being::logic()
{
- if (get_elapsed_time(speech_time) > 5000) {
+ // Determine whether speech should still be displayed
+ if (get_elapsed_time(speech_time) > 5000)
+ {
showSpeech = false;
}
- if (get_elapsed_time(damage_time) > 3000) {
- showDamage = false;
- }
- if (getType() != PLAYER)
+ // Determine whether damange should still be displayed
+ if (get_elapsed_time(damage_time) > 3000)
{
- return;
+ showDamage = false;
}
- switch (action) {
- case WALK:
- frame = (get_elapsed_time(walk_time) * 4) / speed;
- if (frame >= 4) {
- nextStep();
- }
- break;
- case ATTACK:
- frame = (get_elapsed_time(walk_time) * 4) / aspd;
- if (frame >= 4) {
- nextStep();
- if (autoTarget && this == player_node) {
- attack(autoTarget);
+ // Execute next walk or attack command for players
+ if (getType() == PLAYER)
+ {
+ switch (action) {
+ case WALK:
+ mFrame = (get_elapsed_time(walk_time) * 4) / speed;
+ if (mFrame >= 4) {
+ nextStep();
+ }
+ break;
+ case ATTACK:
+ mFrame = (get_elapsed_time(walk_time) * 4) / aspd;
+ if (mFrame >= 4) {
+ nextStep();
+ if (autoTarget && this == player_node) {
+ attack(autoTarget);
+ }
}
+ break;
+ }
+
+ if (emotion != 0)
+ {
+ emotion_time--;
+ if (emotion_time == 0) {
+ emotion = 0;
}
- break;
+ }
}
- if (emotion != 0) {
- emotion_time--;
- if (emotion_time == 0) {
- emotion = 0;
- }
+ // Update pixel coordinates
+ mPx = x * 32;
+ mPy = y * 32;
+
+ if (getType() == PLAYER || getType() == MONSTER)
+ {
+ mPy += getYOffset();
+ mPx += getXOffset();
}
}
-void Being::drawSpeech(Graphics *graphics)
+void Being::drawSpeech(Graphics *graphics, Sint32 offsetX, Sint32 offsetY)
{
+ int px = mPx + offsetX;
+ int py = mPy + offsetY;
+
// Draw speech above this being
- if (showSpeech) {
+ if (showSpeech)
+ {
graphics->setFont(speechFont);
- graphics->drawText(speech,
- text_x + 18, text_y - 60,
- gcn::Graphics::CENTER);
-
- // Backing to default font
- graphics->setFont(gui->getFont());
+ graphics->drawText(speech, px + 18, py - 60, gcn::Graphics::CENTER);
}
- if (showDamage) {
+
+ // Draw damage above this being
+ if (showDamage)
+ {
// Selecting the right color
if (damage == "miss")
{
@@ -361,28 +419,23 @@ void Being::drawSpeech(Graphics *graphics)
graphics->setFont(hitRedFont);
}
- int textX = 0;
- int textY = 0;
- if (getType() == PLAYER) {
- textX = 16;
- textY = 70;
- }
- else {
- textX = 60;
- textY = 0;
- }
+ int textY = (getType() == PLAYER) ? 70 : 32;
graphics->drawText(damage,
- text_x + textX,
- text_y - textY - get_elapsed_time(damage_time) / 100,
- gcn::Graphics::CENTER);
+ px + 16,
+ py - textY - get_elapsed_time(damage_time) / 100,
+ gcn::Graphics::CENTER);
+ }
- // Backing to default font
- graphics->setFont(gui->getFont());
+ // Draw player name
+ if (getType() == PLAYER && this != player_node)
+ {
+ graphics->setFont(speechFont);
+ graphics->drawText(mName, px + 15, py + 30, gcn::Graphics::CENTER);
}
}
-Being::Type Being::getType()
+Being::Type Being::getType() const
{
if (job < 10) {
return PLAYER;
@@ -395,11 +448,6 @@ Being::Type Being::getType()
}
}
-void Being::setWeapon(Uint16 weapon)
-{
- m_weapon = weapon;
-}
-
void Being::setWeaponById(Uint16 weapon)
{
switch (weapon)
@@ -430,7 +478,154 @@ void Being::setWeaponById(Uint16 weapon)
}
}
-void Being::setId(Uint32 id)
+int
+Being::getXOffset() const
+{
+ int offset = 0;
+
+ if (action == WALK)
+ {
+ if (direction != NORTH && direction != SOUTH)
+ {
+ offset = (get_elapsed_time(walk_time) * 32) / speed;
+ if (offset > 32) offset = 32;
+
+ if (direction == WEST || direction == NW || direction == SW) {
+ offset = -offset;
+ offset += 32;
+ }
+ else {
+ offset -= 32;
+ }
+ }
+ }
+
+ return offset;
+}
+
+int
+Being::getYOffset() const
+{
+ int offset = 0;
+
+ if (action == WALK)
+ {
+ if (direction != EAST && direction != WEST)
+ {
+ offset = (get_elapsed_time(walk_time) * 32) / speed;
+ if (offset > 32) offset = 32;
+
+ if (direction == NORTH || direction == NW || direction == NE) {
+ offset = -offset;
+ offset += 32;
+ }
+ else {
+ offset -= 32;
+ }
+ }
+ }
+
+ return offset;
+}
+
+void
+Being::draw(Graphics *graphics, int offsetX, int offsetY)
{
- m_id = id;
+ unsigned char dir = direction / 2;
+ int px = mPx + offsetX;
+ int py = mPy + offsetY;
+ int frame;
+
+ switch (getType())
+ {
+ case PLAYER:
+ if (action == SIT || action == DEAD)
+ {
+ frame = 0;
+ }
+
+ frame = mFrame + action;
+
+ if (action == ATTACK && getWeapon() > 0)
+ {
+ frame += 4 * (getWeapon() - 1);
+ }
+
+ graphics->drawImage(playerset->spriteset[frame + 16 * dir],
+ px - 16, py - 32);
+
+ if (getWeapon() != 0 && action == ATTACK)
+ {
+ Image *image = weaponset->spriteset[
+ 16 * (getWeapon() - 1) + 4 * mFrame + dir];
+
+ graphics->drawImage(image, px - 64, py - 80);
+ }
+
+ if (getHairColor() <= NR_HAIR_COLORS)
+ {
+ int hf = getHairColor() - 1 + 10 * (dir + 4 *
+ (getHairStyle() - 1));
+
+ graphics->drawImage(hairset->spriteset[hf],
+ px - 2 + 2 * hairtable[frame][dir][0],
+ py - 50 + 2 * hairtable[frame][dir][1]);
+ }
+
+ if (emotion != 0)
+ {
+ graphics->drawImage(emotionset->spriteset[emotion - 1],
+ px + 3, py - 90);
+ }
+ break;
+
+ case NPC:
+ graphics->drawImage(npcset->spriteset[job - 100], px - 8, py - 52);
+ break;
+
+ case MONSTER:
+ if (mFrame >= 4)
+ {
+ mFrame = 3;
+ }
+
+ px -= 42;
+ py -= 65;
+
+ frame = mFrame + action;
+
+ if (action == MONSTER_DEAD)
+ {
+ graphics->drawImage(
+ monsterset[job - 1002]->spriteset[dir + 4 * MONSTER_DEAD],
+ px + 30, py + 40);
+ }
+ else
+ {
+ graphics->drawImage(
+ monsterset[job-1002]->spriteset[dir + 4 * frame],
+ px + 30, py + 40);
+
+ /*
+ if (x == mouseTileX && y == mouseTileY)
+ {
+ graphics->drawImage(attackTarget, px + 30 + 16, py + 32);
+ }
+ */
+ }
+
+ if (action != STAND)
+ {
+ mFrame = (get_elapsed_time(walk_time) * 4) / speed;
+
+ if (mFrame >= 4 && action != MONSTER_DEAD)
+ {
+ nextStep();
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
}
diff --git a/src/being.h b/src/being.h
index 07b12232..d5ec7fab 100644
--- a/src/being.h
+++ b/src/being.h
@@ -28,22 +28,27 @@
#include <string>
#include <SDL_types.h>
+#include "sprite.h"
+#include "map.h"
+
#define NR_HAIR_STYLES 5
#define NR_HAIR_COLORS 10
class Map;
class Graphics;
-struct PATH_NODE {
+struct PATH_NODE
+{
/**
* Constructor.
*/
PATH_NODE(unsigned short x, unsigned short y);
- unsigned short x, y;
+ unsigned short x;
+ unsigned short y;
};
-class Being
+class Being : public Sprite
{
public:
enum Type {
@@ -61,7 +66,7 @@ class Being
MONSTER_DEAD = 9,
SIT = 13,
HIT = 14,
- DEAD = 15,
+ DEAD = 15
};
enum Direction {
@@ -73,20 +78,19 @@ class Being
NORTH = 4,
NE = 5,
EAST = 6,
- SE = 7,
+ SE = 7
};
Uint16 job; /**< Job (player job, npc, monster, ) */
Uint16 x, y; /**< Tile coordinates */
Uint8 direction; /**< Facing direction */
Uint8 action;
- Uint8 frame;
+ Uint8 mFrame;
Sint32 speech_color;
Uint16 walk_time;
Uint16 speed;
Uint8 emotion; /**< Currently showing emotion */
Uint8 emotion_time; /**< Time until emotion disappears */
- Uint32 text_x, text_y; // temp solution to fix speech position
Uint16 aspd; /**< Attack speed */
@@ -175,88 +179,147 @@ class Being
/**
* Draws the speech text above the being.
*/
- void drawSpeech(Graphics *graphics);
+ void drawSpeech(Graphics *graphics, Sint32 offsetX, Sint32 offsetY);
/**
* Returns the type of the being.
*/
- Type getType();
+ Type getType() const;
// ACCES METHODS
/**
- * get the weapon picture id.
+ * Gets the weapon picture id.
*/
- Uint16 getWeapon() { return m_weapon; }
+ Uint16 getWeapon() const { return mWeapon; }
/**
- * get the sprite id.
+ * Gets the sprite id.
*/
- Uint32 getId() { return m_id; }
+ Uint32 getId() const { return mId; }
// MODIFICATION METHODS
/**
- * set the weapon picture id.
+ * Sets the weapon picture id.
*
- * @param weapon : the picture id
+ * @param weapon the picture id
*/
- void setWeapon(Uint16 weapon);
+ void
+ setWeapon(Uint16 weapon) { mWeapon = weapon; }
/**
- * set the weapon picture id with the weapon id.
+ * Sets the weapon picture id with the weapon id.
*
- * @param weapon : the weapon id
+ * @param weapon the weapon id
*/
void setWeaponById(Uint16 weapon);
/**
- * set the sprite id.
+ * Sets the sprite id.
*/
- void setId(Uint32 id);
+ void
+ setId(Uint32 id) { mId = id; }
/**
- * Set the map the being is on
+ * Sets the map the being is on
*/
void setMap(Map *map);
+ // SPRITE METHODS
+
+ /**
+ * Draws this being to the given graphics context.
+ *
+ * @see Sprite::draw(Graphics, int, int)
+ */
+ void
+ draw(Graphics *graphics, Sint32 offsetX, Sint32 offsetY);
+
+ /**
+ * Returns the pixel X coordinate.
+ */
+ int
+ getPixelX() const { return mPx; }
+
+ /**
+ * Returns the pixel Y coordinate.
+ *
+ * @see Sprite::getPixelY()
+ */
+ int
+ getPixelY() const { return mPy; }
+
+ /**
+ * Get the current X pixel offset.
+ */
+ int
+ getXOffset() const;
+
+ /**
+ * Get the current Y pixel offset.
+ */
+ int
+ getYOffset() const;
+
private:
- Uint16 m_weapon;
- Uint32 m_id; /**< Unique id */
- Map *map;
+ /**
+ * Sets the new path for this being.
+ */
+ void
+ setPath(std::list<PATH_NODE> path);
- std::list<PATH_NODE> path;
+ Uint16 mWeapon; /**< Weapon picture id */
+ Uint32 mId; /**< Unique id */
+ Map *mMap; /**< Map on which this being resides */
+ std::string mName; /**< Name of character */
+ Sprites::iterator mSpriteIterator;
+
+ std::list<PATH_NODE> mPath;
std::string speech;
std::string damage;
Uint16 hairStyle, hairColor;
Uint32 speech_time;
Uint32 damage_time;
bool showSpeech, showDamage;
- std::string mName; /**< Name of character */
-
- /**
- * Sets the new path for this being.
- */
- void setPath(std::list<PATH_NODE> path);
+ Sint32 mPx, mPy; /**< Pixel coordinates */
};
-/** Return a specific id Being */
-Being *findNode(Uint32 id);
+/**
+ * Return a specific id Being
+ */
+Being*
+findNode(Uint32 id);
-/** Return a being at specific coordinates */
-Being *findNode(Uint16 x, Uint16 y);
+/**
+ * Return a being at specific coordinates
+ */
+Being*
+findNode(Uint16 x, Uint16 y);
-/** Return a being at specific coordinates with specific type*/
-Being *findNode(Uint16 x, Uint16 y, Being::Type type);
+/**
+ * Return a being at specific coordinates with specific type
+ */
+Being*
+findNode(Uint16 x, Uint16 y, Being::Type type);
-/** Create a being and add it to the list of beings */
-Being *createBeing(Uint32 id, Uint16 job, Map *map);
+/**
+ * Create a being and add it to the list of beings
+ */
+Being*
+createBeing(Uint32 id, Uint16 job, Map *map);
-/** Remove a Being */
-void remove_node(Being *being);
+/**
+ * Remove a Being
+ */
+void
+remove_node(Being *being);
-/** Sort beings in vertical order */
-void sort();
+/**
+ * Sort beings in vertical order
+ */
+void
+sort();
extern Being *player_node;
diff --git a/src/engine.cpp b/src/engine.cpp
index 4d934504..b7155ebb 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -54,8 +54,8 @@
extern Being *autoTarget;
extern Graphics *graphics;
extern Minimap *minimap;
-extern Spriteset *hairset, *playerset;
extern std::list<FloorItem*> floorItems;
+extern int frame;
char itemCurrenyQ[10] = "0";
int camera_x, camera_y;
@@ -65,27 +65,11 @@ gcn::Label *debugInfo;
std::map<int, Spriteset*> monsterset;
ItemManager *itemDb; /**< Item database object */
-Spriteset *itemset;
-char hairtable[16][4][2] = {
- // S(x,y) W(x,y) N(x,y) E(x,y)
- { { 0, 0}, {-1, 2}, {-1, 2}, { 0, 2} }, // STAND
- { { 0, 2}, {-2, 3}, {-1, 2}, { 1, 3} }, // WALK 1st frame
- { { 0, 3}, {-2, 4}, {-1, 3}, { 1, 4} }, // WALK 2nd frame
- { { 0, 1}, {-2, 2}, {-1, 2}, { 1, 2} }, // WALK 3rd frame
- { { 0, 2}, {-2, 3}, {-1, 2}, { 1, 3} }, // WALK 4th frame
- { { 0, 1}, { 1, 2}, {-1, 3}, {-2, 2} }, // ATTACK 1st frame
- { { 0, 1}, {-1, 2}, {-1, 3}, { 0, 2} }, // ATTACK 2nd frame
- { { 0, 2}, {-4, 3}, { 0, 4}, { 3, 3} }, // ATTACK 3rd frame
- { { 0, 2}, {-4, 3}, { 0, 4}, { 3, 3} }, // ATTACK 4th frame
- { { 0, 0}, {-1, 2}, {-1, 2}, {-1, 2} }, // BOW_ATTACK 1st frame
- { { 0, 0}, {-1, 2}, {-1, 2}, {-1, 2} }, // BOW_ATTACK 2nd frame
- { { 0, 0}, {-1, 2}, {-1, 2}, {-1, 2} }, // BOW_ATTACK 3rd frame
- { { 0, 0}, {-1, 2}, {-1, 2}, {-1, 2} }, // BOW_ATTACK 4th frame
- { { 0, 4}, {-1, 6}, {-1, 6}, { 0, 6} }, // SIT
- { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, // ?? HIT
- { { 0, 16}, {-1, 6}, {-1, 6}, { 0, 6} } // DEAD
-};
+Spriteset *itemset;
+Spriteset *emotionset;
+Spriteset *npcset;
+Spriteset *weaponset;
int get_x_offset(Being *being)
@@ -240,7 +224,7 @@ void Engine::logic()
being->logic();
- if (being->action == Being::MONSTER_DEAD && being->frame >= 20)
+ if (being->action == Being::MONSTER_DEAD && being->mFrame >= 20)
{
delete being;
beingIterator = beings.erase(beingIterator);
@@ -260,17 +244,16 @@ void Engine::draw()
int midTileX = graphics->getWidth() / 32 / 2;
int midTileY = graphics->getHeight() / 32 / 2;
- int map_x = (player_node->x - midTileX) * 32 + get_x_offset(player_node);
- int map_y = (player_node->y - midTileY) * 32 + get_y_offset(player_node);
-
- if (map_x < 0) {
- map_x = 0;
- }
- if (map_y < 0) {
- map_y = 0;
- }
+ int map_x = (player_node->x - midTileX) * 32 + player_node->getXOffset();
+ int map_y = (player_node->y - midTileY) * 32 + player_node->getYOffset();
if (mCurrentMap) {
+ if (map_x < 0) {
+ map_x = 0;
+ }
+ if (map_y < 0) {
+ map_y = 0;
+ }
if (map_x > (mCurrentMap->getWidth() - midTileX) * 32) {
map_x = (mCurrentMap->getWidth() - midTileX) * 32;
}
@@ -288,145 +271,11 @@ void Engine::draw()
frame++;
- // Draw tiles below nodes
+ // Draw tiles and sprites
if (mCurrentMap != NULL)
{
mCurrentMap->draw(graphics, map_x, map_y, 0);
mCurrentMap->draw(graphics, map_x, map_y, 1);
- }
-
- // Draw nodes
- for (std::list<Being*>::iterator i = beings.begin(); i != beings.end(); i++)
- {
- Being *being = (*i);
-
- unsigned char dir = being->direction / 2;
- int x = being->x * 32 - map_x;
- int y = being->y * 32 - map_y;
-
- int frame;
- switch (being->getType())
- {
- // Draw a player
- case Being::PLAYER:
- being->text_x = x + get_x_offset(being);
- being->text_y = y + get_y_offset(being);
-
- if (being->action == Being::SIT || being->action == Being::DEAD)
- {
- being->frame = 0;
- }
-
- frame = being->frame + being->action;
-
- if (being->action == Being::ATTACK)
- {
- if (being->getWeapon() > 0)
- frame += 4 * (being->getWeapon() - 1);
- }
-
- graphics->drawImage(playerset->spriteset[frame + 16 * dir],
- being->text_x - 16, being->text_y - 32);
-
- if (being->getWeapon() != 0 && being->action == Being::ATTACK)
- {
- Image *image = weaponset->spriteset[
- 16 * (being->getWeapon() - 1) + 4 * being->frame + dir];
-
- graphics->drawImage(image,
- being->text_x - 64, being->text_y - 80);
- }
-
- if (being->getHairColor() <= NR_HAIR_COLORS)
- {
- int hf = being->getHairColor() - 1 + 10 * (dir + 4 *
- (being->getHairStyle() - 1));
-
- graphics->drawImage(hairset->spriteset[hf],
- being->text_x - 2 + 2 * hairtable[frame][dir][0],
- being->text_y - 50 + 2 * hairtable[frame][dir][1]);
- }
-
- if (being->emotion != 0)
- {
- graphics->drawImage(
- emotionset->spriteset[being->emotion - 1],
- being->text_x + 3, being->text_y - 90);
- }
-
- if (being != player_node)
- {
- graphics->setFont(speechFont);
- graphics->drawText(being->getName(),
- being->text_x + 15, being->text_y + 30,
- gcn::Graphics::CENTER);
- graphics->setFont(gui->getFont());
- }
- break;
-
- // Draw a NPC
- case Being::NPC:
- graphics->drawImage(npcset->spriteset[being->job - 100],
- x - 8, y - 52);
- break;
-
- // Draw a monster
- case Being::MONSTER:
- if (being->frame >= 4)
- {
- being->frame = 3;
- }
-
- being->text_x = x - 42 + get_x_offset(being);
- being->text_y = y - 65 + get_y_offset(being);
-
- frame = being->frame + being->action;
-
- if (being->action == Being::MONSTER_DEAD) {
- graphics->drawImage(
- monsterset[being->job - 1002]->spriteset[dir + 4 * Being::MONSTER_DEAD],
- being->text_x + 30, being->text_y + 40);
- }
- else {
- graphics->drawImage(
- monsterset[being->job-1002]->spriteset[dir + 4 * frame],
- being->text_x + 30, being->text_y + 40);
-
- if (being->x == mouseTileX && being->y == mouseTileY)
- {
- graphics->drawImage(attackTarget,
- being->text_x + 30 + 16, being->text_y + 32);
- }
- }
-
- if (being->action != Being::STAND) {
- being->frame =
- (get_elapsed_time(being->walk_time) * 4) / (being->speed);
-
- if (being->frame >= 4 && being->action != Being::MONSTER_DEAD) {
- being->nextStep();
- }
- }
- break;
-
- /*
- // Draw a warp (job == 45)
- case Being::WARP:
- break;
- */
-
- // No idea how to draw this ;)
- default:
- break;
- }
-
- // nodes are ordered so if the next being y is > then the
- // last drawed for fringe layer, draw the missing lines
- }
-
- // Draw tiles below nodes
- if (mCurrentMap != NULL)
- {
mCurrentMap->draw(graphics, map_x, map_y, 2);
}
@@ -460,9 +309,7 @@ void Engine::draw()
// Draw player speech
for (std::list<Being*>::iterator i = beings.begin(); i != beings.end(); i++)
{
- Being *being = (*i);
-
- being->drawSpeech(graphics);
+ (*i)->drawSpeech(graphics, -map_x, -map_y);
}
if (autoTarget)
@@ -470,16 +317,16 @@ void Engine::draw()
if (autoTarget->getType() == Being::PLAYER)
{
graphics->drawText("[TARGET]",
- autoTarget->text_x + 15,
- autoTarget->text_y - 60,
- gcn::Graphics::CENTER);
+ autoTarget->getPixelX() + 15,
+ autoTarget->getPixelY() - 60,
+ gcn::Graphics::CENTER);
}
else
{
graphics->drawText("[TARGET]",
- autoTarget->text_x + 60,
- autoTarget->text_y,
- gcn::Graphics::CENTER);
+ autoTarget->getPixelX() + 60,
+ autoTarget->getPixelY(),
+ gcn::Graphics::CENTER);
}
}
diff --git a/src/engine.h b/src/engine.h
index 49a307f5..74f2ce9d 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -69,7 +69,6 @@ class Engine
void draw();
private:
- Spriteset *emotionset, *npcset, *weaponset;
Map *mCurrentMap;
Image *attackTarget;
};
diff --git a/src/equipment.cpp b/src/equipment.cpp
index 24c20ea4..85b5eda3 100644
--- a/src/equipment.cpp
+++ b/src/equipment.cpp
@@ -24,17 +24,38 @@
#include "equipment.h"
#include "item.h"
-Equipment *Equipment::instance = 0;
+Equipment *Equipment::mInstance = NULL;
Equipment::Equipment():
- arrows(0)
+ mArrows(NULL)
{
for (int i = 0; i < EQUIPMENT_SIZE; i++)
{
- equipment[i] = 0;
+ mEquipment[i] = NULL;
}
}
Equipment::~Equipment()
{
}
+
+Equipment*
+Equipment::getInstance()
+{
+ if (!mInstance) {
+ mInstance = new Equipment();
+ }
+
+ return mInstance;
+}
+
+void
+Equipment::removeEquipment(Item *item)
+{
+ for (int i = 0; i < EQUIPMENT_SIZE; i++) {
+ if (mEquipment[i] == item) {
+ mEquipment[i] = 0;
+ break;
+ }
+ }
+}
diff --git a/src/equipment.h b/src/equipment.h
index 4e6cd705..2bb53e42 100644
--- a/src/equipment.h
+++ b/src/equipment.h
@@ -21,8 +21,10 @@
* $Id$
*/
-#ifndef _EQUIPMENT_H
-#define _EQUIPMENT_H
+#ifndef _TMW_EQUIPMENT_H_
+#define _TMW_EQUIPMENT_H_
+
+#include <stdlib.h>
class Item;
@@ -31,16 +33,45 @@ class Item;
class Equipment
{
public:
+ /**
+ * Retrieve an instance of the equipment class.
+ */
static Equipment* getInstance();
- Item* getEquipment(int index);
- void setEquipment(int index, Item *item);
+ /**
+ * Get equipment at the given slot.
+ */
+ Item*
+ getEquipment(int index) { return mEquipment[index]; }
+
+ /**
+ * Set equipment at the given slot.
+ */
+ void
+ setEquipment(int index, Item *item) { mEquipment[index] = item; }
+
+ /**
+ * Remove equipment from the given slot.
+ */
+ void
+ removeEquipment(int index) { mEquipment[index] = NULL; }
- void removeEquipment(int index);
+ /**
+ * Remove the given item from equipment.
+ */
void removeEquipment(Item *item);
- Item* getArrows();
- void setArrows(Item *arrows);
+ /**
+ * Get the item used in the arrow slot.
+ */
+ Item*
+ getArrows() { return mArrows; }
+
+ /**
+ * Set the item used in the arrow slot.
+ */
+ void
+ setArrows(Item *arrows) { mArrows = arrows; }
protected:
/**
@@ -53,54 +84,11 @@ class Equipment
*/
~Equipment();
- Item *equipment[EQUIPMENT_SIZE];
- Item *arrows;
+ Item *mEquipment[EQUIPMENT_SIZE];
+ Item *mArrows;
private:
- static Equipment *instance;
+ static Equipment *mInstance;
};
-inline Equipment *Equipment::getInstance()
-{
- if (!instance)
- instance = new Equipment();
-
- return instance;
-}
-
-inline Item* Equipment::getEquipment(int index)
-{
- return equipment[index];
-}
-
-inline void Equipment::setEquipment(int index, Item *item)
-{
- equipment[index] = item;
-}
-
-inline void Equipment::removeEquipment(int index)
-{
- equipment[index] = 0;
-}
-
-inline void Equipment::removeEquipment(Item *item)
-{
- for (int i = 0; i < EQUIPMENT_SIZE; i++) {
- if (equipment[i] == item) {
- equipment[i] = 0;
- break;
- }
- }
-}
-
-inline Item* Equipment::getArrows()
-{
- return arrows;
-}
-
-inline void Equipment::setArrows(Item *arrows)
-{
- this->arrows = arrows;
-}
-
#endif
diff --git a/src/floor_item.cpp b/src/floor_item.cpp
index a1b83a75..32b8aee5 100755
--- a/src/floor_item.cpp
+++ b/src/floor_item.cpp
@@ -46,23 +46,16 @@ FloorItem::FloorItem(unsigned int id,
mMap(map)
{
// Retrieve item image using a global itemset and itemDb (alternative?)
- Image *image = itemset->spriteset[
- itemDb->getItemInfo(itemId)->getImage() - 1];
+ mImage = itemset->spriteset[itemDb->getItemInfo(itemId)->getImage() - 1];
- // Create the sprite representing this floor item
- mSprite = new Sprite(mX * map->getTileWidth(),
- mY * map->getTileHeight(),
- image);
-
- // Add the representative sprite to the map
- mSpriteIterator = mMap->addSprite(mSprite);
+ // Add ourselves to the map
+ mSpriteIterator = mMap->addSprite(this);
}
FloorItem::~FloorItem()
{
// Remove and delete the representative sprite
mMap->removeSprite(mSpriteIterator);
- delete mSprite;
}
void empty_floor_items()
diff --git a/src/floor_item.h b/src/floor_item.h
index 5563da24..e004c0a2 100755
--- a/src/floor_item.h
+++ b/src/floor_item.h
@@ -24,14 +24,16 @@
#ifndef _TMW_FLOORITEM_H_
#define _TMW_FLOORITEM_H_
-class Map;
-
+#include "graphics.h"
#include "map.h"
+#include "sprite.h"
+
+class Map;
/**
* An item lying on the floor.
*/
-class FloorItem
+class FloorItem : public Sprite
{
public:
/**
@@ -51,28 +53,53 @@ class FloorItem
/**
* Returns instance id of this item.
*/
- unsigned int getId() { return mId; }
+ unsigned int
+ getId() { return mId; }
/**
* Returns the item id.
*/
- unsigned int getItemId() { return mItemId; }
+ unsigned int
+ getItemId() { return mItemId; }
/**
* Returns the x coordinate.
*/
- unsigned short getX() { return mX; }
+ unsigned short
+ getX() { return mX; }
/**
* Returns the y coordinate.
*/
- unsigned short getY() { return mY; }
+ unsigned short
+ getY() { return mY; }
+
+ /**
+ * Returns the pixel y coordinate.
+ *
+ * @see Sprite::getPixelY()
+ */
+ int
+ getPixelY() const { return mY * 32; }
+
+ /**
+ * Draws this floor item to the given graphics context.
+ *
+ * @see Sprite::draw(Graphics, int, int)
+ */
+ void
+ draw(Graphics *graphics, int offsetX, int offsetY)
+ {
+ graphics->drawImage(mImage,
+ mX * 32 + offsetX,
+ mY * 32 + offsetY);
+ }
private:
unsigned int mId;
unsigned int mItemId;
unsigned short mX, mY;
- Sprite *mSprite;
+ Image *mImage;
Sprites::iterator mSpriteIterator;
Map *mMap;
};
diff --git a/src/game.cpp b/src/game.cpp
index 51848441..d85149fe 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -89,7 +89,6 @@ int fps = 0, frame = 0, current_npc = 0;
bool displayPathToMouse = false;
Uint16 startX = 0, startY = 0;
Being *autoTarget = NULL;
-Map *tiledMap = NULL;
Engine *engine = NULL;
SDL_Joystick *joypad = NULL; /**< Joypad object */
@@ -404,12 +403,11 @@ void game()
void do_exit()
{
delete engine;
- delete tiledMap;
+ delete player_node;
destroyGuiWindows();
close_session();
delete inventory;
- delete player_node;
if (joypad != NULL)
{
@@ -538,43 +536,42 @@ void do_input()
// Picking up items on the floor
case SDLK_g:
case SDLK_z:
- if (chatWindow->isFocused())
+ if (!chatWindow->isFocused())
{
- break;
- }
+ Uint32 id = find_floor_item_by_cor(
+ player_node->x, player_node->y);
- Uint32 id = find_floor_item_by_cor(
- player_node->x, player_node->y);
+ // If none below the player, try the tile in front of
+ // the player
+ if (!id) {
+ Uint16 x = player_node->x;
+ Uint16 y = player_node->y;
- // If none below the player, try the tile in front of
- // the player
- if (!id) {
- Uint16 x = player_node->x;
- Uint16 y = player_node->y;
+ switch (player_node->direction)
+ {
+ case Being::NORTH: y--; break;
+ case Being::SOUTH: y++; break;
+ case Being::WEST: x--; break;
+ case Being::EAST: x++; break;
+ case Being::NW: x--; y--; break;
+ case Being::NE: x++; y--; break;
+ case Being::SW: x--; y++; break;
+ case Being::SE: x++; y++; break;
+ default: break;
+ }
+ id = find_floor_item_by_cor(x, y);
+ }
- switch (player_node->direction)
+ if (id)
{
- case Being::NORTH: y--; break;
- case Being::SOUTH: y++; break;
- case Being::WEST: x--; break;
- case Being::EAST: x++; break;
- case Being::NW: x--; y--; break;
- case Being::NE: x++; y--; break;
- case Being::SW: x--; y++; break;
- case Being::SE: x++; y++; break;
- default: break;
+ // TODO: Remove duplicated code, probably add a
+ // pick up command
+ MessageOut outMsg;
+ outMsg.writeShort(0x009f);
+ outMsg.writeLong(id);
}
- id = find_floor_item_by_cor(x, y);
- }
-
- if (id)
- {
- // TODO: remove duplicated code, probably add a pick up command
- MessageOut outMsg;
- outMsg.writeShort(0x009f);
- outMsg.writeLong(id);
+ used = true;
}
- used = true;
break;
// Quitting confirmation dialog
@@ -841,8 +838,9 @@ void do_input()
} // End while
// Moving player around
- if ((player_node->action != Being::DEAD) && (current_npc == 0) &&
- !chatWindow->isFocused())
+ if (player_node->action != Being::DEAD &&
+ current_npc == 0 &&
+ !chatWindow->isFocused())
{
Uint16 x = player_node->x;
Uint16 y = player_node->y;
@@ -904,7 +902,7 @@ void do_input()
Direction = Being::NE;
}
- tiledMap = engine->getCurrentMap();
+ Map *tiledMap = engine->getCurrentMap();
// Allow keyboard control to interrupt an existing path
if ((xDirection != 0 || yDirection != 0) &&
@@ -961,9 +959,7 @@ void do_input()
if (joy[JOY_BTN1])
{
- Uint16 x = player_node->x;
- Uint16 y = player_node->y;
- Uint32 id = find_floor_item_by_cor(x, y);
+ Uint32 id = find_floor_item_by_cor(player_node->x, player_node->y);
if (id != 0)
{
@@ -1091,7 +1087,7 @@ void do_parse()
else if (msg.getId() == 0x0078)
{
being->clearPath();
- being->frame = 0;
+ being->mFrame = 0;
being->walk_time = tick_time;
being->action = Being::STAND;
}
@@ -1158,7 +1154,7 @@ void do_parse()
{
case Being::MONSTER:
being->action = Being::MONSTER_DEAD;
- being->frame = 0;
+ being->mFrame = 0;
being->walk_time = tick_time;
break;
@@ -1254,7 +1250,7 @@ void do_parse()
msg.readByte(); // unknown
being->walk_time = tick_time;
- being->frame = 0;
+ being->mFrame = 0;
}
break;
@@ -1506,7 +1502,7 @@ void do_parse()
beings.push_back(player_node);
player_node->action = Being::STAND;
- player_node->frame = 0;
+ player_node->mFrame = 0;
player_node->x = x;
player_node->y = y;
player_node->setMap(tiledMap);
@@ -1595,7 +1591,7 @@ void do_parse()
//if (being = findNode(readLong(2))) {
// if (being->getId() != player_node->getId()) {
// being->action = STAND;
- // being->frame = 0;
+ // being->mFrame = 0;
// set_coordinates(being->coordinates,
// readWord(6), readWord(8),
// get_direction(being->coordinates));
@@ -1627,20 +1623,20 @@ void do_parse()
{
// buggy
srcBeing->action = Being::ATTACK;
- srcBeing->frame = 0;
+ srcBeing->mFrame = 0;
srcBeing->walk_time = tick_time;
}
break;
case 2: // Sit
if (srcBeing == NULL) break;
- srcBeing->frame = 0;
+ srcBeing->mFrame = 0;
srcBeing->action = Being::SIT;
break;
case 3: // Stand up
if (srcBeing == NULL) break;
- srcBeing->frame = 0;
+ srcBeing->mFrame = 0;
srcBeing->action = Being::STAND;
break;
}
diff --git a/src/game.h b/src/game.h
index 8b72d508..92ee81a9 100644
--- a/src/game.h
+++ b/src/game.h
@@ -36,7 +36,7 @@ class Being;
extern std::string map_path;
extern std::string tradePartnerName;
-extern int fps, frame, current_npc;
+extern int fps, current_npc;
extern volatile int tick_time;
extern int server_tick;
extern bool displayPathToMouse;
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 74b71888..0a66bb66 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -135,7 +135,7 @@ bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY,
srcY += image->bounds.y;
// Check that preconditions for blitting are met.
- if (!mScreen || !image->image) return false;
+ if (!mScreen || !image->mImage) return false;
SDL_Rect dstRect;
SDL_Rect srcRect;
@@ -144,11 +144,7 @@ bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY,
srcRect.w = width;
srcRect.h = height;
- if (SDL_BlitSurface(image->image, &srcRect, mScreen, &dstRect) < 0) {
- return false;
- }
-
- return true;
+ return !(SDL_BlitSurface(image->mImage, &srcRect, mScreen, &dstRect) < 0);
}
void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h)
@@ -172,13 +168,13 @@ void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h)
}
}
-void Graphics::drawImageRect(
- int x, int y, int w, int h,
- Image *topLeft, Image *topRight,
- Image *bottomLeft, Image *bottomRight,
- Image *top, Image *right,
- Image *bottom, Image *left,
- Image *center)
+void
+Graphics::drawImageRect(int x, int y, int w, int h,
+ Image *topLeft, Image *topRight,
+ Image *bottomLeft, Image *bottomRight,
+ Image *top, Image *right,
+ Image *bottom, Image *left,
+ Image *center)
{
pushClipArea(gcn::Rectangle(x, y, w, h));
@@ -216,9 +212,9 @@ void Graphics::drawImageRect(
popClipArea();
}
-void Graphics::drawImageRect(
- int x, int y, int w, int h,
- const ImageRect &imgRect)
+void
+Graphics::drawImageRect(int x, int y, int w, int h,
+ const ImageRect &imgRect)
{
drawImageRect(x, y, w, h,
imgRect.grid[0], imgRect.grid[2], imgRect.grid[6], imgRect.grid[8],
diff --git a/src/gui/chargedialog.cpp b/src/gui/chargedialog.cpp
index c6cee598..e456810f 100644
--- a/src/gui/chargedialog.cpp
+++ b/src/gui/chargedialog.cpp
@@ -43,11 +43,6 @@ ChargeDialog::~ChargeDialog()
delete progBar;
}
-void ChargeDialog::action(const std::string& eventId)
-{
-
-}
-
// update the dialog
void ChargeDialog::logic()
{
diff --git a/src/gui/chargedialog.h b/src/gui/chargedialog.h
index 4e6d83dc..8a4f9b04 100644
--- a/src/gui/chargedialog.h
+++ b/src/gui/chargedialog.h
@@ -34,7 +34,7 @@ class ProgressBar;
/**
* \ingroup Interface
*/
-class ChargeDialog : public Window, public gcn::ActionListener
+class ChargeDialog : public Window
{
public:
/**
@@ -45,10 +45,8 @@ class ChargeDialog : public Window, public gcn::ActionListener
/**
* Destructor.
*/
- ~ChargeDialog();
-
- // action listener
- void action(const std::string&);
+ ~ChargeDialog();
+
void logic();
private:
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index a091abc9..7e1458c9 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -183,9 +183,9 @@ void ChatWindow::chat_log(std::string line, int own)
}
}
-void ChatWindow::chat_log(CHATSKILL action)
+void ChatWindow::chat_log(CHATSKILL act)
{
- chat_log(const_msg(action), BY_SERVER);
+ chat_log(const_msg(act), BY_SERVER);
}
void ChatWindow::action(const std::string& eventId)
@@ -227,7 +227,8 @@ bool ChatWindow::isFocused()
return chatInput->hasFocus();
}
-char *ChatWindow::chat_send(std::string nick, std::string msg)
+void
+ChatWindow::chat_send(std::string nick, std::string msg)
{
short packetId = CMSG_CHAT_MESSAGE;
@@ -240,7 +241,6 @@ char *ChatWindow::chat_send(std::string nick, std::string msg)
}*/
// prepare ordinary message
chat_log("Sorry but /commands are not available yet", BY_PLAYER);
- return "";
}
else {
nick += " : ";
@@ -254,15 +254,13 @@ char *ChatWindow::chat_send(std::string nick, std::string msg)
outMsg.writeShort(packetId);
outMsg.writeShort(msg.length() + 4);
outMsg.writeString(msg, msg.length());
-
- return "";
}
-std::string ChatWindow::const_msg(CHATSKILL action)
+std::string ChatWindow::const_msg(CHATSKILL act)
{
std::string msg;
- if (action.success == SKILL_FAILED && action.skill == SKILL_BASIC) {
- switch (action.bskill) {
+ if (act.success == SKILL_FAILED && act.skill == SKILL_BASIC) {
+ switch (act.bskill) {
case BSKILL_TRADE :
msg = "Trade failed!";
break;
@@ -283,7 +281,7 @@ std::string ChatWindow::const_msg(CHATSKILL action)
break;
}
- switch (action.reason) {
+ switch (act.reason) {
case RFAIL_SKILLDEP :
msg += " You have not yet reached a high enough lvl!";
break;
@@ -319,7 +317,7 @@ std::string ChatWindow::const_msg(CHATSKILL action)
break;
}
} else {
- switch(action.skill) {
+ switch(act.skill) {
case SKILL_WARP :
msg = "Warp failed...";
break;
diff --git a/src/gui/chat.h b/src/gui/chat.h
index 1766bd08..e648eda5 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -176,7 +176,8 @@ class ChatWindow : public Window, public gcn::ActionListener,
* // for simple message by a user /- message
* chatlog.chat_send("Zaeiru", "Hello to all users on the screen!");
*/
- char *chat_send(std::string nick, std::string msg);
+ void
+ chat_send(std::string nick, std::string msg);
/** Called when key is pressed */
void keyPress(const gcn::Key& key);
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index ba29a1e5..d1d23ee1 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -43,7 +43,6 @@ EquipmentWindow::EquipmentWindow():
setDefaultSize(5, 230, 200, 90);
loadWindowState();
-
ResourceManager *resman = ResourceManager::getInstance();
Image *itemImg = resman->getImage("graphics/sprites/items.png");
if (!itemImg) logger->error("Unable to load items.png");
@@ -94,7 +93,3 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
graphics->drawText(n.str(), 170, 62,
gcn::Graphics::CENTER);
}
-
-void EquipmentWindow::action(const std::string &eventId)
-{
-}
diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h
index 0470ba6f..a3241057 100644
--- a/src/gui/equipmentwindow.h
+++ b/src/gui/equipmentwindow.h
@@ -35,7 +35,8 @@ class Spriteset;
*
* \ingroup Interface
*/
-class EquipmentWindow : public Window, gcn::ActionListener {
+class EquipmentWindow : public Window
+{
public:
/**
* Constructor.
@@ -52,11 +53,6 @@ class EquipmentWindow : public Window, gcn::ActionListener {
*/
void draw(gcn::Graphics *graphics);
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const std::string& eventId);
-
private:
Spriteset *itemset;
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 365d8eba..c829cef7 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -69,12 +69,15 @@ gcn::ImageFont *speechFont;
class GuiConfigListener : public ConfigListener
{
public:
- GuiConfigListener(Gui *gui):mGui(gui) {}
+ GuiConfigListener(Gui *g):
+ mGui(g)
+ {}
void optionChanged(const std::string &name)
{
if (name == "customcursor") {
- mGui->setUseCustomCursor(config.getValue("customcursor", 1) == 1);
+ bool bCustomCursor = config.getValue("customcursor", 1) == 1;
+ mGui->setUseCustomCursor(bCustomCursor);
}
}
private:
diff --git a/src/gui/help.cpp b/src/gui/help.cpp
index 80ddbc9a..71e94340 100644
--- a/src/gui/help.cpp
+++ b/src/gui/help.cpp
@@ -51,7 +51,7 @@ HelpWindow::HelpWindow():
okButton->setEventId("close");
okButton->addActionListener(this);
-
+
browserBox->setLinkHandler(this);
add(scrollArea);
@@ -69,7 +69,10 @@ HelpWindow::~HelpWindow()
void HelpWindow::action(const std::string& eventId)
{
- setVisible(false);
+ if (eventId == "close")
+ {
+ setVisible(false);
+ }
}
void HelpWindow::handleLink(const std::string& link)
@@ -81,7 +84,7 @@ void HelpWindow::handleLink(const std::string& link)
void HelpWindow::loadHelp(const std::string &helpFile)
{
browserBox->clearRows();
-
+
loadFile("header");
loadFile(helpFile);
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 2fca3e3c..9012b8ee 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -42,6 +42,8 @@
#include "../resources/iteminfo.h"
+extern Inventory *inventory;
+
InventoryWindow::InventoryWindow():
Window("Inventory")
{
diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp
index 52570514..b313b98c 100644
--- a/src/gui/item_amount.cpp
+++ b/src/gui/item_amount.cpp
@@ -31,6 +31,8 @@
#include "../inventory.h"
#include "../item.h"
+extern Inventory *inventory;
+
ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item):
Window("Select amount of items to drop.", true, parent),
mItem(item)
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 81a85b8d..3f00f9eb 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -39,7 +39,7 @@
#include "../resources/resourcemanager.h"
ItemContainer::ItemContainer(Inventory *inventory):
- inventory(inventory)
+ mInventory(inventory)
{
ResourceManager *resman = ResourceManager::getInstance();
Image *itemImg = resman->getImage("graphics/sprites/items.png");
@@ -51,7 +51,7 @@ ItemContainer::ItemContainer(Inventory *inventory):
if (!selImg) logger->error("Unable to load selection.png");
selectedItem = 0; // No item selected
- maxItems = inventory->getLastUsedSlot();
+ maxItems = mInventory->getLastUsedSlot();
addMouseListener(this);
}
@@ -66,7 +66,7 @@ void ItemContainer::logic()
{
gcn::Widget::logic();
- int i = inventory->getLastUsedSlot();
+ int i = mInventory->getLastUsedSlot();
if (i != maxItems) {
maxItems = i;
@@ -100,7 +100,7 @@ void ItemContainer::draw(gcn::Graphics* graphics)
*/
for (int i = 2; i < INVENTORY_SIZE; i++)
{
- Item *item = inventory->getItem(i);
+ Item *item = mInventory->getItem(i);
if (item->getQuantity() <= 0) {
continue;
@@ -182,6 +182,6 @@ void ItemContainer::mousePress(int mx, int my, int button)
if (index > INVENTORY_SIZE) {
index = INVENTORY_SIZE - 1;
}
- selectedItem = inventory->getItem(index);
+ selectedItem = mInventory->getItem(index);
}
}
diff --git a/src/gui/itemcontainer.h b/src/gui/itemcontainer.h
index 9cd92812..69134d83 100644
--- a/src/gui/itemcontainer.h
+++ b/src/gui/itemcontainer.h
@@ -82,7 +82,7 @@ class ItemContainer : public gcn::Widget, public gcn::MouseListener
void selectNone();
private:
- Inventory *inventory;
+ Inventory *mInventory;
Spriteset *itemset;
Image *selImg;
Item *selectedItem;
diff --git a/src/gui/linkhandler.h b/src/gui/linkhandler.h
index 05a0a99b..65c0d433 100644
--- a/src/gui/linkhandler.h
+++ b/src/gui/linkhandler.h
@@ -21,8 +21,8 @@
* $Id$
*/
-#ifndef _TMW_LINK_HANDLER_H
-#define _TMW_LINK_HANDLER_H
+#ifndef _TMW_LINK_HANDLER_H_
+#define _TMW_LINK_HANDLER_H_
/**
* A simple interface to windows that need to handle links from BrowserBox
@@ -33,8 +33,8 @@ class LinkHandler
public:
virtual ~LinkHandler() { }
- virtual void handleLink(const std::string& link) { }
-
+ virtual void handleLink(const std::string& link) = 0;
+
protected:
LinkHandler() { }
};
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index aea77768..6d1c896d 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -60,11 +60,14 @@ WrongPasswordNoticeListener::setLoginDialog(LoginDialog *loginDialog)
void
WrongPasswordNoticeListener::action(const std::string &eventId)
{
- // Reset the password and put the caret ready to retype it.
- mLoginDialog->passField->setText("");
- mLoginDialog->passField->setCaretPosition(0);
- mLoginDialog->passField->requestFocus();
- wrongLoginNotice = NULL;
+ if (eventId == "ok")
+ {
+ // Reset the password and put the caret ready to retype it.
+ mLoginDialog->passField->setText("");
+ mLoginDialog->passField->setCaretPosition(0);
+ mLoginDialog->passField->requestFocus();
+ wrongLoginNotice = NULL;
+ }
}
void
@@ -76,10 +79,13 @@ WrongUsernameNoticeListener::setLoginDialog(LoginDialog *loginDialog)
void
WrongUsernameNoticeListener::action(const std::string &eventId)
{
- // Set the focus on the username Field
- mLoginDialog->userField->setCaretPosition(LEN_MAX_USERNAME - 1);
- mLoginDialog->userField->requestFocus();
- wrongLoginNotice = NULL;
+ if (eventId == "ok")
+ {
+ // Set the focus on the username Field
+ mLoginDialog->userField->setCaretPosition(LEN_MAX_USERNAME - 1);
+ mLoginDialog->userField->requestFocus();
+ wrongLoginNotice = NULL;
+ }
}
LoginDialog::LoginDialog():
@@ -269,41 +275,41 @@ LoginDialog::action(const std::string& eventId)
else if (user.length() < LEN_MIN_USERNAME)
{
// Name too short
- std::stringstream errorMessage;
- errorMessage << "The username needs to be at least "
- << LEN_MIN_USERNAME
- << " characters long.";
- wrongLoginNotice = new OkDialog("Error", errorMessage.str(),
+ std::stringstream errorMsg;
+ errorMsg << "The username needs to be at least "
+ << LEN_MIN_USERNAME
+ << " characters long.";
+ wrongLoginNotice = new OkDialog("Error", errorMsg.str(),
&wrongUsernameNoticeListener);
}
else if (user.length() > LEN_MAX_USERNAME - 1 )
{
// Name too long
- std::stringstream errorMessage;
- errorMessage << "The username needs to be less than "
- << LEN_MAX_USERNAME
- << " characters long.";
- wrongLoginNotice = new OkDialog("Error", errorMessage.str(),
+ std::stringstream errorMsg;
+ errorMsg << "The username needs to be less than "
+ << LEN_MAX_USERNAME
+ << " characters long.";
+ wrongLoginNotice = new OkDialog("Error", errorMsg.str(),
&wrongUsernameNoticeListener);
}
else if (passField->getText().length() < LEN_MIN_PASSWORD)
{
// Pass too short
- std::stringstream errorMessage;
- errorMessage << "The password needs to be at least "
- << LEN_MIN_PASSWORD
- << " characters long.";
- wrongLoginNotice = new OkDialog("Error", errorMessage.str(),
+ std::stringstream errorMsg;
+ errorMsg << "The password needs to be at least "
+ << LEN_MIN_PASSWORD
+ << " characters long.";
+ wrongLoginNotice = new OkDialog("Error", errorMsg.str(),
&wrongPasswordNoticeListener);
}
else if (passField->getText().length() > LEN_MAX_PASSWORD - 1 )
{
// Pass too long
- std::stringstream errorMessage;
- errorMessage << "The password needs to be less than "
- << LEN_MAX_PASSWORD
- << " characters long.";
- wrongLoginNotice = new OkDialog("Error", errorMessage.str(),
+ std::stringstream errorMsg;
+ errorMsg << "The password needs to be less than "
+ << LEN_MAX_PASSWORD
+ << " characters long.";
+ wrongLoginNotice = new OkDialog("Error", errorMsg.str(),
&wrongPasswordNoticeListener);
}
else
diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp
index 1e190102..280339a1 100644
--- a/src/gui/menuwindow.cpp
+++ b/src/gui/menuwindow.cpp
@@ -33,6 +33,7 @@
#include "skill.h"
#include "../graphics.h"
+
extern Graphics *graphics;
extern Window *setupWindow;
@@ -78,8 +79,8 @@ MenuWindow::MenuWindow():
int menuWidth = setupButton->getX() + setupButton->getWidth();
setDefaultSize((graphics->getWidth() - menuWidth - 5), 0,
- menuWidth,
- (setupButton->getY() + setupButton->getHeight()));
+ menuWidth,
+ (setupButton->getY() + setupButton->getHeight()));
}
MenuWindow::~MenuWindow()
@@ -91,9 +92,9 @@ MenuWindow::~MenuWindow()
delete setupButton;
}
-void MenuWindow::draw(gcn::Graphics *graphics)
+void MenuWindow::draw(gcn::Graphics *g)
{
- Window::drawContent(graphics);
+ Window::drawContent(g);
}
void MenuWindow::action(const std::string& eventId)
diff --git a/src/gui/newskill.cpp b/src/gui/newskill.cpp
index 12c87b36..ec080d81 100644
--- a/src/gui/newskill.cpp
+++ b/src/gui/newskill.cpp
@@ -34,7 +34,7 @@
#include "../graphics.h"
-char *skill_name[] = {
+const char *skill_name[] = {
// 0-99
// weapon skills 0-9
"Short Blades", "Long Blades", "Hammers", "Archery", "Whip",
@@ -69,7 +69,6 @@ char *skill_name[] = {
};
-
NewSkillDialog::NewSkillDialog():
Window("Skills")
{
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index 9896f08e..2e0b0837 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -80,10 +80,13 @@ NpcTextDialog::addText(const std::string &text)
void
NpcTextDialog::action(const std::string& eventId)
{
- MessageOut outMsg;
- outMsg.writeShort(CMSG_NPC_NEXT_REQUEST);
- outMsg.writeLong(current_npc);
- setText("");
- setVisible(false);
- current_npc = 0;
+ if (eventId == "ok")
+ {
+ MessageOut outMsg;
+ outMsg.writeShort(CMSG_NPC_NEXT_REQUEST);
+ outMsg.writeLong(current_npc);
+ setText("");
+ setVisible(false);
+ current_npc = 0;
+ }
}
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index feb287eb..6bb57f60 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -47,13 +47,17 @@
#include "../resources/itemmanager.h"
extern Being* autoTarget;
+extern Inventory* inventory;
PopupMenu::PopupMenu():
- Window()
+ Window(),
+ mBeing(NULL),
+ mFloorItem(NULL),
+ mItem(NULL)
{
setResizable(false);
setTitleBarHeight(0);
- title = false;
+ mShowTitle = false;
browserBox = new BrowserBox();
browserBox->setPosition(4, 4);
@@ -61,29 +65,25 @@ PopupMenu::PopupMenu():
browserBox->setOpaque(false);
add(browserBox);
browserBox->setLinkHandler(this);
-
- being = NULL;
- floorItem = NULL;
}
PopupMenu::~PopupMenu()
{
delete browserBox;
- delete floorItem;
}
void PopupMenu::showPopup(int x, int y, Being *being)
{
- this->being = being;
+ mBeing = being;
browserBox->clearRows();
- switch (being->getType())
+ switch (mBeing->getType())
{
case Being::PLAYER:
{
// Players can be traded with. Later also attack, follow and
// add as buddy will be options in this menu.
- const std::string &name = being->getName();
+ const std::string &name = mBeing->getName();
browserBox->addRow("@@trade|Trade With " + name + "@@");
browserBox->addRow("@@attack|Attack " + name + "@@");
@@ -112,11 +112,11 @@ void PopupMenu::showPopup(int x, int y, Being *being)
void PopupMenu::showPopup(int x, int y, FloorItem *floorItem)
{
- this->floorItem = floorItem;
+ mFloorItem = floorItem;
browserBox->clearRows();
// Floor item can be picked up (single option, candidate for removal)
- std::string name = itemDb->getItemInfo(floorItem->getItemId())->getName();
+ std::string name = itemDb->getItemInfo(mFloorItem->getItemId())->getName();
browserBox->addRow("@@pickup|Pick Up " + name + "@@");
//browserBox->addRow("@@look|Look To@@");
@@ -129,32 +129,38 @@ void PopupMenu::showPopup(int x, int y, FloorItem *floorItem)
void PopupMenu::handleLink(const std::string& link)
{
// Talk To action
- if ((link == "talk") && being && being->getType() == Being::NPC &&
- (current_npc == 0))
+ if (link == "talk" &&
+ mBeing != NULL &&
+ mBeing->getType() == Being::NPC &&
+ current_npc == 0)
{
MessageOut outMsg;
outMsg.writeShort(CMSG_NPC_TALK);
- outMsg.writeLong(being->getId());
+ outMsg.writeLong(mBeing->getId());
outMsg.writeByte(0);
- current_npc = being->getId();
+ current_npc = mBeing->getId();
}
// Trade action
- else if ((link == "trade") && being && being->getType() == Being::PLAYER)
+ else if (link == "trade" &&
+ mBeing != NULL &&
+ mBeing->getType() == Being::PLAYER)
{
MessageOut outMsg;
outMsg.writeShort(CMSG_TRADE_REQUEST);
- outMsg.writeLong(being->getId());
+ outMsg.writeLong(mBeing->getId());
//tradePartner.flush();
//tradePartner << "Trade: You and " << being->name<< "";
- tradePartnerName = being->getName();
+ tradePartnerName = mBeing->getName();
}
// Attack action
- else if ((link == "attack") && being && being->getType() == Being::PLAYER)
+ else if (link == "attack" &&
+ mBeing != NULL &&
+ mBeing->getType() == Being::PLAYER)
{
- autoTarget = being;
- attack(being);
+ autoTarget = mBeing;
+ attack(mBeing);
}
/*
@@ -165,20 +171,20 @@ void PopupMenu::handleLink(const std::string& link)
/*
// Add Buddy action
- else if ((link == "buddy") && being && being->isPlayer())
+ else if ((link == "buddy") && mBeing != NULL && mBeing->isPlayer())
{
if (!buddyWindow->isVisible())
buddyWindow->setVisible(true);
- buddyWindow->addBuddy(being->getName());
+ buddyWindow->addBuddy(mBeing->getName());
}*/
// Pick Up Floor Item action
- else if ((link == "pickup") && floorItem)
+ else if ((link == "pickup") && mFloorItem != NULL)
{
MessageOut outMsg;
outMsg.writeShort(CMSG_ITEM_PICKUP);
- outMsg.writeLong(floorItem->getId());
+ outMsg.writeLong(mFloorItem->getId());
}
// Look To action
@@ -188,27 +194,27 @@ void PopupMenu::handleLink(const std::string& link)
else if (link == "use")
{
- assert(m_item);
- if (m_item->isEquipment())
+ assert(mItem);
+ if (mItem->isEquipment())
{
- if (m_item->isEquipped())
+ if (mItem->isEquipped())
{
- inventory->unequipItem(m_item);
+ inventory->unequipItem(mItem);
}
else
{
- inventory->equipItem(m_item);
+ inventory->equipItem(mItem);
}
}
else
{
- inventory->useItem(m_item);
+ inventory->useItem(mItem);
}
}
else if (link == "drop")
{
- new ItemAmountWindow(AMOUNT_ITEM_DROP, inventoryWindow, m_item);
+ new ItemAmountWindow(AMOUNT_ITEM_DROP, inventoryWindow, mItem);
}
else if (link == "description")
@@ -231,15 +237,15 @@ void PopupMenu::handleLink(const std::string& link)
*/
_getFocusHandler()->focusNone();
- being = NULL;
- floorItem = NULL;
- m_item = NULL;
+ mBeing = NULL;
+ mFloorItem = NULL;
+ mItem = NULL;
}
void PopupMenu::showPopup(int x, int y, Item *item)
{
assert(item);
- m_item = item;
+ mItem = item;
browserBox->clearRows();
if (item->isEquipment())
diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h
index 0ba9f485..0cd6225c 100644
--- a/src/gui/popupmenu.h
+++ b/src/gui/popupmenu.h
@@ -74,10 +74,9 @@ class PopupMenu : public Window, public LinkHandler
private:
BrowserBox* browserBox;
- Being* being;
- FloorItem* floorItem;
-
- Item *m_item;
+ Being* mBeing;
+ FloorItem* mFloorItem;
+ Item *mItem;
/**
* Shared code for the various showPopup functions.
diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp
index 834ca73a..0863db98 100644
--- a/src/gui/progressbar.cpp
+++ b/src/gui/progressbar.cpp
@@ -35,12 +35,10 @@ int ProgressBar::mInstances = 0;
ProgressBar::ProgressBar(float progress, int x, int y,
unsigned int width, unsigned int height,
- unsigned char red,
- unsigned char green,
- unsigned char blue):
+ Uint8 red, Uint8 green, Uint8 blue):
gcn::Widget(),
- red(red), green(green), blue(blue),
- redToGo(red), greenToGo(green), blueToGo(blue)
+ mRed(red), mGreen(green), mBlue(blue),
+ mRedToGo(red), mGreenToGo(green), mBlueToGo(blue)
{
setProgress(progress);
setX(x);
@@ -88,58 +86,43 @@ ProgressBar::~ProgressBar()
void ProgressBar::logic()
{
// Smoothly changing the color for a nicer effect.
- if (redToGo > red) red++;
- if (redToGo < red) red--;
- if (greenToGo > green) green++;
- if (greenToGo < green) green--;
- if (blueToGo > blue) blue++;
- if (blueToGo < blue) blue--;
+ if (mRedToGo > mRed) mRed++;
+ if (mRedToGo < mRed) mRed--;
+ if (mGreenToGo > mGreen) mGreen++;
+ if (mGreenToGo < mGreen) mGreen--;
+ if (mBlueToGo > mBlue) mBlue++;
+ if (mBlueToGo < mBlue) mBlue--;
}
-void ProgressBar::draw(gcn::Graphics *graphics)
+void
+ProgressBar::draw(gcn::Graphics *graphics)
{
- dynamic_cast<Graphics*>(graphics)->drawImageRect(0, 0, getWidth(), getHeight(),
- mBorder);
+ dynamic_cast<Graphics*>(graphics)->drawImageRect(0, 0,
+ getWidth(), getHeight(),
+ mBorder);
// The bar
- if (progress > 0)
+ if (mProgress > 0)
{
- graphics->setColor(gcn::Color(red, green, blue, 200));
+ graphics->setColor(gcn::Color(mRed, mGreen, mBlue, 200));
graphics->fillRectangle(gcn::Rectangle(4, 4,
- (int)(progress * (getWidth() - 8)), getHeight() - 8));
+ (int)(mProgress * (getWidth() - 8)),
+ getHeight() - 8));
}
}
-void ProgressBar::setProgress(float progress)
+void
+ProgressBar::setProgress(float progress)
{
- if (progress < 0.0f) this->progress = 0.0;
- else if (progress > 1.0f) this->progress = 1.0;
- else this->progress = progress;
+ if (progress < 0.0f) mProgress = 0.0;
+ else if (progress > 1.0f) mProgress = 1.0;
+ else mProgress = progress;
}
-float ProgressBar::getProgress()
+void
+ProgressBar::setColor(Uint8 red, Uint8 green, Uint8 blue)
{
- return progress;
-}
-
-void ProgressBar::setColor(unsigned char red, unsigned char green, unsigned char blue)
-{
- redToGo = red;
- greenToGo = green;
- blueToGo = blue;
-}
-
-unsigned char ProgressBar::getRed()
-{
- return red;
-}
-
-unsigned char ProgressBar::getGreen()
-{
- return green;
-}
-
-unsigned char ProgressBar::getBlue()
-{
- return blue;
+ mRedToGo = red;
+ mGreenToGo = green;
+ mBlueToGo = blue;
}
diff --git a/src/gui/progressbar.h b/src/gui/progressbar.h
index fe9e7085..cd62c498 100644
--- a/src/gui/progressbar.h
+++ b/src/gui/progressbar.h
@@ -26,6 +26,8 @@
#include <guichan/widget.hpp>
+#include <SDL_types.h>
+
class ImageRect;
@@ -40,8 +42,8 @@ class ProgressBar : public gcn::Widget {
* Constructor, initializes the progress with the given value.
*/
ProgressBar(float progress = 0.0f, int x = 0, int y = 0,
- unsigned int width = 40, unsigned int height = 7,
- unsigned char red = 150, unsigned char green = 150, unsigned char blue = 150);
+ unsigned int width = 40, unsigned int height = 7,
+ Uint8 red = 150, Uint8 green = 150, Uint8 blue = 150);
/**
* Destructor.
@@ -51,47 +53,55 @@ class ProgressBar : public gcn::Widget {
/**
* Performs progress bar logic (fading colors)
*/
- void logic();
+ void
+ logic();
/**
* Draws the progress bar.
*/
- void draw(gcn::Graphics *graphics);
+ void
+ draw(gcn::Graphics *graphics);
/**
* Sets the current progress.
*/
- void setProgress(float progress);
+ void
+ setProgress(float progress);
/**
* Returns the current progress.
*/
- float getProgress();
+ float
+ getProgress() { return mProgress; }
/**
* Change the filling of the progress bar.
*/
- void setColor(unsigned char red, unsigned char green, unsigned char blue);
+ void
+ setColor(Uint8, Uint8 green, Uint8 blue);
/**
* Get The red value of color
*/
- unsigned char getRed();
+ Uint8
+ getRed() { return mRed; }
/**
* Get The red value of color
*/
- unsigned char getGreen();
+ Uint8
+ getGreen() { return mGreen; }
- /**
+ /**
* Get The red value of color
*/
- unsigned char getBlue();
+ Uint8
+ getBlue() { return mBlue; }
private:
- float progress;
- unsigned char red, green, blue;
- unsigned char redToGo, greenToGo, blueToGo;
+ float mProgress;
+ Uint8 mRed, mGreen, mBlue;
+ Uint8 mRedToGo, mGreenToGo, mBlueToGo;
static ImageRect mBorder;
static int mInstances;
diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp
index ec8a7946..246e2ffa 100644
--- a/src/gui/scrollarea.cpp
+++ b/src/gui/scrollarea.cpp
@@ -216,21 +216,21 @@ void ScrollArea::draw(gcn::Graphics *graphics)
void ScrollArea::drawBorder(gcn::Graphics *graphics)
{
- int w, h, bs;
- bs = getBorderSize();
- w = getWidth() + bs * 2;
- h = getHeight() + bs * 2;
+ int bs = getBorderSize();
+ int w = getWidth() + bs * 2;
+ int h = getHeight() + bs * 2;
- if (isOpaque()) {
- dynamic_cast<Graphics*>(graphics)->drawImageRect(0, 0, w, h, background);
+ if (mOpaque) {
+ dynamic_cast<Graphics*>(graphics)->drawImageRect(0, 0, w, h,
+ background);
}
}
void ScrollArea::setOpaque(bool opaque)
{
- this->opaque = opaque;
+ mOpaque = opaque;
- if (opaque) {
+ if (mOpaque) {
setBorderSize(2);
}
else {
@@ -238,11 +238,6 @@ void ScrollArea::setOpaque(bool opaque)
}
}
-bool ScrollArea::isOpaque()
-{
- return opaque;
-}
-
void ScrollArea::drawButton(gcn::Graphics *graphics, BUTTON_DIR dir)
{
int state = 0;
diff --git a/src/gui/scrollarea.h b/src/gui/scrollarea.h
index f2e00466..d75e194a 100644
--- a/src/gui/scrollarea.h
+++ b/src/gui/scrollarea.h
@@ -70,19 +70,21 @@ class ScrollArea : public gcn::ScrollArea {
/**
* Sets whether the widget should draw its background or not.
*/
- void setOpaque(bool opaque);
+ void
+ setOpaque(bool opaque);
/**
* Returns whether the widget draws its background or not.
*/
- bool isOpaque();
+ bool
+ isOpaque() { return mOpaque; }
protected:
enum BUTTON_DIR {
UP,
DOWN,
LEFT,
- RIGHT,
+ RIGHT
};
/**
@@ -105,7 +107,7 @@ class ScrollArea : public gcn::ScrollArea {
static ImageRect vMarker;
static Image *buttons[4][2];
- bool opaque;
+ bool mOpaque;
};
#endif
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index 75f77e39..b65fcfd9 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -37,7 +37,7 @@
#include "../graphics.h"
extern Graphics *graphics;
-char *skill_db[] = {
+const char *skill_db[] = {
// 0-99
"", "Basic", "Sword", "Two hand", "HP regeneration", "Bash", "Provoke", "Magnum", "Endure", "MP regeneration",
"", "", "", "", "", "", "", "", "", "",
diff --git a/src/gui/status.cpp b/src/gui/status.cpp
index 1a858297..1ba09b98 100644
--- a/src/gui/status.cpp
+++ b/src/gui/status.cpp
@@ -35,6 +35,7 @@
#include "../net/protocol.h"
#include "../graphics.h"
+
extern Graphics *graphics;
StatusWindow::StatusWindow():
@@ -43,7 +44,7 @@ StatusWindow::StatusWindow():
setWindowName("Status");
setResizable(true);
setDefaultSize((graphics->getWidth() - 365) / 2,
- (graphics->getHeight() - 255) / 2, 365, 255);
+ (graphics->getHeight() - 255) / 2, 365, 255);
loadWindowState();
// ----------------------
@@ -428,11 +429,11 @@ void StatusWindow::update()
jobValueLabel->setPosition(290, jobXpLabel->getY());
}
-void StatusWindow::draw(gcn::Graphics *graphics)
+void StatusWindow::draw(gcn::Graphics *g)
{
update();
- Window::draw(graphics);
+ Window::draw(g);
}
void StatusWindow::action(const std::string& eventId)
diff --git a/src/gui/trade.h b/src/gui/trade.h
index 7cb350da..1a2d0d99 100644
--- a/src/gui/trade.h
+++ b/src/gui/trade.h
@@ -96,7 +96,8 @@ class TradeWindow : public Window, gcn::ActionListener
/**
* Send trade packet.
*/
- void TradeWindow::tradeItem(Item *item, int quantity);
+ void
+ tradeItem(Item *item, int quantity);
/**
* Called on mouse click.
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 2f288fff..54fc0103 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -67,11 +67,11 @@ class WindowConfigListener : public ConfigListener
Window::Window(const std::string& caption, bool modal, Window *parent):
gcn::Window(caption),
- parent(parent),
+ mParent(parent),
mWindowName("window"),
snapSize(8),
- title(true),
- modal(modal),
+ mShowTitle(true),
+ mModal(modal),
resizable(false),
mMouseResize(false),
minWinWidth(6),
@@ -114,14 +114,14 @@ Window::Window(const std::string& caption, bool modal, Window *parent):
setTitleBarHeight(20);
// Add chrome
- chrome = new gcn::Container();
- chrome->setOpaque(false);
- setContent(chrome);
+ mChrome = new gcn::Container();
+ mChrome->setOpaque(false);
+ setContent(mChrome);
// Add this window to the window container
windowContainer->add(this);
- if (modal)
+ if (mModal)
{
requestModalFocus();
}
@@ -163,7 +163,7 @@ Window::~Window()
resizeGrip->decRef();
}
- delete chrome;
+ delete mChrome;
}
void Window::setWindowContainer(WindowContainer *wc)
@@ -186,7 +186,7 @@ void Window::draw(gcn::Graphics* graphics)
}
// Draw title
- if (title) {
+ if (mShowTitle) {
graphics->setFont(getFont());
graphics->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT);
}
@@ -196,13 +196,13 @@ void Window::draw(gcn::Graphics* graphics)
void Window::setContentWidth(int width)
{
- chrome->setWidth(width);
+ mChrome->setWidth(width);
resizeToContent();
}
void Window::setContentHeight(int height)
{
- chrome->setHeight(height);
+ mChrome->setHeight(height);
resizeToContent();
}
@@ -254,11 +254,6 @@ bool Window::isResizable()
return resizable;
}
-Window *Window::getParentWindow()
-{
- return parent;
-}
-
void Window::scheduleDelete()
{
windowContainer->scheduleDelete(this);
@@ -266,12 +261,12 @@ void Window::scheduleDelete()
void Window::add(gcn::Widget *w)
{
- chrome->add(w);
+ mChrome->add(w);
}
void Window::add(gcn::Widget *w, int x, int y)
{
- chrome->add(w, x, y);
+ mChrome->add(w, x, y);
}
void Window::mousePress(int x, int y, int button)
@@ -401,7 +396,8 @@ void Window::mouseMotion(int x, int y)
}
}
-void Window::mouseRelease(int x, int y, int button)
+void
+Window::mouseRelease(int x, int y, int button)
{
if (button == 1)
{
@@ -410,7 +406,8 @@ void Window::mouseRelease(int x, int y, int button)
}
}
-gcn::Rectangle Window::getGripDimension()
+gcn::Rectangle
+Window::getGripDimension()
{
return gcn::Rectangle(getWidth() - resizeGrip->getWidth(),
getHeight() - resizeGrip->getHeight(),
@@ -418,7 +415,8 @@ gcn::Rectangle Window::getGripDimension()
getHeight());
}
-void Window::loadWindowState()
+void
+Window::loadWindowState()
{
const std::string &name = mWindowName;
diff --git a/src/gui/window.h b/src/gui/window.h
index 66330350..ee85c97f 100644
--- a/src/gui/window.h
+++ b/src/gui/window.h
@@ -138,7 +138,8 @@ class Window : public gcn::Window
*
* @return The parent window or <code>NULL</code> if there is none.
*/
- Window *getParentWindow();
+ Window*
+ getParentWindow() { return mParent; }
/**
* Schedule this window for deletion. It will be deleted at the start
@@ -195,12 +196,12 @@ class Window : public gcn::Window
virtual void resetToDefaultSize();
protected:
- gcn::Container *chrome; /**< Contained container */
- Window *parent; /**< The parent window */
+ gcn::Container *mChrome; /**< Contained container */
+ Window *mParent; /**< The parent window */
std::string mWindowName; /**< Name of the window */
int snapSize; /**< Snap distance to window edge */
- bool title; /**< Window has a title bar */
- bool modal; /**< Window is modal */
+ bool mShowTitle; /**< Window has a title bar */
+ bool mModal; /**< Window is modal */
bool resizable; /**< Window can be resized */
bool mMouseResize; /**< Window is being resized */
int minWinWidth; /**< Minimum window width */
diff --git a/src/guichanfwd.h b/src/guichanfwd.h
index 981d6878..5eabc783 100644
--- a/src/guichanfwd.h
+++ b/src/guichanfwd.h
@@ -68,6 +68,6 @@ namespace gcn {
class TextField;
class Widget;
class Window;
-};
+}
#endif
diff --git a/src/inventory.h b/src/inventory.h
index 461a4a50..bd6da744 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -97,6 +97,4 @@ class Inventory
Item *items; /**< The holder of items */
};
-extern Inventory *inventory;
-
#endif
diff --git a/src/map.cpp b/src/map.cpp
index 3237b54a..37b7292a 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -36,8 +36,8 @@ MetaTile::MetaTile():
}
-Location::Location(int x, int y, MetaTile *tile):
- x(x), y(y), tile(tile)
+Location::Location(int iX, int iY, MetaTile *iTile):
+ x(iX), y(iY), tile(iTile)
{
}
@@ -88,7 +88,7 @@ Map::addTileset(Tileset *tileset)
bool spriteCompare(const Sprite *a, const Sprite *b)
{
- return a->getY() < b->getY();
+ return a->getPixelY() < b->getPixelY();
}
void
@@ -118,7 +118,7 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer)
// tiles have been drawn
if (layer == 1)
{
- while (si != mSprites.end() && (*si)->getY() < y * 32)
+ while (si != mSprites.end() && (*si)->getPixelY() <= y * 32 - 32)
{
(*si)->draw(graphics, -scrollX, -scrollY);
si++;
@@ -135,6 +135,16 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer)
}
}
}
+
+ // Draw any remaining sprites
+ if (layer == 1)
+ {
+ while (si != mSprites.end())
+ {
+ (*si)->draw(graphics, -scrollX, -scrollY);
+ si++;
+ }
+ }
}
void
diff --git a/src/map.h b/src/map.h
index 18278c20..95144695 100644
--- a/src/map.h
+++ b/src/map.h
@@ -29,7 +29,6 @@
#include <vector>
#include "properties.h"
-class Being;
class Graphics;
class Image;
class Tileset;
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index 6086e096..25bf2f07 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -126,7 +126,6 @@ std::string
MessageIn::readString(int length)
{
int stringLength = 0;
- std::string readString = "";
// Get string length
if (length < 0) {
@@ -144,10 +143,10 @@ MessageIn::readString(int length)
tmpString[stringLength] = 0;
mPos += stringLength;
- readString = tmpString;
+ std::string read = tmpString;
delete[] tmpString;
- return readString;
+ return read;
}
char& operator<<(char &lhs, MessageIn &msg)
diff --git a/src/net/packet.cpp b/src/net/packet.cpp
index 6d7b2b3e..e77ac117 100644
--- a/src/net/packet.cpp
+++ b/src/net/packet.cpp
@@ -26,15 +26,15 @@
#include <cstring>
Packet::Packet(const char *data, int length):
- length(length)
+ mLength(length)
{
// Create a copy of the data
- this->data = new char[length];
- memcpy(this->data, data, length);
+ mData = new char[mLength];
+ memcpy(mData, data, mLength);
}
Packet::~Packet()
{
// Clean up the data
- delete[] data;
+ delete[] mData;
}
diff --git a/src/net/packet.h b/src/net/packet.h
index 6b9fd18d..84d16d5e 100644
--- a/src/net/packet.h
+++ b/src/net/packet.h
@@ -40,8 +40,8 @@ class Packet
*/
~Packet();
- char *data; /**< Packet data */
- unsigned int length; /**< Length of data in bytes */
+ char *mData; /**< Packet data */
+ unsigned int mLength; /**< Length of data in bytes */
};
#endif
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index d7915256..983c948e 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -89,13 +89,13 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY,
srcY += image->bounds.y;
// Find OpenGL texture coordinates
- float texX1 = srcX / (float)image->texWidth;
- float texY1 = srcY / (float)image->texHeight;
- float texX2 = (srcX + width) / (float)image->texWidth;
- float texY2 = (srcY + height) / (float)image->texHeight;
+ float texX1 = srcX / (float)image->mTexWidth;
+ float texY1 = srcY / (float)image->mTexHeight;
+ float texX2 = (srcX + width) / (float)image->mTexWidth;
+ float texY2 = (srcY + height) / (float)image->mTexHeight;
glColor4f(1.0f, 1.0f, 1.0f, image->alpha);
- glBindTexture(GL_TEXTURE_2D, image->glimage);
+ glBindTexture(GL_TEXTURE_2D, image->mGLImage);
drawTexedQuad(dstX, dstY, width, height, texX1, texY1, texX2, texY2);
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 27fc6497..266f46e3 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -28,28 +28,28 @@
#include "../log.h"
#ifdef USE_OPENGL
-bool Image::useOpenGL = false;
+bool Image::mUseOpenGL = false;
#endif
Image::Image(const std::string &idPath, SDL_Surface *image):
- Resource(idPath), image(image)
+ Resource(idPath), mImage(image)
{
// Default to opaque
alpha = 1.0f;
bounds.x = 0;
bounds.y = 0;
- bounds.w = image->w;
- bounds.h = image->h;
+ bounds.w = mImage->w;
+ bounds.h = mImage->h;
}
#ifdef USE_OPENGL
Image::Image(const std::string &idPath, GLuint glimage, int width, int height,
- int texWidth, int texHeight):
+ int texWidth, int texHeight):
Resource(idPath),
- glimage(glimage),
- texWidth(texWidth),
- texHeight(texHeight)
+ mGLImage(glimage),
+ mTexWidth(texWidth),
+ mTexHeight(texHeight)
{
// Default to opaque
alpha = 1.0f;
@@ -66,7 +66,8 @@ Image::~Image()
unload();
}
-Image* Image::load(void* buffer, unsigned int bufferSize, const std::string &idPath)
+Image* Image::load(void *buffer, unsigned int bufferSize,
+ const std::string &idPath)
{
// Load the raw file data from the buffer in an RWops structure
SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize);
@@ -154,7 +155,7 @@ Image* Image::load(void* buffer, unsigned int bufferSize, const std::string &idP
}
#ifdef USE_OPENGL
- if (useOpenGL)
+ if (mUseOpenGL)
{
int width = tmpImage->w;
int height = tmpImage->h;
@@ -264,40 +265,27 @@ void Image::unload()
loaded = false;
#ifdef USE_OPENGL
- if (useOpenGL) {
- return;
- }
+ if (mUseOpenGL) return;
#endif
- if (!image) {
- return;
- }
+ if (!mImage) return;
// Free the image surface.
- SDL_FreeSurface(image);
- image = NULL;
-}
-
-int Image::getWidth() const
-{
- return bounds.w;
-}
-
-int Image::getHeight() const
-{
- return bounds.h;
+ SDL_FreeSurface(mImage);
+ mImage = NULL;
}
Image *Image::getSubImage(int x, int y, int width, int height)
{
// Create a new clipped sub-image
#ifdef USE_OPENGL
- if (useOpenGL) {
- return new SubImage(this, glimage, x, y, width, height, texWidth, texHeight);
+ if (mUseOpenGL) {
+ return new SubImage(this, mGLImage, x, y, width, height,
+ mTexWidth, mTexHeight);
}
#endif
- return new SubImage(this, image, x, y, width, height);
+ return new SubImage(this, mImage, x, y, width, height);
}
void Image::setAlpha(float a)
@@ -305,13 +293,13 @@ void Image::setAlpha(float a)
alpha = a;
#ifdef USE_OPENGL
- if (useOpenGL) {
+ if (mUseOpenGL) {
return;
}
#endif
// Set the alpha value this image is drawn at
- SDL_SetAlpha(image, SDL_SRCALPHA | SDL_RLEACCEL, (int)(255 * alpha));
+ SDL_SetAlpha(mImage, SDL_SRCALPHA | SDL_RLEACCEL, (int)(255 * alpha));
}
float Image::getAlpha()
@@ -322,7 +310,7 @@ float Image::getAlpha()
#ifdef USE_OPENGL
void Image::setLoadAsOpenGL(bool useOpenGL)
{
- Image::useOpenGL = useOpenGL;
+ Image::mUseOpenGL = useOpenGL;
}
#endif
@@ -332,9 +320,9 @@ void Image::setLoadAsOpenGL(bool useOpenGL)
SubImage::SubImage(Image *parent, SDL_Surface *image,
int x, int y, int width, int height):
- Image("", image), parent(parent)
+ Image("", image), mParent(parent)
{
- parent->incRef();
+ mParent->incRef();
// Set up the rectangle.
bounds.x = x;
@@ -345,10 +333,11 @@ SubImage::SubImage(Image *parent, SDL_Surface *image,
#ifdef USE_OPENGL
SubImage::SubImage(Image *parent, GLuint image,
- int x, int y, int width, int height, int texWidth, int texHeight):
- Image("", image, width, height, texWidth, texHeight), parent(parent)
+ int x, int y, int width, int height,
+ int texWidth, int texHeight):
+ Image("", image, width, height, texWidth, texHeight), mParent(parent)
{
- parent->incRef();
+ mParent->incRef();
// Set up the rectangle.
bounds.x = x;
@@ -361,14 +350,14 @@ SubImage::SubImage(Image *parent, GLuint image,
SubImage::~SubImage()
{
#ifdef USE_OPENGL
- if (!useOpenGL) {
- image = NULL;
+ if (!mUseOpenGL) {
+ mImage = NULL;
}
#else
- image = NULL;
+ mImage = NULL;
#endif
- parent->decRef();
+ mParent->decRef();
}
Image *SubImage::getSubImage(int x, int y, int w, int h)
diff --git a/src/resources/image.h b/src/resources/image.h
index 6fc4e89a..a7d5cdf1 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -70,13 +70,14 @@ class Image : public Resource
* Returns the width of the image.
*/
virtual int
- getWidth() const;
+ getWidth() const { return bounds.w; }
+
/**
* Returns the height of the image.
*/
virtual int
- getHeight() const;
+ getHeight() const { return bounds.h; }
/**
* Creates a new image with the desired clipping rectangle.
@@ -122,12 +123,12 @@ class Image : public Resource
bool loaded;
#ifdef USE_OPENGL
- GLuint glimage;
- int texWidth, texHeight;
+ GLuint mGLImage;
+ int mTexWidth, mTexHeight;
- static bool useOpenGL;
+ static bool mUseOpenGL;
#endif
- SDL_Surface *image;
+ SDL_Surface *mImage;
float alpha;
};
@@ -162,7 +163,7 @@ class SubImage : public Image
getSubImage(int x, int y, int width, int height);
private:
- Image *parent;
+ Image *mParent;
};
#endif
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp
deleted file mode 100644
index 69090dcb..00000000
--- a/src/resources/iteminfo.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * The Mana World
- * Copyright 2004 The Mana World Development Team
- *
- * This file is part of The Mana World.
- *
- * The Mana World is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * The Mana World is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * $Id$
- */
-
-#include "iteminfo.h"
-
-ItemInfo::ItemInfo() :
- image(0), name(""),
- description(""), type(0),
- weight(0), slot(0)
-{
-}
-
-ItemInfo::~ItemInfo()
-{
-}
-
-void ItemInfo::setImage(short image)
-{
- this->image = image;
-}
-
-short ItemInfo::getImage()
-{
- return image;
-}
-
-void ItemInfo::setArt(short art)
-{
- this->art = art;
-}
-
-short ItemInfo::getArt()
-{
- return art;
-}
-
-void ItemInfo::setName(const std::string &name)
-{
- this->name = name;
-}
-
-std::string ItemInfo::getName()
-{
- return name;
-}
-
-void ItemInfo::setDescription(const std::string &description)
-{
- this->description = description;
-}
-
-std::string ItemInfo::getDescription()
-{
- return description;
-}
-
-void ItemInfo::setEffect(const std::string &effect)
-{
- this->effect = effect;
-}
-
-std::string ItemInfo::getEffect()
-{
- return effect;
-}
-
-void ItemInfo::setType(short type)
-{
- this->type = type;
-}
-
-short ItemInfo::getType()
-{
- return type;
-}
-
-void ItemInfo::setWeight(short weight)
-{
- this->weight = weight;
-}
-
-short ItemInfo::getWeight()
-{
- return weight;
-}
-
-void ItemInfo::setSlot(char slot)
-{
- this->slot = slot;
-}
-
-char ItemInfo::getSlot()
-{
- return slot;
-}
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index 937911af..c515fd1c 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -37,52 +37,80 @@ class ItemInfo
/**
* Constructor.
*/
- ItemInfo();
+ ItemInfo():
+ mImage(0),
+ mArt(0),
+ mType(0),
+ mWeight(0),
+ mSlot(0)
+ {
+ }
- void setImage(short image);
-
- short getImage();
-
- void setArt(short art);
-
- short getArt();
-
- void setName(const std::string &name);
-
- std::string getName();
-
- void setDescription(const std::string &description);
+ void
+ setArt(short art) { mArt = art; }
- std::string getDescription();
+ short
+ getArt() { return mArt; }
- void setEffect(const std::string &effect);
+ void
+ setName(const std::string &name) { mName = name; }
- std::string getEffect();
+ std::string
+ getName() { return mName; }
- void setType(short type);
+ void
+ setImage(short image) { mImage = image; }
- short getType();
-
- void setWeight(short weight);
+ short
+ getImage() { return mImage; }
- short getWeight();
-
- void setSlot(char slot);
-
- char getSlot();
+ void
+ setDescription(const std::string &description)
+ {
+ mDescription = description;
+ }
+
+ std::string
+ getDescription() { return mDescription; }
+
+ void
+ setEffect(const std::string &effect) { mEffect = effect; }
+
+ std::string
+ getEffect() { return mEffect; }
+
+ void
+ setType(short type) { mType = type; }
+
+ short
+ getType() { return mType; }
+
+ void
+ setWeight(short weight) { mWeight = weight; }
+
+ short
+ getWeight() { return mWeight; }
+
+ void
+ setSlot(char slot) { mSlot = slot; }
+
+ char
+ getSlot() { return mSlot; }
protected:
/**
* Destructor.
*/
- ~ItemInfo();
-
- short image, art;
- std::string name;
- std::string description;
- std::string effect;
- short type, weight;
- char slot;
+ ~ItemInfo() {}
+
+ short mImage;
+ short mArt;
+ std::string mName;
+ std::string mDescription;
+ std::string mEffect;
+ short mType;
+ short mWeight;
+ char mSlot;
};
#endif
diff --git a/src/resources/music.cpp b/src/resources/music.cpp
index ba9f6df7..09e2752a 100644
--- a/src/resources/music.cpp
+++ b/src/resources/music.cpp
@@ -24,19 +24,20 @@
#include "music.h"
Music::Music(const std::string &idPath, Mix_Chunk *music):
- Resource(idPath), music(music)
+ Resource(idPath),
+ mChunk(music),
+ mChannel(-1)
{
- channel = -1;
}
Music::~Music()
{
//Mix_FreeMusic(music);
- Mix_FreeChunk(music);
- music = NULL;
+ Mix_FreeChunk(mChunk);
}
-Music* Music::load(void* buffer, unsigned int bufferSize, const std::string &idPath)
+Music*
+Music::load(void *buffer, unsigned int bufferSize, const std::string &idPath)
{
// Load the raw file data from the buffer in an RWops structure
SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize);
@@ -44,39 +45,41 @@ Music* Music::load(void* buffer, unsigned int bufferSize, const std::string &idP
// Use Mix_LoadMUS to load the raw music data
//Mix_Music* music = Mix_LoadMUS_RW(rw); Need to be implemeted
Mix_Chunk *tmpMusic = Mix_LoadWAV_RW(rw, 0);
-
+
// Now free the SDL_RWops data
SDL_FreeRW(rw);
return new Music(idPath, tmpMusic);
}
-bool Music::play(int loops)
+bool
+Music::play(int loops)
{
/*
* Warning: loops should be always set to -1 (infinite) with current
* implementation to avoid halting the playback of other samples
*/
-
+
/*if (Mix_PlayMusic(music, loops))
return true;*/
- Mix_VolumeChunk(music, 120);
- channel = Mix_PlayChannel(-1, music, loops);
- if (channel != -1)
- return true;
- return false;
+ Mix_VolumeChunk(mChunk, 120);
+ mChannel = Mix_PlayChannel(-1, mChunk, loops);
+
+ return mChannel != -1;
}
-bool Music::stop()
+void
+Music::stop()
{
/*
* Warning: very dungerous trick, it could try to stop channels occupied
* by samples rather than the current music file
*/
-
+
//Mix_HaltMusic();
- if (channel != -1)
- Mix_HaltChannel(channel);
- // Never fails
- return true;
+
+ if (mChannel != -1)
+ {
+ Mix_HaltChannel(mChannel);
+ }
}
diff --git a/src/resources/music.h b/src/resources/music.h
index 4858eb86..9cf75928 100644
--- a/src/resources/music.h
+++ b/src/resources/music.h
@@ -48,7 +48,8 @@ class Music : public Resource
* @return <code>NULL</code> if the an error occurred, a valid pointer
* otherwise.
*/
- static Music *load(void* buffer, unsigned int bufferSize, const std::string &idPath);
+ static Music*
+ load(void* buffer, unsigned int bufferSize, const std::string &idPath);
/**
* Plays the music.
@@ -58,15 +59,14 @@ class Music : public Resource
* @return <code>true</code> if the playback started properly
* <code>false</code> otherwise.
*/
- virtual bool play(int loops);
+ virtual bool
+ play(int loops);
/**
* Stops the music.
- *
- * @return <code>true</code> if the playback was stopped properly
- * <code>false</code> otherwise.
*/
- virtual bool stop();
+ virtual void
+ stop();
protected:
/**
@@ -75,8 +75,8 @@ class Music : public Resource
Music(const std::string &idPath, Mix_Chunk *music);
//Mix_Music *music;
- Mix_Chunk *music;
- int channel;
+ Mix_Chunk *mChunk;
+ int mChannel;
};
#endif
diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp
index 7c77d5b7..3340e5ea 100644
--- a/src/resources/soundeffect.cpp
+++ b/src/resources/soundeffect.cpp
@@ -24,34 +24,36 @@
#include "soundeffect.h"
SoundEffect::SoundEffect(const std::string &idPath, Mix_Chunk *soundEffect):
- Resource(idPath), soundEffect(soundEffect)
+ Resource(idPath),
+ mChunk(soundEffect)
{
}
SoundEffect::~SoundEffect()
{
- Mix_FreeChunk(soundEffect);
- soundEffect = NULL;
+ Mix_FreeChunk(mChunk);
}
-SoundEffect* SoundEffect::load(void* buffer, unsigned int bufferSize, const std::string &idPath)
+SoundEffect*
+SoundEffect::load(void *buffer, unsigned int bufferSize,
+ const std::string &idPath)
{
// Load the raw file data from the buffer in an RWops structure
SDL_RWops *rw = SDL_RWFromMem(buffer, bufferSize);
// Use Mix_LoadWAV_RW to load the raw music data
Mix_Chunk *tmpSoundEffect = Mix_LoadWAV_RW(rw, 0);
-
+
// Now free the SDL_RWops data
SDL_FreeRW(rw);
return new SoundEffect(idPath, tmpSoundEffect);
}
-bool SoundEffect::play(int loops, int volume)
+bool
+SoundEffect::play(int loops, int volume)
{
- Mix_VolumeChunk(soundEffect, volume);
- if (Mix_PlayChannel(-1, soundEffect, loops) != -1)
- return true;
- return false;
+ Mix_VolumeChunk(mChunk, volume);
+
+ return Mix_PlayChannel(-1, mChunk, loops) != -1;
}
diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h
index bd1c3c00..92b0016a 100644
--- a/src/resources/soundeffect.h
+++ b/src/resources/soundeffect.h
@@ -37,7 +37,8 @@ class SoundEffect : public Resource
/**
* Destructor.
*/
- virtual ~SoundEffect();
+ virtual
+ ~SoundEffect();
/**
* Loads a sample from a buffer in memory.
@@ -48,8 +49,8 @@ class SoundEffect : public Resource
* @return <code>NULL</code> if the an error occurred, a valid pointer
* otherwise.
*/
- static SoundEffect *load(void* buffer, unsigned int bufferSize,
- const std::string &idPath);
+ static SoundEffect*
+ load(void* buffer, unsigned int bufferSize, const std::string &idPath);
/**
* Plays the sample.
@@ -60,7 +61,8 @@ class SoundEffect : public Resource
* @return <code>true</code> if the playback started properly
* <code>false</code> otherwise.
*/
- virtual bool play(int loops, int volume);
+ virtual bool
+ play(int loops, int volume);
protected:
/**
@@ -68,7 +70,7 @@ class SoundEffect : public Resource
*/
SoundEffect(const std::string &idPath, Mix_Chunk *soundEffect);
- Mix_Chunk *soundEffect;
+ Mix_Chunk *mChunk;
};
#endif
diff --git a/src/sound.cpp b/src/sound.cpp
index 7bbe36e7..f4b2a3ed 100644
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -76,7 +76,7 @@ void Sound::info()
SDL_version compiledVersion;
const SDL_version *linkedVersion;
char driver[40] = "Unknown";
- char *format = "Unknown";
+ const char *format = "Unknown";
int rate = 0;
Uint16 audioFormat = 0;
int channels = 0;
diff --git a/src/sprite.h b/src/sprite.h
index 97851138..2950f4e8 100644
--- a/src/sprite.h
+++ b/src/sprite.h
@@ -24,23 +24,20 @@
#ifndef _TMW_SPRITE_H_
#define _TMW_SPRITE_H_
-#include "graphics.h"
+class Graphics;
/**
- * A sprite is some visible object on a map.
+ * A sprite is some visible object on a map. This abstract class defines the
+ * interface used by the map to sort and display the sprite.
*/
class Sprite
{
public:
/**
- * Constructor.
+ * Destructor.
*/
- Sprite(int x = 0, int y = 0, Image *image = NULL):
- mX(x),
- mY(y),
- mImage(image)
- {
- }
+ virtual
+ ~Sprite() {}
/**
* Draws the sprite to the given graphics context.
@@ -49,28 +46,20 @@ class Sprite
* would support setting a translation offset. It already does this
* partly with the clipping rectangle support.
*/
- void
- draw(Graphics *graphics, int offsetX, int offsetY)
- {
- graphics->drawImage(mImage, mX + offsetX, mY + offsetY);
- }
+ virtual void
+ draw(Graphics *graphics, int offsetX, int offsetY) = 0;
/**
- * Returns the X coordinate of the sprite.
+ * Returns the pixel Y coordinate of the sprite.
*/
- int
- getY() const { return mY; }
+ virtual int
+ getPixelY() const = 0;
+ protected:
/**
- * Returns the Y coordinate of the sprite.
+ * Constructor.
*/
- int
- getX() const { return mX; }
-
- private:
- int mX; /**< X coordinate in pixels. */
- int mY; /**< Y coordinate in pixels. */
- Image *mImage; /**< The image currently representing this sprite. */
+ Sprite() {}
};
#endif