当前位置: 首页>>代码示例>>C++>>正文


C++ Nation类代码示例

本文整理汇总了C++中Nation的典型用法代码示例。如果您正苦于以下问题:C++ Nation类的具体用法?C++ Nation怎么用?C++ Nation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Nation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: think_build_firm

//------- Begin of function FirmHarbor::think_build_firm -----------//
//
void FirmHarbor::think_build_firm()
{
	Nation* ownNation = nation_array[nation_recno];

	if( ownNation->cash < 2000 )		// don't build if the cash is too low
		return;

	if( ownNation->true_profit_365days() < (50-ownNation->pref_use_marine)*20 )		//	-1000 to +1000
		return;

	//----- think about building markets ------//

	if( ownNation->pref_trading_tendency >= 60 )
	{
		if( ai_build_firm(FIRM_MARKET) )
			return;
	}

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

	if( ownNation->pref_military_development/2 +
		 (linked_firm_count + ownNation->ai_ship_count + ship_count) * 10 +
		 ownNation->total_jobless_population*2 > 150 )
	{
		ai_build_firm(FIRM_CAMP);
	}
}
开发者ID:AMDmi3,项目名称:7kaa,代码行数:29,代码来源:OF_HARB2.cpp

示例2: think_build_export_market

//------- Begin of function FirmMarket::think_build_export_market -----------//
//
// Think about export goods of this market to other markets.
//
int FirmMarket::think_build_export_market(int townRecno)
{
	Town* 		townPtr = town_array[townRecno];
	Firm* 		firmPtr;
	Nation* 		nationPtr = nation_array[nation_recno];

	//---- see if we already have a market linked to this town ----//

	for( int i=0 ; i<townPtr->linked_firm_count ; i++ )
	{
		firmPtr = firm_array[ townPtr->linked_firm_array[i] ];

		if( firmPtr->firm_id != FIRM_MARKET || firmPtr->firm_recno==firm_recno )
			continue;

		//--- if we already have a market there, no need to build a new market ----//

		if( firmPtr->nation_recno == nation_recno )
			return 0;
	}

	//--- if there is no market place linked to this town, we can set up one ourselves ---//

	short buildXLoc, buildYLoc;

	if( !nationPtr->find_best_firm_loc(FIRM_MARKET, townPtr->loc_x1, townPtr->loc_y1, buildXLoc, buildYLoc) )
	{
		townPtr->no_neighbor_space = 1;
		return 0;
	}

	nationPtr->add_action(buildXLoc, buildYLoc, townPtr->loc_x1, townPtr->loc_y1, ACTION_AI_BUILD_FIRM, FIRM_MARKET);
	return 1;
}
开发者ID:AMDmi3,项目名称:7kaa,代码行数:38,代码来源:OF_MARK2.cpp

示例3: memset

//-------- Begin of function Info::set_rank_data --------//
//
// <int> onlyHasContact - if this is 1, then only nations
//								  that have contact with the viewing
//								  nation is counted. Otherwise all nations
//								  are counted.
//
void Info::set_rank_data(int onlyHasContact)
{
	Nation* viewingNation = NULL; 
	Nation* nationPtr;
	int 	  rankPos=0;

	if( nation_array.player_recno && !nation_array.is_deleted(info.viewing_nation_recno) )
		viewingNation = nation_array[info.viewing_nation_recno];

	memset( nation_rank_data_array, 0, sizeof(nation_rank_data_array) );

	for( int i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) )
			continue;

		if( onlyHasContact )
		{
			if( viewingNation && !viewingNation->get_relation(i)->has_contact )
				continue;
		}

		nationPtr = nation_array[i];

		nation_rank_data_array[0][i-1] = nationPtr->population_rating;

		nation_rank_data_array[1][i-1] = nationPtr->military_rating;

		nation_rank_data_array[2][i-1] = nationPtr->economic_rating;

		nation_rank_data_array[3][i-1] = (int) nationPtr->reputation;

		nation_rank_data_array[4][i-1] = (int) nationPtr->kill_monster_score;
	}
}
开发者ID:MicroVirus,项目名称:7kaa,代码行数:42,代码来源:OR_RANK.cpp

示例4: nation_filter

