Esempio n. 1
0
//--------- Begin of function FirmCamp::detect_soldier_list ---------//
//
// <int> selecteSpyMenu        0=main menu; 1=selecting spy
// when selectSpyMenu is 0, return 1 if left click on a unit, return 2 if right click on a unit
// when selectSpyMenu is 1, return spy_recno of the clicked spy, 0 if no own spy is clicked
//
int FirmCamp::detect_soldier_list(int selectSpyMenu)
{
	int dispY1 = disp_soldier_list_y1;

	// display in ascending order to select the overseer first

	for( int i = 0; i <= soldier_count; ++i )
	{
		// display soldier i

		int row = i/SOLDIER_PER_ROW;
		int x = INFO_X1 + 18 + (i % SOLDIER_PER_ROW) * SOLDIER_X_SPACING;
		int y = INFO_Y1 + 50 + row * SOLDIER_Y_SPACING;
		int yHp = INFO_Y1 + 7 + row * SOLDIER_Y_SPACING;

		int windowX1 = INFO_X1 + 16;
		int windowX2 = INFO_X1 + 220;
		int windowY1 = INFO_Y1 + 5 + row * 84;	// 5,89
		int windowY2 = windowY1 + 80 - 1 ;

		int unitId;
		int hp;
		int maxHp;
		// ##### begin Gilbert 21/9 ######//
		int combatLevel;
		int skillLevel;
		int loyalty;
		// ##### end Gilbert 21/9 ######//
		int ownSpy;

		if( i==0 )
		{
			if( !overseer_recno )
				continue;

			// overseer
			Unit *overseer = unit_array[overseer_recno];
			unitId = overseer->unit_id;

			hp = (int) overseer->hit_points;
			maxHp = overseer->max_hit_points();
			combatLevel = (int) overseer->combat_level();
			skillLevel = (int) overseer->skill_level();

			if( overseer->rank_id != RANK_GENERAL )
				loyalty = overseer->loyalty;
			else
				loyalty = -1;		// king or other(?)

			ownSpy = overseer->is_own_spy() ? overseer->spy_recno : 0;
		}
		else
		{
			// soldier
			Soldier *soldierPtr = &soldier_array[i-1];
			unitId = soldierPtr->unit_id;

			hp = soldierPtr->hit_points;
			maxHp = soldierPtr->max_hit_points();
			combatLevel = (int) soldierPtr->combat_level();
			skillLevel = (int) soldierPtr->skill_level();

			if( soldierPtr->race_id )
				loyalty = soldierPtr->loyalty;
			else
				loyalty = -1;
			ownSpy = soldierPtr->is_own_spy() ? soldierPtr->spy_recno : 0;
		}

		if( selectSpyMenu && !ownSpy )
			continue;

		int rc = info.draw_unit_icon( x+SOLDIER_X_SPACING/2, y,
			unitId, nation_recno, 
			windowX1, windowY1, windowX2, windowY2, 24 );		// detect left button (8) and right button(16)

		if( !rc )
			continue;

		if( selectSpyMenu == 0 )
		{
			// -------- main menu ---------//

			if( rc & 8 )
			{
				// ----- left click select soldier/overseer -------//

				selected_soldier_id = i;
				return 1;
			}
			else if( rc & 16 && is_own() )
			{
				// ------ right click mobilize solidier/overseer ------//

				if( i == 0 )
				{
					if(remote.is_enable())
					{
						// packet structure : <firm recno>
						short *shortPtr=(short *)remote.new_send_queue_msg(MSG_FIRM_MOBL_OVERSEER, sizeof(short));
						shortPtr[0] = firm_recno;
					}
					else
					{
						assign_overseer(0);		// the overseer quits the camp
					}
				}
				else
				{
					// #### begin Gilbert 26/1 #####//
					if( !soldier_array[i-1].is_under_training() )
						mobilize_soldier(i, COMMAND_PLAYER);
					else
						cancel_train_soldier(i, COMMAND_PLAYER);
					// #### end Gilbert 26/1 #####//
				}
				return 2;
			}
		}
		else if( selectSpyMenu == 1 )
		{
			if( rc & 8 && ownSpy )
			{
				selected_soldier_id = i;
				return ownSpy;
			}
		}
	}

	return 0;

	/*
	if( !should_show_info() )
		return 0;

	if( is_own() )
	{
		//------ detect the overseer button -----//
		int rc = mouse.single_click(INFO_X1+6, INFO_Y1+58,
					INFO_X1+5+UNIT_LARGE_ICON_WIDTH, INFO_Y1+57+UNIT_LARGE_ICON_HEIGHT, 2 );

		if( rc==1 )
		{
			selected_soldier_id = 0;
			return 1;
		}
		else if( rc==2 && is_own() )
		{
			if(remote.is_enable())
			{
				// packet structure : <firm recno>
				short *shortPtr=(short *)remote.new_send_queue_msg(MSG_FIRM_MOBL_OVERSEER, sizeof(short));
				shortPtr[0] = firm_recno;
			}
			else
			{
				assign_overseer(0);		// the overseer quits the camp
			}
			return 1;
		}
	}

	//------- detect buttons on hiring firm soldiers -------//

	int i, x, y;

	for( i=0 ; i<soldier_count ; i++ )
	{
		x = INFO_X1+6+i%4*50;
		y = pop_disp_y1+1+i/4*29;

		switch( mouse.single_click(x, y, x+27, y+23, 2) )
		{
		case 1:         // left button to select soldier
			selected_soldier_id = i+1;
			return 1;

		case 2:
			if( is_own() )		// only if this is our own firm
			{
				//--- if the town where the unit lives belongs to the nation of this firm ---//

				mobilize_soldier(i+1, COMMAND_PLAYER);
				return 1;
			}
			break;
		}
	}

	return 0;
	*/
}
Esempio n. 2
0
//--------- Begin of function FirmCamp::disp_soldier_list ---------//
//
void FirmCamp::disp_soldier_list(int dispY1, int refreshFlag, int dispSpyMenu)
{
	disp_soldier_list_y1 = dispY1;

	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;

		for( int i = inc>=0?0:soldier_count; i >= 0 && i <= soldier_count; i +=inc )
		{
			// display soldier i

			int row = i/SOLDIER_PER_ROW;
			int x = INFO_X1 + 18 + (i % SOLDIER_PER_ROW) * SOLDIER_X_SPACING;
			int y = INFO_Y1 + 50 + row * SOLDIER_Y_SPACING;
			int yHp = INFO_Y1 + 7 + row * SOLDIER_Y_SPACING;

			int windowX1 = INFO_X1 + 16;
			int windowX2 = INFO_X1 + 220;
			int windowY1 = INFO_Y1 + 5 + row * 84;	// 5,89
			int windowY2 = windowY1 + 80 - 1 ;

			int unitId;
			int hp;
			int maxHp;
			// ##### begin Gilbert 21/9 ######//
			int combatLevel;
			int skillLevel;
			int loyalty;
			// ##### end Gilbert 21/9 ######//
			int ownSpy;
			int itemId;

			if( i==0 )
			{
				if( !overseer_recno )
					continue;

				// overseer
				Unit *overseer = unit_array[overseer_recno];
				unitId = overseer->unit_id;

				hp = (int) overseer->hit_points;
				maxHp = overseer->max_hit_points();
				combatLevel = (int) overseer->combat_level();
				skillLevel = (int) overseer->skill_level();

				if( overseer->rank_id != RANK_GENERAL )
					loyalty = -1;		// king or other(?)
				else
					loyalty = overseer->loyalty;

				ownSpy = overseer->is_own_spy() ? overseer->spy_recno : 0;
				itemId = overseer->item.id;
			}
			else
			{
				// soldier
				Soldier *soldierPtr = &soldier_array[i-1];
				unitId = soldierPtr->unit_id;

				hp = soldierPtr->hit_points;
				maxHp = soldierPtr->max_hit_points();
				combatLevel = (int) soldierPtr->combat_level();
				skillLevel = (int) soldierPtr->skill_level();

				// ####### begin Gilbert 24/3 #########//
				if( unit_res[soldierPtr->unit_id]->class_info.has_loyalty && nation_recno )
				// ####### end Gilbert 24/3 #########//
					loyalty = soldierPtr->loyalty;
				else
					loyalty = -1;
				ownSpy = soldierPtr->is_own_spy() ? soldierPtr->spy_recno : 0;
				itemId = soldierPtr->item.id;
			}

			if( dispSpyMenu && !ownSpy )			// skip displaying spy
				continue;

			UnitInfo *unitInfo = unit_res[unitId];

			// display that solider icon at x+SOLDIER_X_SPACING/2, y
			// draw a frame if selected

			if( inc < 0 )
			{
				// first round is descending draw to icon
				Soldier *soldierPtr = &soldier_array[i-1];
				info.draw_unit_icon( x+SOLDIER_X_SPACING/2, y,
					unitId, nation_recno,
					windowX1, windowY1, windowX2, windowY2,
					(i>0 && soldierPtr->combat_level() < 20) ? (((20 - soldierPtr->combat_level()) <<6)+ 33) : 1);
			}
			else
			{
				// second round is ascending to draw the frame

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

				// display combat skill

				// ######## begin Gilbert 21/9 #######//
				Font *font = &font_whbl;

				if( !dispSpyMenu )
				{
					if( disp_combat_or_skill )		// display skill level
					{
						font = &font_blue;
						int attribute = -1;
						switch( disp_combat_or_skill )
						{
						case 1: 
							if( unitInfo->class_info.has_combat_level )
								attribute = combatLevel;
							break;
						case 2:
							if( unitInfo->class_info.has_skill_level && skillLevel > 0 )
								attribute = skillLevel; 
							break;
						case 4:
							if( unitInfo->class_info.has_loyalty && nation_recno )
								attribute = loyalty;
							break;
						default:
							err_here();
						}
						if( attribute >= 0 )	// hide attribute on some cases
							font->center_put( x, yHp, x+SOLDIER_X_SPACING, 
								yHp+font->max_font_height, m.format(attribute) );
					}
					else if( ownSpy )		// display spy icon
					{
						vga.active_buf->put_bitmap_trans( x+SOLDIER_X_SPACING/2-8, yHp-5, image_icon.read("U_SPY") );
					}
					else if( unitInfo->class_info.has_combat_level ) 	// display combat skill
					{
						font->center_put( x, yHp, x+SOLDIER_X_SPACING, yHp+font->max_font_height, 
							m.format(combatLevel) );
					}

					if( itemId )
					{
						char *iconPtr = item_res.item_unit_interface(itemId);
						if( iconPtr )
							vga.active_buf->put_bitmap_trans( x+SOLDIER_X_SPACING/2-((Bitmap *)iconPtr)->get_width()/2,
							yHp +53, iconPtr );
					}
				}
				else
				{
					// display spy skill
					err_when( !ownSpy );
					font_whbl.center_put( x, yHp, x+SOLDIER_X_SPACING, yHp+font->max_font_height, 
						m.format(spy_array[ownSpy]->spy_skill) );
				}

				// display hit points bar

				if( i > 0 && soldier_array[i-1].is_under_training() )
					disp_training_bar( x, yHp+font->max_font_height+2, x+SOLDIER_X_SPACING*7/8-1,
						soldier_array[i-1].skill_level(), BASIC_COMBAT_TRAIN );
				else
					disp_soldier_hit_points( x, yHp+font->max_font_height+2, x+SOLDIER_X_SPACING*7/8-1, hp, maxHp );
			}
		}
	}

