Skip to content

Commit

Permalink
some bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah committed Jul 5, 2020
1 parent a8ba6e5 commit 9036ad3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 65 deletions.
88 changes: 41 additions & 47 deletions src/client/tile.cpp
Expand Up @@ -82,11 +82,9 @@ void Tile::drawBottom(const Point& dest, float scaleFactor, LightView* lightView
), scaleFactor, lightView);
}

for(auto it = m_creatures.rbegin(); it != m_creatures.rend(); ++it) {
const auto& creature = *it;
if(!creature->isWalking()) {
creature->draw(dest - m_drawElevation * scaleFactor, scaleFactor, lightView);
}
for(const auto& creature : m_creatures) {
if(creature->isWalking()) continue;
creature->draw(dest - m_drawElevation * scaleFactor, scaleFactor, lightView);
}
}

Expand Down Expand Up @@ -173,7 +171,6 @@ void Tile::addThing(const ThingPtr& thing, int stackPos)
append = !append;
}


for(stackPos = 0; stackPos < size; ++stackPos) {
const int otherPriority = m_things[stackPos]->getStackPriority();
if((append && otherPriority > priority) || (!append && otherPriority >= priority))
Expand Down Expand Up @@ -313,10 +310,7 @@ ThingPtr Tile::getTopThing()
if(isEmpty())
return nullptr;

const ThingPtr& topComumItem = m_commonItems.front();
if(topComumItem) {
return topComumItem;
}
if(!m_commonItems.empty()) return m_commonItems.front();

return m_things[m_things.size() - 1];
}
Expand All @@ -337,10 +331,7 @@ std::vector<ItemPtr> Tile::getItems()

ItemPtr Tile::getGround()
{
if(!m_grounds.empty()) {
const auto& ground = m_grounds[0];
if(ground->isGround()) return ground;
}
if(!m_grounds.empty()) return m_grounds.front();

return nullptr;
}
Expand All @@ -350,35 +341,35 @@ EffectPtr Tile::getEffect(uint16 id)
for(const EffectPtr& effect : m_effects)
if(effect->getId() == id)
return effect;

return nullptr;
}

int Tile::getGroundSpeed()
{
int groundSpeed = 100;
if(const ItemPtr& ground = getGround())
groundSpeed = ground->getGroundSpeed();
return ground->getGroundSpeed();

return groundSpeed;
return 100;
}

