Esempio n. 1
0
/**
 * @brief Adds a defence system to base.
 */
static void BDEF_AddBattery_f (void)
{
	basedefenceType_t basedefType;
	base_t* base;
	const char* type;

	if (cgi->Cmd_Argc() < 3) {
		Com_Printf("Usage: %s <basedefType> <baseIdx>", cgi->Cmd_Argv(0));
		return;
	}

	type = cgi->Cmd_Argv(1);
	if (Q_streq(type, "missile"))
		basedefType = BASEDEF_MISSILE;
	else if (Q_streq(type, "laser"))
		basedefType = BASEDEF_LASER;
	else if (Q_streq(type, "random"))
		basedefType = BASEDEF_RANDOM;
	else {
		Com_Printf("BDEF_AddBattery_f: base defence type %s doesn't exist.\n", type);
		return;
	}

	base = B_GetBaseByIDX(atoi(cgi->Cmd_Argv(2)));
	if (base == nullptr) {
		Com_Printf("BDEF_AddBattery_f: Invalid base index given\n");
		return;
	}

	BDEF_AddBattery(basedefType, base);
}
Esempio n. 2
0
/**
 * @brief Updates the active defences counter
 */
static void BDEF_UpdateActiveBattery_f (void)
{
	base_t* base;
	const char* type;
	int count;

	if (cgi->Cmd_Argc() < 3) {
		Com_Printf("Usage: %s <basedefType> <baseIdx>", cgi->Cmd_Argv(0));
		return;
	}

	base = B_GetBaseByIDX(atoi(cgi->Cmd_Argv(2)));
	if (base == nullptr) {
		Com_Printf("BDEF_UpdateActiveBattery_f: Invalid base index given\n");
		return;
	}

	type = cgi->Cmd_Argv(1);
	if (Q_streq(type, "missile")) {
		B_CheckBuildingTypeStatus(base, B_DEFENCE_MISSILE, B_STATUS_WORKING, &count);
		base->numActiveBatteries = std::min(count, base->numBatteries);
	} else if (Q_streq(type, "laser")) {
		B_CheckBuildingTypeStatus(base, B_DEFENCE_LASER, B_STATUS_WORKING, &count);
		base->numActiveLasers = std::min(count, base->numLasers);
	} else {
		Com_Printf("BDEF_UpdateActiveBattery_f: base defence type %s doesn't exist.\n", type);
		return;
	}
}
/**
 * @brief Destroy a base building
 * @sa B_MarkBuildingDestroy
 * @sa B_BuildingDestroy
 */
static void B_BuildingDestroy_f (void)
{
	base_t *base;
	building_t *building;

	if (cgi->Cmd_Argc() < 3) {
		Com_DPrintf(DEBUG_CLIENT, "Usage: %s <baseID> <buildingID> [confirmed]\n", cgi->Cmd_Argv(0));
		return;
	} else {
		const int baseID = atoi(cgi->Cmd_Argv(1));
		const int buildingID = atoi(cgi->Cmd_Argv(2));
		base = B_GetBaseByIDX(baseID);
		assert(base);
		building = &ccs.buildings[baseID][buildingID];
	}

	if (!base || !building)
		return;

	if (cgi->Cmd_Argc() == 4 && Q_streq(cgi->Cmd_Argv(3), "confirmed")) {
		/** @todo why not use the local building pointer here - we should
		 * reduce the access to these 'current' pointers */
		B_BuildingDestroy(base->buildingCurrent);

		B_ResetBuildingCurrent(base);
		B_BuildingInit(base);
	} else {
		B_MarkBuildingDestroy(building);
	}
}
Esempio n. 4
0
/**
 * @brief For things like craft_ufo_scout that are no real items this function will
 * increase the collected counter by one
 * @note Mission trigger function
 * @sa CP_MissionTriggerFunctions
 * @sa CP_ExecuteMissionTrigger
 */