/*
	//---------------- paint the panel --------------//

	if( overseer_recno )
	{
		//------------ display overseer info -------------//

		Unit* overseerUnit = unit_array[overseer_recno];

		int x=INFO_X1+6, y=dispY1+4, x1=x+UNIT_LARGE_ICON_WIDTH+8;

		if( selected_soldier_id == 0 )
		{
			vga_front.rect( x-2, y-2, x+UNIT_LARGE_ICON_WIDTH+1, y+UNIT_LARGE_ICON_HEIGHT+1, 2, V_YELLOW );
		}
		else
		{
			vga.blt_buf( x-2, y-2, x+UNIT_LARGE_ICON_WIDTH+1, y-1, 0 );
			vga.blt_buf( x-2, y+UNIT_LARGE_ICON_HEIGHT+1, x+UNIT_LARGE_ICON_WIDTH+1, y+UNIT_LARGE_ICON_HEIGHT+2, 0 );
			vga.blt_buf( x-2, y-2, x-1, y+UNIT_LARGE_ICON_HEIGHT+2, 0 );
			vga.blt_buf( x+UNIT_LARGE_ICON_WIDTH, y-2, x+UNIT_LARGE_ICON_WIDTH+1, y+UNIT_LARGE_ICON_HEIGHT+2, 0 );
		}

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

		if( refreshFlag == INFO_REPAINT )
		{
			vga_front.put_bitmap(x, y, unit_res[overseerUnit->unit_id]->get_large_icon_ptr(overseerUnit->rank_id) );
		}

		//-------- set help parameters --------//

		if( mouse.in_area(x, y, x+UNIT_LARGE_ICON_WIDTH+3, y+UNIT_LARGE_ICON_HEIGHT+3) )
			help.set_unit_help( overseerUnit->unit_id, overseerUnit->rank_id, x, y, x+UNIT_LARGE_ICON_WIDTH+3, y+UNIT_LARGE_ICON_HEIGHT+3);

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

		if( overseerUnit->rank_id == RANK_KING )
		{
			if( refreshFlag == INFO_REPAINT )
				font_san.put( x1, y, "King" );

			y+=14;
		}

		if( refreshFlag == INFO_REPAINT )
			font_san.put( x1, y, overseerUnit->unit_name(0), 0, INFO_X2-2 );		// 0-ask unit_name() not to return the title of the unit

		y+=14;

		//------- display leadership -------//

		String str;

		str  = translate.process("Leadership");
		str += ": ";
		str += overseerUnit->skill.skill_level;

		font_san.disp( x1, y, str, INFO_X2-10 );
		y+=14;

		//--------- display loyalty ----------//

		if( overseerUnit->rank_id != RANK_KING )
		{
			x1 = font_san.put( x1, y, "Loyalty:" );

			int x2 = info.disp_loyalty( x1, y-1, x1, overseerUnit->loyalty, overseerUnit->target_loyalty, nation_recno, refreshFlag );

			if( overseerUnit->spy_recno )
			{
				//------ if this is the player's spy -------//

				if( overseerUnit->is_own_spy() )
				{
					vga_front.put_bitmap( x2+5, y+1, image_icon.get_ptr("U_SPY") );
					x2 += 15;
				}
			}

			vga.blt_buf( x2, y-1, INFO_X2-2, dispY1+44, 0 );
		}
	}

	pop_disp_y1 = dispY1;

	//---------------- paint the panel --------------//

	if( refreshFlag == INFO_REPAINT )
		vga.d3_panel_up( INFO_X1, dispY1, INFO_X2, dispY1+60 );

	//----------- display populatin distribution ---------//

	int overseerRaceId=0;

	if( overseer_recno )
		overseerRaceId = unit_array[overseer_recno]->race_id;

	if( selected_soldier_id > soldier_count )
		selected_soldier_id = soldier_count;

	//------ display population composition -------//

	int	  x, y;
	Soldier* soldierPtr = soldier_array;
	static  char last_race_id_array[MAX_SOLDIER];
	static  char last_unit_id_array[MAX_SOLDIER];

	dispY1+=1;

	for( int i=0 ; i<MAX_SOLDIER ; i++, soldierPtr++ )
	{
		x = INFO_X1+4+i%4*50;
		y = dispY1+i/4*29;

		if( i<soldier_count )
		{
			if( refreshFlag==INFO_REPAINT ||
				 last_race_id_array[i] != soldierPtr->race_id ||
				 last_unit_id_array[i] != soldierPtr->unit_id )
			{
				vga_front.put_bitmap(x+2, y+2, soldierPtr->small_icon_ptr());
			}

			//----- highlight the selected soldier -------//

			if( selected_soldier_id == i+1 )
				vga_front.rect( x, y, x+27, y+23, 2, V_YELLOW );
			else
				vga_front.rect( x, y, x+27, y+23, 2, vga_front.color_up );

			//------ display hit points bar --------//

			disp_soldier_hit_points( x+2, y+24, x+25, soldierPtr->shown_hit_points(), soldierPtr->max_hit_points() );

			//----- display combat or skill level ------//

			char* spyIconName=NULL;

			if( soldierPtr->spy_recno )
			{
				Spy* spyPtr = spy_array[soldierPtr->spy_recno];

				//------ if this is the player's spy -------//

				if( nation_array.player_recno &&
					 spyPtr->true_nation_recno == nation_array.player_recno )
				{
					spyIconName = "U_SPY";
				}

				//--------------------------------------------//
				//
				// If this is an enemy spy and this firm belongs
				// to the player and there is a player's phoenix
				// over this firm and the spying skill of the spy
				// is low (below 40)
				//
				//--------------------------------------------//

//				else if( spyPtr->spy_skill < 40 &&
//							nation_recno == nation_array.player_recno &&
//							nation_array.player_recno &&
//					 (~nation_array)->revealed_by_phoenix(loc_x1, loc_y1) )
//				{
//					spyIconName = "ENEMYSPY";
//				}

			}

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

			if( spyIconName )
			{
				vga_front.put_bitmap( x+30, y+6, image_icon.get_ptr(spyIconName) );
				vga.blt_buf( x+40, y+6, x+49, y+15, 0 );
				vga.blt_buf( x+30, y+16, x+49, y+26, 0 );
			}
			else
			{
				font_san.disp(x+30, y+6, soldierPtr->skill.combat_level, 1, x+49);
			}

			last_race_id_array[i] = soldierPtr->race_id;
			last_unit_id_array[i] = soldierPtr->unit_id;

			//------- set help parameters ---------//

			if( mouse.in_area(x, y, x+27, y+23) )
				help.set_unit_help( soldierPtr->unit_id, 0, x, y, x+27, y+23 );
		}
		else
		{
			if( last_race_id_array[i] != 0 || last_unit_id_array[i] != 0 )
			{
				vga.blt_buf( x, y, x+49, y+27, 0 );
				last_race_id_array[i] = 0;
				last_unit_id_array[i] = 0;
			}
		}
	}
*/
}