Skip to content

Commit

Permalink
Use references where object is assumed valid
Browse files Browse the repository at this point in the history
  • Loading branch information
kornholi committed Jan 8, 2015
1 parent 80f8f71 commit 6bc3431
Show file tree
Hide file tree
Showing 30 changed files with 179 additions and 178 deletions.
2 changes: 1 addition & 1 deletion src/bed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ bool BedItem::sleep(Player* player)
g_game.setBedSleeper(this, player->getGUID());

// make the player walk onto the bed
g_game.getMap()->moveCreature(player, getTile());
g_game.getMap()->moveCreature(*player, *getTile());

// display 'Zzzz'/sleep effect
g_game.addMagicEffect(player->getPosition(), CONST_ME_SLEEP);
Expand Down
30 changes: 15 additions & 15 deletions src/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void Container::onRemoveContainerItem(uint32_t index, Item* item)
}
}

ReturnValue Container::queryAdd(int32_t index, const Thing *thing, uint32_t count,
ReturnValue Container::queryAdd(int32_t index, const Thing& thing, uint32_t count,
uint32_t flags, Creature *actor/* = nullptr*/) const
{
bool childIsOwner = hasBitSet(FLAG_CHILDISOWNER, flags);
Expand All @@ -286,7 +286,7 @@ ReturnValue Container::queryAdd(int32_t index, const Thing *thing, uint32_t coun
return RETURNVALUE_NOTPOSSIBLE;
}

const Item* item = thing->getItem();
const Item* item = thing.getItem();
if (item == nullptr) {
return RETURNVALUE_NOTPOSSIBLE;
}
Expand All @@ -302,7 +302,7 @@ ReturnValue Container::queryAdd(int32_t index, const Thing *thing, uint32_t coun
const Cylinder* cylinder = getParent();
if (!hasBitSet(FLAG_NOLIMIT, flags)) {
while (cylinder) {
if (cylinder == thing) {
if (cylinder == &thing) {
return RETURNVALUE_THISISIMPOSSIBLE;
}

Expand All @@ -318,7 +318,7 @@ ReturnValue Container::queryAdd(int32_t index, const Thing *thing, uint32_t coun
}
} else {
while (cylinder) {
if (cylinder == thing) {
if (cylinder == &thing) {
return RETURNVALUE_THISISIMPOSSIBLE;
}

Expand All @@ -328,16 +328,16 @@ ReturnValue Container::queryAdd(int32_t index, const Thing *thing, uint32_t coun

const Cylinder* topParent = getTopParent();
if (topParent != this) {
return topParent->queryAdd(INDEX_WHEREEVER, item, count, flags | FLAG_CHILDISOWNER, actor);
return topParent->queryAdd(INDEX_WHEREEVER, *item, count, flags | FLAG_CHILDISOWNER, actor);
} else {
return RETURNVALUE_NOERROR;
}
}

ReturnValue Container::queryMaxCount(int32_t index, const Thing *thing, uint32_t count,
uint32_t &maxQueryCount, uint32_t flags) const
ReturnValue Container::queryMaxCount(int32_t index, const Thing& thing, uint32_t count,
uint32_t& maxQueryCount, uint32_t flags) const
{
const Item* item = thing->getItem();
const Item* item = thing.getItem();
if (item == nullptr) {
maxQueryCount = 0;
return RETURNVALUE_NOTPOSSIBLE;
Expand All @@ -359,7 +359,7 @@ ReturnValue Container::queryMaxCount(int32_t index, const Thing *thing, uint32_t
for (Item* containerItem : itemlist) {
if (containerItem != item && containerItem->equals(item) && containerItem->getItemCount() < 100) {
uint32_t remainder = (100 - containerItem->getItemCount());
if (queryAdd(slotIndex++, item, remainder, flags) == RETURNVALUE_NOERROR) {
if (queryAdd(slotIndex++, *item, remainder, flags) == RETURNVALUE_NOERROR) {
n += remainder;
}
}
Expand All @@ -368,7 +368,7 @@ ReturnValue Container::queryMaxCount(int32_t index, const Thing *thing, uint32_t
const Item* destItem = getItemByIndex(index);
if (item->equals(destItem) && destItem->getItemCount() < 100) {
uint32_t remainder = 100 - destItem->getItemCount();
if (queryAdd(index, item, remainder, flags) == RETURNVALUE_NOERROR) {
if (queryAdd(index, *item, remainder, flags) == RETURNVALUE_NOERROR) {
n = remainder;
}
}
Expand All @@ -387,14 +387,14 @@ ReturnValue Container::queryMaxCount(int32_t index, const Thing *thing, uint32_t
return RETURNVALUE_NOERROR;
}

ReturnValue Container::queryRemove(const Thing *thing, uint32_t count, uint32_t flags) const
ReturnValue Container::queryRemove(const Thing& thing, uint32_t count, uint32_t flags) const
{
int32_t index = getThingIndex(thing);
int32_t index = getThingIndex(&thing);
if (index == -1) {
return RETURNVALUE_NOTPOSSIBLE;
}

const Item* item = thing->getItem();
const Item* item = thing.getItem();
if (item == nullptr) {
return RETURNVALUE_NOTPOSSIBLE;
}
Expand All @@ -409,7 +409,7 @@ ReturnValue Container::queryRemove(const Thing *thing, uint32_t count, uint32_t
return RETURNVALUE_NOERROR;
}

Cylinder* Container::queryDestination(int32_t &index, const Thing *thing, Item **destItem,
Cylinder* Container::queryDestination(int32_t &index, const Thing &thing, Item **destItem,
uint32_t &flags)
{
if (!unlocked) {
Expand Down Expand Up @@ -443,7 +443,7 @@ Cylinder* Container::queryDestination(int32_t &index, const Thing *thing, Item *
*destItem = nullptr;
}

const Item* item = thing->getItem();
const Item* item = thing.getItem();
if (!item) {
return this;
}
Expand Down
10 changes: 5 additions & 5 deletions src/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ class Container : public Item, public Cylinder
}

//cylinder implementations
virtual ReturnValue queryAdd(int32_t index, const Thing *thing, uint32_t count,
virtual ReturnValue queryAdd(int32_t index, const Thing& thing, uint32_t count,
uint32_t flags, Creature *actor = nullptr) const override;
ReturnValue queryMaxCount(int32_t index, const Thing *thing, uint32_t count, uint32_t &maxQueryCount,
ReturnValue queryMaxCount(int32_t index, const Thing& thing, uint32_t count, uint32_t& maxQueryCount,
uint32_t flags) const final;
ReturnValue queryRemove(const Thing *thing, uint32_t count, uint32_t flags) const final;
Cylinder*queryDestination(int32_t &index, const Thing *thing, Item **destItem,
uint32_t &flags) final;
ReturnValue queryRemove(const Thing& thing, uint32_t count, uint32_t flags) const final;
Cylinder* queryDestination(int32_t& index, const Thing& thing, Item **destItem,
uint32_t& flags) final;

void addThing(Thing *thing) final;
void addThing(int32_t index, Thing *thing) final;
Expand Down
2 changes: 1 addition & 1 deletion src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ void Creature::updateMapCache()
void Creature::updateTileCache(const Tile* tile, int32_t dx, int32_t dy)
{
if (std::abs(dx) <= maxWalkCacheWidth && std::abs(dy) <= maxWalkCacheHeight) {
localMapCache[maxWalkCacheHeight + dy][maxWalkCacheWidth + dx] = tile && tile->queryAdd(0, this, 1, FLAG_PATHFINDING | FLAG_IGNOREFIELDDAMAGE) == RETURNVALUE_NOERROR;
localMapCache[maxWalkCacheHeight + dy][maxWalkCacheWidth + dx] = tile && tile->queryAdd(0, *this, 1, FLAG_PATHFINDING | FLAG_IGNOREFIELDDAMAGE) == RETURNVALUE_NOERROR;
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/cylinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Cylinder : virtual public Thing
* \param actor the creature trying to add the thing
* \returns ReturnValue holds the return value
*/
virtual ReturnValue queryAdd(int32_t index, const Thing *thing, uint32_t count,
virtual ReturnValue queryAdd(int32_t index, const Thing& thing, uint32_t count,
uint32_t flags, Creature *actor = nullptr) const = 0;

/**
Expand All @@ -73,7 +73,7 @@ class Cylinder : virtual public Thing
* \param flags optional flags to modify the default behaviour
* \returns ReturnValue holds the return value
*/
virtual ReturnValue queryMaxCount(int32_t index, const Thing *thing, uint32_t count, uint32_t &maxQueryCount,
virtual ReturnValue queryMaxCount(int32_t index, const Thing& thing, uint32_t count, uint32_t& maxQueryCount,
uint32_t flags) const = 0;

/**
Expand All @@ -83,7 +83,7 @@ class Cylinder : virtual public Thing
* \param flags optional flags to modify the default behaviour
* \returns ReturnValue holds the return value
*/
virtual ReturnValue queryRemove(const Thing *thing, uint32_t count, uint32_t flags) const = 0;
virtual ReturnValue queryRemove(const Thing& thing, uint32_t count, uint32_t flags) const = 0;

/**
* Query the destination cylinder
Expand All @@ -95,8 +95,8 @@ class Cylinder : virtual public Thing
* this method can modify the flags
* \returns Cylinder returns the destination cylinder
*/
virtual Cylinder* queryDestination(int32_t &index, const Thing *thing, Item **destItem,
uint32_t &flags) = 0;
virtual Cylinder* queryDestination(int32_t& index, const Thing& thing, Item **destItem,
uint32_t& flags) = 0;

/**
* Add the object to the cylinder
Expand Down Expand Up @@ -211,16 +211,16 @@ class VirtualCylinder final : public Cylinder
public:
static VirtualCylinder* virtualCylinder;

virtual ReturnValue queryAdd(int32_t, const Thing *, uint32_t, uint32_t, Creature * = nullptr) const {
virtual ReturnValue queryAdd(int32_t, const Thing&, uint32_t, uint32_t, Creature * = nullptr) const {
return RETURNVALUE_NOTPOSSIBLE;
}
virtual ReturnValue queryMaxCount(int32_t, const Thing *, uint32_t, uint32_t &, uint32_t) const {
virtual ReturnValue queryMaxCount(int32_t, const Thing&, uint32_t, uint32_t&, uint32_t) const {
return RETURNVALUE_NOTPOSSIBLE;
}
virtual ReturnValue queryRemove(const Thing *, uint32_t, uint32_t) const {
virtual ReturnValue queryRemove(const Thing&, uint32_t, uint32_t) const {
return RETURNVALUE_NOTPOSSIBLE;
}
virtual Cylinder*queryDestination(int32_t &, const Thing *, Item **, uint32_t &) {
virtual Cylinder* queryDestination(int32_t &, const Thing&, Item **, uint32_t &) {
return nullptr;
}

Expand Down
4 changes: 2 additions & 2 deletions src/depotchest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ DepotChest::DepotChest(uint16_t _type) :
maxDepotItems = 1500;
}

ReturnValue DepotChest::queryAdd(int32_t index, const Thing *thing, uint32_t count,
ReturnValue DepotChest::queryAdd(int32_t index, const Thing& thing, uint32_t count,
uint32_t flags, Creature *actor/* = nullptr*/) const
{
const Item* item = thing->getItem();
const Item* item = thing.getItem();
if (item == nullptr) {
return RETURNVALUE_NOTPOSSIBLE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/depotchest.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DepotChest final : public Container
}

//cylinder implementations
ReturnValue queryAdd(int32_t index, const Thing *thing, uint32_t count,
ReturnValue queryAdd(int32_t index, const Thing& thing, uint32_t count,
uint32_t flags, Creature *actor = nullptr) const;

void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t link = LINK_OWNER);
Expand Down
2 changes: 1 addition & 1 deletion src/depotlocker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Attr_ReadValue DepotLocker::readAttr(AttrTypes_t attr, PropStream& propStream)
return Item::readAttr(attr, propStream);
}

ReturnValue DepotLocker::queryAdd(int32_t, const Thing *, uint32_t, uint32_t, Creature *) const
ReturnValue DepotLocker::queryAdd(int32_t, const Thing&, uint32_t, uint32_t, Creature *) const
{
return RETURNVALUE_NOTENOUGHROOM;
}
Expand Down
2 changes: 1 addition & 1 deletion src/depotlocker.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DepotLocker final : public Container
}

//cylinder implementations
ReturnValue queryAdd(int32_t index, const Thing *thing, uint32_t count,
ReturnValue queryAdd(int32_t index, const Thing& thing, uint32_t count,
uint32_t flags, Creature *actor = nullptr) const final;

void postAddNotification(Thing* thing, const Cylinder* oldParent, int32_t index, cylinderlink_t link = LINK_OWNER) final;
Expand Down
Loading

0 comments on commit 6bc3431

Please sign in to comment.