// Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // // Copyright(C) 2006 Simon Howard // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. // #include #include #include #include "d_englsh.h" #include "textscreen.h" #include "configfile.h" #include "execute.h" #include "multiplayer.h" #define NUM_WADS 10 #define NUM_EXTRA_PARAMS 10 typedef enum { WARP_DOOM1, WARP_DOOM2, } warptype_t; static char *skills[] = { "I'm too young to die!", "Hey, not too rough.", "Hurt me plenty.", "Ultra-violence", "NIGHTMARE!", }; static char *gamemodes[] = { "Co-operative", "Deathmatch", "Deathmatch 2.0", }; char *net_player_name; char *chat_macros[10]; static char *wads[NUM_WADS]; static char *extra_params[NUM_EXTRA_PARAMS]; static int skill = 2; static int nomonsters = 0; static int deathmatch = 0; static int fast = 0; static int respawn = 0; static int udpport = 4815; static int timer = 0; static txt_button_t *warpbutton; static warptype_t warptype = WARP_DOOM2; static int warpepisode = 1; static int warpmap = 1; // Address to connect to when joining a game static char *connect_address = NULL; static void AddWADs(execute_context_t *exec) { int have_wads = 0; int i; for (i=0; i 0) { if (!have_wads) { AddCmdLineParameter(exec, "-file"); } AddCmdLineParameter(exec, "\"%s\"", wads[i]); } } } static void AddExtraParameters(execute_context_t *exec) { int i; for (i=0; i 0) { AddCmdLineParameter(exec, extra_params[i]); } } } static void StartGame(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(user_data)) { execute_context_t *exec; exec = NewExecuteContext(); AddCmdLineParameter(exec, "-server"); AddCmdLineParameter(exec, "-skill %i", skill + 1); if (nomonsters) { AddCmdLineParameter(exec, "-nomonsters"); } if (fast) { AddCmdLineParameter(exec, "-fast"); } if (respawn) { AddCmdLineParameter(exec, "-respawn"); } if (deathmatch == 1) { AddCmdLineParameter(exec, "-deathmatch"); } else if (deathmatch == 2) { AddCmdLineParameter(exec, "-altdeath"); } if (timer > 0) { AddCmdLineParameter(exec, "-timer %i", timer); } if (warptype == WARP_DOOM1) { // TODO: select IWAD based on warp type AddCmdLineParameter(exec, "-warp %i %i", warpepisode, warpmap); } else if (warptype == WARP_DOOM2) { AddCmdLineParameter(exec, "-warp %i", warpmap); } AddCmdLineParameter(exec, "-port %i", udpport); AddWADs(exec); AddExtraParameters(exec); TXT_Shutdown(); M_SaveDefaults(); AddConfigParameters(exec); ExecuteDoom(exec); exit(0); } static void UpdateWarpButton(void) { char buf[10]; if (warptype == WARP_DOOM1) { sprintf(buf, "E%iM%i", warpepisode, warpmap); } else if (warptype == WARP_DOOM2) { sprintf(buf, "MAP%02i", warpmap); } TXT_SetButtonLabel(warpbutton, buf); } static void SetDoom1Warp(TXT_UNCAST_ARG(widget), void *val) { int l; l = (int) val; warptype = WARP_DOOM1; warpepisode = l / 10; warpmap = l % 10; UpdateWarpButton(); } static void SetDoom2Warp(TXT_UNCAST_ARG(widget), void *val) { int l; l = (int) val; warptype = WARP_DOOM2; warpmap = l; UpdateWarpButton(); } static void CloseLevelSelectDialog(TXT_UNCAST_ARG(button), TXT_UNCAST_ARG(window)) { TXT_CAST_ARG(txt_window_t, window); TXT_CloseWindow(window); } static void LevelSelectDialog(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(user_data)) { txt_window_t *window; txt_table_t *table; txt_button_t *button; char buf[10]; int x, y; int l; window = TXT_NewWindow("Select level"); table = TXT_NewTable(8); TXT_AddWidget(window, table); for (y=1; y<=9; ++y) { // MAP?? levels for (x=0; x<4; ++x) { l = x * 9 + y; if (l > 32) { TXT_AddWidget(table, NULL); } else { sprintf(buf, " MAP%02i ", l); button = TXT_NewButton(buf); TXT_SignalConnect(button, "pressed", SetDoom2Warp, (void *) l); TXT_SignalConnect(button, "pressed", CloseLevelSelectDialog, window); TXT_AddWidget(table, button); if (warptype == WARP_DOOM2 && warpmap == l) { TXT_SelectWidget(table, button); } } } // ExMy levels for (x=1; x<=4; ++x) { if (y > 9) { TXT_AddWidget(table, NULL); } else { sprintf(buf, " E%iM%i ", x, y); button = TXT_NewButton(buf); TXT_SignalConnect(button, "pressed", SetDoom1Warp, (void *) (x * 10 + y)); TXT_SignalConnect(button, "pressed", CloseLevelSelectDialog, window); TXT_AddWidget(table, button); if (warptype == WARP_DOOM1 && warpepisode == x && warpmap == y) { TXT_SelectWidget(table, button); } } } } } static txt_window_action_t *StartGameAction(void) { txt_window_action_t *action; action = TXT_NewWindowAction(KEY_F10, "Start"); TXT_SignalConnect(action, "pressed", StartGame, NULL); return action; } static void OpenWadsWindow(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(user_data)) { txt_window_t *window; int i; window = TXT_NewWindow("Add WADs"); for (i=0; i