Пример #1
0
//Create an entity from its category name. The category name is looked
//up in the EntityCats.hrd file to check what properties must be attached
//to the entity. All required properties will be attached, and all
//attributes will be initialised in their default state.
//!!!!!tmp not const!
CEntity* CEntityFactory::CreateEntityByCategory(CStrID GUID, CStrID Category, EntityPool EntPool) //const
{
	int Idx = Categories.FindIndex(Category);
	if (Idx != INVALID_INDEX)
	{
		const CEntityCat& Cat = Categories.ValueAtIndex(Idx);
		n_assert(Cat.InstDataset.isvalid());
		
		CEntity* pEntity = CreateEntityByClassName(Cat.CppClass);
		pEntity->SetLive(EntPool == LivePool);
		pEntity->SetAttrTable(Cat.InstDataset->GetValueTable());
		pEntity->SetAttrTableRowIndex(Cat.InstDataset->GetValueTable()->AddRow());
		pEntity->SetCategory(Category);
		pEntity->SetUniqueID(GUID);

		for (int i = 0; i < Cat.Properties.Size(); i++)
			AttachProperty(*pEntity, Cat.Properties[i]);

		return pEntity;
	}
	else
	{
		n_error("Loading::CEntityFactory::CreateEntityByCategory(%s): category not found in EntityCats.hrd!",
		Category.CStr());
		return NULL;
	}
}
Пример #2
0
CEntity* CEntityFactory::CreateTmpEntity(CStrID GUID, CStrID Category, PValueTable Table, int Row) const
{
	CEntity* pEntity = CreateEntityByClassName("Entity");
	pEntity->SetCategory(Category); //???add to dummy table all attrs if category exists?
	pEntity->SetAttrTable(Table);
	pEntity->SetAttrTableRowIndex(Row);
	pEntity->SetUniqueID(GUID);
	pEntity->SetLive(true);
	return pEntity;
}
Пример #3
0
CEntity* CEntityFactory::CreateEntityByTemplate(CStrID GUID, CStrID Category, CStrID TplName, EntityPool EntPool)
{
	n_assert(Category.IsValid());
	n_assert(TplName.IsValid());

	const CEntityCat& Cat = Categories[Category];
	
	int TplIdx = FindTemplate(TplName, Cat);
	if (TplIdx == INVALID_INDEX) return NULL;

	CEntity* pEntity = CreateEntityByClassName(Cat.CppClass);
	pEntity->SetLive(EntPool == LivePool);
	pEntity->SetAttrTable(Cat.InstDataset->GetValueTable());
	pEntity->SetAttrTableRowIndex(Cat.InstDataset->GetValueTable()->CopyExtRow(Cat.TplDataset->GetValueTable(), TplIdx, true));
	pEntity->SetCategory(Category);
	pEntity->SetUniqueID(GUID);

	for (int i = 0; i < Cat.Properties.Size(); i++)
		AttachProperty(*pEntity, Cat.Properties[i]);

	return pEntity;
}