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(); }
long int Abc() { long int ret; Xyz(); ret = 18; K = 20; ret = 19; return ret; }
Dxyz(std::string v) : Dxyz() { const auto s(pdal::Utils::split(v, [](char c) { return !std::isdigit(c); })); if (s.size() != 4) { throw std::runtime_error("Couldn't parse " + v + " as DXYZ"); } d = std::stoull(s[0]); p = Xyz( std::stoull(s[1]), std::stoull(s[2]), std::stoull(s[3])); assert(toString() == v); }
bool Active::Gravitate(const int range, int bottom, int top, const int calmness) { const World* const world = World::GetCWorld(); const int bound = World::GetBound(); // analyze world around int for_north = 0, for_west = 0; const int my_x = X(); const int my_y = Y(); const int y_start = std::max(my_y-range, 0); const int y_end = std::min(my_y+range, bound); const int x_end = std::min(my_x+range, bound); bottom = std::max(Z() - bottom, 0); top = std::min(Z() + top, HEIGHT-1); const Xyz my_place(my_x, my_y, Z()); for (int x=std::max(my_x-range, 0); x<=x_end; ++x) for (int y=y_start; y<=y_end; ++y) { Shred* const current_shred = world->GetShred(x, y); for (int z=bottom; z<=top; ++z) { const int attractive = Attractive(current_shred->GetBlock( Shred::CoordInShred(x), Shred::CoordInShred(y), z)->Sub()); if (attractive && world->DirectlyVisible(my_place, Xyz(x, y, z))) { if ( y!=my_y ) for_north += attractive / (my_y-y); if ( x!=my_x ) for_west += attractive / (my_x-x); } } } // make direction and move there if ( std::abs(for_north)>calmness || std::abs(for_west)>calmness ) { SetDir( ( std::abs(for_north)>std::abs(for_west) ) ? ( ( for_north>0 ) ? NORTH : SOUTH ) : ( ( for_west >0 ) ? WEST : EAST ) ); return true; } else { return false; } }