summaryrefslogtreecommitdiff
path: root/src/setup/mode.c
blob: 2fcfc9f892a888a0923d697563005f71825eb36d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// 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 <string.h>

#include "doomtype.h"
#include "d_mode.h"
#include "i_system.h"
#include "m_argv.h"
#include "m_config.h"
#include "m_controls.h"

#include "compatibility.h"
#include "display.h"
#include "joystick.h"
#include "keyboard.h"
#include "mouse.h"
#include "multiplayer.h"
#include "sound.h"

#include "mode.h"

GameMission_t gamemission;

typedef struct
{
    GameMission_t mission;
    char *name;
    char *config_file;
    char *extra_config_file;
} mission_config_t;

static mission_config_t config_files[] =
{
    { doom,     "doom",    "default.cfg", PROGRAM_PREFIX "doom.cfg" },
    { heretic,  "heretic", "heretic.cfg", PROGRAM_PREFIX "heretic.cfg" },
    { hexen,    "hexen",   "hexen.cfg",   PROGRAM_PREFIX "hexen.cfg" },
};

// Miscellaneous variables that aren't used in setup.

static int showMessages = 1;
static int screenblocks = 9;
static int detailLevel = 0;
static char *savedir = NULL;

static void BindMiscVariables(void)
{
    M_BindVariable("screenblocks",      &screenblocks);

    if (gamemission == doom)
    {
        M_BindVariable("detaillevel",       &detailLevel);
        M_BindVariable("show_messages",     &showMessages);
    }

    if (gamemission == hexen)
    {
        M_BindVariable("savedir",           &savedir);
        M_BindVariable("messageson",        &showMessages);
    }
}

//
// Initialise all configuration file bindings.
//

void InitBindings(void)
{
    // Keyboard, mouse, joystick controls

    M_BindBaseControls();

    if (gamemission == heretic || gamemission == hexen)
    {
        M_BindHereticControls();
    }

    if (gamemission == hexen)
    {
        M_BindHexenControls();
    }

    // All other variables

    BindCompatibilityVariables();
    BindDisplayVariables();
    BindJoystickVariables();
    BindKeyboardVariables();
    BindMouseVariables();
    BindSoundVariables();
    BindMiscVariables();
    BindMultiplayerVariables();
}

static void SetMission(mission_config_t *config)
{
    gamemission = config->mission;
    M_SetConfigFilenames(config->config_file, config->extra_config_file);
}

static mission_config_t *GetMissionForName(char *name)
{
    int i;

    for (i=0; i<arrlen(config_files); ++i)
    {
        if (!strcmp(config_files[i].name, name))
        {
            return &config_files[i];
        }
    }

    return NULL;
}

void SetupMission(void)
{
    mission_config_t *config;
    char *mission_name;
    int p;

    //!
    // @arg <game>
    //
    // Specify the game to configure the settings for.  Valid
    // values are 'doom', 'heretic' and 'hexen'.
    //

    p = M_CheckParm("-game");

    if (p > 0) 
    {
        mission_name = myargv[p + 1];
    }
    else
    {
        mission_name = "doom";
    }

    config = GetMissionForName(mission_name);

    if (config == NULL)
    {
        I_Error("Invalid parameter - '%s'", mission_name);
    }

    SetMission(config);
}