示例#1
0
// ---------------------------------------------------------------
// a freestanding lump of material
// ---------------------------------------------------------------
void t_material_pile::activate_trigger( t_army* army, t_adv_map_point const& point, 
		                                t_direction direction, t_adventure_frame* frame )
{
	t_player* owner = army->get_owner();

	owner->gain( m_amount.material, m_amount.amount );
	if (!army->get_owner()->is_computer())
	{
		t_adventure_map*		 map = frame->get_map();
		t_adventure_map_window*  map_window = frame->get_map_window();
		t_screen_point           screen_point;
		t_window*				 timed_window;
		t_text_window*			 text_window;
		std::string              text;

		screen_point = get_screen_point( *map, *this, get_position() ) - map_window->get_view_pos();
		timed_window = new t_timed_window( screen_point, map_window, 3000, 
			                                         t_screen_point( -1, -1 ), 100 );
		text = format_string( "+%i ", m_amount.amount ) 
				+ get_material_name( m_amount.material );
		text_window = new t_text_window( get_font( 25 ), t_screen_point(0,0), 
			                             timed_window, text, t_pixel_24( 255, 255, 255 ) );
		text_window->set_drop_shadow( true );
		frame->update_funds();

		t_adventure_sound_type type = (t_adventure_sound_type)( (int)k_adventure_sound_pickup_1 + random(0,5) );
		get_adventure_sound( type )->play( get_sound_volume() );
	}
	destroy();
}
示例#2
0
int update_sound( t_level_map_point_2d point, t_managed_sound * playing_sound, bool initing_volume )
{
	t_level_map_point_2d const & sound_point = playing_sound->get_position();
	int dist_sq = 0;

	// if the sounds are on the same level
	// check their distances from one another
	if( point.level == sound_point.level && playing_sound->get_sound_ptr()->is_playing() )
	{
		int row_delta = point.row - sound_point.row;
		int col_delta = point.column - sound_point.column;

		dist_sq = ( row_delta * row_delta ) + ( col_delta * col_delta );

		// adjust the sound volume based on distance
		if( dist_sq <= k_max_sound_dist_sq )
		{
			int volume = get_sound_volume() + 10000;
			volume = (int)( (float)volume * ( 1.0f - ( (float)dist_sq / (float)k_max_sound_dist_sq ) ) ) - 10000;
			playing_sound->set_former_volume(volume);	// set intended volume
			playing_sound->get_sound_ptr()->set_volume( volume, !initing_volume );
		}
	}

	return dist_sq;
}
示例#3
0
文件: music.c 项目: DrItanium/moo
void queue_song(
	short song_index)
{
	if (music_state && music_state->initialized && get_sound_volume())
	{
		if (!music_state->channel)
		{	
			allocate_music_channel();
		}
	
		if (music_state->channel)
		{
			if (music_playing())
			{
				/* By setting the song_index after we tell it to fade, we will */
				/*  cause the new song to start at the end of the fade. */
				fade_out_music(10*MACINTOSH_TICKS_PER_SECOND);
				music_state->song_index= song_index;
			}
			else
			{
				assert(music_state->state==_no_song_playing);
		
				/* Must be done everytime in case Jason killed it in sound.c */
				music_state->channel->userInfo= (long) music_state;
				music_state->song_index= song_index;
				music_state->state= _delaying_for_loop;
				music_state->phase= 1;
				music_state->ticks_at_last_update= TickCount();
				music_state->flags &= ~_song_completed;
				/* next time through we will start.. */
			}
		}
	}
}
示例#4
0
void
ConfigManager::set_sound_volume(int v)
{
  log_info("ConfigManager::set_sound_volume: %1%", v);
  Sound::PingusSound::set_sound_volume(static_cast<float>(v) / 100.0f);

  m_opts.sound_volume.set(get_sound_volume());
}
示例#5
0
// --------------------------------------------------------
// handle a left button down
// --------------------------------------------------------
void t_button::left_button_down( t_mouse_event const& event )
{
    if (m_pressed || m_disabled)
        return;
    m_pressed = true;
	set_image();
	get_dialog_sound( k_dialog_sound_button )->play( get_sound_volume() );
	m_down_clicked( this );
}
示例#6
0
// --------------------------------------------------------------
// object which gives a temporary boost to luck
// --------------------------------------------------------------
void t_luck_object::activate_trigger( t_army* army, t_adv_map_point const& point, 
		                              t_direction direction, t_adventure_frame* frame )
{
	int  i;
	bool any_award = false;

	// loop through all heroes/creatures in the army and award temporary statistic based on subtype

	t_creature_array& creatures = army->get_creatures();


	for (i = 0; i < t_creature_array::k_size; i++)
	{
		if (creatures[i].get_number() == 0)
			continue;
		if (creatures[i].has_temporary_bonus( get_type() ))
			continue;
		add_bonus( creatures[i] );
		any_award = true;
	}

	// determine what response to print
	if (army->get_owner()->is_computer())
		return;

	t_basic_dialog*          dialog;
	std::string              text;

	dialog = new t_basic_dialog;
	if (any_award)
	{
		text = get_text( "initial" );
		add_icons( dialog );
	}
	else
	{
		text = get_text( "empty" );
	}

	dialog->set_text( text );
	dialog->add_ok_button();
	dialog->set_title( get_name() );
	dialog->open( get_dialog_bottom( point ), true, k_align_bottom );
	t_sound_cache music = get_music_playing();
	stop_music();
	get_dialog_sound( k_dialog_sound_luck )->play( get_sound_volume() );
	dialog->run_modal();
    // Update stats.
    frame->update_army();
	play_music( music );
}
示例#7
0
void t_sanctuary::activate_trigger( t_army* army, t_adv_map_point const& point, 
									t_direction direction, 
									t_adventure_frame* frame )
{
	t_dialog_sanctuary*				dialog;
	t_player*						player = army->get_owner();
	std::string						text;
	t_screen_point					zero(0,0);

	resurrect_heroes( *army, k_text_sanctuary_resurrects_heroes, frame );
	dialog = new t_dialog_sanctuary( frame );

	if (!empty())
	{
		dialog->set_text( get_text( "denied" ) );
		dialog->enable_entry( false );
	}
	else if (m_paid[army->get_owner_number()])
	{
		dialog->set_text( get_text( "paid" ) );
		dialog->enable_entry( true );
	}
	else
	{
		dialog->set_text( get_text( "initial" ));
		dialog->enable_entry( player->get_funds()[k_gold] >= k_rental_fee);
	}
	dialog->set_title( get_name() );

	t_sound_cache music = get_music_playing();
	stop_music();
	get_dialog_sound( k_dialog_sound_sanctuary )->play( get_sound_volume() );
	switch (dialog->run_modal())
	{
		case k_choice_cancel:
			return;

		case k_choice_enter:
			if (!m_paid[army->get_owner_number()])
			{
				player->spend( k_gold, k_rental_fee );
				m_paid[army->get_owner_number()] = true;
			}
			set_owner( army->get_owner_number() );
			swap( army->get_creatures() );
			frame->destroy_army( army );
			break;
	}
	play_music( music );
}
示例#8
0
// -------------------------------------------------------
// artifact as it appears on the adventure map
// -------------------------------------------------------
void t_adv_artifact::activate_trigger( t_army* army, t_adv_map_point const& point, 
		                               t_direction direction, t_adventure_frame* frame )
{
	destroy(); // we should not be deleted by this, because the caller has a reference.
	if (!army->get_owner()->is_computer())
	{
		army->add( m_artifact );

		std::string text = m_artifact.get_pickup_text();
		std::string name = m_artifact.get_name();
		t_adventure_map*		 map = get_map();
		t_adventure_map_window*  map_window = frame->get_map_window();
		t_level_map_point_2d     location = get_position();
		t_screen_point           screen_point = get_screen_point( *map, *this, location )
												- map_window->get_view_pos();
		t_artifact_type          type = m_artifact.get_icon();
		t_bitmap_layer_ptr       icon = get_icon( type );

		//t_bitmap_layer_cache_window_ptr icon_window;
		t_counted_ptr<t_basic_dialog>	dialog = new t_basic_dialog( frame );

		dialog->add_ok_button();
		//icon_window = new t_bitmap_layer_cache_window( icon, t_screen_point(0,0), dialog, false );
		//icon_window->set_help_balloon_text( m_artifact.get_name() );
		//icon_window->set_right_click_text( m_artifact.get_help_text() );
		dialog->add_artifact( m_artifact, 1, true );
		dialog->set_text( text );
		//dialog->add_display_window( icon_window, name );
		dialog->set_title( get_name() );
		dialog->open( screen_point, true, k_align_bottom );
		t_sound_cache music = get_music_playing();
		stop_music();
		get_dialog_sound( k_dialog_sound_treasure )->play( get_sound_volume() );
		dialog->run_modal();
		play_music( music );
	} 
	else 
		ai_give_artifact_to_army( *army, m_artifact );
}
示例#9
0
/*
** Player visits this blacksmith.
*/
void t_adv_blacksmith::activate_trigger( t_army* army_ptr, t_adv_map_point const& point, 
		                               t_direction direction, t_adventure_frame* frame_ptr )
{

	t_counted_ptr<t_dialog_blacksmith> dialog_ptr;

    // Set player visited.
	m_visited[army_ptr->get_owner_number()] = true;

    /*
    ** Create and show dialog, and let user buy from this blacksmith.
    */
	dialog_ptr = new t_dialog_blacksmith( frame_ptr );
	dialog_ptr->init_dialog( frame_ptr, army_ptr, m_available_potions, m_available_items, m_available_long_items);
	t_sound_cache music = get_music_playing();
	stop_music();
	get_dialog_sound( k_dialog_sound_marketplace )->play( get_sound_volume() );
	dialog_ptr->run_modal();
	play_music( music );
    
	frame_ptr->update_funds();
}
示例#10
0
// -------------------------------------------------------------------
// Army touched the prison. Release prisoner
// -------------------------------------------------------------------
void t_adv_prison::activate_trigger( t_army* army, t_adv_map_point const& point, 
		                             t_direction direction, t_adventure_frame* frame )
{
	t_counted_ptr< t_adventure_map > map = frame->get_map();

	t_player* owner = army->get_owner();

	if (!owner) return;

	if (!owner->is_computer())
	{
		/*
		** Setup result dialog box.
		*/
		t_counted_ptr<t_basic_dialog> dialog_ptr = new t_basic_dialog ();
		std::string     text;

		text = replace_keywords( get_text("Initial"), m_hero.get() );

		dialog_ptr->set_text( text );
		dialog_ptr->add_ok_button();
		dialog_ptr->add_creature ( *m_hero, false );
		/*
		** Update frame.
		*/
		//frame->update_armies();
		frame->update();

		// Result dialog box.
		dialog_ptr->open();
		t_sound_cache music = get_music_playing();
		stop_music();
		get_dialog_sound( k_dialog_sound_thieves_guild )->play( get_sound_volume() );
		dialog_ptr->run_modal();
		play_music( music );
	}

    /*
    ** Add hero.  Add to creature array if possible.
    */
    if (army->get_creatures().can_add_hero())
    {
        army->get_creatures().add( m_hero ); //, 1 );
    }
    /*
    ** Or else create new army.
    */
    else	// TODO:  Should this be "else if ( player.can_create_army() )"? -- SCR 1/24/02
    {
	    t_army *		    temp_army = new t_army;
	    t_creature_array&   temp_creatures = temp_army->get_creatures();

        /*
        ** Create new army.
        ** Make army same color as player.
        */
	    temp_creatures.add ( m_hero );
	    temp_army->set_owner( army->get_owner_number() );
	    t_army * army = frame->create_army( this, temp_army, temp_army );

		army->trigger_events();
    }

    destroy();
}
示例#11
0
void t_magic_university::activate_trigger( t_army* army, t_adv_map_point const& point,
        t_direction direction, t_adventure_frame* frame )
{
    int                  i;
    t_hero*              hero;
    std::vector<t_hero*> heroes;
    t_creature_array&    creatures = army->get_creatures();
    std::string          text;
    int                  random_skill_index = 0;

    if (army->get_owner_number() >= 0)
        m_visited[army->get_owner_number()] = true;
    else
        return; // A gray army shouldn't be here.

    // AI decider
    if (army->get_owner()->is_computer())
    {
        for (int i = 0; i < t_creature_array::k_size; i++)
        {
            t_hero* hero  = (*army)[i].get_hero();
            if (!hero) continue;

            t_skill_type type = get_best_compatible_skill( hero, army );
            while (type != k_skill_none)
            {
                hero->learn_skill(t_skill(type, k_mastery_basic), false );
                army->get_owner()->spend( k_gold, k_skill_upgrade_cost );
                type = get_best_compatible_skill( hero, army );
            }
        }
        return;
    }

    /*
    ** Check for eligible heroes.
    */
    bool                    dead_heroes = true;
    bool                    any_heroes = false;
    for (i = 0; i < t_creature_array::k_size; i++)
    {
        hero = creatures[i].get_hero();

        // Hero or not?
        if (hero == 0)
            continue;

        any_heroes = true;

        if (hero->is_dead())
            continue;
        dead_heroes = false;

        heroes.push_back( hero );
    }

    t_sound_cache music = get_music_playing();
    stop_music();
    get_dialog_sound( k_dialog_sound_university )->play( get_sound_volume() );
    std::string status_text;
    if (any_heroes && (dead_heroes == true))
    {
        status_text = get_text("heroes_dead");
        if (status_text == "")
            status_text = k_text_dead_heroes_ineligible;
        ok_dialog( status_text, get_dialog_bottom( point ) );
        play_music( music );
        return;
    }
    // No heroes, show app. message...
    else if (!any_heroes)
    {
        status_text = get_text ("help.empty");
        ok_dialog( status_text, get_dialog_bottom( point ) );
        play_music( music );
        return;
    }

    select_heroes_dialog ( heroes, frame, army);
    play_music( music );
}
示例#12
0
// ------------------------------------------------------------------------
// class to move army on adventure map
// ------------------------------------------------------------------------
void t_army_mover::enter_new_square()
{
	assert( m_step < m_path.size() );
	assert( m_crossing_point > 0 );

	t_adventure_map const&  map = *m_army->get_map();
	t_adventure_path_point& point = m_path[m_step];
	t_screen_point			old_screen_point;
	t_screen_point			new_screen_point;
	t_screen_point			delta;

	m_crossing_point = -m_divisor;
	old_screen_point = get_screen_point( map, *m_army, m_army->get_position() );
	new_screen_point = get_screen_point( map, *m_army, point );
	delta = new_screen_point - old_screen_point;
	delta *= m_divisor;
	m_offset -= delta;
	m_army->move( point );
	expend_movement( point.move_cost );
	mark_eluded_armies();
	if (m_is_visible && !map.get_map_window()->is_visible( point ) )
	{
		map.get_map_window()->center_view( point );
	}

	// play appropriate movement sound
	t_level_map_point_2d const &	army_point = m_army->get_creatures().get_position();
	if ( !m_movement_sound && m_is_visible )
	{
		t_creature_stack &				leader	= m_army->get_creatures().get_leader();
		t_sound_ptr						sound;
		t_adv_actor_action_id			action = m_army->get_action();
	
		if (m_army->is_boat())
		{
			static t_sound_cache	boat_sound_cache( "hero ship.walk" ) ;

			sound =  boat_sound_cache.get();
		}
		else
			sound = leader.get_sound( action );

		if ( sound )
			m_movement_sound = play_adventure_sound( *m_army, sound, army_point, 
													 get_sound_volume() );
	}

	if ( m_movement_sound && m_is_visible )
	{
		// update the movement sound's position so the sound follows the owner army
		t_level_map_point_2d const & sound_point = m_army->get_creatures().get_position();

		if( m_movement_sound.get() )
			m_movement_sound->set_position( sound_point );
	}

	// update the active sounds queue
	bool is_computer = false;
	if( m_army )
	{
		t_player* owner = m_army->get_owner();
		is_computer = owner && owner->is_computer();
	}

	if( m_is_visible && !is_computer )
		update_active_sounds( army_point, map );
}