create thing m_type

This commit is contained in:
Henrique 2011-12-02 00:29:05 -02:00
parent 9bb7332ac0
commit 3e27d5a79f
17 changed files with 119 additions and 111 deletions

View File

@ -45,8 +45,6 @@ Creature::Creature() : Thing()
void Creature::draw(const Point& p) void Creature::draw(const Point& p)
{ {
const ThingType& type = getType();
// TODO: activate on attack, follow, discover how 'attacked' works // TODO: activate on attack, follow, discover how 'attacked' works
if(m_showSquareColor) { if(m_showSquareColor) {
g_graphics.bindColor(Outfit::getColor(m_squareColor)); g_graphics.bindColor(Outfit::getColor(m_squareColor));
@ -54,7 +52,7 @@ void Creature::draw(const Point& p)
} }
// Render creature // Render creature
for(m_yPattern = 0; m_yPattern < type.dimensions[ThingType::PatternY]; m_yPattern++) { for(m_yPattern = 0; m_yPattern < m_type->dimensions[ThingType::PatternY]; m_yPattern++) {
// continue if we dont have this addon. // continue if we dont have this addon.
if(m_yPattern > 0 && !(m_outfit.getAddons() & (1 << (m_yPattern-1)))) if(m_yPattern > 0 && !(m_outfit.getAddons() & (1 << (m_yPattern-1))))
@ -65,7 +63,7 @@ void Creature::draw(const Point& p)
internalDraw(p + m_walkOffset, 0); internalDraw(p + m_walkOffset, 0);
// draw mask if exists // draw mask if exists
if(type.dimensions[ThingType::Layers] > 1) { if(m_type->dimensions[ThingType::Layers] > 1) {
// switch to blend color mode // switch to blend color mode
g_graphics.bindBlendFunc(Fw::BlendColorzing); g_graphics.bindBlendFunc(Fw::BlendColorzing);
@ -194,7 +192,7 @@ void Creature::walk(const Position& position, bool inverse)
ItemPtr ground = g_map.getTile(position)->getGround(); ItemPtr ground = g_map.getTile(position)->getGround();
if(ground) if(ground)
groundSpeed = ground->getType().parameters[ThingType::GroundSpeed]; groundSpeed = ground->getType()->parameters[ThingType::GroundSpeed];
float walkTime = walkTimeFactor * 1000.0 * (float)groundSpeed / m_speed; float walkTime = walkTimeFactor * 1000.0 * (float)groundSpeed / m_speed;
walkTime = (walkTime == 0) ? 1000 : walkTime; walkTime = (walkTime == 0) ? 1000 : walkTime;
@ -208,7 +206,6 @@ void Creature::walk(const Position& position, bool inverse)
void Creature::updateWalk() void Creature::updateWalk()
{ {
const ThingType& type = getType();
if(m_walking) { if(m_walking) {
int elapsedTicks = g_clock.ticks() - m_walkStartTicks; int elapsedTicks = g_clock.ticks() - m_walkStartTicks;
int totalPixelsWalked = std::min((int)round(elapsedTicks / m_walkTimePerPixel), 32); int totalPixelsWalked = std::min((int)round(elapsedTicks / m_walkTimePerPixel), 32);
@ -240,8 +237,8 @@ void Creature::updateWalk()
} }
int totalWalkTileTicks = (int)m_walkTimePerPixel*32 * 0.5; int totalWalkTileTicks = (int)m_walkTimePerPixel*32 * 0.5;
if(type.dimensions[ThingType::AnimationPhases] > 0) if(m_type->dimensions[ThingType::AnimationPhases] > 0)
m_animation = (g_clock.ticks() % totalWalkTileTicks) / (totalWalkTileTicks / (type.dimensions[ThingType::AnimationPhases] - 1)) + 1; m_animation = (g_clock.ticks() % totalWalkTileTicks) / (totalWalkTileTicks / (m_type->dimensions[ThingType::AnimationPhases] - 1)) + 1;
else else
m_animation = 0; m_animation = 0;
g_dispatcher.scheduleEvent(std::bind(&Creature::updateWalk, asCreature()), m_walkTimePerPixel); g_dispatcher.scheduleEvent(std::bind(&Creature::updateWalk, asCreature()), m_walkTimePerPixel);
@ -320,7 +317,13 @@ void Creature::setDirection(Otc::Direction direction)
m_direction = direction; m_direction = direction;
} }
const ThingType& Creature::getType() void Creature::setOutfit(const Outfit& outfit)
{
m_outfit = outfit;
m_type = getType();
}
ThingType *Creature::getType()
{ {
return g_thingsType.getThingType(m_outfit.getType(), ThingsType::Creature); return g_thingsType.getThingType(m_outfit.getType(), ThingsType::Creature);
} }

View File

@ -39,7 +39,7 @@ public:
void setName(const std::string& name); void setName(const std::string& name);
void setHealthPercent(uint8 healthPercent); void setHealthPercent(uint8 healthPercent);
void setDirection(Otc::Direction direction); void setDirection(Otc::Direction direction);
void setOutfit(const Outfit& outfit) { m_outfit = outfit; } void setOutfit(const Outfit& outfit);
void setLight(const Light& light) { m_light = light; } void setLight(const Light& light) { m_light = light; }
void setSpeed(uint16 speed) { m_speed = speed; } void setSpeed(uint16 speed) { m_speed = speed; }
void setSkull(uint8 skull) { m_skull = skull; } void setSkull(uint8 skull) { m_skull = skull; }
@ -58,7 +58,7 @@ public:
uint8 getShield() { return m_shield; } uint8 getShield() { return m_shield; }
uint8 getEmblem() { return m_emblem; } uint8 getEmblem() { return m_emblem; }
bool getImpassable() { return m_impassable; } bool getImpassable() { return m_impassable; }
const ThingType& getType(); ThingType *getType();
virtual void walk(const Position& position, bool inverse = true); virtual void walk(const Position& position, bool inverse = true);
virtual void cancelWalk(Otc::Direction direction); virtual void cancelWalk(Otc::Direction direction);

View File

@ -53,7 +53,7 @@ void Effect::startAnimation()
}, TICKS_PER_FRAME * getAnimationPhases()); }, TICKS_PER_FRAME * getAnimationPhases());
} }
const ThingType& Effect::getType() ThingType *Effect::getType()
{ {
return g_thingsType.getThingType(m_id, ThingsType::Effect); return g_thingsType.getThingType(m_id, ThingsType::Effect);
} }

