parent
3a5683b549
commit
651315d4cd
@ -0,0 +1,3 @@
|
|||||||
|
#include "game.h"
|
||||||
|
|
||||||
|
Game g_game;
|
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef GAME_H
|
||||||
|
#define GAME_H
|
||||||
|
|
||||||
|
#include <global.h>
|
||||||
|
#include "map.h"
|
||||||
|
#include "player.h"
|
||||||
|
|
||||||
|
class Game
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Map *getMap() { return &m_map; }
|
||||||
|
Player *getPlayer() { return &m_player; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Map m_map;
|
||||||
|
Player m_player;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Game g_game;
|
||||||
|
|
||||||
|
#endif // GAME_H
|
@ -0,0 +1,79 @@
|
|||||||
|
#include "item.h"
|
||||||
|
#include "tibiadat.h"
|
||||||
|
#include "tibiaspr.h"
|
||||||
|
#include <graphics/graphics.h>
|
||||||
|
|
||||||
|
ItemAttributes::ItemAttributes()
|
||||||
|
{
|
||||||
|
group = ITEM_GROUP_NONE;
|
||||||
|
blockSolid = false;
|
||||||
|
hasHeight = false;
|
||||||
|
blockPathFind = false;
|
||||||
|
blockProjectile = false;
|
||||||
|
alwaysOnTop = false;
|
||||||
|
alwaysOnTopOrder = 0;
|
||||||
|
stackable = false;
|
||||||
|
useable = false;
|
||||||
|
moveable = true;
|
||||||
|
pickupable = false;
|
||||||
|
rotable = false;
|
||||||
|
readable = false;
|
||||||
|
lookThrough = false;
|
||||||
|
speed = 0;
|
||||||
|
lightLevel = 0;
|
||||||
|
lightColor = 0;
|
||||||
|
isVertical = false;
|
||||||
|
isHorizontal = false;
|
||||||
|
isHangable = false;
|
||||||
|
miniMapColor = 0;
|
||||||
|
hasMiniMapColor = false;
|
||||||
|
subParam07 = 0;
|
||||||
|
subParam08 = 0;
|
||||||
|
sprites = NULL;
|
||||||
|
width = 0;
|
||||||
|
height = 0;
|
||||||
|
blendframes = 0;
|
||||||
|
xdiv = 0;
|
||||||
|
ydiv = 0;
|
||||||
|
zdiv = 0;
|
||||||
|
animcount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemAttributes::~ItemAttributes()
|
||||||
|
{
|
||||||
|
if(sprites)
|
||||||
|
delete []sprites;
|
||||||
|
}
|
||||||
|
|
||||||
|
Item::Item()
|
||||||
|
{
|
||||||
|
m_type = Thing::TYPE_ITEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Item::draw(int x, int y)
|
||||||
|
{
|
||||||
|
ItemAttributes *itemAttributes = g_tibiaDat.getItemAttributes(m_id);
|
||||||
|
|
||||||
|
int cDivX = 0, cDivY = 0, cDivZ = 0, cAnim = 0;
|
||||||
|
|
||||||
|
for(int b = 0; b < itemAttributes->blendframes; b++) {
|
||||||
|
for(int yi = 0; yi < itemAttributes->height; yi++) {
|
||||||
|
for(int xi = 0; xi < itemAttributes->width; xi++) {
|
||||||
|
uint16 sprIndex = xi +
|
||||||
|
yi * itemAttributes->width +
|
||||||
|
b * itemAttributes->width * itemAttributes->height +
|
||||||
|
cDivX * itemAttributes->width * itemAttributes->height * itemAttributes->blendframes +
|
||||||
|
cDivY * itemAttributes->width * itemAttributes->height * itemAttributes->blendframes * itemAttributes->xdiv +
|
||||||
|
cDivZ * itemAttributes->width * itemAttributes->height * itemAttributes->blendframes * itemAttributes->xdiv * itemAttributes->ydiv +
|
||||||
|
cAnim * itemAttributes->width * itemAttributes->height * itemAttributes->blendframes * itemAttributes->xdiv * itemAttributes->ydiv * itemAttributes->zdiv;
|
||||||
|
uint16 itemId = itemAttributes->sprites[sprIndex];
|
||||||
|
if(itemId == 0xFFFF)
|
||||||
|
continue;
|
||||||
|
TexturePtr data = g_tibiaSpr.getSprite(itemId);
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
#ifndef ITEM_H
|
||||||
|
#define ITEM_H
|
||||||
|
|
||||||
|
#include <global.h>
|
||||||
|
#include "thing.h"
|
||||||
|
|
||||||
|
enum ItemGroup {
|
||||||
|
ITEM_GROUP_NONE = 0,
|
||||||
|
ITEM_GROUP_GROUND,
|
||||||
|
ITEM_GROUP_CONTAINER,
|
||||||
|
ITEM_GROUP_WEAPON,
|
||||||
|
ITEM_GROUP_AMMUNITION,
|
||||||
|
ITEM_GROUP_ARMOR,
|
||||||
|
ITEM_GROUP_RUNE,
|
||||||
|
ITEM_GROUP_TELEPORT,
|
||||||
|
ITEM_GROUP_MAGICFIELD,
|
||||||
|
ITEM_GROUP_WRITEABLE,
|
||||||
|
ITEM_GROUP_KEY,
|
||||||
|
ITEM_GROUP_SPLASH,
|
||||||
|
ITEM_GROUP_FLUID,
|
||||||
|
ITEM_GROUP_DOOR,
|
||||||
|
ITEM_GROUP_LAST
|
||||||
|
};
|
||||||
|
|
||||||
|
class ItemAttributes
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ItemAttributes();
|
||||||
|
~ItemAttributes();
|
||||||
|
|
||||||
|
bool stackable, alwaysOnTop, useable, readable, moveable, blockSolid, blockProjectile, blockPathFind, pickupable,
|
||||||
|
isHangable, isHorizontal, isVertical, rotable, hasHeight, lookThrough, hasMiniMapColor;
|
||||||
|
uint8 alwaysOnTopOrder, width, height, blendframes, xdiv, ydiv, zdiv, animcount;
|
||||||
|
uint16 id, speed, subParam07, subParam08, lightLevel, lightColor, uheight, miniMapColor;
|
||||||
|
uint16 *sprites;
|
||||||
|
ItemGroup group;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Item : virtual public Thing
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Item();
|
||||||
|
|
||||||
|
void draw(int x, int y);
|
||||||
|
|
||||||
|
void setId(uint16 id) { m_id = id; }
|
||||||
|
uint16 getId() const { return m_id; }
|
||||||
|
|
||||||
|
void setCount(uint8 count) { m_count = count; }
|
||||||
|
|
||||||
|
virtual Item* getItem() { return this; }
|
||||||
|
virtual const Item* getItem() const { return this; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint16 m_id;
|
||||||
|
uint8 m_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,32 @@
|
|||||||
|
#include "map.h"
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
|
void Map::draw(int x, int y, int width, int heigth)
|
||||||
|
{
|
||||||
|
Position playerPos = g_game.getPlayer()->getPosition();
|
||||||
|
for(int ix = 0; ix < 19; ++ix) {
|
||||||
|
for(int iy = 0; iy < 15; ++iy) {
|
||||||
|
if(playerPos.getZ() >= 7) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Map::addThing(Thing *thing, const Position& pos)
|
||||||
|
{
|
||||||
|
Position playerPos = g_game.getPlayer()->getPosition();
|
||||||
|
Position relativePos = Position(pos.getX() - playerPos.getX() + 8, pos.getY() - playerPos.getY() + 6, pos.getZ());
|
||||||
|
|
||||||
|
if(relativePos.getX() >= 18)
|
||||||
|
logDebug("relativePos is invalid.");
|
||||||
|
if(relativePos.getY() >= 14)
|
||||||
|
logDebug("relativePos is invalid.");
|
||||||
|
if(relativePos.getZ() >= 15)
|
||||||
|
logDebug("relativePos is invalid.");
|
||||||
|
|
||||||
|
logDebug("x: ", (int)relativePos.getX(), " y: ", (int)relativePos.getY(), " z: ", (int)relativePos.getZ());
|
||||||
|
m_map[relativePos.getX()][relativePos.getY()][relativePos.getZ()].addThing(thing);
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef MAP_H
|
||||||
|
#define MAP_H
|
||||||
|
|
||||||
|
#include "position.h"
|
||||||
|
#include "tile.h"
|
||||||
|
|
||||||
|
class Map
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void addThing(Thing *thing, const Position& pos);
|
||||||
|
|
||||||
|
void draw(int x, int y, int width, int heigth);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Visible tiles are 15x11, but we have a +3 value. We have 15 floors.
|
||||||
|
Tile m_map[19][15][15];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MAP_H
|
@ -0,0 +1,9 @@
|
|||||||
|
#include "protocolgame.h"
|
||||||
|
|
||||||
|
void ProtocolGame::sendPing()
|
||||||
|
{
|
||||||
|
OutputMessage oMsg;
|
||||||
|
oMsg.reset();
|
||||||
|
oMsg.addU8(0x1E);
|
||||||
|
send(oMsg);
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
#include "thing.h"
|
||||||
|
|
||||||
|
Thing::Thing()
|
||||||
|
{
|
||||||
|
m_type = TYPE_NONE;
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef THING_H
|
||||||
|
#define THING_H
|
||||||
|
|
||||||
|
#include <global.h>
|
||||||
|
|
||||||
|
class Item;
|
||||||
|
|
||||||
|
class Thing
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Thing();
|
||||||
|
|
||||||
|
enum Type {
|
||||||
|
TYPE_NONE,
|
||||||
|
TYPE_ITEM,
|
||||||
|
TYPE_CREATURE
|
||||||
|
};
|
||||||
|
|
||||||
|
void setType(Type type) { m_type = type; }
|
||||||
|
Type getType() const { return m_type; }
|
||||||
|
|
||||||
|
virtual void draw(int, int) {}
|
||||||
|
|
||||||
|
virtual Item* getItem() { return NULL; }
|
||||||
|
virtual const Item *getItem() const { return NULL; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Type m_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // THING_H
|
@ -0,0 +1,121 @@
|
|||||||
|
#include "tibiaspr.h"
|
||||||
|
#include <core/resources.h>
|
||||||
|
|
||||||
|
TibiaSpr g_tibiaSpr;
|
||||||
|
|
||||||
|
TibiaSpr::TibiaSpr()
|
||||||
|
{
|
||||||
|
m_sprites = NULL;
|
||||||
|
m_spritesCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
TibiaSpr::~TibiaSpr()
|
||||||
|
{
|
||||||
|
//for(uint16 i = 0; i < m_spritesCount; i++)
|
||||||
|
//if(m_sprites[i])
|
||||||
|
//delete m_sprites[i];
|
||||||
|
|
||||||
|
if(m_sprites)
|
||||||
|
delete []m_sprites;
|
||||||
|
|
||||||
|
//delete m_transparentSprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TibiaSpr::load(const std::string &filename)
|
||||||
|
{
|
||||||
|
if(!g_resources.loadFile(filename, m_fin))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_fin.read((char*)&m_signature, 4);
|
||||||
|
m_fin.read((char*)&m_spritesCount, 2);
|
||||||
|
|
||||||
|
m_sprites = new TexturePtr[m_spritesCount];
|
||||||
|
|
||||||
|
//for(uint16 i = 0; i < m_spritesCount; i++)
|
||||||
|
//m_sprites[i] = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
uchar pixels[4096];
|
||||||
|
for(int i = 0; i < 32*32*4; i += 4) {
|
||||||
|
pixels[i + 0] = 0xFF;
|
||||||
|
pixels[i + 1] = 0x00;
|
||||||
|
pixels[i + 2] = 0xFF;
|
||||||
|
pixels[i + 3] = 0xFF;
|
||||||
|
}
|
||||||
|
m_transparentSprite = TexturePtr(new Texture(32, 32, 4, pixels));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TexturePtr TibiaSpr::loadSprite(uint32 id)
|
||||||
|
{
|
||||||
|
if(m_fin.eof())
|
||||||
|
return TexturePtr();
|
||||||
|
|
||||||
|
m_fin.seekg((id * 4) + 6, std::ios_base::beg);
|
||||||
|
|
||||||
|
uint32 spriteAddress;
|
||||||
|
m_fin.read((char*)&spriteAddress, 4);
|
||||||
|
|
||||||
|
if(spriteAddress == 0) // Some error on tibia.spr, save a blank image.
|
||||||
|
return TexturePtr();
|
||||||
|
|
||||||
|
m_fin.seekg(spriteAddress, std::ios_base::beg);
|
||||||
|
|
||||||
|
uint32 colorKey = 0;
|
||||||
|
m_fin.read((char*)&colorKey, 3);
|
||||||
|
|
||||||
|
uint16 spriteSize;
|
||||||
|
m_fin.read((char*)&spriteSize, 2);
|
||||||
|
|
||||||
|
uchar image[4096];
|
||||||
|
uint16 imgPos = 0, read = 0, transparentPixels, coloredPixels, x;
|
||||||
|
while(read < spriteSize) {
|
||||||
|
m_fin.read((char*)&transparentPixels, 2);
|
||||||
|
m_fin.read((char*)&coloredPixels, 2);
|
||||||
|
|
||||||
|
for(x = 0; x < transparentPixels; x++) {
|
||||||
|
image[imgPos + 0] = 0x00;
|
||||||
|
image[imgPos + 1] = 0x00;
|
||||||
|
image[imgPos + 2] = 0x00;
|
||||||
|
image[imgPos + 3] = 0x00;
|
||||||
|
imgPos += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(x = 0; x < coloredPixels; x++) {
|
||||||
|
m_fin.read((char*)&image[imgPos + 0], 1);
|
||||||
|
m_fin.read((char*)&image[imgPos + 1], 1);
|
||||||
|
m_fin.read((char*)&image[imgPos + 2], 1);
|
||||||
|
image[imgPos + 3] = 0xFF;
|
||||||
|
|
||||||
|
imgPos += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
read += 4 + (3 * coloredPixels);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill remaining bytes with pink.
|
||||||
|
if(imgPos < 32 * 32 * 4) {
|
||||||
|
for(x = imgPos; x < 32 * 32 * 4; x += 4) {
|
||||||
|
image[x + 0] = 0xFF;
|
||||||
|
image[x + 1] = 0x00;
|
||||||
|
image[x + 2] = 0xFF;
|
||||||
|
image[x + 3] = 0x00;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TexturePtr(new Texture(32, 32, 4, image));
|
||||||
|
}
|
||||||
|
|
||||||
|
TexturePtr TibiaSpr::getSprite(uint32 id)
|
||||||
|
{
|
||||||
|
if(!m_sprites)
|
||||||
|
return m_transparentSprite;
|
||||||
|
|
||||||
|
if(!m_sprites[id]) {
|
||||||
|
m_sprites[id] = loadSprite(id);
|
||||||
|
if(!m_sprites[id])
|
||||||
|
return m_transparentSprite;
|
||||||
|
}
|
||||||
|
return m_sprites[id];
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef TIBIASPR_H
|
||||||
|
#define TIBIASPR_H
|
||||||
|
|
||||||
|
#include <global.h>
|
||||||
|
#include <graphics/texture.h>
|
||||||
|
|
||||||
|
class TibiaSpr
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TibiaSpr();
|
||||||
|
~TibiaSpr();
|
||||||
|
|
||||||
|
bool load(const std::string& filename);
|
||||||
|
|
||||||
|
uint32 getSignature() { return m_signature; }
|
||||||
|
uint16 getSpritesCount() { return m_spritesCount; }
|
||||||
|
TexturePtr getSprite(uint32 id);
|
||||||
|
|
||||||
|
private:
|
||||||
|
TexturePtr loadSprite(uint32 id);
|
||||||
|
|
||||||
|
std::stringstream m_fin;
|
||||||
|
uint32 m_signature;
|
||||||
|
uint16 m_spritesCount;
|
||||||
|
TexturePtr *m_sprites;
|
||||||
|
TexturePtr m_transparentSprite;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern TibiaSpr g_tibiaSpr;
|
||||||
|
|
||||||
|
#endif // TIBIASPR_H
|
@ -0,0 +1,34 @@
|
|||||||
|
#include "tile.h"
|
||||||
|
#include "item.h"
|
||||||
|
#include "tibiadat.h"
|
||||||
|
|
||||||
|
void Tile::addThing(Thing *thing)
|
||||||
|
{
|
||||||
|
if(!thing)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(thing->getType() == Thing::TYPE_ITEM) {
|
||||||
|
const Item *item = thing->getItem();
|
||||||
|
if(item) {
|
||||||
|
ItemAttributes *itemAttributes = g_tibiaDat.getItemAttributes(item->getId());
|
||||||
|
|
||||||
|
if(itemAttributes->alwaysOnTop)
|
||||||
|
m_itemsTop.push_back(thing);
|
||||||
|
else
|
||||||
|
m_itemsBot.push_back(thing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(thing->getType() == Thing::TYPE_CREATURE) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tile::draw(int x, int y)
|
||||||
|
{
|
||||||
|
for(auto it = m_itemsBot.begin(), end = m_itemsBot.end(); it != end; ++it)
|
||||||
|
(*it)->draw(x, y);
|
||||||
|
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)
|
||||||
|
(*it)->draw(x, y);
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef TILE_H
|
||||||
|
#define TILE_H
|
||||||
|
|
||||||
|
#include <global.h>
|
||||||
|
#include "thing.h"
|
||||||
|
|
||||||
|
class Tile
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void addThing(Thing *thing);
|
||||||
|
|
||||||
|
void draw(int x, int y);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// ground
|
||||||
|
std::list<Thing*> m_itemsBot;
|
||||||
|
std::list<Thing*> m_creatures;
|
||||||
|
std::list<Thing*> m_itemsTop;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TILE_H
|
Loading…
Reference in new issue