Пример #1
0
int Unit::think_weapon_action()
{
	//---- first try to assign the weapon to an existing camp ----//

	if( think_assign_weapon_to_camp() )
		return 1;

	//----- if no camp to assign, build a new one ------//

	if( think_build_camp() )
		return 1;

	return 0;
}
Пример #2
0
//--------- Begin of function Town::process_ai ----------//
//
void Town::process_ai()
{
	Nation* ownNation = nation_array[nation_recno];

#if defined(DEBUG) && defined(ENABLE_LOG)
	String logStr;

	logStr = "begin Town::process_ai, town_recno=";
	logStr += town_recno;
	logStr += " nation_recno=";
	logStr += nation_recno;
	LOG_MSG(logStr);
#endif

	//---- think about cancelling the base town status ----//

	if( info.game_date%30==town_recno%30 )
	{
		LOG_MSG(" update_base_town_status");
		update_base_town_status();
		LOG_MSG(m.get_random_seed());
	}

	//------ think about granting villagers ---//

	if( info.game_date%30==town_recno%30 )
	{
		LOG_MSG(" think_reward");
		think_reward();
		LOG_MSG(m.get_random_seed());
	}

	//----- if this town should migrate now -----//

	if( should_ai_migrate() )
	{
		if( info.game_date%30==town_recno%30 )
		{
			LOG_MSG(" think_ai_migrate");
			think_ai_migrate();
			LOG_MSG(m.get_random_seed());
		}

		return;		// don't do anything else if the town is about to migrate
	}

	//------ think about building camps first -------//

	if( info.game_date%30==town_recno%30 && !no_neighbor_space &&		// if there is no space in the neighbor area for building a new firm.
		 population > 1 )
	{
		LOG_MSG(" think_build_camp");
		if( think_build_camp() )
		{
			LOG_MSG(m.get_random_seed());
			return;
		}
		LOG_MSG(m.get_random_seed());
	}

	//----- the following are base town only functions ----//

	if( !is_base_town )
		return;

	//------ think about collecting tax ---//

	if( info.game_date%30==(town_recno+15)%30 )
	{
		LOG_MSG("think_collect_tax");
		think_collect_tax();
		LOG_MSG(m.get_random_seed());
	}

	//---- think about scouting in an unexplored map ----//

	if( info.game_date%30==(town_recno+20)%30  )
	{
		think_scout();
	}

	//---- think about splitting the town ---//

	if( info.game_date%30==town_recno%30 )
	{
		LOG_MSG("think_split_town");
		think_split_town();
		LOG_MSG(m.get_random_seed() );
		LOG_MSG("think_move_between_town");
		think_move_between_town();
		LOG_MSG(m.get_random_seed() );
	}

	//---- think about attacking firms/units nearby ---//

	if( info.game_date%30==town_recno%30 )
	{
		LOG_MSG(" think_attack_nearby_enemy");
		if( think_attack_nearby_enemy() )
		{
			LOG_MSG(m.get_random_seed());
			return;
		}
		LOG_MSG(m.get_random_seed());

		LOG_MSG(" think_attack_linked_enemy");
		if( think_attack_linked_enemy() )
		{
			LOG_MSG(m.get_random_seed());
			return;
		}
		LOG_MSG(m.get_random_seed());
	}

	//---- think about capturing linked enemy firms ----//

	if( info.game_date%60==town_recno%60 )
	{
		LOG_MSG(" think_capture_linked_firm");
		think_capture_linked_firm();
		LOG_MSG(m.get_random_seed());
	}

	//---- think about capturing enemy towns ----//

	if( info.game_date%120==town_recno%120 )
	{
		LOG_MSG(" think_capture_enemy_town");
		think_capture_enemy_town();
		LOG_MSG(m.get_random_seed());
	}

	//---- think about using spies on enemies ----//

	if( info.game_date%60==(town_recno+10)%60 )
	{
		LOG_MSG(" think_spying_town");
		if( think_spying_town() )
		{
			LOG_MSG(m.get_random_seed());
			return;
		}
	}

	//---- think about anti-spies activities ----//

	if( info.game_date%60==(town_recno+20)%60 )
	{
		LOG_MSG(" think_counter_spy");
		if( think_counter_spy() )
		{
			LOG_MSG(m.get_random_seed());
			return;
		}
	}

	//--- think about setting up firms next to this town ---//

	if( info.game_date%30==town_recno%30 && !no_neighbor_space &&		// if there is no space in the neighbor area for building a new firm.
		 population >= 5 )
	{
		LOG_MSG(" think_build_market");
		if( think_build_market() )
		{
			LOG_MSG(m.get_random_seed());
			return;
		}
		LOG_MSG(m.get_random_seed());

		//--- the following functions will only be called when the nation has at least a mine ---//

		if( site_array.untapped_raw_count > 0 &&
			 ownNation->ai_mine_count==0 &&		// don't build other structures if there are untapped raw sites and our nation still doesn't have any
			 ownNation->true_profit_365days() < 0 )
		{
			return;
		}

		//---- only build the following if we have enough food ----//

      if( ownNation->ai_has_enough_food() )
		{
			LOG_MSG(" think_build_research");
			if( think_build_research() )
			{
				LOG_MSG(m.get_random_seed());
				return;
			}
			LOG_MSG(m.get_random_seed());

			LOG_MSG(" think_build_war_factory");
			if( think_build_war_factory() )
			{
				LOG_MSG(m.get_random_seed());
				return;
			}
			LOG_MSG(m.get_random_seed());

			LOG_MSG(" think_build_base");
			if( think_build_base() )
			{
				LOG_MSG(m.get_random_seed());
				return;
			}
			LOG_MSG(m.get_random_seed());
		}

		//-------- think build inn ---------//

		LOG_MSG(" think_build_inn");
		think_build_inn();
		LOG_MSG(m.get_random_seed());
	}
}