示例#1
0
文件: of_inn.cpp 项目: 112212/7k2
// ------- Begin of function FirmInn::buy_item ------//
//
// checkingFlag : false = buy , 1 = check if can buy
// 
int FirmInn::buy_item( short recNo, int checkingFlag )
{
	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, unless own spy ------//

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

	if( !innUnit->item.id )
		return 0;

	if( innUnit->true_nation_recno() != nation_recno && nationPtr->cash < innUnit->item.cost() )
		return 0;

	if( !checkingFlag )
	{
		// drop the item outside

		if( site_array.add_site( loc_x2, loc_y2, SITE_ITEM, innUnit->item.id, innUnit->item.para )
			|| site_array.add_site( loc_x2, loc_y1, SITE_ITEM, innUnit->item.id, innUnit->item.para )
			|| site_array.add_site( loc_x1, loc_y2, SITE_ITEM, innUnit->item.id, innUnit->item.para )
			|| site_array.add_site( loc_x1, loc_y1, SITE_ITEM, innUnit->item.id, innUnit->item.para ) )
		{
			// reduce nation cash

			if( innUnit->true_nation_recno() != nation_recno )
			{
				nationPtr->add_expense( EXPENSE_HIRE_UNIT, (float) innUnit->item.cost(), 0 );
			}

			// clear item

			innUnit->item.clear();

			// recalc hire cost

			innUnit->set_hire_cost();

			return 1;
		}

		return 0;
	}

	return 1;
}
示例#2
0
文件: of_inn.cpp 项目: 112212/7k2
//--------- 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;
}