Exemple #1
0
//--------- Begin of function FirmInn::hire ---------//
//
// <short> recNo			inn unit recno
// [int] spyEscape      whether this is an instance which a spy escape from the inn, instead of hiring a unit. i.e. no hire cost required
//								(default: 0)
// [short] exitFirmRecno  exit inn's firm recno if not same as this inn (see transfer_inn_unit)
//                      (default :0)
//
int FirmInn::hire(short recNo, int spyEscape, short exitFirmRecno)
{
	err_when( recNo < 1 );

	if( recNo > inn_unit_count )		// this may happen in a multiplayer game
		return 0;

	//--------- first check if you have enough money to hire ------//

	Nation* 	nationPtr = nation_array[nation_recno];
	InnUnit* innUnit = inn_unit_array+recNo-1;
	int unitRecno = 0;

	err_when( exitFirmRecno && firm_array.is_deleted(exitFirmRecno) );

	if( innUnit->spy_recno && (spyEscape 											// no expense if mobilizing spy
		|| innUnit->true_nation_recno() == nation_recno) )	// no expense if it is own spy
	{
		// free, no need to play money
		unitRecno = (exitFirmRecno ? firm_array[exitFirmRecno] : this)->create_unit(innUnit->unit_id );
		if( !unitRecno )
			return 0;		// no space for creating the unit
	}
	else
	{
		if( nationPtr->cash < innUnit->hire_cost )
			return 0;
		unitRecno = (exitFirmRecno ? firm_array[exitFirmRecno] : this)->create_unit( innUnit->unit_id );
		if( !unitRecno )
			return 0;		// no space for creating the unit
		nationPtr->add_expense(EXPENSE_HIRE_UNIT, innUnit->hire_cost);
	}

	//-------- set skills of the unit --------//

	err_when( !unitRecno );

	Unit* unitPtr = unit_array[unitRecno];

	unitPtr->skill 	  = innUnit->skill;
	unitPtr->hit_points = innUnit->hit_points;

	err_when( innUnit->combat_level()<=0 || innUnit->combat_level()>1000 );

	//----------------------------------------//
	//
	// Set loyalty of the hired unit
	//
	// = 30 + the nation's reputation / 2 + 30 if racially homogenous
	//
	//----------------------------------------//

	int unitLoyalty = 30 + (int)nationPtr->reputation/2;
	if( innUnit->spy_recno && (spyEscape
		|| innUnit->true_nation_recno() == nation_recno) )
	{
		unitLoyalty = spy_array[innUnit->spy_recno]->spy_loyalty;
	}

	if( race_res.is_same_race(unitPtr->race_id, nationPtr->race_id) )
		unitLoyalty += 20;

	unitLoyalty = MAX( 40, unitLoyalty );
	unitLoyalty = MIN( 100, unitLoyalty );

	unitPtr->loyalty = unitLoyalty;
	// ######## begin Gilbert 24/2 #######//
	unitPtr->unique_id = innUnit->unique_id;		// set unique before add_spy/set_spy_place
	// ######## end Gilbert 24/2 #######//

	//----------------------------------------------------//
	//
	// If spy_skill>0, this unit is a spy with a
	// spying skill for hire, he is added by FirmInn
	//
	//----------------------------------------------------//

	if( innUnit->spy_skill > 0 )
	{
		unitPtr->spy_recno = spy_array.add_spy(unitRecno, innUnit->spy_skill);
		spy_array[unitPtr->spy_recno]->spy_loyalty = unitLoyalty;		// this is the spy's true loyalty towards you
	}

	//----------------------------------------------------//
	//
	// If spy_recno>0, this unit is an enemy spy sneaked
	// into the inn.
	//
	//----------------------------------------------------//

	else if( innUnit->spy_recno )
	{
		err_when( spy_array.is_deleted(innUnit->spy_recno) );
		Spy *spyPtr = spy_array[innUnit->spy_recno];
		unitPtr->spy_recno = innUnit->spy_recno;
		innUnit->spy_recno = 0;								// prevent del_inn_unit call spy_array.del_spy
		unitPtr->loyalty = unitLoyalty;					// this is his fake loyalty towards you
		// ##### begin Gilbert 1/3 ########//
		if( unitPtr->race_id && spyPtr->name_id )
		{
			unitPtr->set_name( spyPtr->name_id );
		}
		// ##### end Gilbert 1/3 ########//
		spy_array[unitPtr->spy_recno]->set_place(SPY_MOBILE, unitRecno);

		if( spyEscape )
		{
			unitPtr->spy_change_nation(spyPtr->true_nation_recno, COMMAND_AUTO);
		}
	}

	// ------ hero id -------//

	unitPtr->hero_id = innUnit->hero_id;
	innUnit->hero_id = 0;
	// ##### begin Gilbert 24/2 #######//
	// unitPtr->unique_id = innUnit->unique_id;
	// ##### end Gilbert 24/2 #######//

	// ------ set item -------//

	unitPtr->item = innUnit->item;

	// ###### begin Gilbert 4/11 ######//
	unitPtr->set_combat_level(-1);
	// ###### end Gilbert 4/11 ######//

	//---- remove the record from the hire list ----//

	del_inn_unit(recNo);

	// ##### begin Gilbert 24/2 #######//
	// ------- update win/lose condition on changing of unit recno -----//

	game.update_condition_on_mobilize(unitRecno, unitPtr->unique_id );
	// ##### end Gilbert 24/2 #######//

	return unitRecno;
}
Exemple #2
0
//--------- Begin of function FirmInn::disp_unit_info ---------//
//
// Display the skill information of the people in the town.
//
// <int> 			 dispY1		 - the top y coordination of the info area
// <InnUnit*> hireInfoPtr - pointer to a HireInfo structure
// <int>    		 refreshFlag - refresh flag
//
void FirmInn::disp_unit_info(int dispY1, int refreshFlag)
{
	if( !selected_unit_id || selected_unit_id > inn_unit_count)
		return;

	// ##### begin Gilbert 8/1 #####//
//	int x = INFO_X1 + 83;
	int x = INFO_X1 + 20;
	// ##### end Gilbert 8/1 #####//
	int y = dispY1;
	int x2;

	err_when( selected_unit_id <= 0 || selected_unit_id > inn_unit_count );

	InnUnit *innUnit = inn_unit_array + selected_unit_id - 1;

	// display unit name

	if( innUnit->hero_id )
		font_snds.put( x, y, hero_res[innUnit->hero_id]->name, 0, -1, 1 );
	else
		font_snds.put( x, y, unit_res[innUnit->unit_id]->name, 0, -1, 1 );

	y += 14;

	// display combat level

	// x2 = font_snds.put( x, y, "Combat" ) + 10;
	x2 = font_snds.put( x, y, text_unit.str_combat_level() ) + 10;
	font_snds.right_put( INFO_X2-100, y, m.format(innUnit->combat_level(), 4) );
//	x2 = font_snds.put( x2, y, innUnit->combat_level() ) + 15;

	// display spying skill

	if( innUnit->item.id )
	{
		if( innUnit->spy_skill > 0 )
		{
			// x2 = font_snds.put( x+110, y, "Spying" ) + 10;
			x2 = font_snds.put( x+110, y, text_unit.str_spy_skill() ) + 10;
			font_snds.right_put( INFO_X2-10, y, m.format(innUnit->spy_skill,4) );
		}
		else if( innUnit->is_own_spy() )
		{
			// x2 = font_snds.put( x+110, y, "Spying" ) + 10;
			x2 = font_snds.put( x+110, y, text_unit.str_spy_skill() ) + 10;
			font_snds.right_put( INFO_X2-10, y, m.format(spy_array[innUnit->spy_recno]->spy_skill,4) );
		}
		else if ( innUnit->hero_id )
		{
//			String str;
//			str  = race_res[ unit_res[innUnit->unit_id]->race_id ]->adjective;
//			str += " Hero";
//			font_red.right_put( INFO_X2-5, y, str );
			font_red.right_put( INFO_X2-5, y, text_unit.str_race_hero(race_res[ unit_res[innUnit->unit_id]->race_id ]->adjective) );
		}
	}

	y += 14;

	// display leadership skill

	if( innUnit->skill_level() > 0 )
	{
		// x2 = font_snds.put( x, y, "Leadership" ) + 10;
		x2 = font_snds.put( x, y, text_unit.str_leadership() ) + 10;
		font_snds.right_put( INFO_X2-100, y, m.format(innUnit->skill_level(), 4) );
	//	font_snds.put( x2, y, innUnit->skill_level() );
	}

	// display hire cost

	font_snds.right_put( INFO_X1+212, y, m.format(innUnit->hire_cost, 2) );

	y += 14;

	// display item

	if( innUnit->item.id )
	{
		font_snds.put( x, y, innUnit->item.item_name() );
		font_snds.right_put( INFO_X1+212, y, m.format(innUnit->item.cost(), 2) );
	}
	else
	{
		if( innUnit->spy_skill > 0 )
		{
			// x2 = font_snds.put( x, y, "Spying" ) + 10;
			x2 = font_snds.put( x, y, text_unit.str_spy_skill() ) + 10;
			font_snds.right_put( INFO_X2-100, y, m.format(innUnit->spy_skill, 4) );
		//	font_snds.put( x2, y, innUnit->spy_skill );
		}
		else if( innUnit->is_own_spy() )
		{
			// x2 = font_snds.put( x, y, "Spying" ) + 10;
			x2 = font_snds.put( x, y, text_unit.str_spy_skill() ) + 10;
			font_snds.right_put( INFO_X2-100, y, m.format(spy_array[innUnit->spy_recno]->spy_skill, 4) );
		//	font_snds.put( x2, y, spy_array[innUnit->spy_recno]->spy_skill );
		}
		else if ( innUnit->hero_id )
		{
//			String str;
//			str  = race_res[ unit_res[innUnit->unit_id]->race_id ]->adjective;
//			str += " Hero";
//			font_red.right_put( INFO_X2-95, y, str );
			font_red.right_put( INFO_X2-95, y, text_unit.str_race_hero(race_res[ unit_res[innUnit->unit_id]->race_id ]->adjective) );
		}
	}
//	info.draw_unit_icon( INFO_X1+38, INFO_Y1+228-32,
//		innUnit->unit_id, nation_recno,
//		INFO_X1+14, INFO_Y1+157, INFO_X1+63, INFO_Y1+228, 1 );

}