Ejemplo n.º 1
0
//------ Begin of function Nation::ai_build_camp_town_next_to ------//
//
// Build a new camp and settle a new town next to the given location.
//
// <int> xLoc1, yLoc1, xLoc2, yLoc2 - the location that the new camp
//												  and town should be built next to.
//
int Nation::ai_build_camp_town_next_to(int xLoc1, int yLoc1, int xLoc2, int yLoc2)
{
	//---- first see if we already have a camp in the region ---//

	int regionId = world.get_region_id(xLoc1, yLoc1);

	// ##### patch begin Gilbert 16/3 #######//
	//#ifdef AMPLUS
	if( region_array[regionId]->region_stat_id == 0)
		return 0;
	//#endif
	// ##### patch end Gilbert 16/3 #######//

	if( region_array.get_region_stat(regionId)->camp_nation_count_array[nation_recno-1] == 0 )
	{
		//--- if we don't have one yet, build one next to the destination ---//

		if( !world.locate_space( xLoc1, yLoc1, xLoc2, yLoc2,
									 3, 3, UNIT_LAND, regionId, 1 ) )		// 1-locating the space for building
		{
			return 0;
		}

		if( !world.can_build_firm( xLoc1, yLoc1, FIRM_CAMP ) )
			return 0;

		return ai_patrol_to_region(xLoc1, yLoc1, SEA_ACTION_BUILD_CAMP);
	}
	else //-- if there's already a camp there, then set people there to settle --//
	{
		FirmCamp* firmCamp;

		for( int i=0 ; i<ai_camp_count ; i++ )
		{
			firmCamp = (FirmCamp*) firm_array[ ai_camp_array[i] ];

			if( firmCamp->region_id != regionId )
				continue;

			xLoc1 = firmCamp->loc_x1;
			yLoc1 = firmCamp->loc_y1;
			xLoc2 = firmCamp->loc_x2;
			yLoc2 = firmCamp->loc_y2;

			if( world.locate_space( xLoc1, yLoc1, xLoc2, yLoc2,
				 STD_TOWN_LOC_WIDTH, STD_TOWN_LOC_HEIGHT, UNIT_LAND, regionId, 1 ) )		// 1-locating the space for building
			{
				if( world.can_build_town( xLoc1, yLoc1 ) )
					return ai_settle_to_region(xLoc1, yLoc1, SEA_ACTION_SETTLE);
			}
		}
	}

	return 0;
}
Ejemplo n.º 2
0
//------ Begin of function Nation::think_move_troop_between_region ------//
//
// Thing about moving units between regions
//
int Nation::think_move_troop_between_region()
{
	//----- find the region with the least population -----//

	int campCount, maxCampCount=0, minCampCount=0x1000;
	int maxRegionId=0, minRegionId=0;
	RegionStat* regionStat = region_array.region_stat_array;
	int curRating, minRegionRating=0;

	int i;
	for( i=0 ; i<region_array.region_stat_count ; i++, regionStat++ )
	{
		if( regionStat->nation_presence_count==0 &&
			 regionStat->independent_town_count==0 &&
			 regionStat->raw_count==0 )
		{
			continue;
		}

		campCount = regionStat->camp_nation_count_array[nation_recno-1];

		if( campCount > maxCampCount )
		{
			maxCampCount = campCount;
			maxRegionId   = regionStat->region_id;
		}

		if( campCount <= minCampCount )
		{
			curRating = ai_should_sail_to_rating(i+1);

			if( campCount < minCampCount || curRating >= minRegionRating )
			{
				minCampCount 	 = campCount;
				minRegionId  	 = regionStat->region_id;
				minRegionRating = curRating;
			}
		}
	}

	if( !maxRegionId || !minRegionId || maxRegionId==minRegionId )
		return 0;

	//----- only move if the difference is big enough ------//

	int minJoblessPop = region_array.get_region_stat(minRegionId)->nation_jobless_population_array[nation_recno-1];
	int maxJoblessPop = region_array.get_region_stat(maxRegionId)->nation_jobless_population_array[nation_recno-1];

	if( pref_use_marine < 90 )		// if > 90, it will ignore all these and move anyway  
	{
		if( minCampCount==0 )
		{
			if( maxJoblessPop - minJoblessPop < 200 - pref_use_marine )  // 150 to 200 (pref_use_marine is always >= 50, if it is < 50, marine functions are not called at all
				return 0;
		}
		else
		{
			if( maxJoblessPop - minJoblessPop < 150 - pref_use_marine )  // 100 to 150 (pref_use_marine is always >= 50, if it is < 50, marine functions are not called at all
				return 0;
		}
	}
	else
	{
		if( maxJoblessPop < 20 )		// don't move if we only have a few jobless people
			return 0;
	}

	//------------ see if we have any camps in the region -----------//

	int   destRegionId = minRegionId;
	Firm* firmPtr;

	for( i=ai_camp_count-1 ; i>=0 ; i-- )
	{
		firmPtr = firm_array[ai_camp_array[i]];

		if( firmPtr->region_id == destRegionId &&
			 !firmPtr->under_construction )				// if it's under construction there may be unit waiting outside of the camp
		{
			//--- if there is one, must move the troop close to it ---//

			return ai_patrol_to_region(firmPtr->center_x, firmPtr->center_y, SEA_ACTION_NONE);
		}
	}
	//----- if we don't have any camps in the region, build one ----//

	int 		 xLoc=0, yLoc=0;
	FirmInfo* firmInfo = firm_res[FIRM_CAMP];

	if(world.locate_space_random(xLoc, yLoc, MAX_WORLD_X_LOC-1,
		MAX_WORLD_Y_LOC-1, firmInfo->loc_width, firmInfo->loc_height,
		MAX_WORLD_X_LOC*MAX_WORLD_Y_LOC, destRegionId, 1))
	{
		return ai_patrol_to_region(xLoc, yLoc, SEA_ACTION_BUILD_CAMP);
	}

	return 0;
}