uint8 Tile::getMinimapColorByte()
{
if(m_minimapColor != 0)
return m_minimapColor;

for(const ItemPtr& item : m_topItems) {
if(!item->isIgnoreLook()) return item->getMinimapColor();
if(!m_topItems.empty()) {
const uint8 c = m_topItems.back()->getMinimapColor();
if(c != 0) return c;
}

for(auto it = m_bottomItems.rbegin(); it != m_bottomItems.rend(); ++it) {
const ItemPtr& item = *it;
if(!item->isIgnoreLook()) return item->getMinimapColor();
if(!m_bottomItems.empty()) {
const uint8 c = m_bottomItems.back()->getMinimapColor();
if(c != 0) return c;
}

for(auto it = m_grounds.rbegin(); it != m_grounds.rend(); ++it) {
const ItemPtr& item = *it;
const uint8 c = item->getMinimapColor();
if(!m_grounds.empty()) {
const uint8 c = m_grounds.back()->getMinimapColor();
if(c != 0) return c;
}

Expand All @@ -387,7 +378,16 @@ uint8 Tile::getMinimapColorByte()

ThingPtr Tile::getTopLookThing()
{
for(const ItemPtr& item : m_commonItems) {
if(isEmpty()) return nullptr;

for(auto it = m_topItems.rbegin(); it != m_topItems.rend(); ++it) {
const ItemPtr& item = *it;
if(!item->isIgnoreLook()) return item;
}

if(!m_creatures.empty()) return m_creatures.back();

for(const auto& item : m_commonItems) {
if(!item->isIgnoreLook()) return item;
}

Expand All @@ -408,7 +408,7 @@ ThingPtr Tile::getTopUseThing()
{
if(isEmpty()) return nullptr;

for(const auto& item : m_bottomItems) {
for(const auto& item : m_commonItems) {
if(item->isForceUse()) return item;
}

Expand All @@ -422,6 +422,7 @@ ThingPtr Tile::getTopUseThing()
if(item->isForceUse()) return item;
}

if(!m_topItems.empty()) return m_topItems.back();
if(!m_commonItems.empty()) return m_commonItems.front();
if(!m_bottomItems.empty()) return m_bottomItems.back();

Expand All @@ -432,7 +433,7 @@ CreaturePtr Tile::getTopCreature()
{
const CreaturePtr creature;
if(!m_creatures.empty())
return m_creatures.front();
return m_creatures.back();

if(!m_walkingCreatures.empty())
return m_walkingCreatures.back();
Expand Down Expand Up @@ -468,20 +469,14 @@ ThingPtr Tile::getTopMoveThing()
if(!thing->isNotMoveable()) return thing;
}

for(auto it = m_bottomItems.rbegin(); it != m_bottomItems.rend(); ++it) {
const ItemPtr& thing = *it;
if(!thing->isNotMoveable()) return thing;
}

if(hasCreature()) return m_creatures.front();
if(hasCreature()) return m_creatures.back();

return nullptr;
}

ThingPtr Tile::getTopMultiUseThing()
{
if(isEmpty())
return nullptr;
if(isEmpty()) return nullptr;

if(CreaturePtr topCreature = getTopCreature())
return topCreature;
Expand All @@ -495,7 +490,12 @@ ThingPtr Tile::getTopMultiUseThing()
if(thing->isMultiUse()) return thing;
}

return m_things[0];
if(!m_grounds.empty()) {
const ItemPtr& ground = m_grounds.front();
if(ground->isMultiUse()) return ground;
}

return nullptr;
}

bool Tile::isWalkable(bool ignoreCreatures)
Expand Down Expand Up @@ -605,13 +605,7 @@ bool Tile::hasElevation(int elevation)

bool Tile::hasLight()
{
if(m_countFlag.hasLight > 0) return true;

for(const CreaturePtr& creature : m_creatures) {
if(creature->hasLight()) return true;
}

return false;
return m_countFlag.hasLight > 0;
}

void Tile::checkTranslucentLight()
Expand Down Expand Up @@ -653,6 +647,9 @@ void Tile::analyzeThing(const ThingPtr& thing, bool add)
if(thing->getHeight() != 1 || thing->getWidth() != 1)
m_countFlag.notSingleDimension += value;

if(thing->hasLight())
m_countFlag.hasLight += value;

if(!thing->isItem()) return;

if(thing->isNotWalkable())
Expand Down Expand Up @@ -684,9 +681,6 @@ void Tile::analyzeThing(const ThingPtr& thing, bool add)
if(thing->isOpaque())
m_countFlag.opaque += value;

if(thing->hasLight())
m_countFlag.hasLight += value;

// Check that the item is opaque, so that it does not draw anything that is less than or equal below it.
if(thing->isOpaque() && !thing->isOnTop() && !thing->isGround() && !thing->isGroundBorder()) {
const int commonSize = m_commonItems.size();
Expand Down
36 changes: 18 additions & 18 deletions src/framework/core/filestream.cpp
Expand Up @@ -26,7 +26,7 @@

#include <physfs.h>

FileStream::FileStream(const std::string& name, PHYSFS_File *fileHandle, bool writeable) :
FileStream::FileStream(const std::string& name, PHYSFS_File* fileHandle, bool writeable) :
m_name(name),
m_fileHandle(fileHandle),
m_pos(0),
Expand Down Expand Up @@ -106,7 +106,7 @@ void FileStream::flush()
}
}

int FileStream::read(void *buffer, uint32 size, uint32 nmemb)
int FileStream::read(void* buffer, uint32 size, uint32 nmemb)
{
if(!m_caching) {
int res = PHYSFS_readBytes(m_fileHandle, buffer, size * nmemb);
Expand All @@ -115,19 +115,19 @@ int FileStream::read(void *buffer, uint32 size, uint32 nmemb)
return res;
} else {
int writePos = 0;
uint8 *outBuffer = static_cast<uint8*>(buffer);
for(uint i=0;i<nmemb;++i) {
if(m_pos+size > m_data.size())
uint8* outBuffer = static_cast<uint8*>(buffer);
for(uint i = 0; i < nmemb; ++i) {
if(m_pos + size > m_data.size())
return i;

for(uint j=0;j<size;++j)
for(uint j = 0; j < size; ++j)
outBuffer[writePos++] = m_data[m_pos++];
}
return nmemb;
}
}

void FileStream::write(const void *buffer, uint32 count)
void FileStream::write(const void* buffer, uint32 count)
{
if(!m_caching) {
if(PHYSFS_writeBytes(m_fileHandle, buffer, count) != count)
Expand Down Expand Up @@ -187,7 +187,7 @@ uint8 FileStream::getU8()
if(PHYSFS_readBytes(m_fileHandle, &v, 1) != 1)
throwError("read failed", true);
} else {
if(m_pos+1 > m_data.size())
if(m_pos + 1 > m_data.size())
throwError("read failed");

v = m_data[m_pos];
Expand All @@ -203,7 +203,7 @@ uint16 FileStream::getU16()
if(PHYSFS_readULE16(m_fileHandle, &v) == 0)
throwError("read failed", true);
} else {
if(m_pos+2 > m_data.size())
if(m_pos + 2 > m_data.size())
throwError("read failed");

v = stdext::readULE16(&m_data[m_pos]);
Expand All @@ -219,7 +219,7 @@ uint32 FileStream::getU32()
if(PHYSFS_readULE32(m_fileHandle, &v) == 0)
throwError("read failed", true);
} else {
if(m_pos+4 > m_data.size())
if(m_pos + 4 > m_data.size())
throwError("read failed");

v = stdext::readULE32(&m_data[m_pos]);
Expand All @@ -232,10 +232,10 @@ uint64 FileStream::getU64()
{
uint64 v = 0;
if(!m_caching) {
if(PHYSFS_readULE64(m_fileHandle, static_cast<PHYSFS_uint64*>(&v)) == 0)
if(PHYSFS_readULE64(m_fileHandle, (PHYSFS_uint64*)&v) == 0)
throwError("read failed", true);
} else {
if(m_pos+8 > m_data.size())
if(m_pos + 8 > m_data.size())
throwError("read failed");
v = stdext::readULE64(&m_data[m_pos]);
m_pos += 8;
Expand All @@ -250,7 +250,7 @@ int8 FileStream::get8()
if(PHYSFS_readBytes(m_fileHandle, &v, 1) != 1)
throwError("read failed", true);
} else {
if(m_pos+1 > m_data.size())
if(m_pos + 1 > m_data.size())
throwError("read failed");

v = m_data[m_pos];
Expand All @@ -266,7 +266,7 @@ int16 FileStream::get16()
if(PHYSFS_readSLE16(m_fileHandle, &v) == 0)
throwError("read failed", true);
} else {
if(m_pos+2 > m_data.size())
if(m_pos + 2 > m_data.size())
throwError("read failed");

v = stdext::readSLE16(&m_data[m_pos]);
Expand All @@ -282,7 +282,7 @@ int32 FileStream::get32()
if(PHYSFS_readSLE32(m_fileHandle, &v) == 0)
throwError("read failed", true);
} else {
if(m_pos+4 > m_data.size())
if(m_pos + 4 > m_data.size())
throwError("read failed");

v = stdext::readSLE32(&m_data[m_pos]);
Expand All @@ -295,10 +295,10 @@ int64 FileStream::get64()
{
int64 v = 0;
if(!m_caching) {
if(PHYSFS_readSLE64(m_fileHandle, static_cast<PHYSFS_sint64*>(&v)) == 0)
if(PHYSFS_readSLE64(m_fileHandle, (PHYSFS_sint64*)&v) == 0)
throwError("read failed", true);
} else {
if(m_pos+8 > m_data.size())
if(m_pos + 8 > m_data.size())
throwError("read failed");
v = stdext::readSLE64(&m_data[m_pos]);
m_pos += 8;
Expand All @@ -318,7 +318,7 @@ std::string FileStream::getString()
else
str = std::string(buffer, len);
} else {
if(m_pos+len > m_data.size()) {
if(m_pos + len > m_data.size()) {
throwError("read failed");
return nullptr;
}
Expand Down

0 comments on commit 9036ad3

Please sign in to comment.