summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-01-04 02:20:38 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-01-04 02:20:38 +0000
commit4eec29ac0f6a9b05562ac0fbe3d4e5d7e82deeac (patch)
tree0b18ed6970f8fdd6750459e6f9032e444d253580 /src
parente160ba567bf3d2ae915e67c12c13e213c1a32a62 (diff)
downloadmana-4eec29ac0f6a9b05562ac0fbe3d4e5d7e82deeac.tar.gz
mana-4eec29ac0f6a9b05562ac0fbe3d4e5d7e82deeac.tar.bz2
mana-4eec29ac0f6a9b05562ac0fbe3d4e5d7e82deeac.tar.xz
mana-4eec29ac0f6a9b05562ac0fbe3d4e5d7e82deeac.zip
Merged 0.0 changes from revision 2898 to 2988 to trunk.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt12
-rw-r--r--src/Makefile.am12
-rw-r--r--src/animatedsprite.cpp6
-rw-r--r--src/animatedsprite.h9
-rw-r--r--src/being.cpp33
-rw-r--r--src/being.h1
-rw-r--r--src/engine.cpp32
-rw-r--r--src/engine.h9
-rw-r--r--src/game.cpp4
-rw-r--r--src/gui/buy.cpp57
-rw-r--r--src/gui/chargedialog.cpp1
-rw-r--r--src/gui/listbox.cpp7
-rw-r--r--src/gui/listbox.h4
-rw-r--r--src/gui/sell.cpp3
-rw-r--r--src/gui/shop.cpp2
-rw-r--r--src/gui/shoplistbox.cpp142
-rw-r--r--src/gui/shoplistbox.h20
-rw-r--r--src/gui/updatewindow.cpp175
-rw-r--r--src/gui/updatewindow.h9
-rw-r--r--src/gui/viewport.cpp4
-rw-r--r--src/guichanfwd.h5
-rw-r--r--src/inventory.h7
-rw-r--r--src/localplayer.cpp19
-rw-r--r--src/localplayer.h17
-rw-r--r--src/main.cpp20
-rw-r--r--src/main.h3
-rw-r--r--src/net/playerhandler.cpp16
-rw-r--r--src/npc.cpp1
-rw-r--r--src/resources/action.cpp (renamed from src/action.cpp)3
-rw-r--r--src/resources/action.h (renamed from src/action.h)0
-rw-r--r--src/resources/animation.cpp (renamed from src/animation.cpp)14
-rw-r--r--src/resources/animation.h (renamed from src/animation.h)16
-rw-r--r--src/resources/equipmentdb.cpp3
-rw-r--r--src/resources/image.cpp6
-rw-r--r--src/resources/itemdb.cpp8
-rw-r--r--src/resources/itemdb.h6
-rw-r--r--src/resources/mapreader.cpp2
-rw-r--r--src/resources/monsterdb.cpp8
-rw-r--r--src/resources/openglsdlimageloader.cpp3
-rw-r--r--src/resources/openglsdlimageloader.h3
-rw-r--r--src/resources/spritedef.cpp37
-rw-r--r--src/resources/spritedef.h3
-rw-r--r--src/resources/spriteset.cpp2
-rw-r--r--src/tmw.rc41
-rw-r--r--src/utils/base64.cpp (renamed from src/base64.cpp)0
-rw-r--r--src/utils/base64.h (renamed from src/base64.h)0
-rw-r--r--src/utils/wingettimeofday.h8
-rw-r--r--src/winver.h6
48 files changed, 409 insertions, 390 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e0b93382..55109ec4 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -214,10 +214,14 @@ SET(SRCS
net/gameserver/internal.h
net/gameserver/player.cpp
net/gameserver/player.h
+ resources/action.cpp
+ resources/action.h
resources/ambientoverlay.cpp
resources/ambientoverlay.h
resources/buddylist.cpp
resources/buddylist.h
+ resources/animation.cpp
+ resources/animation.h
resources/equipmentdb.cpp
resources/equipmentdb.h
resources/equipmentinfo.h
@@ -251,18 +255,14 @@ SET(SRCS
resources/spritedef.h
resources/spritedef.cpp
resources/spriteset.h
+ utils/base64.cpp
+ utils/base64.h
utils/dtor.h
utils/tostring.h
utils/xml.cpp
utils/xml.h
- action.cpp
- action.h
animatedsprite.cpp
animatedsprite.h
- animation.cpp
- animation.h
- base64.cpp
- base64.h
being.cpp
being.h
beingmanager.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 1628df18..777cc30e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -179,8 +179,12 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \
net/gameserver/internal.h \
net/gameserver/player.cpp \
net/gameserver/player.h \
+ resources/action.cpp \
+ resources/action.h \
resources/ambientoverlay.cpp \
resources/ambientoverlay.h \
+ resources/animation.cpp \
+ resources/animation.h \
resources/equipmentdb.cpp \
resources/equipmentdb.h \
resources/equipmentinfo.h \
@@ -216,18 +220,14 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \
resources/spriteset.cpp \
resources/buddylist.h \
resources/buddylist.cpp \
+ utils/base64.cpp \
+ utils/base64.h \
utils/dtor.h \
utils/tostring.h \
utils/xml.cpp \
utils/xml.h \
- action.cpp \
- action.h \
animatedsprite.cpp \
animatedsprite.h \
- animation.cpp \
- animation.h \
- base64.cpp \
- base64.h \
being.cpp \
being.h \
beingmanager.cpp \
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index 46369c80..3d1979a9 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -23,14 +23,14 @@
#include "animatedsprite.h"
-#include "animation.h"
-#include "action.h"
#include "graphics.h"
#include "log.h"
+#include "resources/action.h"
+#include "resources/animation.h"
+#include "resources/image.h"
#include "resources/resourcemanager.h"
#include "resources/spriteset.h"
-#include "resources/image.h"
#include "utils/xml.h"
diff --git a/src/animatedsprite.h b/src/animatedsprite.h
index 4e485f14..2257c0f0 100644
--- a/src/animatedsprite.h
+++ b/src/animatedsprite.h
@@ -29,8 +29,9 @@
#include <map>
#include <string>
+class Animation;
class Graphics;
-struct AnimationPhase;
+struct Frame;
/**
* Animates a sprite by adding playback state.
@@ -72,13 +73,13 @@ class AnimatedSprite
/**
* Inform the animation of the passed time so that it can output the
- * correct animation phase.
+ * correct animation frame.
*/
void
update(int time);
/**
- * Draw the current animation phase at the coordinates given in screen
+ * Draw the current animation frame at the coordinates given in screen
* pixels.
*/
bool
@@ -103,7 +104,7 @@ class AnimatedSprite
SpriteDef *mSprite; /**< The sprite definition. */
Action *mAction; /**< The currently active action. */
Animation *mAnimation; /**< The currently active animation. */
- AnimationPhase *mFrame; /**< The currently active frame. */
+ Frame *mFrame; /**< The currently active frame. */
std::string mAnimationFile;
};
diff --git a/src/being.cpp b/src/being.cpp
index 68c670fd..ac003d1c 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -65,7 +65,6 @@ Being::Being(Uint16 id, Uint16 job, Map *map):
mHairStyle(0), mHairColor(0),
mSpeechTime(0),
mDamageTime(0),
- mShowSpeech(false), mShowDamage(false),
mPx(0), mPy(0),
mSprites(VECTOREND_SPRITE, NULL),
mEquipmentSpriteIDs(VECTOREND_SPRITE, 0)
@@ -272,16 +271,14 @@ void
Being::setSpeech(const std::string &text, Uint32 time)
{
mSpeech = text;
- mSpeechTime = tick_time;
- mShowSpeech = true;
+ mSpeechTime = 500;
}
void
Being::setDamage(Sint16 amount, Uint32 time)
{
mDamage = amount ? toString(amount) : "miss";
- mDamageTime = tick_time;
- mShowDamage = true;
+ mDamageTime = 300;
}
void
@@ -443,17 +440,13 @@ Being::logic()
nextStep();
}
- // Determine whether speech should still be displayed
- if (get_elapsed_time(mSpeechTime) > 5000)
- {
- mShowSpeech = false;
- }
+ // Reduce the time that speech is still displayed
+ if (mSpeechTime > 0)
+ mSpeechTime--;
- // Determine whether damage should still be displayed
- if (get_elapsed_time(mDamageTime) > 3000)
- {
- mShowDamage = false;
- }
+ // Reduce the time that damage is still displayed
+ if (mDamageTime > 0)
+ mDamageTime--;
// Update pixel coordinates
mPx = mX - 16 + getXOffset();
@@ -511,7 +504,7 @@ Being::drawSpeech(Graphics *graphics, Sint32 offsetX, Sint32 offsetY)
int py = mPy + offsetY;
// Draw speech above this being
- if (mShowSpeech)
+ if (mSpeechTime > 0)
{
graphics->setFont(speechFont);
graphics->setColor(gcn::Color(255, 255, 255));
@@ -519,7 +512,7 @@ Being::drawSpeech(Graphics *graphics, Sint32 offsetX, Sint32 offsetY)
}
// Draw damage above this being
- if (mShowDamage && get_elapsed_time(mDamageTime) > 250)
+ if (mDamageTime > 0 && mDamageTime < 275)
{
// Selecting the right color
if (mDamage == "miss")
@@ -536,13 +529,13 @@ Being::drawSpeech(Graphics *graphics, Sint32 offsetX, Sint32 offsetY)
}
int textY = (getType() == MONSTER) ? 32 : 70;
- int ft = get_elapsed_time(mDamageTime) - 1500;
- float a = (ft > 0) ? 1.0 - ft / 1500.0 : 1.0;
+ int ft = 150 - mDamageTime;
+ float a = (ft > 0) ? 1.0 - ft / 150.0 : 1.0;
graphics->setColor(gcn::Color(255, 255, 255, (int)(255 * a)));
graphics->drawText(mDamage,
px + 16,
- py - textY - get_elapsed_time(mDamageTime) / 100,
+ py - textY - (300 - mDamageTime) / 10,
gcn::Graphics::CENTER);
// Reset alpha value
diff --git a/src/being.h b/src/being.h
index f9287b65..bfd01568 100644
--- a/src/being.h
+++ b/src/being.h
@@ -368,7 +368,6 @@ class Being : public Sprite
Uint16 mHairStyle, mHairColor;
Uint32 mSpeechTime;
Uint32 mDamageTime;
- bool mShowSpeech, mShowDamage;
Sint32 mPx, mPy; /**< Pixel coordinates */
std::vector<AnimatedSprite*> mSprites;
diff --git a/src/engine.cpp b/src/engine.cpp
index 30f0097e..d2ce6d6f 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -54,42 +54,19 @@ extern Minimap *minimap;
char itemCurrenyQ[10] = "0";
Spriteset *emotionset;
-Spriteset *npcset;
-std::vector<Spriteset *> weaponset;
Engine::Engine():
mCurrentMap(NULL)
{
- // Load the sprite sets
+ // Load the emotion set
ResourceManager *resman = ResourceManager::getInstance();
-
- npcset = resman->getSpriteset("graphics/sprites/npcs.png", 50, 80);
- emotionset = resman->getSpriteset("graphics/sprites/emotions.png",
- 30, 32);
- for (int i = 0; i < 2; i++)
- {
- Spriteset *tmp = ResourceManager::getInstance()->getSpriteset(
- "graphics/sprites/weapon" + toString(i) + ".png", 64, 64);
- if (!tmp) {
- logger->error("Unable to load weaponset");
- } else {
- weaponset.push_back(tmp);
- }
- }
-
- if (!npcset) logger->error("Unable to load NPC spriteset!");
+ emotionset = resman->getSpriteset("graphics/sprites/emotions.png", 30, 32);
if (!emotionset) logger->error("Unable to load emotions spriteset!");
}
Engine::~Engine()
{
- // Delete sprite sets
- npcset->decRef();
emotionset->decRef();
-
- std::for_each(weaponset.begin(), weaponset.end(),
- std::mem_fun(&Spriteset::decRef));
- weaponset.clear();
}
void Engine::changeMap(const std::string &mapPath)
@@ -142,8 +119,3 @@ void Engine::logic()
beingManager->logic();
gui->logic();
}
-
-void Engine::draw(Graphics *graphics)
-{
- gui->draw();
-}
diff --git a/src/engine.h b/src/engine.h
index 62e82a49..b16b7c13 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -26,11 +26,11 @@
#include <iosfwd>
-class Graphics;
class Map;
/**
- * Game engine that does the main drawing.
+ * Game engine. Actually hardly does anything anymore except keeping track of
+ * the current map and loading the emotes.
*/
class Engine
{
@@ -60,11 +60,6 @@ class Engine
*/
void logic();
- /**
- * Draws everything on the screen.
- */
- void draw(Graphics *graphics);
-
private:
Map *mCurrentMap;
};
diff --git a/src/game.cpp b/src/game.cpp
index f708fabf..2af13146 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -360,7 +360,7 @@ void Game::logic()
get_elapsed_time(mDrawTime / 10) > mMinFrameTime)
{
frame++;
- engine->draw(graphics);
+ gui->draw();
graphics->updateScreen();
mDrawTime += mMinFrameTime;
@@ -662,7 +662,7 @@ void Game::handleInput()
direction |= Being::RIGHT;
}
- player_node->walk(direction);
+ player_node->setWalkingDir(direction);
// Target the nearest monster if 'a' pressed
if (keys[SDLK_a])
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
index 9fcf752b..102dd49e 100644
--- a/src/gui/buy.cpp
+++ b/src/gui/buy.cpp
@@ -85,7 +85,6 @@ BuyDialog::BuyDialog():
mShopItemList->setEventId("item");
mSlider->setEventId("slider");
- mShopItemList->addActionListener(this);
mShopItemList->addSelectionListener(this);
mSlider->addActionListener(this);
@@ -112,7 +111,7 @@ void BuyDialog::setMoney(int amount)
{
mMoney = amount;
mShopItemList->setPlayersMoney(amount);
- mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP");
+ mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP");
mMoneyLabel->adjustSize();
}
@@ -129,7 +128,7 @@ void BuyDialog::reset()
mDecreaseButton->setEnabled(false);
mQuantityLabel->setCaption("0");
mQuantityLabel->adjustSize();
- mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP");
+ mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP");
mMoneyLabel->adjustSize();
mItemDescLabel->setCaption("");
mItemEffectLabel->setCaption("");
@@ -145,31 +144,7 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget)
{
int selectedItem = mShopItemList->getSelected();
- if (eventId == "item")
- {
- // Reset amount of items and update labels
- mAmountItems = 0;
- mSlider->setValue(0);
- mQuantityLabel->setCaption("0");
- mQuantityLabel->adjustSize();
- mMoneyLabel->setCaption("Price : 0 GP / " + toString(mMoney) + " GP");
- mMoneyLabel->adjustSize();
-
- // Disable buttons for buying and decreasing
- mBuyButton->setEnabled(false);
- mDecreaseButton->setEnabled(false);
-
- // If no item was selected, none can be bought, otherwise
- // calculate how many the player can afford
- mMaxItems = (mShopItemList->getSelected() == -1) ? 0 :
- mMoney / mShopItems->at(selectedItem).price;
-
- // When at least one item can be bought, enable the slider and the
- // increase button
- mIncreaseButton->setEnabled(mMaxItems > 0);
- mSlider->setEnabled(mMaxItems > 0);
- }
- else if (eventId == "quit")
+ if (eventId == "quit")
{
setVisible(false);
current_npc = 0;
@@ -253,7 +228,7 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget)
mQuantityLabel->adjustSize();
int price = mAmountItems * mShopItems->at(selectedItem).price;
- mMoneyLabel->setCaption("Price : " + toString(price) + " GP / "
+ mMoneyLabel->setCaption("Price: " + toString(price) + " GP / "
+ toString(mMoney) + " GP" );
mMoneyLabel->adjustSize();
}
@@ -261,19 +236,39 @@ void BuyDialog::action(const std::string &eventId, gcn::Widget *widget)
void BuyDialog::selectionChanged(const SelectionEvent &event)
{
+ // Reset amount of items and update labels
+ mAmountItems = 0;
+ mSlider->setValue(0);
+ mQuantityLabel->setCaption("0");
+ mQuantityLabel->adjustSize();
+ mMoneyLabel->setCaption("Price: 0 GP / " + toString(mMoney) + " GP");
+ mMoneyLabel->adjustSize();
+
+ // Disable buttons for buying and decreasing
+ mBuyButton->setEnabled(false);
+ mDecreaseButton->setEnabled(false);
+
int selectedItem = mShopItemList->getSelected();
if (selectedItem > -1)
{
- const ItemInfo &info =
- ItemDB::get(mShopItems->at(selectedItem).id);
+ const ItemInfo &info = ItemDB::get(mShopItems->at(selectedItem).id);
mItemDescLabel->setCaption("Description: " + info.getDescription());
mItemEffectLabel->setCaption("Effect: " + info.getEffect());
+
+ // Calculate how many the player can afford
+ mMaxItems = mMoney / mShopItems->at(selectedItem).price;
}
else
{
mItemDescLabel->setCaption("Description:");
mItemEffectLabel->setCaption("Effect:");
+ mMaxItems = 0;
}
+
+ // When at least one item can be bought, enable the slider and the
+ // increase button
+ mIncreaseButton->setEnabled(mMaxItems > 0);
+ mSlider->setEnabled(mMaxItems > 0);
}
diff --git a/src/gui/chargedialog.cpp b/src/gui/chargedialog.cpp
index 349ca223..862378ae 100644
--- a/src/gui/chargedialog.cpp
+++ b/src/gui/chargedialog.cpp
@@ -37,6 +37,7 @@ ChargeDialog::ChargeDialog():
mProgBar = new ProgressBar(0.0f, 140, 25, 128, 128, 128);
mProgBar->setPosition(20, 40);
add(mProgBar);
+ setVisible(true);
}
// update the dialog
diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp
index 14626d06..d4a2c6cb 100644
--- a/src/gui/listbox.cpp
+++ b/src/gui/listbox.cpp
@@ -38,9 +38,8 @@ ListBox::ListBox(gcn::ListModel *listModel):
void ListBox::draw(gcn::Graphics *graphics)
{
- if (mListModel == NULL) {
+ if (!mListModel)
return;
- }
graphics->setColor(gcn::Color(110, 160, 255));
graphics->setFont(getFont());
@@ -54,7 +53,9 @@ void ListBox::draw(gcn::Graphics *graphics)
}
// Draw the list elements
- for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += fontHeight)
+ for (int i = 0, y = 0;
+ i < mListModel->getNumberOfElements();
+ ++i, y += fontHeight)
{
graphics->drawText(mListModel->getElementAt(i), 1, y);
}
diff --git a/src/gui/listbox.h b/src/gui/listbox.h
index c1932f54..deca07cf 100644
--- a/src/gui/listbox.h
+++ b/src/gui/listbox.h
@@ -73,9 +73,9 @@ class ListBox : public gcn::ListBox
/**
* Sets the index of the selected element.
*/
- void setSelected(int selected);
+ virtual void setSelected(int selected);
- private:
+ protected:
/**
* Sends out selection events to the list of selection listeners.
*/
diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp
index 499bbd05..b0957f9e 100644
--- a/src/gui/sell.cpp
+++ b/src/gui/sell.cpp
@@ -142,7 +142,8 @@ void SellDialog::addItem(Item *item, int price)
ITEM_SHOP item_shop;
- item_shop.name = item->getInfo().getName() + " " + toString(price) + " GP";
+ item_shop.name = item->getInfo().getName()
+ + " (" + toString(price) + " GP)";
item_shop.price = price;
item_shop.index = item->getInvIndex();
item_shop.id = item->getId();
diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp
index 2d33e8a8..3d972bc2 100644
--- a/src/gui/shop.cpp
+++ b/src/gui/shop.cpp
@@ -45,7 +45,7 @@ void ShopItems::addItem(short id, int price)
ITEM_SHOP item_shop;
item_shop.name = ItemDB::get(id).getName()
- + " " + toString(price) + " GP";
+ + " (" + toString(price) + " GP)";
item_shop.price = price;
item_shop.id = id;
item_shop.image = ItemDB::get(id).getImage();
diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp
index 61abff35..4821067c 100644
--- a/src/gui/shoplistbox.cpp
+++ b/src/gui/shoplistbox.cpp
@@ -34,11 +34,10 @@
#include "../graphics.h"
-const int ITEM_SPRITE_HEIGHT = 32;
+const int ITEM_ICON_SIZE = 32;
ShopListBox::ShopListBox(gcn::ListModel *listModel):
- gcn::ListBox(listModel),
- mMousePressed(false),
+ ListBox(listModel),
mPlayerMoney(0)
{
mRowHeight = getFont()->getHeight();
@@ -46,105 +45,101 @@ ShopListBox::ShopListBox(gcn::ListModel *listModel):
}
ShopListBox::ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel):
- gcn::ListBox(listModel),
- mMousePressed(false),
+ ListBox(listModel),
mPlayerMoney(0),
mShopItems(shopListModel)
{
- mRowHeight = (getFont()->getHeight() > ITEM_SPRITE_HEIGHT ?
- getFont()->getHeight() : ITEM_SPRITE_HEIGHT);
+ mRowHeight = std::max(getFont()->getHeight(), ITEM_ICON_SIZE);
mPriceCheck = true;
}
-
void ShopListBox::setPlayersMoney(int money)
{
mPlayerMoney = money;
}
-void ShopListBox::draw(gcn::Graphics *graphics)
+void ShopListBox::draw(gcn::Graphics *gcnGraphics)
{
- if (mListModel == NULL) {
+ if (!mListModel)
return;
- }
+
+ Graphics *graphics = static_cast<Graphics*>(gcnGraphics);
graphics->setFont(getFont());
// Draw the list elements
- for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += mRowHeight)
+ for (int i = 0, y = 0;
+ i < mListModel->getNumberOfElements();
+ ++i, y += mRowHeight)
{
- graphics->setColor(gcn::Color(0xffffff));
- if (mShopItems != NULL)
+ gcn::Color backgroundColor = gcn::Color(0xffffff);
+
+ if (i == mSelected)
{
- if(mPlayerMoney < mShopItems->at(i).price && mPriceCheck)
- {
- graphics->setColor(gcn::Color(0x919191));
- }
+ backgroundColor = gcn::Color(110, 160, 255);
}
+ else if (mShopItems &&
+ mPlayerMoney < mShopItems->at(i).price && mPriceCheck)
+ {
+ backgroundColor = gcn::Color(0x919191);
+ }
+
+ graphics->setColor(backgroundColor);
graphics->fillRectangle(gcn::Rectangle(0, y, getWidth(), mRowHeight));
- if (mShopItems)
- dynamic_cast<Graphics*>(graphics)->drawImage(mShopItems->at(i).image, 1, y);
- graphics->drawText(mListModel->getElementAt(i), ITEM_SPRITE_HEIGHT, y);
- }
- // Draw rectangle below the selected list element and the list element
- // not shown.
- if (mSelected >= 0) {
- graphics->setColor(gcn::Color(110, 160, 255));
- graphics->fillRectangle(gcn::Rectangle(0, mRowHeight * mSelected,
- getWidth(), mRowHeight));
if (mShopItems)
- dynamic_cast<Graphics*>(graphics)->drawImage(
- mShopItems->at(mSelected).image, 1, mRowHeight * mSelected);
- graphics->drawText(mListModel->getElementAt(mSelected),
- ITEM_SPRITE_HEIGHT, mRowHeight * mSelected);
+ {
+ Image *icon = mShopItems->at(i).image;
+ if (icon)
+ {
+ graphics->drawImage(icon, 1, y);
+ }
+ }
+ graphics->drawText(mListModel->getElementAt(i), ITEM_ICON_SIZE + 5,
+ y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2);
}
}
void ShopListBox::setSelected(int selected)
{
- gcn::ListBox::setSelected(selected);
- if (mListModel != NULL)
+ if (!mListModel)
{
- gcn::BasicContainer *par = getParent();
- if (par == NULL)
- {
- return;
- }
-
- gcn::Rectangle scroll;
+ mSelected = -1;
+ }
+ else
+ {
+ // Update mSelected with bounds checking
+ mSelected = std::min(mListModel->getNumberOfElements() - 1,
+ std::max(-1, selected));
- if (mSelected < 0)
+ gcn::BasicContainer *parent = getParent();
+ if (parent)
{
- scroll.y = 0;
+ gcn::Rectangle scroll;
+ scroll.y = (mSelected < 0) ? 0 : mRowHeight * mSelected;
+ scroll.height = mRowHeight;
+ parent->showWidgetPart(this, scroll);
}
- else
- {
- scroll.y = mRowHeight * mSelected;
- }
-
- scroll.height = mRowHeight;
- par->showWidgetPart(this, scroll);
}
+
fireSelectionChangedEvent();
}
void ShopListBox::mousePress(int x, int y, int button)
{
-
- bool enoughMoney = false;
if (button == gcn::MouseInput::LEFT && hasMouse())
{
- if (mShopItems)
+ bool enoughMoney = false;
+
+ if (mShopItems && mPriceCheck)
{
- if(mPlayerMoney >= mShopItems->at(y / mRowHeight).price)
+ if (mPlayerMoney >= mShopItems->at(y / mRowHeight).price)
enoughMoney = true;
}
else // Old Behaviour
+ {
enoughMoney = true;
-
- if (!mPriceCheck)
- enoughMoney = true;
+ }
if (enoughMoney)
{
@@ -155,40 +150,9 @@ void ShopListBox::mousePress(int x, int y, int button)
}
}
-void ShopListBox::mouseRelease(int x, int y, int button)
-{
- gcn::ListBox::mouseRelease(x, y, button);
-
- mMousePressed = false;
-}
-
-void ShopListBox::mouseMotion(int x, int y)
-{
- gcn::ListBox::mouseMotion(x, y);
-
- // Pretend mouse is pressed continuously while dragged. Causes list
- // selection to be updated as is default in many GUIs.
- if (mMousePressed)
- {
- mousePress(x, y, gcn::MouseInput::LEFT);
- }
-}
-
-void ShopListBox::fireSelectionChangedEvent()
-{
- SelectionEvent event(this);
- SelectionListeners::iterator i_end = mListeners.end();
- SelectionListeners::iterator i;
-
- for (i = mListeners.begin(); i != i_end; ++i)
- {
- (*i)->selectionChanged(event);
- }
-}
-
void ShopListBox::adjustSize()
{
- if (mListModel != NULL)
+ if (mListModel)
{
setHeight(mRowHeight * mListModel->getNumberOfElements());
}
diff --git a/src/gui/shoplistbox.h b/src/gui/shoplistbox.h
index 2dff8977..476564b2 100644
--- a/src/gui/shoplistbox.h
+++ b/src/gui/shoplistbox.h
@@ -21,10 +21,10 @@
* $Id: listbox.h 2655 2006-09-03 21:25:02Z b_lindeijer $
*/
-#ifndef _TMW_LISTBOX_H
-#define _TMW_LISTBOX_H
+#ifndef _TMW_SHOPLISTBOX_H
+#define _TMW_SHOPLISTBOX_H
-#include <guichan/widgets/listbox.hpp>
+#include "listbox.h"
#include "shop.h"
class SelectionListener;
@@ -36,7 +36,7 @@ class SelectionListener;
*
* \ingroup GUI
*/
-class ShopListBox : public gcn::ListBox
+class ShopListBox : public ListBox
{
public:
/**
@@ -55,8 +55,6 @@ class ShopListBox : public gcn::ListBox
void draw(gcn::Graphics *graphics);
void mousePress(int x, int y, int button);
- void mouseRelease(int x, int y, int button);
- void mouseMotion(int x, int y);
/**
* Adds a listener to the list that's notified each time a change to
@@ -98,15 +96,6 @@ class ShopListBox : public gcn::ListBox
void setPriceCheck(bool check);
private:
- /**
- * Sends out selection events to the list of selection listeners.
- */
- void fireSelectionChangedEvent();
-
- bool mMousePressed; /**< Keeps track of mouse pressed status. */
-
- std::list<SelectionListener*> mListeners;
-
int mPlayerMoney;
/**
@@ -118,7 +107,6 @@ class ShopListBox : public gcn::ListBox
int mRowHeight; /**< Row Height */
bool mPriceCheck;
-
};
#endif
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index 73343483..73e4489e 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -26,6 +26,7 @@
#include <iostream>
#include <SDL.h>
#include <SDL_thread.h>
+#include <zlib.h>
#include <curl/curl.h>
@@ -48,9 +49,9 @@ UpdaterWindow::UpdaterWindow():
Window("Updating..."),
mThread(NULL), mMutex(NULL), mDownloadStatus(UPDATE_NEWS),
mUpdateHost(""), mCurrentFile("news.txt"), mBasePath(""),
- mStoreInMemory(true), mDownloadComplete(true), mUserCancel(false),
- mDownloadedBytes(0), mMemoryBuffer(NULL),
- mCurlError(new char[CURL_ERROR_SIZE]), mFileIndex(0)
+ mStoreInMemory(true), mDownloadComplete(true), mUserCancel(false),
+ mDownloadedBytes(0), mMemoryBuffer(NULL),
+ mCurlError(new char[CURL_ERROR_SIZE]), mLineIndex(0)
{
mCurlError[0] = 0;
@@ -83,8 +84,9 @@ UpdaterWindow::UpdaterWindow():
add(mCancelButton);
add(mPlayButton);
- mCancelButton->requestFocus();
setLocationRelativeTo(getParent());
+ setVisible(true);
+ mCancelButton->requestFocus();
mUpdateHost =
config.getValue("updatehost", "http://updates.themanaworld.org");
@@ -179,7 +181,6 @@ void UpdaterWindow::loadNews()
mMemoryBuffer = NULL;
mScrollArea->setVerticalScrollAmount(0);
- setVisible(true);
}
int UpdaterWindow::updateProgress(void *ptr,
@@ -227,78 +228,116 @@ size_t UpdaterWindow::memoryWrite(void *ptr,
int UpdaterWindow::downloadThread(void *ptr)
{
+ int attempts = 0;
+ UpdaterWindow *uw = reinterpret_cast<UpdaterWindow *>(ptr);
CURL *curl;
CURLcode res;
- FILE *outfile = NULL;
- UpdaterWindow *uw = reinterpret_cast<UpdaterWindow *>(ptr);
std::string outFilename;
std::string url(uw->mUpdateHost + "/" + uw->mCurrentFile);
- uw->setLabel(uw->mCurrentFile + " (0%)");
- curl = curl_easy_init();
+ while (attempts < 3 && !uw->mDownloadComplete) {
+ FILE *outfile = NULL;
+ uw->setLabel(uw->mCurrentFile + " (0%)");
- if (curl)
- {
- logger->log("Downloading: %s", url.c_str());
+ curl = curl_easy_init();
- if (uw->mStoreInMemory)
+ if (curl)
{
- uw->mDownloadedBytes = 0;
- curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
- UpdaterWindow::memoryWrite);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, ptr);
- }
- else
- {
- // Download in the proper folder : ./updates under win,
- // /home/user/.tmw/updates for unices
- outFilename = uw->mBasePath + "/updates/download.temp";
- outfile = fopen(outFilename.c_str(), "wb");
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
- }
+ logger->log("Downloading: %s", url.c_str());
- curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, uw->mCurlError);
- curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
- curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
- curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION,
- UpdaterWindow::updateProgress);
- curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, ptr);
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15);
+ if (uw->mStoreInMemory)
+ {
+ uw->mDownloadedBytes = 0;
+ curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
+ UpdaterWindow::memoryWrite);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, ptr);
+ }
+ else
+ {
+ // Download in the proper folder : ./updates under win,
+ // /home/user/.tmw/updates for unices
+ outFilename = uw->mBasePath + "/updates/download.temp";
+ outfile = fopen(outFilename.c_str(), "w+b");
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
+ }
- if ((res = curl_easy_perform(curl)) != 0)
- {
- uw->mDownloadStatus = UPDATE_ERROR;
- switch (res)
+ curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, uw->mCurlError);
+ curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
+ curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
+ curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION,
+ UpdaterWindow::updateProgress);
+ curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, ptr);
+ curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
+ curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15);
+
+ if ((res = curl_easy_perform(curl)) != 0)
{
- case CURLE_COULDNT_CONNECT: // give more debug info on that error
- std::cerr << "curl error " << res << " : " << uw->mCurlError << " " << url.c_str()
- << std::endl;
- break;
-
- default:
- std::cerr << "curl error " << res << " : " << uw->mCurlError << " host: " << url.c_str()
- << std::endl;
+ uw->mDownloadStatus = UPDATE_ERROR;
+ switch (res)
+ {
+ case CURLE_COULDNT_CONNECT: // give more debug info on that error
+ std::cerr << "curl error " << res << " : " << uw->mCurlError << " " << url.c_str()
+ << std::endl;
+ break;
+
+ default:
+ std::cerr << "curl error " << res << " : " << uw->mCurlError << " host: " << url.c_str()
+ << std::endl;
+ }
}
- }
- curl_easy_cleanup(curl);
- uw->mDownloadComplete = true;
+ curl_easy_cleanup(curl);
- if (!uw->mStoreInMemory)
- {
- fclose(outfile);
+ uw->mDownloadComplete = true;
- // Give the file the proper name
- std::string newName(uw->mBasePath + "/updates/" +
- uw->mCurrentFile.c_str());
+ if (!uw->mStoreInMemory)
+ {
+ long fileSize;
+ char *buffer;
+ // Obtain file size.
+ fseek(outfile, 0, SEEK_END);
+ fileSize = ftell(outfile);
+ rewind(outfile);
+ buffer = (char*)malloc(fileSize);
+ fread(buffer, 1, fileSize, outfile);
+ fclose(outfile);
+
+ // Give the file the proper name
+ std::string newName(uw->mBasePath + "/updates/" +
+ uw->mCurrentFile.c_str());
+
+ // Any existing file with this name is deleted first, otherwise the
+ // rename will fail on Windows.
+ ::remove(newName.c_str());
+ ::rename(outFilename.c_str(), newName.c_str());
+
+ // Don't check resources2.txt checksum
+ if (uw->mDownloadStatus == UPDATE_RESOURCES)
+ {
+ // Calculate Adler-32 checksum
+ unsigned long adler = adler32(0L, Z_NULL, 0);
+ adler = adler32(adler, (Bytef *)buffer, fileSize);
+ free(buffer);
+
+ if (uw->mCurrentChecksum != adler) {
+ uw->mDownloadComplete = false;
+ // Remove the corrupted file
+ ::remove(newName.c_str());
+ logger->log(
+ "Checksum for file %s failed: (%lx/%lx)",
+ uw->mCurrentFile.c_str(),
+ adler, uw->mCurrentChecksum);
+ }
+ }
- // Any existing file with this name is deleted first, otherwise the
- // rename will fail on Windows.
- ::remove(newName.c_str());
- ::rename(outFilename.c_str(), newName.c_str());
+ }
}
+ attempts++;
+ }
+
+ if (!uw->mDownloadComplete) {
+ uw->mDownloadStatus = UPDATE_ERROR;
}
return 0;
@@ -351,7 +390,7 @@ void UpdaterWindow::logic()
// Parse current memory buffer as news and dispose of the data
loadNews();
- mCurrentFile = "resources.txt";
+ mCurrentFile = "resources2.txt";
mStoreInMemory = false;
download();
mDownloadStatus = UPDATE_LIST;
@@ -361,7 +400,7 @@ void UpdaterWindow::logic()
if (mDownloadComplete)
{
ResourceManager *resman = ResourceManager::getInstance();
- mFiles = resman->loadTextFile("updates/resources.txt");
+ mLines = resman->loadTextFile("updates/resources2.txt");
mStoreInMemory = false;
mDownloadStatus = UPDATE_RESOURCES;
}
@@ -375,9 +414,15 @@ void UpdaterWindow::logic()
mThread = NULL;
}
- if (mFileIndex < mFiles.size())
+ if (mLineIndex < mLines.size())
{
- mCurrentFile = mFiles[mFileIndex];
+ std::stringstream line(mLines[mLineIndex]);
+ line >> mCurrentFile;
+ std::string checksum;
+ line >> checksum;
+ std::stringstream ss(checksum);
+ ss >> std::hex >> mCurrentChecksum;
+
std::ifstream temp(
(mBasePath + "/updates/" + mCurrentFile).c_str());
if (!temp.is_open())
@@ -389,7 +434,7 @@ void UpdaterWindow::logic()
{
logger->log("%s already here", mCurrentFile.c_str());
}
- mFileIndex++;
+ mLineIndex++;
}
else
{
diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h
index 16442656..0d1493ee 100644
--- a/src/gui/updatewindow.h
+++ b/src/gui/updatewindow.h
@@ -141,6 +141,11 @@ class UpdaterWindow : public Window, public gcn::ActionListener
std::string mCurrentFile;
/**
+ * The Adler32 checksum of the file currently downloading.
+ */
+ unsigned long mCurrentChecksum;
+
+ /**
* Absolute path to locally save downloaded files.
*/
std::string mBasePath;
@@ -179,12 +184,12 @@ class UpdaterWindow : public Window, public gcn::ActionListener
/**
* List of files to download
*/
- std::vector<std::string> mFiles;
+ std::vector<std::string> mLines;
/**
* Index of the file to be downloaded
*/
- unsigned int mFileIndex;
+ unsigned int mLineIndex;
gcn::Label *mLabel; /**< Progress bar caption. */
Button *mCancelButton; /**< Button to stop the update process. */
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 3346c07a..75a16865 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -197,8 +197,8 @@ Viewport::draw(gcn::Graphics *gcnGraphics)
}
// Draw target marker if needed
- Being *target;
- if ((target = player_node->getTarget()))
+ Being *target = player_node->getTarget();
+ if (target)
{
graphics->setFont(speechFont);
graphics->setColor(gcn::Color(255, 32, 32));
diff --git a/src/guichanfwd.h b/src/guichanfwd.h
index 5eabc783..812f3f7a 100644
--- a/src/guichanfwd.h
+++ b/src/guichanfwd.h
@@ -27,6 +27,7 @@
namespace gcn {
class ActionListener;
class AllegroGraphics;
+ class AllegroImage;
class AllegroImageLoader;
class AllegroInput;
class BasicContainer;
@@ -56,11 +57,13 @@ namespace gcn {
class MouseInput;
class MouseListener;
class OpenGLGraphics;
- class OpenGLImageLoader;
+ class OpenGLImage;
+ class OpenGLSDLImageLoader;
class RadioButton;
class Rectangle;
class ScrollArea;
class SDLGraphics;
+ class SDLImage;
class SDLImageLoader;
class SDLInput;
class Slider;
diff --git a/src/inventory.h b/src/inventory.h
index 40bcafbb..32ae393e 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -31,7 +31,14 @@ class Item;
class Inventory
{
public:
+ /**
+ * Constructor.
+ */
Inventory();
+
+ /**
+ * Destructor.
+ */
~Inventory();
/**
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index ba7b6117..8076c538 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -166,11 +166,6 @@ void LocalPlayer::pickUp(FloorItem *item)
void LocalPlayer::walk(unsigned char dir)
{
- if (mWalkingDir != dir)
- {
- mWalkingDir = dir;
- }
-
if (!mMap || !dir)
return;
@@ -237,6 +232,20 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y)
Being::setDestination(x, y);
}
+void LocalPlayer::setWalkingDir(int dir)
+{
+ if (mWalkingDir != dir)
+ {
+ mWalkingDir = dir;
+ }
+
+ // If we're not already walking, start walking.
+ if (mAction != WALK && dir)
+ {
+ walk(dir);
+ }
+}
+
void LocalPlayer::raiseAttribute(Attribute attr)
{
// XXX Convert for new server
diff --git a/src/localplayer.h b/src/localplayer.h
index 59b59812..765b7cca 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -42,9 +42,15 @@ class LocalPlayer : public Player
STR = 0, AGI, VIT, INT, DEX, LUK
};
+ /**
+ * Constructor.
+ */
LocalPlayer();
- virtual ~LocalPlayer();
+ /**
+ * Destructor.
+ */
+ ~LocalPlayer();
virtual void logic();
@@ -111,13 +117,16 @@ class LocalPlayer : public Player
*/
void setTarget(Being* target) { mTarget = target; }
- void walk(unsigned char dir);
-
/**
* Sets a new destination for this being to walk to.
*/
void setDestination(Uint16 x, Uint16 y);
+ /**
+ * Sets a new direction to keep walking in.
+ */
+ void setWalkingDir(int dir);
+
void raiseAttribute(Attribute attr);
void raiseSkill(Uint16 skillId);
@@ -151,6 +160,8 @@ class LocalPlayer : public Player
std::auto_ptr<Inventory> mInventory;
protected:
+ void walk(unsigned char dir);
+
Being *mTarget;
FloorItem *mPickUpTarget;
diff --git a/src/main.cpp b/src/main.cpp
index 90368b7d..8163cde3 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -309,11 +309,6 @@ void init_engine()
errorMessage = err;
logger->log("Warning: %s", err);
}
-
- // Load XML databases
- EquipmentDB::load();
- ItemDB::load();
- MonsterDB::load();
}
/** Clear the engine */
@@ -411,19 +406,22 @@ void parseOptions(int argc, char *argv[], Options &options)
}
/**
- * Reads the file "updates/resources.txt" and attempts to load each update
+ * Reads the file "updates/resources2.txt" and attempts to load each update
* mentioned in it.
*/
void loadUpdates()
{
- const std::string updatesFile = "updates/resources.txt";
+ const std::string updatesFile = "updates/resources2.txt";
ResourceManager *resman = ResourceManager::getInstance();
std::vector<std::string> lines = resman->loadTextFile(updatesFile);
std::string homeDir = config.getValue("homeDir", "");
for (unsigned int i = 0; i < lines.size(); ++i)
{
- resman->addToSearchPath(homeDir + "/updates/" + lines[i], false);
+ std::stringstream line(lines[i]);
+ std::string filename;
+ line >> filename;
+ resman->addToSearchPath(homeDir + "/updates/" + filename, false);
}
}
@@ -687,6 +685,12 @@ int main(int argc, char *argv[])
case STATE_LOGIN:
logger->log("State: LOGIN");
+
+ // Load XML databases
+ EquipmentDB::load();
+ ItemDB::load();
+ MonsterDB::load();
+
currentDialog = new LoginDialog(&loginData);
// TODO: Restore autologin
//if (!loginData.password.empty()) {
diff --git a/src/main.h b/src/main.h
index b68a4e4d..14f52e4d 100644
--- a/src/main.h
+++ b/src/main.h
@@ -29,8 +29,7 @@
#ifdef HAVE_CONFIG_H
#include "../config.h"
#elif defined WIN32
-#include "../The_Mana_World_private.h"
-#define PACKAGE_VERSION PRODUCT_VERSION
+#include "winver.h"
#endif
#ifndef TMW_DATADIR
diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp
index 988a9a68..f16037cf 100644
--- a/src/net/playerhandler.cpp
+++ b/src/net/playerhandler.cpp
@@ -31,14 +31,24 @@
#include "../log.h"
#include "../npc.h"
+#include "../gui/buy.h"
#include "../gui/chat.h"
+#include "../gui/npclistdialog.h"
+#include "../gui/npc_text.h"
#include "../gui/ok_dialog.h"
+#include "../gui/sell.h"
#include "../gui/skill.h"
// TODO Move somewhere else
OkDialog *weightNotice = NULL;
OkDialog *deathNotice = NULL;
+extern NpcListDialog *npcListDialog;
+extern NpcTextDialog *npcTextDialog;
+extern BuyDialog *buyDialog;
+extern SellDialog *sellDialog;
+extern Window *buySellDialog;
+
/**
* Listener used for handling the overweigth message.
*/
@@ -64,6 +74,12 @@ namespace {
{
player_node->revive();
deathNotice = NULL;
+ npcListDialog->setVisible(false);
+ npcTextDialog->setVisible(false);
+ buyDialog->setVisible(false);
+ sellDialog->setVisible(false);
+ buySellDialog->setVisible(false);
+ current_npc = 0;
}
} deathListener;
}
diff --git a/src/npc.cpp b/src/npc.cpp
index 3c142889..ccd085b6 100644
--- a/src/npc.cpp
+++ b/src/npc.cpp
@@ -29,7 +29,6 @@
#include "gui/gui.h"
class Spriteset;
-extern Spriteset *npcset;
NPC *current_npc = 0;
diff --git a/src/action.cpp b/src/resources/action.cpp
index 148ea105..247455db 100644
--- a/src/action.cpp
+++ b/src/resources/action.cpp
@@ -26,7 +26,8 @@
#include <algorithm>
#include "animation.h"
-#include "utils/dtor.h"
+
+#include "../utils/dtor.h"
Action::Action()
diff --git a/src/action.h b/src/resources/action.h
index 8d5e8d11..8d5e8d11 100644
--- a/src/action.h
+++ b/src/resources/action.h
diff --git a/src/animation.cpp b/src/resources/animation.cpp
index 67fdae11..de96525c 100644
--- a/src/animation.cpp
+++ b/src/resources/animation.cpp
@@ -25,7 +25,7 @@
#include <algorithm>
-#include "utils/dtor.h"
+#include "../utils/dtor.h"
Animation::Animation():
mDuration(0)
@@ -33,23 +33,21 @@ Animation::Animation():
}
void
-Animation::addPhase(Image *image, unsigned int delay, int offsetX, int offsetY)
+Animation::addFrame(Image *image, unsigned int delay, int offsetX, int offsetY)
{
- // Add new phase to animation list
- AnimationPhase newPhase = { image, delay, offsetX, offsetY };
-
- mAnimationPhases.push_back(newPhase);
+ Frame frame = { image, delay, offsetX, offsetY };
+ mFrames.push_back(frame);
mDuration += delay;
}
void
Animation::addTerminator()
{
- addPhase(NULL, 0, 0, 0);
+ addFrame(NULL, 0, 0, 0);
}
bool
-Animation::isTerminator(const AnimationPhase candidate)
+Animation::isTerminator(const Frame &candidate)
{
return (candidate.image == NULL);
}
diff --git a/src/animation.h b/src/resources/animation.h
index 85e950d7..54142bcb 100644
--- a/src/animation.h
+++ b/src/resources/animation.h
@@ -33,10 +33,8 @@ class Spriteset;
/**
* A single frame in an animation, with a delay and an offset.
- *
- * TODO: Rename this struct to Frame
*/
-struct AnimationPhase
+struct Frame
{
Image *image;
unsigned int delay;
@@ -60,7 +58,7 @@ class Animation
* Appends a new animation at the end of the sequence
*/
void
- addPhase(Image *image, unsigned int delay, int offsetX, int offsetY);
+ addFrame(Image *image, unsigned int delay, int offsetX, int offsetY);
/**
* Appends an animation terminator that states that the animation
@@ -72,14 +70,14 @@ class Animation
/**
* Returns the frame at the specified index.
*/
- AnimationPhase*
- getFrame(int index) { return &(mAnimationPhases[index]); }
+ Frame*
+ getFrame(int index) { return &(mFrames[index]); }
/**
* Returns the length of this animation in frames.
*/
unsigned int
- getLength() const { return mAnimationPhases.size(); }
+ getLength() const { return mFrames.size(); }
/**
* Returns the duration of this animation.
@@ -91,10 +89,10 @@ class Animation
* Determines whether the given animation frame is a terminator.
*/
static bool
- isTerminator(const AnimationPhase phase);
+ isTerminator(const Frame &phase);
protected:
- std::vector<AnimationPhase> mAnimationPhases;
+ std::vector<Frame> mFrames;
int mDuration;
};
diff --git a/src/resources/equipmentdb.cpp b/src/resources/equipmentdb.cpp
index 78ae3b6a..52a9fbd3 100644
--- a/src/resources/equipmentdb.cpp
+++ b/src/resources/equipmentdb.cpp
@@ -40,6 +40,9 @@ namespace
void
EquipmentDB::load()
{
+ if (mLoaded)
+ return;
+
logger->log("Initializing equipment database...");
mUnknown.setSprite("error.xml", 0);
mUnknown.setSprite("error.xml", 1);
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 48818f6f..9398e06b 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -153,10 +153,10 @@ Image* Image::load(void *buffer, unsigned int bufferSize,
SDL_FreeSurface(image);
if (hasPink && !hasAlpha) {
- SDL_SetColorKey(tmpImage, SDL_SRCCOLORKEY | SDL_RLEACCEL,
+ SDL_SetColorKey(tmpImage, SDL_SRCCOLORKEY,
SDL_MapRGB(tmpImage->format, 255, 0, 255));
} else if (hasAlpha) {
- SDL_SetAlpha(tmpImage, SDL_SRCALPHA | SDL_RLEACCEL, SDL_ALPHA_OPAQUE);
+ SDL_SetAlpha(tmpImage, SDL_SRCALPHA, SDL_ALPHA_OPAQUE);
}
#ifdef USE_OPENGL
@@ -305,7 +305,7 @@ void Image::setAlpha(float a)
if (mImage) {
// Set the alpha value this image is drawn at
- SDL_SetAlpha(mImage, SDL_SRCALPHA | SDL_RLEACCEL, (int)(255 * mAlpha));
+ SDL_SetAlpha(mImage, SDL_SRCALPHA, (int) (255 * mAlpha));
}
}
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index b91e34cc..f914af47 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -37,11 +37,15 @@ namespace
{
ItemDB::ItemInfos mItemInfos;
ItemInfo mUnknown;
+ bool mLoaded = false;
}
void ItemDB::load()
{
+ if (mLoaded)
+ return;
+
logger->log("Initializing item database...");
mUnknown.setName("Unknown item");
@@ -150,6 +154,8 @@ void ItemDB::load()
}
xmlFreeDoc(doc);
+
+ mLoaded = true;
}
void ItemDB::unload()
@@ -159,6 +165,8 @@ void ItemDB::unload()
delete i->second;
}
mItemInfos.clear();
+
+ mLoaded = false;
}
const ItemInfo&
diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h
index 5922984a..c080194b 100644
--- a/src/resources/itemdb.h
+++ b/src/resources/itemdb.h
@@ -29,17 +29,17 @@
#include <map>
/**
- * The namespace that holds the item information
+ * The namespace that holds the item information.
*/
namespace ItemDB
{
/**
- * Loads the item data from Items.xml
+ * Loads the item data from <code>items.xml</code>.
*/
void load();
/**
- * Frees item data
+ * Frees item data.
*/
void unload();
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 4569ced7..15a88b4d 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -30,11 +30,11 @@
#include "resourcemanager.h"
#include "image.h"
-#include "../base64.h"
#include "../log.h"
#include "../map.h"
#include "../tileset.h"
+#include "../utils/base64.h"
#include "../utils/tostring.h"
#include "../utils/xml.h"
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index fb03f6c1..e4406f9c 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -34,11 +34,15 @@ namespace
{
MonsterDB::MonsterInfos mMonsterInfos;
MonsterInfo mUnknown;
+ bool mLoaded = false;
}
void
MonsterDB::load()
{
+ if (mLoaded)
+ return;
+
mUnknown.setSprite("error.xml");
mUnknown.setName("unnamed");
@@ -123,6 +127,8 @@ MonsterDB::load()
}
mMonsterInfos[XML::getProperty(monsterNode, "id", 0)] = currentInfo;
}
+
+ mLoaded = true;
}
void
@@ -131,6 +137,8 @@ MonsterDB::unload()
for_each ( mMonsterInfos.begin(), mMonsterInfos.end(),
make_dtor(mMonsterInfos));
mMonsterInfos.clear();
+
+ mLoaded = false;
}
diff --git a/src/resources/openglsdlimageloader.cpp b/src/resources/openglsdlimageloader.cpp
index b3e1601e..68de1e19 100644
--- a/src/resources/openglsdlimageloader.cpp
+++ b/src/resources/openglsdlimageloader.cpp
@@ -31,7 +31,8 @@
#ifdef USE_OPENGL
-SDL_Surface* OpenGLSDLImageLoader::loadSDLSurface(const std::string& filename)
+SDL_Surface*
+OpenGLSDLImageLoader::loadSDLSurface(const std::string &filename)
{
ResourceManager *resman = ResourceManager::getInstance();
return resman->loadSDLSurface(filename);
diff --git a/src/resources/openglsdlimageloader.h b/src/resources/openglsdlimageloader.h
index 29be294c..b79dde15 100644
--- a/src/resources/openglsdlimageloader.h
+++ b/src/resources/openglsdlimageloader.h
@@ -31,7 +31,8 @@
class OpenGLSDLImageLoader : public gcn::OpenGLSDLImageLoader
{
protected:
- SDL_Surface* loadSDLSurface(const std::string& filename);
+ SDL_Surface*
+ loadSDLSurface(const std::string &filename);
};
#endif
diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp
index bd273b3b..feb6f8f8 100644
--- a/src/resources/spritedef.cpp
+++ b/src/resources/spritedef.cpp
@@ -23,11 +23,10 @@
#include "spritedef.h"
-#include "../animation.h"
-#include "../action.h"
-#include "../graphics.h"
#include "../log.h"
+#include "animation.h"
+#include "action.h"
#include "resourcemanager.h"
#include "spriteset.h"
#include "image.h"
@@ -208,20 +207,20 @@ SpriteDef::loadAnimation(xmlNodePtr animationNode,
Animation *animation = new Animation();
action->setAnimation(directionType, animation);
- // Get animation phases
- for (xmlNodePtr phaseNode = animationNode->xmlChildrenNode;
- phaseNode != NULL;
- phaseNode = phaseNode->next)
+ // Get animation frames
+ for (xmlNodePtr frameNode = animationNode->xmlChildrenNode;
+ frameNode != NULL;
+ frameNode = frameNode->next)
{
- int delay = XML::getProperty(phaseNode, "delay", 0);
- int offsetX = XML::getProperty(phaseNode, "offsetX", 0);
- int offsetY = XML::getProperty(phaseNode, "offsetY", 0);
+ int delay = XML::getProperty(frameNode, "delay", 0);
+ int offsetX = XML::getProperty(frameNode, "offsetX", 0);
+ int offsetY = XML::getProperty(frameNode, "offsetY", 0);
offsetY -= imageset->getHeight() - 32;
offsetX -= imageset->getWidth() / 2 - 16;
- if (xmlStrEqual(phaseNode->name, BAD_CAST "frame"))
+ if (xmlStrEqual(frameNode->name, BAD_CAST "frame"))
{
- int index = XML::getProperty(phaseNode, "index", -1);
+ int index = XML::getProperty(frameNode, "index", -1);
if (index < 0)
{
@@ -237,12 +236,12 @@ SpriteDef::loadAnimation(xmlNodePtr animationNode,
continue;
}
- animation->addPhase(img, delay, offsetX, offsetY);
+ animation->addFrame(img, delay, offsetX, offsetY);
}
- else if (xmlStrEqual(phaseNode->name, BAD_CAST "sequence"))
+ else if (xmlStrEqual(frameNode->name, BAD_CAST "sequence"))
{
- int start = XML::getProperty(phaseNode, "start", -1);
- int end = XML::getProperty(phaseNode, "end", -1);
+ int start = XML::getProperty(frameNode, "start", -1);
+ int end = XML::getProperty(frameNode, "end", -1);
if (start < 0 || end < 0)
{
@@ -261,15 +260,15 @@ SpriteDef::loadAnimation(xmlNodePtr animationNode,
continue;
}
- animation->addPhase(img, delay, offsetX, offsetY);
+ animation->addFrame(img, delay, offsetX, offsetY);
start++;
}
}
- else if (xmlStrEqual(phaseNode->name, BAD_CAST "end"))
+ else if (xmlStrEqual(frameNode->name, BAD_CAST "end"))
{
animation->addTerminator();
}
- } // for phaseNode
+ } // for frameNode
}
void
diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h
index 64414259..057129ad 100644
--- a/src/resources/spritedef.h
+++ b/src/resources/spritedef.h
@@ -32,10 +32,7 @@
#include <libxml/tree.h>
class Action;
-class Graphics;
class Spriteset;
-struct AnimationPhase;
-class Animation;
enum SpriteAction
{
diff --git a/src/resources/spriteset.cpp b/src/resources/spriteset.cpp
index 9b09f1e5..96bcef0c 100644
--- a/src/resources/spriteset.cpp
+++ b/src/resources/spriteset.cpp
@@ -53,7 +53,7 @@ Spriteset::~Spriteset()
Image*
Spriteset::get(size_type i)
{
- if (i > mSpriteset.size())
+ if (i >= mSpriteset.size())
{
logger->log("Warning: Sprite #%i does not exist in this spriteset", i);
return NULL;
diff --git a/src/tmw.rc b/src/tmw.rc
index 5a3b1649..ee5f99cd 100644
--- a/src/tmw.rc
+++ b/src/tmw.rc
@@ -1,34 +1,23 @@
#include <windows.h> // include for version info constants
+#include "winver.h"
A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "data/icons/tmw-icon.ico"
-//
-// TO CHANGE VERSION INFORMATION, EDIT PROJECT OPTIONS...
-//
1 VERSIONINFO
-FILEVERSION 0,1,0,0
-PRODUCTVERSION 0,1,0,0
-FILETYPE VFT_APP
-{
- BLOCK "StringFileInfo"
- {
- BLOCK "040904E4"
- {
- VALUE "CompanyName", "The Mana World Development Team"
- VALUE "FileVersion", "0.1.0"
- VALUE "FileDescription", "The Mana World"
- VALUE "InternalName", "tmw.exe"
- VALUE "LegalCopyright", "2004-2006 (C)"
- VALUE "LegalTrademarks", ""
- VALUE "OriginalFilename", "tmw.exe"
- VALUE "ProductName", "The Mana World MMORPG"
- VALUE "ProductVersion", "0.1.0"
- }
- }
- BLOCK "VarFileInfo"
- {
- VALUE "Translation", 0x0409, 1252
- }
+FILEVERSION VER_MAJOR,VER_MINOR,VER_RELEASE,VER_BUILD
+PRODUCTVERSION VER_MAJOR,VER_MINOR,VER_RELEASE,VER_BUILD
+FILETYPE VFT_APP {
+ BLOCK "StringFileInfo" {
+ BLOCK "040904E4" {
+ VALUE "CompanyName", "The Mana World Development Team"
+ VALUE "FileVersion", PACKAGE_VERSION
+ VALUE "FileDescription", "The Mana World"
+ VALUE "LegalCopyright", "2004-2006 (C)"
+ VALUE "OriginalFilename", "tmw.exe"
+ VALUE "ProductName", "The Mana World MMORPG"
+ VALUE "ProductVersion", PACKAGE_VERSION
+ }
+ }
}
diff --git a/src/base64.cpp b/src/utils/base64.cpp
index 9a8f6356..9a8f6356 100644
--- a/src/base64.cpp
+++ b/src/utils/base64.cpp
diff --git a/src/base64.h b/src/utils/base64.h
index ff20ac53..ff20ac53 100644
--- a/src/base64.h
+++ b/src/utils/base64.h
diff --git a/src/utils/wingettimeofday.h b/src/utils/wingettimeofday.h
index 0f8b767a..a5537f39 100644
--- a/src/utils/wingettimeofday.h
+++ b/src/utils/wingettimeofday.h
@@ -1,5 +1,5 @@
/*
- * The Mana World Server
+ * The Mana World
* Copyright 2004 The Mana World Development Team
*
* This file is part of The Mana World.
@@ -17,10 +17,12 @@
* 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$
*/
-#ifndef _TMWSERV_WINGETTIMEOFDAY_H_
-#define _TMWSERV_WINGETTIMEOFDAY_H_
+#ifndef _TMW_WINGETTIMEOFDAY_H_
+#define _TMW_WINGETTIMEOFDAY_H_
#ifdef WIN32
diff --git a/src/winver.h b/src/winver.h
new file mode 100644
index 00000000..58f11bea
--- /dev/null
+++ b/src/winver.h
@@ -0,0 +1,6 @@
+/* VERSION DEFINITIONS */
+#define VER_MAJOR 0
+#define VER_MINOR 1
+#define VER_RELEASE 0
+#define VER_BUILD 0
+#define PACKAGE_VERSION "0.1.0"