static void CP_UFOCarrierMissionUpdate (mission_t *mission)
{
	/* delay the next update for some time */
	const date_t delay = {2, 0};
	Date_Add(mission->finalDate, delay);

	if (INS_HasType(INSTALLATION_ORBIT)) {
		cgi->UI_PopupButton(_("UFO-Carrier"), _("Attack the UFO-Carrier?"),
			"ui_pop;", _("Cancel"), _("Don't attack the UFO-Carrier"),
			"cp_attack_ufocarrier;ui_pop;", _("Attack"), _("Attack the UFO-Carrier"),
			NULL, NULL, NULL);
	}
}
Example #2
0
/**
 * @brief Fills create installation / installation type selection popup
 */
static void INS_FillTypes_f (void)
{
	cgi->UI_ExecuteConfunc("installationtype_clear");
	if (INS_GetCount() < B_GetInstallationLimit()) {
		for (int i = 0; i < ccs.numInstallationTemplates; i++) {
			const installationTemplate_t* tpl = &ccs.installationTemplates[i];
			if (tpl->once && INS_HasType(tpl->type, INSTALLATION_NOT_USED))
				continue;
			if (tpl->tech == nullptr || RS_IsResearched_ptr(tpl->tech)) {
				cgi->UI_ExecuteConfunc("installationtype_add \"%s\" \"%s\" \"%s\" \"%d c\"", tpl->id, _(tpl->name),
					(tpl->buildTime > 0) ? va("%d %s", tpl->buildTime, ngettext("day", "days", tpl->buildTime)) : "-", tpl->cost);
			}
		}
	}

	/** @todo Move this out from installations code */
	if (B_GetCount() < MAX_BASES)
		cgi->UI_ExecuteConfunc("installationtype_add base \"%s\" - \"%d c\"", _("Base"), ccs.curCampaign->basecost);
}
/**
 * @brief Selects installation type to build
 */
static void INS_SelectType_f (void)
{
	if (cgi->Cmd_Argc() < 2)
		return;

	const char* id = cgi->Cmd_Argv(1);

	if (ccs.mapAction == MA_NEWINSTALLATION) {
		GEO_ResetAction();
		return;
	}

	const installationTemplate_t* tpl = INS_GetInstallationTemplateByID(id);
	if (!tpl) {
		Com_Printf("Invalid installation template\n");
		return;
	}

	if (INS_GetCount() >= B_GetInstallationLimit()) {
		Com_Printf("Maximum number of installations reached\n");
		return;
	}

	if (tpl->tech != nullptr && !RS_IsResearched_ptr(tpl->tech)) {
		Com_Printf("This type of installation is not yet researched\n");
		return;
	}

	if (tpl->once && INS_HasType(tpl->type, INSTALLATION_NOT_USED)) {
		Com_Printf("Cannot build more of this installation\n");
		return;
	}

	ccs.mapAction = MA_NEWINSTALLATION;

	/* show radar overlay (if not already displayed) */
	if (tpl->type == INSTALLATION_RADAR && !GEO_IsRadarOverlayActivated())
		GEO_SetOverlay("radar");

	INS_SetInstallationTitle(tpl->type);
	cgi->Cvar_Set("mn_installation_type", "%s", tpl->id);
}
Example #4
0
static int CP_CheckTriggerEvent (const char *expression, const void* userdata)
{
	const char *type;

	/* check that a particular installation type is built already */
	type = Q_strstart(expression, "installation");
	if (type != 0) {
		if (strlen(type) <= 1)
			return -1;
		char value[MAX_VAR];
		Q_strncpyz(value, type + 1, sizeof(value));
		value[strlen(value) - 1] = '\0';
		const installationType_t insType = INS_GetType(value);
		if (INS_HasType(insType, INSTALLATION_NOT_USED))
			return 1;
		return 0;
	}

	/* check whether a particular ufo was detected */
	type = Q_strstart(expression, "ufo");
	if (type != 0) {
		if (strlen(type) <= 1)
			return -1;
		char value[MAX_VAR];
		Q_strncpyz(value, type + 1, sizeof(value));
		value[strlen(value) - 1] = '\0';
		const char* detectedUFO = static_cast<const char*>(userdata);
		if (Q_strnull(detectedUFO))
			return -1;
		return Q_streq(detectedUFO, value);
	}

	/* check that the given xvi level is reached in any nation */
	type = Q_strstart(expression, "xvi");
	if (type != 0) {
		int xvi;
		if (sscanf(type, "[%i]", &xvi) != 1)
			return -1;
		int i;
		/* check for XVI infection rate */
		for (i = 0; i < ccs.numNations; i++) {
			const nation_t *nation = NAT_GetNationByIDX(i);
			const nationInfo_t *stats = NAT_GetCurrentMonthInfo(nation);
			if (stats->xviInfection >= xvi)
				return 1;
		}
		return 0;
	}

	/* check for nation happiness - also see the lost conditions in the campaign */
	type = Q_strstart(expression, "nationhappiness");
	if (type != 0) {
		int nationAmount;

		if (sscanf(type, "[%i]", &nationAmount) != 1)
			return -1;

		int j, nationBelowLimit = 0;
		for (j = 0; j < ccs.numNations; j++) {
			const nation_t *nation = NAT_GetNationByIDX(j);
			const nationInfo_t *stats = NAT_GetCurrentMonthInfo(nation);
			if (stats->happiness < ccs.curCampaign->minhappiness) {
				nationBelowLimit++;
				if (nationBelowLimit >= nationAmount)
					return 1;
			}
		}
		return 0;
	}

	/* check that the given average xvi level is reached */
	type = Q_strstart(expression, "averagexvi");
	if (type != 0) {
		int xvipercent;
		if (sscanf(type, "[%i]", &xvipercent) != 1)
			return -1;
		if (xvipercent < 0 || xvipercent > 100)
			return -1;
		const int xvi = CP_GetAverageXVIRate();
		if (xvi > ccs.curCampaign->maxAllowedXVIRateUntilLost * xvipercent / 100)
			return 1;
		return 0;
	}

	type = Q_strstart(expression, "difficulty");
	if (type != 0) {
		int difficulty;
		if (sscanf(type, "[%i]", &difficulty) != 1)
			return -1;
		return ccs.curCampaign->difficulty == difficulty;
	}

	/* check that these days have passed in the campaign */
	type = Q_strstart(expression, "days");
	if (type != 0) {
		int days;
		if (sscanf(type, "[%i]", &days) != 1)
			return -1;
		date_t d = ccs.curCampaign->date;
		d.day += days;
		if (Date_IsDue(&d))
			return 1;
		return 0;
	}

	type = Q_strstart(expression, "alienscaptured");
	if (type != 0) {
		if (ccs.campaignStats.capturedAliens > 0)
			return 1;
		return 0;
	}

	type = Q_strstart(expression, "samsitearmed");
	if (type != 0) {
		if (!INS_HasType(INSTALLATION_DEFENCE))
			return 1;

		INS_ForeachOfType(installation, INSTALLATION_DEFENCE) {
			if (installation->installationStatus == INSTALLATION_WORKING) {
				for (int i = 0; i < installation->installationTemplate->maxBatteries; i++) {
					const aircraftSlot_t *slot = &installation->batteries[i].slot;
					if (slot->ammoLeft > 0)
						return 1;
				}
			}
		}

		return 0;
	}

	return -1;
}