Beispiel #1
0
void FirmInn::add_inn_unit(int unitId)
{
	err_when( inn_unit_count >= MAX_INN_UNIT );

	InnUnit *innUnit = inn_unit_array+inn_unit_count;

	inn_unit_count++;

	innUnit->unit_id = unitId;

	//--------- set the skill now -----------------//

	char skillId = (char) next_skill_id;

	if( ++next_skill_id > MAX_TRAINABLE_SKILL )
		next_skill_id = 1;

	innUnit->skill.skill_id = skillId;

	if( skillId > 0 )
		innUnit->skill.skill_level = 30+misc.random(70);
	else
		innUnit->skill.skill_level = 0;

	if( skillId==0 || skillId==SKILL_LEADING )
		innUnit->skill.combat_level = 30+misc.random(70);
	else
		innUnit->skill.combat_level = 10;

	innUnit->set_hire_cost();

	innUnit->stay_count = 5 + misc.random(5);

	innUnit->spy_recno = 0;
}
Beispiel #2
0
// ------- 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;
}
Beispiel #3
0
//--------- Begin of function FirmInn::assign_unit ---------//
//
void FirmInn::assign_unit(int unitRecno)
{
	Unit* unitPtr = unit_array[unitRecno];

	//--- can only assign if the unit is a spy cloaked into independent ---//

	if( !can_accept_assign(unitRecno) )
		return;

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

	if( inn_unit_count == MAX_INN_UNIT 
		|| count_soldier() >= MAX_INN_UNIT/2 )
		return;

	err_when( inn_unit_count >= MAX_INN_UNIT );

	//--------- add the InnUnit --------//

	InnUnit *innUnit = inn_unit_array+inn_unit_count;
	memset( innUnit, 0, sizeof(InnUnit) );

	inn_unit_count++;

	//--------- set InnUnit vars -----------------//

	innUnit->unit_id    = unitPtr->unit_id;
	innUnit->skill      = unitPtr->skill;
	innUnit->hit_points = unitPtr->hit_points;
	innUnit->hero_id    = unitPtr->hero_id;
	unitPtr->hero_id = 0;
	innUnit->unique_id  = unitPtr->unique_id;
	innUnit->item       = unitPtr->item;
	unitPtr->item.clear();

	int spyRecno = innUnit->spy_recno = unitPtr->spy_recno;
	spy_array[spyRecno]->set_place(SPY_FIRM, firm_recno);
	unitPtr->spy_recno = 0;				// prevent Unit::deinit call spy_array.del_spy

	innUnit->set_hire_cost();
	innUnit->stay_count = 10 + misc.random(5);
	unitPtr->deinit_sprite();
	unit_array.disappear_in_firm(unitRecno);
}
Beispiel #4
0
//-------- Begin of function FirmInn::should_show_info --------//
//
int FirmInn::should_show_info()
{
	int rc = Firm::should_show_info();
	if(rc)
		return rc;

	// check any spy in the innUnit

	// --------- if if any own spy here -------//

	InnUnit *innUnit = inn_unit_array;
	int playerSpyCount = 0;
	for( int i = 0; i < inn_unit_count; ++i, ++innUnit )
	{
		if( innUnit->is_own_spy() )
			return 1;
	}

	return 0;
}
Beispiel #5
0
//------- Begin of function FirmInn::recover_hit_point -------//
//
// Units recover their hit points. Units assigned to this firm
// by players will have lower than maximum hit points
//
void FirmInn::recover_hit_point()
{
	InnUnit* innUnit = inn_unit_array;

	for( int i=0 ; i<inn_unit_count ; i++, innUnit++ )
	{
		int hpInc = 1;
		short maxHp = innUnit->max_hit_points();

		//------- item effect -------- //

		hpInc += ( 1 + innUnit->item.ability(ITEM_ABILITY_RECOVERY) ) / 2;

		//------- increase soldier hit points --------//

		if( innUnit->hit_points < maxHp )
		{
			innUnit->hit_points += hpInc;

			if( innUnit->hit_points > maxHp )
				innUnit->hit_points = maxHp;
		}
	}
}
Beispiel #6
0
//-------- Begin of function FirmInn::transfer_inn_unit --------//
//
int FirmInn::transfer_inn_unit(int recNo)
{
	err_when( recNo < 1 );
	
	if( recNo > inn_unit_count )
		return 0;

	InnUnit *innUnit = inn_unit_array+recNo-1;

	if( !innUnit->spy_recno )
		return 0;					// only spy considers transfer

	Spy *spyPtr = NULL;
	if( innUnit->spy_recno && !spy_array.is_deleted(innUnit->spy_recno) )
		spyPtr = spy_array[innUnit->spy_recno];

	// -------- scan any inn firm in world ----------//

	int ownFirmRecno = 0;
	int anyOwnInn = 0;
	int firmRecno = 1+misc.random(firm_array.size());

	int firmCount;
	for( firmCount = firm_array.size(); firmCount > 0; --firmCount, ++firmRecno )
	{
		if( firmRecno > firm_array.size() )
			firmRecno -= firm_array.size();
		err_when(firmRecno < 1 || firmRecno > firm_array.size());

		if( firm_array.is_deleted(firmRecno) )
			continue;

		FirmInn *firmInn = firm_array[firmRecno]->cast_to_FirmInn();

		if( !firmInn )
			continue;

		if( spyPtr && firmInn->nation_recno == spyPtr->true_nation_recno )
		{
			if( !anyOwnInn )
				anyOwnInn = firmRecno;
		}

		if( firmRecno == firm_recno )		// never go back to the same inn
			continue;

		if( firmInn->inn_unit_count >= MAX_INN_UNIT )
			continue;

		if( spyPtr && firmInn->nation_recno == spyPtr->true_nation_recno )
		{
			if( !ownFirmRecno )
				ownFirmRecno = firmRecno;
			continue;							// spy tend not to go back to own firmInn, unless no other choice
		}

		break;
	}

	if( firmCount <= 0 )				// if no other firm found, go back to own firm
		firmRecno = ownFirmRecno;

	if( firmRecno )					// if no any firm to go return false
	{
		// ------ transfer inn unit -------//

		FirmInn *firmInn = firm_array[firmRecno]->cast_to_FirmInn();		
		err_when( !firmInn );
		InnUnit *newInnUnit = firmInn->inn_unit_array + firmInn->inn_unit_count;
		firmInn->inn_unit_count++;
		*newInnUnit = *innUnit;

		// ------- generate new stay count ------//

		newInnUnit->stay_count = 10 + misc.random(5);
		newInnUnit->set_hire_cost();

		// ------ trasfer Spy ------- //

		if( spyPtr )
			spyPtr->set_place(SPY_FIRM, firmRecno);
		innUnit->spy_recno = 0;					// prevent del_inn_unit call spy_array.del_spy

		// ------ delete inn unit of current inn ------//

		del_inn_unit(recNo);
		innUnit = newInnUnit;			// set innUnit to the transferred place for later use
	}
	else if( (firmRecno = anyOwnInn) )
	{
		// mobilize in another any own inn

		hire( recNo, 1, firmRecno );
		innUnit = NULL;
	}

	return firmRecno;
}
Beispiel #7
0
void FirmInn::add_inn_unit(int raceId)
{
	err_when( inn_unit_count >= MAX_INN_UNIT );

	InnUnit *innUnit = inn_unit_array+inn_unit_count;
	RaceInfo *raceInfo = race_res[raceId];

	int spyFlag = 0;	// must determine before inn_unit_count increase

	if( count_soldier() >= MAX_INN_UNIT/2 )
		spyFlag = 1;
	else if( count_spy() >= MAX_INN_UNIT/2 )
		spyFlag = 0;
	else
		spyFlag = misc.random(2);

	memset( innUnit, 0, sizeof(InnUnit) );

	inn_unit_count++;

	//---- determine whether the unit is a spy or a military unit ----//

	if( !spyFlag )		// a military unit
	{
		//------- create a unit now -----------//

		int unitRecno;

		if( misc.random(20)==0 )		// 5% have a hero
		{
			unitRecno = hero_res.create_hero( -1, -1, 0, 0, 0, 0, 1);		// -1 - create the unit as an invisible unit
		}																								// last 1 - the heroes are for hire, check the HeroInfo::for_hire before adding it
		else		//---- just create a unit, not a hero  -----//
		{
			int unitId;

			int heroPower = 20 + misc.random(20);

			if( misc.random(2)==0 )
				unitId = raceInfo->infantry_unit_id;
			else
				unitId = raceInfo->special_unit_id;

			unitRecno = hero_res.create_powerful_unit( -1, -1, 0, unitId, heroPower);		// -1 - create the unit as an invisible unit
		}

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

		if( !unitRecno )
		{
			inn_unit_count--;
			return;
		}

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

		Unit* unitPtr = unit_array[unitRecno];

		err_when( !unitPtr->unit_id );

		innUnit->hero_id 	  = unitPtr->hero_id;
		innUnit->unit_id	  = unitPtr->unit_id;
		innUnit->skill      = unitPtr->skill;
		innUnit->hit_points = unitPtr->hit_points;
		innUnit->item       = unitPtr->item;
		unitPtr->item.clear();

		unit_array.del(unitRecno);		// delete the unit as it was created temporarily for setting skill and item values
	}
	else							// a spy
	{
		switch( misc.random(3) )
		{
		case 0:					// civilian spy
			innUnit->unit_id = (char) raceInfo->civilian_unit_id;
			innUnit->skill.init(innUnit->unit_id, CITIZEN_COMBAT_LEVEL, 0);
			innUnit->spy_skill			 = 30+misc.random(40);
			break;
		case 1:					// infantry spy
			innUnit->unit_id = (char) raceInfo->infantry_unit_id;
			innUnit->skill.init(innUnit->unit_id, 20+misc.random(30), 20+misc.random(30));	// a spy also have leadership and combat ability, but lower than units with leadership as their main skills
			innUnit->spy_skill			 = 30+misc.random(40);
			break;
		case 2:					// special unit spy
			innUnit->unit_id = (char) raceInfo->special_unit_id;
			innUnit->skill.init(innUnit->unit_id, 30+misc.random(30), 10+misc.random(20));	// a spy also have leadership and combat ability, but lower than units with leadership as their main skills
			innUnit->spy_skill			 = 30+misc.random(40);
			break;
		default:
			err_here();
		}

		if( misc.random(4)==0 )
			innUnit->spy_skill += misc.random(30);

		else if( misc.random(2)==0 )
			innUnit->spy_skill += misc.random(15);
	}

	err_when( !innUnit->unit_id );

	// ------ randomly assign a unique id --------//

	// ###### begin Gilbert 23/2 ######//
	innUnit->unique_id = misc.rand_long();
	// ###### end Gilbert 23/2 ######//

	// ------ set current hit point -------//

	innUnit->hit_points = (float) innUnit->max_hit_points();

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

	innUnit->set_hire_cost();
	innUnit->stay_count = 10 + misc.random(5);
}
Beispiel #8
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;
}
Beispiel #9
0
//--------- Begin of function FirmInn::put_info ---------//
//
void FirmInn::put_info(int refreshFlag)
{
	if( selected_unit_id < 0 )
		selected_unit_id = 0;
	if( selected_unit_id > inn_unit_count )
		selected_unit_id = inn_unit_count;

	Firm::put_info(refreshFlag);

	button_hire.create(INFO_X1+13, INFO_Y1+235, 'A', "HIREUNIT" );
	button_hire.enable_flag = 0;
	button_spy_mobilize.create(INFO_X1+13, INFO_Y1+235, 'A', "MOBILSPY" );
	button_spy_mobilize.enable_flag = 0;
	button_buy_item.create( INFO_X1+13+BUTTON_DISTANCE, INFO_Y1+235, 
		INFO_X1+13+BUTTON_DISTANCE+ITEM_ICON_WIDTH, INFO_Y1+235+ITEM_ICON_HEIGHT,
		disp_item_button, ButtonCustomPara(NULL, 0) );
	button_buy_item.visible_flag = 0;

	button_hire_visible = button_spy_mobilize_visible = 0;

	if( !should_show_info() )
		return;

	vga.active_buf->put_bitmap( INFO_X1, INFO_Y1, image_gameif.read("INN_BASE") );

	disp_unit_list( INFO_Y1, refreshFlag );

	disp_unit_info( INFO_Y1 + 165, refreshFlag );

	// ------ main interface --------//

	// ------ display hire button -------//

	button_hire.enable_flag = 0;
	button_spy_mobilize.enable_flag = 0;

	if( selected_unit_id > 0 && selected_unit_id <= inn_unit_count )
	{
		InnUnit *innUnit = inn_unit_array + selected_unit_id - 1;

		if( innUnit->is_own_spy() )
		{
			button_spy_mobilize.enable_flag = 1;
			button_spy_mobilize.paint();
			button_spy_mobilize_visible = 1;
		}
		else if( is_own() )
		{
			button_hire.enable_flag = (~nation_array)->cash >= innUnit->hire_cost;
			button_hire.paint();
			button_hire_visible = 1;
		}
		else
		{
			button_spy_mobilize.paint();
			button_spy_mobilize_visible = 1;
		}

		if( (button_buy_item.visible_flag = innUnit->item.id != 0) )
		{
			button_buy_item.enable_flag = is_own() && buy_item( selected_unit_id, 1 );		// checking only
			button_buy_item.custom_para.value = innUnit->item.id;
			button_buy_item.paint();
		}
	}
	else
	{
		if( is_own() )
		{
			button_hire.paint();
			button_hire_visible = 1;
		}
		else
		{
			button_spy_mobilize.paint();
			button_spy_mobilize_visible = 0;
		}

		button_buy_item.visible_flag = 0;
	}
}
Beispiel #10
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 );

}
Beispiel #11
0
// -------- Begin of function FirmInn::disp_unit_list -------//
//
void FirmInn::disp_unit_list(int dispY1, int refreshFlag)
{
	disp_unit_list_y1 = dispY1;

	// ##### begin Gilbert 7/12 #######//
	// count no. of units on each row

	int rowUnitCountOld[2] = { 0, 0 };		// no of soldier and no of spy counted
	rowUnitCountOld[0] = count_soldier();
	rowUnitCountOld[1] = count_spy();
	// ##### end Gilbert 7/12 #######//

	for( int inc = -1; inc <= 1; inc += 2 )
	{
		err_when( inc == 0 );

		// first round is descending draw to icon
		// second round is ascending to draw the frame

		int inAreaFlag = 4;

		// ##### begin Gilbert 7/10 ######//
		// initial rowUnitCount according to inc
		int rowUnitCount[2];		// no of soldier and no of spy counted
		if( inc >= 0 )
			memset( rowUnitCount, 0, sizeof(rowUnitCount) );
		else
			memcpy( rowUnitCount, rowUnitCountOld, sizeof(rowUnitCount) );
		// ##### end Gilbert 7/10 ######//

		for( int i = inc>=0?1:inn_unit_count; i > 0 && i <= inn_unit_count; i +=inc )
		{
			InnUnit *innUnit = inn_unit_array + i - 1;

			int row = innUnit->spy_skill <= 0 ? 0 : 1;		// soldier on row 0, spy on row 1
			// ##### begin Gilbert 7/10 ######//
			if( inc < 0 )
				--rowUnitCount[row];				// decrease rowUnitCount before use
			// ##### end Gilbert 7/10 ######//
			int x = INFO_X1 + 67 + rowUnitCount[row] * UNIT_X_SPACING;
			int y = INFO_Y1 + 44 + row * UNIT_Y_SPACING;
			int yHp = INFO_Y1 + 7 + row * UNIT_Y_SPACING;

			int windowX1 = INFO_X1 + 16;
			int windowX2 = INFO_X1 + 218;
			int windowY1 = INFO_Y1 + 5 + row * 76;	// 5,81
			int windowY2 = windowY1 + 72 - 1 ;

			// ###### begin Gilbert 7/10 #######//
			if( inc >= 0 )
				++rowUnitCount[row];				// increase rowUnitCount after use
			// ###### end Gilbert 7/10 #######//

			if( inc < 0 )
			{
				// first pass descending, draw unit icon

				info.draw_unit_icon( x+UNIT_X_SPACING/2, y,
					innUnit->unit_id, nation_recno,
					windowX1, windowY1, windowX2, windowY2, 1 );
			}
			else
			{
				// second round is ascending to draw the frame

				if( info.draw_unit_icon( x+UNIT_X_SPACING/2, y,
					innUnit->unit_id, nation_recno,
					windowX1, windowY1, windowX2, windowY2, 
					inAreaFlag | (i==selected_unit_id?3:0) ) & 4 )
				{
					inAreaFlag = 0;		// frame for mouse cursor is drawn, disable the frame
				}

				int fontHeight = font_whbl.max_font_height;

				if( innUnit->is_own_spy() )		// display spy icon
				{
					vga.active_buf->put_bitmap_trans( x+UNIT_X_SPACING/2-8, yHp-5, image_icon.read("U_SPY") );
				}
				else if( innUnit->hero_id )
				{
					vga.active_buf->put_bitmap_trans( x+UNIT_X_SPACING/2-8, yHp-5, image_icon.read("U_HERO") );
				}
				else
				{
					if( row == 0 )		// display combat skill and leadership
					{
						font_whbl.center_put( x, yHp, x+UNIT_X_SPACING, yHp+fontHeight, m.format(innUnit->skill_level()) );
					}
					else if( row == 1 )		// display spy skill
					{
						font_whbl.center_put( x, yHp, x+UNIT_X_SPACING, yHp+fontHeight, m.format(innUnit->spy_skill) );
					}
				}

				if( innUnit->item.id )
				{
					char *iconPtr = item_res.item_unit_interface(innUnit->item.id);
					if( iconPtr )
						vga.active_buf->put_bitmap_trans( x+UNIT_X_SPACING/2 -((Bitmap *)iconPtr)->get_width()/2,
						yHp +53, iconPtr );
				}

			}
		}
	}
}
Beispiel #12
0
//--------- Begin of function Nation::hire_unit --------//
//
// <int>		raceId  - the race the selected unit should have
//							 (0 for any races)
// <int> isCivilian - whether the unit to be hired should be a civilian unit
// <int>   hireSpy  - whether hire a spy or a normal military unit
//	<short>	destX	  - the x location the unit will move to
//	<short>	destY	  - the y location the unit will move to
//
// Note: Units hired in inns are military units only.
// 		There are no civilian units in inns.
//
// return: <int> recno of the unit recruited.
//
int Nation::hire_unit(int raceId, int isCivilian, int hireSpy, short destX, short destY)
{
	if( !ai_should_hire_unit(20) )			// 20 - importance rating
		return 0;

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

	FirmInn	*firmInnPtr;
	Firm		*firmPtr;
	InnUnit *innUnit;
	Skill		*innUnitSkill;
	int		i, j, innUnitCount, curRating, curFirmDist;
	int		bestRating=0, bestInnRecno=0, bestInnUnitId=0;
	int		destRegionId = world.get_region_id(destX, destY);

	for(i=0; i<ai_inn_count; i++)
	{
		firmPtr = firm_array[ai_inn_array[i]];

		if( firmPtr->region_id != destRegionId )
			continue;

		firmInnPtr = firmPtr->cast_to_FirmInn();

		innUnitCount=firmInnPtr->inn_unit_count;

		if( !innUnitCount )
			continue;

		innUnit = firmInnPtr->inn_unit_array + innUnitCount - 1;

		curFirmDist = m.points_distance(firmPtr->center_x, firmPtr->center_y, destX, destY);

		//------- check units in the inn ---------//

		for(j=innUnitCount; j>0; j--, innUnit--)
		{
			innUnitSkill = &(innUnit->skill);

			if( raceId && unit_res[innUnit->unit_id]->race_id != raceId )
				continue;

			if( isCivilian != unit_res[innUnit->unit_id]->is_civilian )
				continue;

			if( hireSpy && innUnit->spy_skill==0 )
				continue;

			if( cash < innUnit->hire_cost )
				continue;

			//----------------------------------------------//
			// evalute a unit on:
			// -its race, whether it's the same as the nation's race
			// -the inn's distance from the destination
			// -the skill level of the unit.
			//----------------------------------------------//

			curRating = (int) innUnit->skill_level()
							- (100-100*curFirmDist/MAX_WORLD_X_LOC);

			if( unit_res[innUnit->unit_id]->race_id == race_id )
				curRating += 50;

			if( curRating > bestRating )
			{
				bestRating = curRating;

				bestInnRecno  = firmInnPtr->firm_recno;
				bestInnUnitId = j;
			}
		}
	}

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

	if( bestInnUnitId )
	{
		firmPtr = firm_array[bestInnRecno];
		firmInnPtr = firmPtr->cast_to_FirmInn();

		return firmInnPtr->hire(bestInnUnitId);
	}

	return 0;
}