Beispiel #1
0
bool AIIdea::CanUseWeapon(const Weapon * weapon)
{
  bool correct_weapon = weapon == &(ActiveTeam().GetWeapon());
  bool can_change_weapon = ActiveTeam().GetWeapon().CanChangeWeapon()
    && (Game::GetInstance()->ReadState() == Game::PLAYING);
  return correct_weapon || (can_change_weapon && weapon->EnoughAmmo());
}
Beispiel #2
0
void WeaponMember::Draw(const Point2i & /*_pos*/,
                        int /*flip_center*/,
                        LRDirection /*direction*/)
{
  if (!ActiveCharacter().IsDead() && Game::END_TURN != Game::GetInstance()->ReadState()) {
    ActiveTeam().crosshair.Draw();
    ActiveTeam().AccessWeapon().Draw();
  }
}
Beispiel #3
0
bool WeaponsList::GetWeaponBySort(Weapon::category_t sort, Weapon::Weapon_type &type)
{
  weapons_list_it it, end=m_weapons_list.end();
  bool open = ActiveMap()->LoadedData()->IsOpened();

  /* find the current position */
  it = std::find(m_weapons_list.begin(),
                 m_weapons_list.end(),
                 &ActiveTeam().GetWeapon());

  /* if the current weapon match the criteria */
  if (it != end && ActiveTeam().GetWeapon().Category() == sort)
    {
      /* try to find the next weapon matching our criteria */
      do {
        ++it;
      } while(it != end
              && ((*it)->Category() != sort
                  || ActiveTeam().ReadNbAmmos((*it)->GetType()) == 0
                  || (!((*it)->CanBeUsedOnClosedMap()) && !open))
              );

      /* Ok, a weapon was found let's return it */
      if (it != end && (*it)->Category() == sort)
        {
          type = (*it)->GetType();
          return true;
        }
    }
  /* we didn't find a valid weapon after the current one ; lets wrap:
   * restart from the begining and try to find the first one matching
   * our criteria */
  it = m_weapons_list.begin();
  while(it != end && (*it)->Category() != sort)
    ++it;

  /* no weapon of this sort was found -> give up... */
  if (it == end)
    return false;

  /* try to find the next weapon matching our criteria */
  while(it != end
      && ((*it)->Category() != sort
        || ActiveTeam().ReadNbAmmos((*it)->GetType()) == 0
            || (!(*it)->CanBeUsedOnClosedMap() && open)))
    ++it;

  /* Ok, a weapon was found let's return it if it is not the one active */
  if (it != end && (*it)->Category() == sort && (*it) != &ActiveTeam().GetWeapon())
    {
      type = (*it)->GetType();
      return true;
    }

  /* we definitly found nothing... */
  return false;
}
Beispiel #4
0
bool Weapon::CanChangeWeapon() const
{
  if (ActiveTeam().ReadNbUnits() != m_initial_nb_unit_per_ammo &&
      !m_can_change_weapon)
    return false;

  if (ActiveTeam().GetWeapon().IsOnCooldownFromShot())
    return false;

  return true;
}
Beispiel #5
0
void GameClassic::__SetState_END_TURN()
{
  MSG_DEBUG("game.statechange", "End of turn");
  countdown_sample.Stop();
  ActiveTeam().AccessWeapon().SignalTurnEnd();
  ActiveTeam().AccessWeapon().Deselect();
  CharacterCursor::GetInstance()->Hide();
  duration = GameMode::GetInstance()->duration_exchange_player;
  Interface::GetInstance()->UpdateTimer(duration, false, true);
  Interface::GetInstance()->EnableDisplayTimer(false);
  last_clock_update = GameTime::GetInstance()->Read();

  // Applying Disease damage and Death mode.
  ApplyDiseaseDamage();
  ApplyDeathMode();
}
Beispiel #6
0
void Weapon::Deselect()
{
  ActiveTeam().crosshair.SetActive(false);
  ActiveCharacter().SetFiringAngle(0);
  ActiveCharacter().SetMovement("breathe");
  MSG_DEBUG("weapon.change", "Deselect %s", m_name.c_str());
  p_Deselect();
}
Beispiel #7
0
void Weapon::UseAmmoUnit() const
{
  // Use one ammo unit.
  int *unit = &ActiveTeam().AccessNbUnits();
  (*unit)--;

  ASSERT(*unit >= 0);
}
Beispiel #8
0
void Weapon::UseAmmo() const
{
  // Use one ammo...
  int *ammo = &ActiveTeam().AccessNbAmmos();
  if (*ammo != INFINITE_AMMO) (*ammo)--;

  ASSERT(*ammo >= 0 || *ammo == INFINITE_AMMO);
}
Beispiel #9
0
bool SelectWeaponCommand::Execute()
{
  if (weapon == ActiveTeam().GetWeapon().GetType())
    return true;
  Action * a = new Action(Action::ACTION_PLAYER_CHANGE_WEAPON, weapon);
  ActionHandler::GetInstance()->NewAction(a);
  return true;
}
Beispiel #10
0
bool WeaponsMenu::ActionClic(const Point2i &/*mouse_pos*/)
{
  if (!show)
    return false;
  Weapon * tmp = UpdateCurrentOverflyItem(weapons_menu);
  if (!tmp)
    tmp = UpdateCurrentOverflyItem(tools_menu);
  if (tmp) {
    // Check we have enough ammo
    int nb_bullets = ActiveTeam().ReadNbAmmos(tmp->GetType());
    if ((nb_bullets == INFINITE_AMMO || nb_bullets > 0) && ActiveTeam().GetWeapon().CanChangeWeapon()) {
      ActionHandler::GetInstance()->NewAction(new Action(Action::ACTION_PLAYER_CHANGE_WEAPON, tmp->GetType()));
      Hide(false);
      return true;
    }
  }
  return false;
}
Beispiel #11
0
void Blowtorch::StartShooting()
{
  if (active) {
     active = false;
     ActiveTeam().AccessNbUnits() = 0;
  } else {
    if (EnoughAmmo())
      active = true;
  }
}
Beispiel #12
0
void Weapon::Select()
{
  MSG_DEBUG("weapon.change", "Select %s", m_name.c_str());

  m_time_anim_begin = Time::GetInstance()->Read();
  m_strength = 0;
  m_last_fire_time = 0;
  ActiveTeam().ResetNbUnits();

  ActiveCharacter().SetWeaponClothe();

  // is there a crosshair ?
  if (m_display_crosshair)
    ActiveTeam().crosshair.SetActive(true);

  p_Select();

  // be sure that angle is correct
  ActiveCharacter().SetFiringAngle(ActiveCharacter().GetAbsFiringAngle());
}
Beispiel #13
0
void Airhammer::Refresh()
{
  if (active && deactivation_requested && !ActiveCharacter().IsPreparingShoot()) {
    active = false;
    drill_sound.Stop();
    PlaySoundSelect();
    ActiveTeam().AccessNbUnits() = 0;
  }
  if (EnoughAmmoUnit() && active) {
    Weapon::RepeatShoot();
  }
}
Beispiel #14
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();
    }
  }
}
Beispiel #15
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;
}
Beispiel #16
0
void WeaponMenuItem::Draw(Surface * dest)
{
  Double scale = DEFAULT_ICON_SCALE;
  if (zoom || zoom_start_time + GetZoomTime() > GameTime::GetInstance()->Read()) {
    scale = (GameTime::GetInstance()->Read() - zoom_start_time) / (Double)GetZoomTime();
    if (zoom) {
      scale = DEFAULT_ICON_SCALE + (MAX_ICON_SCALE - DEFAULT_ICON_SCALE) * scale;
      scale = (scale > MAX_ICON_SCALE ? MAX_ICON_SCALE : scale);
    } else {
      scale = MAX_ICON_SCALE - (MAX_ICON_SCALE - DEFAULT_ICON_SCALE) * scale;
      scale = (scale > DEFAULT_ICON_SCALE ? scale : DEFAULT_ICON_SCALE);
    }
  }
  item->SetAlpha(1);
  item->Scale(scale, scale);

  int nb_bullets = ActiveTeam().ReadNbAmmos(weapon->GetType());
  Point2i tmp = GetOffsetAlignment() + Point2i(0, item->GetWidth() - 10);

  char buffer[5] = { 0, };
  if (nb_bullets ==  INFINITE_AMMO) {
#define UTF8_INFINITE "\xE2\x88\x9E"
    PolygonItem::Draw(dest);
    Font::GetInstance(Font::FONT_MEDIUM, Font::FONT_BOLD)->WriteLeft(tmp, UTF8_INFINITE, dark_gray_color);
  } else if (nb_bullets == 0) {
      int num = weapon->AvailableAfterTurn() - (int)Game::GetInstance()->GetCurrentTurn();
      if (num > -1){
        PolygonItem::Draw(dest);
        tmp.y -= 4;
        m_parent->m_not_yet_available->Blit(*dest, tmp);

        tmp.x += m_parent->m_not_yet_available->GetWidth()-5;
        tmp.y += 10;
        snprintf(buffer, 4, "%i ", num);
        Font::GetInstance(Font::FONT_SMALL, Font::FONT_BOLD)->WriteLeft(tmp, buffer, dark_red_color);
      } else {
        item->SetAlpha(0.3);
        PolygonItem::Draw(dest);
      }
  } else {
    PolygonItem::Draw(dest);
    std::ostringstream txt;
    snprintf(buffer, 4, "%i ", nb_bullets);
    Font::GetInstance(Font::FONT_MEDIUM, Font::FONT_BOLD)->WriteLeft(tmp, buffer, dark_gray_color);
  }
}
Beispiel #17
0
void Weapon::DrawAmmoUnits() const
{
  if (!ShouldAmmoUnitsBeDrawn())
    return;

  if (m_initial_nb_unit_per_ammo > 1)
  {
    Rectanglei rect;

    std::ostringstream ss;

    ss << ActiveTeam().ReadNbUnits();

    DrawTmpBoxText(*Font::GetInstance(Font::FONT_SMALL),
                   Point2i(ActiveCharacter().GetCenterX(),
                           ActiveCharacter().GetY() - UNIT_BOX_HEIGHT / 2 - UNIT_BOX_GAP )
                   - Camera::GetInstance()->GetPosition(),
                   ss.str());
  }
}
Beispiel #18
0
void Weapon::Manage()
{
  Refresh();

  Game * game_loop = Game::GetInstance();

  if (game_loop->ReadState() != Game::PLAYING)
    return;

  if (IsOnCooldownFromShot())
    return ;

  if (ActiveTeam().ReadNbUnits() == 0) {
    Deselect();

    if (m_can_change_weapon)
      Select();
    else
      game_loop->SetState(Game::HAS_PLAYED);
  }
}
Beispiel #19
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;
}
Beispiel #20
0
// Weapon menu display (init of the animation)
void WeaponsMenu::Show(const Point2i& pos)
{
  if (!ActiveTeam().GetWeapon().CanChangeWeapon())
    return;

  Surface& window = GetMainWindow();
  uint scroll_border = 0;
  
  if (Config::GetInstance()->GetScrollOnBorder()) {
    scroll_border = Config::GetInstance()->GetScrollBorderSize();
  }

  click_pos = pos;
  int p = 5 + scroll_border;
  if (click_pos.x < p)
    click_pos.x = p;
  if (click_pos.y < p)
    click_pos.y = window.GetHeight(); // Force moving to bottom
  p = window.GetWidth()-10
    - (weapons_menu->GetWidth() + 10 + tools_menu->GetWidth());
  if (click_pos.x > p)
    click_pos.x = p;
  p = window.GetHeight() - Interface::GetRef().GetMenuHeight()
    - weapons_menu->GetHeight() - 10;
  if (click_pos.y > p)
    click_pos.y = p;

  ShowGameInterface();
  if (!show) {
    if (motion_start_time + GetIconsDrawTime() < GameTime::GetInstance()->Read())
      motion_start_time = GameTime::GetInstance()->Read();
    else
      motion_start_time = GameTime::GetInstance()->Read() - (GetIconsDrawTime() - (GameTime::GetInstance()->Read() - motion_start_time));
    show = true;

    JukeBox::GetInstance()->Play("default", "menu/weapon_menu_show");

    old_pointer = Mouse::GetInstance()->SetPointer(Mouse::POINTER_SELECT);
  }
}
Beispiel #21
0
void JetPack::StartFlying()
{
  if (m_flying)
    return;

  ActiveCharacter().SetMovement("jetpack-fire");

  m_last_fuel_down = Time::GetInstance()->Read();
  flying_sound.Play(ActiveTeam().GetSoundProfile(),"weapon/jetpack", -1);

  Camera::GetInstance()->FollowObject(&ActiveCharacter(), true);


  // this avoids to show the arrow on top of character that can hide the ammo units
  ActiveCharacter().UpdateLastMovingTime();

  // do not display the character on top of the active character
  // else it will hide the ammo unit of the jetpack (bug #11479)
  CharacterCursor::GetInstance()->Hide();

  m_flying = true;
}
Beispiel #22
0
bool WeaponMenuItem::IsMouseOver()
{
  if (!ActiveTeam().ReadNbAmmos(weapon->GetType())) {
    if (zoom)
      SetZoom(false);
    return false;
  }

  // Compute the size of the icon bounding box
  Point2i size(MAX_ICON_SIZE, MAX_ICON_SIZE);

  // The icon bounding box for this is centered around the transformed position
  Rectanglei r(transformed_position + 1 - size/2, size);
  if (r.Contains(Mouse::GetInstance()->GetPosition())) {
    if (!zoom)
      SetZoom(true);
    return true;
  }
  if (zoom)
    SetZoom(false);
  return false;
}
Beispiel #23
0
// Move to a point with collision test
collision_t PhysicalObj::NotifyMove(Point2d oldPos, Point2d newPos)
{
  if (IsGhost())
    return NO_COLLISION;

  Point2d contactPos;
  Double contactAngle;
  Point2d pos, offset;
  PhysicalObj* collided_obj = NULL;

  collision_t collision = NO_COLLISION;

  // Convert meters to pixels.
  oldPos *= PIXEL_PER_METER;
  newPos *= PIXEL_PER_METER;

  // Compute distance between old and new position.
  Double lg = oldPos.SquareDistance(newPos);

  MSG_DEBUG("physic.move", "%s moves (%s, %s) -> (%s, %s), square distance: %s",
            GetName().c_str(),
            Double2str(oldPos.x).c_str(), Double2str(oldPos.y).c_str(),
            Double2str(newPos.x).c_str(), Double2str(newPos.y).c_str(),
            Double2str(lg).c_str());

  if (!lg.IsNotZero())
    return NO_COLLISION;

  // Compute increments to move the object step by step from the old
  // to the new position.
  lg = sqrt(lg);
  offset = (newPos - oldPos) / lg;

  // First iteration position.
  pos = oldPos + offset;

  if (!m_collides_with_ground || IsInWater()) {
    MSG_DEBUG("physic.move", "%s moves (%s, %s) -> (%s, %s), collides ground:%d, water:%d",
              GetName().c_str(),
              Double2str(oldPos.x).c_str(), Double2str(oldPos.y).c_str(),
              Double2str(newPos.x).c_str(), Double2str(newPos.y).c_str(),
              m_collides_with_ground, IsInWater());

    SetXY(newPos);
    return NO_COLLISION;
  }

  do {
    Point2i tmpPos(uround(pos.x), uround(pos.y));

    // Check if we exit the GetWorld(). If so, we stop moving and return.
    if (IsOutsideWorldXY(tmpPos)) {

      if (!GetWorld().IsOpen()) {
        tmpPos.x = InRange_Long(tmpPos.x, 0, GetWorld().GetWidth() - GetWidth() - 1);
        tmpPos.y = InRange_Long(tmpPos.y, 0, GetWorld().GetHeight() - GetHeight() - 1);
        MSG_DEBUG("physic.state", "%s - DeplaceTestCollision touche un bord : %d, %d",
                  GetName().c_str(), tmpPos.x, tmpPos.y);
        collision = COLLISION_ON_GROUND;
        break;
      }

      SetXY(pos);

      MSG_DEBUG("physic.move", "%s moves (%f, %f) -> (%f, %f) : OUTSIDE WORLD",
                GetName().c_str(), oldPos.x.tofloat(), oldPos.y.tofloat(),
                newPos.x.tofloat(), newPos.y.tofloat());
      return NO_COLLISION;
    }

    // Test if we collide...
    collided_obj = CollidedObjectXY(tmpPos);
    if (collided_obj) {
      if (!m_go_through_objects || m_last_collided_object != collided_obj) {
        MSG_DEBUG("physic.state", "%s collide on %s", GetName().c_str(), collided_obj->GetName().c_str());

        if (m_go_through_objects) {
          SignalObjectCollision(GetSpeed(), collided_obj, collided_obj->GetSpeed());
          collision = NO_COLLISION;
        } else {
          collision = COLLISION_ON_OBJECT;
        }
        m_last_collided_object = collided_obj;
      } else {
        collided_obj = NULL;
        collision = NO_COLLISION;
      }
    } else if (!IsInVacuumXY(tmpPos, false)) {
      collision = COLLISION_ON_GROUND;
      m_last_collided_object = NULL;
    }

    if (collision != NO_COLLISION) {
      // Nothing more to do!
      MSG_DEBUG("physic.state", "%s - Collision at %d,%d : on %s",
                GetName().c_str(), tmpPos.x, tmpPos.y,
                collision == COLLISION_ON_GROUND ? "ground" : "an object");

      // Set the object position to the current position.
      SetXY(Point2d(pos.x - offset.x, pos.y - offset.y));
      break;
    }

    // Next motion step
    pos += offset;
    lg -= ONE;
  } while (ZERO < lg);

  Point2d speed_before_collision = GetSpeed();
  Point2d speed_collided_obj;
  if (collided_obj) {
    speed_collided_obj = collided_obj->GetSpeed();
  }

  ContactPointAngleOnGround(pos, contactPos, contactAngle);

  Collide(collision, collided_obj, pos);

  // ===================================
  // it's time to signal object(s) about collision!
  // WARNING: the following calls can send Action(s) over the network (cf bug #11232)
  // Be sure to keep it isolated here
  // ===================================
  ActiveTeam().AccessWeapon().NotifyMove(!!collision);
  switch (collision) {
  case NO_COLLISION:
    // Nothing more to do!
    break;
  case COLLISION_ON_GROUND:
    SignalGroundCollision(speed_before_collision, contactAngle);
    break;
  case COLLISION_ON_OBJECT:
    SignalObjectCollision(speed_before_collision, collided_obj, speed_collided_obj);
    collided_obj->SignalObjectCollision(speed_collided_obj, this, speed_before_collision);
    break;
  }
  // ===================================

  return collision;
}
Beispiel #24
0
void Weapon::Message(const std::string& msg)
{
  GameMessages::GetInstance()->Add(msg, ActiveTeam().GetColor());
}
Beispiel #25
0
bool Weapon::EnoughAmmoUnit() const
{
  int unit = ActiveTeam().ReadNbUnits(m_type);
  return (unit > 0);
}
Beispiel #26
0
void GameClassic::RefreshClock()
{
  GameTime * global_time = GameTime::GetInstance();

  if (1000 < global_time->Read() - last_clock_update) {
    last_clock_update = global_time->Read();

    switch (state) {

    case PLAYING:
      if (duration <= 1) {

        /* let the user release the key to shoot */
        if (ActiveTeam().GetWeapon().IsLoading())
          break;

        JukeBox::GetInstance()->Play("default", "end_turn");
        SetState(END_TURN);
      } else {
        duration--;
        if (duration == 12) {
          countdown_sample.Play("default", "countdown-end_turn");
        }
        if (duration > 10) {
          Interface::GetInstance()->UpdateTimer(duration, false, false);
        } else {
          Interface::GetInstance()->UpdateTimer(duration, true, false);
        }
      }
      break;

    case HAS_PLAYED:
      if (duration <= 1) {
        SetState(END_TURN);
      } else {
        duration--;
        Interface::GetInstance()->UpdateTimer(duration, false, false);
      }
      break;

    case END_TURN:
      if (duration <= 1) {

        if (IsAnythingMoving()) {
          duration = 1;
          // Hack to be sure that nothing is moving since long enough
          // it avoids giving hand to another team during the end of an explosion for example
          break;
        }

        if (IsGameFinished()) {
          duration--;
          break;
        }

        if (give_objbox && GetWorld().IsOpen()) {
          NewBox();
          give_objbox = false;
          break;
        }
        else {
          SetState(PLAYING);
          break;
        }
      } else {
        duration--;
      }
      break;
    } // switch
  }// if
}
Beispiel #27
0
bool WaitForStrengthCommand::Execute()
{
  float current_strength = ActiveTeam().GetWeapon().GetStrength().tofloat();
  return (current_strength >= target_strength);
}
Beispiel #28
0
bool Network::IsTurnMaster() const
{
  return ActiveTeam().IsLocal();
}
// Handle a pressed key
void ManMachineInterface::HandleKeyPressed(const Key_t &key)
{
  // Key repeat is useful in the menu, but we are handling it manually
  // during the game
  if (PressedKeys[key]) {
    SDL_EnableKeyRepeat(0,0);
    return;
  }

  switch (key) {
    case KEY_MOVE_CAMERA_RIGHT:
      Camera::GetInstance()->AddLRMoveIntention(INTENTION_MOVE_RIGHT);
      break;
    case KEY_MOVE_CAMERA_LEFT:
      Camera::GetInstance()->AddLRMoveIntention(INTENTION_MOVE_LEFT);
      break;
    case KEY_MOVE_CAMERA_UP:
      Camera::GetInstance()->AddUDMoveIntention(INTENTION_MOVE_UP);
      break;
    case KEY_MOVE_CAMERA_DOWN:
      Camera::GetInstance()->AddUDMoveIntention(INTENTION_MOVE_DOWN);
      break;
    default:
      break;
  }

  // Managing keys related to character moves
  // Available only when local
  if (!ActiveTeam().IsLocalHuman()) return;
  if (Game::GetInstance()->ReadState() == Game::END_TURN) return;
  if (ActiveCharacter().IsDead()) return;

  switch (key) {
    case KEY_MOVE_RIGHT:
      ActiveCharacter().HandleKeyPressed_MoveRight(false);
      break;
    case KEY_MOVE_RIGHT_SLOWLY:
      ActiveCharacter().HandleKeyPressed_MoveRight(true);
      break;
    case KEY_MOVE_LEFT:
      ActiveCharacter().HandleKeyPressed_MoveLeft(false);
      break;
    case KEY_MOVE_LEFT_SLOWLY:
      ActiveCharacter().HandleKeyPressed_MoveLeft(true);
      break;
    case KEY_UP:
      ActiveCharacter().HandleKeyPressed_Up(false);
      break;
    case KEY_UP_SLOWLY:
      ActiveCharacter().HandleKeyPressed_Up(true);
      break;
    case KEY_DOWN:
      ActiveCharacter().HandleKeyPressed_Down(false);
      break;
    case KEY_DOWN_SLOWLY:
      ActiveCharacter().HandleKeyPressed_Down(true);
      break;
    case KEY_JUMP:
      ActiveCharacter().HandleKeyPressed_Jump();
      break;
    case KEY_HIGH_JUMP:
      ActiveCharacter().HandleKeyPressed_HighJump();
      break;
    case KEY_BACK_JUMP:
      ActiveCharacter().HandleKeyPressed_BackJump();
      break;
    case KEY_SHOOT:
      // Shoot key is not accepted in HAS_PLAYED state
      if (Game::GetInstance()->ReadState() == Game::HAS_PLAYED)
        return;
      break;
    case KEY_SCREENSHOT:
      AppWarmux::GetInstance()->video->SaveScreenshot();
      return;
    default:
      // key not supported
      return;
  }
  if (Game::GetInstance()->ReadState() == Game::PLAYING) {
    switch (key) {
    case KEY_MOVE_RIGHT:
      ActiveTeam().AccessWeapon().HandleKeyPressed_MoveRight(false);
      break;
    case KEY_MOVE_RIGHT_SLOWLY:
      ActiveTeam().AccessWeapon().HandleKeyPressed_MoveRight(true);
      break;
    case KEY_MOVE_LEFT:
      ActiveTeam().AccessWeapon().HandleKeyPressed_MoveLeft(false);
      break;
    case KEY_MOVE_LEFT_SLOWLY:
      ActiveTeam().AccessWeapon().HandleKeyPressed_MoveLeft(true);
      break;
    case KEY_UP:
      ActiveTeam().AccessWeapon().HandleKeyPressed_Up(false);
      break;
    case KEY_UP_SLOWLY:
      ActiveTeam().AccessWeapon().HandleKeyPressed_Up(true);
      break;
    case KEY_DOWN:
      ActiveTeam().AccessWeapon().HandleKeyPressed_Down(false);
      break;
    case KEY_DOWN_SLOWLY:
      ActiveTeam().AccessWeapon().HandleKeyPressed_Down(true);
      break;
    case KEY_JUMP:
      ActiveTeam().AccessWeapon().HandleKeyPressed_Jump();
      break;
    case KEY_HIGH_JUMP:
      ActiveTeam().AccessWeapon().HandleKeyPressed_HighJump();
      break;
    case KEY_BACK_JUMP:
      ActiveTeam().AccessWeapon().HandleKeyPressed_BackJump();
      break;
    case KEY_SHOOT:
      ActiveTeam().AccessWeapon().HandleKeyPressed_Shoot();
      break;
    default:
      // key not supported
      return;
    }
  }

  PressedKeys[key] = true ;
}
// Handle a released key
void ManMachineInterface::HandleKeyReleased(const Key_t &key)
{
  PressedKeys[key] = false;
  // Here we manage only actions which are activated on KEY_RELEASED event.

  { // Managing keys related to interface (no game interaction)
    // Always available
    switch(key){
      // Managing interface
    case KEY_HELP:
      Game::GetInstance()->UserAsksForHelpMenu();
      return;
    case KEY_QUIT:
    case KEY_PAUSE:
      Game::GetInstance()->UserAsksForMenu();
      return;
    case KEY_FULLSCREEN:
      AppWarmux::GetInstance()->video->ToggleFullscreen();
      return;
    case KEY_CHAT:
      if(Network::IsConnected())
        Game::GetInstance()->chatsession.ShowInput();
      return;
    case KEY_CENTER:
      Camera::GetInstance()->CenterOnActiveCharacter();
      return;
    case KEY_TOGGLE_INTERFACE:
      Interface::GetInstance()->EnableDisplay(!Interface::GetInstance()->IsDisplayed());
      return;
    case KEY_MINIMAP_FROM_GAME:
      Interface::GetInstance()->ToggleMinimap();
      return;
    case KEY_MENU_OPTIONS_FROM_GAME: {
      OptionMenu options_menu;
      options_menu.Run();
      return;
    }
    case KEY_MOVE_CAMERA_RIGHT:
      Camera::GetInstance()->RemoveLRMoveIntention(INTENTION_MOVE_RIGHT);
      return;
    case KEY_MOVE_CAMERA_LEFT:
      Camera::GetInstance()->RemoveLRMoveIntention(INTENTION_MOVE_LEFT);
      return;
    case KEY_MOVE_CAMERA_UP:
      Camera::GetInstance()->RemoveUDMoveIntention(INTENTION_MOVE_UP);
      return;
    case KEY_MOVE_CAMERA_DOWN:
      Camera::GetInstance()->RemoveUDMoveIntention(INTENTION_MOVE_DOWN);
      return;
    case KEY_DECREASE_MINIMAP:
      Interface::GetInstance()->MinimapSizeDelta(1);
      return;
    case KEY_INCREASE_MINIMAP:
      Interface::GetInstance()->MinimapSizeDelta(-1);
      return;
    case KEY_DECREASE_VOLUME:
      {
        Config *cfg = Config::GetInstance();
        int volume = cfg->GetVolumeMusic() - 5;
        if (volume > 0) {
          cfg->SetVolumeMusic(volume);
        } else {
          cfg->SetVolumeMusic(0);
          JukeBox::GetInstance()->ActiveMusic(false);
        }
        volume = cfg->GetVolumeEffects() - 5;
        if (volume > 0) {
          cfg->SetVolumeEffects(volume);
        } else {
          cfg->SetVolumeEffects(0);
          cfg->SetSoundEffects(false);
        }
        return;
      }
    case KEY_INCREASE_VOLUME:
      {
        Config *cfg = Config::GetInstance();
        int max_volume = cfg->GetMaxVolume();
        int volume = cfg->GetVolumeMusic() + 5;
        if (volume < max_volume) {
          cfg->SetVolumeMusic(volume);
        } else {
          cfg->SetVolumeMusic(max_volume);
        }
        JukeBox::GetInstance()->ActiveMusic(true);

        volume = cfg->GetVolumeEffects() + 5;
        if (volume < max_volume) {
          cfg->SetVolumeEffects(volume);
        } else {
          cfg->SetVolumeEffects(max_volume);
        }
        cfg->SetSoundEffects(true);
        return;
      }
    default:
      break;
    }
  }

  // Managing shoot key
  // Drop bonus box or medkit when outside a turn
  // Shoot when in turn
  if (key == KEY_SHOOT) {

    if (Game::GetInstance()->ReadState() == Game::END_TURN) {
      Game::GetInstance()->RequestBonusBoxDrop();
    } else if (Game::GetInstance()->ReadState() == Game::PLAYING &&
               ActiveTeam().IsLocalHuman() &&
               !ActiveCharacter().IsDead()) {
      ActiveTeam().AccessWeapon().HandleKeyReleased_Shoot();
    }
    return;
  }

  { // Managing keys related to character moves
    // Available only when local
    if (!ActiveTeam().IsLocalHuman()) return;
    if (ActiveCharacter().IsDead()) return;
    if (Game::GetInstance()->ReadState() == Game::END_TURN) return;

    switch (key) {
      case KEY_MOVE_RIGHT:
        ActiveCharacter().HandleKeyReleased_MoveRight(false);
        break;
      case KEY_MOVE_RIGHT_SLOWLY:
        ActiveCharacter().HandleKeyReleased_MoveRight(true);
        break;
      case KEY_MOVE_LEFT:
        ActiveCharacter().HandleKeyReleased_MoveLeft(false);
        break;
      case KEY_MOVE_LEFT_SLOWLY:
        ActiveCharacter().HandleKeyReleased_MoveLeft(true);
        break;
      case KEY_UP:
        ActiveCharacter().HandleKeyReleased_Up(false);
        break;
      case KEY_UP_SLOWLY:
        ActiveCharacter().HandleKeyReleased_Up(true);
        break;
      case KEY_DOWN:
        ActiveCharacter().HandleKeyReleased_Down(false);
        break;
      case KEY_DOWN_SLOWLY:
        ActiveCharacter().HandleKeyReleased_Down(true);
        break;
      case KEY_JUMP:
        ActiveCharacter().HandleKeyReleased_Jump();
        break;
      case KEY_HIGH_JUMP:
        ActiveCharacter().HandleKeyReleased_HighJump();
        break;
      case KEY_BACK_JUMP:
        ActiveCharacter().HandleKeyReleased_BackJump();
        break;
      default:
        if (Game::GetInstance()->ReadState() == Game::HAS_PLAYED)
          return;
        break;
    }
    if (Game::GetInstance()->ReadState() == Game::PLAYING) {
      switch (key) {

      case KEY_MOVE_RIGHT:
        ActiveTeam().AccessWeapon().HandleKeyReleased_MoveRight(false);
        return;
      case KEY_MOVE_RIGHT_SLOWLY:
        ActiveTeam().AccessWeapon().HandleKeyReleased_MoveRight(true);
        return;
      case KEY_MOVE_LEFT:
        ActiveTeam().AccessWeapon().HandleKeyReleased_MoveLeft(false);
        return;
      case KEY_MOVE_LEFT_SLOWLY:
        ActiveTeam().AccessWeapon().HandleKeyReleased_MoveLeft(true);
        return;
      case KEY_UP:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Up(false);
        return;
      case KEY_UP_SLOWLY:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Up(true);
        return;
      case KEY_DOWN:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Down(false);
        return;
      case KEY_DOWN_SLOWLY:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Down(true);
        return;
      case KEY_JUMP:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Jump();
        return;
      case KEY_HIGH_JUMP:
        ActiveTeam().AccessWeapon().HandleKeyReleased_HighJump();
        return;
      case KEY_BACK_JUMP:
        ActiveTeam().AccessWeapon().HandleKeyReleased_BackJump();
        return;

        // Shoot key
      case KEY_SHOOT:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Shoot();
        return;

        // Other keys usefull for weapons
      case KEY_WEAPON_1:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Num1();
        return;
      case KEY_WEAPON_2:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Num2();
        return;
      case KEY_WEAPON_3:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Num3();
        return;
      case KEY_WEAPON_4:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Num4();
        return;
      case KEY_WEAPON_5:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Num5();
        return;
      case KEY_WEAPON_6:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Num6();
        return;
      case KEY_WEAPON_7:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Num7();
        return;
      case KEY_WEAPON_8:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Num8();
        return;
      case KEY_WEAPON_9:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Num9();
        return;
      case KEY_WEAPON_LESS:
        ActiveTeam().AccessWeapon().HandleKeyReleased_Less();
        return;
      case KEY_WEAPON_MORE:
        ActiveTeam().AccessWeapon().HandleKeyReleased_More();
        return;
      default:
        break;
      }
    }
  }

  { // Managing keys related to change of character or weapon

    if (Game::GetInstance()->ReadState() != Game::PLAYING ||
        !ActiveTeam().GetWeapon().CanChangeWeapon() ||
        !ActiveTeam().IsLocalHuman())
      return;

    Weapon::category_t weapon_sort = Weapon::INVALID;

    switch(key) {

    case KEY_NEXT_CHARACTER:
      if (GameMode::GetInstance()->AllowCharacterSelection()) {
        SDLMod mod = SDL_GetModState();
        if (mod & KMOD_CTRL) {
          ActiveTeam().PreviousCharacter();
        } else {
          ActiveTeam().NextCharacter();
        }
        ActionHandler::GetInstance()->NewActionActiveCharacter();
      }
      return;

    case KEY_WEAPONS1:
      weapon_sort = Weapon::HEAVY;
      break;
    case KEY_WEAPONS2:
      weapon_sort = Weapon::RIFLE;
      break;
    case KEY_WEAPONS3:
      weapon_sort = Weapon::THROW;
      break;
    case KEY_WEAPONS4:
      weapon_sort = Weapon::SPECIAL;
      break;
    case KEY_WEAPONS5:
      weapon_sort = Weapon::DUEL;
      break;
    case KEY_WEAPONS6:
      weapon_sort = Weapon::MOVE;
      break;
    case KEY_WEAPONS7:
      weapon_sort = Weapon::TOOL;
      break;
    default:
      // Key not supported
      return;
    }

    if (weapon_sort != Weapon::INVALID && ActiveTeam().GetWeapon().CanChangeWeapon()) {
      Weapon::Weapon_type weapon;
      WeaponsList * weapons_list = Game::GetInstance()->GetWeaponsList();
      if (weapons_list->GetWeaponBySort(weapon_sort, weapon)) {
        ASSERT (weapon >= Weapon::FIRST && weapon <= Weapon::LAST);
        ActionHandler::GetInstance()->NewAction(new Action(Action::ACTION_PLAYER_CHANGE_WEAPON, weapon));
      }
    }
  }
}