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


C++ Town::auto_set_layout方法代码示例

本文整理汇总了C++中Town::auto_set_layout方法的典型用法代码示例。如果您正苦于以下问题:C++ Town::auto_set_layout方法的具体用法?C++ Town::auto_set_layout怎么用?C++ Town::auto_set_layout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Town的用法示例。


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

示例1: think_new_independent_town


//.........这里部分代码省略.........
		if( town_array.is_deleted(i) )
			continue;

		townPtr = town_array[i];

		allTotalPop += townPtr->population;

		if( townPtr->nation_recno == 0 )
			independentTownCount++;
	}

	if( independentTownCount >= 10 )		// only when the no. of independent town is less than 10
		return;

	//--- if the total population of all nations combined > 1000, then no new independent town will emerge ---//

	if( allTotalPop > 1000 )
		return;

	//--- add 1 to 2 wanderer per month per race ---//

	for( i=0 ; i<MAX_RACE ; i++ )
	{
		race_wander_pop_array[i] += 2+m.random(5);
	}

	//----- check if there are enough wanderers to set up a new town ---//

	int raceId = m.random(MAX_RACE)+1;

	for( i=0 ; i<MAX_RACE ; i++ )
	{
		if( ++raceId > MAX_RACE )
			raceId = 1;

		if( race_wander_pop_array[raceId-1] >= 10 )	// one of the race must have at least 10 people
			break;
	}

	if( i==MAX_RACE )
		return;

	//------- locate for a space to build the town ------//

	int xLoc, yLoc;

	if( !think_town_loc(MAX_WORLD_X_LOC*MAX_WORLD_Y_LOC/4, xLoc, yLoc) )
		return;

	//--------------- create town ---------------//

	int townRecno  = town_array.add_town(0, raceId, xLoc, yLoc);
	int maxTownPop = 20 + m.random(10);
	int addPop, townResistance;
	int loopCount=0;

	townPtr = town_array[townRecno];

	while(1)
	{
		err_when( loopCount++ > 100 );

		addPop = race_wander_pop_array[raceId-1];
		addPop = MIN(maxTownPop-townPtr->population, addPop);

		townResistance = independent_town_resistance();

		townPtr->init_pop( raceId, addPop, townResistance, 0, 1 );		// 0-the add pop do not have jobs, 1-first init

		race_wander_pop_array[raceId-1] -= addPop;

		err_when( race_wander_pop_array[raceId-1] < 0 );

		if( townPtr->population >= maxTownPop )
			break;

		//---- next race to be added to the independent town ----//

		raceId = m.random(MAX_RACE)+1;

		for( i=0 ; i<MAX_RACE ; i++ )
		{
			if( ++raceId > MAX_RACE )
				raceId = 1;

			if( race_wander_pop_array[raceId-1] >= 5 )
				break;
		}

		if( i==MAX_RACE )		// no suitable race
			break;
	}

	//---------- set town layout -----------//

	townPtr->auto_set_layout();

//	if( sys.debug_session )
//		box.msg( "A new independent town has emerged." );
}
开发者ID:brianV,项目名称:7kaa,代码行数:101,代码来源:OTOWNA.cpp

示例2: create_town

//-------- Begin of function Battle::create_town --------//
//
// <int> nationRecno = the nation recno of the town
// <int> raceId      = the race id. of the town
//
// <int&> xLoc = for the starting location of the town
// <int&> yLoc = for the starting location of the town
//
// return: <int> townRecno - >0  the recno of the town created
//                           ==0 no town created
//
int Battle::create_town(int nationRecno, int raceId, int& xLoc, int& yLoc)
{
	//------- locate for a space to build the town ------//

	if( !town_array.think_town_loc(MAX_WORLD_X_LOC*MAX_WORLD_Y_LOC, xLoc, yLoc) )
		return 0;

	//--------------- create town ---------------//

	int townRecno = town_array.add_town(nationRecno, raceId, xLoc, yLoc);

	Town* townPtr = town_array[townRecno];

	//--------- no. of mixed races ---------//

	if( nationRecno )
	{
		int initPop;

		if( config.random_start_up )
			initPop = 25 + misc.random(26);		// 25 to 50
		else
			initPop = 40;

		Town* townPtr = town_array[townRecno];

		townPtr->init_pop( raceId, initPop, 100, 0, 1 );		// 100-startup loyalty, last 1-first initialization at the beginning of the game
	}
	else
	{
		int mixedRaceCount;

		if( nationRecno )
			mixedRaceCount = 1;
		else
			mixedRaceCount= misc.random(3)+1;		// 1 to 3 mixed races

		int curPop, totalPop=0, townResistance;

		for( int i=0 ; i<mixedRaceCount ; i++ )
		{
			if(totalPop>=MAX_TOWN_POPULATION)
				break;

			townResistance = town_array.independent_town_resistance();

			if( i==0 )
			{
				curPop = 15/mixedRaceCount + misc.random(15/mixedRaceCount);
				if(curPop>=MAX_TOWN_POPULATION)
					curPop = MAX_TOWN_POPULATION;

				err_when(curPop==0);
				townPtr->init_pop( raceId, curPop, townResistance, 0, 1 ); 	// last 1-first initialization at the beginning of the game
				totalPop += curPop;
			}
			else
			{
				curPop = 10/mixedRaceCount + misc.random(10/mixedRaceCount);
				if(curPop>=MAX_TOWN_POPULATION-totalPop)
					curPop = MAX_TOWN_POPULATION-totalPop;

				err_when(curPop==0);
				townPtr->init_pop( misc.random(MAX_RACE)+1, curPop, townResistance, 0, 1 );
				totalPop += curPop;
			}
		}
	}

	//---------- set town layout -----------//

	townPtr->auto_set_layout();

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

示例3: detect_human_view

// ----- begin of function ScenarioEditor::detect_human_view ------//
//
int ScenarioEditor::detect_human_view()
{
	if( power.command_id )
		return 0;

	// detect map area

	if( mouse.double_click( ZOOM_X1, ZOOM_Y1, ZOOM_X2, ZOOM_Y2, 0 ) )	// left click
	{
		int xLoc, yLoc;
		if( world.zoom_matrix->get_detect_location(mouse.click_x(0), mouse.click_y(0),
			&xLoc, &yLoc, NULL) )
		{
			if( unit_or_struct == 0 && !vbrowse_unit_id.none_record )
			{
				// put unit human_unit_id_array[human_unit_id_browse_recno-1]
				// on (xLoc, yLoc)
				int unitId = human_unit_id_array[human_unit_id_browse_recno-1];
				UnitInfo *unitInfo = unit_res[unitId];
				SpriteInfo *spriteInfo = sprite_res[unitInfo->sprite_id];
				if( world.check_unit_space(xLoc, yLoc, 
					xLoc+spriteInfo->loc_width-1, yLoc+spriteInfo->loc_height-1, unitInfo->mobile_type) )
				{
					int unitRecno = unit_array.add_unit( unitId, brush_player_recno, RANK_SOLDIER, 100, xLoc, yLoc );

					if( unitRecno && unitId == UNIT_WAGON )
					{
						err_when( !human_race_filter );
						UnitWagon* unitPtr = (UnitWagon *)unit_array[unitRecno];
						unitPtr->race_id = human_race_filter;
						unitPtr->set_pop( MAX_WAGON_POPULATION );
					}
				}
			}
			else if( unit_or_struct == 1 && !vbrowse_firm_build.none_record )
			{
				err_when( human_firm_group_array[human_firm_group_browse_recno] == 0 );
				if( human_firm_group_array[human_firm_group_browse_recno-1] < 0 )
				{
					// put town of race -human_firm_group_array[human_firm_group_browse_recno]
					// (xLoc, yLoc)

					if( world.can_build_town(xLoc, yLoc, 0) )
					{
						int raceId = -human_firm_group_array[human_firm_group_browse_recno-1];
						int townRecno = town_array.generate_town(brush_player_recno, raceId, xLoc, yLoc);
						if( townRecno )
						{
							Town *townPtr = town_array[townRecno];
							townPtr->construction_completion_percent = 100;
							townPtr->under_construction = 0;

							// init_pop
							if( brush_player_recno )
								townPtr->init_pop( 0, 100, 0, 1 );
							else
								townPtr->init_pop( 0, town_array.independent_town_resistance(), 0, 1 );

							townPtr->auto_set_layout();
						}
					}
				}
				else
				{
					// put firm group human_firm_group_array[human_firm_group_browse_recno-1]
					// on (xLoc, yLoc)

					FirmGroup *firmGroup = firm_res.get_group(human_firm_group_array[human_firm_group_browse_recno-1]);
					if( world.can_build_firm( xLoc, yLoc, firmGroup->firm_id, 0) )
					{
						if (brush_player_recno == 0)
						{
							box.msg( text_editor.str_no_independent() ); // "Cannot add any Independent structures" );
						}
						else
						{
							if( firmGroup->firm_id == FIRM_BASE )		// if it's a seat of power, give the nation a scroll of power first
								god_res[firmGroup->race_id]->enable_know(brush_player_recno);

							firm_array.generate_firm( xLoc, yLoc, brush_player_recno, firmGroup->firm_id, firmGroup->race_code );
						}
					}
				}
			}
		}
		return 1;
	}

	if( mouse.double_click( ZOOM_X1, ZOOM_Y1, ZOOM_X2, ZOOM_Y2, 1) )	// right click to remove
	{
		int xLoc, yLoc;
		char mobileType;
		Location* locPtr = power.test_detect(mouse.click_x(1), mouse.click_y(1), &mobileType, &xLoc, &yLoc );
		if( locPtr )
		{
			if( locPtr->unit_recno(mobileType) )		// remove unit
			{
				int unitRecno = locPtr->unit_recno(mobileType);
//.........这里部分代码省略.........
开发者ID:mecirt,项目名称:7k2,代码行数:101,代码来源:osedit_h.cpp


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