static void CP_AddItemAsCollected_f (void)
{
	int baseID;
	const char* id;
	base_t *base;
	const objDef_t *item;

	if (Cmd_Argc() < 2) {
		Com_Printf("Usage: %s <item>\n", Cmd_Argv(0));
		return;
	}

	id = Cmd_Argv(1);
	baseID = atoi(Cmd_Argv(2));
	base = B_GetBaseByIDX(baseID);
	if (base == NULL)
		return;

	/* i = item index */
	item = INVSH_GetItemByIDSilent(id);
	if (item) {
		technology_t *tech = RS_GetTechForItem(item);
		base->storage.numItems[item->idx]++;
		Com_DPrintf(DEBUG_CLIENT, "add item: '%s'\n", item->id);
		RS_MarkCollected(tech);
	}
}
/**
 * @brief Builds a base map for tactical combat.
 * @sa SV_AssembleMap
 * @sa CP_BaseAttackChooseBase
 */
static void B_AssembleMap_f (void)
{
	const base_t* base;

	if (cgi->Cmd_Argc() < 2) {
		Com_DPrintf(DEBUG_CLIENT, "Usage: %s <baseID>\n", cgi->Cmd_Argv(0));
		base = B_GetCurrentSelectedBase();
	} else {
		const int baseID = atoi(cgi->Cmd_Argv(1));
		base = B_GetBaseByIDX(baseID);
	}

	B_AssembleMap(base);
}
Esempio n. 6
0
/**
 * @brief Load callback for savin in XML Format
 * @sa AC_LoadXML
 * @sa B_SaveXML
 * @sa SAV_GameLoadXML
 */
qboolean AC_LoadXML (mxml_node_t * parent)
{
	mxml_node_t *aliencont;
	mxml_node_t *contNode;
	int i;

	aliencont = mxml_GetNode(parent, SAVE_ALIENCONT_ALIENCONT);
	ccs.breathingMailSent = mxml_GetBool(aliencont, SAVE_ALIENCONT_BREATHINGMAILSENT, qfalse);

	/* Init alienContainers */
	for (i = 0; i < MAX_BASES; i++) {
		base_t *base = B_GetBaseByIDX(i);

		AL_FillInContainment(base);
	}
	/* Load data */
	for (contNode = mxml_GetNode(aliencont, SAVE_ALIENCONT_CONT); contNode;
			contNode = mxml_GetNextNode(contNode, aliencont, SAVE_ALIENCONT_CONT)) {
		int j = mxml_GetInt(contNode, SAVE_ALIENCONT_BASEIDX, MAX_BASES);
		base_t *base = B_GetFoundedBaseByIDX(j);
		int k;
		mxml_node_t *alienNode;

		if (!base) {
			Com_Printf("AC_LoadXML: Invalid base idx '%i'\n", j);
			continue;
		}

		for (k = 0, alienNode = mxml_GetNode(contNode, SAVE_ALIENCONT_ALIEN); alienNode && k < MAX_ALIENCONT_CAP; alienNode = mxml_GetNextNode(alienNode, contNode, SAVE_ALIENCONT_ALIEN), k++) {
			const char *const s = mxml_GetString(alienNode, SAVE_ALIENCONT_TEAMID);
			/* Fill Alien Containment with default values like the tech pointer. */
			base->alienscont[k].teamDef = Com_GetTeamDefinitionByID(s);
			if (base->alienscont[k].teamDef) {
				base->alienscont[k].amountAlive = mxml_GetInt(alienNode, SAVE_ALIENCONT_AMOUNTALIVE, 0);
				base->alienscont[k].amountDead = mxml_GetInt(alienNode, SAVE_ALIENCONT_AMOUNTDEAD, 0);
			}
		}
	}

	return qtrue;
}
Esempio n. 7
0
/**
 * @brief Draw a small square with the layout of the given base
 */
static void UI_BaseLayoutNodeDraw (uiNode_t * node)
{
	base_t *base;
	int height, width, y;
	int row, col;
	const vec4_t c_gray = {0.5, 0.5, 0.5, 1.0};
	vec2_t nodepos;
	int totalMarge;

	if (EXTRADATA(node).baseid >= MAX_BASES || EXTRADATA(node).baseid < 0)
		return;

	totalMarge = node->padding * (BASE_SIZE + 1);
	width = (node->size[0] - totalMarge) / BASE_SIZE;
	height = (node->size[1] - totalMarge) / BASE_SIZE;

	UI_GetNodeAbsPos(node, nodepos);

	base = B_GetBaseByIDX(EXTRADATA(node).baseid);

	y = nodepos[1] + node->padding;
	for (row = 0; row < BASE_SIZE; row++) {
		int x = nodepos[0] + node->padding;
		for (col = 0; col < BASE_SIZE; col++) {
			if (B_IsTileBlocked(base, col, row)) {
				UI_DrawFill(x, y, width, height, c_gray);
			} else if (B_GetBuildingAt(base, col, row) != NULL) {
				/* maybe destroyed in the meantime */
				if (base->founded)
					UI_DrawFill(x, y, width, height, node->color);
			}
			x += width + node->padding;
		}
		y += height + node->padding;
	}
}
Esempio n. 8
0
/**
 * @brief Load callback for xml savegames
 * @param[in] p XML Node structure, where we get the information from
 * @sa PR_SaveXML
 * @sa SAV_GameLoadXML
 */
