/** * @brief Fills the UI with ufo yard data */ static void INS_FillUFOYardData_f (void) { installation_t *ins; cgi->UI_ExecuteConfunc("ufolist_clear"); if (cgi->Cmd_Argc() < 2 || atoi(cgi->Cmd_Argv(1)) < 0) { ins = INS_GetCurrentSelectedInstallation(); if (!ins || ins->installationTemplate->type != INSTALLATION_UFOYARD) ins = INS_GetFirstUFOYard(false); } else { ins = INS_GetByIDX(atoi(cgi->Cmd_Argv(1))); if (!ins) Com_DPrintf(DEBUG_CLIENT, "Installation not founded (idx %i)\n", atoi(cgi->Cmd_Argv(1))); } if (ins) { const nation_t *nat = MAP_GetNation(ins->pos); const int timeToBuild = std::max(0, ins->installationTemplate->buildTime - (ccs.date.day - ins->buildStart)); const char *buildTime = (timeToBuild > 0 && ins->installationStatus == INSTALLATION_UNDER_CONSTRUCTION) ? va(ngettext("%d day", "%d days", timeToBuild), timeToBuild) : "-"; const int freeCap = std::max(0, ins->ufoCapacity.max - ins->ufoCapacity.cur); const char *nationName = nat ? _(nat->name) : ""; cgi->UI_ExecuteConfunc("ufolist_addufoyard %d \"%s\" \"%s\" %d %d \"%s\"", ins->idx, ins->name, nationName, ins->ufoCapacity.max, freeCap, buildTime); US_Foreach(ufo) { if (ufo->installation != ins) continue; const char *ufoName = UFO_AircraftToIDOnGeoscape(ufo->ufoTemplate); const char *condition = va(_("Condition: %3.0f%%"), ufo->condition * 100); const char *status = US_StoredUFOStatus(ufo); cgi->UI_ExecuteConfunc("ufolist_addufo %d \"%s\" \"%s\" \"%s\" \"%s\"", ufo->idx, ufoName, condition, ufo->ufoTemplate->model, status); } } }
static void SCP_CampaignAddMission (setState_t *set) { actMis_t *mis; mission_t * mission; const nation_t *nation; /* add mission */ if (scd->numActiveMissions >= MAX_ACTMISSIONS) { return; } mis = &scd->activeMissions[scd->numActiveMissions]; OBJZERO(*mis); /* set relevant info */ mis->def = SCP_GetMission(set); if (mis->def == NULL) { return; } mis->cause = set; if (set->def->expire.day) mis->expire = Date_Add(ccs.date, set->def->expire); /* prepare next event (if any) */ set->num++; if (set->def->number && set->num >= set->def->number) { set->active = false; } else { const date_t minTime = {0, 0}; set->event = Date_Add(ccs.date, Date_Random(minTime, set->def->frame)); } mission = CP_CreateNewMission(INTERESTCATEGORY_TERROR_ATTACK, true); mission->mapDef = cgi->Com_GetMapDefinitionByID(mis->def->id); if (!mission->mapDef) { Com_Printf("SCP_CampaignAddMission: Could not get the mapdef '%s'\n", mis->def->id); CP_MissionRemove(mission); return; } Vector2Copy(mis->def->pos, mission->pos); mission->posAssigned = true; nation = MAP_GetNation(mission->pos); if (nation) { Com_sprintf(mission->location, sizeof(mission->location), "%s", _(nation->name)); } else { Com_sprintf(mission->location, sizeof(mission->location), "%s", _("No nation")); } CP_TerrorMissionStart(mission); mission->finalDate = mis->expire; mis->mission = mission; Com_Printf("spawned map '%s'\n", mis->def->id); scd->numActiveMissions++; }
/** * @brief Set ground mission, and go to ground mission pos. * @note Recon mission -- Stage 1 * @note ground mission can be spawned without UFO * @sa CP_ReconMissionSelect */ void CP_ReconMissionGroundGo (mission_t *mission) { const nation_t *nation; mission->stage = STAGE_MISSION_GOTO; /* maybe the UFO just finished a ground mission and starts a new one? */ if (mission->ufo) { CP_MissionRemoveFromGeoscape(mission); mission->ufo->landed = false; } /* Choose a map */ if (CP_ChooseMap(mission, NULL)) { int counter; for (counter = 0; counter < MAX_POS_LOOP; counter++) { if (!CP_GetRandomPosOnGeoscapeWithParameters(mission->pos, mission->mapDef->terrains, mission->mapDef->cultures, mission->mapDef->populations, NULL)) continue; if (MAP_PositionCloseToBase(mission->pos)) continue; mission->posAssigned = true; break; } if (counter >= MAX_POS_LOOP) { Com_Printf("CP_ReconMissionGroundGo: Error, could not set position.\n"); CP_MissionRemove(mission); return; } } else { Com_Printf("CP_ReconMissionGroundGo: No map found, remove mission.\n"); CP_MissionRemove(mission); return; } nation = MAP_GetNation(mission->pos); if (nation) { Com_sprintf(mission->location, sizeof(mission->location), "%s", _(nation->name)); } else { Com_sprintf(mission->location, sizeof(mission->location), "%s", _("No nation")); } if (mission->ufo) { CP_MissionDisableTimeLimit(mission); UFO_SendToDestination(mission->ufo, mission->pos); } else { /* Go to next stage on next frame */ mission->finalDate = ccs.date; } }
/** * @brief Constructs a new installation. */ static void INS_BuildInstallation_f (void) { const installationTemplate_t *installationTemplate; if (cgi->Cmd_Argc() < 1) { Com_Printf("Usage: %s <installationType>\n", cgi->Cmd_Argv(0)); return; } /* We shouldn't build more installations than the actual limit */ if (B_GetInstallationLimit() <= INS_GetCount()) return; installationTemplate = INS_GetInstallationTemplateByID(cgi->Cmd_Argv(1)); if (!installationTemplate) { Com_Printf("The installation type %s passed for %s is not valid.\n", cgi->Cmd_Argv(1), cgi->Cmd_Argv(0)); return; } assert(installationTemplate->cost >= 0); if (ccs.credits - installationTemplate->cost > 0) { /* set up the installation */ installation_t *installation = INS_Build(installationTemplate, ccs.newBasePos, cgi->Cvar_GetString("mn_installation_title")); CP_UpdateCredits(ccs.credits - installationTemplate->cost); /* this cvar is used for disabling the installation build button on geoscape if MAX_INSTALLATIONS was reached */ cgi->Cvar_SetValue("mn_installation_count", INS_GetCount()); const nation_t *nation = MAP_GetNation(installation->pos); if (nation) Com_sprintf(cp_messageBuffer, sizeof(cp_messageBuffer), _("A new installation has been built: %s (nation: %s)"), installation->name, _(nation->name)); else Com_sprintf(cp_messageBuffer, sizeof(cp_messageBuffer), _("A new installation has been built: %s"), installation->name); MSO_CheckAddNewMessage(NT_INSTALLATION_BUILDSTART, _("Installation building"), cp_messageBuffer, MSG_CONSTRUCTION); } else { if (installationTemplate->type == INSTALLATION_RADAR) { if (MAP_IsRadarOverlayActivated()) MAP_SetOverlay("radar"); } if (ccs.mapAction == MA_NEWINSTALLATION) ccs.mapAction = MA_NONE; CP_Popup(_("Notice"), _("Not enough credits to set up a new installation.")); } ccs.mapAction = MA_NONE; }
/** * @brief Set Harvest mission, and go to mission pos. * @note Harvesting attack mission -- Stage 1 * @todo Remove me when CP_XVIMissionGo will be implemented * This function should take a location close to an XVI infection point * see gameplay proposal on wiki */ void CP_HarvestMissionGo (mission_t *mission) { const nation_t *nation; mission->stage = STAGE_MISSION_GOTO; /* Choose a map */ if (CP_ChooseMap(mission, NULL)) { int counter; linkedList_t *nationList = NULL; const qboolean nationTest = CP_ChooseNation(mission, &nationList); for (counter = 0; counter < MAX_POS_LOOP; counter++) { if (!CP_GetRandomPosOnGeoscapeWithParameters(mission->pos, mission->mapDef->terrains, mission->mapDef->cultures, mission->mapDef->populations, nationTest ? nationList : NULL)) continue; if (MAP_PositionCloseToBase(mission->pos)) continue; mission->posAssigned = qtrue; break; } if (counter >= MAX_POS_LOOP) { Com_Printf("CP_HarvestMissionGo: Error, could not set position.\n"); CP_MissionRemove(mission); return; } LIST_Delete(&nationList); } else { Com_Printf("CP_HarvestMissionGo: No map found, remove mission.\n"); CP_MissionRemove(mission); return; } nation = MAP_GetNation(mission->pos); if (nation) { Com_sprintf(mission->location, sizeof(mission->location), "%s", _(nation->name)); } else { Com_sprintf(mission->location, sizeof(mission->location), "%s", _("No nation")); } if (mission->ufo) { CP_MissionDisableTimeLimit(mission); UFO_SendToDestination(mission->ufo, mission->pos); } else { /* Go to next stage on next frame */ mission->finalDate = ccs.date; } }
/** * @brief Constructs a new base. * @sa B_NewBase */ static void B_BuildBase_f (void) { const nation_t *nation; const campaign_t *campaign = ccs.curCampaign; if (ccs.mapAction == MA_NEWBASE) ccs.mapAction = MA_NONE; if (ccs.credits - campaign->basecost > 0) { const char *baseName = mn_base_title->string; base_t *base; /* there may be no " in the base name */ if (!Com_IsValidName(baseName)) baseName = _("Base"); base = B_Build(campaign, ccs.newBasePos, baseName); if (!base) cgi->Com_Error(ERR_DROP, "Cannot build base"); CP_UpdateCredits(ccs.credits - campaign->basecost); nation = MAP_GetNation(base->pos); if (nation) Com_sprintf(cp_messageBuffer, sizeof(cp_messageBuffer), _("A new base has been built: %s (nation: %s)"), mn_base_title->string, _(nation->name)); else Com_sprintf(cp_messageBuffer, sizeof(cp_messageBuffer), _("A new base has been built: %s"), mn_base_title->string); MS_AddNewMessage(_("Base built"), cp_messageBuffer, MSG_CONSTRUCTION); /* First base */ if (ccs.campaignStats.basesBuilt == 1) B_SetUpFirstBase(campaign, base); cgi->Cvar_SetValue("mn_base_count", B_GetCount()); B_SelectBase(base); } else { if (MAP_IsRadarOverlayActivated()) MAP_SetOverlay("radar"); CP_PopupList(_("Notice"), _("Not enough credits to set up a new base.")); } }
/** * @brief Subverting Mission ends: UFO leave earth. * @note Build Base mission -- Stage 3 */ static void CP_BuildBaseGovernmentLeave (const campaign_t *campaign, mission_t *mission) { nation_t *nation; assert(mission); assert(mission->ufo); mission->stage = STAGE_RETURN_TO_ORBIT; /* Mission is a success: government is subverted => lower happiness */ nation = MAP_GetNation(mission->pos); /** @todo when the mission is created, we should select a position where nation exists, * otherwise subverting a government is meaningless */ if (nation) { const nationInfo_t *stats = NAT_GetCurrentMonthInfo(nation); NAT_SetHappiness(campaign->minhappiness, nation, stats->happiness + HAPPINESS_SUBVERSION_LOSS); } CP_MissionDisableTimeLimit(mission); UFO_SetRandomDest(mission->ufo); /* Display UFO on geoscape if it is detected */ mission->ufo->landed = false; }
/** * @brief Changes nation happiness by given value. * @note There must be argument passed to this function being converted to float. */ static void CP_ChangeNationHappiness_f (void) { float change; nation_t *nation; const nationInfo_t *stats; const mission_t *mission = MAP_GetSelectedMission(); if (Cmd_Argc() < 2) { Com_Printf("Usage: %s <absolute change value>\n", Cmd_Argv(0)); return; } change = atof(Cmd_Argv(1)); if (!mission) { Com_Printf("No mission selected - could not determine nation to use\n"); return; } nation = MAP_GetNation(mission->pos); assert(nation); stats = NAT_GetCurrentMonthInfo(nation); NAT_SetHappiness(ccs.curCampaign->minhappiness, nation, stats->happiness + change); }