View File

@ -40,7 +40,7 @@ public:
void startAnimation(); void startAnimation();
void updateAnimation(); void updateAnimation();
const ThingType& getType(); ThingType *getType();
EffectPtr asEffect() { return std::static_pointer_cast<Effect>(shared_from_this()); } EffectPtr asEffect() { return std::static_pointer_cast<Effect>(shared_from_this()); }

View File

@ -34,23 +34,19 @@ Item::Item() : Thing()
void Item::draw(const Point& p) void Item::draw(const Point& p)
{ {
const ThingType& type = getType(); if(m_type->dimensions[ThingType::AnimationPhases] > 1)
m_animation = (g_clock.ticks() % (TICKS_PER_FRAME * m_type->dimensions[ThingType::AnimationPhases])) / TICKS_PER_FRAME;
if(type.dimensions[ThingType::AnimationPhases] > 1) for(int b = 0; b < m_type->dimensions[ThingType::Layers]; b++)
m_animation = (g_clock.ticks() % (TICKS_PER_FRAME * type.dimensions[ThingType::AnimationPhases])) / TICKS_PER_FRAME;
for(int b = 0; b < type.dimensions[ThingType::Layers]; b++)
internalDraw(p, b); internalDraw(p, b);
} }
void Item::setPosition(const Position& position) void Item::setPosition(const Position& position)
{ {
const ThingType& type = getType(); if(m_type->properties[ThingType::IsGround]) {
m_xPattern = position.x % m_type->dimensions[ThingType::PatternX];
if(type.properties[ThingType::IsGround]) { m_yPattern = position.y % m_type->dimensions[ThingType::PatternY];
m_xPattern = position.x % type.dimensions[ThingType::PatternX]; m_zPattern = position.z % m_type->dimensions[ThingType::PatternZ];
m_yPattern = position.y % type.dimensions[ThingType::PatternY];
m_zPattern = position.z % type.dimensions[ThingType::PatternZ];
} }
Thing::setPosition(position); Thing::setPosition(position);
@ -58,9 +54,7 @@ void Item::setPosition(const Position& position)
void Item::setData(int data) void Item::setData(int data)
{ {
const ThingType& type = getType(); if(m_type->properties[ThingType::IsStackable] && m_type->dimensions[ThingType::PatternX] == 4 && m_type->dimensions[ThingType::PatternY] == 2) {
if(type.properties[ThingType::IsStackable] && type.dimensions[ThingType::PatternX] == 4 && type.dimensions[ThingType::PatternY] == 2) {
if(data < 5) { if(data < 5) {
m_xPattern = data-1; m_xPattern = data-1;
m_yPattern = 0; m_yPattern = 0;
@ -82,15 +76,15 @@ void Item::setData(int data)
m_yPattern = 1; m_yPattern = 1;
} }
} }
else if(type.properties[ThingType::IsHangable]) { else if(m_type->properties[ThingType::IsHangable]) {
if(type.properties[ThingType::HookSouth]) { if(m_type->properties[ThingType::HookSouth]) {
m_xPattern = type.dimensions[ThingType::PatternX] >= 2 ? 1 : 0; m_xPattern = m_type->dimensions[ThingType::PatternX] >= 2 ? 1 : 0;
} }
else if(type.properties[ThingType::HookEast]) { else if(m_type->properties[ThingType::HookEast]) {
m_xPattern = type.dimensions[ThingType::PatternX] >= 3 ? 2 : 0; m_xPattern = m_type->dimensions[ThingType::PatternX] >= 3 ? 2 : 0;
} }
} }
else if(type.properties[ThingType::IsFluid] || type.properties[ThingType::IsFluidContainer]) { else if(m_type->properties[ThingType::IsFluid] || m_type->properties[ThingType::IsFluidContainer]) {
int color = 0; int color = 0;
// TODO: find out what the heck does it mean 4, 7, 12, 13, 14, 16, 17. options are already there // TODO: find out what the heck does it mean 4, 7, 12, 13, 14, 16, 17. options are already there
switch(data) { switch(data) {
@ -153,14 +147,14 @@ void Item::setData(int data)
break; break;
} }
m_xPattern = (color % 4) % type.dimensions[ThingType::PatternX]; m_xPattern = (color % 4) % m_type->dimensions[ThingType::PatternX];
m_yPattern = (color / 4) % type.dimensions[ThingType::PatternY]; m_yPattern = (color / 4) % m_type->dimensions[ThingType::PatternY];
} }
m_data = data; m_data = data;
} }
const ThingType& Item::getType() ThingType *Item::getType()
{ {
return g_thingsType.getThingType(m_id, ThingsType::Item); return g_thingsType.getThingType(m_id, ThingsType::Item);
} }

View File

@ -41,7 +41,7 @@ public:
void setData(int data); void setData(int data);
int getData() { return m_data; } int getData() { return m_data; }
const ThingType& getType(); ThingType *getType();
ItemPtr asItem() { return std::static_pointer_cast<Item>(shared_from_this()); } ItemPtr asItem() { return std::static_pointer_cast<Item>(shared_from_this()); }

View File

@ -134,8 +134,8 @@ int Map::getFirstVisibleFloor()
while(upperPos.z >= firstFloor) { while(upperPos.z >= firstFloor) {
if(TilePtr tile = m_tiles[upperPos]) { if(TilePtr tile = m_tiles[upperPos]) {
if(ThingPtr firstThing = tile->getThing(0)) { if(ThingPtr firstThing = tile->getThing(0)) {
const ThingType type = firstThing->getType(); ThingType *type = firstThing->getType();
if((type.properties[ThingType::IsGround] || type.properties[ThingType::IsOnBottom]) && !type.properties[ThingType::DontHide]) { if((type->properties[ThingType::IsGround] || type->properties[ThingType::IsOnBottom]) && !type->properties[ThingType::DontHide]) {
firstFloor = upperPos.z + 1; firstFloor = upperPos.z + 1;
break; break;
} }
@ -143,8 +143,8 @@ int Map::getFirstVisibleFloor()
} }
if(TilePtr tile = m_tiles[perspectivePos]) { if(TilePtr tile = m_tiles[perspectivePos]) {
if(ThingPtr firstThing = tile->getThing(0)) { if(ThingPtr firstThing = tile->getThing(0)) {
const ThingType type = firstThing->getType(); ThingType *type = firstThing->getType();
if((type.properties[ThingType::IsGround] || type.properties[ThingType::IsOnBottom]) && !type.properties[ThingType::DontHide]) { if((type->properties[ThingType::IsGround] || type->properties[ThingType::IsOnBottom]) && !type->properties[ThingType::DontHide]) {
firstFloor = perspectivePos.z + 1; firstFloor = perspectivePos.z + 1;
break; break;
} }

View File

@ -117,7 +117,7 @@ void Missile::setPath(const Position& fromPosition, const Position& toPosition)
}, m_duration); }, m_duration);
} }
const ThingType& Missile::getType() ThingType *Missile::getType()
{ {
return g_thingsType.getThingType(m_id, ThingsType::Missile); return g_thingsType.getThingType(m_id, ThingsType::Missile);
} }

View File

@ -41,7 +41,7 @@ public:
void setPath(const Position& fromPosition, const Position& toPosition); void setPath(const Position& fromPosition, const Position& toPosition);
const ThingType& getType(); ThingType *getType();
MissilePtr asMissile() { return std::static_pointer_cast<Missile>(shared_from_this()); } MissilePtr asMissile() { return std::static_pointer_cast<Missile>(shared_from_this()); }

View File

@ -22,6 +22,11 @@
#include "outfit.h" #include "outfit.h"
Outfit::Outfit()
{
m_type = 0;
}
Color Outfit::getColor(int color) Color Outfit::getColor(int color)
{ {
if(color >= HSI_H_STEPS * HSI_SI_VALUES) if(color >= HSI_H_STEPS * HSI_SI_VALUES)
@ -78,37 +83,37 @@ Color Outfit::getColor(int color)
return Color(loc7, loc7, loc7); return Color(loc7, loc7, loc7);
} }
float loc4 = 0, loc5 = 0, loc6 = 0; float red = 0, green = 0, blue = 0;
if(loc1 < 1.0/6.0) { if(loc1 < 1.0/6.0) {
loc4 = loc3; red = loc3;
loc6 = loc3 * (1 - loc2); blue = loc3 * (1 - loc2);
loc5 = loc6 + (loc3 - loc6) * 6 * loc1; green = blue + (loc3 - blue) * 6 * loc1;
} }
else if (loc1 < 2.0/6.0) { else if (loc1 < 2.0/6.0) {
loc5 = loc3; green = loc3;
loc6 = loc3 * (1 - loc2); blue = loc3 * (1 - loc2);
loc4 = loc5 - (loc3 - loc6) * (6 * loc1 - 1); red = green - (loc3 - blue) * (6 * loc1 - 1);
} }
else if(loc1 < 3.0/6.0) { else if(loc1 < 3.0/6.0) {
loc5 = loc3; green = loc3;
loc4 = loc3 * (1 - loc2); red = loc3 * (1 - loc2);
loc6 = loc4 + (loc3 - loc4) * (6 * loc1 - 2); blue = red + (loc3 - red) * (6 * loc1 - 2);
} }
else if (loc1 < 4.0/6.0) { else if (loc1 < 4.0/6.0) {
loc6 = loc3; blue = loc3;
loc4 = loc3 * (1 - loc2); red = loc3 * (1 - loc2);
loc5 = loc6 - (loc3 - loc4) * (6 * loc1 - 3); green = blue - (loc3 - red) * (6 * loc1 - 3);
} }
else if (loc1 < 5.0/6.0) { else if (loc1 < 5.0/6.0) {
loc6 = loc3; blue = loc3;
loc5 = loc3 * (1 - loc2); green = loc3 * (1 - loc2);
loc4 = loc5 + (loc3 - loc5) * (6 * loc1 - 4); red = green + (loc3 - green) * (6 * loc1 - 4);
} }
else { else {
loc4 = loc3; red = loc3;
loc5 = loc3 * (1 - loc2); green = loc3 * (1 - loc2);
loc6 = loc4 - (loc3 - loc5) * (6 * loc1 - 5); blue = red - (loc3 - green) * (6 * loc1 - 5);
} }
return Color(int(loc4 * 255), int(loc5 * 255), int(loc6 * 255)); return Color(int(red * 255), int(green * 255), int(blue * 255));
} }

View File

@ -33,6 +33,8 @@ class Outfit
}; };
public: public:
Outfit();
static Color getColor(int color); static Color getColor(int color);
void setType(int type) { m_type = type; } void setType(int type) { m_type = type; }

