コード例 #1
0
ファイル: Animal.cpp プロジェクト: Panzerschrek/FREG-3d_2.0
 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();
 }
コード例 #2
0
ファイル: Weapons.cpp プロジェクト: mmaulwurff/FREG
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())));
}
コード例 #3
0
ファイル: Active.cpp プロジェクト: mmaulwurff/FREG
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;
    }
}
コード例 #4
0
ファイル: Active.cpp プロジェクト: mmaulwurff/FREG
void Falling::FallDamage() {
    const int SAFE_FALL_HEIGHT = 5;
    if ( fallHeight > SAFE_FALL_HEIGHT ) {
        const int dmg = (fallHeight - SAFE_FALL_HEIGHT)*10;
        World* const world = World::GetWorld();
        Block* const block_under = world->GetBlock(X(), Y(), Z()-1);
        world->Damage(X(), Y(), Z()-1, dmg, DamageKind());
        if ( block_under->GetDurability() <= 0 ) {
            world->DestroyAndReplace(X(), Y(), Z()-1);
        }
        Damage(dmg, block_under->DamageKind());
        if ( GetDurability() <= 0 ) {
            world->DestroyAndReplace(X(), Y(), Z());
            return;
        }
    }
    falling = false;
    fallHeight = 0;
}