Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
marksamman committed Jan 1, 2014
1 parent f76349e commit 73c3cc6
Show file tree
Hide file tree
Showing 29 changed files with 115 additions and 146 deletions.
2 changes: 1 addition & 1 deletion src/beds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool BedItem::serializeAttr(PropWriteStream& propWriteStream) const

if (sleepStart != 0) {
propWriteStream.ADD_UCHAR(ATTR_SLEEPSTART);
propWriteStream.ADD_ULONG((int32_t)sleepStart);
propWriteStream.ADD_ULONG((uint32_t)sleepStart);
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions src/beds.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class BedItem : public Item
void internalSetSleeper(const Player* player);
void internalRemoveSleeper();

uint32_t sleeperGUID;
uint64_t sleepStart;
House* house;
uint64_t sleepStart;
uint32_t sleeperGUID;
};

class Beds
Expand Down
23 changes: 11 additions & 12 deletions src/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1162,9 +1162,9 @@ void AreaCombat::getList(const Position& centerPos, const Position& targetPos, s
area->getCenter(centerY, centerX);

Position tmpPos(targetPos.x - centerX, targetPos.y - centerY, targetPos.z);
size_t cols = area->getCols();
for (size_t y = 0, rows = area->getRows(); y < rows; ++y) {
for (size_t x = 0; x < cols; ++x) {
uint32_t cols = area->getCols();
for (uint32_t y = 0, rows = area->getRows(); y < rows; ++y) {
for (uint32_t x = 0; x < cols; ++x) {
if (area->getValue(y, x) != 0) {
if (g_game.isSightClear(targetPos, tmpPos, true)) {
Tile* tile = g_game.getTile(tmpPos);
Expand Down Expand Up @@ -1197,19 +1197,17 @@ void AreaCombat::copyArea(const MatrixArea* input, MatrixArea* output, MatrixOpe
output->setCenter(centerY, centerX);
} else if (op == MATRIXOPERATION_MIRROR) {
for (uint32_t y = 0; y < input->getRows(); ++y) {
int32_t rx = 0;

for (int32_t x = input->getCols() - 1; x >= 0; --x) {
uint32_t rx = 0;
for (int32_t x = input->getCols(); --x >= 0;) {
(*output)[y][rx++] = (*input)[y][x];
}
}

output->setCenter(centerY, (input->getRows() - 1) - centerX);
} else if (op == MATRIXOPERATION_FLIP) {
for (uint32_t x = 0; x < input->getCols(); ++x) {
int32_t ry = 0;

for (int32_t y = input->getRows() - 1; y >= 0; --y) {
uint32_t ry = 0;
for (int32_t y = input->getRows(); --y >= 0;) {
(*output)[ry++][x] = (*input)[y][x];
}
}
Expand All @@ -1219,7 +1217,7 @@ void AreaCombat::copyArea(const MatrixArea* input, MatrixArea* output, MatrixOpe
// rotation
int32_t rotateCenterX = (output->getCols() / 2) - 1;
int32_t rotateCenterY = (output->getRows() / 2) - 1;
int32_t angle = 0;
int32_t angle;

switch (op) {
case MATRIXOPERATION_ROTATE90:
Expand All @@ -1246,8 +1244,9 @@ void AreaCombat::copyArea(const MatrixArea* input, MatrixArea* output, MatrixOpe
double c = std::sin(angleRad);
double d = std::cos(angleRad);

for (int32_t x = 0, cols = input->getCols(); x < cols; ++x) {
for (int32_t y = 0, rows = input->getRows(); y < rows; ++y) {
const uint32_t rows = input->getRows();
for (uint32_t x = 0, cols = input->getCols(); x < cols; ++x) {
for (uint32_t y = 0; y < rows; ++y) {
//calculate new coordinates using rotation center
int32_t newX = x - centerX;
int32_t newY = y - centerY;
Expand Down
4 changes: 2 additions & 2 deletions src/combat.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ class MatrixArea
y = centerY;
}

size_t getRows() const {
uint32_t getRows() const {
return rows;
}
size_t getCols() const {
uint32_t getCols() const {
return cols;
}

Expand Down
6 changes: 3 additions & 3 deletions src/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ bool Condition::serialize(PropWriteStream& propWriteStream)
propWriteStream.ADD_VALUE((int32_t)id);

propWriteStream.ADD_UCHAR(CONDITIONATTR_TICKS);
propWriteStream.ADD_VALUE((int32_t)ticks);
propWriteStream.ADD_VALUE(ticks);

propWriteStream.ADD_UCHAR(CONDITIONATTR_ISBUFF);
propWriteStream.ADD_VALUE((int8_t)isBuff);

propWriteStream.ADD_UCHAR(CONDITIONATTR_SUBID);
propWriteStream.ADD_VALUE((int32_t)subId);
propWriteStream.ADD_VALUE(subId);
return true;
}

Expand All @@ -175,7 +175,7 @@ bool Condition::executeCondition(Creature*, int32_t interval)

Condition* Condition::createCondition(ConditionId_t _id, ConditionType_t _type, int32_t _ticks, int32_t param/* = 0*/, bool _buff/* = false*/, uint32_t _subId/* = 0*/)
{
switch ((int32_t)_type) {
switch (_type) {
case CONDITION_POISON:
case CONDITION_FIRE:
case CONDITION_ENERGY:
Expand Down
4 changes: 2 additions & 2 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ void Creature::onCreatureMove(const Creature* creature, const Tile* newTile, con

if (oldPos.y > newPos.y) { //north
//shift y south
for (int32_t y = mapWalkHeight - 2; y >= 0; --y) {
for (int32_t y = mapWalkHeight - 1; --y >= 0;) {
memcpy(localMapCache[y + 1], localMapCache[y], sizeof(localMapCache[y]));
}

Expand Down Expand Up @@ -617,7 +617,7 @@ void Creature::onCreatureMove(const Creature* creature, const Tile* newTile, con
}

for (int32_t y = starty; y <= endy; ++y) {
for (int32_t x = mapWalkWidth - 2; x >= 0; --x) {
for (int32_t x = mapWalkWidth - 1; --x >= 0;) {
localMapCache[y][x + 1] = localMapCache[y][x];
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/fileloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,21 +349,21 @@ inline bool FileLoader::readBytes(uint8_t* buffer, uint32_t size, int32_t pos)

//get maximum read block size and calculate remaining bytes
reading = std::min<int32_t>(remain, m_cached_data[i].size - m_cache_offset);
remain = remain - reading;
remain -= reading;

//read it
memcpy(buffer + bufferPos, m_cached_data[m_cache_index].data + m_cache_offset, reading);

//update variables
m_cache_offset = m_cache_offset + reading;
bufferPos = bufferPos + reading;
pos = pos + reading;
m_cache_offset += reading;
bufferPos += reading;
pos += reading;
} while (remain > 0);

return true;
}

if (fseek(m_file, pos, SEEK_SET)) {
if (fseek(m_file, pos, SEEK_SET) != 0) {
m_lastError = ERROR_SEEK_ERROR;
return false;
}
Expand All @@ -386,7 +386,7 @@ inline bool FileLoader::safeSeek(uint32_t pos)

m_cache_index = i;
m_cache_offset = pos - m_cached_data[i].base;
} else if (fseek(m_file, pos, SEEK_SET)) {
} else if (fseek(m_file, pos, SEEK_SET) != 0) {
m_lastError = ERROR_SEEK_ERROR;
return false;
}
Expand All @@ -411,7 +411,7 @@ inline bool FileLoader::safeTell(int32_t& pos)
return false;
}

pos = pos - 1;
--pos;
return true;
}

Expand Down Expand Up @@ -449,7 +449,7 @@ int32_t FileLoader::loadCacheBlock(uint32_t pos)

if (loading_cache == -1) {
for (i = 0; i < CACHE_BLOCKS; i++) {
if ((long)(abs((long)m_cached_data[i].base - base_pos)) > (long)(2 * m_cache_size)) {
if (abs((long)m_cached_data[i].base - base_pos) > (long)(2 * m_cache_size)) {
loading_cache = i;
break;
}
Expand All @@ -466,7 +466,7 @@ int32_t FileLoader::loadCacheBlock(uint32_t pos)

m_cached_data[loading_cache].base = base_pos;

if (fseek(m_file, m_cached_data[loading_cache].base, SEEK_SET)) {
if (fseek(m_file, m_cached_data[loading_cache].base, SEEK_SET) != 0) {
m_lastError = ERROR_SEEK_ERROR;
return -1;
}
Expand Down
33 changes: 4 additions & 29 deletions src/fileloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class PropStream
end = a + size;
}

uint64_t size() const {
size_t size() const {
return end - p;
}

Expand Down Expand Up @@ -240,8 +240,8 @@ class PropStream
return GET_STRING(ret, str_len);
}

inline bool GET_STRING(std::string& ret, uint16_t str_len) {
if (size() < (int32_t)str_len) {
inline bool GET_STRING(std::string& ret, size_t str_len) {
if (size() < str_len) {
return false;
}

Expand All @@ -260,31 +260,7 @@ class PropStream
return false;
}

if (size() < str_len) {
return false;
}

char* str = new char[str_len + 1];
memcpy(str, p, str_len);
str[str_len] = 0;
ret.assign(str, str_len);
delete[] str;
p += str_len;
return true;
}

inline bool GET_NSTRING(unsigned short str_len, std::string& ret) {
if (size() < (int32_t)str_len) {
return false;
}

char* str = new char[str_len + 1];
memcpy(str, p, str_len);
str[str_len] = 0;
ret.assign(str, str_len); // String can contain 0s
delete[] str;
p += str_len;
return true;
return GET_STRING(ret, str_len);
}

inline bool SKIP_N(uint32_t n) {
Expand Down Expand Up @@ -374,7 +350,6 @@ class PropWriteStream

inline void ADD_LSTRING(const std::string& add) {
uint32_t str_len = (uint32_t)add.size();

ADD_ULONG(str_len);

if ((buffer_size - size) < str_len) {
Expand Down
2 changes: 1 addition & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5052,7 +5052,7 @@ void Game::saveMotdNum() const

void Game::checkPlayersRecord()
{
const uint32_t playersOnline = getPlayersOnline();
const size_t playersOnline = getPlayersOnline();
if (playersOnline > playersRecord) {
uint32_t previousRecord = playersRecord;
playersRecord = playersOnline;
Expand Down
12 changes: 6 additions & 6 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,14 @@ class Game
void addCreatureCheck(Creature* creature);
void removeCreatureCheck(Creature* creature);

uint32_t getPlayersOnline() const {
return (uint32_t)players.size();
size_t getPlayersOnline() const {
return players.size();
}
uint32_t getMonstersOnline() const {
return (uint32_t)monsters.size();
size_t getMonstersOnline() const {
return monsters.size();
}
uint32_t getNpcsOnline() const {
return (uint32_t)npcs.size();
size_t getNpcsOnline() const {
return npcs.size();
}
uint32_t getPlayersRecord() const {
return playersRecord;
Expand Down
2 changes: 1 addition & 1 deletion src/house.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Door : public Item
virtual bool serializeAttr(PropWriteStream& propWriteStream) const;

void setDoorId(uint32_t _doorId) {
setIntAttr(ATTR_ITEM_DOORID, (uint32_t)_doorId);
setIntAttr(ATTR_ITEM_DOORID, _doorId);
}
uint32_t getDoorId() const {
return getIntAttr(ATTR_ITEM_DOORID);
Expand Down
7 changes: 3 additions & 4 deletions src/iologindata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,7 @@ bool IOLoginData::loadPlayer(Player* player, DBResult* result)
player->currentOutfit = player->defaultOutfit;

if (g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED) {
int32_t skullSeconds = result->getDataInt("skulltime") - time(nullptr);

const int32_t skullSeconds = result->getDataInt("skulltime") - time(nullptr);
if (skullSeconds > 0) {
//ensure that we round up the number of ticks
player->skullTicks = (skullSeconds + 2) * 1000;
Expand Down Expand Up @@ -671,15 +670,15 @@ bool IOLoginData::savePlayer(Player* player)
query << "UPDATE `players` SET ";
query << "`level` = " << player->level << ',';
query << "`group_id` = " << player->group->id << ',';
query << "`vocation` = " << (int32_t)player->getVocationId() << ',';
query << "`vocation` = " << player->getVocationId() << ',';
query << "`health` = " << player->health << ',';
query << "`healthmax` = " << player->healthMax << ',';
query << "`experience` = " << player->experience << ',';
query << "`lookbody` = " << (int32_t)player->defaultOutfit.lookBody << ',';
query << "`lookfeet` = " << (int32_t)player->defaultOutfit.lookFeet << ',';
query << "`lookhead` = " << (int32_t)player->defaultOutfit.lookHead << ',';
query << "`looklegs` = " << (int32_t)player->defaultOutfit.lookLegs << ',';
query << "`looktype` = " << (int32_t)player->defaultOutfit.lookType << ',';
query << "`looktype` = " << player->defaultOutfit.lookType << ',';
query << "`lookaddons` = " << (int32_t)player->defaultOutfit.lookAddons << ',';
query << "`maglevel` = " << player->magLevel << ',';
query << "`mana` = " << player->mana << ',';
Expand Down
4 changes: 2 additions & 2 deletions src/iomap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ bool IOMap::loadMap(Map* map, const std::string& identifier)
return false;
}

if (root_header->majorVersionItems > (uint32_t)Items::dwMajorVersion) {
if (root_header->majorVersionItems > Items::dwMajorVersion) {
setLastErrorString("The map was saved with a different items.otb version, an upgraded items.otb is required.");
return false;
}
Expand All @@ -134,7 +134,7 @@ bool IOMap::loadMap(Map* map, const std::string& identifier)
return false;
}

if (root_header->minorVersionItems > (uint32_t)Items::dwMinorVersion) {
if (root_header->minorVersionItems > Items::dwMinorVersion) {
std::cout << "[Warning - IOMap::loadMap] This map needs an updated items.otb." << std::endl;
}

Expand Down
1 change: 0 additions & 1 deletion src/iomarket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ HistoryMarketOfferList IOMarket::getOwnHistory(MarketAction_t action, uint32_t p
offer.timestamp = result->getDataInt("expires_at");

MarketOfferState_t offerState = (MarketOfferState_t)result->getDataInt("state");

if (offerState == OFFERSTATE_ACCEPTEDEX) {
offerState = OFFERSTATE_ACCEPTED;
}
Expand Down
10 changes: 5 additions & 5 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance,
s << ", ";
}

s << "speed " << std::showpos << (int32_t)(it.abilities->speed / 2) << std::noshowpos;
s << "speed " << std::showpos << (it.abilities->speed >> 1) << std::noshowpos;
}
}

Expand Down Expand Up @@ -975,15 +975,15 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance,
s << ", ";
}

s << "speed " << std::showpos << (int32_t)(it.abilities->speed / 2) << std::noshowpos;
s << "speed " << std::showpos << (it.abilities->speed >> 1) << std::noshowpos;
}
}

if (!begin) {
s << ')';
}
} else if (it.isContainer()) {
s << " (Vol:" << (int32_t)it.maxItems << ')';
s << " (Vol:" << it.maxItems << ')';
} else {
bool found = true;

Expand Down Expand Up @@ -1127,7 +1127,7 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance,
}

if (it.wieldInfo & WIELDINFO_LEVEL) {
s << " of level " << (int32_t)it.minReqLevel << " or higher";
s << " of level " << it.minReqLevel << " or higher";
}

if (it.wieldInfo & WIELDINFO_MAGLV) {
Expand All @@ -1137,7 +1137,7 @@ std::string Item::getDescription(const ItemType& it, int32_t lookDistance,
s << " of";
}

s << " magic level " << (int32_t)it.minReqMagicLevel << " or higher";
s << " magic level " << it.minReqMagicLevel << " or higher";
}

s << '.';
Expand Down
Loading

0 comments on commit 73c3cc6

Please sign in to comment.