View File

@ -34,42 +34,45 @@ Thing::Thing() : m_id(0)
void Thing::internalDraw(const Point& p, int layers, Otc::SpriteMask mask) void Thing::internalDraw(const Point& p, int layers, Otc::SpriteMask mask)
{ {
const ThingType& type = getType(); for(int yi = 0; yi < m_type->dimensions[ThingType::Height]; yi++) {
for(int xi = 0; xi < m_type->dimensions[ThingType::Width]; xi++) {
int sprIndex = ((((((m_animation % m_type->dimensions[ThingType::AnimationPhases])
* m_type->dimensions[ThingType::PatternZ] + m_zPattern)
* m_type->dimensions[ThingType::PatternY] + m_yPattern)
* m_type->dimensions[ThingType::PatternX] + m_xPattern)
* m_type->dimensions[ThingType::Layers] + layers)
* m_type->dimensions[ThingType::Height] + yi)
* m_type->dimensions[ThingType::Width] + xi;
for(int yi = 0; yi < type.dimensions[ThingType::Height]; yi++) { int spriteId = m_type->sprites[sprIndex];
for(int xi = 0; xi < type.dimensions[ThingType::Width]; xi++) {
int sprIndex = ((((((m_animation % type.dimensions[ThingType::AnimationPhases])
* type.dimensions[ThingType::PatternZ] + m_zPattern)
* type.dimensions[ThingType::PatternY] + m_yPattern)
* type.dimensions[ThingType::PatternX] + m_xPattern)
* type.dimensions[ThingType::Layers] + layers)
* type.dimensions[ThingType::Height] + yi)
* type.dimensions[ThingType::Width] + xi;
int spriteId = type.sprites[sprIndex];
if(!spriteId) if(!spriteId)
continue; continue;
TexturePtr spriteTex = g_sprites.getSpriteTexture(spriteId, mask); TexturePtr spriteTex = g_sprites.getSpriteTexture(spriteId, mask);
Rect drawRect((p.x - xi*32) - type.parameters[ThingType::DisplacementX], Rect drawRect((p.x - xi*32) - m_type->parameters[ThingType::DisplacementX],
(p.y - yi*32) - type.parameters[ThingType::DisplacementY], (p.y - yi*32) - m_type->parameters[ThingType::DisplacementY],
32, 32); 32, 32);
g_graphics.drawTexturedRect(drawRect, spriteTex); g_graphics.drawTexturedRect(drawRect, spriteTex);
} }
} }
} }
void Thing::setId(uint32 id)
{
m_id = id;
m_type = getType();
}
int Thing::getStackPriority() int Thing::getStackPriority()
{ {
const ThingType& type = getType(); if(m_type->properties[ThingType::IsGround])
if(type.properties[ThingType::IsGround])
return 0; return 0;
else if(type.properties[ThingType::IsGroundBorder]) else if(m_type->properties[ThingType::IsGroundBorder])
return 1; return 1;
else if(type.properties[ThingType::IsOnBottom]) else if(m_type->properties[ThingType::IsOnBottom])
return 2; return 2;
else if(type.properties[ThingType::IsOnTop]) else if(m_type->properties[ThingType::IsOnTop])
return 3; return 3;
else if(asCreature()) else if(asCreature())
return 4; return 4;

View File

@ -41,14 +41,14 @@ public:
virtual void draw(const Point& p) = 0; virtual void draw(const Point& p) = 0;
void setId(uint32 id) { m_id = id; } void setId(uint32 id);
virtual void setPosition(const Position& position) { m_position = position; } virtual void setPosition(const Position& position) { m_position = position; }
uint32 getId() const { return m_id; } uint32 getId() const { return m_id; }
Position getPosition() const { return m_position; } Position getPosition() const { return m_position; }
int getStackPriority(); int getStackPriority();
virtual const ThingType& getType() = 0; virtual ThingType *getType() = 0;
int getAnimationPhases() { return getType().dimensions[ThingType::AnimationPhases]; } int getAnimationPhases() { return m_type->dimensions[ThingType::AnimationPhases]; }
void setXPattern(int xPattern) { m_xPattern = xPattern; } void setXPattern(int xPattern) { m_xPattern = xPattern; }
void setYPattern(int yPattern) { m_yPattern = yPattern; } void setYPattern(int yPattern) { m_yPattern = yPattern; }
@ -67,6 +67,7 @@ protected:
uint32 m_id; uint32 m_id;
Position m_position; Position m_position;
ThingType *m_type;
int m_xPattern, m_yPattern, m_zPattern, m_animation; int m_xPattern, m_yPattern, m_zPattern, m_animation;
}; };

