Пример #1
0
/**
 * \brief Create level bonus objects.
 */
void ptb::honeypot::create_level_bonus(const std::string& name)
{
  bonus_points* new_bonus = new bonus_points( name, 0 );

  new_bonus->set_picture_filename("gfx/ui/bonus-icons/bonus-icons.png");
  new_bonus->set_picture_name(name);
  new_bonus->set_condition
    ( bear::engine::bool_level_variable_getter(&get_level(), name) );

  new_item( *new_bonus );
  CLAW_ASSERT(new_bonus->is_valid(),
              "The bonus isn't correctly initialized" );
  new_bonus->set_center_of_mass(get_center_of_mass());

  if ( m_id == 1 )
    {
      bonus_points* bonus = new bonus_points( "Honey pots", 5000 );

      bonus->set_points
        ( 5000
          * bear::engine::linear_level_variable_getter<unsigned int>
          (&get_level(), "honeypots_found") );

      new_item( *bonus );
      CLAW_ASSERT(new_bonus->is_valid(),
                  "The bonus isn't correctly initialized" );
      bonus->set_center_of_mass(get_center_of_mass());
    }
} // honeypot::create_level_bonus()
Пример #2
0
/**
 * \brief Create a splinter item.
 * \param splinter_index Index of animation in splinter_animations list.
 * \param pos Position of item to create.
 */
void bear::explosion_effect_item::create_splinter_item
(unsigned int splinter_index, bear::universe::position_type pos)
{
  bear::decorative_item* item = new bear::decorative_item;

  item->set_animation(m_splinter_animations[splinter_index]);
  item->set_kill_when_leaving(true);
  item->set_kill_when_finished(false);
  item->set_mass(1);
  item->set_z_position(get_z_position());
  item->set_density(0.002);

  universe::force_type force;
  double angle = ( 6.283 * rand() ) / RAND_MAX;
  double factor = (double)rand() / RAND_MAX / 2.0 + 0.5;
  force.x = cos(angle) * m_force * factor;
  force.y = sin(angle) * m_force * factor;
  item->set_external_force(force);

  item->set_system_angle(angle);
  item->set_system_angle_as_visual_angle(true);

  new_item( *item );

  item->set_center_of_mass(pos);

  CLAW_ASSERT
    ( item->is_valid(),
      "A decorative item created by exposion_effect_item isn't correctly "
      "initialized" );

} // explosion_effect_item::create_splinter_item()
Пример #3
0
/**
 * \brief Get a workspace by its name.
 * \param w The workspace to give.
 */
const bf::workspace&
bf::path_configuration::get_workspace( const std::string& w ) const
{
    CLAW_ASSERT( has_workspace( w ), "Workspace is required" );

    return m_workspaces.find(w)->second;
} // path_configuration::get_workspace()
Пример #4
0
/**
 * \brief Check if the bottom of the "that" item was
 *        lower than \a m_value, relative to the top of the "self" item.
 * \param info Informations on the collision.
 * \param self The first item in the collision.
 * \param that The other item in the collision.
 */
bool bear::universe::bottom_contact_is_lower::operator()
  ( const collision_info& info, physical_item& self, physical_item& that ) const
{
  bear::universe::position_type origin( that.get_bottom_middle() );
  claw::math::line_2d<bear::universe::coordinate_type> movement
    ( origin, info.other_previous_state().get_bottom_middle() - origin );
  bear::universe::coordinate_type that_bottom;
  bear::universe::coordinate_type y_bound;

  switch ( info.get_collision_side() )
    {
    case zone::middle_right_zone:
      that_bottom = movement.y_value( self.get_right() );
      y_bound = m_line.y_value( self.get_width() );
      break;
    case zone::middle_left_zone:
      that_bottom = movement.y_value( self.get_top_left().x );
      y_bound = m_line.y_value( self.get_top_left().x );
      break;
    case zone::middle_zone:
      that_bottom = info.other_previous_state().get_bottom();
      y_bound = m_line.y_value
        ( info.other_previous_state().get_center_of_mass().x
          - self.get_top_left().x );
      break;
    default:
      {
        CLAW_ASSERT( false, "This test is for left/middle/right collisions" );
      }
    }

  return that_bottom - (int)self.get_top_left().y < y_bound;
} // bottom_contact_is_lower::operator()()
Пример #5
0
/**
 * \brief Function called when the explosition starts.
 */
