/**
 * @brief Update the building-list.
 * @sa B_BuildingInit_f
 */
static void B_BuildingInit (base_t* base)
{
	int i;
	linkedList_t *buildingList = NULL;

	/* maybe someone call this command before the bases are parsed?? */
	if (!base)
		return;

	for (i = 0; i < ccs.numBuildingTemplates; i++) {
		building_t *tpl = &ccs.buildingTemplates[i];
		/* make an entry in list for this building */

		if (tpl->mapPart) {
			const int numSameBuildings = B_GetNumberOfBuildingsInBaseByTemplate(base, tpl);

			if (tpl->maxCount >= 0 && tpl->maxCount <= numSameBuildings)
				continue;
			/* skip if limit of BASE_SIZE*BASE_SIZE exceeded */
			if (numSameBuildings >= BASE_SIZE * BASE_SIZE)
				continue;

			/* if the building is researched add it to the list */
			if (RS_IsResearched_ptr(tpl->tech))
				B_BuildingAddToList(&buildingList, tpl);
		}
	}
	if (base->buildingCurrent)
		B_DrawBuilding(base->buildingCurrent);
	else
		cgi->UI_ExecuteConfunc("mn_buildings_reset");

	buildingNumber = LIST_Count(buildingList);
	cgi->UI_RegisterLinkedListText(TEXT_BUILDINGS, buildingList);
}
/**
 * @brief Script function for clicking the building list text field.
 */
static void B_BuildingClick_f (void)
{
	building_t *building;
	base_t *base = B_GetCurrentSelectedBase();

	if (!base)
		return;

	if (cgi->Cmd_Argc() < 2) {
		Com_Printf("Usage: %s <building_id|building list index>\n", cgi->Cmd_Argv(0));
		return;
	}

	/* which building? */
	building = B_GetBuildingTemplateSilent(cgi->Cmd_Argv(1));
	if (!building) {
		int num = atoi(cgi->Cmd_Argv(1));
		if (num > buildingNumber || num < 0) {
			Com_DPrintf(DEBUG_CLIENT, "B_BuildingClick_f: max exceeded %i/%i\n", num, buildingNumber);
			return;
		}
		building = buildingConstructionList[num];
	}

	base->buildingCurrent = building;
	B_DrawBuilding(building);

	ccs.baseAction = BA_NEWBUILDING;
}
Beispiel #3
0
/**
 * @brief Middle click on the basemap
 * @sa UI_BaseMapNodeClick
 * @param[in] node Node definition for the base map
 * @param[in] x The x screen coordinate
 * @param[in] y The y screen coordinate
 * @note relies on @c baseCurrent
 */
static void UI_BaseMapNodeMiddleClick (uiNode_t *node, int x, int y)
{
	int row, col;
	const base_t *base = B_GetCurrentSelectedBase();
	const building_t *entry;
	if (base == NULL)
		return;

	assert(node);
	assert(node->root);

	UI_BaseMapGetCellAtPos(node, x, y, &col, &row);
	if (col == -1)
		return;

	entry = base->map[row][col].building;
	if (entry) {
		assert(!B_IsTileBlocked(base, col, row));
		B_DrawBuilding(entry);
	}
}