look improvements

master
Henrique Santiago 13 years ago
parent 9104305f37
commit a52ff707fe

@ -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

@ -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)

@ -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();

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

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

@ -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; }

Loading…
Cancel
Save