Example #1
0
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;
}
Example #2
0
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;
			}
		}

		object->AddComponant(ComponentType, newComponent);
	}
	else
	{
		//everything failed, return false
		return false;
	}
}