addons, item count, stackpos fix

master
Henrique 13 years ago
parent 10ea2e5de1
commit 9088bad0b0

@ -1,8 +1,6 @@
#include "creature.h" #include "creature.h"
#include "datmanager.h" #include "datmanager.h"
#include <framework/graphics/graphics.h> #include <framework/graphics/graphics.h>
#include <framework/graphics/framebuffer.h>
#include "game.h"
#include <framework/graphics/fontmanager.h> #include <framework/graphics/fontmanager.h>
Creature::Creature() : Thing(THING_CREATURE) Creature::Creature() : Thing(THING_CREATURE)
@ -13,34 +11,41 @@ Creature::Creature() : Thing(THING_CREATURE)
void Creature::draw(int x, int y) void Creature::draw(int x, int y)
{ {
//ThingAttributes *creatureAttributes = getAttributes();
int anim = 0; int anim = 0;
// draw outfit
internalDraw(x, y, 0, m_direction, 0, 0, anim);
const ThingAttributes& attributes = getAttributes(); const ThingAttributes& attributes = getAttributes();
if(attributes.blendframes > 1) { for(int ydiv = 0; ydiv < attributes.ydiv; ydiv++) {
g_graphics.bindBlendFunc(BLEND_COLORIZING);
// continue if we dont have this addon.
for(int mask = 0; mask < 4; ++mask) { if(ydiv > 0 && !(m_outfit.addons & (1 << (ydiv-1))))
continue;
int outfitColorId = 0;
if(mask == SpriteMaskYellow) // draw white item
outfitColorId = m_outfit.head; internalDraw(x, y, 0, m_direction, ydiv, 0, anim);
else if(mask == SpriteMaskRed)
outfitColorId = m_outfit.body; // draw mask if exists
else if(mask == SpriteMaskGreen) if(attributes.blendframes > 1) {
outfitColorId = m_outfit.legs; g_graphics.bindBlendFunc(BLEND_COLORIZING);
else if(mask == SpriteMaskBlue)
outfitColorId = m_outfit.feet;
g_graphics.bindColor(OutfitColors[outfitColorId]);
internalDraw(x, y, 1, m_direction, 0, 0, anim, (SpriteMask)mask);
}
g_graphics.bindBlendFunc(BLEND_NORMAL); for(int mask = 0; mask < 4; ++mask) {
g_graphics.bindColor(Color::white);
int outfitColorId = 0;
if(mask == SpriteMaskYellow)
outfitColorId = m_outfit.head;
else if(mask == SpriteMaskRed)
outfitColorId = m_outfit.body;
else if(mask == SpriteMaskGreen)
outfitColorId = m_outfit.legs;
else if(mask == SpriteMaskBlue)
outfitColorId = m_outfit.feet;
g_graphics.bindColor(OutfitColors[outfitColorId]);
internalDraw(x, y, 1, m_direction, ydiv, 0, anim, (SpriteMask)mask);
}
g_graphics.bindBlendFunc(BLEND_NORMAL);
g_graphics.bindColor(Color::white);
}
} }
} }

