コード例 #1
0
ファイル: template.cpp プロジェクト: cybersphinx/warzone2100
bool loadDroidTemplates(const char *filename)
{
	WzConfig ini(filename, WzConfig::ReadOnlyAndRequired);
	QStringList list = ini.childGroups();
	for (int i = 0; i < list.size(); ++i)
	{
		ini.beginGroup(list[i]);
		DROID_TEMPLATE design = loadTemplateCommon(ini);
		design.id = list[i];
		design.name = ini.value("name").toString();
		design.multiPlayerID = generateNewObjectId();
		design.prefab = true;
		design.stored = false;
		design.enabled = true;
		bool available = ini.value("available", false).toBool();
		char const *droidResourceName = getDroidResourceName(list[i].toUtf8().constData());
		design.name = droidResourceName != NULL ? droidResourceName : GetDefaultTemplateName(&design);
		ini.endGroup();

		for (int i = 0; i < MAX_PLAYERS; ++i)
		{
			// Give those meant for humans to all human players.
			if (NetPlay.players[i].allocated && available)
			{
				design.prefab = false;
				copyTemplate(i, &design);

				// This sets up the UI templates for display purposes ONLY--we still only use droidTemplates for making them.
				// FIXME: Why are we doing this here, and not on demand ?
				// Only add unique designs to the UI list (Note, perhaps better to use std::map instead?)
				std::list<DROID_TEMPLATE>::iterator it;
				for (it = localTemplates.begin(); it != localTemplates.end(); ++it)
				{
					DROID_TEMPLATE *psCurr = &*it;
					if (psCurr->multiPlayerID == design.multiPlayerID)
					{
						debug(LOG_ERROR, "Design id:%d (%s) *NOT* added to UI list (duplicate), player= %d", design.multiPlayerID, getName(&design), i);
						break;
					}
				}
				if (it == localTemplates.end())
				{
					debug(LOG_NEVER, "Design id:%d (%s) added to UI list, player =%d", design.multiPlayerID, getName(&design), i);
					localTemplates.push_back(design);
				}
			}
			else if (!NetPlay.players[i].allocated)	// AI template
			{
				design.prefab = true;  // prefabricated templates referenced from VLOs
				copyTemplate(i, &design);
			}
		}
		debug(LOG_NEVER, "Droid template found, Name: %s, MP ID: %d, ref: %u, ID: %s, prefab: %s, type:%d (loading)",
		      getName(&design), design.multiPlayerID, design.ref, getID(&design), design.prefab ? "yes" : "no", design.droidType);
	}

	return true;
}
コード例 #2
0
ファイル: template.cpp プロジェクト: Cjkjvfnby/warzone2100
/* load the Droid stats for the components from the Access database */
bool loadDroidTemplates(const char *filename)
{
	WzConfig ini(filename, WzConfig::ReadOnlyAndRequired);
	QStringList list = ini.childGroups();
	for (int i = 0; i < list.size(); ++i)
	{
		ini.beginGroup(list[i]);
		DROID_TEMPLATE design;
		QString droidType = ini.value("type").toString();
		design.id = list[i];
		design.name = ini.value("name").toString();
		if (droidType == "PERSON") design.droidType = DROID_PERSON;
		else if (droidType == "CYBORG") design.droidType = DROID_CYBORG;
		else if (droidType == "CYBORG_SUPER") design.droidType = DROID_CYBORG_SUPER;
		else if (droidType == "CYBORG_CONSTRUCT") design.droidType = DROID_CYBORG_CONSTRUCT;
		else if (droidType == "CYBORG_REPAIR") design.droidType = DROID_CYBORG_REPAIR;
		else if (droidType == "TRANSPORTER") design.droidType = DROID_TRANSPORTER;
		else if (droidType == "SUPERTRANSPORTER") design.droidType = DROID_SUPERTRANSPORTER;
		else if (droidType == "DROID") design.droidType = DROID_DEFAULT;
		else ASSERT(false, "No such droid type \"%s\" for %s", droidType.toUtf8().constData(), getID(&design));
		design.multiPlayerID = generateNewObjectId();
		design.asParts[COMP_BODY] = getCompFromName(COMP_BODY, ini.value("compBody", "ZNULLBODY").toString());
		design.asParts[COMP_BRAIN] = getCompFromName(COMP_BRAIN, ini.value("compBrain", "ZNULLBRAIN").toString());
		design.asParts[COMP_REPAIRUNIT] = getCompFromName(COMP_REPAIRUNIT, ini.value("compRepair", "ZNULLREPAIR").toString());
		design.asParts[COMP_CONSTRUCT] = getCompFromName(COMP_CONSTRUCT, ini.value("compConstruct", "ZNULLCONSTRUCT").toString());
		design.asParts[COMP_ECM] = getCompFromName(COMP_ECM, ini.value("compECM", "ZNULLECM").toString());
		design.asParts[COMP_SENSOR] = getCompFromName(COMP_SENSOR, ini.value("compSensor", "ZNULLSENSOR").toString());
		design.asParts[COMP_PROPULSION] = getCompFromName(COMP_PROPULSION, ini.value("compPropulsion", "ZNULLPROP").toString());
		QStringList weapons = ini.value("weapons").toStringList();
		for (int j = 0; j < weapons.size(); j++)
		{
			design.asWeaps[j] = getCompFromName(COMP_WEAPON, weapons[j]);
		}
		design.numWeaps = weapons.size();
		design.prefab = true;
		design.stored = false;
		design.enabled = true;
		bool available = ini.value("available", false).toBool();
		char const *droidResourceName = getDroidResourceName(list[i].toUtf8().constData());
		design.name = droidResourceName != NULL? droidResourceName : GetDefaultTemplateName(&design);
		ini.endGroup();

		for (int i = 0; i < MAX_PLAYERS; ++i)
		{
			// Give those meant for humans to all human players.
			if (NetPlay.players[i].allocated && available)
			{
				design.prefab = false;
				addTemplateToList(&design, &apsDroidTemplates[i]);

				// This sets up the UI templates for display purposes ONLY--we still only use apsDroidTemplates for making them.
				// FIXME: Why are we doing this here, and not on demand ?
				// Only add unique designs to the UI list (Note, perhaps better to use std::map instead?)
				std::list<DROID_TEMPLATE>::iterator it;
				for (it = localTemplates.begin(); it != localTemplates.end(); ++it)
				{
					DROID_TEMPLATE *psCurr = &*it;
					if (psCurr->multiPlayerID == design.multiPlayerID)
					{
						debug(LOG_ERROR, "Design id:%d (%s) *NOT* added to UI list (duplicate), player= %d", design.multiPlayerID, getName(&design), i);
						break;
					}
				}
				if (it == localTemplates.end())
				{
					debug(LOG_NEVER, "Design id:%d (%s) added to UI list, player =%d", design.multiPlayerID, getName(&design), i);
					localTemplates.push_front(design);
				}
			}
			else if (!NetPlay.players[i].allocated)	// AI template
			{
				design.prefab = true;  // prefabricated templates referenced from VLOs
				addTemplateToList(&design, &apsDroidTemplates[i]);
			}
		}
		debug(LOG_NEVER, "Droid template found, Name: %s, MP ID: %d, ref: %u, ID: %s, prefab: %s, type:%d (loading)",
		      getName(&design), design.multiPlayerID, design.ref, getID(&design), design.prefab ? "yes":"no", design.droidType);
	}

	return true;
}
コード例 #3
0
ファイル: template.cpp プロジェクト: raquim/warzone2100
/* load the Droid stats for the components from the Access database */
bool loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
{
	bool bDefaultTemplateFound = false;

	TableView table(pDroidData, bufferSize);

	for (unsigned i = 0; i < table.size(); ++i)
	{
		LineView line(table, i);

		DROID_TEMPLATE design(line);
		if (table.isError())
		{
			debug(LOG_ERROR, "%s", table.getError().toUtf8().constData());
			return false;
		}

		std::string const pNameCache = design.aName;
		design.pName = const_cast<char *>(pNameCache.c_str());

		if (getTemplateFromUniqueName(design.pName, 0))
		{
			debug(LOG_ERROR, "Duplicate template %s", design.pName);
			continue;
		}

		// Store translated name in aName
		char const *droidResourceName = getDroidResourceName(design.aName);
		sstrcpy(design.aName, droidResourceName != NULL? droidResourceName : GetDefaultTemplateName(&design));

		// Store global default design if found else store in the appropriate array
		if (design.droidType == DROID_ANY)
		{
			design.droidType = DROID_DEFAULT;
			// NOTE: sDefaultDesignTemplate.pName takes ownership
			//       of the memory allocated to pDroidDesign->pName
			//       here. Which is good because pDroidDesign leaves
			//       scope here anyway.
			sDefaultDesignTemplate = design;
			sDefaultDesignTemplate.pName = strdup(design.pName);
			bDefaultTemplateFound = true;
		}
		else
		{
			std::string playerType = line.s(6);
			// Give those meant for humans to all human players.
			// Also support the old template format, in which those meant
			// for humans were player 0 (in campaign) or 5 (in multiplayer).
			if ((!bMultiPlayer && playerType == "0") ||
			    ( bMultiPlayer && playerType == "5") ||
					      playerType == "YES"
			   )
			{
				for (int i = 0; i < MAX_PLAYERS; ++i)
				{
					if (NetPlay.players[i].allocated)  // human prototype template
					{
						design.prefab = false;
						addTemplateToList(&design, &apsDroidTemplates[i]);
					}
				}
				localTemplates.push_front(design);
				localTemplates.front().pName = strdup(localTemplates.front().pName);
			}
			// Add all templates to static template list
			design.prefab = true;  // prefabricated templates referenced from VLOs
			addTemplateToList(&design, &apsStaticTemplates);
		}

		debug(LOG_NEVER, "(default) Droid template found, aName: %s, MP ID: %d, ref: %u, pname: %s, prefab: %s, type:%d (loading)",
			design.aName, design.multiPlayerID, design.ref, design.pName, design.prefab ? "yes":"no", design.droidType);
	}

	ASSERT_OR_RETURN(false, bDefaultTemplateFound, "Default template not found");

	return true;
}
コード例 #4
0
/* load the Droid stats for the components from the Access database */
bool loadDroidTemplates(const char *pDroidData, UDWORD bufferSize)
{
	bool bDefaultTemplateFound = false;

	TableView table(pDroidData, bufferSize);

	for (unsigned i = 0; i < table.size(); ++i)
	{
		LineView line(table, i);

		DROID_TEMPLATE design(line);
		if (table.isError())
		{
			debug(LOG_ERROR, "%s", table.getError().toUtf8().constData());
			return false;
		}

		std::string const pNameCache = design.aName;
		design.pName = const_cast<char *>(pNameCache.c_str());

		if (getTemplateFromUniqueName(design.pName, 0))
		{
			debug(LOG_ERROR, "Duplicate template %s", design.pName);
			continue;
		}

		// Store translated name in aName
		char const *droidResourceName = getDroidResourceName(design.aName);
		sstrcpy(design.aName, droidResourceName != NULL? droidResourceName : GetDefaultTemplateName(&design));

		// Store global default design if found else store in the appropriate array
		if (design.droidType == DROID_ANY)
		{
			design.droidType = DROID_DEFAULT;
			// NOTE: sDefaultDesignTemplate.pName takes ownership
			//       of the memory allocated to pDroidDesign->pName
			//       here. Which is good because pDroidDesign leaves
			//       scope here anyway.
			sDefaultDesignTemplate = design;
			sDefaultDesignTemplate.pName = strdup(design.pName);
			bDefaultTemplateFound = true;
		}
		else
		{
			std::string playerType = line.s(6);

			for (int i = 0; i < MAX_PLAYERS; ++i)
			{
				// Give those meant for humans to all human players.
				// Also support the old template format, in which those meant
				// for humans were player 0 (in campaign) or 5 (in multiplayer), ("YES" is used in MP stats)
				if (NetPlay.players[i].allocated &&
					((!bMultiPlayer && playerType == "0") || (bMultiPlayer && playerType == "5") || playerType == "YES"))
				{
					debug(LOG_NEVER, "HUMAN (%d): %s id:%d enabled:%d", i, design.aName, design.multiPlayerID, design.enabled);
					design.prefab = false;
					addTemplateToList(&design, &apsDroidTemplates[i]);

					// This sets up the UI templates for display purposes ONLY--we still only use apsDroidTemplates for making them.
					// FIXME: Why are we doing this here, and not on demmand ?
					// Only add unique designs to the UI list (Note, perhaps better to use std::map instead?)
					std::list<DROID_TEMPLATE>::iterator it;
					for (it = localTemplates.begin(); it != localTemplates.end(); ++it)
					{
						DROID_TEMPLATE *psCurr = &*it;
						if (psCurr->multiPlayerID == design.multiPlayerID)
						{
							debug(LOG_NEVER, "Design id:%d (%s) *NOT* added to UI list (duplicate), player= %d", design.multiPlayerID, design.aName, i);
							break;
						}
					}
					if (it == localTemplates.end())
					{
						debug(LOG_NEVER, "Design id:%d (%s) added to UI list, player =%d", design.multiPlayerID, design.aName, i);
						localTemplates.push_front(design);
						localTemplates.front().pName = strdup(localTemplates.front().pName);
					}
				}
				else if (NetPlay.players[i].allocated)	//skip the ones not meant for puny humans
				{
					continue;
				}
				else	// assume everything else is for AI
				{
					debug(LOG_NEVER, "AI (%d): %s id:%d enabled:%d", i, design.aName, design.multiPlayerID, design.enabled);
					design.prefab = true;  // prefabricated templates referenced from VLOs
					addTemplateToList(&design, &apsDroidTemplates[i]);
				}
			}
		}
		debug(LOG_NEVER, "(default) Droid template found, aName: %s, MP ID: %d, ref: %u, pname: %s, prefab: %s, type:%d (loading)",
			design.aName, design.multiPlayerID, design.ref, design.pName, design.prefab ? "yes":"no", design.droidType);
	}

	ASSERT_OR_RETURN(false, bDefaultTemplateFound, "Default template not found");

	return true;
}