Example #1
0
QList<NPC*> GameLoader::loadNpcs(const QDomElement& element)
{
	QList<NPC*> npcs;
	QString source = element.attribute("source");
	if (!source.isNull())
	{
		QDomDocument document = load(path()+"/"+source);
		npcs = loadNpcs(document.documentElement());
		_paths.pop();
		return npcs;
	}

	QDomNodeList children = element.childNodes();
	for (int i=0; i<children.size(); ++i)
	{
		QDomElement child = children.at(i).toElement();
		if (child.tagName()=="npc")
		{
			NPC* npc = new NPC();
			npc->setName(child.attribute("name"));
			initializeObject(child, npc);
			npcs << npc;
		}
	}

	return npcs;
}
Example #2
0
Game* GameLoader::createGame(const QDomElement& element)
{
	if (element.tagName()!="game") return nullptr;


	Game* game = new Game();
	initializeObject(element.firstChildElement("player"), game->player());

	QDomNodeList children = element.childNodes();
	for (int i=0; i<children.size(); ++i)
	{
		QDomElement child = children.at(i).toElement();
		if (child.tagName()=="npcs")
		{
			for (NPC* npc: loadNpcs(child))
			{
				game->npcFactory()->addPrototype(npc->name(), npc);
			}
		}
	}

	QString mapSource = element.attribute("startmap");
	QString target = element.attribute("target");

	game->changeMap(mapSource, target);

	return game;
}
Example #3
0
bool CLevel::loadGraal(CString& pFileName)
{
	CPacket levelData;
	CString version;
	char* dataFile = getDataFile(pFileName.text());
	if(!strlen(dataFile))
		return false;
	if(!levelData.load(dataFile))
		return false;
	fileName = pFileName;
	modTime = getFileModTime(dataFile);
	version = levelData.readChars(8);

	bool v0 = (version == "GR-V1.00");
	bool v1 = (version == "GR-V1.01");
	bool v2 = (version == "GR-V1.02");
	bool v3 = (version == "GR-V1.03");
	//printf("Loading map %s\n", pFileName.text());
	//printf("Loading tiles..\n");
	loadTiles(levelData, version);
	//printf("Loading links..\n");
	loadLinks(levelData);
	//printf("Loading baddies..\n");
	loadBaddies(levelData);
	if (v0 || v1 || v2 || v3)
	{
		//printf("Loading npcs..\n");
		loadNpcs(levelData);
	}
	if (v1 || v2 || v3)
	{
		//printf("Loading chests..\n");
		loadChests(levelData);
	}
	//printf("Loading signs..\n");
	loadSigns(levelData);

	//Find our map id
	for(int i = 0; i < CMap::mapList.count(); i++)
	{
		CMap* m = (CMap*)CMap::mapList[i];
		if((levelIndex = m->getLevelpos(pFileName)) >= 0)
		{
			map = m;
			break;
		}
	}

	return true;
}
Example #4
0
bool CLevel::loadGraal(CString& pFileName)
{
	CPacket levelData;
	CString version;
	char* dataFile = getDataFile(pFileName.text());
	if(!strlen(dataFile))
		return false;
	if(!levelData.load(dataFile))
		return false;
	fileName = pFileName;
	modTime = getFileModTime(dataFile);
	version = levelData.readChars(8);

	bool v0 = (version == "GR-V1.00");
	bool v1 = (version == "GR-V1.01");
	bool v2 = (version == "GR-V1.02");
	bool v3 = (version == "GR-V1.03");
	//printf("Loading map %s\n", pFileName.text());
	//printf("Loading tiles..\n");
	loadTiles(levelData, version);
	//printf("Loading links..\n");
	loadLinks(levelData);
	//printf("Loading baddies..\n");
	loadBaddies(levelData);
	if (v0 || v1 || v2 || v3)
	{
		//printf("Loading npcs..\n");
		loadNpcs(levelData);
	}
	if (v1 || v2 || v3)
	{
		//printf("Loading chests..\n");
		loadChests(levelData);
	}
	//printf("Loading signs..\n");
	loadSigns(levelData);
	return true;
}