/**
 * @brief Load callback for savegames in XML Format
 * @param[in] parent XML Node structure, where we get the information from
 */
bool INT_LoadXML (xmlNode_t *parent)
{
	xmlNode_t *node;
	xmlNode_t *interestsNode = XML_GetNode(parent, SAVE_INTERESTS);
	bool success = true;

	ccs.lastInterestIncreaseDelay = XML_GetInt(interestsNode, SAVE_INTERESTS_LASTINCREASEDELAY, 0);
	ccs.lastMissionSpawnedDelay = XML_GetInt(interestsNode, SAVE_INTERESTS_LASTMISSIONSPAWNEDDELAY, 0);
	ccs.overallInterest = XML_GetInt(interestsNode, SAVE_INTERESTS_OVERALL, 0);
	Com_RegisterConstList(saveInterestConstants);
	for (node = XML_GetNode(interestsNode, SAVE_INTERESTS_INTEREST); node;
			node = XML_GetNextNode(node, interestsNode, SAVE_INTERESTS_INTEREST)) {
		const char *categoryId = XML_GetString(node, SAVE_INTERESTS_ID);
		int cat;

		if (!Com_GetConstInt(categoryId, (int*) &cat)) {
			Com_Printf("Invalid interest category '%s'\n", categoryId);
			success = false;
			break;
		}
		ccs.interest[cat]= XML_GetInt(node, SAVE_INTERESTS_VAL, 0);
	}
	Com_UnregisterConstList(saveInterestConstants);
	return success;
}
Beispiel #2
0
/**
 * @brief Save callback for savegames in xml
 * @param[out] p XML Node structure, where we write the information to
 * @sa INS_LoadXML
 * @sa SAV_GameSaveXML
 */
qboolean INS_SaveXML (xmlNode_t *p)
{
	xmlNode_t *n;
	installation_t *inst;

	n = XML_AddNode(p, SAVE_INSTALLATION_INSTALLATIONS);
	Com_RegisterConstList(saveInstallationConstants);
	INS_Foreach(inst) {
		xmlNode_t *s, *ss;

		s = XML_AddNode(n, SAVE_INSTALLATION_INSTALLATION);
		XML_AddString(s, SAVE_INSTALLATION_TEMPLATEID, inst->installationTemplate->id);
		XML_AddInt(s, SAVE_INSTALLATION_IDX, inst->idx);
		XML_AddString(s, SAVE_INSTALLATION_NAME, inst->name);
		XML_AddPos3(s, SAVE_INSTALLATION_POS, inst->pos);
		XML_AddString(s, SAVE_INSTALLATION_STATUS, Com_GetConstVariable(SAVE_INSTALLATIONSTATUS_NAMESPACE, inst->installationStatus));
		XML_AddInt(s, SAVE_INSTALLATION_DAMAGE, inst->installationDamage);
		XML_AddFloat(s, SAVE_INSTALLATION_ALIENINTEREST, inst->alienInterest);
		XML_AddInt(s, SAVE_INSTALLATION_BUILDSTART, inst->buildStart);

		ss = XML_AddNode(s, SAVE_INSTALLATION_BATTERIES);
		XML_AddIntValue(ss, SAVE_INSTALLATION_NUM, inst->numBatteries);
		B_SaveBaseSlotsXML(inst->batteries, inst->numBatteries, ss);
	}
	Com_UnregisterConstList(saveInstallationConstants);
	return qtrue;
}
/**
 * @brief Save callback for savegames in XML Format
 * @param[out] parent XML Node structure, where we write the information to
 */
