look improvements
This commit is contained in:
parent
9104305f37
commit
a52ff707fe
|
@ -32,7 +32,6 @@ end
|
|||
-- hooked events
|
||||
function TextMessage.onTextMessage(type, message)
|
||||
local messageType = messageTypes[type - messageTypes.first]
|
||||
print(messageType.color)
|
||||
|
||||
if messageType.showOnConsole then
|
||||
-- TODO
|
||||
|
|
|
@ -158,13 +158,22 @@ void Game::turn(Otc::Direction direction)
|
|||
|
||||
void Game::look(const Position& position)
|
||||
{
|
||||
const TilePtr& tile = g_map.getTile(position);
|
||||
if(tile) {
|
||||
int stackpos = tile->getLookStackpos();
|
||||
ThingPtr thing = tile->getThing(stackpos);
|
||||
if(thing)
|
||||
m_protocolGame->sendLookAt(position, thing->getId(), stackpos);
|
||||
Position tilePos = position;
|
||||
TilePtr tile = nullptr;
|
||||
int stackpos = -1;
|
||||
|
||||
while(true) {
|
||||
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)
|
||||
|
|
|
@ -183,10 +183,13 @@ ItemPtr Tile::getGround()
|
|||
|
||||
int Tile::getLookStackpos()
|
||||
{
|
||||
// TODO: this needs to be improved
|
||||
// check if thing has look property.
|
||||
// check other floors
|
||||
return m_things.size() - 1;
|
||||
for(int i = m_things.size() - 1; i >= 0; --i) {
|
||||
ThingType *type = m_things[i]->getType();
|
||||
if(!type->properties[ThingType::IgnoreLook] &&
|
||||
(type->properties[ThingType::IsGround] || type->properties[ThingType::IsGroundBorder] || type->properties[ThingType::IsOnBottom] || type->properties[ThingType::IsOnTop]))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool Tile::isWalkable()
|
||||
|
@ -247,6 +250,11 @@ bool Tile::hasCreature()
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Tile::isEmpty()
|
||||
{
|
||||
return m_things.size() == 0;
|
||||
}
|
||||
|
||||
/*bool Tile::canAttack()
|
||||
{
|
||||
return hasCreature();
|
||||
|
|
|
@ -52,6 +52,7 @@ public:
|
|||
bool isFullyOpaque();
|
||||
bool isLookPossible();
|
||||
bool hasCreature();
|
||||
bool isEmpty();
|
||||
|
||||
void useItem();
|
||||
|
||||
|
|
|
@ -58,50 +58,44 @@ void UIMap::onStyleApply(const OTMLNodePtr& styleNode)
|
|||
|
||||
bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
|
||||
{
|
||||
if(m_mapRect.contains(mousePos)) {
|
||||
Point relativeStretchMousePos = mousePos - m_mapRect.topLeft();
|
||||
Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS);
|
||||
if(!m_mapRect.contains(mousePos))
|
||||
return UIWidget::onMousePress(mousePos, button);
|
||||
|
||||
PointF stretchFactor(m_mapRect.width() / (float)mapSize.width(), m_mapRect.height() / (float)mapSize.height());
|
||||
PointF relativeMousePos = PointF(relativeStretchMousePos.x, relativeStretchMousePos.y) / stretchFactor;
|
||||
// Get tile position
|
||||
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;
|
||||
Position tilePos = Position(1 + (int)tilePosF.x - g_map.getCentralOffset().x, 1 + (int)tilePosF.y - g_map.getCentralOffset().y, 0) + g_map.getCentralPosition();
|
||||
PointF stretchFactor(m_mapRect.width() / (float)mapSize.width(), m_mapRect.height() / (float)mapSize.height());
|
||||
PointF relativeMousePos = PointF(relativeStretchMousePos.x, relativeStretchMousePos.y) / stretchFactor;
|
||||
|
||||
TilePtr tile = g_map.getTile(tilePos);
|
||||
if(tile)
|
||||
tile->useItem();
|
||||
PointF tilePosF = relativeMousePos / Map::NUM_TILE_PIXELS;
|
||||
Position tilePos = Position(1 + (int)tilePosF.x - g_map.getCentralOffset().x, 1 + (int)tilePosF.y - g_map.getCentralOffset().y, 0) + g_map.getCentralPosition();
|
||||
|
||||
// cool testing \/
|
||||
if(button == Fw::MouseLeftButton) {
|
||||
MissilePtr shot = MissilePtr(new Missile());
|
||||
shot->setId(1);
|
||||
shot->setPath(g_map.getCentralPosition(), tilePos);
|
||||
g_map.addThing(shot, g_map.getCentralPosition());
|
||||
// Get tile
|
||||
TilePtr tile = nullptr;
|
||||
|
||||
AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText);
|
||||
animatedText->setPosition(g_map.getCentralPosition());
|
||||
animatedText->setColor(12);
|
||||
animatedText->setText("text");
|
||||
|
||||
g_map.addThing(animatedText, g_map.getCentralPosition());
|
||||
}
|
||||
else if(button == Fw::MouseRightButton) {
|
||||
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);
|
||||
}
|
||||
// We must check every floor, from top to bottom
|
||||
int firstFloor = g_map.getFirstVisibleFloor();
|
||||
tilePos.perspectiveUp(tilePos.z - firstFloor);
|
||||
for(int i = firstFloor; i <= Map::MAX_Z; i++) {
|
||||
tile = g_map.getTile(tilePos);
|
||||
if(!tile->isEmpty())
|
||||
break;
|
||||
tilePos.coveredDown();
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -98,7 +98,7 @@ public:
|
|||
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) { x+=other.x; y+=other.y; z +=other.z; return *this; }
|
||||
|
|
Loading…
Reference in New Issue