View File

@ -111,7 +111,7 @@ void ThingsType::parseThingType(std::stringstream& fin, ThingType& thingType)
thingType.sprites[i] = Fw::getU16(fin); thingType.sprites[i] = Fw::getU16(fin);
} }
ThingType& ThingsType::getThingType(uint16 id, Categories category) ThingType *ThingsType::getThingType(uint16 id, Categories category)
{ {
if(category == Item) if(category == Item)
id -= 100; id -= 100;
@ -122,8 +122,8 @@ ThingType& ThingsType::getThingType(uint16 id, Categories category)
if(id >= m_things[category].size()) { if(id >= m_things[category].size()) {
//logTraceErrorOnce("got an invalid type"); //logTraceErrorOnce("got an invalid type");
static ThingType emptyType; static ThingType emptyType;
return emptyType; return &emptyType;
} }
return m_things[category][id]; return &m_things[category][id];
} }

View File

@ -43,7 +43,7 @@ public:
void parseThingType(std::stringstream& fin, ThingType& thingType); void parseThingType(std::stringstream& fin, ThingType& thingType);
ThingType& getThingType(uint16 id, Categories category); ThingType *getThingType(uint16 id, Categories category);
uint32 getSignature() { return m_signature; } uint32 getSignature() { return m_signature; }

