/** * @brief Returns if a building is fully buildt up * @param[in] building Pointer to the building to check * @note it always return @c true for buildings with {0, 0} timeStart */ bool B_IsBuildingBuiltUp (const building_t* building) { if (!building) return false; if (building->timeStart.day == 0 && building->timeStart.sec == 0) return true; date_t due = building->timeStart; due.day += building->buildTime; return Date_IsDue(&due); }
/** * @brief Returns if a building is fully buildt up * @param[in] building Pointer to the building to check * @note it always return @c true for buildings with {0, 0} timeStart */ qboolean B_IsBuildingBuiltUp (const building_t *building) { date_t due; if (!building) return qfalse; if (building->timeStart.day == 0 && building->timeStart.sec == 0) return qtrue; due = building->timeStart; due.day += building->buildTime; if (Date_IsDue(&due)) return qtrue; return qfalse; }
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; }