Пример #1
0
void Polecat::Fart()
{
  // particles must be exactly the same accross the network
  Double norme = Double(RandomSync().GetInt(0, 500))/100;
  Double angle = Double(RandomSync().GetInt(0, 3000))/100;
  ParticleEngine::AddNow(GetPosition(), 3, particle_POLECAT_FART, true, angle, norme);
  last_fart_time = GameTime::GetInstance()->Read();
  JukeBox::GetInstance()->Play("default", "weapon/polecat_fart");
}
Пример #2
0
Weapon * WeaponsList::GetRandomWeaponToDrop()
{
  std::list<Weapon*>::iterator it;
  Double probability_sum = 0;
  for (it = m_weapons_list.begin(); it != m_weapons_list.end(); ++it) {
    probability_sum += (*it)->GetDropProbability();
  }
  ASSERT(probability_sum > 0);

  MSG_DEBUG("random.get", "WeaponList::GetRandomWeaponToDrop()");
  Double num = RandomSync().GetDouble(0, probability_sum);
  Double total_bf_weapon = 0;
  Double total_after_weapon = 0;

  for (it = m_weapons_list.begin(); it != m_weapons_list.end(); it++) {
    Weapon * weapon = *it;
    total_after_weapon = total_bf_weapon + weapon->GetDropProbability();
    if (total_bf_weapon < num && num <= total_after_weapon) {
      MSG_DEBUG("bonus","Weapon choosed: %s", weapon->GetName().c_str());
      return weapon;
    }
    total_bf_weapon = total_after_weapon;
  }
  ASSERT(false);
  return NULL;
}
Пример #3
0
void Plane::Refresh()
{

  UpdatePosition();
  image->Update();
  // First shoot !!
  if (OnTopOfTarget() && nb_dropped_bombs == 0) {
    DropBomb();
    m_ignore_movements = true;
    MSG_DEBUG("random.get", "Plane::Refresh() first bomb");
    next_height = RandomSync().GetInt(20,100);
  } else if (nb_dropped_bombs > 0 &&  nb_dropped_bombs < cfg.nbr_obus) {
    // Get the last rocket and check the position to be sure to not collide with it
    if (!last_dropped_bomb || last_dropped_bomb->GetY() > GetY()+GetHeight()+next_height) {
      MSG_DEBUG("random.get", "Plane::Refresh() another bomb");
      next_height = RandomSync().GetInt(20,100);
      DropBomb();
    }
  }
}
Пример #4
0
BodyMemberParticle::BodyMemberParticle(Sprite& spr, const Point2i& position)
  : Particle("body_member_particle")
  , angle_rad(0)
{
  SetCollisionModel(true, false, false);
  m_time_left_to_live = 100;
  // Bug #17408: make sure there's an available surface for the sprite
  spr.RefreshSurface();
  image = new Sprite(spr.GetSurface());
  image->EnableCaches(false, 0); // Some generic particle code requires it to be flipped
  ASSERT(image->GetWidth() && image->GetHeight());
  SetXY(position);

  SetSize(image->GetSize());
  SetOnTop(true);
  MSG_DEBUG("random.get", "BodyMemberParticle::BodyMemberParticle(...) speed vector length");
  Double speed_vector_length = (Double)RandomSync().GetInt(10, 15);
  MSG_DEBUG("random.get", "BodyMemberParticle::BodyMemberParticle(...) speed vector angle");
  Double speed_vector_angle = - RandomSync().GetDouble(0, 3);
  SetSpeed(speed_vector_length, speed_vector_angle);
}
Пример #5
0
void Plane::DropBomb()
{
  Obus * instance = new Obus(cfg);
  instance->SetXY(Point2i(GetX(), obus_dy));

  Point2d speed_vector = GetSpeedXY();

  int fx = RandomSync().GetInt(FORCE_X_MIN, FORCE_X_MAX);
  fx *= GetDirection();
  int fy = RandomSync().GetInt(FORCE_Y_MIN, FORCE_Y_MAX);

  speed_vector.SetValues(speed_vector.x + fx/(Double)30.0, speed_vector.y + fy/(Double)30.0);
  instance->SetSpeedXY(speed_vector);

  ObjectsList::GetRef().AddObject(instance);

  last_dropped_bomb = instance;
  nb_dropped_bombs++;

  if (nb_dropped_bombs == 1)
    Camera::GetInstance()->FollowObject(instance);
}
Пример #6
0
void SpriteAnimation::CalculateWait()
{
  MSG_DEBUG("eye", "CalculateWait stat   :  wait = %d , random = %d", loop_wait, loop_wait_random);
  MSG_DEBUG("eye", "CalculateWait 1 : %d", last_update);

  if (loop_wait != 0) {
    last_update += loop_wait;
    if (loop_wait_random != 0) {
      MSG_DEBUG("random.get","SpriteAnimation::CalculateWait()");
      last_update +=  RandomSync().GetInt(0, loop_wait_random) - loop_wait_random/2;
    }
  }
  MSG_DEBUG("eye", "CalculateWait 2 : %d", last_update);
}
Пример #7
0
void FootBomb::DoExplosion()
{
  WeaponProjectile::DoExplosion();

  if (!m_recursions)
    return;

  FootBombConfig &config = static_cast<FootBombConfig &>(cfg);
  Double half_angle_range = config.nb_angle_dispersion * PI / 180;
  Point2i pos = GetPosition();

  for (uint i=0; i<config.nb_fragments; ++i) {
    Double angle = -PI / 2; // this angle is "upwards" here
    Double cluster_deviation = RandomSync().GetDouble(-half_angle_range, half_angle_range);
    Double speed = RandomSync().GetDouble(config.nb_min_speed, config.nb_max_speed);

    FootBomb *cluster = new FootBomb(config, launcher);
    cluster->Shoot(pos, speed, angle+cluster_deviation, m_recursions-1);
    cluster->SetTimeOut(cfg.timeout + m_timeout_modifier);

    ObjectsList::GetRef().AddObject(cluster);
  }
}
Пример #8
0
void ObjMine::StartTimeout()
{
  if (!animation) {
    animation=true;

    // is it a fake mine ? (here because Constructor is called before random
    // number generator is synchronized over the network)
    fake = !(RandomSync().GetUint(0, 9));

    Camera::GetInstance()->FollowObject(this);

    MSG_DEBUG("mine", "EnableDetection - CurrentTime : %d",GameTime::GetInstance()->ReadSec() );
    attente = GameTime::GetInstance()->ReadSec() + cfg.timeout;
    MSG_DEBUG("mine", "EnableDetection : %d", attente);

    timeout_sound.Play("default", "weapon/mine_beep", -1);
  }
}
Пример #9
0
void ClusterBomb::DoExplosion()
{
  WeaponProjectile::DoExplosion();

  const uint fragments = static_cast<ClusterBombConfig &>(cfg).nb_fragments;
  Cluster * cluster;

  const Double angle_range = HALF_PI;
  Point2i pos = GetPosition();
  for (uint i = 0; i < fragments; ++i )
  {
    Double angle = -HALF_PI; // this angle is "upwards" here
    Double cluster_deviation = angle_range * i / ( Double )fragments - angle_range / TWO;
    Double speed = RandomSync().GetDouble(10, 25);

    cluster = new Cluster(static_cast<ClusterBombConfig &>(cfg), launcher);
    cluster->Shoot( pos, speed, angle + cluster_deviation );

    ObjectsList::GetRef().AddObject(cluster);
  }
}
Пример #10
0
void CluzookaCluster::Shoot(const Point2i & start_pos, Double strength, Double angle, uint recurse_times)
{
  m_recursion_depth = recurse_times;
#else
void CluzookaCluster::Shoot(const Point2i & start_pos, Double strength, Double angle)
{
#endif

  Camera::GetInstance()->FollowObject(this);
  ResetConstants();
  SetCollisionModel(true, true, false ); // a bit hackish...
  // we do need to collide with objects, but if we allow for this, the clusters
  // will explode on spawn (because of colliding with each other)
  SetXY(start_pos);
  SetSpeed(strength, angle);

  explode_with_timeout = true;
  StartTimeout();
  m_time_before_spawn = 750;
  // make time a bit random to unsychronize particles

  m_time_before_spawn += RandomSync().GetDouble(-300, 100);
}
Пример #11
0
void Polecat::Refresh()
{
  if (m_energy == 0) {
    Explosion();
    return;
  }
  int tmp = GetMSSinceTimeoutStart();
  if (cfg.timeout && tmp > 1000 * (GetTotalTimeout())) {
    if (!last_fart_time) {
      std::string txt = Format(_("%s has done something for the environment, he has not ordered the polecat to fart."),
             ActiveCharacter().GetName().c_str());
      Weapon::Message(txt);
    }
    SignalTimeout();
  }

  Double norm, angle;
  if (last_fart_time && last_fart_time + TIME_BETWEEN_FART < GameTime::GetInstance()->Read()) {
    Fart();
  }

  //When we hit the ground, jump !
  if(!IsMoving() && !FootsInVacuum()) {
    // Limiting number of rebound to avoid desync
    if(last_rebound_time + TIME_BETWEEN_REBOUND > GameTime::GetInstance()->Read()) {
      image->SetRotation_rad(0.0);
      return;
    }
    last_rebound_time = GameTime::GetInstance()->Read();
    MSG_DEBUG("weapon.polecat", "Jump ! (time = %d)", last_rebound_time);
    //If the GNU is stuck in ground -> change direction
    int x = GetX();
    int y = GetY();
    if(x == save_x && y == save_y)
      m_sens = -m_sens;
    save_x = x;
    save_y = y;

    //Do the jump
    norm = RandomSync().GetDouble(1.0, 2.0);
    PutOutOfGround();
    SetSpeedXY(Point2d(m_sens * norm , -norm * THREE));
  }
  //Due to a bug in the physic engine
  //sometimes, angle==infinite (according to gdb) ??
  GetSpeed(norm, angle);

  angle = RestrictAngle(angle) * ONE_HALF;
  bool flipped = m_sens == -1;
  if (flipped) {
    if (angle > 0)
      angle -= HALF_PI;
    else
      angle += HALF_PI;
  }

  image->SetRotation_rad(angle);
  image->SetFlipped(flipped);
  image->Scale(ONE, ONE);
  image->Update();
}
Пример #12
0
bool BenchmarkMenu::Launch(BenchItem *b)
{
  if (!b)
    return false;

  bool        ok    = false;
  float       score = 0.0f;
  const char *fmt   = "";

  switch (b->type) {
  case BENCH_MENU:
    {
      Stopwatch   clock;
      delete (new OptionMenu());
      score = 1000.0f / clock.GetValue();
      fmt   = "%.3f";
      ok    = true;
      break;
    }
  case BENCH_GRAPHICS:
    {
      graph->UnsetResults();

      // Backup and set playing teams
      std::vector<Team*> list_bak = GetTeamsList().GetPlayingList();
      std::list<uint> sel; sel.push_back(1); sel.push_back(2);
      GetTeamsList().ChangeSelection(sel);

      // Backup and set team configuration - make it quick ;)
      std::vector<Team*>& list = GetTeamsList().GetPlayingList();
      for (uint i=0; i<list.size(); i++) {
        printf("Setting %s\n", list[i]->GetName().c_str());
        list[i]->SetPlayerName("CPU");
        list[i]->SetNbCharacters(10);
        list[i]->SetAIName(STRONG_AI_NAME);
        list[i]->SetGroup(i);
      }

      // Backup and set game mode
      Config *cfg = Config::GetInstance();
      std::string game_mode = cfg->GetGameMode();
      cfg->SetGameMode("benchmark");
      GameMode::GetInstance()->Load();

      // Backup and set some config options
      uint wind_particles = cfg->GetWindParticlesPercentage(); cfg->SetWindParticlesPercentage(100);
      bool display_energy = cfg->GetDisplayEnergyCharacter(); cfg->SetDisplayEnergyCharacter(true);
      bool display_multisky = cfg->GetDisplayMultiLayerSky(); cfg->SetDisplayMultiLayerSky(false);

      // Mute all sounds
      JukeBox *jbox = JukeBox::GetInstance();
      bool music = cfg->GetSoundMusic(); jbox->ActiveMusic(false);
      bool sfx = cfg->GetSoundEffects(); cfg->SetSoundEffects(false);

      // Backup and set default map - should I save the config?
      std::string map_name = cfg->GetMapName();
      MapsList *maps = MapsList::GetInstance();
      int map_id_bak = maps->GetActiveMapIndex(); maps->SelectMapByName("banquise");
      if (!maps->lst[maps->GetActiveMapIndex()]->LoadBasicInfo()) {
        fmt = "Error!";
        break;
      }

      // Set max FPS
      Video *video = AppWarmux::GetInstance()->video;
      int fps = video->GetMaxFps(); video->SetMaxFps(60);

      // Set seeds - we'll set random ones afterwards
      RandomLocal().SetSeed(0xABADCAFE);
      RandomSync().SetSeed(0xABADCAFE);

      // All set, run the game!
      float num  = Game::UpdateGameRules()->Start(true);
      if (num) {
        GraphCanvas::Result res;
        res.list = Game::GetInstance()->GetBenchResults();
        GraphCanvas::FindMax(res);

        float  time = res.xmax - res.list[0].first;
        score = (num * video->window.GetWidth()*video->window.GetHeight())
              / (1000.0f * time);
        fmt = "%.0f";

        res.item = NULL;
        res.color = primary_red_color;
        graph->AddResult(res);
      } else {
        fmt = "Aborted";
      }
      graph->NeedRedrawing();

      // Restore all!
      video->SetMaxFps(fps);
      jbox->ActiveMusic(music);
      cfg->SetSoundEffects(sfx);
      maps->SelectMapByIndex(map_id_bak);
      cfg->SetMapName(map_name);
      cfg->SetDisplayMultiLayerSky(display_multisky);
      cfg->SetDisplayEnergyCharacter(display_energy);
      cfg->SetWindParticlesPercentage(wind_particles);
      cfg->SetGameMode(game_mode);
      GetTeamsList().SetPlayingList(list_bak);

      ok = num == 0;
      break;
    }
  default: break;
  }

  b->SetScore(fmt, score);
  return ok;
}
Пример #13
0
void ParseArgs(int argc, char * argv[])
{
  int c;
  int option_index = 0;
  struct option long_options[] = {
    {"unrandom",   no_argument,       NULL, 'u'},
    {"force-refresh", no_argument,    NULL, 'f'},
    {"help",       no_argument,       NULL, 'h'},
    {"version",    no_argument,       NULL, 'v'},
    {"play",       no_argument,       NULL, 'p'},
    {"quick-quit", no_argument,       NULL, 'q'},
    {"client",     optional_argument, NULL, 'c'},
    {"server",     no_argument,       NULL, 's'},
    {"index-server", optional_argument, NULL, 'i'},
    {"game-mode",  required_argument, NULL, 'g'},
    {"debug",      required_argument, NULL, 'd'},
    {"reset-config", no_argument,     NULL, 'r'},
    {"size",       required_argument, NULL, 'S'},
    {"replay",     required_argument, NULL, 'R'},
    {NULL,         no_argument,       NULL,  0 }
  };

  while ((c = getopt_long(argc, argv, "ufhvpqc::si::g:d:rS:R:",
                          long_options, &option_index)) != -1) {
    switch (c) {
    case 'u':
      RandomSync().UnRandom();
      RandomLocal().UnRandom();
      break;
    case 'f':
      // This option is useful to run with valgrind
      extern bool force_refresh;
      force_refresh = true;
      break;
    case 'h':
      PrintUsage(argv[0]);
      exit(EXIT_SUCCESS);
      break;
    case 'v':
      DisplayWelcomeMessage();
      exit(EXIT_SUCCESS);
      break;
    case 'p':
      choice = MainMenu::PLAY;
      skip_menu = true;
      break;
    case 'c':
      choice = MainMenu::NETWORK;
      net_action = NetworkConnectionMenu::NET_CONNECT;
      if (optarg)
        {
          Config::GetInstance()->SetNetworkClientHost(optarg);
        }
      skip_menu = true;
      break;
    case 'd':
#ifdef WMX_LOG
      printf("Debug: %s\n", optarg);
      AddDebugMode(optarg);
#else
      fprintf(stderr, "Option -d is not available. Warmux has not been compiled with debug/logging option.\n");
#endif
      break;
    case 'R':
      replay = optarg;
      break;
    case 's':
      choice = MainMenu::NETWORK;
      net_action = NetworkConnectionMenu::NET_HOST;
      skip_menu = true;
      break;
    case 'i':
      {
        std::string index_server_address;
        if (optarg) index_server_address = optarg;
        else index_server_address = "127.0.0.1";
        printf("Using %s as address for index server. This option must be used only for debugging.\n",
               index_server_address.c_str());
        IndexServer::GetInstance()->SetAddress(index_server_address.c_str());
      }
      break;
    case 'g':
      printf("Game-mode: %s\n", optarg);
      Config::GetInstance()->SetGameMode(optarg);
      break;
    case 'q':
      quit_game = true; // immediately exit the game after first run
      break;
    case 'r':
      {
        bool r;
        r = Config::GetInstance()->RemovePersonalConfigFile();
        if (!r)
          exit(EXIT_FAILURE);
        exit(EXIT_SUCCESS);
      }
      break;
    case 'S':
      {
	      uint width, height;
	      int ret = sscanf(optarg, "%ux%u", &width, &height);
	      if (ret == 2) {
	        Config::GetInstance()->SetVideoWidth(width);
	        Config::GetInstance()->SetVideoHeight(height);
	      } else {
	        fprintf(stderr, "Error: %s is not a valid resolution\n", optarg);
	      }
      }
      break;
    case '?': /* returns by getopt if option was invalid */
      PrintUsage(argv[0]);
      exit(EXIT_FAILURE);
      break;

    default:
      fprintf(stderr, "Sorry, it seems that option '-%c' is not implemented!\n", c);
      ASSERT(false);
      exit(EXIT_FAILURE);
      break;
    }
  }
}
Пример #14
0
bool Keyboard::HandleKeyEvent(const SDL_Event& evnt)
{
  // Not a registred event
  if (!IsRegistredEvent(evnt.type))
    return false;

  Key_Event_t event_type;
  switch(evnt.type) {
  case SDL_KEYDOWN:
    event_type = KEY_PRESSED;
    break;
  case SDL_KEYUP:
    event_type = KEY_RELEASED;
    break;
  default:
    return false;
  }

  //Handle input text for Chat session in Network game
  if (Game::GetInstance()->chatsession.CheckInput()) {
    if (event_type == KEY_PRESSED)
      Game::GetInstance()->chatsession.HandleKeyPressed(evnt);
    else if (event_type == KEY_RELEASED)
      Game::GetInstance()->chatsession.HandleKeyReleased(evnt);
    return false;
  }

  SDLKey basic_key_code = evnt.key.keysym.sym;

#ifdef DEBUG
  if (IsLOGGING("killsynchro")
      && basic_key_code == SDLK_k
      && event_type == KEY_RELEASED) {
    fprintf(stderr, "\n\nKILLING NETWORK SYNCHRONISATION!\n\n");
    RandomSync().SetSeed(0);
  }
#endif

  // Also ignore real key code of a modifier, fix bug #15238
  if (IsModifier(basic_key_code)) {
    int modifier_changed = modifier_only_bits ^ GetModifierBits();
    if (event_type == KEY_RELEASED) {
      for (std::set<SDLKey>::const_iterator it = pressed_keys.begin(); it != pressed_keys.end(); it++ ) {
        int key_code = *it + MODIFIER_OFFSET * modifier_changed;
        HandleKeyComboEvent(key_code, KEY_RELEASED);
      }
    } else if (modifier_only_bits && event_type == KEY_PRESSED) {
      for (std::set<SDLKey>::const_iterator it = pressed_keys.begin(); it != pressed_keys.end(); it++ ) {
        int key_code = *it + MODIFIER_OFFSET * modifier_only_bits;
        HandleKeyComboEvent(key_code, KEY_RELEASED);
      }
    }
    modifier_only_bits = GetModifierBits();
    return false;
  }
#ifdef MAEMO
  if (SDL_GetModState() & KMOD_MODE) {
    if (basic_key_code == SDLK_LEFT) basic_key_code = SDLK_UP;
    if (basic_key_code == SDLK_RIGHT) basic_key_code = SDLK_DOWN;
  }
#endif

  int key_code;
  int previous_modifier_bits = modifier_bits;
  modifier_bits = GetModifierBits();

  if (modifier_bits != previous_modifier_bits) {
    std::set<SDLKey>::const_iterator it = pressed_keys.find(basic_key_code);
    if (it !=  pressed_keys.end()) {
      key_code = basic_key_code + MODIFIER_OFFSET * previous_modifier_bits;
      HandleKeyComboEvent(key_code, KEY_RELEASED);
      if (key_code != basic_key_code)
        HandleKeyComboEvent(basic_key_code, KEY_RELEASED);
      pressed_keys.erase(basic_key_code);
      if (event_type == KEY_PRESSED) {
        key_code = basic_key_code + MODIFIER_OFFSET * modifier_bits;
        HandleKeyComboEvent(key_code, KEY_PRESSED);
        pressed_keys.insert(basic_key_code);
      }
      return true;
    }
  }

  if (event_type == KEY_PRESSED) {
    key_code = basic_key_code + (MODIFIER_OFFSET * modifier_bits);
    HandleKeyComboEvent(key_code, KEY_PRESSED);
    if (previous_modifier_bits ^ modifier_bits) {
      key_code = basic_key_code + (MODIFIER_OFFSET * previous_modifier_bits);
      HandleKeyComboEvent(key_code, KEY_RELEASED);
    }
    pressed_keys.insert(basic_key_code);
  } else {
    ASSERT(event_type == KEY_RELEASED);
    key_code = basic_key_code + (MODIFIER_OFFSET * previous_modifier_bits);
    HandleKeyComboEvent(key_code, KEY_RELEASED);
    if (key_code != basic_key_code)
      HandleKeyComboEvent(basic_key_code, KEY_RELEASED);
    pressed_keys.erase(basic_key_code);
  }
  return true;
}