look improvements

This commit is contained in:
Henrique Santiago 2012-01-02 17:01:48 -02:00
parent 9104305f37
commit a52ff707fe
6 changed files with 60 additions and 49 deletions

View File

@ -32,7 +32,6 @@ end
-- hooked events -- hooked events
function TextMessage.onTextMessage(type, message) function TextMessage.onTextMessage(type, message)
local messageType = messageTypes[type - messageTypes.first] local messageType = messageTypes[type - messageTypes.first]
print(messageType.color)
if messageType.showOnConsole then if messageType.showOnConsole then
-- TODO -- TODO

View File

@ -158,13 +158,22 @@ void Game::turn(Otc::Direction direction)
void Game::look(const Position& position) void Game::look(const Position& position)
{ {
const TilePtr& tile = g_map.getTile(position); Position tilePos = position;
if(tile) { TilePtr tile = nullptr;
int stackpos = tile->getLookStackpos(); int stackpos = -1;
ThingPtr thing = tile->getThing(stackpos);
if(thing) while(true) {
m_protocolGame->sendLookAt(position, thing->getId(), stackpos); tile = g_map.getTile(tilePos);
stackpos = tile->getLookStackpos();
if(stackpos != -1 || tilePos.z >= Map::MAX_Z)
break;
tilePos.coveredDown();
} }
ThingPtr thing = tile->getThing(stackpos);
if(thing)
m_protocolGame->sendLookAt(tilePos, thing->getId(), stackpos);
} }
void Game::talkChannel(int channelType, int channelId, const std::string& message) void Game::talkChannel(int channelType, int channelId, const std::string& message)

View File

@ -183,10 +183,13 @@ ItemPtr Tile::getGround()
int Tile::getLookStackpos() int Tile::getLookStackpos()
{ {
// TODO: this needs to be improved for(int i = m_things.size() - 1; i >= 0; --i) {
// check if thing has look property. ThingType *type = m_things[i]->getType();
// check other floors if(!type->properties[ThingType::IgnoreLook] &&
return m_things.size() - 1; (type->properties[ThingType::IsGround] || type->properties[ThingType::IsGroundBorder] || type->properties[ThingType::IsOnBottom] || type->properties[ThingType::IsOnTop]))
return i;
}
return -1;
} }
bool Tile::isWalkable() bool Tile::isWalkable()
@ -247,6 +250,11 @@ bool Tile::hasCreature()
return false; return false;
} }
bool Tile::isEmpty()
{
return m_things.size() == 0;
}
/*bool Tile::canAttack() /*bool Tile::canAttack()
{ {
return hasCreature(); return hasCreature();

View File

@ -52,6 +52,7 @@ public:
bool isFullyOpaque(); bool isFullyOpaque();
bool isLookPossible(); bool isLookPossible();
bool hasCreature(); bool hasCreature();
bool isEmpty();
void useItem(); void useItem();

View File

@ -58,50 +58,44 @@ void UIMap::onStyleApply(const OTMLNodePtr& styleNode)
bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button) bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
{ {
if(m_mapRect.contains(mousePos)) { if(!m_mapRect.contains(mousePos))
Point relativeStretchMousePos = mousePos - m_mapRect.topLeft(); return UIWidget::onMousePress(mousePos, button);
Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS);
PointF stretchFactor(m_mapRect.width() / (float)mapSize.width(), m_mapRect.height() / (float)mapSize.height()); // Get tile position
PointF relativeMousePos = PointF(relativeStretchMousePos.x, relativeStretchMousePos.y) / stretchFactor; Point relativeStretchMousePos = mousePos - m_mapRect.topLeft();
Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS);
PointF tilePosF = relativeMousePos / Map::NUM_TILE_PIXELS; PointF stretchFactor(m_mapRect.width() / (float)mapSize.width(), m_mapRect.height() / (float)mapSize.height());
Position tilePos = Position(1 + (int)tilePosF.x - g_map.getCentralOffset().x, 1 + (int)tilePosF.y - g_map.getCentralOffset().y, 0) + g_map.getCentralPosition(); PointF relativeMousePos = PointF(relativeStretchMousePos.x, relativeStretchMousePos.y) / stretchFactor;
TilePtr tile = g_map.getTile(tilePos); PointF tilePosF = relativeMousePos / Map::NUM_TILE_PIXELS;
if(tile) Position tilePos = Position(1 + (int)tilePosF.x - g_map.getCentralOffset().x, 1 + (int)tilePosF.y - g_map.getCentralOffset().y, 0) + g_map.getCentralPosition();
tile->useItem();
// cool testing \/ // Get tile
if(button == Fw::MouseLeftButton) { TilePtr tile = nullptr;
MissilePtr shot = MissilePtr(new Missile());
shot->setId(1);
shot->setPath(g_map.getCentralPosition(), tilePos);
g_map.addThing(shot, g_map.getCentralPosition());
AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); // We must check every floor, from top to bottom
animatedText->setPosition(g_map.getCentralPosition()); int firstFloor = g_map.getFirstVisibleFloor();
animatedText->setColor(12); tilePos.perspectiveUp(tilePos.z - firstFloor);
animatedText->setText("text"); for(int i = firstFloor; i <= Map::MAX_Z; i++) {
tile = g_map.getTile(tilePos);
g_map.addThing(animatedText, g_map.getCentralPosition()); if(!tile->isEmpty())
} break;
else if(button == Fw::MouseRightButton) { tilePos.coveredDown();
EffectPtr effect = EffectPtr(new Effect());
effect->setId(6);
g_map.addThing(effect, tilePos);
AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText);
animatedText->setPosition(g_map.getCentralPosition());
animatedText->setColor(12);
animatedText->setText("8");
g_map.addThing(animatedText, g_map.getCentralPosition());
g_game.look(tilePos);
}
} }
return UIWidget::onMousePress(mousePos, button); if(!tile || tile->isEmpty())
return true;
//tile->useItem();
if(button == Fw::MouseLeftButton) {
}
else if(button == Fw::MouseRightButton) {
g_game.look(tilePos);
}
return true;
} }
void UIMap::onGeometryUpdate(const Rect& oldRect, const Rect& newRect) void UIMap::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)

View File

@ -98,7 +98,7 @@ public:
return Otc::InvalidDirection; return Otc::InvalidDirection;
} }
bool isValid() const { return x >= 0 && y >= 0 && z >= 0 && x < 65536 && y < 65536 && z < 15; } bool isValid() const { return x >= 0 && y >= 0 && z >= 0 && x < 65536 && y < 65536 && z < 16; }
Position operator+(const Position& other) const { return Position(x + other.x, y + other.y, z + other.z); } Position operator+(const Position& other) const { return Position(x + other.x, y + other.y, z + other.z); }
Position& operator+=(const Position& other) { x+=other.x; y+=other.y; z +=other.z; return *this; } Position& operator+=(const Position& other) { x+=other.x; y+=other.y; z +=other.z; return *this; }