void rp::zeppelin::explose()
{ 
  set_transportability(false);
  kill_interactive_item();
  drop();
  m_hit = true;
  util::create_floating_score(*this,750);

  bear::universe::position_type pos = get_center_of_mass();
  pos.x -= get_width()/4;

  for ( unsigned int i = 0; i != 3; ++i )
    {
      explosion* item = new explosion(15,20,0.6);
      item->set_z_position(get_z_position() + 1000);
      item->set_combo_value(get_combo_value());
      item->set_center_of_mass(pos);
      new_item( *item );
      CLAW_ASSERT( item->is_valid(),
                   "The explosion of bomb isn't correctly initialized" );
      
      bear::universe::forced_tracking m;
      m.set_reference_point_on_center(*this);
      item->set_forced_movement(m);
      pos.x += get_width()/4;
    }

  start_model_action("explose");
} // zeppelin::explose()
Пример #6
0
/**
 * \brief Align the other item of the collision.
 * \param info Some informations about the collision.
 * \param policy The description of how to align the items.
 */
bool bear::universe::physical_item::default_collision
( const collision_info& info, const collision_align_policy& policy )
{
  bool result(false);
  position_type p( info.get_bottom_left_on_contact() );

  switch( info.get_collision_side() )
    {
    case zone::bottom_zone:
      p.y -= get_align_epsilon();
      result = collision_align_bottom(info, p, policy);
      break;
    case zone::top_zone:
      p.y += get_align_epsilon();
      result = collision_align_top(info, p, policy);
      break;
    case zone::middle_left_zone:
      p.x -= get_align_epsilon();
      result = collision_align_left(info, p, policy);
      break;
    case zone::middle_right_zone:
      p.x += get_align_epsilon();
      result = collision_align_right(info, p, policy);
      break;
    case zone::middle_zone:
      result = collision_middle(info, policy);
      break;
    default: { CLAW_ASSERT( false, "Invalid collision side." ); }
    }

  return result;
} // physical_item::default_collision()
Пример #7
0
/**
 * \brief Fill m_sprite.
 */
void bf::action_player::fill_sprites()
{
  m_sprite.clear();

  if ( m_action == NULL )
    return;

  const snapshot* s = m_action->get_snapshot_before_or_at_date(m_date);

  if ( s == NULL )
    return;

  snapshot::const_mark_placement_iterator it;

  for( it=s->mark_placement_begin(); it!=s->mark_placement_end(); ++it )
    {
      const mark* m( it->get_mark() );

      if ( m->has_animation() )
        {
          player_map::const_iterator itp=m_player.find(m);

          CLAW_ASSERT
            ( itp!=m_player.end(),
              "There is no player for a mark with an animation." );

          m_sprite[it->get_mark()] = itp->second.get_sprite();

          if ( m->apply_angle_to_animation() )
            m_sprite[it->get_mark()].set_angle
              ( m_sprite[it->get_mark()].get_angle()
                + it->get_angle() );
        }
    }
} // action_player::fill_sprites()
Пример #8
0
/**
 * \brief Get the string value of an argument.
 * \param arg_name The name of the argument to get.
 * \pre has_value(arg_name)
 */
const std::string&
claw::arguments::get_string( const std::string& arg_name ) const
{
  CLAW_ASSERT( has_value(arg_name),
               "arguments::get_string(): argument is not set." );

  return m_pairs.find( arg_name )->second.back();
} // arguments::get_string()
Пример #9
0
/**
 * \brief Get the real value of an argument.
 * \param arg_name The name of the argument to get.
 * \pre has_value(arg_name)
 */
double claw::arguments::get_real( const std::string& arg_name ) const
{
  CLAW_ASSERT( has_value(arg_name),
               "arguments::get_real(): argument is not set." );

  std::istringstream iss( m_pairs.find( arg_name )->second.back() );
  double val;
  iss >> val;

  return val;
} // arguments::get_real()
Пример #10
0
/**
 * \brief Create an explosion.
 * \param nb_explosions Number of explosions to display.
 * \param radius The radius of the explosion.
 */
