Ejemplo n.º 1
0
bool CreatureDatabase::importXMLFromOT(const FileName& filename, wxString& error, wxArrayString& warnings)
{
	pugi::xml_document doc;
	pugi::xml_parse_result result = doc.load_file(filename.GetFullPath().mb_str());
	if (!result) {
		error = wxT("Couldn't open file \"") + filename.GetFullName() + wxT("\", invalid format?");
		return false;
	}

	pugi::xml_node node;
	if ((node = doc.child("monsters"))) {
		for (pugi::xml_node monsterNode = node.first_child(); monsterNode; monsterNode = monsterNode.next_sibling()) {
			if (as_lower_str(monsterNode.name()) != "monster") {
				continue;
			}

			pugi::xml_attribute attribute;
			if (!(attribute = monsterNode.attribute("file"))) {
				continue;
			}

			FileName monsterFile(filename);
			monsterFile.SetFullName(wxString(attribute.as_string(), wxConvUTF8));

			pugi::xml_document monsterDoc;
			pugi::xml_parse_result monsterResult = monsterDoc.load_file(monsterFile.GetFullPath().mb_str());
			if (!monsterResult) {
				continue;
			}

			CreatureType* creatureType = CreatureType::loadFromOTXML(monsterFile, monsterDoc, warnings);
			if (creatureType) {
				CreatureType* current = (*this)[creatureType->name];
				if (current) {
					*current = *creatureType;
					delete creatureType;
				} else {
					creature_map[as_lower_str(creatureType->name)] = creatureType;

					Tileset* tileSet = nullptr;
					if (creatureType->isNpc) {
						tileSet = materials.tilesets["NPCs"];
					} else {
						tileSet = materials.tilesets["Others"];
					}
					ASSERT(tileSet != nullptr);
					
					Brush* brush = newd CreatureBrush(creatureType);
					brushes.addBrush(brush);

					TilesetCategory* tileSetCategory = tileSet->getCategory(TILESET_CREATURE);
					tileSetCategory->brushlist.push_back(brush);
				}
			}
		}
	} else if ((node = doc.child("monster")) || (node = doc.child("npc"))) {
		CreatureType* creatureType = CreatureType::loadFromOTXML(filename, doc, warnings);
		if (creatureType) {
			CreatureType* current = (*this)[creatureType->name];

			if (current) {
				*current = *creatureType;
				delete creatureType;
			} else {
				creature_map[as_lower_str(creatureType->name)] = creatureType;

				Tileset* tileSet = nullptr;
				if (creatureType->isNpc) {
					tileSet = materials.tilesets["NPCs"];
				} else {
					tileSet = materials.tilesets["Others"];
				}
				ASSERT(tileSet != nullptr);

				Brush* brush = newd CreatureBrush(creatureType);
				brushes.addBrush(brush);

				TilesetCategory* tileSetCategory = tileSet->getCategory(TILESET_CREATURE);
				tileSetCategory->brushlist.push_back(brush);
			}
		}
	} else {
		error = wxT("This is not valid OT npc/monster data file.");
		return false;
	}
	return true;
}
Ejemplo n.º 2
0
void Tileset::loadCategory(xmlNodePtr node, wxArrayString &warnings)
{
	TilesetCategory* category = NULL;
	TilesetCategory* category2 = NULL;

	if(xmlStrcmp(node->name,(const xmlChar*)"terrain") == 0)
	{
		category = getCategory(TILESET_TERRAIN);
	}
	else if(xmlStrcmp(node->name,(const xmlChar*)"doodad") == 0)
	{
		category = getCategory(TILESET_DOODAD);
	}
	else if(xmlStrcmp(node->name,(const xmlChar*)"items") == 0)
	{
		category = getCategory(TILESET_ITEM);
	}
	else if(xmlStrcmp(node->name,(const xmlChar*)"raw") == 0)
	{
		category = getCategory(TILESET_RAW);
	} else if(xmlStrcmp(node->name,(const xmlChar*)"terrain_and_raw") == 0)
	{
		category = getCategory(TILESET_TERRAIN);
		category2 = getCategory(TILESET_RAW);
	}
	else if(xmlStrcmp(node->name,(const xmlChar*)"doodad_and_raw") == 0)
	{
		category = getCategory(TILESET_DOODAD);
		category2 = getCategory(TILESET_RAW);
	}
	else if(xmlStrcmp(node->name,(const xmlChar*)"items_and_raw") == 0)
	{
		category = getCategory(TILESET_ITEM);
		category2 = getCategory(TILESET_RAW);
	}
	else if(xmlStrcmp(node->name,(const xmlChar*)"creatures") == 0)
	{
		category = getCategory(TILESET_CREATURE);
		for(xmlNodePtr brushNode = node->children; brushNode != NULL; brushNode = brushNode->next)
		{
			if(xmlStrcmp(brushNode->name,(const xmlChar*)"creature") == 0)
			{
				std::string creature_name;
				if(!readXMLValue(brushNode, "name", creature_name))
				{
					warnings.push_back(wxT("Couldn't read creature name tag of creature tileset"));
					continue;
				}

				CreatureType* ctype = creature_db[creature_name];
				if(ctype)
				{
					CreatureBrush* brush;
					if(ctype->brush)
					{
						brush = ctype->brush;
					}
					else
					{
						brush = ctype->brush = newd CreatureBrush(ctype);
						brushes.addBrush(brush);
					}
					brush->flagAsVisible();
					category->brushlist.push_back(brush);
				}
				else
				{
					warnings.push_back(wxString(wxT("Unknown creature type \"")) << wxstr(creature_name) << wxT("\""));
				}
			}
		}
	}
	
	if(!category)
		return;

	for(xmlNodePtr brushNode = node->children; brushNode != NULL; brushNode = brushNode->next)
	{
		category->loadBrush(brushNode, warnings);
		if(category2)
			category2->loadBrush(brushNode, warnings);
	}
}
Ejemplo n.º 3
0
void Materials::createOtherTileset()
{
	Tileset* others;
	Tileset* npc_tileset;

	if(tilesets["Others"] != nullptr) {
		others = tilesets["Others"];
		others->clear();
	} else {
		others = newd Tileset(g_brushes, "Others");
		tilesets["Others"] = others;
	}

	if(tilesets["NPCs"] != nullptr) {
		npc_tileset = tilesets["NPCs"];
		npc_tileset->clear();
	} else {
		npc_tileset = newd Tileset(g_brushes, "NPCs");
		tilesets["NPCs"] = npc_tileset;
	}

	// There should really be an iterator to do this
	for(int32_t id = 0; id <= g_items.getMaxID(); ++id) {
		ItemType& it = g_items[id];
		if(it.id == 0) {
			continue;
		}

		if(!it.isMetaItem()) {
			Brush* brush;
			if(it.in_other_tileset) {
				others->getCategory(TILESET_RAW)->brushlist.push_back(it.raw_brush);
				continue;
			} else if(it.raw_brush == nullptr) {
				brush = it.raw_brush = newd RAWBrush(it.id);
				it.has_raw = true;
				g_brushes.addBrush(it.raw_brush);
			} else if(!it.has_raw) {
				brush = it.raw_brush;
			} else
				continue;

			brush->flagAsVisible();
			others->getCategory(TILESET_RAW)->brushlist.push_back(it.raw_brush);
			it.in_other_tileset = true;
		}
	}

	for(CreatureMap::iterator iter = g_creatures.begin(); iter != g_creatures.end(); ++iter) {
		CreatureType* type = iter->second;
		if(type->in_other_tileset) {
			if(type->isNpc) {
				npc_tileset->getCategory(TILESET_CREATURE)->brushlist.push_back(type->brush);
			} else {
				others->getCategory(TILESET_CREATURE)->brushlist.push_back(type->brush);
			}
		} else if(type->brush == nullptr) {
			type->brush = newd CreatureBrush(type);
			g_brushes.addBrush(type->brush);
			type->brush->flagAsVisible();
			type->in_other_tileset = true;
			if(type->isNpc) {
				npc_tileset->getCategory(TILESET_CREATURE)->brushlist.push_back(type->brush);
			} else {
				others->getCategory(TILESET_CREATURE)->brushlist.push_back(type->brush);
			}
		}
	}
}