some rework

This commit is contained in:
Henrique Santiago 2011-12-30 12:15:23 -02:00
parent ded2133e7c
commit 88f36b0455
7 changed files with 93 additions and 36 deletions

View File

@ -45,7 +45,7 @@ public:
void setSkull(uint8 skull) { m_skull = skull; }
void setShield(uint8 shield) { m_shield = shield; }
void setEmblem(uint8 emblem) { m_emblem = emblem; }
void setImpassable(bool impassable) { m_impassable = impassable; }
void setPassable(bool passable) { m_passable = passable; }
void setSquareColor(uint8 squareColor) { m_squareColor = squareColor; }
std::string getName() { return m_name; }
@ -57,7 +57,7 @@ public:
uint8 getSkull() { return m_skull; }
uint8 getShield() { return m_shield; }
uint8 getEmblem() { return m_emblem; }
bool getImpassable() { return m_impassable; }
bool getPassable() { return m_passable; }
ThingType *getType();
virtual void walk(const Position& position, bool inverse = true);
@ -82,7 +82,7 @@ protected:
uint8 m_skull;
uint8 m_shield;
uint8 m_emblem;
bool m_impassable;
bool m_passable;
uint8 m_squareColor;
bool m_showSquareColor;

View File

@ -47,7 +47,7 @@ void Effect::start()
// schedule removal
g_dispatcher.scheduleEvent([self]() {
g_map.getTile(self->getPosition())->removeEffect(self);
g_map.removeThing(self);
}, TICKS_PER_FRAME * getAnimationPhases());
}

View File

@ -245,9 +245,6 @@ void Map::addThing(const ThingPtr& thing, const Position& pos, int stackPos)
tile->addThing(thing, stackPos);
m_creatures[creature->getId()] = creature;
}
else if(EffectPtr effect = thing->asEffect()) {
tile->addEffect(effect);
}
else if(MissilePtr shot = thing->asMissile()) {
m_missilesAtFloor[shot->getPosition().z].push_back(shot);
}

View File

@ -98,25 +98,16 @@ void Tile::clean()
m_effects.clear();
}
void Tile::addEffect(const EffectPtr& effect)
{
m_effects.push_back(effect);
effect->setPosition(m_position);
}
void Tile::removeEffect(const EffectPtr& effect)
{
auto it = std::find(m_effects.begin(), m_effects.end(), effect);
if(it != m_effects.end()) {
m_effects.erase(it);
}
}
ThingPtr Tile::addThing(const ThingPtr& thing, int stackPos)
{
if(!thing)
return nullptr;
if(EffectPtr effect = thing->asEffect()) {
m_effects.push_back(effect);
return nullptr;
}
if(stackPos < 0) {
stackPos = 0;
int priority = thing->getStackPriority();
@ -154,6 +145,12 @@ ThingPtr Tile::removeThing(int stackPos)
ThingPtr Tile::removeThing(const ThingPtr& thing)
{
if(EffectPtr effect = thing->asEffect()) {
auto it = std::find(m_effects.begin(), m_effects.end(), effect);
if(it != m_effects.end())
m_effects.erase(it);
return thing;
}
ThingPtr oldObject;
auto it = std::find(m_things.begin(), m_things.end(), thing);
if(it != m_things.end()) {
@ -193,6 +190,11 @@ bool Tile::isWalkable()
ThingType *type = thing->getType();
if(type->properties[ThingType::NotWalkable])
return false;
if(CreaturePtr creature = thing->asCreature()) {
if(!creature->getPassable())
return false;
}
}
return true;
}
@ -229,13 +231,78 @@ bool Tile::isLookPossible()
return true;
}
bool Tile::hasCreature()
{
for(const ThingPtr& thing : m_things)
if(thing->asCreature())
return true;
return false;
}
/*bool Tile::canAttack()
{
return hasCreature();
}
bool Tile::canFollow()
{
return hasCreature();
}
bool Tile::canCopyName()
{
return hasCreature();
}*/
// TODO:
/*
//Ranges for ID Creatures
#define PLAYER_ID_RANGE 0x10000000
#define MONSTER_ID_RANGE 0x40000000
#define NPC_ID_RANGE 0x80000000
Get menu options
if invited to party
if creature, attack and follow
if item, use or use with
if creature:
Look
-----
Attack
Follow
-----
Copy Name
if item:
Look
Use (if not container)
Open (if container)
Use with ... (if multiuse?)
Rotate (if rotable)
-----
Trade with ... (if pickupable?)
if player:
Look
-----
Attack
Follow
-----
Message to NAME
Add to VIP list
Ignore NAME
Invite to Party
-----
Report Offense
-----
Copy Name
if localplayer:
Look
-----
Set Outfit
-----
Copy Name
*/
void Tile::useItem()

View File

@ -37,8 +37,6 @@ public:
void draw(const Point& p);
void clean();
void addEffect(const EffectPtr& effect);
void removeEffect(const EffectPtr& effect);
ThingPtr addThing(const ThingPtr& thing, int stackPos = -1);
ThingPtr getThing(int stackPos);
ThingPtr removeThing(int stackPos);
@ -52,13 +50,14 @@ public:
bool isFullGround();
bool isFullyOpaque();
bool isLookPossible();
bool hasCreature();
void useItem();
TilePtr asTile() { return std::static_pointer_cast<Tile>(shared_from_this()); }
private:
std::vector<EffectPtr> m_effects;
std::vector<EffectPtr> m_effects; // Leave this outside m_things because it has no stackpos.
std::vector<ThingPtr> m_things;
Position m_position;
int m_drawElevation;

View File

@ -847,8 +847,6 @@ void ProtocolGame::parseCancelWalk(InputMessage& msg)
void ProtocolGame::parseFloorChangeUp(InputMessage& msg)
{
logTraceDebug("this function has never been tested.");
Position pos = g_map.getCentralPosition();
pos.z--;
@ -866,8 +864,6 @@ void ProtocolGame::parseFloorChangeUp(InputMessage& msg)
void ProtocolGame::parseFloorChangeDown(InputMessage& msg)
{
logTraceDebug("this function has never been tested.");
Position pos = g_map.getCentralPosition();
pos.z++;
@ -1108,7 +1104,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
if(thingId == 0x0061) // emblem is sent only in packet type 0x61
emblem = msg.getU8();
bool impassable = (msg.getU8() == 0); // impassable
bool passable = (msg.getU8() == 0);
creature->setHealthPercent(healthPercent);
creature->setDirection(direction);
@ -1118,7 +1114,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
creature->setSkull(skull);
creature->setShield(shield);
creature->setEmblem(emblem);
creature->setImpassable(impassable);
creature->setPassable(passable);
creature->cancelWalk(direction);
thing = creature;

View File

@ -88,9 +88,7 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
else if(button == Fw::MouseRightButton) {
EffectPtr effect = EffectPtr(new Effect());
effect->setId(6);
effect->start();
if(tile)
tile->addEffect(effect);
g_map.addThing(effect, tilePos);
AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText);
animatedText->setPosition(g_map.getCentralPosition());