bool PR_LoadXML (xmlNode_t* p)
{
	xmlNode_t* node = cgi->XML_GetNode(p, SAVE_PRODUCE_PRODUCTION);

	for (xmlNode_t* snode = cgi->XML_GetNode(node, SAVE_PRODUCE_QUEUE); snode;
			snode = cgi->XML_GetNextNode(snode, node, SAVE_PRODUCE_QUEUE)) {
		xmlNode_t* ssnode;
		const int baseIDX = cgi->XML_GetInt(snode, SAVE_PRODUCE_QUEUEIDX, MAX_BASES);
		base_t* base = B_GetBaseByIDX(baseIDX);
		production_queue_t* pq;

		if (base == nullptr) {
			Com_Printf("Invalid production queue index %i\n", baseIDX);
			continue;
		}

		pq = PR_GetProductionForBase(base);

		for (ssnode = cgi->XML_GetNode(snode, SAVE_PRODUCE_ITEM); pq->numItems < MAX_PRODUCTIONS && ssnode;
				ssnode = cgi->XML_GetNextNode(ssnode, snode, SAVE_PRODUCE_ITEM)) {
			const char* s1 = cgi->XML_GetString(ssnode, SAVE_PRODUCE_ITEMID);
			production_t* prod = &pq->items[pq->numItems];

			prod->idx = pq->numItems;
			prod->amount = cgi->XML_GetInt(ssnode, SAVE_PRODUCE_AMOUNT, 0);
			prod->frame = cgi->XML_GetInt(ssnode, SAVE_PRODUCE_PROGRESS, 0);

			/* amount */
			if (prod->amount <= 0) {
				Com_Printf("PR_LoadXML: Production with amount <= 0 dropped (baseidx=%i, production idx=%i).\n",
						baseIDX, pq->numItems);
				continue;
			}
			/* item */
			if (s1[0] != '\0')
				PR_SetData(&prod->data, PRODUCTION_TYPE_ITEM, INVSH_GetItemByID(s1));
			/* UFO */
			const int ufoIDX = cgi->XML_GetInt(ssnode, SAVE_PRODUCE_UFOIDX, -1);
			if (ufoIDX != -1) {
				storedUFO_t* ufo = US_GetStoredUFOByIDX(ufoIDX);

				if (!ufo) {
					Com_Printf("PR_LoadXML: Could not find ufo idx: %i\n", ufoIDX);
					continue;
				}

				PR_SetData(&prod->data, PRODUCTION_TYPE_DISASSEMBLY, ufo);
				PR_SetUFODisassembly(prod);
			}
			/* aircraft */
			const char* s2 = cgi->XML_GetString(ssnode, SAVE_PRODUCE_AIRCRAFTID);
			if (s2[0] != '\0')
				PR_SetData(&prod->data, PRODUCTION_TYPE_AIRCRAFT, AIR_GetAircraft(s2));

			if (!PR_IsDataValid(&prod->data)) {
				Com_Printf("PR_LoadXML: Production is not an item an aircraft nor a disassembly\n");
				continue;
			}

			pq->numItems++;
		}
	}
	return true;
}
Esempio n. 9
0
/**
 * @brief Called after the end of the node load from script (all data and/or child are set)
 */
static void UI_AbstractBaseNodeLoaded (uiNode_t * node)
{
	const int id = EXTRADATA(node).baseid;
	if (B_GetBaseByIDX(id) == NULL)
		Com_Printf("UI_AbstractBaseNodeLoaded: Invalid baseid given %i", id);
}