//-------- Begin of static function nation_filter --------//
//
// This function has dual purpose :
//
// 1. when <int> recNo is not given :
//    - return the total no. of nations of this nation
//
// 2. when <int> recNo is given :
//    - return the nation recno in nation_array of the given recno.
//
int Info::nation_filter(int recNo)
{
	int    	i, nationCount=0;
//	Nation*  viewingNation = nation_array[info.viewing_nation_recno];

	Nation*  viewingNation = NULL;
	
	if( nation_array.player_recno )
		viewingNation = nation_array[info.viewing_nation_recno];

	for( i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) )
			continue;

		if( i==info.viewing_nation_recno ||
			 !viewingNation ||
			 viewingNation->get_relation(i)->has_contact )
		{
			nationCount++;
		}

		if( recNo && nationCount==recNo )
			return i;
	}

	err_when( recNo );   // the recNo is not found, it is out of range

	return nationCount;
}
开发者ID:112212,项目名称:7k2,代码行数:40,代码来源:or_nat.cpp

示例5: region_id

//--------- Begin of function Unit::ai_build_camp --------//
//
// Order this unit to build a camp in its region.
//
int Unit::ai_build_camp()
{
	//--- to prevent building more than one camp at the same time ---//

	int     curRegionId = region_id();
	Nation* ownNation = nation_array[nation_recno];

	if( ownNation->is_action_exist( ACTION_AI_BUILD_FIRM, FIRM_CAMP, curRegionId ) )
		return 0;

	//------- locate a place for the camp --------//

	FirmInfo* firmInfo = firm_res[FIRM_CAMP];
	int 		 xLoc=0, yLoc=0;
	char 	 	 teraMask = UnitRes::mobile_type_to_mask(UNIT_LAND);

	if( world.locate_space_random(xLoc, yLoc, MAX_WORLD_X_LOC-1,
		 MAX_WORLD_Y_LOC-1, firmInfo->loc_width+2, firmInfo->loc_height+2,   // leave at least one location space around the building
		 MAX_WORLD_X_LOC*MAX_WORLD_Y_LOC, curRegionId, 1, teraMask) )
	{
		return ownNation->add_action( xLoc, yLoc, -1, -1,
					ACTION_AI_BUILD_FIRM, FIRM_CAMP, 1, sprite_recno );
	}

	return 0;
}
开发者ID:MicroVirus,项目名称:7kaa,代码行数:30,代码来源:OUNITAI.cpp

示例6: think_build_firm

//------- Begin of function Town::think_build_firm --------//
//
// Think about building a specific type of firm next to this town.
//
// <int> firmId  - id. of the firm to be built.
// <int> maxFirm - max. no. of firm of this type to be built next to this town.
//
int Town::think_build_firm(int firmId, int maxFirm)
{
	Nation* nationPtr = nation_array[nation_recno];

	//--- check whether the AI can build a new firm next this firm ---//

	if( !nationPtr->can_ai_build(firmId) )
		return 0;

	//-- only build one market place next to this town, check if there is any existing one --//

	Firm* firmPtr;
	int 	firmCount=0;

	for(int i=0; i<linked_firm_count; i++)
	{
		err_when(!linked_firm_array[i] || firm_array.is_deleted(linked_firm_array[i]));

		firmPtr = firm_array[linked_firm_array[i]];

		//---- if there is one firm of this type near the town already ----//

		if( firmPtr->firm_id == firmId &&
			 firmPtr->nation_recno == nation_recno )
		{
			if( ++firmCount >= maxFirm )
				return 0;
		}
	}

	//------ queue building a new firm -------//

	return ai_build_neighbor_firm(firmId);
}
开发者ID:spippolatore,项目名称:7kaa,代码行数:41,代码来源:OTOWNAI.cpp

示例7: average_loyalty

//------- Begin of function Town::think_reward --------//
//
// Think about granting the villagers.
//
void Town::think_reward()
{
	if( !has_linked_own_camp )
		return;

	if( accumulated_reward_penalty > 0 )
		return;

	//---- if accumulated_reward_penalty>0, don't grant unless the villagers are near the rebel level ----//

	Nation* ownNation = nation_array[nation_recno];
	int averageLoyalty = average_loyalty();

	if( averageLoyalty < REBEL_LOYALTY + 5 + ownNation->pref_loyalty_concern/10 )		// 35 to 45
	{
		int importanceRating;

		if( averageLoyalty < REBEL_LOYALTY+5 )
			importanceRating = 40+population;
		else
			importanceRating = population;

		if( ownNation->ai_should_spend(importanceRating) )
			reward( COMMAND_AI );
	}
}
开发者ID:spippolatore,项目名称:7kaa,代码行数:30,代码来源:OTOWNAI.cpp

示例8: recruit

