1 //---------------------------------------------------------------------------- 2 // EDGE Data Definition File Code (Local Header) 3 //---------------------------------------------------------------------------- 4 // 5 // Copyright (c) 1999-2008 The EDGE Team. 6 // 7 // This program is free software; you can redistribute it and/or 8 // modify it under the terms of the GNU General Public License 9 // as published by the Free Software Foundation; either version 2 10 // of the License, or (at your option) any later version. 11 // 12 // This program is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 // 17 //---------------------------------------------------------------------------- 18 19 #ifndef __DDF_LOCAL_H__ 20 #define __DDF_LOCAL_H__ 21 22 #include "epi/epi.h" 23 #include "epi/str_format.h" 24 25 #include "types.h" 26 #include "main.h" 27 #include "states.h" 28 29 // defines for parser stuff. 30 #define BUFFERSIZE 1024 31 32 // enum thats gives the parser's current status 33 typedef enum 34 { 35 readstatus_invalid = 0, 36 waiting_tag, 37 reading_tag, 38 waiting_newdef, 39 reading_newdef, 40 reading_command, 41 reading_data, 42 reading_remark, 43 reading_string 44 } 45 readstatus_e; 46 47 // enum thats describes the return value from DDF_MainProcessChar 48 typedef enum 49 { 50 nothing, 51 command_read, 52 property_read, 53 def_start, 54 def_stop, 55 remark_start, 56 remark_stop, 57 separator, 58 string_start, 59 string_stop, 60 group_start, 61 group_stop, 62 tag_start, 63 tag_stop, 64 terminator, 65 ok_char 66 } 67 readchar_t; 68 69 // 70 // This structure forms the basis for the command checking, it hands back a code 71 // pointer and sometimes a pointer to a (int) numeric value. (used for info that gets 72 // its value directly from the file). 73 // 74 typedef struct commandlist_s 75 { 76 // command name 77 const char *name; 78 79 // parse function. 80 void (*parse_command) (const char *info, void *storage); 81 82 ptrdiff_t offset; 83 84 const struct commandlist_s *sub_comms; 85 } 86 commandlist_t; 87 88 // NOTE: requires DDF_CMD_BASE to be defined as the dummy struct 89 90 #define DDF_FIELD(name,field,parser) \ 91 { name, parser, ((char*)&DDF_CMD_BASE.field - (char*)&DDF_CMD_BASE), NULL } 92 93 #define DDF_SUB_LIST(name,field,subcomms) \ 94 { "*" name, NULL, ((char*)&DDF_CMD_BASE.field - (char*)&DDF_CMD_BASE), subcomms } 95 96 #define DDF_CMD_END { NULL, NULL, 0, NULL } 97 98 #define DDF_STATE(name,redir,field) \ 99 { name, redir, ((char*)&DDF_CMD_BASE.field - (char*)&DDF_CMD_BASE) } 100 101 #define DDF_STATE_END { NULL, NULL, 0 } 102 103 104 // 105 // This structure passes the information needed to DDF_MainReadFile, so that 106 // the reader uses the correct procedures when reading a file. 107 // 108 typedef struct readinfo_s 109 { 110 const char *message; // message displayed 111 const char *filename; // filename (when memfile == NULL) 112 const char *lumpname; // lumpnume (when memfile != NULL) 113 114 const char *tag; // the file has to start with <tag> 115 116 char *memfile; 117 unsigned int memsize; 118 119 // number of entries per displayed `.' 120 int entries_per_dot; 121 122 // 123 // FUNCTIONS 124 // 125 126 // create a new dynamic entry with the given name. For number-only 127 // ddf files (lines, sectors and playlist), it is a number. For 128 // things.ddf, it is a name with an optional ":####" number 129 // appended. For everything else it is just a normal name. 130 // 131 // this also instantiates the static entry's information (excluding 132 // name and/or number) using the built-in defaults. 133 // 134 // if an entry with the given name/number already exists, re-use 135 // that entry for the dynamic part, otherwise create a new dynamic 136 // entry and add it to the list. Note that only the name and/or 137 // number need to be kept valid in the dynamic entry. Returns true 138 // if the name already existed, otherwise false. 139 // 140 // Note: for things.ddf, only the name is significant when checking 141 // if the entry already exists. 142 // 143 void (*start_entry) (const char *name, bool extend); 144 145 // parse a single field for the entry. Usually it will just call 146 // the ddf_main routine to handle the command list. For 147 // comma-separated fields (specials, states, etc), this routine will 148 // be called multiple times, once for each element, and `index' is 149 // used to indicate which element (starting at 0). 150 // 151 void (*parse_field) (const char *field, const char *contents, 152 int index, bool is_last); 153 154 // when the entry has finished, this routine can perform any 155 // necessary operations here (such as updating a number -> entry 156 // lookup table). In particular, it should copy the static buffer 157 // part into the dynamic part. It also should compute the CRC. 158 // 159 void (*finish_entry) (void); 160 161 // this function is called when the #CLEARALL directive is used. 162 // The entries should be deleted if it is safe (i.e. there are no 163 // pointers to them), otherwise they should be marked `disabled' and 164 // ignored in subsequent searches. Note: The parser ensures that 165 // this is never called in the middle of an entry. 166 // 167 void (*clear_all) (void); 168 } 169 readinfo_t; 170 171 // 172 // This structure forms the basis for referencing specials. 173 // 174 typedef struct 175 { 176 // name of special 177 const char *name; 178 179 // flag(s) or value of special 180 int flags; 181 182 // this is true if the DDF name (e.g. "GRAVITY") is opposite to the 183 // code's flag name (e.g. MF_NoGravity). 184 bool negative; 185 } 186 specflags_t; 187 188 typedef enum 189 { 190 // special flag is unknown 191 CHKF_Unknown, 192 193 // the flag should be set (i.e. forced on) 194 CHKF_Positive, 195 196 // the flag should be cleared (i.e. forced off) 197 CHKF_Negative, 198 199 // the flag should be made user-definable 200 CHKF_User 201 } 202 checkflag_result_e; 203 204 // 205 // This is a reference table, that determines what code pointer is placed in the 206 // states table entry. 207 // 208 typedef struct 209 { 210 const char *actionname; 211 void (*action) (struct mobj_s * mo); 212 213 // -AJA- 1999/08/09: This function handles the argument when brackets 214 // are present (e.g. "WEAPON_SHOOT(FIREBALL)"). NULL if unused. 215 void (*handle_arg) (const char *arg, state_t * curstate); 216 } 217 actioncode_t; 218 219 // This structure is used for parsing states 220 typedef struct 221 { 222 // state label 223 const char *label; 224 225 // redirection label for last state 226 const char *last_redir; 227 228 // pointer to state_num storage 229 ptrdiff_t offset; 230 } 231 state_starter_t; 232 233 // DDF_MAIN Code (Reading all files, main init & generic functions). 234 bool DDF_MainReadFile (readinfo_t * readinfo); 235 236 extern int cur_ddf_line_num; 237 extern std::string cur_ddf_filename; 238 extern std::string cur_ddf_entryname; 239 extern std::string cur_ddf_linedata; 240 241 void DDF_Error (const char *err, ...) GCCATTR((format (printf,1,2))); 242 void DDF_Warning (const char *err, ...) GCCATTR((format (printf,1,2))); 243 void DDF_WarnError(const char *err, ...) GCCATTR((format (printf,1,2))); 244 245 void DDF_MainGetPercent (const char *info, void *storage); 246 void DDF_MainGetPercentAny (const char *info, void *storage); 247 void DDF_MainGetBoolean (const char *info, void *storage); 248 void DDF_MainGetFloat (const char *info, void *storage); 249 void DDF_MainGetAngle (const char *info, void *storage); 250 void DDF_MainGetSlope (const char *info, void *storage); 251 void DDF_MainGetNumeric (const char *info, void *storage); 252 void DDF_MainGetString (const char *info, void *storage); 253 void DDF_MainGetLumpName (const char *info, void *storage); 254 void DDF_MainGetTime (const char *info, void *storage); 255 void DDF_MainGetColourmap (const char *info, void *storage); 256 void DDF_MainGetRGB (const char *info, void *storage); 257 void DDF_MainGetWhenAppear (const char *info, void *storage); 258 void DDF_MainGetBitSet (const char *info, void *storage); 259 260 bool DDF_MainParseField (const commandlist_t * commands, 261 const char *field, const char *contents, 262 byte *obj_base); 263 void DDF_MainLookupSound (const char *info, void *storage); 264 void DDF_MainRefAttack (const char *info, void *storage); 265 266 void DDF_DummyFunction (const char *info, void *storage); 267 268 checkflag_result_e DDF_MainCheckSpecialFlag(const char *name, 269 const specflags_t * flag_set, int *flag_value, 270 bool allow_prefixes, bool allow_user); 271 272 int DDF_MainLookupDirector (const mobjtype_c * obj, const char *info); 273 274 // DDF_ANIM Code 275 void DDF_AnimInit (void); 276 void DDF_AnimCleanUp (void); 277 278 // DDF_ATK Code 279 void DDF_AttackInit (void); 280 void DDF_AttackCleanUp (void); 281 282 // DDF_GAME Code 283 void DDF_GameInit (void); 284 void DDF_GameCleanUp (void); 285 286 // DDF_LANG Code 287 void DDF_LanguageInit (void); 288 void DDF_LanguageCleanUp (void); 289 290 // DDF_LEVL Code 291 void DDF_LevelInit (void); 292 void DDF_LevelCleanUp (void); 293 294 // DDF_LINE Code 295 void DDF_LinedefInit (void); 296 void DDF_LinedefCleanUp (void); 297 298 #define EMPTY_COLMAP_NAME "_NONE_" 299 #define EMPTY_COLMAP_NUM -777 300 301 // DDF_MOBJ Code (Moving Objects) 302 void DDF_MobjInit (void); 303 void DDF_MobjCleanUp (void); 304 void DDF_MobjGetExtra (const char *info, void *storage); 305 void DDF_MobjGetItemType (const char *info, void *storage); 306 void DDF_MobjGetBpAmmo (const char *info, void *storage); 307 void DDF_MobjGetBpAmmoLimit (const char *info, void *storage); 308 void DDF_MobjGetBpArmour (const char *info, void *storage); 309 void DDF_MobjGetBpKeys (const char *info, void *storage); 310 void DDF_MobjGetBpWeapon (const char *info, void *storage); 311 void DDF_MobjGetPlayer (const char *info, void *storage); 312 313 void ThingParseField(const char *field, const char *contents, 314 int index, bool is_last); 315 316 // DDF_MUS Code 317 void DDF_MusicPlaylistInit (void); 318 void DDF_MusicPlaylistCleanUp (void); 319 320 // DDF_STAT Code 321 void DDF_StateInit (void); 322 void DDF_StateGetAttack (const char *arg, state_t * cur_state); 323 void DDF_StateGetMobj (const char *arg, state_t * cur_state); 324 void DDF_StateGetSound (const char *arg, state_t * cur_state); 325 void DDF_StateGetInteger (const char *arg, state_t * cur_state); 326 void DDF_StateGetIntPair (const char *arg, state_t * cur_state); 327 void DDF_StateGetFloat (const char *arg, state_t * cur_state); 328 void DDF_StateGetPercent (const char *arg, state_t * cur_state); 329 void DDF_StateGetJump (const char *arg, state_t * cur_state); 330 void DDF_StateGetBecome(const char *arg, state_t * cur_state); 331 void DDF_StateGetFrame (const char *arg, state_t * cur_state); 332 void DDF_StateGetAngle (const char *arg, state_t * cur_state); 333 void DDF_StateGetSlope (const char *arg, state_t * cur_state); 334 void DDF_StateGetRGB (const char *arg, state_t * cur_state); 335 336 bool DDF_MainParseState(byte *object, state_group_t& group, 337 const char *field, const char *contents, 338 int index, bool is_last, bool is_weapon, 339 const state_starter_t *starters, 340 const actioncode_t *actions); 341 342 void DDF_StateBeginRange (state_group_t& group); 343 void DDF_StateFinishRange(state_group_t& group); 344 void DDF_StateCleanUp (void); 345 346 // DDF_SECT Code 347 void DDF_SectorInit (void); 348 void DDF_SectGetDestRef (const char *info, void *storage); 349 void DDF_SectGetExit (const char *info, void *storage); 350 void DDF_SectGetLighttype (const char *info, void *storage); 351 void DDF_SectGetMType (const char *info, void *storage); 352 void DDF_SectorCleanUp (void); 353 354 // DDF_SFX Code 355 void DDF_SFXInit (void); 356 void DDF_SFXCleanUp (void); 357 358 // DDF_SWTH Code 359 // -KM- 1998/07/31 Switch and Anim ddfs. 360 void DDF_SwitchInit (void); 361 void DDF_SwitchCleanUp (void); 362 363 // DDF_WEAP Code 364 void DDF_WeaponInit (void); 365 void DDF_WeaponCleanUp (void); 366 extern const specflags_t ammo_types[]; 367 368 // DDF_COLM Code -AJA- 1999/07/09. 369 void DDF_ColmapInit (void); 370 void DDF_ColmapCleanUp (void); 371 372 // DDF_FONT Code -AJA- 2004/11/13. 373 void DDF_FontInit (void); 374 void DDF_FontCleanUp (void); 375 376 // DDF_STYLE Code -AJA- 2004/11/14. 377 void DDF_StyleInit (void); 378 void DDF_StyleCleanUp (void); 379 380 // DDF_FONT Code -AJA- 2004/11/18. 381 void DDF_ImageInit (void); 382 void DDF_ImageCleanUp (void); 383 384 // Miscellaneous stuff needed here & there 385 extern const commandlist_t floor_commands[]; 386 extern const commandlist_t damage_commands[]; 387 388 389 #endif //__DDF_LOCAL_H__*/ 390 391 //--- editor settings --- 392 // vi:ts=4:sw=4:noexpandtab 393