void Converter::DoRareAction() { if ( isOn && fuelLevel < World::SECONDS_IN_DAY/DamageLevel() ) { for (int i=GetSize()-1; i>=0; --i) { Block* const block = ShowBlock(i); if ( block ) { const int add = ConvertRatio(block->Sub()); if ( add > 0 ) { fuelLevel += add; Pull(i); delete block; break; } } } } World* const world = World::GetWorld(); if ( fuelLevel <= 0 || ( Sub() == STONE && world->GetBlock(X(), Y(), Z()+1)->Sub() == WATER ) ) { Damage(1, damageKindOff); } else { if (world->Damage(X(), Y(), Z()+1, DamageLevel(), damageKindOn)<=0) { world->DestroyAndReplace(X(), Y(), Z()+1); } fuelLevel -= DamageLevel(); } }
QString Weapon::Description() const { TrString description = QObject::tr("Damage: %1. Damage type: %2."); return description .arg(DamageLevel()) .arg(TrManager::GetDamageString( static_cast<damage_kinds>(DamageKind()))); }
void Predator::DoRareAction() { const Xyz coords[] = { Xyz(X()-1, Y(), Z()), Xyz(X()+1, Y(), Z()), Xyz(X(), Y()-1, Z()), Xyz(X(), Y()+1, Z()), Xyz(X(), Y(), Z()-1) }; World * const world = GetWorld(); for (const Xyz xyz : coords) { if ( not world->InBounds(xyz.X(), xyz.Y()) ) { continue; } Block * const block = world->GetBlock(xyz.X(), xyz.Y(), xyz.Z()); if ( Attractive(block->Sub()) ) { block->ReceiveSignal(tr("Predator bites you!")); world->Damage(xyz.X(), xyz.Y(), xyz.Z(), DamageLevel(), DamageKind()); Eat(static_cast<subs>(block->Sub())); } } if ( SECONDS_IN_DAY/4 > Satiation() ) { EatGrass(); } Animal::DoRareAction(); }
bool Active::TryDestroy(const int x, const int y, const int z) const { World* const world = World::GetWorld(); if ( world->Damage(x, y, z, DamageLevel(), DamageKind()) <= 0 ) { world->DestroyAndReplace(x, y, z); return true; } else { return false; } }
QString Converter::FullName() const { TrString stoneName = QObject::tr("Furnace"); TrString chargeString = QObject::tr(" (charge for %1 s)"); QString name; switch ( Sub() ) { default: name = Block::FullName(); break; case STONE: name = stoneName; break; } return name + chargeString.arg(fuelLevel/DamageLevel()); }