Пример #1
0
 virtual MoveInfo getMove() override {
   const Creature* other = getClosestEnemy();
   if (other != nullptr) {
     double myDamage = creature->getAttr(AttrType::DAMAGE);
     Item* weapon = getBestWeapon();
     if (!creature->getWeapon() && weapon)
       myDamage += weapon->getModifier(AttrType::DAMAGE);
     double powerRatio = courage * myDamage / other->getAttr(AttrType::DAMAGE);
     bool significantEnemy = myDamage < 5 * other->getAttr(AttrType::DAMAGE);
     double weight = 1. - creature->getHealth() * 0.9;
     if (powerRatio < maxPowerRatio)
       weight += 2 - powerRatio * 2;
     weight = min(1.0, max(0.0, weight));
     if (creature->isAffected(Creature::PANIC))
       weight = 1;
     if (other->isAffected(Creature::SLEEP) || other->isStationary())
       weight = 0;
     Debug() << creature->getName() << " panic weight " << weight;
     if (weight >= 0.5) {
       double dist = creature->getPosition().dist8(other->getPosition());
       if (dist < 7) {
         if (dist == 1)
           EventListener::addSurrenderEvent(creature, other);
         if (MoveInfo move = getPanicMove(other, weight))
           return move;
         else
           return getAttackMove(other, significantEnemy && chase);
       }
       return NoMove;
     } else
       return getAttackMove(other, significantEnemy && chase);
   } else
     return getLastSeenMove();
 }
Пример #2
0
 virtual MoveInfo getMove() override {
   const Creature* enemy = getClosestEnemy();
   if (Random.roll(15) || ( enemy && enemy->getPosition().dist8(creature->getPosition()) < maxDist))
     if (auto action = creature->flyAway())
       return {1.0, action};
   return NoMove;
 }
Пример #3
0
CannonProjectile* CannonTower::update(std::vector<Enemy*>& enemies)
{
    Enemy* enemy = getClosestEnemy(enemies);
    if(counter >= counterMax)
    {
        if(!(enemy == NULL))
        {
            counter = 0;
            CannonProjectile* cannonProjectile = new CannonProjectile(xPos, yPos, damage, range/CANONPROJECTILESPEED, 70, enemy);
            if(firingSound != NULL)
            {
                firingSound->play();
            }
            return cannonProjectile;
        }
        else
        {
            return NULL;
        }
    }
    else
    {
        counter++;
        return NULL;
    }
}
Пример #4
0
 virtual MoveInfo getMove() override {
   const Creature* enemy = getClosestEnemy();
   bool fly = Random.roll(15) || ( enemy && (enemy->getPosition() - creature->getPosition()).lengthD() < maxDist);
   if (creature->canFlyAway() && fly)
     return {1.0, [this] () {
       creature->flyAway();
     }};
   else
     return NoMove;
 }