View File

@ -42,11 +42,11 @@ void Tile::draw(const Point& p)
// first bottom items // first bottom items
for(const ThingPtr& thing : m_things) { for(const ThingPtr& thing : m_things) {
const ThingType& type = thing->getType(); ThingType *type = thing->getType();
if(!type.properties[ThingType::IsGround] && !type.properties[ThingType::IsGroundBorder] && !type.properties[ThingType::IsOnBottom]) if(!type->properties[ThingType::IsGround] && !type->properties[ThingType::IsGroundBorder] && !type->properties[ThingType::IsOnBottom])
break; break;
thing->draw(p - m_drawElevation); thing->draw(p - m_drawElevation);
m_drawElevation += type.parameters[ThingType::Elevation]; m_drawElevation += type->parameters[ThingType::Elevation];
if(m_drawElevation > MAX_DRAW_ELEVATION) if(m_drawElevation > MAX_DRAW_ELEVATION)
m_drawElevation = MAX_DRAW_ELEVATION; m_drawElevation = MAX_DRAW_ELEVATION;
} }
@ -54,11 +54,11 @@ void Tile::draw(const Point& p)
// now common items // now common items
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) { for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
const ThingPtr& thing = *it; const ThingPtr& thing = *it;
const ThingType& type = thing->getType(); ThingType *type = thing->getType();
if(thing->asCreature() || type.properties[ThingType::IsOnTop] || type.properties[ThingType::IsOnBottom] || type.properties[ThingType::IsGroundBorder] || type.properties[ThingType::IsGround]) if(thing->asCreature() || type->properties[ThingType::IsOnTop] || type->properties[ThingType::IsOnBottom] || type->properties[ThingType::IsGroundBorder] || type->properties[ThingType::IsGround])
break; break;
thing->draw(p - m_drawElevation); thing->draw(p - m_drawElevation);
m_drawElevation += type.parameters[ThingType::Elevation]; m_drawElevation += type->parameters[ThingType::Elevation];
if(m_drawElevation > MAX_DRAW_ELEVATION) if(m_drawElevation > MAX_DRAW_ELEVATION)
m_drawElevation = MAX_DRAW_ELEVATION; m_drawElevation = MAX_DRAW_ELEVATION;
} }
@ -68,8 +68,8 @@ void Tile::draw(const Point& p)
for(int xi = -1; xi <= 1; ++xi) { for(int xi = -1; xi <= 1; ++xi) {
for(int yi = -1; yi <= 1; ++yi) { for(int yi = -1; yi <= 1; ++yi) {
for(CreaturePtr creature : g_map.getTile(m_position + Position(xi, yi, 0))->getCreatures()) { for(CreaturePtr creature : g_map.getTile(m_position + Position(xi, yi, 0))->getCreatures()) {
const ThingType& type = creature->getType(); ThingType *type = creature->getType();
Rect creatureRect(p.x + xi*32 + creature->getWalkOffset().x - type.parameters[ThingType::DisplacementX], p.y + yi*32 + creature->getWalkOffset().y - type.parameters[ThingType::DisplacementY], 32, 32); Rect creatureRect(p.x + xi*32 + creature->getWalkOffset().x - type->parameters[ThingType::DisplacementX], p.y + yi*32 + creature->getWalkOffset().y - type->parameters[ThingType::DisplacementY], 32, 32);
Rect thisTileRect(p.x, p.y, 32, 32); Rect thisTileRect(p.x, p.y, 32, 32);
// only render creatures where bottom right is inside our rect // only render creatures where bottom right is inside our rect
@ -86,8 +86,8 @@ void Tile::draw(const Point& p)
// top items // top items
for(const ThingPtr& thing : m_things) { for(const ThingPtr& thing : m_things) {
const ThingType& type = thing->getType(); ThingType *type = thing->getType();
if(type.properties[ThingType::IsOnTop]) if(type->properties[ThingType::IsOnTop])
thing->draw(p); thing->draw(p);
} }
} }
@ -179,8 +179,8 @@ ItemPtr Tile::getGround()
ThingPtr firstObject = getThing(0); ThingPtr firstObject = getThing(0);
if(!firstObject) if(!firstObject)
return nullptr; return nullptr;
const ThingType& type = firstObject->getType(); ThingType *type = firstObject->getType();
if(type.properties[ThingType::IsGround]) if(type->properties[ThingType::IsGround])
return firstObject->asItem(); return firstObject->asItem();
return nullptr; return nullptr;
} }
@ -191,8 +191,8 @@ bool Tile::isWalkable()
return false; return false;
for(const ThingPtr& thing : m_things) { for(const ThingPtr& thing : m_things) {
const ThingType& type = thing->getType(); ThingType *type = thing->getType();
if(type.properties[ThingType::NotWalkable]) if(type->properties[ThingType::NotWalkable])
return false; return false;
} }
return true; return true;
@ -203,8 +203,8 @@ bool Tile::isFullGround()
ThingPtr ground = getThing(0); ThingPtr ground = getThing(0);
if(!ground) if(!ground)
return false; return false;
const ThingType& type = ground->getType(); ThingType *type = ground->getType();
if(type.properties[ThingType::IsGround] && type.properties[ThingType::IsFullGround]) if(type->properties[ThingType::IsGround] && type->properties[ThingType::IsFullGround])
return true; return true;
return false; return false;
} }
@ -213,8 +213,8 @@ bool Tile::isFullyOpaque()
{ {
ThingPtr firstObject = getThing(0); ThingPtr firstObject = getThing(0);
if(firstObject) { if(firstObject) {
const ThingType& type = firstObject->getType(); ThingType *type = firstObject->getType();
if(type.properties[ThingType::IsFullGround]) if(type->properties[ThingType::IsFullGround])
return true; return true;
} }
return false; return false;
@ -223,8 +223,8 @@ bool Tile::isFullyOpaque()
bool Tile::isLookPossible() bool Tile::isLookPossible()
{ {
for(const ThingPtr& thing : m_things) { for(const ThingPtr& thing : m_things) {
const ThingType& type = thing->getType(); ThingType *type = thing->getType();
if(type.properties[ThingType::BlockProjectile]) if(type->properties[ThingType::BlockProjectile])
return false; return false;
} }
return true; return true;

View File

@ -1110,8 +1110,8 @@ ItemPtr ProtocolGame::internalGetItem(InputMessage& msg, uint16 id)
id = msg.getU16(); id = msg.getU16();
item->setId(id); item->setId(id);
const ThingType& itemType = item->getType(); ThingType *itemType = item->getType();
if(itemType.properties[ThingType::IsStackable] || itemType.properties[ThingType::IsFluidContainer] || itemType.properties[ThingType::IsFluid]) if(itemType->properties[ThingType::IsStackable] || itemType->properties[ThingType::IsFluidContainer] || itemType->properties[ThingType::IsFluid])
item->setData(msg.getU8()); item->setData(msg.getU8());
return item; return item;