/** * @brief Destroys a stored UFO * @note it's called by 'ui_destroystoredufo' command with a parameter of the stored UFO IDX and a confirmation value */ static void US_DestroySoredUFO_f (void) { if (cgi->Cmd_Argc() < 2) { Com_DPrintf(DEBUG_CLIENT, "Usage: %s <idx> [0|1]\nWhere the second, optional parameter is the confirmation.\n", cgi->Cmd_Argv(0)); return; } storedUFO_t *ufo = US_GetStoredUFOByIDX(atoi(cgi->Cmd_Argv(1))); if (!ufo) { Com_DPrintf(DEBUG_CLIENT, "Stored UFO with idx: %i does not exist\n", atoi(cgi->Cmd_Argv(1))); return; } /* Ask 'Are you sure?' by default */ if (cgi->Cmd_Argc() < 3 || !atoi(cgi->Cmd_Argv(2))) { char command[128]; Com_sprintf(command, sizeof(command), "ui_pop; ui_destroystoredufo %d 1; mn_installation_select %d;", ufo->idx, ufo->installation->idx); cgi->UI_PopupButton(_("Destroy stored UFO"), _("Do you really want to destroy this stored UFO?"), command, _("Destroy"), _("Destroy stored UFO"), "ui_pop;", _("Cancel"), _("Forget it"), nullptr, nullptr, nullptr); return; } US_RemoveStoredUFO(ufo); cgi->Cmd_ExecuteString(va("mn_installation_select %d", ufo->installation->idx)); }
/** * @brief Callback to start the transfer of a stored UFO */ static void US_TransferUFO_f (void) { storedUFO_t *ufo; installation_t *ins = nullptr; if (cgi->Cmd_Argc() < 3) { Com_Printf("Usage: %s <stored-ufo-idx> <ufoyard-idx>\n", cgi->Cmd_Argv(0)); return; } ufo = US_GetStoredUFOByIDX(atoi(cgi->Cmd_Argv(1))); if (ufo == nullptr) { Com_Printf("Stored ufo with idx %i not found.\n", atoi(cgi->Cmd_Argv(1))); return; } ins = INS_GetByIDX(atoi(cgi->Cmd_Argv(2))); if (!ins) { Com_Printf("Installation with idx: %i does not exist\n", atoi(cgi->Cmd_Argv(2))); return; } US_TransferUFO(ufo, ins); }
/** * @brief Send Stored UFO data to the UI * @note it's called by 'ui_selectstoredufo' command with a parameter of the stored UFO IDX */ static void US_SelectStoredUfo_f (void) { const storedUFO_t *ufo; if (cgi->Cmd_Argc() < 2 || (ufo = US_GetStoredUFOByIDX(atoi(cgi->Cmd_Argv(1)))) == nullptr) { cgi->UI_ExecuteConfunc("show_storedufo -"); return; } const char *ufoName = UFO_GetName(ufo->ufoTemplate); const char *status = US_StoredUFOStatus(ufo); const char *eta; if (Q_streq(status, "transfering")) { date_t time = Date_Substract(ufo->arrive, ccs.date); eta = CP_SecondConvert(Date_DateToSeconds(&time)); } else { eta = "-"; } cgi->UI_ExecuteConfunc("show_storedufo %d \"%s\" %3.0f \"%s\" \"%s\" \"%s\" \"%s\"", ufo->idx, ufoName, ufo->condition * 100, ufo->ufoTemplate->model, status, eta, ufo->installation->name); }
/** * @brief Fills UFO Yard UI with transfer destinations */ static void US_FillUFOTransfer_f (void) { if (cgi->Cmd_Argc() < 2) { Com_DPrintf(DEBUG_CLIENT, "Usage: %s <idx>\n", cgi->Cmd_Argv(0)); return; } storedUFO_t *ufo = US_GetStoredUFOByIDX(atoi(cgi->Cmd_Argv(1))); if (!ufo) { Com_DPrintf(DEBUG_CLIENT, "Stored UFO with idx: %i does not exist\n", atoi(cgi->Cmd_Argv(1))); return; } cgi->UI_ExecuteConfunc("ufotransferlist_clear"); INS_ForeachOfType(ins, INSTALLATION_UFOYARD) { if (ins == ufo->installation) continue; nation_t *nat = GEO_GetNation(ins->pos); const char *nationName = nat ? _(nat->name) : ""; const int freeSpace = std::max(0, ins->ufoCapacity.max - ins->ufoCapacity.cur); cgi->UI_ExecuteConfunc("ufotransferlist_addyard %d \"%s\" \"%s\" %d %d", ins->idx, ins->name, nationName, freeSpace, ins->ufoCapacity.max); } }
/** * @brief Load callback for xml savegames * @param[in] p XML Node structure, where we get the information from * @sa PR_SaveXML * @sa SAV_GameLoadXML */ bool PR_LoadXML (xmlNode_t* p) { xmlNode_t* node = cgi->XML_GetNode(p, SAVE_PRODUCE_PRODUCTION); for (xmlNode_t* snode = cgi->XML_GetNode(node, SAVE_PRODUCE_QUEUE); snode; snode = cgi->XML_GetNextNode(snode, node, SAVE_PRODUCE_QUEUE)) { xmlNode_t* ssnode; const int baseIDX = cgi->XML_GetInt(snode, SAVE_PRODUCE_QUEUEIDX, MAX_BASES); base_t* base = B_GetBaseByIDX(baseIDX); production_queue_t* pq; if (base == nullptr) { Com_Printf("Invalid production queue index %i\n", baseIDX); continue; } pq = PR_GetProductionForBase(base); for (ssnode = cgi->XML_GetNode(snode, SAVE_PRODUCE_ITEM); pq->numItems < MAX_PRODUCTIONS && ssnode; ssnode = cgi->XML_GetNextNode(ssnode, snode, SAVE_PRODUCE_ITEM)) { const char* s1 = cgi->XML_GetString(ssnode, SAVE_PRODUCE_ITEMID); production_t* prod = &pq->items[pq->numItems]; prod->idx = pq->numItems; prod->amount = cgi->XML_GetInt(ssnode, SAVE_PRODUCE_AMOUNT, 0); prod->frame = cgi->XML_GetInt(ssnode, SAVE_PRODUCE_PROGRESS, 0); /* amount */ if (prod->amount <= 0) { Com_Printf("PR_LoadXML: Production with amount <= 0 dropped (baseidx=%i, production idx=%i).\n", baseIDX, pq->numItems); continue; } /* item */ if (s1[0] != '\0') PR_SetData(&prod->data, PRODUCTION_TYPE_ITEM, INVSH_GetItemByID(s1)); /* UFO */ const int ufoIDX = cgi->XML_GetInt(ssnode, SAVE_PRODUCE_UFOIDX, -1); if (ufoIDX != -1) { storedUFO_t* ufo = US_GetStoredUFOByIDX(ufoIDX); if (!ufo) { Com_Printf("PR_LoadXML: Could not find ufo idx: %i\n", ufoIDX); continue; } PR_SetData(&prod->data, PRODUCTION_TYPE_DISASSEMBLY, ufo); PR_SetUFODisassembly(prod); } /* aircraft */ const char* s2 = cgi->XML_GetString(ssnode, SAVE_PRODUCE_AIRCRAFTID); if (s2[0] != '\0') PR_SetData(&prod->data, PRODUCTION_TYPE_AIRCRAFT, AIR_GetAircraft(s2)); if (!PR_IsDataValid(&prod->data)) { Com_Printf("PR_LoadXML: Production is not an item an aircraft nor a disassembly\n"); continue; } pq->numItems++; } } return true; }