//-------- Begin of function Town::think_spying_town_assign_to --------//
//
// Think about planting spies into independent towns and enemy towns.
//
int Town::think_spying_town_assign_to(int raceId)
{
	Nation* ownNation = nation_array[nation_recno];

	int targetTownRecno = ownNation->think_assign_spy_target_town(race_id, region_id);

	if( !targetTownRecno )
		return 0;

	//------- assign the spy now -------//

	int unitRecno = recruit(SKILL_SPYING, raceId, COMMAND_AI);

	if( !unitRecno )
		return 0;

	Town* targetTown = town_array[targetTownRecno];

	int actionRecno = ownNation->add_action( targetTown->loc_x1, targetTown->loc_y1,
							-1, -1, ACTION_AI_ASSIGN_SPY, targetTown->nation_recno, 1, unitRecno );

	if( !actionRecno )
		return 0;

	train_unit_action_id = ownNation->get_action(actionRecno)->action_id;

	return 1;
}
开发者ID:spippolatore,项目名称:7kaa,代码行数:32,代码来源:OTOWNAI.cpp

示例9: pay_weapon_expense

//------- Begin of function FirmCamp::pay_weapon_expense -------//
//
void FirmCamp::pay_weapon_expense()
{
	Worker* workerPtr = worker_array;
	Nation* nationPtr = nation_array[nation_recno];

	for( int i=1 ; i<=worker_count ; i++, workerPtr++ )
	{
		if( workerPtr->unit_id &&
			 unit_res[workerPtr->unit_id]->unit_class == UNIT_CLASS_WEAPON )
		{
			if( nationPtr->cash > 0 )
			{
				nationPtr->add_expense( EXPENSE_WEAPON, (float) unit_res[workerPtr->unit_id]->year_cost / 365, 1 );
			}
			else     // decrease hit points if the nation cannot pay the unit
			{
				if( workerPtr->hit_points > 0 )
					workerPtr->hit_points--;

				if( workerPtr->hit_points == 0 )
					kill_worker(i);		// if its hit points is zero, delete it

				err_when( workerPtr->hit_points < 0 );
			}
		}
	}
}
开发者ID:spippolatore,项目名称:7kaa,代码行数:29,代码来源:OF_CAMP.cpp

示例10: err_when

//--------- Begin of function Firm::ai_update_link_status ---------//
//
// Updating link status of this firm with towns. 
//
void Firm::ai_update_link_status()
{
	err_when( firm_id == FIRM_CAMP );		// FirmCamp has its own ai_update_link_status(), this version shouldn't be called.

	if( !worker_array )		// if this firm does not need any workers. 
		return;

	if( is_worker_full() )	// if this firm already has all the workers it needs. 
		return;

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

	Nation* ownNation = nation_array[nation_recno];
	int	  i, rc;

	for( i=0 ; i<linked_town_count ; i++ )
	{
		Town* townPtr = town_array[linked_town_array[i]];

		//--- enable link to hire people from the town ---//

		rc = townPtr->nation_recno==0 ||		// either it's an independent town or it's friendly or allied to our nation
			  ownNation->get_relation_status(townPtr->nation_recno) >= NATION_FRIENDLY;

		toggle_town_link( i+1, rc, COMMAND_AI );
	}
}
开发者ID:AMDmi3,项目名称:7kaa,代码行数:31,代码来源:OFIRMAI.cpp

示例11: should_build_new_weapon

//----- Begin of function FirmWar::should_build_new_weapon ------//
//
int FirmWar::should_build_new_weapon()
{
	//----- first see if we have enough money to build & support the weapon ----//

	Nation* nationPtr = nation_array[nation_recno];

	if( nationPtr->true_profit_365days() < 0 )		// don't build new weapons if we are currently losing money
		return 0;

	if( nationPtr->expense_365days(EXPENSE_WEAPON) >
		 nationPtr->income_365days() * 30 + nationPtr->pref_use_weapon/2 )		// if weapon expenses are larger than 30% to 80% of the total income, don't build new weapons
	{
		return 0;
	}

	//----- see if there is any space on existing camps -----//

	Firm* firmPtr;

	for( int i=0 ; i<nationPtr->ai_camp_count ; i++ )
	{
		firmPtr = firm_array[ nationPtr->ai_camp_array[i] ];

		if( firmPtr->region_id != region_id )
			continue;

		if( firmPtr->worker_count < MAX_WORKER )		// there is space in this firm
			return 1;
	}

	return 0;
}
开发者ID:AMDmi3,项目名称:7kaa,代码行数:34,代码来源:OF_WAR2.cpp

示例12: while

