FS2_Open
Open source remastering of the Freespace 2 engine
mod_table.cpp
Go to the documentation of this file.
1 /*
2  * Created by Hassan "Karajorma" Kazmi for the FreeSpace2 Source Code Project.
3  * You may not sell or otherwise commercially exploit the source or things you
4  * create based on the source.
5  */
6 
7 #include "gamesnd/eventmusic.h"
8 #include "globalincs/def_files.h"
9 #include "globalincs/version.h"
10 #include "localization/localize.h"
12 #include "mission/missionmessage.h"
14 #include "mod_table/mod_table.h"
15 #include "parse/parselo.h"
16 #include "sound/sound.h"
17 
28 int Default_detail_level = 3; // "very high" seems a reasonable default in 2012 -zookeeper
29 bool Full_color_head_anis = false;
32 int FS2NetD_port = 0;
33 float Briefing_window_FOV = 0.29375f;
39 
40 
41 void parse_mod_table(const char *filename)
42 {
43  // SCP_vector<SCP_string> lines;
44 
45  try
46  {
47  if (filename == NULL)
48  read_file_text_from_array(defaults_get_file("game_settings.tbl"));
49  else
50  read_file_text(filename, CF_TYPE_TABLES);
51 
52  reset_parse();
53 
54  // start parsing
55  optional_string("#GAME SETTINGS");
56 
57  if (optional_string("$Minimum version:")) {
58  int major = 0;
59  int minor = 0;
60  int build = 0;
61  int revision = 0;
62 
63  required_string("+Major:");
64  stuff_int(&major);
65 
66  required_string("+Minor:");
67  stuff_int(&minor);
68 
69  required_string("+Build:");
70  stuff_int(&build);
71 
72  if (optional_string("+Revision:")) {
73  stuff_int(&revision);
74  }
75 
76  mprintf(("Game Settings Table: Parsed minimum version of %s\n", version::format_version(major, minor, build, revision).c_str()));
77 
78  if (!version::check_at_least(major, minor, build, revision)) {
79  Error(LOCATION, "This modification needs at least version %s of FreeSpace Open. However, the current is only %s!",
80  version::format_version(major, minor, build, revision).c_str(),
82  }
83  }
84 
85  optional_string("#CAMPAIGN SETTINGS");
86 
87  if (optional_string("$Default Campaign File Name:")) {
88  char temp[MAX_FILENAME_LEN];
90 
91  // remove extension?
92  if (drop_extension(temp)) {
93  mprintf(("Game Settings Table: Removed extension on default campaign file name %s\n", temp));
94  }
95 
96  // check length
97  int maxlen = (MAX_FILENAME_LEN - 4);
98  int len = strlen(temp);
99  if (len > maxlen) {
100  Warning(LOCATION, "Token too long: [%s]. Length = %i. Max is %i.\n", temp, len, maxlen);
101  temp[maxlen] = 0;
102  }
103 
105  }
106 
107  if (optional_string("#Ignored Campaign File Names")) {
108  SCP_string campaign_name;
109 
110  while (optional_string("$Campaign File Name:")) {
111  stuff_string(campaign_name, F_NAME);
112 
113  // remove extension?
114  if (drop_extension(campaign_name)) {
115  mprintf(("Game Settings Table: Removed extension on ignored campaign file name %s\n", campaign_name.c_str()));
116  }
117 
118  Ignored_campaigns.push_back(campaign_name);
119  }
120  }
121 
122  if (optional_string("$Red-alert applies to delayed ships:")) {
125  mprintf(("Game Settings Table: Red-alert stats will be loaded for ships that arrive later in missions\n"));
126  }
127  else {
128  mprintf(("Game Settings Table: Red-alert stats will NOT be loaded for ships that arrive later in missions (this is retail behavior)\n"));
129  }
130  }
131 
132  optional_string("#HUD SETTINGS");
133 
134  // how long should the game wait before displaying a directive?
135  if (optional_string("$Directive Wait Time:")) {
137  }
138 
139  if (optional_string("$Cutscene camera displays HUD:")) {
141  }
142  // compatibility
143  if (optional_string("$Cutscene camera disables HUD:")) {
144  mprintf(("Game Settings Table: \"$$Cutscene camera disables HUD\" is deprecated in favor of \"$Cutscene camera displays HUD\"\n"));
145  bool temp;
146  stuff_boolean(&temp);
148  }
149 
150  if (optional_string("$Full color head animations:")) {
152  }
153  // compatibility
154  if (optional_string("$Color head animations with hud colors:")) {
155  mprintf(("Game Settings Table: \"$Color head animations with hud colors\" is deprecated in favor of \"$Full color head animations\"\n"));
156  bool temp;
157  stuff_boolean(&temp);
159  }
160 
161  optional_string("#SEXP SETTINGS");
162 
163  if (optional_string("$Loop SEXPs Then Arguments:")) {
166  mprintf(("Game Settings Table: Using Reversed Loops For SEXP Arguments\n"));
167  }
168  else {
169  mprintf(("Game Settings Table: Using Standard Loops For SEXP Arguments\n"));
170  }
171  }
172 
173  if (optional_string("$Use Alternate Chaining Behavior:")) {
176  mprintf(("Game Settings Table: Using alternate event chaining behavior\n"));
177  }
178  else {
179  mprintf(("Game Settings Table: Using standard event chaining behavior\n"));
180  }
181  }
182 
183  optional_string("#GRAPHICS SETTINGS");
184 
185  if (optional_string("$Enable External Shaders:")) {
188  mprintf(("Game Settings Table: External shaders are enabled\n"));
189  else
190  mprintf(("Game Settings Table: External shaders are DISABLED\n"));
191  }
192 
193  if (optional_string("$Default Detail Level:")) {
194  int detail_level;
195 
196  stuff_int(&detail_level);
197 
198  mprintf(("Game Settings Table: Setting default detail level to %i of %i-%i\n", detail_level, 0, NUM_DEFAULT_DETAIL_LEVELS - 1));
199 
200  if (detail_level < 0 || detail_level > NUM_DEFAULT_DETAIL_LEVELS - 1) {
201  Warning(LOCATION, "Invalid detail level: %i, setting to %i\n", detail_level, Default_detail_level);
202  }
203  else {
204  Default_detail_level = detail_level;
205  }
206  }
207 
208  if (optional_string("$Briefing Window FOV:")) {
209  float fov;
210 
211  stuff_float(&fov);
212 
213  mprintf(("Game Settings Table: Setting briefing window FOV from %f to %f\n", Briefing_window_FOV, fov));
214 
216  }
217 
218 
219  if (optional_string("$Generic Pain Flash Factor:")) {
221  if (Generic_pain_flash_factor != 1.0f)
222  mprintf(("Game Settings Table: Setting generic pain flash factor to %.2f\n", Generic_pain_flash_factor));
223 
224  }
225 
226  if (optional_string("$Shield Pain Flash Factor:")) {
228  if (Shield_pain_flash_factor != 0.0f)
229  mprintf(("Game Settings Table: Setting shield pain flash factor to %.2f\n", Shield_pain_flash_factor));
230 
231  }
232 
233  optional_string("#NETWORK SETTINGS");
234 
235  if (optional_string("$FS2NetD port:")) {
237  if (FS2NetD_port)
238  mprintf(("Game Settings Table: FS2NetD connecting to port %i\n", FS2NetD_port));
239  }
240 
241  optional_string("#SOUND SETTINGS");
242 
243  if (optional_string("$Default Sound Volume:")) {
245  }
246 
247  if (optional_string("$Default Music Volume:")) {
249  }
250 
251  if (optional_string("$Default Voice Volume:")) {
253  }
254 
255  optional_string("#FRED SETTINGS");
256 
257  if (optional_string("$Disable Hard Coded Message Head Ani Files:")) {
260  mprintf(("Game Settings Table: FRED - Disabling Hard Coded Message Ani Files\n"));
261  }
262  else {
263  mprintf(("Game Settings Table: FRED - Using Hard Coded Message Ani Files\n"));
264 
265  }
266  }
267 
268  optional_string("#OTHER SETTINGS");
269 
270  if (optional_string("$Fixed Turret Collisions:")) {
272  }
273 
274  if (optional_string("$Damage Impacted Subsystem First:")) {
276  }
277 
278  if (optional_string("$Default ship select effect:")) {
279  char effect[NAME_LENGTH];
280  stuff_string(effect, F_NAME, NAME_LENGTH);
281  if (!stricmp(effect, "FS2"))
283  else if (!stricmp(effect, "FS1"))
285  else if (!stricmp(effect, "off"))
287  }
288 
289  if (optional_string("$Default weapon select effect:")) {
290  char effect[NAME_LENGTH];
291  stuff_string(effect, F_NAME, NAME_LENGTH);
292  if (!stricmp(effect, "FS2"))
294  else if (!stricmp(effect, "FS1"))
296  else if (!stricmp(effect, "off"))
298  }
299 
300  if (optional_string("$Weapons inherit parent collision group:")) {
303  mprintf(("Game Settings Table: Weapons inherit parent collision group\n"));
304  }
305 
306  if (optional_string("$Flight controls follow eyepoint orientation:")) {
309  mprintf(("Game Settings Table: Flight controls follow eyepoint orientation\n"));
310  }
311 
312  if (optional_string("$Beams Use Damage Factors:")) {
315  mprintf(("Game Settings Table: Beams will use Damage Factors\n"));
316  }
317  else {
318  mprintf(("Game Settings Table: Beams will ignore Damage Factors (retail behavior)\n"));
319  }
320  }
321 
322  if (optional_string("$Default fiction viewer UI:")) {
323  char ui_name[NAME_LENGTH];
324  stuff_string(ui_name, F_NAME, NAME_LENGTH);
325  if (!stricmp(ui_name, "auto"))
327  else {
328  int ui_index = fiction_viewer_ui_name_to_index(ui_name);
329  if (ui_index >= 0)
330  Default_fiction_viewer_ui = ui_index;
331  else
332  Warning(LOCATION, "Unrecognized fiction viewer UI: %s", ui_name);
333  }
334  }
335 
336  required_string("#END");
337  }
338  catch (const parse::ParseException& e)
339  {
340  mprintf(("TABLES: Unable to parse '%s'! Error message = %s.\n", (filename) ? filename : "<default game_settings.tbl>", e.what()));
341  return;
342  }
343 }
344 
346 {
347  // first parse the default table
348  parse_mod_table(NULL);
349 
350  // if a mod.tbl exists read it
351  if (cf_exists_full("game_settings.tbl", CF_TYPE_TABLES)) {
352  parse_mod_table("game_settings.tbl");
353  }
354 
355  // parse any modular tables
356  parse_modular_table("*-mod.tbm", parse_mod_table);
357 }
void mod_table_init()
Definition: mod_table.cpp:345
int FS2NetD_port
Definition: mod_table.cpp:32
#define MAX_FILENAME_LEN
Definition: pstypes.h:324
float Briefing_window_FOV
Definition: mod_table.cpp:33
bool Full_color_head_anis
Definition: mod_table.cpp:29
bool Beams_use_damage_factors
Definition: mod_table.cpp:36
bool Alternate_chaining_behavior
Definition: mod_table.cpp:23
void _cdecl void void _cdecl void _cdecl Warning(char *filename, int line, SCP_FORMAT_STRING const char *format,...) SCP_FORMAT_STRING_ARGS(3
#define mprintf(args)
Definition: pstypes.h:238
bool Damage_impacted_subsystem_first
Definition: mod_table.cpp:21
#define FS_VERSION_MAJOR
Definition: version.h:37
GLclampf f
Definition: Glext.h:7097
const char * defaults_get_file(const char *filename)
Definition: def_files.cpp:103
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
Definition: vmallocator.h:21
int Default_ship_select_effect
Definition: mod_table.cpp:24
void stuff_float(float *f)
Definition: parselo.cpp:2328
float Shield_pain_flash_factor
Definition: mod_table.cpp:38
int Default_fiction_viewer_ui
Definition: mod_table.cpp:26
float Master_sound_volume
Definition: sound.cpp:53
int cf_exists_full(const char *filename, int dir_type)
Definition: cfile.cpp:527
char * filename
bool Flight_controls_follow_eyepoint_orientation
Definition: mod_table.cpp:31
void stuff_string(char *outstr, int type, int len, char *terminators)
Definition: parselo.cpp:1189
#define CF_TYPE_TABLES
Definition: cfile.h:50
char Default_campaign_file_name[MAX_FILENAME_LEN-4]
int required_string(const char *pstr)
Definition: parselo.cpp:468
#define FS_VERSION_MINOR
Definition: version.h:38
int Directive_wait_time
Definition: mod_table.cpp:18
int optional_string(const char *pstr)
Definition: parselo.cpp:539
#define NUM_DEFAULT_DETAIL_LEVELS
Definition: systemvars.h:185
int Default_detail_level
Definition: mod_table.cpp:28
void read_file_text(const char *filename, int mode, char *processed_text, char *raw_text)
Definition: parselo.cpp:1995
bool Disable_hc_message_ani
Definition: mod_table.cpp:34
SCP_string format_version(int major, int minor, int build, int revision)
Returns the string representation of the passed version.
Definition: version.cpp:75
void read_file_text_from_array(const char *array, char *processed_text, char *raw_text)
Definition: parselo.cpp:2022
void stuff_boolean(int *i, bool a_to_eol)
Definition: parselo.cpp:2519
void _cdecl void void _cdecl Error(const char *filename, int line, SCP_FORMAT_STRING const char *format,...) SCP_FORMAT_STRING_ARGS(3
void reset_parse(char *text)
Definition: parselo.cpp:3305
void stuff_int(int *i)
Definition: parselo.cpp:2372
float Generic_pain_flash_factor
Definition: mod_table.cpp:37
#define FS_VERSION_REVIS
Definition: version.h:40
#define NAME_LENGTH
Definition: globals.h:15
bool Fixed_turret_collisions
Definition: mod_table.cpp:20
bool True_loop_argument_sexps
Definition: mod_table.cpp:19
#define F_NAME
Definition: parselo.h:34
#define LOCATION
Definition: pstypes.h:245
float Master_event_music_volume
Definition: eventmusic.cpp:40
bool check_at_least(int major, int minor, int build, int revision)
Checks if the current version is at least the given version.
Definition: version.cpp:15
void parse_mod_table(const char *filename)
Definition: mod_table.cpp:41
SCP_vector< SCP_string > Ignored_campaigns
float fov
Definition: lua.cpp:9155
int parse_modular_table(const char *name_check, void(*parse_callback)(const char *filename), int path_type, int sort_type)
Definition: parselo.cpp:4205
GLenum GLsizei len
Definition: Glext.h:6283
#define FS_VERSION_BUILD
Definition: version.h:39
int temp
Definition: lua.cpp:4996
bool Enable_external_shaders
Definition: mod_table.cpp:27
bool Cutscene_camera_displays_hud
Definition: mod_table.cpp:22
int fiction_viewer_ui_name_to_index(const char *ui_name)
bool drop_extension(char *str)
Definition: parselo.cpp:4043
bool Red_alert_applies_to_delayed_ships
Definition: mod_table.cpp:35
#define stricmp(s1, s2)
Definition: config.h:271
float Master_voice_volume
Definition: sound.cpp:54
bool Weapons_inherit_parent_collision_group
Definition: mod_table.cpp:30
int Default_weapon_select_effect
Definition: mod_table.cpp:25
#define strcpy_s(...)
Definition: safe_strings.h:67