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


C++ CSystem::GetAllBuildings方法代码示例

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


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

示例1: CheckEnergyConsumers

bool CSystemManager::CheckEnergyConsumers(CSystem& system)
{
	if(!m_bOnOffline)
		return false;
	CEnergyConsumersChecker checker(system);
	CArray<CBuilding>* buildings = system.GetAllBuildings();
	bool bomb_warning = false;
	bool defense_checked = false;
	const CSystemProd& prod = *system.GetProduction();
	int additional_available_energy = prod.GetAvailableEnergy();
	for(int i = 0; i < buildings->GetSize(); ++i)
	{
		CBuilding& building = buildings->GetAt(i);
		const CBuildingInfo& info = resources::BuildingInfo->GetAt(building.GetRunningNumber() - 1);
		const int needed = info.GetNeededEnergy();
		if(needed == 0)
			continue;
		if(m_IgnoredBuildings.find(info.GetRunningNumber()) != m_IgnoredBuildings.end())
			continue;
		bool should_be_online = building.GetIsBuildingOnline();
		if(info.GetShipYard() || info.GetShipBuildSpeed() > 0)
		{
			AssertBotE(!info.IsDefenseBuilding());
			should_be_online = checker.ShouldTakeShipyardOnline();
		}
		if(info.IsDefenseBuilding())
		{
			AssertBotE(!info.GetShipYard());
			if(bomb_warning)
				should_be_online = true;
			else if(!defense_checked)
			{
				bomb_warning = checker.BomberInSector();
				should_be_online = bomb_warning;
				defense_checked = true;
			}
			else
				should_be_online = false;
		}
		if(info.IsDeritiumRefinery())
			should_be_online = checker.CheckStoreFull(RESOURCES::DERITIUM, info, building);

		if(info.GetResistance() > 0)
			should_be_online = !system.Taken();

		if(info.GetShipTraining() > 0)
			should_be_online = system.GetOwnerOfShip(system.OwnerID(), true);

		if(info.GetTroopTraining() > 0)
			should_be_online = !system.GetTroops()->IsEmpty();

		bool minus_moral = false;
		if(info.GetMoralProd() < 0)
			minus_moral = should_be_online = checker.CheckMoral(info, building, m_iMinMoral, m_iMinMoralProd);

		const WORKER::Typ type = info.ProducesWorkerfull();
		if(type != WORKER::NONE)
		{
			should_be_online = system.HasStore(type) ?
				checker.CheckStoreFull(WorkerToResource(type), info, building) : true;
		}

		should_be_online = should_be_online || info.IsUsefulForProduction();
		should_be_online = should_be_online &&
			(info.OnlyImprovesProduction(minus_moral) ||
				(info.GetShipBuildSpeed() > 0 && checker.ShouldTakeShipyardOnline()));
		should_be_online = should_be_online || info.IsUsefulMoral();

		const bool is_online = building.GetIsBuildingOnline();
		if(should_be_online && !is_online)
		{
			if(additional_available_energy >= needed)
			{
				building.SetIsBuildingOnline(true);
				additional_available_energy -= needed;
				system.CalculateVariables();
			}
		}
		else if (!should_be_online && is_online)
		{
			const int needed = info.GetNeededEnergy();
			building.SetIsBuildingOnline(false);
			additional_available_energy += needed;
			system.CalculateVariables();
		}
	}
	AssertBotE(additional_available_energy >= 0);
	return m_bBombWarning && bomb_warning;
}
开发者ID:bote-team,项目名称:bote,代码行数:89,代码来源:Manager.cpp


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