Improved code clarity, added documentation.

This commit is contained in:
Felix Ableitner 2013-09-17 19:19:30 +02:00
parent ecff3d56b7
commit c94380c809
2 changed files with 18 additions and 9 deletions

View file

@ -65,13 +65,17 @@ Tile::getConfig(Type type) {
return ""; return "";
} }
} }
/**
* Returns true if collisions with this tile type are enabled.
*/
bool bool
Tile::isSolid(Type type) { Tile::isSolid(Type type) {
switch (type) { switch (type) {
case Type::FLOOR: case Type::FLOOR:
return false; return false;
case Type::WALL: case Type::WALL:
// falltrough return true;
default: default:
return true; return true;
} }

View file

@ -91,7 +91,18 @@ Character::getFaction() const {
return mFaction; return mFaction;
} }
/**
* Inserts the item into the world. Does not remove it from the Character.
*/
void Character::dropItem(std::shared_ptr<Item> item) { void Character::dropItem(std::shared_ptr<Item> item) {
if (!item)
return;
// To avoid weapons continuing to fire after drop and pickup.
auto weapon = std::dynamic_pointer_cast<Weapon>(item);
if (weapon)
weapon->releaseTrigger();
mWorld.insert(item); mWorld.insert(item);
item->drop(getPosition()); item->drop(getPosition());
} }
@ -108,22 +119,16 @@ Character::onDeath() {
else else
switch (rand() % 3) { switch (rand() % 3) {
case 0: case 0:
// To avoid weapons continuing to fire after drop and pickup.
mFirstWeapon->releaseTrigger();
dropItem(mFirstWeapon); dropItem(mFirstWeapon);
break; break;
case 1: case 1:
// Same here.
mSecondWeapon->releaseTrigger();
dropItem(mSecondWeapon); dropItem(mSecondWeapon);
break; break;
case 2: case 2:
if (mLeftGadget) dropItem(mLeftGadget);
dropItem(mLeftGadget);
break; break;
case 3: case 3:
if (mRightGadget) dropItem(mRightGadget);
dropItem(mRightGadget);
break; break;
} }
} }