00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "../cl_shared.h"
00027 #include "../ui/ui_main.h"
00028 #include "cp_campaign.h"
00029 #include "cp_installation_callbacks.h"
00030 #include "cp_installation.h"
00031 #include "cp_map.h"
00032 #include "../ui/ui_popup.h"
00033
00038 static void INS_SetInstallationTitle (void)
00039 {
00040 const installationTemplate_t *insTemp = INS_GetInstallationTemplateFromInstallationID(Cvar_GetString("mn_installation_type"));
00041 char insName[MAX_VAR];
00042 int i = 1;
00043 int j;
00044
00045 do {
00046 j = 0;
00047 Com_sprintf(insName, lengthof(insName), "%s #%i", (insTemp) ? _(insTemp->name) : _("Installation"), i);
00048 while (j <= ccs.numInstallations && strcmp(insName, ccs.installations[j++].name));
00049 } while (i++ <= ccs.numInstallations && j <= ccs.numInstallations);
00050
00051 Cvar_Set("mn_installation_title", insName);
00052 if (!insTemp || !insTemp->description || !strlen(insTemp->description))
00053 UI_ResetData(TEXT_BUILDING_INFO);
00054 else
00055 UI_RegisterText(TEXT_BUILDING_INFO, _(insTemp->description));
00056 }
00057
00064 void INS_SelectInstallation (installation_t *installation)
00065 {
00066
00067 if (!installation) {
00068
00069
00070 if (ccs.mapAction == MA_NEWINSTALLATION || ccs.numInstallations >= B_GetInstallationLimit()) {
00071 MAP_ResetAction();
00072 return;
00073 } else {
00074 ccs.mapAction = MA_NEWINSTALLATION;
00075
00076
00077 if (!MAP_IsRadarOverlayActivated())
00078 MAP_SetOverlay("radar");
00079
00080 INS_SetInstallationTitle();
00081 }
00082 } else {
00083 const int timetobuild = max(0, installation->installationTemplate->buildTime - (ccs.date.day - installation->buildStart));
00084
00085 Com_DPrintf(DEBUG_CLIENT, "INS_SelectInstallation: select installation with id %i\n", installation->idx);
00086 ccs.mapAction = MA_NONE;
00087 if (installation->installationStatus == INSTALLATION_WORKING) {
00088 Cvar_Set("mn_installation_timetobuild", "-");
00089 } else {
00090 Cvar_Set("mn_installation_timetobuild", va(ngettext("%d day", "%d days", timetobuild), timetobuild));
00091 }
00092 INS_SetCurrentSelectedInstallation(installation);
00093 UI_PushWindow("popup_installationstatus", NULL);
00094 }
00095 }
00096
00101 static void INS_BuildInstallation_f (void)
00102 {
00103 const nation_t *nation;
00104 installationTemplate_t *installationTemplate;
00105 installation_t *installation;
00106
00107 if (Cmd_Argc() < 1) {
00108 Com_Printf("Usage: %s <installationType>\n", Cmd_Argv(0));
00109 return;
00110 }
00111
00112
00113 if (B_GetInstallationLimit() <= ccs.numInstallations)
00114 return;
00115
00116 installationTemplate = INS_GetInstallationTemplateFromInstallationID(Cmd_Argv(1));
00117 if (!installationTemplate) {
00118 Com_Printf("The installation type %s passed for %s is not valid.\n", Cmd_Argv(1), Cmd_Argv(0));
00119 return;
00120 }
00121
00122 installation = INS_GetFirstUnfoundedInstallation();
00123 if (!installation)
00124 return;
00125
00126 assert(!installation->founded);
00127 assert(installationTemplate->cost >= 0);
00128
00129 if (ccs.credits - installationTemplate->cost > 0) {
00130
00131 INS_SetUpInstallation(installation, installationTemplate, newBasePos);
00132
00133 ccs.numInstallations++;
00134 ccs.campaignStats.installationsBuild++;
00135 ccs.mapAction = MA_NONE;
00136
00137 CL_UpdateCredits(ccs.credits - installationTemplate->cost);
00138
00139 Cvar_SetValue("mn_installation_count", ccs.numInstallations);
00140 Q_strncpyz(installation->name, Cvar_GetString("mn_installation_title"), sizeof(installation->name));
00141 nation = MAP_GetNation(installation->pos);
00142 if (nation)
00143 Com_sprintf(cp_messageBuffer, sizeof(cp_messageBuffer), _("A new installation has been built: %s (nation: %s)"), installation->name, _(nation->name));
00144 else
00145 Com_sprintf(cp_messageBuffer, sizeof(cp_messageBuffer), _("A new installation has been built: %s"), installation->name);
00146 MSO_CheckAddNewMessage(NT_INSTALLATION_BUILDSTART, _("Installation building"), cp_messageBuffer, qfalse, MSG_CONSTRUCTION, NULL);
00147 } else {
00148 if (MAP_IsRadarOverlayActivated())
00149 MAP_SetOverlay("radar");
00150 if (ccs.mapAction == MA_NEWINSTALLATION)
00151 ccs.mapAction = MA_NONE;
00152
00153 UI_Popup(_("Notice"), _("Not enough credits to set up a new installation."));
00154 }
00155 }
00156
00161 static void INS_SelectInstallation_f (void)
00162 {
00163 int installationID;
00164 installation_t *installation;
00165
00166 if (Cmd_Argc() < 2) {
00167 Com_Printf("Usage: %s <installationID>\n", Cmd_Argv(0));
00168 return;
00169 }
00170 installationID = atoi(Cmd_Argv(1));
00171
00172 if (installationID >= 0 && installationID < ccs.numInstallations)
00173 installation = INS_GetFoundedInstallationByIDX(installationID);
00174 else
00175
00176 installation = NULL;
00177 INS_SelectInstallation(installation);
00178 }
00179
00185 static void INS_ChangeInstallationName_f (void)
00186 {
00187 installation_t *installation = INS_GetCurrentSelectedInstallation();
00188
00189
00190 if (!installation)
00191 return;
00192
00193 Q_strncpyz(installation->name, Cvar_GetString("mn_installation_title"), sizeof(installation->name));
00194 }
00195
00200 static void INS_DestroyInstallation_f (void)
00201 {
00202 installation_t *installation;
00203
00204 if (Cmd_Argc() < 2 || atoi(Cmd_Argv(1)) < 0) {
00205 installation = INS_GetCurrentSelectedInstallation();
00206 } else {
00207 installation = INS_GetFoundedInstallationByIDX(atoi(Cmd_Argv(1)));
00208 if (!installation) {
00209 Com_DPrintf(DEBUG_CLIENT, "Installation not founded (idx %i)\n", atoi(Cmd_Argv(1)));
00210 return;
00211 }
00212 }
00213
00214
00215 if (Cmd_Argc() < 3) {
00216 char command[MAX_VAR];
00217
00218 Com_sprintf(command, sizeof(command), "mn_installation_destroy %d 1; mn_pop;", installation->idx);
00219 UI_PopupButton(_("Destroy Installation"), _("Do you really want to destroy this installation?"),
00220 command, _("Destroy"), _("Destroy installation"),
00221 "mn_pop;", _("Cancel"), _("Forget it"),
00222 NULL, NULL, NULL);
00223 return;
00224 }
00225 INS_DestroyInstallation(installation);
00226 }
00227
00231 static void INS_UpdateInsatallationLimit_f (void)
00232 {
00233 Cvar_SetValue("mn_installation_max", B_GetInstallationLimit());
00234 }
00235
00236 void INS_InitCallbacks (void)
00237 {
00238 Cmd_AddCommand("mn_installation_select", INS_SelectInstallation_f, "Parameter is the installation index. -1 will build a new one.");
00239 Cmd_AddCommand("mn_installation_build", INS_BuildInstallation_f, NULL);
00240 Cmd_AddCommand("mn_installation_changename", INS_ChangeInstallationName_f, "Called after editing the cvar installation name");
00241 Cmd_AddCommand("mn_installation_destroy", INS_DestroyInstallation_f, "Destroys an installation");
00242 Cmd_AddCommand("mn_installation_update_max_count", INS_UpdateInsatallationLimit_f, "Updates the installation count limit");
00243
00244 INS_UpdateInsatallationLimit_f();
00245 Cvar_SetValue("mn_installation_count", ccs.numInstallations);
00246 Cvar_Set("mn_installation_title", "");
00247 Cvar_Set("mn_installation_type", "");
00248 }
00249
00250 void INS_ShutdownCallbacks (void)
00251 {
00252 Cmd_RemoveCommand("mn_installation_select");
00253 Cmd_RemoveCommand("mn_installation_build");
00254 Cmd_RemoveCommand("mn_installation_changename");
00255 Cmd_RemoveCommand("mn_installation_destroy");
00256 Cmd_RemoveCommand("mn_installation_update_max_count");
00257 Cvar_Delete("mn_installation_count");
00258 Cvar_Delete("mn_installation_title");
00259 Cvar_Delete("mn_installation_max");
00260 Cvar_Delete("mn_installation_type");
00261 }