Skip to content

Commit

Permalink
* Perspective fixed!!! Now you'll see floors right as you see in the …
Browse files Browse the repository at this point in the history
…Official Client.
  • Loading branch information
Alexander Severino committed Mar 3, 2010
1 parent c3558b6 commit c7e27e3
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 6 deletions.
36 changes: 36 additions & 0 deletions gamecontent/map.cpp
Expand Up @@ -288,6 +288,42 @@ bool Tile::isTileBlocking() const
return false;
}

bool Tile::isWall() const
{
int pos = 0;
for(; pos != getThingCount(); ++pos) {
const Thing* thing = getThingByStackPos(pos);
if(!thing)
return false;

const Item* item = thing->getItem();

if(item)
if(pos == 1 && (item->getObjectType()->isHorizontal || item->getObjectType()->isVertical))
return true;
}

return false;
}

bool Tile::canSeeThrough() const
{
int pos = 0;
for(; pos != getThingCount(); ++pos) {
const Thing* thing = getThingByStackPos(pos);
if(!thing)
return false;

const Item* item = thing->getItem();

if(item)
if(item->getObjectType()->blockProjectile)
return false;
}

return true;
}

const Item* Tile::getGround() const
{
return m_ground;
Expand Down
3 changes: 3 additions & 0 deletions gamecontent/map.h
Expand Up @@ -177,6 +177,9 @@ class Tile{

bool blockPath() const;

bool isWall() const;
bool canSeeThrough() const;

private:
Item* m_ground;
ThingVector m_objects;
Expand Down
2 changes: 1 addition & 1 deletion gm_gameworld.cpp
Expand Up @@ -1482,7 +1482,7 @@ void GM_Gameworld::onCreatureMove(uint32_t id, const Position& oldPos, const Pos
}
if(id == GlobalVariables::getPlayerID())
{
m_mapui.getMinZ();
m_mapui.getMinZ(newPos);
}
}

Expand Down
40 changes: 36 additions & 4 deletions mapui.cpp
Expand Up @@ -673,19 +673,51 @@ void MapUI::drawPrivateMessages()
g_engine->drawTextGW(text.c_str() , "gamefont", x, y, scale, (*it).getColor());
}

int MapUI::getMinZ() { // find out how far can we render... if anything is directly above player, then don't render above that floor
Position pos = GlobalVariables::getPlayerPosition();
const Tile* tile = Map::getInstance().getTile(pos.x, pos.y, pos.z);
int MapUI::getMinZ(Position pos) {

// NOTE (Kilouco): It works, don't ask me how. Just believe me.
const Tile* tile = Map::getInstance().getTile(pos.x, pos.y, pos.z);
const Tile* tile_perspective = Map::getInstance().getTile(pos.x, pos.y, pos.z);
int minz = 0;

// See if there is anything right above player (perspectively).
for (int z = pos.z-1; z>=0; z--) {
tile = Map::getInstance().getTile(pos.x, pos.y, z);
if (tile && tile->getThingCount()) {
minz = z+1;

return (m_minz = minz);
}
}

// Now see if is there anything above player not perspectively but just blocking his view.
for (int z = pos.z-1; z>=0; z--) {
tile = Map::getInstance().getTile(pos.x-(z-pos.z), pos.y-(z-pos.z), z);
if (tile && tile->getThingCount() ) {
if (tile && tile->getThingCount()) {
minz = z+1;

return (m_minz = minz);
}
}

// Last but not least: we take a look around.
for (int z = pos.z-1; z>=0; z--) {
for (int y = -1; y <= 1; y++)
for (int x = -1; x <= 1; x++) {

if((x != 0 && y != 0) || (x == 0 && y == 0))
continue;

tile = Map::getInstance().getTile(pos.x + x, pos.y + y, pos.z);
tile_perspective = Map::getInstance().getTile(pos.x + x, pos.y + y, z);

if (tile && tile_perspective)
if (tile->canSeeThrough() && (tile_perspective->getGround() || tile_perspective->getThingCount())) {
minz = z+1;
return (m_minz = minz);
}
}
}
return (m_minz = 0);
}

Expand Down
4 changes: 3 additions & 1 deletion mapui.h
Expand Up @@ -24,6 +24,8 @@
#include "gamecontent/map.h"
#include "popup.h"

#include "gamecontent/globalvars.h"

struct vertex;

class MapUI {
Expand Down Expand Up @@ -57,7 +59,7 @@ class MapUI {
std::list<Direction> getPathTo(int scrx, int scry);


int getMinZ();
int getMinZ(Position pos = GlobalVariables::getPlayerPosition());
void drawPublicMessages(Position pos, float walkoffx, float walkoffy);
void drawPrivateMessages();

Expand Down

0 comments on commit c7e27e3

Please sign in to comment.