Example #1
0
void Blowtorch::Refresh()
{
  if (active) {
    const LRMoveIntention * lr_move_intention = ActiveCharacter().GetLastLRMoveIntention();
    if (lr_move_intention && EnoughAmmoUnit()) {
      Weapon::RepeatShoot();
    }
  }
  if (!EnoughAmmoUnit()) {
    active = false;
    if (EnoughAmmo()) {
      ActiveTeam().ResetNbUnits();
    }
  }
}
Example #2
0
void Airhammer::Refresh()
{
  if (active && deactivation_requested && !ActiveCharacter().IsPreparingShoot()) {
    active = false;
    drill_sound.Stop();
    PlaySoundSelect();
    ActiveTeam().AccessNbUnits() = 0;
  }
  if (EnoughAmmoUnit() && active) {
    Weapon::RepeatShoot();
  }
}
Example #3
0
bool Weapon::IsReady() const
{
  // WARNING: The following commented code is wrong! Please see explanation following
  //   if (!EnoughAmmo()
  //       || (use_unit_on_first_shoot && !EnoughAmmoUnit()))
  //     return false;


  // Gentildemon : YES the following code seems strange!
  // BUT when have only one ammo left, you shoot, then nb_ammo == 0
  // then you need to be able to use the left ammo units

  if (use_unit_on_first_shoot && !EnoughAmmoUnit())
    return false;

  if (!EnoughAmmo())
    if (!(ActiveTeam().ReadNbAmmos() == 0
          && use_unit_on_first_shoot && EnoughAmmoUnit()))
      return false;
  return true;
}
Example #4
0
bool Weapon::Shoot()
{
  MSG_DEBUG("weapon.shoot", "Enough ammo ? %d", EnoughAmmo());
  MSG_DEBUG("weapon.shoot", "Enough ammo unit ? %d", EnoughAmmoUnit());
  MSG_DEBUG("weapon.shoot", "Use unit on 1st shoot ? %d", use_unit_on_first_shoot);

  if (!IsReady())
    return false;

  MSG_DEBUG("weapon.shoot", "Enough ammo");

  #ifdef DEBUG
  Point2i hand;
  ActiveCharacter().GetHandPosition(hand);
  MSG_DEBUG("weapon.shoot", "%s Shooting at position:%d,%d (hand: %d,%d)",
            ActiveCharacter().GetName().c_str(),
            ActiveCharacter().GetX(),
            ActiveCharacter().GetY(),
            hand.GetX(),
            hand.GetY());
  ActiveCharacter().body->DebugState();
  #endif
  if (!p_Shoot()) {
    MSG_DEBUG("weapon.shoot", "shoot has failed!!");
    return false;
  }
  m_last_fire_time = Time::GetInstance()->Read();

  MSG_DEBUG("weapon.shoot", "shoot!");

  // Is this the first shoot for this ammo use ?
  if (ActiveTeam().ReadNbUnits() == m_initial_nb_unit_per_ammo) {
    UseAmmo();
  }

  if (use_unit_on_first_shoot){
    UseAmmoUnit();
  }

  if (max_strength.IsNotZero())
    ActiveCharacter().previous_strength = m_strength;

  Game::GetInstance()->SetCharacterChosen(true);

  return true;
}
Example #5
0
void JetPack::Refresh()
{
  if (active) {
    Point2d F(0.0, 0.0);
    const UDMoveIntention * ud_move_intention = ActiveCharacter().GetLastUDMoveIntention();
    if (ud_move_intention && ud_move_intention->GetDirection() == DIRECTION_UP) {
      F.y = -(ActiveCharacter().GetMass() * GameMode::GetInstance()->gravity + JETPACK_FORCE);
    }
    const LRMoveIntention * lr_move_intention = ActiveCharacter().GetLastLRMoveIntention();
    if (lr_move_intention && IsInAir()) {
      LRDirection direction = lr_move_intention->GetDirection();
      if (direction == DIRECTION_LEFT)
        F.x = -JETPACK_FORCE;
      else
        F.x = JETPACK_FORCE;
      ActiveCharacter().SetDirection(direction);
    }

    if (F.IsNull() && m_flying)
      StopFlying();
    else if (!F.IsNull() && !m_flying)
      StartFlying();

    ActiveCharacter().SetExternForceXY(F);

    if (!F.IsNull()) {
      // We are using fuel !!!
      uint current = GameTime::GetInstance()->Read() ;
      int64_t delta = current - m_last_fuel_down;

      while (delta >= DELTA_FUEL_DOWN) {
        if (EnoughAmmoUnit()) {
          UseAmmoUnit();
          m_last_fuel_down += DELTA_FUEL_DOWN ;
          delta -= DELTA_FUEL_DOWN ;
        } else {
          p_Deselect();
          break;
        }
      }

    }
  }
}
Example #6
0
void Construct::Draw()
{
  Weapon::Draw();

  if (EnoughAmmo()
      && EnoughAmmoUnit()
      && !Interface::GetInstance()->weapons_menu.IsDisplayed()
      && Interface::GetInstance()->IsDisplayed()
      && Network::GetInstance()->IsTurnMaster()) {

    dst = Mouse::GetInstance()->GetWorldPosition();
    construct_spr->SetRotation_rad(angle);
    construct_spr->Draw(dst - construct_spr->GetSize() / 2);

#ifdef DEBUG
    if (IsLOGGING("test_rectangle")) {
      Rectanglei test_rect(dst - construct_spr->GetSizeMax() / 2, construct_spr->GetSizeMax());
      test_rect.SetPosition(test_rect.GetPosition() - Camera::GetInstance()->GetPosition());
      GetMainWindow().RectangleColor(test_rect, primary_red_color, 1);
    }
#endif
  }
}