diff options
author | Jan-Fabian Humann <malastare@gmx.net> | 2005-02-28 20:35:08 +0000 |
---|---|---|
committer | Jan-Fabian Humann <malastare@gmx.net> | 2005-02-28 20:35:08 +0000 |
commit | 15383fabbacec848b5735fa0f728bb6242c6ce0e (patch) | |
tree | 811d6b007cec21635caf8c7945d4384ae30c5d25 /src | |
parent | 8a21b07ae278697e401a8be25d96d5989f5aeacd (diff) | |
download | mana-15383fabbacec848b5735fa0f728bb6242c6ce0e.tar.gz mana-15383fabbacec848b5735fa0f728bb6242c6ce0e.tar.bz2 mana-15383fabbacec848b5735fa0f728bb6242c6ce0e.tar.xz mana-15383fabbacec848b5735fa0f728bb6242c6ce0e.zip |
Adding support for drop items part 2/2
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/game.cpp | 84 | ||||
-rw-r--r-- | src/graphic/graphic.cpp | 33 | ||||
-rw-r--r-- | src/graphic/graphic.h | 5 | ||||
-rw-r--r-- | src/gui/inventory.cpp | 1 |
5 files changed, 118 insertions, 7 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index d947f837..534ff962 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -94,6 +94,8 @@ tmw_SOURCES = graphic/graphic.cpp \ being.h \ configuration.cpp \ configuration.h \ + floor_item.cpp \ + floor_item.h \ game.cpp \ game.h \ log.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 3d7fa64f..c3157aab 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -24,6 +24,7 @@ #include "main.h" #include "map.h" #include "being.h" +#include "floor_item.h" #include "log.h" #include "gui/chat.h" #include "gui/gui.h" @@ -242,7 +243,54 @@ void do_input() { state = EXIT; } - + + if (keysym.sym == SDLK_g) + { + // Get the item code + + int id = 0; + id = find_floor_item_by_cor(player_node->x, player_node->y); + if (id != 0) + { + WFIFOW(0) = net_w_value(0x009f); + WFIFOL(2) = net_l_value(id); + WFIFOSET(6); + } + else { + switch (player_node->direction) { + case NORTH: + id = find_floor_item_by_cor(player_node->x, player_node->y-1); + break; + case SOUTH: + id = find_floor_item_by_cor(player_node->x, player_node->y+1); + break; + case WEST: + id = find_floor_item_by_cor(player_node->x-1, player_node->y); + break; + case EAST: + id = find_floor_item_by_cor(player_node->x+1, player_node->y); + break; + case NW: + id = find_floor_item_by_cor(player_node->x-1, player_node->y-1); + break; + case NE: + id = find_floor_item_by_cor(player_node->x+1, player_node->y-1); + break; + case SW: + id = find_floor_item_by_cor(player_node->x-1, player_node->y+1); + break; + case SE: + id = find_floor_item_by_cor(player_node->x+1, player_node->y+1); + break; + default: + break; + } + WFIFOW(0) = net_w_value(0x009f); + WFIFOL(2) = net_l_value(id); + WFIFOSET(6); + } + } + if (keysym.sym == SDLK_f) { if (keysym.mod & KMOD_CTRL) @@ -406,6 +454,7 @@ void do_parse() { char *temp; char direction; Being *being = NULL; + FloorItem *floorItem = NULL; int len, n_items; // We need at least 2 bytes to identify a packet @@ -989,13 +1038,38 @@ void do_parse() { case 0x010c: chatBox->chat_log("MVP player", BY_SERVER); break; + // Item is found + case 0x009d: + floorItem = new FloorItem(); + floorItem->id = net_w_value(RFIFOW(6)); + floorItem->x = net_w_value(RFIFOW(9)); + floorItem->y = net_w_value(RFIFOW(11)); + floorItem->subx = net_b_value(RFIFOB(15)); + floorItem->suby = net_b_value(RFIFOB(16)); + floorItem->int_id = net_l_value(RFIFOL(2)); + add_floor_item(floorItem); + break; // Item drop case 0x009e: - WFIFOW(0) = net_w_value(0x009f); - WFIFOL(2) = net_l_value(RFIFOL(2)); - WFIFOSET(6); - // To be fixed or you will pick up again what you drop + floorItem = new FloorItem(); + floorItem->id = net_w_value(RFIFOW(6)); + floorItem->x = net_w_value(RFIFOW(9)); + floorItem->y = net_w_value(RFIFOW(11)); + floorItem->subx = net_b_value(RFIFOB(13)); + floorItem->suby = net_b_value(RFIFOB(14)); + floorItem->int_id = net_l_value(RFIFOL(2)); + add_floor_item(floorItem); break; + // Item disappearing + case 0x00a1: + floorItem = find_floor_item_by_id(net_l_value(RFIFOL(2))); + if (floorItem != NULL) { + remove_floor_item(net_l_value(RFIFOL(2))); + } + else { + remove_floor_item(net_l_value(RFIFOL(2))); + } + break; // Next button in NPC dialog case 0x00b5: strcpy(npc_button, "Next"); diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp index ce4bc4a1..aa27e8ba 100644 --- a/src/graphic/graphic.cpp +++ b/src/graphic/graphic.cpp @@ -29,8 +29,10 @@ #include "../gui/equipment.h" #include "../gui/newskill.h" #include "../gui/chargedialog.h" +#include "../gui/itemcontainer.h" #include "../main.h" #include "../being.h" +#include "../floor_item.h" #ifdef USE_OPENGL #include <SDL_opengl.h> #endif @@ -321,16 +323,20 @@ Engine::Engine() "core/graphics/sprites/monsters.png"); Image *weaponbitmap = resman->getImage( "core/graphics/sprites/weapons.png"); + Image *itembitmap = resman->getImage( + "core/graphics/sprites/items.png"); if (!npcbmp) error("Unable to load npcs.png"); if (!emotionbmp) error("Unable to load emotions.png"); if (!monsterbitmap) error("Unable to load monsters.png"); if (!weaponbitmap) error("Unable to load weapons.png"); + if (!itembitmap) error("Unable to load items.png"); npcset = new Spriteset(npcbmp, 50, 80); emotionset = new Spriteset(emotionbmp, 19, 19); monsterset = new Spriteset(monsterbitmap, 60, 60); weaponset = new Spriteset(weaponbitmap, 160, 120); + itemset = new Spriteset(itembitmap, 20, 20); } Engine::~Engine() @@ -353,6 +359,7 @@ Engine::~Engine() delete npcset; delete emotionset; delete weaponset; + delete itemset; } void Engine::draw() @@ -388,7 +395,33 @@ void Engine::draw() } } } + + // Draw items + std::list<FloorItem*>::iterator floorItemIterator = floorItems.begin(); + while (floorItemIterator != floorItems.end()) + { + FloorItem *floorItem = (*floorItemIterator); + unsigned short x = floorItem->x; + unsigned short y = floorItem->y; + int sx = x - camera_x; + int sy = y - camera_y; + int absx = sx * 32 - floorItem->subx - offset_x; + int absy = sy * 32 - floorItem->suby - offset_y; + /** + * subx and suby are serverside randomly generated to be + * either 3, 6, 9 or 12. + * this seems to be a finer differentiation for coordinates. + * TODO: Find a better way to implement subx and suby. + */ + if (floorItem->id >= 501 && floorItem->id <= 1202) { + itemset->spriteset[floorItem->id - 501]->draw(screen, + absx, + absy); + } + floorItemIterator++; + } + // Draw nodes std::list<Being*>::iterator beingIterator = beings.begin(); while (beingIterator != beings.end()) diff --git a/src/graphic/graphic.h b/src/graphic/graphic.h index b85c29ae..b3903c9a 100644 --- a/src/graphic/graphic.h +++ b/src/graphic/graphic.h @@ -162,8 +162,9 @@ class Graphics : public gcn::SDLGraphics { */ class Engine { private: - Spriteset *emotionset, *npcset, *monsterset, *weaponset; - + Spriteset *emotionset, *npcset, *monsterset, *weaponset, *itemset; + // Fix this number to an appropriate + public: Engine(); ~Engine(); diff --git a/src/gui/inventory.cpp b/src/gui/inventory.cpp index 23520ba2..6dfbff69 100644 --- a/src/gui/inventory.cpp +++ b/src/gui/inventory.cpp @@ -106,6 +106,7 @@ int InventoryWindow::useItem(int index, int id) { } int InventoryWindow::dropItem(int index, int quantity) { + // TODO: Fix wrong coordinates of drops, serverside? WFIFOW(0) = net_w_value(0x00a2); WFIFOW(2) = net_w_value(index); WFIFOW(4) = net_w_value(quantity); |