Example #1
0
//--------- Begin of function Nation::ai_assign_spy_to_firm --------//
//
// Think about sending spies to the specific firm.
//
// return: <int> 1 - a spy is assigned successfully.
// 				  0 - failure.
//
int Nation::ai_assign_spy_to_firm(int firmRecno)
{
	Firm* firmPtr = firm_array[firmRecno];

	err_when( !firmPtr->worker_array );

	//---- check if the firm is full or not -----//

	if( firmPtr->nation_recno == nation_recno )	// if it's our own firm
	{
		if( firmPtr->is_worker_full() )	// use is_worker_full() for own firms as it take into account of units patrolling outside
			return 0;
	}
	else
	{
		if( firmPtr->worker_count == MAX_WORKER )
			return 0;
	}

	//------ look for an existing spy -------//

	int raceId	   = firmPtr->majority_race();
	int mobileOnly = firmPtr->nation_recno == nation_recno;   // if assign to own firms/firms, only get mobile spies, don't get spies from existing firms/firms as that will result in a loop effect

	return ai_assign_spy( firmPtr->loc_x1, firmPtr->loc_y1, raceId, mobileOnly );
}