Esempio n. 1
0
static void test_add_bonus(void ** state)
{
	Board b = init_board1();
	int nb_snakes = 0;
	Serpent** snakes = malloc(nb_snakes * sizeof(Serpent*));
	add_bonus(&b, snakes, nb_snakes);
	assert_non_null(b.pTabBonus);
	assert_int_equal(b.nNbBonus, 1);
	free_board(b);
	free_snakes(snakes, nb_snakes);
}
Esempio n. 2
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 );
}
Esempio n. 3
0
// Kill the enemy
void ENEMY::die() {
	if(dying)
		return;		// Hey, don't you die twice, man! ;)
	dying = true;
	kill_count++;
	die_anim = 1.0f;

	// Create a bonus
	add_bonus((int)get_real_x(), (int)get_real_y(), type);

	// Play the sound
	static int last_sound = -1;
	int sound = last_sound;
	while(sound == last_sound)
		sound = RAND(SND_DIE1, SND_DIE6);
	play_sound(sound, false);
	last_sound = sound;
}
Esempio n. 4
0
bool
Player::add_bonus(const std::string& bonustype)
{
  BonusType type = NO_BONUS;

  if(bonustype == "grow") {
    type = GROWUP_BONUS;
  } else if(bonustype == "fireflower") {
    type = FIRE_BONUS;
  } else if(bonustype == "iceflower") {
    type = ICE_BONUS;
  } else if(bonustype == "none") {
    type = NO_BONUS;
  } else {
    std::ostringstream msg;
    msg << "Unknown bonus type "  << bonustype;
    throw std::runtime_error(msg.str());
  }

  return add_bonus(type);
}
Esempio n. 5
0
//---------- Begin of function PlayerSchool::scenario_check_target ----------//
//!
void PlayerSchool::scenario_check_target() {
    if ( scenario_id <= SCN_NONE )
	return;

    //---------------------------------------------------------------------------//
    // when the player has achieved all possible goals in a scenario, display the
    // following message in a popup window
    //---------------------------------------------------------------------------//

    if ( scen_quit_game_flag > 0  &&
	 sys.view_mode != MODE_AWARD_REPORT &&
	 sys.view_mode != MODE_FINAL_SCORE ) {
	int rc = 0;

	vga.use_front();
	rc = box.ask("You have achieved all possible scenario objectives.\n Do you want to continue playing?", "Yes", "No");
	vga.use_back();

	if ( rc == 1 ) {
	    scen_quit_game_flag = 0;                    // continue play
	    sys.redraw_all_flag = 1;
	}
	else
	    sys.set_staying_view_mode(MODE_FINAL_SCORE);// should go to final game score screen

	return;
    }

    //-------- check scenario target monthly ---------///

    if ( info.game_day != 1 )
	return;

    //----------------------------------//

    int i;
    int plaque = -1;                                // = enum { PLAQUE_GOLD=0, PLAQUE_SILVER, PLAQUE_BRONZE, TOTAL_PLAQUE_COUNT=3 };
    int bonus = 0;
    int gameStartYear = date.year(info.game_start_date);
    int yearPassed = info.game_year - gameStartYear;

    if ( info.game_month < date.month(info.game_start_date) )
	yearPassed--;

    err_when( yearPassed < 0 );

    //---- if the game is approaching its time limit, display warning message ------//

    if( yearPassed == scenario_max_game_years - 1 && info.game_month == 9 ) {
	news_array.scenario_near_end();
    }

    //------- check the target of individual scenarios ------//

    switch (  scenario_id ) {

    case SCN_BALANCE_BUDGET:
	if( scen_balance_budget_score() >= scenario_base ) {
	    if ( scenario_target[2] <= finance.this_year.surplus_deficit ) {
		if ( yearPassed <= goal_deadline[PLAQUE_BRONZE] )
		    plaque = PLAQUE_BRONZE;
	    }
	    else if ( scenario_target[1] <= finance.this_year.surplus_deficit ) {
		if ( yearPassed <= goal_deadline[PLAQUE_SILVER] )
		    plaque = PLAQUE_SILVER;
	    }
	    else if ( scenario_target[0] <= finance.this_year.asset_array[AC_OPERATING_RESERVE] ) {
		if ( yearPassed <= goal_deadline[PLAQUE_GOLD] )
		    plaque = PLAQUE_GOLD;
	    }
	}
	break;

    case SCN_RAISE_SALARY: {
	for( i=0 ; i<TOTAL_PLAQUE_COUNT ; i++ ) {
	    if ( yearPassed > goal_deadline[i] )      // exceeded time limit
		continue;

	    //## chea  050899 if ( curSal >= targetSal ) is the org. target checking
	    if ( scenario_faculty_salary_increase >= scenario_target[i] ) {
		plaque = i;
		break;
	    }
	}
    }
    break;

    case SCN_INVEST_ACADEMIC :
	for( i=0 ; i<TOTAL_PLAQUE_COUNT ; i++ ) {
	    if( yearPassed <= goal_deadline[i] &&
		//## chea 260799 another way to do the same alg.
		scenario_target[i] <= scenario_invest_academic_get_cur()-scenario_base ) {
		plaque = i;
		break;
	    }
	}
	break;

    case SCN_TEACHING_QUALITY :
	for( i=0 ; i<TOTAL_PLAQUE_COUNT ; i++ ) {
	    if( yearPassed <= goal_deadline[i] &&
		//## chea 260799 another way to do the same alg.
		scenario_target[i] <= sub_score[S_EDUCATIONAL_QUALITY][THIS_MONTH] ) {
		plaque = i;
		break;
	    }
	}
	break;

    case SCN_RESEARCH_QUALITY :
	for( i=0 ; i<TOTAL_PLAQUE_COUNT ; i++ ) {
	    if( yearPassed <= goal_deadline[i] &&
		//## chea 260799 another way to do the same alg.
		scenario_target[i] <= sub_score[S_SCHOLARSHIP_BROADLY_DEFINED][THIS_MONTH]  ) {
		plaque = i;
		break;
	    }
	}
	break;

    case SCN_WINNING_ATHLETICS:
	if ( athletics_office.football_percent_win*100 >= scenario_target[2] &&
	     athletics_office.basketball_percent_win*100 >= scenario_target[2] &&
	     yearPassed <= goal_deadline[PLAQUE_BRONZE] ) {
	    plaque = PLAQUE_BRONZE;
	}
	else if ( athletics_office.football_percent_win*100 >= scenario_target[1] &&
		  athletics_office.basketball_percent_win*100 >= scenario_target[1] &&
		  yearPassed <= goal_deadline[PLAQUE_SILVER] ) {
	    plaque = PLAQUE_SILVER;
	}
	else if ( athletics_office.football_percent_win*100 >= scenario_target[0] &&
		  athletics_office.basketball_percent_win*100 >= scenario_target[0] &&
		  yearPassed <= goal_deadline[PLAQUE_GOLD]
		  && athletics_office.ncaa_level_input == INPUT_HIGH
		  && INPUT_HIGH > scenario_base ) {
	    plaque = PLAQUE_GOLD;
	}
	break;

    case SCN_LIMIT_TUITION_GROWTH:
	if( 100.0f * (1.0f - finance.tuition_rate  / scenario_float_base) >= scenario_target[0]
	    && player_school.cur_game_score >= scenario_target[1] ) {
	    for ( i=0; i<TOTAL_PLAQUE_COUNT; i++ ) {
		if ( yearPassed <= goal_deadline[i] ) {
		    plaque = i;
		    break;
		}
	    }
	}
	break;

    case SCN_COMPENSATE_FOR_ENROLLMENT_SHIFTS:
	for ( i=0; i<TOTAL_PLAQUE_COUNT; i++ ) {
	    if( yearPassed <= goal_deadline[i] &&
		scenario_target[i] <= sub_score[S_EDUCATIONAL_QUALITY][THIS_MONTH] ) {
		plaque = i;
		break;
	    }
	}
	break;

    case SCN_STUDENT_DIVERSITY:
	for( i=0 ; i<TOTAL_PLAQUE_COUNT ; i++ ) {
	    if( yearPassed <= goal_deadline[i] &&
		scenario_target[i] <= enroll_res.overall_percent_minority ) {
		plaque = i;
		break;
	    }
	}
	break;

    case SCN_FACULTY_DIVERSITY: {

	int totalFacCount = department_array.faculty_gender_history[GENDER_ETHNIC_TYPE_COUNT][THIS_YEAR];
	int valueA = ( department_array.faculty_gender_history[MINORITY_MALE][THIS_YEAR] + department_array.faculty_gender_history[MINORITY_FEMALE][THIS_YEAR]) * 100 / totalFacCount;
	int valueB = ( department_array.faculty_gender_history[MINORITY_FEMALE][THIS_YEAR] + department_array.faculty_gender_history[NONMINORITY_FEMALE][THIS_YEAR]) * 100 / totalFacCount;

	if ( valueA >= scenario_target[0] && valueB >= scenario_target[1] ) {
	    for ( i=0; i<TOTAL_PLAQUE_COUNT; i++ )
		if ( yearPassed <= goal_deadline[i] ) {
		    plaque = i;
		    //0309 scen_quit_game_flag = 1;
		    break;
		}
	}

    }
    break;
    }

    //--------- if the player has achieved an objective --------//

    if( plaque >= 0 && !plaque_granted[plaque] ) {  // it is the first time the player gets the plaque
	plaque_granted[plaque] = 1;
	plaque_last = plaque;

	//------- add score bonus now -------//

	int bonusArray[TOTAL_PLAQUE_COUNT] = { 300,200,100 };
	add_bonus(bonusArray[plaque]);

	sys.set_staying_view_mode(MODE_AWARD_REPORT); // go to plaque screen

	// playsound
	audio.play_wav("NEWS", audio.int_to_DsVolume(config.sound_effect_volume));

	//--- if no other objectives can be possibly be achieved, prompt if the player wants to quit ---//

	for(int i=0 ; i<TOTAL_PLAQUE_COUNT ; i++) {
	    // if none of the plaque that have not been achieved are still within the time limit
	    if( !plaque_granted[i] && yearPassed <= goal_deadline[i] )
		break;
	}

	if( i==TOTAL_PLAQUE_COUNT )                   // if none of the plaque that have not been achieved are still within the time limit
	    scen_quit_game_flag = 1;
    }

    //----- End the game if it PASSED "scenario_max_game_years" years. -----//

    if ( yearPassed == scenario_max_game_years ) {
	if ( plaque_granted[0] + plaque_granted[1] + plaque_granted[2] <= 0 ) {
	    // go to lost screen and then final score screen
	    sys.set_staying_view_mode(MODE_LOSE_GAME);
	}
	else {                                        //--- if the player has previously achieved one of the objectives ---//
	    scen_quit_game_flag = 2;                    // signal MODE_FINAL_SCORE to ignore mouse.any_click

	    // display newspaper
	    news_array.scenario_news(1);                // 1: end of scenario

	    // to go to scenario achivement report then to final score screen
	    sys.set_staying_view_mode(MODE_FINAL_SCORE);
	}
    }
}