コード例 #1
0
ファイル: OFIRMRES.cpp プロジェクト: Stummi/7kaa
//-------- Start of function FirmInfo::can_build -------------//
//
// Whether unit of this race can build this firm or not.
//
// <int> unitRecno - check whether this unit knows how to build
//						   this firm.
//
int FirmInfo::can_build(int unitRecno)
{
	if( !buildable )
		return 0;

	Unit* unitPtr = unit_array[unitRecno];

	if( !unitPtr->nation_recno )
		return 0;

	if( !(get_nation_tech_level(unitPtr->nation_recno) > 0) )
		return 0;

	//------ fortress of power ------//

	if( firm_id == FIRM_BASE )	// only if the nation has acquired the myth to build it
	{
		if( unitPtr->rank_id == RANK_GENERAL ||
			 unitPtr->rank_id == RANK_KING ||
			 unitPtr->skill.skill_id == SKILL_PRAYING ||
			 unitPtr->skill.skill_id == SKILL_CONSTRUCTION )
		{
			//----- each nation can only build one seat of power -----//

			if( unitPtr->nation_recno > 0 &&
				 unitPtr->race_id > 0 &&
				 nation_array[unitPtr->nation_recno]->base_count_array[unitPtr->race_id-1] == 0 )
			{
				//--- if this nation has acquired the needed scroll of power ---//

				return nation_array[unitPtr->nation_recno]->know_base_array[unitPtr->race_id-1];
			}
		}

		return 0;
	}

	//------ a king or a unit with construction skill knows how to build all buildings -----//

	if( firm_race_id == 0 )
	{
		if( unitPtr->rank_id == RANK_KING || unitPtr->skill.skill_id == SKILL_CONSTRUCTION )
			return 1;
	}

	//----- if the firm is race specific, if the unit is right race, return true ----//

	if( firm_race_id == unitPtr->race_id )
		return 1;

	//---- if the unit has the skill needed by the firm or the unit has general construction skill ----//

	if( firm_skill_id && firm_skill_id == unitPtr->skill.skill_id )
		return 1;

	return 0;
}
コード例 #2
0
ファイル: ofirmres.cpp プロジェクト: 112212/7k2
//-------- Start of function FirmInfo::nation_can_build -------------//
//
// Whether the given nation can build this firm or not.
//
// <int> nationRecno - recno of the nation.
// <int> raceId		- race of the firm to be built.
// [int] checkCash   - check if the building nation has enough cash and
//							  live points (default: 1)
//
int FirmInfo::nation_can_build(int nationRecno, int raceId, int checkCash)
{
	if( !buildable || !nationRecno || !raceId )
		return 0;

	if( get_nation_tech_level(nationRecno) <= 0 )
		return 0;

	Nation* nationPtr = nation_array[nationRecno];

	//--- human nation cannot build monster firms before monster firms cost live points ---//

	if( nationPtr->is_human() && raceId<0 )	
		return 0;

	//--- check if the building nation has enough cash and live points ---//
	
	if( checkCash )
	{
		if( nationPtr->cash < setup_cost ||
			 nationPtr->live_points < setup_live_points_cost )
		{
			return 0;
		}
	}

	//----- special unit training structure -----//

	if( firm_id == FIRM_SPECIAL )
	{
		if (raceId < 0)
			return 0;

		err_when( raceId < 1 || raceId > MAX_RACE );

		if( !tech_res[TECH_SPU_STRUCTURE(raceId)]->get_nation_tech_level(nationRecno) )
			return 0;
	}

	//------ Seat of Power ------//

	if( firm_id == FIRM_BASE )	// only if the nation has acquired the myth to build it
	{
		//--- if this nation has acquired the needed scroll of power ---//
		//----- each nation can only build one seat of power -----//
#ifdef DEMO
		return 0;
#else
		if( game.game_mode == GAME_TUTORIAL &&
			nationRecno != nation_array.player_recno )
		{
			return 0;
		}

		if( !( nationPtr->base_count_array[raceId-1] == 0 &&
				 nationPtr->know_base_array[raceId-1] ) )
		{
			return 0;
		}
#endif
	}

	// ###### begin Gilbert 23/12 ########//
	if( firm_id == FIRM_FORTRESS )
	{
		return 0;		// cannot build monster fortress
	}
	// ###### end Gilbert 23/12 ########//

#ifdef DEMO
	if( firm_id == FIRM_OFFENSIVE_BUILDING_1 ||
	 	 firm_id == FIRM_OFFENSIVE_BUILDING_2 ||
		 firm_id == FIRM_OFFENSIVE_BUILDING_3 ||
		 firm_id == FIRM_OFFENSIVE_BUILDING_4 )
	{
		return 0;		// cannot build monster fortress
	}
#endif

	return 1;
}