/** * @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 Destroys an installation * @param[in,out] installation Pointer to the installation to be destroyed */ void INS_DestroyInstallation (installation_t *installation) { if (!installation) return; /* Disable radar */ RADAR_UpdateInstallationRadarCoverage(installation, 0, 0); /* Destroy stored UFOs */ if (installation->ufoCapacity.max > 0) { installation->ufoCapacity.max = 0; US_RemoveUFOsExceedingCapacity(installation); } CP_MissionNotifyInstallationDestroyed(installation); Com_sprintf(cp_messageBuffer, sizeof(cp_messageBuffer), _("Installation %s was destroyed."), installation->name); MSO_CheckAddNewMessage(NT_INSTALLATION_DESTROY, _("Installation destroyed"), cp_messageBuffer, qfalse, MSG_CONSTRUCTION, NULL); LIST_Remove(&ccs.installations, installation); Cvar_Set("mn_installation_count", va("%i", INS_GetCount())); }
/** * @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); }
/** * @brief Load callback for savegames * @param[in] p XML Node structure, where we get the information from * @sa INS_SaveXML * @sa SAV_GameLoadXML * @sa INS_LoadItemSlots */ qboolean INS_LoadXML (xmlNode_t *p) { xmlNode_t *n = XML_GetNode(p, SAVE_INSTALLATION_INSTALLATIONS); xmlNode_t *s; int i = 0; qboolean success = qtrue; if (!n) return qfalse; Com_RegisterConstList(saveInstallationConstants); for (s = XML_GetNode(n, SAVE_INSTALLATION_INSTALLATION); s; s = XML_GetNextNode(s,n, SAVE_INSTALLATION_INSTALLATION), i++) { xmlNode_t *ss; installation_t inst; installation_t *instp; const char *instID = XML_GetString(s, SAVE_INSTALLATION_TEMPLATEID); const char *instStat = XML_GetString(s, SAVE_INSTALLATION_STATUS); inst.idx = XML_GetInt(s, SAVE_INSTALLATION_IDX, -1); if (inst.idx < 0) { /** @todo fallback code for compatibility */ inst.idx = i; } inst.installationTemplate = INS_GetInstallationTemplateFromInstallationID(instID); if (!inst.installationTemplate) { Com_Printf("Could not find installation template '%s'\n", instID); success = qfalse; break; } if (!Com_GetConstIntFromNamespace(SAVE_INSTALLATIONSTATUS_NAMESPACE, instStat, (int*) &inst.installationStatus)) { Com_Printf("Invalid installation status '%s'\n", instStat); success = qfalse; break; } Q_strncpyz(inst.name, XML_GetString(s, SAVE_INSTALLATION_NAME), sizeof(inst.name)); XML_GetPos3(s, SAVE_INSTALLATION_POS, inst.pos); inst.installationDamage = XML_GetInt(s, SAVE_INSTALLATION_DAMAGE, 0); inst.alienInterest = XML_GetFloat(s, SAVE_INSTALLATION_ALIENINTEREST, 0.0); inst.buildStart = XML_GetInt(s, SAVE_INSTALLATION_BUILDSTART, 0); /* Radar */ RADAR_InitialiseUFOs(&inst.radar); RADAR_Initialise(&(inst.radar), 0.0f, 0.0f, 1.0f, qtrue); if (inst.installationStatus == INSTALLATION_WORKING) { RADAR_UpdateInstallationRadarCoverage(&inst, inst.installationTemplate->radarRange, inst.installationTemplate->trackingRange); /* UFO Yard */ inst.ufoCapacity.max = inst.installationTemplate->maxUFOsStored; } else { inst.ufoCapacity.max = 0; } inst.ufoCapacity.cur = 0; /* read battery slots */ ss = XML_GetNode(s, SAVE_INSTALLATION_BATTERIES); if (!ss) { Com_Printf("INS_LoadXML: Batteries not defined!\n"); success = qfalse; break; } inst.numBatteries = XML_GetInt(ss, SAVE_INSTALLATION_NUM, 0); if (inst.numBatteries > inst.installationTemplate->maxBatteries) { Com_Printf("Installation has more batteries than possible, using upper bound\n"); inst.numBatteries = inst.installationTemplate->maxBatteries; } instp = (installation_t*)(LIST_Add(&ccs.installations, (void*)&inst, sizeof(inst)))->data; BDEF_InitialiseInstallationSlots(instp); B_LoadBaseSlotsXML(instp->batteries, instp->numBatteries, ss); } Com_UnregisterConstList(saveInstallationConstants); Cvar_Set("mn_installation_count", va("%i", INS_GetCount())); return success; }