FS2_Open
Open source remastering of the Freespace 2 engine
species_defs.cpp
Go to the documentation of this file.
1 /*
2  * Species_Defs.CPP
3  * Extended Species Support for FS2 Open
4  *
5  * You may not sell or otherwise commercially exploit the source or things you
6  * create based on the source.
7  *
8  */
9 
10 
11 #include "cfile/cfile.h"
12 #include "globalincs/def_files.h"
13 #include "iff_defs/iff_defs.h"
14 #include "localization/localize.h"
15 #include "parse/parselo.h"
17 
18 
20 
21 //+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
22 
23 // This function parses the data from the species_defs.tbl
24 // Names only - actual loading is done elsewhere
25 
26 void parse_thrust_anims(species_info *species, bool no_create)
27 {
28  if (!no_create)
29  {
30  required_string("$ThrustAnims:");
31 
40  }
41  else if (!optional_string("$ThrustAnims:"))
42  {
43  return;
44  }
45 
46  // favor new style
47  if (no_create)
48  {
49  if (optional_string("+Pri_Normal:") || optional_string("+Normal:"))
51  }
52  else
53  {
54  if (!optional_string("+Pri_Normal:"))
55  required_string("+Normal:");
56 
58  }
59 
60  // if no primary thruster anim is wanted then clear it
63 
64  // and again
65  if (no_create)
66  {
67  if (optional_string("+Pri_Afterburn:") || optional_string("+Afterburn:"))
69  }
70  else
71  {
72  if (!optional_string("+Pri_Afterburn:"))
73  required_string("+Afterburn:");
74 
76  }
77 
78  // if no primary thruster anim is wanted then clear it
81 
82  // extra thruster stuff, bah
83  if (optional_string("+Sec_Normal:"))
85 
86  // etc.
87  if (optional_string("+Sec_Afterburn:"))
89 
90  // etc.
91  if (optional_string("+Ter_Normal:"))
93 
94  // etc.
95  if (optional_string("+Ter_Afterburn:"))
97 
98  // etc.
99  if (optional_string("+Dist_Normal:"))
101 
102  // etc.
103  if (optional_string("+Dist_Afterburn:"))
105 }
106 
107 void parse_thrust_glows(species_info *species, bool no_create)
108 {
109  if (!no_create)
110  {
111  required_string("$ThrustGlows:");
112 
113  generic_anim_init(&species->thruster_info.glow.normal, NULL);
115  }
116  else if (!optional_string("$ThrustGlows:"))
117  {
118  return;
119  }
120 
121  if (no_create)
122  {
123  if (optional_string("+Normal:"))
125  }
126  else
127  {
128  required_string("+Normal:");
130  }
131 
132  // if no glow is wanted then clear it
133  if ( !VALID_FNAME(species->thruster_info.glow.normal.filename) )
134  generic_anim_init(&species->thruster_info.glow.normal, NULL);
135 
136  if (no_create)
137  {
138  if (optional_string("+Afterburn:"))
140  }
141  else
142  {
143  required_string("+Afterburn:");
145  }
146 
147  // if no glow is wanted then clear it
150 }
151 
152 void parse_species_tbl(const char *filename)
153 {
154  int i;
155  char species_name[NAME_LENGTH];
156 
157  try
158  {
159  if (filename == NULL)
160  read_file_text_from_array(defaults_get_file("species_defs.tbl"));
161  else
162  read_file_text(filename, CF_TYPE_TABLES);
163 
164  reset_parse();
165 
166 
167  // start parsing
168  required_string("#SPECIES DEFS");
169 
170  // no longer required: counted automatically
171  if (optional_string("$NumSpecies:"))
172  {
173  int temp;
174  stuff_int(&temp);
175  }
176 
177  // begin reading data
178  while (required_string_either("#END", "$Species_Name:"))
179  {
180  bool no_create = false;
181  species_info *species, new_species;
182 
183  species = &new_species;
184 
185  // Start Species - Get its name
186  required_string("$Species_Name:");
187  stuff_string(species_name, F_NAME, NAME_LENGTH);
188 
189  if (optional_string("+nocreate"))
190  {
191  no_create = true;
192 
193  for (i = 0; i < (int)Species_info.size(); i++)
194  {
195  if (!stricmp(Species_info[i].species_name, species_name))
196  {
197  species = &Species_info[i];
198  break;
199  }
200  }
201  }
202  else
203  {
204  strcpy_s(species->species_name, species_name);
205  }
206 
207  // Goober5000 - IFF
208  if (optional_string("$Default IFF:"))
209  {
210  bool iff_found = false;
211  char temp_name[NAME_LENGTH];
212  stuff_string(temp_name, F_NAME, NAME_LENGTH);
213 
214  // search for it in iffs
215  for (int iLoop = 0; iLoop < Num_iffs; iLoop++)
216  {
217  if (!stricmp(Iff_info[iLoop].iff_name, temp_name))
218  {
219  species->default_iff = iLoop;
220  iff_found = true;
221  }
222  }
223 
224  if (!iff_found)
225  {
226  species->default_iff = 0;
227  Warning(LOCATION, "Species %s default IFF %s not found in iff_defs.tbl! Defaulting to %s.\n", species->species_name, temp_name, Iff_info[species->default_iff].iff_name);
228  }
229  }
230  else if (!no_create)
231  {
232  // we have no idea which it could be, so default to 0
233  species->default_iff = 0;
234 
235  // let them know
236  Warning(LOCATION, "$Default IFF not specified for species %s in species_defs.tbl! Defaulting to %s.\n", species->species_name, Iff_info[species->default_iff].iff_name);
237  }
238 
239  // Goober5000 - FRED color
240  if (optional_string("$FRED Color:") || optional_string("$FRED Colour:"))
241  {
243  }
244  else if (!no_create)
245  {
246  // set defaults to Volition's originals
247  if (!stricmp(species->species_name, "Terran"))
248  {
249  species->fred_color.rgb.r = 0;
250  species->fred_color.rgb.g = 0;
251  species->fred_color.rgb.b = 192;
252  }
253  else if (!stricmp(species->species_name, "Vasudan"))
254  {
255  species->fred_color.rgb.r = 0;
256  species->fred_color.rgb.g = 128;
257  species->fred_color.rgb.b = 0;
258  }
259  else if (!stricmp(species->species_name, "Shivan"))
260  {
261  species->fred_color.rgb.r = 192;
262  species->fred_color.rgb.g = 0;
263  species->fred_color.rgb.b = 0;
264  }
265  else if (!stricmp(species->species_name, "Ancients") || !stricmp(species->species_name, "Ancient"))
266  {
267  species->fred_color.rgb.r = 192;
268  species->fred_color.rgb.g = 0;
269  species->fred_color.rgb.b = 192;
270  }
271  else
272  {
273  species->fred_color.rgb.r = 0;
274  species->fred_color.rgb.g = 0;
275  species->fred_color.rgb.b = 0;
276  }
277 
278  // let them know
279  Warning(LOCATION, "$FRED Color not specified for species %s in species_defs.tbl! Defaulting to (%d, %d, %d).\n", species->species_name, species->fred_color.rgb.r, species->fred_color.rgb.g, species->fred_color.rgb.b);
280  }
281 
282  // stuff
283  optional_string("$MiscAnims:");
284 
285  // Get its Debris Texture
286  if ((!no_create && required_string("+Debris_Texture:")) || optional_string("+Debris_Texture:"))
287  {
288  generic_bitmap_init(&species->debris_texture, NULL);
290  }
291 
292 
293  // Shield Hit Animation
294  if (optional_string("+Shield_Hit_ani:")) // Shouldn't be required -- LPine
295  {
296  generic_anim_init(&species->shield_anim, NULL);
298  }
299  else if (!no_create)
300  {
301  species->shield_anim.filename[0] = '\0';
302  species->shield_anim.first_frame = -1; // Landmine to trip up anyone who does end up using this
303  }
304 
305 
306  // Thruster Anims
307  parse_thrust_anims(species, no_create);
308 
309  // Thruster Glow Anims
310  parse_thrust_glows(species, no_create);
311 
312 
313  // Goober5000 - AWACS multiplier
314  if (optional_string("$AwacsMultiplier:"))
315  {
316  stuff_float(&species->awacs_multiplier);
317  }
318  else if (!no_create)
319  {
320  // set defaults to Volition's originals
321  if (!stricmp(species->species_name, "Vasudan"))
322  species->awacs_multiplier = 1.25f;
323  else if (!stricmp(species->species_name, "Shivan"))
324  species->awacs_multiplier = 1.50f;
325  else
326  species->awacs_multiplier = 1.0f;
327 
328  // let them know
329  Warning(LOCATION, "$AwacsMultiplier not specified for species %s in species_defs.tbl! Defaulting to %.2f.\n", species->species_name, species->awacs_multiplier);
330  }
331 
332  // Goober5000 - countermeasure type
333  // (we won't be able to resolve it until after we've parsed the weapons table)
334  if (optional_string("$Countermeasure type:"))
336 
337  // don't add new entry if this is just a modified one
338  if (!no_create)
339  Species_info.push_back(new_species);
340  }
341 
342  required_string("#END");
343 
344  // add tbl/tbm to multiplayer validation list
345  extern void fs2netd_add_table_validation(const char *tblname);
347  }
348  catch (const parse::ParseException& e)
349  {
350  mprintf(("TABLES: Unable to parse '%s'! Error message = %s.\n", (filename) ? filename : NOX("<default species_defs.tbl>"), e.what()));
351  return;
352  }
353 }
354 
356 
358 {
359  if (Species_initted)
360  return;
361 
362  Species_info.clear();
363 
364 
365  if (cf_exists_full("species_defs.tbl", CF_TYPE_TABLES))
366  parse_species_tbl("species_defs.tbl");
367  else
368  parse_species_tbl(NULL);
369 
371 
372 
373  Species_initted = 1;
374 }
#define MAX_FILENAME_LEN
Definition: pstypes.h:324
float awacs_multiplier
Definition: species_defs.h:49
int i
Definition: multi_pxo.cpp:466
thrust_pair flames
Definition: species_defs.h:35
void species_init()
generic_bitmap normal
Definition: species_defs.h:24
void parse_thrust_glows(species_info *species, bool no_create)
void fs2netd_add_table_validation(const char *tblname)
char cmeasure_name[NAME_LENGTH]
Definition: species_defs.h:75
void _cdecl void void _cdecl void _cdecl Warning(char *filename, int line, SCP_FORMAT_STRING const char *format,...) SCP_FORMAT_STRING_ARGS(3
thrust_pair_bitmap thruster_distortion_info
Definition: species_defs.h:65
void generic_bitmap_init(generic_bitmap *gb, const char *filename)
Definition: generic.cpp:124
#define mprintf(args)
Definition: pstypes.h:238
union species_info::@265 fred_color
void parse_thrust_anims(species_info *species, bool no_create)
const char * defaults_get_file(const char *filename)
Definition: def_files.cpp:103
generic_anim afterburn
Definition: species_defs.h:31
int required_string_either(char *str1, char *str2)
Checks for one of two required strings.
Definition: parselo.cpp:673
void stuff_float(float *f)
Definition: parselo.cpp:2328
iff_info Iff_info[MAX_IFFS]
Definition: iff_defs.cpp:20
thrust_pair_bitmap thruster_tertiary_glow_info
Definition: species_defs.h:64
thrust_info thruster_info
Definition: species_defs.h:60
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
int first_frame
Definition: generic.h:19
int cf_exists_full(const char *filename, int dir_type)
Definition: cfile.cpp:527
char * filename
thrust_pair_bitmap thruster_secondary_glow_info
Definition: species_defs.h:63
void stuff_string(char *outstr, int type, int len, char *terminators)
Definition: parselo.cpp:1189
#define CF_TYPE_TABLES
Definition: cfile.h:50
generic_anim shield_anim
Definition: species_defs.h:59
generic_anim normal
Definition: species_defs.h:30
int required_string(const char *pstr)
Definition: parselo.cpp:468
int optional_string(const char *pstr)
Definition: parselo.cpp:539
generic_bitmap debris_texture
Definition: species_defs.h:58
generic_bitmap afterburn
Definition: species_defs.h:25
void read_file_text(const char *filename, int mode, char *processed_text, char *raw_text)
Definition: parselo.cpp:1995
void read_file_text_from_array(const char *array, char *processed_text, char *raw_text)
Definition: parselo.cpp:2022
#define NOX(s)
Definition: pstypes.h:473
void reset_parse(char *text)
Definition: parselo.cpp:3305
thrust_pair glow
Definition: species_defs.h:36
void stuff_int(int *i)
Definition: parselo.cpp:2372
int stuff_int_list(int *ilp, int max_ints, int lookup_type)
Definition: parselo.cpp:2782
#define NAME_LENGTH
Definition: globals.h:15
void generic_anim_init(generic_anim *ga)
Definition: generic.cpp:80
#define F_NAME
Definition: parselo.h:34
#define LOCATION
Definition: pstypes.h:245
char species_name[NAME_LENGTH]
Definition: species_defs.h:47
SCP_vector< species_info > Species_info
#define VALID_FNAME(x)
Definition: pstypes.h:418
int parse_modular_table(const char *name_check, void(*parse_callback)(const char *filename), int path_type, int sort_type)
Definition: parselo.cpp:4205
int temp
Definition: lua.cpp:4996
int Num_iffs
Definition: iff_defs.cpp:19
int Species_initted
char filename[MAX_FILENAME_LEN]
Definition: generic.h:52
char filename[MAX_FILENAME_LEN]
Definition: generic.h:18
struct species_info::@265::@266 rgb
void parse_species_tbl(const char *filename)
char iff_name[NAME_LENGTH]
Definition: iff_defs.h:36
#define stricmp(s1, s2)
Definition: config.h:271
#define RAW_INTEGER_TYPE
Definition: parselo.h:52
#define strcpy_s(...)
Definition: safe_strings.h:67