@ -1,7 +1,6 @@
#include "item.h" #include "item.h"
#include "datmanager.h" #include "datmanager.h"
#include "spritemanager.h" #include "spritemanager.h"
#include <framework/graphics/graphics.h>
#include "thing.h" #include "thing.h"
Item::Item() : Thing(THING_ITEM) Item::Item() : Thing(THING_ITEM)
@ -15,9 +14,32 @@ void Item::draw(int x, int y)
int xdiv = 0, ydiv = 0, zdiv = 0, anim = 0; int xdiv = 0, ydiv = 0, zdiv = 0, anim = 0;
if(attributes.group == THING_GROUP_SPLASH || attributes.group == THING_GROUP_FLUID || attributes.stackable) { if(attributes.group == THING_GROUP_SPLASH || attributes.group == THING_GROUP_FLUID) {
//cDivX = subType % itemAttributes->xdiv; //xdiv = m_count % attributes.xdiv;
//cDivY = subType / itemAttributes->xdiv; //ydiv = m_count / attributes.ydiv;
}
else if(attributes.stackable) {
if(m_count < 5) {
xdiv = m_count-1;
ydiv = 0;
}
else if(m_count < 10) {
xdiv = 0;
ydiv = 1;
}
else if(m_count < 25) {
xdiv = 1;
ydiv = 1;
}
else if(m_count < 50) {
xdiv = 2;
ydiv = 1;
}
else if(m_count <= 100) {
xdiv = 3;
ydiv = 1;
}
} }
else if(!attributes.moveable) { else if(!attributes.moveable) {
xdiv = m_position.x % attributes.xdiv; xdiv = m_position.x % attributes.xdiv;

@ -40,7 +40,7 @@ void Map::draw(const Rect& rect)
for(int jz = 6; jz >= 0; --jz) { for(int jz = 6; jz >= 0; --jz) {
Position coverPos = Position(playerPos.x+(7-jz)-1, playerPos.y+(7-jz)-1, jz); Position coverPos = Position(playerPos.x+(7-jz)-1, playerPos.y+(7-jz)-1, jz);
if(const TilePtr& tile = m_tiles[coverPos]) { if(const TilePtr& tile = m_tiles[coverPos]) {
if(tile->getStackSize() > 0 && jz < playerPos.z) { if(tile->getStackSize(3) > 0 && jz < playerPos.z) {
drawFloorStop = jz; drawFloorStop = jz;
break; break;
} }
@ -99,7 +99,7 @@ void Map::draw(const Rect& rect)
} }
} }
void Map::addThing(ThingPtr thing, uint8 stackpos) void Map::addThing(ThingPtr thing, int stackpos)
{ {
if(!thing) if(!thing)
return; return;
@ -115,7 +115,7 @@ void Map::addThing(ThingPtr thing, uint8 stackpos)
m_creatures[thing->getId()] = creature; m_creatures[thing->getId()] = creature;
} }
ThingPtr Map::getThing(const Position& pos, uint8 stackpos) ThingPtr Map::getThing(const Position& pos, int stackpos)
{ {
if(const TilePtr& tile = m_tiles[pos]) { if(const TilePtr& tile = m_tiles[pos]) {
return tile->getThing(stackpos); return tile->getThing(stackpos);
@ -123,7 +123,7 @@ ThingPtr Map::getThing(const Position& pos, uint8 stackpos)
return ThingPtr(); return ThingPtr();
} }
void Map::removeThing(const Position& pos, uint8 stackpos) void Map::removeThing(const Position& pos, int stackpos)
{ {
if(TilePtr& tile = m_tiles[pos]) { if(TilePtr& tile = m_tiles[pos]) {
tile->removeThing(stackpos); tile->removeThing(stackpos);

@ -10,9 +10,9 @@ class Map
public: public:
void draw(const Rect& rect); void draw(const Rect& rect);
void addThing(ThingPtr thing, uint8 stackpos = 0); void addThing(ThingPtr thing, int stackpos = -1);
ThingPtr getThing(const Position& pos, uint8 stackpos); ThingPtr getThing(const Position& pos, int stackpos);
void removeThing(const Position& pos, uint8 stackpos); void removeThing(const Position& pos, int stackpos);
void removeThingByPtr(ThingPtr thing); void removeThingByPtr(ThingPtr thing);
void clean(); void clean();

@ -72,8 +72,9 @@ void Tile::draw(int x, int y)
} }
} }
void Tile::addThing(ThingPtr thing, uint8 stackpos) void Tile::addThing(ThingPtr thing, int stackpos)
{ {
// TODO: rework this. that -1 sucks
if(!thing) if(!thing)
return; return;
@ -89,8 +90,13 @@ void Tile::addThing(ThingPtr thing, uint8 stackpos)
else { else {
if(thingAttributes.alwaysOnTop) if(thingAttributes.alwaysOnTop)
m_itemsTop.push_back(thing); m_itemsTop.push_back(thing);
else else {
m_itemsBottom.push_back(thing); if(stackpos == -1)
m_itemsBottom.push_back(thing);
else {
m_itemsBottom.insert(m_itemsBottom.begin()+(stackpos-getStackSize(2)), thing);
}
}
} }
} }
else if(thing->asCreature()) { else if(thing->asCreature()) {
@ -101,7 +107,7 @@ void Tile::addThing(ThingPtr thing, uint8 stackpos)
} }
} }
ThingPtr Tile::getThing(uint8 stackpos) ThingPtr Tile::getThing(unsigned int stackpos)
{ {
if(stackpos == 0) if(stackpos == 0)
return m_ground; return m_ground;
@ -121,7 +127,7 @@ ThingPtr Tile::getThing(uint8 stackpos)
return ThingPtr(); return ThingPtr();
} }
void Tile::removeThing(uint8 stackpos) void Tile::removeThing(unsigned int stackpos)
{ {
if(stackpos == 0) { if(stackpos == 0) {
m_ground.reset(); m_ground.reset();
@ -205,13 +211,20 @@ void Tile::clean()
m_effects.clear(); m_effects.clear();
} }
int Tile::getStackSize() int Tile::getStackSize(int stop)
{ {
int ret = 0; int ret = m_ground ? 1 : 0;
if(m_ground) if(stop == 0)
ret++; return ret;
ret += m_itemsBottom.size();
ret += m_creatures.size();
ret += m_itemsTop.size(); ret += m_itemsTop.size();
if(stop == 1)
return ret;
ret += m_creatures.size();
if(stop == 2)
return ret;
ret += m_itemsBottom.size();
return ret; return ret;
} }

@ -11,16 +11,16 @@ public:
void draw(int x, int y); void draw(int x, int y);
void addThing(ThingPtr thing, uint8 stackpos); void addThing(ThingPtr thing, int stackpos);
ThingPtr getThing(uint8 stackpos); ThingPtr getThing(unsigned int stackpos);
void removeThing(uint8 stackpos); void removeThing(unsigned int stackpos);
void removeThingByPtr(ThingPtr thing); void removeThingByPtr(ThingPtr thing);
void clean(); void clean();
bool hasGround() { return (!!m_ground); } bool hasGround() { return (!!m_ground); }
int getStackSize(); int getStackSize(int stop);
std::deque<ThingPtr> getCreatures() { return m_creatures; } std::deque<ThingPtr> getCreatures() { return m_creatures; }
int getDrawNextOffset() { return m_drawNextOffset; } int getDrawNextOffset() { return m_drawNextOffset; }

@ -923,7 +923,7 @@ void ProtocolGame::setTileDescription(InputMessage& msg, Position position)
ThingPtr thing = internalGetThing(msg); ThingPtr thing = internalGetThing(msg);
if(thing) if(thing)
thing->setPosition(position); thing->setPosition(position);
g_map.addThing(thing, stackpos); g_map.addThing(thing);
} }
stackpos++; stackpos++;
} }

Loading…
Cancel
Save