void rp::tnt::create_explosion
(unsigned int nb_explosions, bear::universe::coordinate_type radius)
{ 
  explosion* item = new explosion(nb_explosions,radius, 0.6);
      
  item->set_z_position(get_z_position() + 10);
  item->set_combo_value(get_combo_value());
  item->set_center_of_mass(get_center_of_mass());
  new_item( *item );
  CLAW_ASSERT( item->is_valid(),
               "The explosion of tnt isn't correctly initialized" );
} // tnt::create_explosion()
Пример #11
0
/**
 * \brief Set item on the bridge.
 * \param The item on the bridge.
 */
void bear::bridge::item_on_bridge::set_item_on_bridge(engine::base_item* item)
{
  CLAW_ASSERT
    ( item != NULL,
      "An item_on_bridge is created with NULL item" );
  
  m_item = item_handle(item);
  
  m_reference_item = new bear::reference_item;
  m_reference_item->set_center_of_mass
    ( item->get_bottom_middle() + 
      universe::position_type(0,-s_line_width/2) );
} // item_on_bridge() 
Пример #12
0
/**
 * \brief Get the field with a given name, common to all items.
 * \param name The name of the field.
 */
const bf::type_field&
bf::item_field_edit::get_common_field( const std::string& name ) const
{
  CLAW_PRECOND( !empty() );

#ifndef NDEBUG
  for (item_iterator it=begin(); it!=end(); ++it)
    {
      CLAW_ASSERT( it->get_class().has_field(name),
                   "Class '" + it->get_class().get_class_name() +
                   "' has no field named '" + name + "'." );
    }

  const type_field::field_type check_type =
    begin()->get_class().get_field(name).get_field_type();

  for (item_iterator it=begin(); it!=end(); ++it)
    {
      CLAW_ASSERT( it->get_class().get_field(name).get_field_type()
                   == check_type,
                   "Class '" + it->get_class().get_class_name() +
                   "' has a field named '" + name
                   + "' but with a different type." );
    }

  const bool check_list =
    begin()->get_class().get_field(name).is_list();

  for (item_iterator it=begin(); it!=end(); ++it)
    {
      CLAW_ASSERT( it->get_class().get_field(name).is_list() == check_list,
                   "Class '" + it->get_class().get_class_name() +
                   "' has a field named '" + name
                   + "' but with a different list status." );
    }
#endif

  return (*m_group.begin())->get_class().get_field(name);
} // item_field_edit::get_common_field()
Пример #13
0
/**
 * \brief Add a block for the margins.
 * \param x X-coordinate of the block.
 * \param y Y-coordinate of the block.
 * \param width The width of the block.
 * \param height The height of the block.
 * \param block The block to add.
 */
void ptb::layer_border::new_margin_block
( bear::universe::coordinate_type x, bear::universe::coordinate_type y,
  bear::universe::size_type width, bear::universe::size_type height,
  base_item& block ) const
{
  block.set_bottom_left( bear::universe::position_type(x, y) );
  block.set_size( width, height );
  block.set_insert_as_static();

  CLAW_ASSERT( block.is_valid(),
               "layer_border::new_margin_block(): the block is not valid" );

  new_item( block );
} // layer_border::new_margin_block()
/**
 * \brief Create level bonus object.
 */
void ptb::hideout_bonus_item::create_level_bonus()
{
  bonus_points* new_bonus = new bonus_points( "Great explorer", 10000 );

  new_bonus->set_picture_filename("gfx/ui/bonus-icons/bonus-icons.png");
  new_bonus->set_picture_name("hideouts");
  new_bonus->set_condition
   ( bear::engine::bool_level_variable_getter
     (&get_level(), "all_hideouts_found"));

  new_item( *new_bonus );
  CLAW_ASSERT(new_bonus->is_valid(),
              "The bonus isn't correctly initialized" );
  new_bonus->set_center_of_mass(get_center_of_mass());
} // hideout_bonus_item::create_level_bonus()
Пример #15
0
/**
 * \brief Show the adequate dialog for editing a given string field.
 * \param f The type of the field we are editing.
 */
