now is walking
This commit is contained in:
		
							parent
							
								
									651315d4cd
								
							
						
					
					
						commit
						a5cdf634b3
					
				| 
						 | 
					@ -9,6 +9,7 @@
 | 
				
			||||||
#include <script/luainterface.h>
 | 
					#include <script/luainterface.h>
 | 
				
			||||||
#include <net/connection.h>
 | 
					#include <net/connection.h>
 | 
				
			||||||
#include <../game.h>
 | 
					#include <../game.h>
 | 
				
			||||||
 | 
					#include <../item.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Engine g_engine;
 | 
					Engine g_engine;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -97,7 +98,15 @@ void Engine::run()
 | 
				
			||||||
                defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - fpsTextSize.width() - 10, 10));
 | 
					                defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - fpsTextSize.width() - 10, 10));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // todo remove. render map
 | 
					            // todo remove. render map
 | 
				
			||||||
            g_game.getMap()->draw(0, 0, g_graphics.getScreenSize().width(), g_graphics.getScreenSize().height());
 | 
					            g_game.getMap()->draw(0, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // todo remove. view items
 | 
				
			||||||
 | 
					            static Item *item = NULL;
 | 
				
			||||||
 | 
					            if(!item) {
 | 
				
			||||||
 | 
					                item = new Item();
 | 
				
			||||||
 | 
					                item->setId(8377);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            //item->draw(1, 1, 7);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            g_graphics.endRender();
 | 
					            g_graphics.endRender();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -129,4 +138,18 @@ void Engine::onResize(const Size& size)
 | 
				
			||||||
void Engine::onInputEvent(const InputEvent& event)
 | 
					void Engine::onInputEvent(const InputEvent& event)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    UIContainer::getRoot()->onInputEvent(event);
 | 
					    UIContainer::getRoot()->onInputEvent(event);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ProtocolGame *protocol = g_game.getProtocol();
 | 
				
			||||||
 | 
					    if(protocol) {
 | 
				
			||||||
 | 
					        if(event.type == EV_KEY_DOWN) {
 | 
				
			||||||
 | 
					            if(event.keycode == KC_UP)
 | 
				
			||||||
 | 
					                protocol->sendWalkNorth();
 | 
				
			||||||
 | 
					            if(event.keycode == KC_RIGHT)
 | 
				
			||||||
 | 
					                protocol->sendWalkEast();
 | 
				
			||||||
 | 
					            if(event.keycode == KC_DOWN)
 | 
				
			||||||
 | 
					                protocol->sendWalkSouth();
 | 
				
			||||||
 | 
					            if(event.keycode == KC_LEFT)
 | 
				
			||||||
 | 
					                protocol->sendWalkWest();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,6 +29,7 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    uint8* getBuffer() { return m_buffer; }
 | 
					    uint8* getBuffer() { return m_buffer; }
 | 
				
			||||||
    uint16 getMessageSize() { return m_messageSize; }
 | 
					    uint16 getMessageSize() { return m_messageSize; }
 | 
				
			||||||
 | 
					    void setMessageSize(uint16 messageSize) { m_messageSize = messageSize; }
 | 
				
			||||||
    void setWritePos(uint16 writePos) { m_writePos = writePos; }
 | 
					    void setWritePos(uint16 writePos) { m_writePos = writePos; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -125,6 +125,13 @@ void Protocol::xteaEncrypt(OutputMessage& outputMessage)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    uint16 messageLength = outputMessage.getMessageSize();
 | 
					    uint16 messageLength = outputMessage.getMessageSize();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    memmove(outputMessage.getBuffer() + OutputMessage::DATA_POS + 2, outputMessage.getBuffer() + OutputMessage::DATA_POS, messageLength);
 | 
				
			||||||
 | 
					    *(uint16*)(outputMessage.getBuffer() + OutputMessage::DATA_POS) = messageLength;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    messageLength += 2;
 | 
				
			||||||
 | 
					    outputMessage.setMessageSize(messageLength);
 | 
				
			||||||
 | 
					    outputMessage.setWritePos(messageLength + OutputMessage::DATA_POS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //add bytes until reach 8 multiple
 | 
					    //add bytes until reach 8 multiple
 | 
				
			||||||
    if((messageLength % 8) != 0) {
 | 
					    if((messageLength % 8) != 0) {
 | 
				
			||||||
        uint16 n = 8 - (messageLength % 8);
 | 
					        uint16 n = 8 - (messageLength % 8);
 | 
				
			||||||
| 
						 | 
					@ -133,7 +140,7 @@ void Protocol::xteaEncrypt(OutputMessage& outputMessage)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int readPos = 0;
 | 
					    int readPos = 0;
 | 
				
			||||||
    uint32 *buffer = (uint32*)outputMessage.getBuffer() + OutputMessage::DATA_POS;
 | 
					    uint32 *buffer = (uint32*)(outputMessage.getBuffer() + OutputMessage::DATA_POS);
 | 
				
			||||||
    while(readPos < messageLength / 4) {
 | 
					    while(readPos < messageLength / 4) {
 | 
				
			||||||
        uint32 v0 = buffer[readPos], v1 = buffer[readPos + 1];
 | 
					        uint32 v0 = buffer[readPos], v1 = buffer[readPos + 1];
 | 
				
			||||||
        uint32 delta = 0x61C88647;
 | 
					        uint32 delta = 0x61C88647;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,16 +4,21 @@
 | 
				
			||||||
#include <global.h>
 | 
					#include <global.h>
 | 
				
			||||||
#include "map.h"
 | 
					#include "map.h"
 | 
				
			||||||
#include "player.h"
 | 
					#include "player.h"
 | 
				
			||||||
 | 
					#include "protocolgame.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Game
 | 
					class Game
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
 | 
					    void setProtocol(ProtocolGame *protocolGame) { m_protocolGame = protocolGame; }
 | 
				
			||||||
 | 
					    ProtocolGame *getProtocol() { return m_protocolGame; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Map *getMap() { return &m_map; }
 | 
					    Map *getMap() { return &m_map; }
 | 
				
			||||||
    Player *getPlayer() { return &m_player; }
 | 
					    Player *getPlayer() { return &m_player; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    Map m_map;
 | 
					    Map m_map;
 | 
				
			||||||
    Player m_player;
 | 
					    Player m_player;
 | 
				
			||||||
 | 
					    ProtocolGame *m_protocolGame;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										19
									
								
								src/item.cpp
								
								
								
								
							
							
						
						
									
										19
									
								
								src/item.cpp
								
								
								
								
							| 
						 | 
					@ -50,12 +50,26 @@ Item::Item()
 | 
				
			||||||
    m_type = Thing::TYPE_ITEM;
 | 
					    m_type = Thing::TYPE_ITEM;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Item::draw(int x, int y)
 | 
					void Item::draw(int x, int y, int z)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ItemAttributes *itemAttributes = g_tibiaDat.getItemAttributes(m_id);
 | 
					    ItemAttributes *itemAttributes = g_tibiaDat.getItemAttributes(m_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int cDivX = 0, cDivY = 0, cDivZ = 0, cAnim = 0;
 | 
					    int cDivX = 0, cDivY = 0, cDivZ = 0, cAnim = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if(itemAttributes->group == ITEM_GROUP_SPLASH || itemAttributes->group == ITEM_GROUP_FLUID || itemAttributes->stackable) {
 | 
				
			||||||
 | 
					        //cDivX = subType % itemAttributes->xdiv;
 | 
				
			||||||
 | 
					        //cDivY = subType / itemAttributes->xdiv;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else if(!itemAttributes->moveable) {
 | 
				
			||||||
 | 
					        cDivX = x % itemAttributes->xdiv;
 | 
				
			||||||
 | 
					        cDivY = y % itemAttributes->ydiv;
 | 
				
			||||||
 | 
					        cDivZ = z % itemAttributes->zdiv;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    x *= 32;
 | 
				
			||||||
 | 
					    y *= 32;
 | 
				
			||||||
 | 
					    z = (7-z)*32;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for(int b = 0; b < itemAttributes->blendframes; b++) {
 | 
					    for(int b = 0; b < itemAttributes->blendframes; b++) {
 | 
				
			||||||
        for(int yi = 0; yi < itemAttributes->height; yi++) {
 | 
					        for(int yi = 0; yi < itemAttributes->height; yi++) {
 | 
				
			||||||
            for(int xi = 0; xi < itemAttributes->width; xi++) {
 | 
					            for(int xi = 0; xi < itemAttributes->width; xi++) {
 | 
				
			||||||
| 
						 | 
					@ -72,7 +86,8 @@ void Item::draw(int x, int y)
 | 
				
			||||||
                TexturePtr data = g_tibiaSpr.getSprite(itemId);
 | 
					                TexturePtr data = g_tibiaSpr.getSprite(itemId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // todo verify this to draw in correct pos (screenX, screenY)
 | 
					                // todo verify this to draw in correct pos (screenX, screenY)
 | 
				
			||||||
                g_graphics.drawTexturedRect(Rect(x - xi*32 - 32, y - yi*32 - 32, 32, 32), data, Rect(0, 0, 32, 32));
 | 
					                g_graphics.drawTexturedRect(Rect(x - xi*32 - z + 32, y - yi*32 - z + 32, 32, 32), data, Rect(0, 0, 32, 32));
 | 
				
			||||||
 | 
					                g_graphics.drawBoundingRect(Rect(x - xi*32 - z + 32, y - yi*32 - z + 32, 32, 32));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,7 +41,7 @@ class Item : virtual public Thing
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    Item();
 | 
					    Item();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void draw(int x, int y);
 | 
					    void draw(int x, int y, int z);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void setId(uint16 id) { m_id = id; }
 | 
					    void setId(uint16 id) { m_id = id; }
 | 
				
			||||||
    uint16 getId() const { return m_id; }
 | 
					    uint16 getId() const { return m_id; }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,14 +1,14 @@
 | 
				
			||||||
#include "map.h"
 | 
					#include "map.h"
 | 
				
			||||||
#include "game.h"
 | 
					#include "game.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Map::draw(int x, int y, int width, int heigth)
 | 
					void Map::draw(int x, int y)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Position playerPos = g_game.getPlayer()->getPosition();
 | 
					    Position playerPos = g_game.getPlayer()->getPosition();
 | 
				
			||||||
    for(int ix = 0; ix < 19; ++ix) {
 | 
					    for(int ix = 0; ix < 19; ++ix) {
 | 
				
			||||||
        for(int iy = 0; iy < 15; ++iy) {
 | 
					        for(int iy = 0; iy < 15; ++iy) {
 | 
				
			||||||
            if(playerPos.getZ() >= 7) {
 | 
					            if(playerPos.getZ() >= 7) {
 | 
				
			||||||
                for(int iz = 7; iz > 0; --iz) {
 | 
					                for(int iz = 7; iz > 0; --iz) {
 | 
				
			||||||
                    m_map[ix][iy][iz].draw(x+ix*32-(7-iz)*32, y+iy*32-(7-iz)*32);
 | 
					                    m_map[ix][iy][iz].draw(x+ix, y+iy, iz);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -27,6 +27,6 @@ void Map::addThing(Thing *thing, const Position& pos)
 | 
				
			||||||
    if(relativePos.getZ() >= 15)
 | 
					    if(relativePos.getZ() >= 15)
 | 
				
			||||||
        logDebug("relativePos is invalid.");
 | 
					        logDebug("relativePos is invalid.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    logDebug("x: ", (int)relativePos.getX(), " y: ", (int)relativePos.getY(), " z: ", (int)relativePos.getZ());
 | 
					    //logDebug("x: ", (int)relativePos.getX(), " y: ", (int)relativePos.getY(), " z: ", (int)relativePos.getZ());
 | 
				
			||||||
    m_map[relativePos.getX()][relativePos.getY()][relativePos.getZ()].addThing(thing);
 | 
					    m_map[relativePos.getX()][relativePos.getY()][relativePos.getZ()].addThing(thing);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,11 +9,11 @@ class Map
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    void addThing(Thing *thing, const Position& pos);
 | 
					    void addThing(Thing *thing, const Position& pos);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void draw(int x, int y, int width, int heigth);
 | 
					    void draw(int x, int y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    // Visible tiles are 15x11, but we have a +3 value. We have 15 floors.
 | 
					    // Visible tiles are 15x11, but we have a +3 value. We have 15 floors.
 | 
				
			||||||
    Tile m_map[19][15][15];
 | 
					    Tile m_map[20][16][15];
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // MAP_H
 | 
					#endif // MAP_H
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,10 +5,12 @@
 | 
				
			||||||
ProtocolGame::ProtocolGame()
 | 
					ProtocolGame::ProtocolGame()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    m_checksumEnabled = false;
 | 
					    m_checksumEnabled = false;
 | 
				
			||||||
 | 
					    g_game.setProtocol(this);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ProtocolGame::~ProtocolGame()
 | 
					ProtocolGame::~ProtocolGame()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    g_game.setProtocol(NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ProtocolGame::login(const std::string& accountName, const std::string& accountPassword, uint32 ip, uint16 port, const std::string& characterName)
 | 
					void ProtocolGame::login(const std::string& accountName, const std::string& accountPassword, uint32 ip, uint16 port, const std::string& characterName)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,9 +21,17 @@ public:
 | 
				
			||||||
    void onConnect();
 | 
					    void onConnect();
 | 
				
			||||||
    void onRecv(InputMessage& inputMessage);
 | 
					    void onRecv(InputMessage& inputMessage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Send Messages
 | 
				
			||||||
 | 
					    void sendPing();
 | 
				
			||||||
 | 
					    void sendWalkNorth();
 | 
				
			||||||
 | 
					    void sendWalkEast();
 | 
				
			||||||
 | 
					    void sendWalkSouth();
 | 
				
			||||||
 | 
					    void sendWalkWest();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void sendLoginPacket(uint32 timestamp, uint8 unknown);
 | 
					    void sendLoginPacket(uint32 timestamp, uint8 unknown);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Parse Messages
 | 
				
			||||||
    void parseMessage(InputMessage& msg);
 | 
					    void parseMessage(InputMessage& msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void parsePlayerLogin(InputMessage& msg);
 | 
					    void parsePlayerLogin(InputMessage& msg);
 | 
				
			||||||
| 
						 | 
					@ -96,8 +104,6 @@ private:
 | 
				
			||||||
    void parseQuestList(InputMessage& msg);
 | 
					    void parseQuestList(InputMessage& msg);
 | 
				
			||||||
    void parseQuestPartList(InputMessage& msg);
 | 
					    void parseQuestPartList(InputMessage& msg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void sendPing();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    void setMapDescription(InputMessage& msg, int32 x, int32 y, int32 z, int32 width, int32 height);
 | 
					    void setMapDescription(InputMessage& msg, int32 x, int32 y, int32 z, int32 width, int32 height);
 | 
				
			||||||
    void setFloorDescription(InputMessage& msg, int32 x, int32 y, int32 z, int32 width, int32 height, int32 offset, int32* skipTiles);
 | 
					    void setFloorDescription(InputMessage& msg, int32 x, int32 y, int32 z, int32 width, int32 height, int32 offset, int32* skipTiles);
 | 
				
			||||||
    void setTileDescription(InputMessage& msg, Position position);
 | 
					    void setTileDescription(InputMessage& msg, Position position);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -229,6 +229,8 @@ void ProtocolGame::parseMessage(InputMessage& msg)
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    recv();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ProtocolGame::parsePlayerLogin(InputMessage& msg)
 | 
					void ProtocolGame::parsePlayerLogin(InputMessage& msg)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,35 @@
 | 
				
			||||||
void ProtocolGame::sendPing()
 | 
					void ProtocolGame::sendPing()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    OutputMessage oMsg;
 | 
					    OutputMessage oMsg;
 | 
				
			||||||
    oMsg.reset();
 | 
					 | 
				
			||||||
    oMsg.addU8(0x1E);
 | 
					    oMsg.addU8(0x1E);
 | 
				
			||||||
    send(oMsg);
 | 
					    send(oMsg);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ProtocolGame::sendWalkNorth()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    OutputMessage oMsg;
 | 
				
			||||||
 | 
					    oMsg.addU8(0x65);
 | 
				
			||||||
 | 
					    send(oMsg);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ProtocolGame::sendWalkEast()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    OutputMessage oMsg;
 | 
				
			||||||
 | 
					    oMsg.addU8(0x66);
 | 
				
			||||||
 | 
					    send(oMsg);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ProtocolGame::sendWalkSouth()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    OutputMessage oMsg;
 | 
				
			||||||
 | 
					    oMsg.addU8(0x67);
 | 
				
			||||||
 | 
					    send(oMsg);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void ProtocolGame::sendWalkWest()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    OutputMessage oMsg;
 | 
				
			||||||
 | 
					    oMsg.addU8(0x68);
 | 
				
			||||||
 | 
					    send(oMsg);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,7 @@ public:
 | 
				
			||||||
    void setType(Type type) { m_type = type; }
 | 
					    void setType(Type type) { m_type = type; }
 | 
				
			||||||
    Type getType() const { return m_type; }
 | 
					    Type getType() const { return m_type; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual void draw(int, int) {}
 | 
					    virtual void draw(int, int, int) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual Item* getItem() { return NULL; }
 | 
					    virtual Item* getItem() { return NULL; }
 | 
				
			||||||
    virtual const Item *getItem() const { return NULL; }
 | 
					    virtual const Item *getItem() const { return NULL; }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										37
									
								
								src/tile.cpp
								
								
								
								
							
							
						
						
									
										37
									
								
								src/tile.cpp
								
								
								
								
							| 
						 | 
					@ -2,20 +2,29 @@
 | 
				
			||||||
#include "item.h"
 | 
					#include "item.h"
 | 
				
			||||||
#include "tibiadat.h"
 | 
					#include "tibiadat.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Tile::Tile()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    m_ground = NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Tile::addThing(Thing *thing)
 | 
					void Tile::addThing(Thing *thing)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if(!thing)
 | 
					    if(!thing)
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(thing->getType() == Thing::TYPE_ITEM) {
 | 
					    if(thing->getType() == Thing::TYPE_ITEM) {
 | 
				
			||||||
        const Item *item = thing->getItem();
 | 
					        Item *item = thing->getItem();
 | 
				
			||||||
        if(item) {
 | 
					        if(item) {
 | 
				
			||||||
            ItemAttributes *itemAttributes = g_tibiaDat.getItemAttributes(item->getId());
 | 
					            ItemAttributes *itemAttributes = g_tibiaDat.getItemAttributes(item->getId());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if(itemAttributes->alwaysOnTop)
 | 
					            if(itemAttributes->group == ITEM_GROUP_GROUND)
 | 
				
			||||||
                m_itemsTop.push_back(thing);
 | 
					                m_ground = item;
 | 
				
			||||||
            else
 | 
					            else {
 | 
				
			||||||
                m_itemsBot.push_back(thing);
 | 
					                if(itemAttributes->alwaysOnTop)
 | 
				
			||||||
 | 
					                    m_itemsTop.push_back(thing);
 | 
				
			||||||
 | 
					                else
 | 
				
			||||||
 | 
					                    m_itemsBot.push_back(thing);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if(thing->getType() == Thing::TYPE_CREATURE) {
 | 
					    else if(thing->getType() == Thing::TYPE_CREATURE) {
 | 
				
			||||||
| 
						 | 
					@ -23,12 +32,18 @@ void Tile::addThing(Thing *thing)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Tile::draw(int x, int y)
 | 
					void Tile::draw(int x, int y, int z)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    for(auto it = m_itemsBot.begin(), end = m_itemsBot.end(); it != end; ++it)
 | 
					    if(m_ground)
 | 
				
			||||||
        (*it)->draw(x, y);
 | 
					        m_ground->draw(x, y, z);
 | 
				
			||||||
    for(auto it = m_creatures.begin(), end = m_creatures.end(); it != end; ++it)
 | 
					
 | 
				
			||||||
        (*it)->draw(x, y);
 | 
					 | 
				
			||||||
    for(auto it = m_itemsTop.begin(), end = m_itemsTop.end(); it != end; ++it)
 | 
					    for(auto it = m_itemsTop.begin(), end = m_itemsTop.end(); it != end; ++it)
 | 
				
			||||||
        (*it)->draw(x, y);
 | 
					        (*it)->draw(x, y, z);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for(auto it = m_creatures.begin(), end = m_creatures.end(); it != end; ++it)
 | 
				
			||||||
 | 
					        (*it)->draw(x, y, z);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for(auto it = m_itemsBot.begin(), end = m_itemsBot.end(); it != end; ++it)
 | 
				
			||||||
 | 
					        (*it)->draw(x, y, z);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,12 +7,14 @@
 | 
				
			||||||
class Tile
 | 
					class Tile
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
 | 
					    Tile();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void addThing(Thing *thing);
 | 
					    void addThing(Thing *thing);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void draw(int x, int y);
 | 
					    void draw(int x, int y, int z);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    // ground
 | 
					    Item *m_ground;
 | 
				
			||||||
    std::list<Thing*> m_itemsBot;
 | 
					    std::list<Thing*> m_itemsBot;
 | 
				
			||||||
    std::list<Thing*> m_creatures;
 | 
					    std::list<Thing*> m_creatures;
 | 
				
			||||||
    std::list<Thing*> m_itemsTop;
 | 
					    std::list<Thing*> m_itemsTop;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue