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


C++ Firm::cast_to_FirmInn方法代码示例

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


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

示例1: catch_spy

//-------- Begin of function SpyArray::catch_spy ------//
//
// <int> spyPlace - either SPY_TOWN or SPY_FIRM
// <int> spyPlacePara - town_recno or firm_recno
//
int SpyArray::catch_spy(int spyPlace, int spyPlacePara)
{
	int nationRecno, totalPop;

	if( spyPlace == SPY_TOWN )
	{
		Town* townPtr = town_array[spyPlacePara];

		nationRecno = townPtr->nation_recno;
		totalPop    = townPtr->population;
	}
	else if( spyPlace == SPY_FIRM )
	{
		Firm* firmPtr = firm_array[spyPlacePara];

		nationRecno = firmPtr->nation_recno;
		if( firmPtr->cast_to_FirmCamp() )
		{
			FirmCamp *firmCamp = firmPtr->cast_to_FirmCamp();
			totalPop    = firmCamp->soldier_count + (firmCamp->overseer_recno>0);
		}
		else if( firmPtr->cast_to_FirmWork() )
		{
			FirmWork *firmWork = firmPtr->cast_to_FirmWork();
			totalPop    = firmWork->worker_count;
		}
		else if( firmPtr->cast_to_FirmTrain() )
		{
			totalPop = firmPtr->cast_to_FirmTrain()->trainee_count;
			return 0;		// don't catch spy
		}
		else if( firmPtr->cast_to_FirmInn() )
		{
			totalPop = firmPtr->cast_to_FirmInn()->inn_unit_count;
			return 0;		// don't catch spy
		}
		else if( firmPtr->cast_to_FirmMarket() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmMonsterTrain() )
		{
			totalPop = firmPtr->cast_to_FirmMonsterTrain()->trainee_count;
			return 0;		// don't catch spy
		}
		else if( firmPtr->cast_to_FirmMonsterAlchemy() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmLishorr() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmMonsterFortress() )
		{
			FirmMonsterFortress *firmMonsterFortress = firmPtr->cast_to_FirmMonsterFortress();
			totalPop = firmMonsterFortress->archer_count + firmMonsterFortress->extra_builder_count;
		}
		else if( firmPtr->cast_to_FirmAnimal() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmIncubator() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmMagic() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmOffensive() )
		{
			totalPop = 0;
			return 0;
		}
		else if( firmPtr->cast_to_FirmOffensive2() )
		{
			totalPop = 0;
			return 0;
		}
		else
		{
			err_here();
			totalPop = 0;
		}
	}
	else
		err_here();

//.........这里部分代码省略.........
开发者ID:mecirt,项目名称:7k2,代码行数:101,代码来源:ospya.cpp

示例2: hire_best_capturer

//-------- Begin of function Nation::hire_best_capturer ------//
//
// Hire the best unit you can find in one of the existing inns.
//
// <int>  townRecno 			    - recno of the town to capture
// <int>  raceId				    - race id. of the unit to hire
//
// return: <int> the recno of the unit hired.
//
int Nation::hire_best_capturer(int townRecno, int raceId)
{
	if( !ai_should_hire_unit(30) )		// 30 - importance rating
		return 0;

	FirmInn	*firmInn;
	Firm		*firmPtr;
	InnUnit *innUnit;
	Skill		*innUnitSkill;
	int		i, j, innUnitCount, curRating;
	int		bestRating=0, bestInnRecno=0, bestInnUnitId=0;
	Town* 	townPtr = town_array[townRecno];
	int		destRegionId = world.get_region_id(townPtr->loc_x1, townPtr->loc_y1);

	for(i=0; i<ai_inn_count; i++)
	{
		firmPtr = (FirmInn*) firm_array[ai_inn_array[i]];

		err_when( firmPtr->firm_id != FIRM_INN );

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

		firmInn = firmPtr->cast_to_FirmInn();

		innUnitCount=firmInn->inn_unit_count;

		if( !innUnitCount )
			continue;

		innUnit = firmInn->inn_unit_array + innUnitCount - 1;

		//------- check units in the inn ---------//

		for(j=innUnitCount; j>0; j--, innUnit--)
		{
			innUnitSkill = &(innUnit->skill);

			if( innUnitSkill->skill_id==SKILL_LEADING &&
				 unit_res[innUnit->unit_id]->race_id == raceId &&
				 cash >= innUnit->hire_cost )
			{
				//----------------------------------------------//
				// evalute a unit on:
				// -its race, whether it's the same as the nation's race
				// -the inn's distance from the destination
				// -the skill level of the unit.
				//----------------------------------------------//

				curRating = innUnitSkill->skill_level;

				if( curRating > bestRating )
				{
					bestRating = curRating;

					bestInnRecno  = firmInn->firm_recno;
					bestInnUnitId = j;
				}
			}
		}
	}

	if( !bestInnUnitId )
		return 0;

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

	firmInn = (FirmInn*) firm_array[bestInnRecno];

	int unitRecno = firmInn->hire(bestInnUnitId);

	if( !unitRecno )
		return 0;

	unit_array[unitRecno]->set_rank(RANK_GENERAL);

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

示例3: hire_unit

//--------- Begin of function Nation::hire_unit --------//
//
// <int>		raceId  - the race the selected unit should have
//							 (0 for any races)
// <int> isCivilian - whether the unit to be hired should be a civilian unit
// <int>   hireSpy  - whether hire a spy or a normal military unit
//	<short>	destX	  - the x location the unit will move to
//	<short>	destY	  - the y location the unit will move to
//
// Note: Units hired in inns are military units only.
// 		There are no civilian units in inns.
//
// return: <int> recno of the unit recruited.
//
int Nation::hire_unit(int raceId, int isCivilian, int hireSpy, short destX, short destY)
{
	if( !ai_should_hire_unit(20) )			// 20 - importance rating
		return 0;

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

	FirmInn	*firmInnPtr;
	Firm		*firmPtr;
	InnUnit *innUnit;
	Skill		*innUnitSkill;
	int		i, j, innUnitCount, curRating, curFirmDist;
	int		bestRating=0, bestInnRecno=0, bestInnUnitId=0;
	int		destRegionId = world.get_region_id(destX, destY);

	for(i=0; i<ai_inn_count; i++)
	{
		firmPtr = firm_array[ai_inn_array[i]];

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

		firmInnPtr = firmPtr->cast_to_FirmInn();

		innUnitCount=firmInnPtr->inn_unit_count;

		if( !innUnitCount )
			continue;

		innUnit = firmInnPtr->inn_unit_array + innUnitCount - 1;

		curFirmDist = m.points_distance(firmPtr->center_x, firmPtr->center_y, destX, destY);

		//------- check units in the inn ---------//

		for(j=innUnitCount; j>0; j--, innUnit--)
		{
			innUnitSkill = &(innUnit->skill);

			if( raceId && unit_res[innUnit->unit_id]->race_id != raceId )
				continue;

			if( isCivilian != unit_res[innUnit->unit_id]->is_civilian )
				continue;

			if( hireSpy && innUnit->spy_skill==0 )
				continue;

			if( cash < innUnit->hire_cost )
				continue;

			//----------------------------------------------//
			// evalute a unit on:
			// -its race, whether it's the same as the nation's race
			// -the inn's distance from the destination
			// -the skill level of the unit.
			//----------------------------------------------//

			curRating = (int) innUnit->skill_level()
							- (100-100*curFirmDist/MAX_WORLD_X_LOC);

			if( unit_res[innUnit->unit_id]->race_id == race_id )
				curRating += 50;

			if( curRating > bestRating )
			{
				bestRating = curRating;

				bestInnRecno  = firmInnPtr->firm_recno;
				bestInnUnitId = j;
			}
		}
	}

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

	if( bestInnUnitId )
	{
		firmPtr = firm_array[bestInnRecno];
		firmInnPtr = firmPtr->cast_to_FirmInn();

		return firmInnPtr->hire(bestInnUnitId);
	}

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


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