Пример #1
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 );
				}

			}
		}
	}
}
Пример #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 );

}
Пример #3
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;
}