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


C++ Object::AddComponant方法代码示例

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


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

示例1: AddFuelComponent

bool ObjectManager::AddFuelComponent(int objectNumber, SMapSquare fuelPoint)
{
	BaseComponent* newComponent = new FuelPatrolComponent(Objects.at(objectNumber), myMap, fuelPoint);
	vector<string> newComponentRequirements = newComponent->GetRequiredComponents();
	Object* object = Objects.at(objectNumber);

		//check for each requirement on the object.
		//if any requirements are missing delete the new component and fail the attachment
		for (int i = 0; i < newComponentRequirements.size(); i++)
		{
			if (!object->CheckForComponant(newComponentRequirements.at(i)))
			{
				delete newComponent;
				return false;
			}
		}

		//check if there is already an override of this type
		if (object->CheckForComponant("PatrolAIOverride"))
		{
			//delete the existing component and replace it
			delete object->GetComponentPointer("PatrolAIOverride");
		}

		object->AddComponant("PatrolAIOverride", newComponent);
		return true;
}
开发者ID:Nixxus,项目名称:ComponentFYP,代码行数:27,代码来源:ObjectManager.cpp

示例2: AddComponent

bool ObjectManager::AddComponent(string ComponentType, int objectNumber, string mesh, float X, float Y, float Z)
{
	BaseComponent* newComponent;
	vector<string> newComponentRequirements;
	Object* object = Objects.at(objectNumber);

	if (ComponentMap.find(ComponentType) != ComponentMap.end()) // if we have the requested component
	{
		string name;
		//create the new component and get it's requiremernts
		newComponent = ComponentMap[ComponentType](object ,myMap);
		newComponentRequirements = newComponent->GetRequiredComponents();

		//Set override name for components
		if (ComponentType == "ChargeAttackComponent")
		{
			name = "AttackAIOverride";
		}
		else if (ComponentType == "BlockSearchComponent")
		{
			name = "SearchAIOverride";
		}
		else 
		{
			name  = ComponentType;
		}

		//check for each requirement on the object.
		//if any requirements are missing delete the new component and fail the attachment
		for (int i = 0; i < newComponentRequirements.size(); i++)
		{
			if (!object->CheckForComponant(newComponentRequirements.at(i)))
			{
				delete newComponent;
				return false;
			}
		}


		//add the component to the object and give a pointer to the object to the component
		object->AddComponant(name,newComponent);
		return true;
	}
	else if(ComponentType == "ModelComponent") // exception as this component requires a mesh and co-ordinates
	{
		//create the model from the mesh
		tle::IModel* model = MeshMap[mesh]->CreateModel(X,Y,Z);
		//create a new component with this model
		newComponent = new ModelComponent(Objects.at(objectNumber), model);
		newComponentRequirements = newComponent->GetRequiredComponents();

		//check for each requirement on the object.
		//if any requirements are missing delete the new component and fail the attachment
		for (int i = 0; i < newComponentRequirements.size(); i++)
		{
			if (!object->CheckForComponant(newComponentRequirements.at(i)))
			{
				delete newComponent;
				return false;
			}
		}

		//add the model to the component
		object->AddComponant(ComponentType,newComponent);
		return true;
	}
	else if(ComponentType == "ControlComponent")
	{
		newComponent = new ControlComponent(Objects.at(objectNumber), myEngine);
		newComponentRequirements = newComponent->GetRequiredComponents();

		//check for each requirement on the object.
		//if any requirements are missing delete the new component and fail the attachment
		for (int i = 0; i < newComponentRequirements.size(); i++)
		{
			if (!object->CheckForComponant(newComponentRequirements.at(i)))
			{
				delete newComponent;
				return false;
			}
		}

		object->AddComponant(ComponentType, newComponent);
	}
	else if (ComponentType == "InfoPanelComponent")
	{
		newComponent = new InfoPanelComponent(Objects.at(objectNumber), myEngine);
		newComponentRequirements = newComponent->GetRequiredComponents();

		//check for each requirement on the object.
		//if any requirements are missing delete the new component and fail the attachment
		for (int i = 0; i < newComponentRequirements.size(); i++)
		{
			if (!object->CheckForComponant(newComponentRequirements.at(i)))
			{
				delete newComponent;
				return false;
			}
		}

//.........这里部分代码省略.........
开发者ID:Nixxus,项目名称:ComponentFYP,代码行数:101,代码来源:ObjectManager.cpp


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