void bf::item_field_edit::show_string_property_dialog( const type_field& f )
{
  switch ( f.get_range_type() )
    {
    case type_field::field_range_free:
      show_property_dialog< free_edit<string_type> >(f, _("string"));
      break;
    case type_field::field_range_set:
      show_property_dialog< set_edit<string_type> >(f, _("string"));
      break;
    default:
      {
        CLAW_ASSERT(false, "range type is not valid.");
      }
    }
} // item_field_edit::show_string_property_dialog()
Пример #16
0
/**
 * \brief Create a decoration.
 */
void ptb::honeypot::create_decoration()
{
  bear::decorative_item* item = new bear::decorative_item;

  item->set_animation
    (get_level_globals().get_animation
     ("animation/corrupting-bonus-disapearing.canim"));
  item->get_rendering_attributes().set_angle(get_visual_angle());
  item->set_kill_when_finished(true);
  item->set_z_position(get_z_position()-1);

  new_item( *item );

  item->set_center_of_mass(get_center_of_mass());

  CLAW_ASSERT( item->is_valid(),
               "The decoration of corrupting_bonus isn't correctly "
               "initialized" );
} // honeypot::create_decoration()
Пример #17
0
/**
 * \brief Create an extremities.
 */
void bear::bridge::create_extremities
( base_item* & item, base_item* reference)
{  
  item = new bear::reference_item;

  CLAW_ASSERT
    (item->is_valid(),
     "The reference_item created by bridge isn't correctly initialized" );

  item->set_center_of_mass
    ( reference->get_center_of_mass() + 
      universe::position_type(0,-s_line_width/2));
  
  new_item( *item );

  bear::universe::forced_tracking mvt;
  mvt.set_reference_point_on_center(*reference);
  
  item->set_forced_movement( mvt );
} // bridge::create_extremities()
Пример #18
0
/**
 * \brief Create a dust item.
 * \param dust_index Index of animation in dust_animations list.
 * \param pos Position of item to create.
 */
void bear::explosion_effect_item::create_dust_item
(unsigned int dust_index, bear::universe::position_type pos)
{
  bear::decorative_item* item = new bear::decorative_item;

  item->set_animation(m_dust_animations[dust_index]);
  item->set_kill_when_finished(true);
  item->set_kill_when_leaving(true);
  item->set_z_position(get_z_position()-1);
  double angle = ( 6.283 * rand() ) / RAND_MAX;
  item->set_system_angle(angle);
  item->set_system_angle_as_visual_angle(true);

  new_item( *item );

  item->set_center_of_mass(pos);

  CLAW_ASSERT
    ( item->is_valid(),
      "A decorative item created by exposion_effect_item isn't correctly "
      "initialized" );
} // explosion_effect_item::create_dust_item()
Пример #19
0
/**
 * \brief Create some smoke.
 * \param ref The item on which the smoke is created.
 * \param min_intensity The minimum intensity of the clouds.
 * \param max_intensity The maximum intensity of the clouds.
 * \param z_shift The z position of the smoke, relatively to the reference.
 */
void rp::util::create_smoke
( const bear::engine::base_item& ref, double min_intensity,
  double max_intensity, int z_shift )
{
  bear::visual::animation anim
    ( ref.get_level_globals().get_animation("animation/effect/steam.canim") );
  anim.set_time_factor( 1 + 3 * (double)rand() / RAND_MAX );

  const double intensity =
    min_intensity + (max_intensity - min_intensity) * rand() / RAND_MAX;
  anim.set_intensity( intensity, intensity, intensity );

  bear::decorative_item* item = new bear::decorative_item;

  item->set_mass( 1 );
  item->set_density( 0.0006 + 0.0002 * rand() / RAND_MAX );

  item->set_animation( anim );
  item->set_z_position( ref.get_z_position() + z_shift );
  item->set_kill_when_leaving( true );
  item->set_kill_when_finished( true );
  item->get_rendering_attributes().set_angle( 6.29 * rand() / RAND_MAX );

  const bear::universe::position_type pos
    ( ref.get_width() * rand() / RAND_MAX,
      ref.get_height() * rand() / RAND_MAX );

  item->set_center_of_mass( ref.get_bottom_left() + pos );
  
  ref.new_item( *item );
  
  apply_random_smoke_effect( *item );

  CLAW_ASSERT
    ( item->is_valid(), 
      "The decoration of explosion isn't correctly initialized" );
} // util::create_smoke()