bool INT_SaveXML (xmlNode_t *parent)
{
	xmlNode_t *interestsNode = XML_AddNode(parent, SAVE_INTERESTS);
	int i;

	XML_AddShortValue(interestsNode, SAVE_INTERESTS_LASTINCREASEDELAY, ccs.lastInterestIncreaseDelay);
	XML_AddShortValue(interestsNode, SAVE_INTERESTS_LASTMISSIONSPAWNEDDELAY, ccs.lastMissionSpawnedDelay);
	XML_AddShortValue(interestsNode, SAVE_INTERESTS_OVERALL, ccs.overallInterest);
	Com_RegisterConstList(saveInterestConstants);
	for (i = 0; i < INTERESTCATEGORY_MAX; i++) {
		xmlNode_t * interestNode = XML_AddNode(interestsNode, SAVE_INTERESTS_INTEREST);
		XML_AddString(interestNode, SAVE_INTERESTS_ID, Com_GetConstVariable(SAVE_INTERESTCAT_NAMESPACE, i));
		XML_AddShort(interestNode, SAVE_INTERESTS_VAL, ccs.interest[i]);
	}
	Com_UnregisterConstList(saveInterestConstants);
	return true;
}
Beispiel #4
0
static void testConstInt (void)
{
	const constListEntry_t list[] = {
		{"namespace::power", 1},
		{"namespace::speed", 2},
		{"namespace::accuracy", 3},
		{"namespace::mind", 4},
		{"namespace::close", 5},
		{"namespace::heavy", 6},
		{"namespace::assault", 7},
		{"namespace::sniper", 8},
		{"namespace::explosive", 9},
		{"namespace::hp", 10},

		{NULL, -1}
	};
	const constListEntry_t list2[] = {
		{"namespace2::soldier", 0},
		{"namespace2::scientist", 1},
		{"namespace2::worker", 2},
		{"namespace2::pilot", 3},
		{NULL, -1}
	};
	int out;

	Com_RegisterConstInt("namespace::variable", 1);
	CU_ASSERT(Com_UnregisterConstVariable("namespace::variable"));

	Com_RegisterConstInt("namespace::variable", 1);
	CU_ASSERT(Com_UnregisterConstVariable("namespace::variable"));

	Com_RegisterConstInt("namespace::variable2", 2);
	Com_RegisterConstInt("namespace::variable3", 3);
	Com_RegisterConstInt("namespace::variable4", 4);
	Com_RegisterConstInt("namespace::variable5", 5);
	Com_RegisterConstInt("namespace::variable6", 6);

	Com_RegisterConstInt("namespace2::variable2", 10);

	out = 0;
	CU_ASSERT_TRUE(Com_GetConstInt("namespace2::variable2", &out));
	CU_ASSERT_EQUAL(out, 10);
	out = 0;
	CU_ASSERT_TRUE(Com_GetConstInt("namespace::variable2", &out));
	CU_ASSERT_EQUAL(out, 2);
	out = 0;
	CU_ASSERT_TRUE(Com_GetConstInt("variable2", &out));
	CU_ASSERT_EQUAL(out, 10);

	CU_ASSERT_STRING_EQUAL(Com_GetConstVariable("namespace", 2), "variable2");

	CU_ASSERT(Com_UnregisterConstVariable("namespace2::variable2"));
	CU_ASSERT(Com_UnregisterConstVariable("namespace::variable2"));
	CU_ASSERT(Com_UnregisterConstVariable("namespace::variable3"));
	CU_ASSERT(Com_UnregisterConstVariable("namespace::variable4"));
	CU_ASSERT(Com_UnregisterConstVariable("namespace::variable5"));
	CU_ASSERT(Com_UnregisterConstVariable("namespace::variable6"));

	CU_ASSERT(!Com_UnregisterConstVariable("namespace::variable"));
	CU_ASSERT(!Com_UnregisterConstVariable("namespace::variable2"));
	CU_ASSERT(!Com_UnregisterConstVariable("namespace::variable3"));
	CU_ASSERT(!Com_UnregisterConstVariable("namespace::variable4"));
	CU_ASSERT(!Com_UnregisterConstVariable("namespace::variable5"));
	CU_ASSERT(!Com_UnregisterConstVariable("namespace::variable6"));

	Com_RegisterConstList(list);
	out = 0;
	CU_ASSERT_TRUE(Com_GetConstInt("sniper", &out));
	CU_ASSERT_EQUAL(out, 8);

	CU_ASSERT_TRUE(Com_UnregisterConstList(list));
	out = 0;
	CU_ASSERT_FALSE(Com_GetConstInt("sniper", &out));

	Com_RegisterConstList(list2);

	Com_RegisterConstList(list);
	CU_ASSERT_TRUE(Com_UnregisterConstList(list));

	out = 0;
	CU_ASSERT(Com_GetConstInt("pilot", &out));
	CU_ASSERT_EQUAL(out, 3);
	Com_UnregisterConstList(list2);
}
Beispiel #5
0
/**
 * @brief Load callback for savegames
 * @param[in] p XML Node structure, where we get the information from
 * @sa INS_SaveXML
 * @sa SAV_GameLoadXML
 * @sa INS_LoadItemSlots
 */