//--------- Begin of function FirmWar::process_queue ---------//
//
void FirmWar::process_queue()
{
    if( build_queue_count==0 )
        return;

    // ######## begin Gilbert 30/12 #######//
    // --- cancel if technology lost -----//

    // do not cancel build in progress because tech may be recovered
    // cancel when it is going to build

    if( nation_recno )
    {
        // ---- delete queue until the first unit in the queue can build ----//

        while( build_queue_count > 0
                && unit_res[build_queue_array[0]]->get_nation_tech_level(nation_recno) == 0 )
        {
            misc.del_array_rec( build_queue_array, build_queue_count, sizeof(build_queue_array[0]), 1 );
            build_queue_count--;
        }
    }

    if( build_queue_count==0)
        return;
    // ######## end Gilbert 30/12 #######//



    //--- first check if the nation has enough money to build the weapon ---//

    Nation* nationPtr = nation_array[nation_recno];
    build_unit_id = build_queue_array[0];

    if( nationPtr->cash < unit_res[build_unit_id]->build_cost )
    {
        build_unit_id = 0;
        return;
    }

    nationPtr->add_expense( EXPENSE_WEAPON, unit_res[build_unit_id]->build_cost, 1);

    err_when( build_queue_count > MAX_BUILD_QUEUE );

    misc.del_array_rec( build_queue_array, build_queue_count, sizeof(build_queue_array[0]), 1 );

    build_queue_count--;

    //------- set building parameters -------//

    last_process_build_frame_no = sys.frame_count;
    build_progress_days = (float) 0;

    if( firm_array.selected_recno == firm_recno )
    {
        // disable_refresh = 1;
        // info.disp();
        // disable_refresh = 0;
    }
}
开发者ID:7k2,项目名称:7k2,代码行数:62,代码来源:of_war.cpp

示例13: get_relation

//----- Begin of function Nation::consider_alliance_rating -----//
//
// Return a rating from 0 to 100 for whether this nation should ally
// with the given nation.
//
int Nation::consider_alliance_rating(int nationRecno)
{
	Nation* nationPtr = nation_array[nationRecno];

	//---- the current relation affect the alliance tendency ---//

	NationRelation* nationRelation = get_relation(nationRecno);

	int allianceRating = nationRelation->ai_relation_level-20;

	//--- if the nation has a bad record of starting wars with us before, decrease the rating ---//

	allianceRating -= nationRelation->started_war_on_us_count * 20;

	//------ add the trade rating -------//

	int tradeRating = trade_rating(nationRecno) +				// existing trade amount
							ai_trade_with_rating(nationRecno)/2;	// possible trade

	allianceRating += tradeRating;

	//---- if the nation's power is larger than us, it's a plus ----//

	int powerRating = nationPtr->military_rank_rating() - military_rank_rating();		// if the nation's power is larger than ours, it's good to form treaty with them

	if( powerRating > 0 )
		allianceRating += powerRating;

	return allianceRating;
}
开发者ID:mecirt,项目名称:7k2,代码行数:35,代码来源:oai_talk.cpp

示例14: put_expense_rec

//-------- Begin of static function put_expense_rec --------//
//
static void put_expense_rec(int recNo, int x, int y, int refreshFlag)
{
	//----- define expense descriptions -------//

	static const char* expense_des_array[EXPENSE_TYPE_COUNT] =
	{
		"General Costs",
		"Spy Costs",
		"Other Mobile Human Unit Costs",
		"Caravan Costs",
		"Weapons Costs",
		"Ship Costs",
		"Buildings Costs",
		"Training Units",
		"Hiring Units",
		"Honoring Units",
		"Foreign Worker Salaries",
		"Grants to Your Villagers",
		"Grants to Other Villagers",
		"Imports",
		"Aid/Tribute to Other Kingdoms",
		"Bribes",
	};

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

	x+=3;
	y+=3;

	Nation* nationPtr = nation_array[info.viewing_nation_recno];

	font_san.put( x    , y, expense_des_array[recNo-1] );
	font_san.put( x+370, y, misc.format( (int) nationPtr->expense_365days(recNo-1), 2 ) );
}
开发者ID:Stummi,项目名称:7kaa,代码行数:36,代码来源:OR_ECO.cpp

示例15: think_adjust_workforce

//------- Begin of function FirmBase::think_adjust_workforce -------//
//
// Think about adjusting the workforce by increasing or decreasing
// needed_worker_count.
//
int FirmBase::think_adjust_workforce()
{
	Nation* nationPtr = nation_array[nation_recno];

	//---- if we have enough food -----//

	if( nationPtr->ai_has_enough_food() )
	{
		if( needed_worker_count < MAX_WORKER )
		{
			set_needed_worker_count( needed_worker_count+1, COMMAND_AI );
			return 1;
		}
	}

	//---- if we are running out of food -----//

	else
	{
		if( needed_worker_count > MAX_WORKER/2 )
		{
			set_needed_worker_count( needed_worker_count-1, COMMAND_AI );
			return 1;
		}
	}

	return 0;
}
开发者ID:112212,项目名称:7k2,代码行数:33,代码来源:of_basea.cpp


注:本文中的Nation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。