Exemple #1
0
//--------- Begin of function Firm::disp_spy_button --------//
//
void Firm::disp_spy_button(int x, int y, int refreshFlag)
{
	if( !own_firm() )		// if not own firm, there is not other button other than the spy button, so always display it left-aligned
		x = INFO_X1;		// if own firm, the x passed will be space position on the interface already, taking into account of the other buttons on interface

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

	if( player_spy_count > 0 )
	{
		//------------ spy menu -----------//

		if( refreshFlag == INFO_REPAINT )
			button_spy_menu.paint( x, y, 'A', "SPYMENU" );

		x += BUTTON_ACTION_WIDTH;

		//---------- bribe button -----------//

		if( nation_recno != nation_array.player_recno ) 	// only display the bribe button for non-player owned towns
		{
			int canBribe=0;

			if( selected_worker_id )
				canBribe = can_spy_bribe(selected_worker_id, nation_array.player_recno );

			else if( overseer_recno )
				canBribe = can_spy_bribe(0, nation_array.player_recno );

			//-------- display the bribe button -------//

			if( refreshFlag == INFO_REPAINT )
				button_bribe.paint( x, y, 'A', "SELBRIBE" );

			if( canBribe )
				button_bribe.enable();
			else
				button_bribe.disable();

			x += BUTTON_ACTION_WIDTH;
		}
	}

	//--------- capture button ----------//

	int canCapture = can_worker_capture(nation_array.player_recno);

	if( canCapture )
	{
		if( !button_capture.enable_flag || refreshFlag==INFO_REPAINT )
			button_capture.paint( x, y, 'A', "CAPTURE" );
	}
	else
	{
		if( refreshFlag==INFO_REPAINT )
			button_capture.reset();

		else if( button_capture.enable_flag )
			button_capture.hide();
	}
}
Exemple #2
0
void Firm::detect_spy_button()
{
	if( player_spy_count>0 )
	{
		if( button_spy_menu.detect() )
		{
			firm_menu_mode = FIRM_MENU_SPY;
			info.disp();
		}

		if( nation_recno != nation_array.player_recno )		// only display the bribe button for non-player towns
		{
			if( button_bribe.detect() )
			{
				if( player_spy_count > 1 )
				{
					firm_menu_mode = FIRM_MENU_SELECT_BRIBER;
				}
				else
				{
					action_spy_recno = get_player_spy_recno(firm_recno);		// the player has only one spy in this firm
					firm_menu_mode   = FIRM_MENU_SET_BRIBE_AMOUNT;
				}

				info.disp();
			}
		}
	}

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

	if( button_capture.detect() && can_worker_capture(nation_array.player_recno) )
	{
		// ##### begin Gilbert 24/6 ##########//
		if( !remote.is_enable() )
		{
			capture_firm(nation_array.player_recno);               // update RemoteMsg::firm_capture
		}
		else
		{
			// packet structure <firm recno> <capturer's nation recno>
			short *shortPtr = (short *)remote.new_send_queue_msg(MSG_FIRM_CAPTURE, 2*sizeof(short) );
			*shortPtr = firm_recno;
			shortPtr[1] = nation_array.player_recno;
		}
		// ##### end Gilbert 24/6 ##########//
	}
}
Exemple #3
0
//------- Begin of function Firm::think_capture -----------//
//
int Firm::think_capture()
{
	Nation* nationPtr;

	int i;
	for( i=nation_array.size() ; i>0 ; i-- )
	{
		if( nation_array.is_deleted(i) )
			continue;

		nationPtr = nation_array[i];

		if( nationPtr->is_ai() && can_worker_capture(i) )
			break;
	}

	if( i==0 )
		return 0;

	//------- capture the firm --------//

	capture_firm(i);

	//------ order troops to attack nearby enemy camps -----//

	Firm *firmPtr, *bestTarget=NULL;
	int  curDistance, minDistance=0x1000;

	for( i=firm_array.size() ; i>0 ; i-- )
	{
		if( firm_array.is_deleted(i) )
			continue;

		firmPtr = firm_array[i];

		//----- only attack enemy camps -----//

		if( firmPtr->nation_recno != nation_recno ||
			 firmPtr->firm_id != FIRM_CAMP )
		{
			continue;
		}

		curDistance = misc.points_distance(center_x, center_y,
						  firmPtr->center_x, firmPtr->center_y );

		//--- only attack camps within 15 location distance to this firm ---//

		if( curDistance < 15 && curDistance < minDistance )
		{
			minDistance = curDistance;
			bestTarget  = firmPtr;
		}
	}

	if( bestTarget )
	{
		int useAllCamp = nationPtr->pref_military_courage > 60 || misc.random(3)==0;

		nationPtr->ai_attack_target( bestTarget->loc_x1, bestTarget->loc_y1,
			((FirmCamp*)bestTarget)->total_combat_level(), 0, 0, 0, 0, useAllCamp );
	}

	return 1;
}