qboolean INS_LoadXML (xmlNode_t *p)
{
	xmlNode_t *n = XML_GetNode(p, SAVE_INSTALLATION_INSTALLATIONS);
	xmlNode_t *s;
	int i = 0;
	qboolean success = qtrue;

	if (!n)
		return qfalse;

	Com_RegisterConstList(saveInstallationConstants);
	for (s = XML_GetNode(n, SAVE_INSTALLATION_INSTALLATION); s; s = XML_GetNextNode(s,n, SAVE_INSTALLATION_INSTALLATION), i++) {
		xmlNode_t *ss;
		installation_t inst;
		installation_t *instp;
		const char *instID = XML_GetString(s, SAVE_INSTALLATION_TEMPLATEID);
		const char *instStat = XML_GetString(s, SAVE_INSTALLATION_STATUS);

		inst.idx = XML_GetInt(s, SAVE_INSTALLATION_IDX, -1);
		if (inst.idx < 0) {
			/** @todo fallback code for compatibility */
			inst.idx = i;
		}
		inst.installationTemplate = INS_GetInstallationTemplateFromInstallationID(instID);
		if (!inst.installationTemplate) {
			Com_Printf("Could not find installation template '%s'\n", instID);
			success = qfalse;
			break;
		}

		if (!Com_GetConstIntFromNamespace(SAVE_INSTALLATIONSTATUS_NAMESPACE, instStat, (int*) &inst.installationStatus)) {
			Com_Printf("Invalid installation status '%s'\n", instStat);
			success = qfalse;
			break;
		}

		Q_strncpyz(inst.name, XML_GetString(s, SAVE_INSTALLATION_NAME), sizeof(inst.name));
		XML_GetPos3(s, SAVE_INSTALLATION_POS, inst.pos);

		inst.installationDamage = XML_GetInt(s, SAVE_INSTALLATION_DAMAGE, 0);
		inst.alienInterest = XML_GetFloat(s, SAVE_INSTALLATION_ALIENINTEREST, 0.0);
		inst.buildStart = XML_GetInt(s, SAVE_INSTALLATION_BUILDSTART, 0);

		/* Radar */
		RADAR_InitialiseUFOs(&inst.radar);
		RADAR_Initialise(&(inst.radar), 0.0f, 0.0f, 1.0f, qtrue);
		if (inst.installationStatus == INSTALLATION_WORKING) {
			RADAR_UpdateInstallationRadarCoverage(&inst, inst.installationTemplate->radarRange, inst.installationTemplate->trackingRange);
			/* UFO Yard */
			inst.ufoCapacity.max = inst.installationTemplate->maxUFOsStored;
		} else {
			inst.ufoCapacity.max = 0;
		}
		inst.ufoCapacity.cur = 0;

		/* read battery slots */
		ss = XML_GetNode(s, SAVE_INSTALLATION_BATTERIES);
		if (!ss) {
			Com_Printf("INS_LoadXML: Batteries not defined!\n");
			success = qfalse;
			break;
		}
		inst.numBatteries = XML_GetInt(ss, SAVE_INSTALLATION_NUM, 0);
		if (inst.numBatteries > inst.installationTemplate->maxBatteries) {
			Com_Printf("Installation has more batteries than possible, using upper bound\n");
			inst.numBatteries = inst.installationTemplate->maxBatteries;
		}

		instp = (installation_t*)(LIST_Add(&ccs.installations, (void*)&inst, sizeof(inst)))->data;
		BDEF_InitialiseInstallationSlots(instp);
		B_LoadBaseSlotsXML(instp->batteries, instp->numBatteries, ss);
	}
	Com_UnregisterConstList(saveInstallationConstants);
	Cvar_Set("mn_installation_count", va("%i", INS_GetCount()));

	return success;
}