cl_game_skirmish.c

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2002-2010 UFO: Alien Invasion.
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018 See the GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 
00024 */
00025 
00026 #include "client.h"
00027 #include "cl_game.h"
00028 #include "cl_team.h"
00029 #include "cl_inventory.h"
00030 #include "ui/ui_main.h"
00031 #include "ui/ui_popup.h"
00032 
00033 #define DROPSHIP_MAX INTERCEPTOR_STILETTO
00034 
00035 static cvar_t *cl_equip;
00036 
00041 static void GAME_SK_SetMissionParameters (const mapDef_t *md)
00042 {
00043     int i;
00044 
00045     Cvar_SetValue("ai_numcivilians", 8);
00046     Cvar_Set("ai_civilian", "europe");
00047 
00048     if (md->hurtAliens)
00049         Cvar_Set("sv_hurtaliens", "1");
00050     else
00051         Cvar_Set("sv_hurtaliens", "0");
00052 
00053     /* now store the alien teams in the shared csi struct to let the game dll
00054      * have access to this data, too */
00055     csi.numAlienTeams = 0;
00056     for (i = 0; i < csi.numTeamDefs; i++) {
00057         const teamDef_t* td = &csi.teamDef[i];
00058         if (CHRSH_IsTeamDefAlien(td))
00059             csi.alienTeams[csi.numAlienTeams++] = td;
00060     }
00061 }
00062 
00066 static void GAME_SK_Start_f (void)
00067 {
00068     char map[MAX_VAR];
00069     mapDef_t *md;
00070     const char *name = Cvar_GetString("cl_equip");
00071     const equipDef_t *ed = INV_GetEquipmentDefinitionByID(name);
00072     const char *teamDefID = GAME_GetTeamDef();
00073     const size_t size = GAME_GetCharacterArraySize();
00074     int maxSoldiers = Cvar_GetInteger("sv_maxsoldiersperplayer");
00075     int ugvs = Cvar_GetInteger("cl_ugvs");
00077     const char *ugvTeamDefID = "phalanx_ugv_phoenix";
00078     int i;
00079 
00080     if (maxSoldiers <= 0)
00081         maxSoldiers = size;
00082 
00083     ugvs = min(ugvs, size - maxSoldiers);
00084 
00085     assert(cls.currentSelectedMap >= 0);
00086     assert(cls.currentSelectedMap < MAX_MAPDEFS);
00087 
00088     md = Com_GetMapDefByIDX(cls.currentSelectedMap);
00089     if (!md)
00090         return;
00091 
00092     GAME_SK_SetMissionParameters(md);
00093 
00094     Com_Printf("Starting skirmish with %i soldiers and %i ugvs\n", maxSoldiers, ugvs);
00095     GAME_GenerateTeam(teamDefID, ed, maxSoldiers);
00096     for (i = 0; i < ugvs; i++)
00097         GAME_AppendTeamMember(i + maxSoldiers, ugvTeamDefID, ed);
00098 
00099     assert(md->map);
00100     Com_sprintf(map, sizeof(map), "map %s %s %s;", Cvar_GetInteger("mn_serverday") ? "day" : "night", md->map, md->param ? md->param : "");
00101 
00102     /* prepare */
00103     UI_InitStack(NULL, "singleplayermission", qtrue, qfalse);
00104 
00105     Cbuf_AddText(map);
00106 }
00107 
00108 static void GAME_SK_Restart_f (void)
00109 {
00110     GAME_ReloadMode();
00111     GAME_SK_Start_f();
00112 }
00113 
00117 static void GAME_SK_ChangeEquip_f (void)
00118 {
00119     const equipDef_t *ed;
00120     int index;
00121     const char *cvarName;
00122 
00123     if (Cmd_Argc() < 2) {
00124         Com_Printf("Usage: %s <cvarname>\n", Cmd_Argv(0));
00125         return;
00126     }
00127 
00128     cvarName = Cmd_Argv(1);
00129     ed = INV_GetEquipmentDefinitionByID(Cvar_GetString(cvarName));
00130     index = ed - csi.eds;
00131 
00132     if (!strcmp(Cmd_Argv(0), "sk_prevequip")) {
00133         index--;
00134         if (index < 0)
00135             index = csi.numEDs - 1;
00136         Cvar_Set(cvarName, csi.eds[index].name);
00137     } else {
00138         index++;
00139         if (index >= csi.numEDs)
00140             index = 0;
00141         Cvar_Set(cvarName, csi.eds[index].name);
00142     }
00143 }
00144 
00156 void GAME_SK_Results (struct dbuffer *msg, int winner, int *numSpawned, int *numAlive, int numKilled[][MAX_TEAMS], int numStunned[][MAX_TEAMS])
00157 {
00158     char resultText[UI_MAX_SMALLTEXTLEN];
00159     int enemiesKilled, enemiesStunned;
00160     int i;
00161 
00162     CL_Drop();
00163 
00164     if (winner == 0) {
00165         UI_Popup(_("Game Drawn!"), _("The game was a draw!\n\nNo survivors left on any side."));
00166         return;
00167     }
00168 
00169     enemiesKilled = enemiesStunned = 0;
00170     for (i = 0; i < MAX_TEAMS; i++) {
00171         if (i != cls.team && i != TEAM_CIVILIAN) {
00172             enemiesKilled += numKilled[cls.team][i];
00173             enemiesStunned += numStunned[cls.team][i];
00174         }
00175     }
00176 
00177     Com_sprintf(resultText, sizeof(resultText),
00178             _("Enemies killed:\t\t%i\n"
00179               "Team survivors:\t\t%i\n"
00180               "Enemy survivors:\t\t%i\n"
00181               "Friendly fire:\t\t%i\n"
00182               "Civilians killed:\t\t%i\n"
00183               "Civilians killed by enemy:\t\t%i\n"),
00184             enemiesKilled + enemiesStunned, numAlive[cls.team], numAlive[TEAM_ALIEN],
00185             numKilled[cls.team][cls.team], numKilled[cls.team][TEAM_CIVILIAN], numKilled[TEAM_ALIEN][TEAM_CIVILIAN]);
00186     if (winner == cls.team) {
00187         Com_sprintf(popupText, lengthof(popupText), "%s\n%s", _("You won the game!"), resultText);
00188         UI_Popup(_("Congratulations"), popupText);
00189     } else {
00190         Com_sprintf(popupText, lengthof(popupText), "%s\n%s", _("You've lost the game!"), resultText);
00191         UI_Popup(_("Better luck next time"), popupText);
00192     }
00193 }
00194 
00200 static inline void GAME_SK_HideDropships (const linkedList_t *dropships)
00201 {
00202     const qboolean hide = (dropships == NULL);
00203     if (hide) {
00204         UI_ExecuteConfunc("skirmish_hide_dropships true");
00205         Cvar_Set("rm_drop", "");
00206     } else {
00207         const char *rma = Com_GetRandomMapAssemblyNameForCraft((const char *)dropships->data);
00208         Cvar_Set("rm_drop", rma);
00209         UI_UpdateInvisOptions(UI_GetOption(OPTION_DROPSHIPS), dropships);
00210 
00211         UI_ExecuteConfunc("skirmish_hide_dropships false");
00212     }
00213 }
00214 
00220 static inline void GAME_SK_HideUFOs (const linkedList_t *ufos)
00221 {
00222     const qboolean hide = (ufos == NULL);
00223     if (hide) {
00224         UI_ExecuteConfunc("skirmish_hide_ufos true");
00225         Cvar_Set("rm_ufo", "");
00226     } else {
00227         const char *rma = Com_GetRandomMapAssemblyNameForCraft((const char *)ufos->data);
00228         Cvar_Set("rm_ufo", rma);
00229         UI_UpdateInvisOptions(UI_GetOption(OPTION_UFOS), ufos);
00230 
00231         UI_ExecuteConfunc("skirmish_hide_ufos false");
00232     }
00233 }
00234 
00235 const mapDef_t* GAME_SK_MapInfo (int step)
00236 {
00237     const mapDef_t *md = Com_GetMapDefByIDX(cls.currentSelectedMap);
00238 
00239     if (md->map[0] == '.')
00240         return NULL;
00241 
00242     if (md->map[0] == '+') {
00243         GAME_SK_HideUFOs(md->ufos);
00244         GAME_SK_HideDropships(md->aircraft);
00245     } else {
00246         GAME_SK_HideUFOs(NULL);
00247         GAME_SK_HideDropships(NULL);
00248     }
00249 
00250     return md;
00251 }
00252 
00253 int GAME_SK_GetTeam (void)
00254 {
00255     return cl_team->integer;
00256 }
00257 
00258 static void GAME_InitMenuOptions (void)
00259 {
00260     int i;
00261     uiNode_t* ufoOptions = NULL;
00262     uiNode_t* aircraftOptions = NULL;
00263 
00264     for (i = 0; i < UFO_MAX; i++) {
00265         const char *shortName = Com_UFOTypeToShortName(i);
00266         UI_AddOption(&ufoOptions, shortName, shortName, Com_GetRandomMapAssemblyNameForCraft(shortName));
00267     }
00268     for (i = 0; i < UFO_MAX; i++) {
00269         const char *shortName = Com_UFOCrashedTypeToShortName(i);
00270         UI_AddOption(&ufoOptions, shortName, shortName, Com_GetRandomMapAssemblyNameForCraft(shortName));
00271     }
00272     UI_RegisterOption(OPTION_UFOS, ufoOptions);
00273 
00274     for (i = 0; i < DROPSHIP_MAX; i++) {
00275         const char *shortName = Com_DropShipTypeToShortName(i);
00276         UI_AddOption(&aircraftOptions, shortName, shortName, Com_GetRandomMapAssemblyNameForCraft(shortName));
00277     }
00278     UI_RegisterOption(OPTION_DROPSHIPS, aircraftOptions);
00279 }
00280 
00281 void GAME_SK_InitStartup (void)
00282 {
00283     Cvar_ForceSet("sv_maxclients", "1");
00284     cl_equip = Cvar_Get("cl_equip", "multiplayer_initial", 0, "Equipment that is used for skirmish mode games");
00285 
00286     Cmd_AddCommand("sk_start", GAME_SK_Start_f, "Start the new skirmish game");
00287     Cmd_AddCommand("sk_prevequip", GAME_SK_ChangeEquip_f, "Previous equipment definition");
00288     Cmd_AddCommand("sk_nextequip", GAME_SK_ChangeEquip_f, "Next equipment definition");
00289     Cmd_AddCommand("game_go", GAME_SK_Restart_f, "Restart the skirmish mission");
00290 
00291     GAME_InitMenuOptions();
00292 }
00293 
00294 void GAME_SK_Shutdown (void)
00295 {
00296     Cvar_Delete("cl_equip");
00297 
00298     Cmd_RemoveCommand("sk_start");
00299     Cmd_RemoveCommand("sk_nextequip");
00300     Cmd_RemoveCommand("sk_prevequip");
00301     Cmd_RemoveCommand("game_go");
00302 
00303     UI_ResetData(OPTION_DROPSHIPS);
00304     UI_ResetData(OPTION_UFOS);
00305 
00306     SV_Shutdown("Quitting server.", qfalse);
00307 }

Generated by  doxygen 1.6.2