diff options
author | Simon Howard | 2005-10-02 23:49:01 +0000 |
---|---|---|
committer | Simon Howard | 2005-10-02 23:49:01 +0000 |
commit | d0ab12d7099bb3db032c225b71c1a170c040d9ac (patch) | |
tree | fdbfd11128f42503e21af662de434ed04034fa3d | |
parent | 33b6861e500ee5483e89e325008fea68627efbd3 (diff) | |
download | chocolate-doom-d0ab12d7099bb3db032c225b71c1a170c040d9ac.tar.gz chocolate-doom-d0ab12d7099bb3db032c225b71c1a170c040d9ac.tar.bz2 chocolate-doom-d0ab12d7099bb3db032c225b71c1a170c040d9ac.zip |
The beginnings of dehacked support
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 153
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/d_main.c | 10 | ||||
-rw-r--r-- | src/deh_ammo.c | 59 | ||||
-rw-r--r-- | src/deh_defs.h | 68 | ||||
-rw-r--r-- | src/deh_frame.c | 137 | ||||
-rw-r--r-- | src/deh_io.c | 169 | ||||
-rw-r--r-- | src/deh_io.h | 45 | ||||
-rw-r--r-- | src/deh_main.c | 274 | ||||
-rw-r--r-- | src/deh_main.h | 44 | ||||
-rw-r--r-- | src/deh_ptr.c | 134 | ||||
-rw-r--r-- | src/deh_text.c | 59 | ||||
-rw-r--r-- | src/deh_thing.c | 200 | ||||
-rw-r--r-- | src/deh_weapon.c | 59 |
13 files changed, 1260 insertions, 3 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 622f5d2f..de6bdac8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -27,7 +27,10 @@ doomtype.h info.h m_swap.c p_sight.c r_segs.h w_wad.h \ d_player.h i_sound.c m_swap.h p_spec.c r_sky.c z_zone.c \ dstrings.c i_sound.h p_ceilng.c p_spec.h r_sky.h z_zone.h \ dstrings.h i_system.c p_doors.c p_switch.c r_state.h mmus2mid.c \ -d_textur.h i_system.h p_enemy.c p_telept.c r_things.c mmus2mid.h +d_textur.h i_system.h p_enemy.c p_telept.c r_things.c mmus2mid.h \ +deh_defs.h deh_frame.c deh_main.c deh_ptr.c deh_text.c deh_thing.c \ +deh_io.c deh_io.h deh_ammo.c deh_weapon.c + if HAVE_WINDRES chocolate_doom_SOURCES=$(SOURCE_FILES) chocolate-doom-res.rc diff --git a/src/d_main.c b/src/d_main.c index 5953a991..23d9b9af 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: d_main.c 149 2005-10-02 04:16:47Z fraggle $ +// $Id: d_main.c 153 2005-10-02 23:49:01Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -22,6 +22,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.17 2005/10/02 23:49:01 fraggle +// The beginnings of dehacked support +// // Revision 1.16 2005/10/02 04:16:47 fraggle // Fixes for Final Doom // @@ -90,7 +93,7 @@ //----------------------------------------------------------------------------- -static const char rcsid[] = "$Id: d_main.c 149 2005-10-02 04:16:47Z fraggle $"; +static const char rcsid[] = "$Id: d_main.c 153 2005-10-02 23:49:01Z fraggle $"; #define BGCOLOR 7 #define FGCOLOR 8 @@ -109,6 +112,7 @@ static const char rcsid[] = "$Id: d_main.c 149 2005-10-02 04:16:47Z fraggle $"; #include "config.h" +#include "deh_main.h" #include "doomdef.h" #include "doomstat.h" @@ -1208,5 +1212,7 @@ void D_DoomMain (void) } + DEH_CheckCommandLine(); + D_DoomLoop (); // never returns } diff --git a/src/deh_ammo.c b/src/deh_ammo.c new file mode 100644 index 00000000..fe626a4a --- /dev/null +++ b/src/deh_ammo.c @@ -0,0 +1,59 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id: deh_ammo.c 153 2005-10-02 23:49:01Z fraggle $ +// +// Copyright(C) 2005 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. +// +// $Log$ +// Revision 1.1 2005/10/02 23:49:01 fraggle +// The beginnings of dehacked support +// +// +//----------------------------------------------------------------------------- +// +// Parses "Ammo" sections in dehacked files +// +//----------------------------------------------------------------------------- + +#include "doomdef.h" +#include "doomtype.h" +#include "deh_defs.h" + +static void *DEH_AmmoStart(deh_context_t *context, char *line) +{ + return NULL; +} + +static void DEH_AmmoEnd(deh_context_t *context, void *tag) +{ +} + +static void DEH_AmmoParseLine(deh_context_t *context, char *line, void *tag) +{ +} + +deh_section_t deh_section_ammo = +{ + "Ammo", + NULL, + DEH_AmmoStart, + DEH_AmmoParseLine, + DEH_AmmoEnd, +}; + diff --git a/src/deh_defs.h b/src/deh_defs.h new file mode 100644 index 00000000..c31893a7 --- /dev/null +++ b/src/deh_defs.h @@ -0,0 +1,68 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id: deh_defs.h 153 2005-10-02 23:49:01Z fraggle $ +// +// Copyright(C) 2005 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. +// +// $Log$ +// Revision 1.1 2005/10/02 23:49:01 fraggle +// The beginnings of dehacked support +// +// +//----------------------------------------------------------------------------- +// +// Definitions for use in the dehacked code +// +//----------------------------------------------------------------------------- + +#ifndef DEH_DEFS_H +#define DEH_DEFS_H + +typedef struct deh_context_s deh_context_t; +typedef struct deh_section_s deh_section_t; +typedef void (*deh_section_init_t)(void); +typedef void *(*deh_section_start_t)(deh_context_t *context, char *line); +typedef void (*deh_section_end_t)(deh_context_t *context, void *tag); +typedef void (*deh_line_parser_t)(deh_context_t *context, char *line, void *tag); + +struct deh_section_s +{ + char *name; + + // Called on startup to initialise code + + deh_section_init_t init; + + // This is called when a new section is started. The pointer + // returned is used as a tag for the following calls. + + deh_section_start_t start; + + // This is called for each line in the section + + deh_line_parser_t line_parser; + + // This is called at the end of the section for any cleanup + + deh_section_end_t end; +}; + +#endif /* #ifndef DEH_DEFS_H */ + + diff --git a/src/deh_frame.c b/src/deh_frame.c new file mode 100644 index 00000000..592223e7 --- /dev/null +++ b/src/deh_frame.c @@ -0,0 +1,137 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id: deh_frame.c 153 2005-10-02 23:49:01Z fraggle $ +// +// Copyright(C) 2005 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. +// +// $Log$ +// Revision 1.1 2005/10/02 23:49:01 fraggle +// The beginnings of dehacked support +// +// +//----------------------------------------------------------------------------- +// +// Parses "Frame" sections in dehacked files +// +//----------------------------------------------------------------------------- + +#include <stdlib.h> + +#include "doomdef.h" +#include "doomtype.h" +#include "info.h" + +#include "deh_defs.h" +#include "deh_main.h" + +static void *DEH_FrameStart(deh_context_t *context, char *line) +{ + int frame_number = 0; + state_t *state; + + sscanf(line, "Frame %i", &frame_number); + + // dehacked files are indexed from 1, not 0 + + --frame_number; + + if (frame_number < 0 || frame_number >= NUMSTATES) + return NULL; + + state = &states[frame_number]; + + return state; +} + +static void DEH_FrameEnd(deh_context_t *context, void *tag) +{ +} + +static void DEH_FrameParseLine(deh_context_t *context, char *line, void *tag) +{ + state_t *state; + char *variable_name, *value; + int ivalue; + + if (tag == NULL) + return; + + state = (state_t *) tag; + + // Parse the assignment + + if (!DEH_ParseAssignment(line, &variable_name, &value)) + { + // Failed to parse + + return; + } + +// printf("Set %s to %s for state\n", variable_name, value); + + // all values are integers + + ivalue = atoi(value); + + // set the appropriate field + + if (!strcasecmp(variable_name, "Sprite number")) + { + state->sprite = ivalue; + } + else if (!strcasecmp(variable_name, "Sprite subnumber")) + { + state->frame = ivalue; + } + else if (!strcasecmp(variable_name, "Duration")) + { + state->tics = ivalue; + } + else if (!strcasecmp(variable_name, "Next frame")) + { + state->nextstate = ivalue; + } + else if (!strcasecmp(variable_name, "Codep Frame")) + { + // FIXME: code pointer + } + else if (!strcasecmp(variable_name, "Unknown 1")) + { + state->misc1 = ivalue; + } + else if (!strcasecmp(variable_name, "Unknown 2")) + { + state->misc2 = ivalue; + } + else + { + printf("Unknown variable name %s\n", variable_name); + } + +} + +deh_section_t deh_section_frame = +{ + "Frame", + NULL, + DEH_FrameStart, + DEH_FrameParseLine, + DEH_FrameEnd, +}; + diff --git a/src/deh_io.c b/src/deh_io.c new file mode 100644 index 00000000..56b75e6b --- /dev/null +++ b/src/deh_io.c @@ -0,0 +1,169 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id: deh_io.c 153 2005-10-02 23:49:01Z fraggle $ +// +// Copyright(C) 2005 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. +// +// $Log$ +// Revision 1.1 2005/10/02 23:49:01 fraggle +// The beginnings of dehacked support +// +// +//----------------------------------------------------------------------------- +// +// Dehacked I/O code (does all reads from dehacked files) +// +//----------------------------------------------------------------------------- + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "z_zone.h" + +#include "deh_defs.h" +#include "deh_io.h" + +struct deh_context_s +{ + FILE *stream; + char *readbuffer; + int readbuffer_size; +}; + +// Open a dehacked file for reading +// Returns NULL if open failed + +deh_context_t *DEH_OpenFile(char *filename) +{ + FILE *fstream; + deh_context_t *context; + + fstream = fopen(filename, "r"); + + if (fstream == NULL) + return NULL; + + context = Z_Malloc(sizeof(*context), PU_STATIC, NULL); + context->stream = fstream; + + // Initial read buffer size of 128 bytes + + context->readbuffer_size = 128; + context->readbuffer = Z_Malloc(context->readbuffer_size, PU_STATIC, NULL); + + return context; +} + +// Close dehacked file + +void DEH_CloseFile(deh_context_t *context) +{ + fclose(context->stream); + Z_Free(context->readbuffer); + Z_Free(context); +} + +// Reads a single character from a dehacked file + +int DEH_GetChar(deh_context_t *context) +{ + int result; + + // Read characters, but ignore carriage returns + // Essentially this is a DOS->Unix conversion + + do + { + if (feof(context->stream)) + { + // end of file + + result = -1; + } + else + { + result = fgetc(context->stream); + } + + } while (result == '\r'); + + return result; +} + +// Increase the read buffer size + +static void IncreaseReadBuffer(deh_context_t *context) +{ + char *newbuffer; + int newbuffer_size; + + newbuffer_size = context->readbuffer_size * 2; + newbuffer = Z_Malloc(newbuffer_size, PU_STATIC, NULL); + + memcpy(newbuffer, context->readbuffer, context->readbuffer_size); + + Z_Free(context->readbuffer); + + context->readbuffer = newbuffer; + context->readbuffer_size = newbuffer_size; +} + +// Read a whole line + +char *DEH_ReadLine(deh_context_t *context) +{ + char *p; + int c; + int pos; + + for (pos=0; ; ++pos) + { + c = DEH_GetChar(context); + + if (c < 0) + { + // end of file + + return NULL; + } + + // cope with lines of any length: increase the buffer size + + if (pos >= context->readbuffer_size) + { + IncreaseReadBuffer(context); + } + + if (c == '\n') + { + // end of line: a full line has been read + + context->readbuffer[pos] = '\0'; + break; + } + else + { + context->readbuffer[pos] = (char) c; + } + } + + return context->readbuffer; +} + diff --git a/src/deh_io.h b/src/deh_io.h new file mode 100644 index 00000000..96de223d --- /dev/null +++ b/src/deh_io.h @@ -0,0 +1,45 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id: deh_io.h 153 2005-10-02 23:49:01Z fraggle $ +// +// Copyright(C) 2005 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. +// +// $Log$ +// Revision 1.1 2005/10/02 23:49:01 fraggle +// The beginnings of dehacked support +// +// +//----------------------------------------------------------------------------- +// +// Dehacked I/O code (does all reads from dehacked files) +// +//----------------------------------------------------------------------------- + +#ifndef DEH_IO_H +#define DEH_IO_H + +#include "deh_defs.h" + +deh_context_t *DEH_OpenFile(char *filename); +void DEH_CloseFile(deh_context_t *context); +int DEH_GetChar(deh_context_t *context); +char *DEH_ReadLine(deh_context_t *context); + +#endif /* #ifndef DEH_IO_H */ + diff --git a/src/deh_main.c b/src/deh_main.c new file mode 100644 index 00000000..22391785 --- /dev/null +++ b/src/deh_main.c @@ -0,0 +1,274 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id: deh_main.c 153 2005-10-02 23:49:01Z fraggle $ +// +// Copyright(C) 2005 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. +// +// $Log$ +// Revision 1.1 2005/10/02 23:49:01 fraggle +// The beginnings of dehacked support +// +// +//----------------------------------------------------------------------------- +// +// Main dehacked code +// +//----------------------------------------------------------------------------- + +#include <ctype.h> +#include <strings.h> + +#include "doomdef.h" +#include "doomtype.h" +#include "m_argv.h" + +#include "deh_defs.h" +#include "deh_io.h" + +// deh_ammo.c: +extern deh_section_t deh_section_ammo; +// deh_frame.c: +extern deh_section_t deh_section_frame; +// deh_pointer.c: +extern deh_section_t deh_section_pointer; +// deh_text.c: +extern deh_section_t deh_section_text; +// deh_thing.c: +extern deh_section_t deh_section_thing; +// deh_weapon.c: +extern deh_section_t deh_section_weapon; + +// +// List of section types: +// + +static deh_section_t *section_types[] = +{ + &deh_section_ammo, + &deh_section_frame, + &deh_section_pointer, + &deh_section_text, + &deh_section_thing, + &deh_section_weapon, +}; + +static int num_section_types = sizeof(section_types) / sizeof(*section_types); + +// Called on startup to call the Init functions + +static void InitialiseSections(void) +{ + int i; + + for (i=0; i<num_section_types; ++i) + { + if (section_types[i]->init != NULL) + { + section_types[i]->init(); + } + } +} + +// Given a section name, get the section structure which corresponds + +static deh_section_t *GetSectionByName(char *name) +{ + int i; + + for (i=0; i<num_section_types; ++i) + { + if (!strcasecmp(section_types[i]->name, name)) + { + return section_types[i]; + } + } + + return NULL; +} + +// Is the string passed just whitespace? + +static boolean IsWhitespace(char *s) +{ + for (; *s; ++s) + { + if (!isspace(*s)) + return false; + } + + return true; +} + +// Strip whitespace from the start and end of a string + +static char *CleanString(char *s) +{ + char *strending; + + // Leading whitespace + + while (*s && isspace(*s)) + ++s; + + // Trailing whitespace + + strending = s + strlen(s) - 1; + + while (strlen(s) > 0 && isspace(*strending)) + { + *strending = '\0'; + --strending; + } + + return s; +} + +// This pattern is used a lot of times in different sections, +// an assignment is essentially just a statement of the form: +// +// Variable Name = Value +// +// The variable name can include spaces or any other characters. +// The string is split on the '=', essentially. +// +// Returns true if read correctly + +boolean DEH_ParseAssignment(char *line, char **variable_name, char **value) +{ + char *p; + + // find the equals + + p = strchr(line, '='); + + if (p == NULL && p-line > 2) + { + return false; + } + + // variable name at the start + // turn the '=' into a \0 to terminate the string here + + *p = '\0'; + *variable_name = CleanString(line); + + // value immediately follows the '=' + + *value = CleanString(p+1); + + return true; +} + +// Parses a dehacked file by reading from the context + +static void DEH_ParseContext(deh_context_t *context) +{ + deh_section_t *current_section = NULL; + char section_name[20]; + void *tag = NULL; + char *line; + + for (;;) + { + // read a new line + + line = DEH_ReadLine(context); + + // end of file? + + if (line == NULL) + return; + + if (IsWhitespace(line)) + { + if (current_section != NULL) + { + // end of section + + current_section->end(context, tag); + //printf("end %s tag\n", current_section->name); + current_section = NULL; + } + } + else + { + if (current_section != NULL) + { + // parse this line + + current_section->line_parser(context, line, tag); + } + else + { + // possibly the start of a new section + + sscanf(line, "%19s", section_name); + + current_section = GetSectionByName(section_name); + + if (current_section != NULL) + { + tag = current_section->start(context, line); + //printf("started %s tag\n", section_name); + } + else + { + //printf("unknown section name %s\n", section_name); + } + } + } + } +} + +// Parses a dehacked file + +static void DEH_ParseFile(char *filename) +{ + deh_context_t *context; + + context = DEH_OpenFile(filename); + + if (context == NULL) + { + fprintf(stderr, "DEH_ParseFile: Unable to open %s\n", filename); + return; + } + + DEH_ParseContext(context); + + DEH_CloseFile(context); +} + +// Checks the command line for -deh argument + +void DEH_CheckCommandLine(void) +{ + int argc; + + InitialiseSections(); + + argc = M_CheckParm("-deh"); + + if (argc > 0) + { + DEH_ParseFile(myargv[argc+1]); + } +} + + diff --git a/src/deh_main.h b/src/deh_main.h new file mode 100644 index 00000000..10604b1c --- /dev/null +++ b/src/deh_main.h @@ -0,0 +1,44 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id: deh_main.h 153 2005-10-02 23:49:01Z fraggle $ +// +// Copyright(C) 2005 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. +// +// $Log$ +// Revision 1.1 2005/10/02 23:49:01 fraggle +// The beginnings of dehacked support +// +// +//----------------------------------------------------------------------------- +// +// Dehacked entrypoint and common code +// +//----------------------------------------------------------------------------- + +#ifndef DEH_MAIN_H +#define DEH_MAIN_H + +#include "doomtype.h" + +void DEH_CheckCommandLine(void); + +boolean DEH_ParseAssignment(char *line, char **variable_name, char **value); + +#endif /* #ifndef DEH_MAIN_H */ + diff --git a/src/deh_ptr.c b/src/deh_ptr.c new file mode 100644 index 00000000..d9217f26 --- /dev/null +++ b/src/deh_ptr.c @@ -0,0 +1,134 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id: deh_ptr.c 153 2005-10-02 23:49:01Z fraggle $ +// +// Copyright(C) 2005 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. +// +// $Log$ +// Revision 1.1 2005/10/02 23:49:01 fraggle +// The beginnings of dehacked support +// +// +//----------------------------------------------------------------------------- +// +// Parses Action Pointer entries in dehacked files +// +//----------------------------------------------------------------------------- + +#include <stdlib.h> +#include <string.h> + +#include "doomdef.h" +#include "doomtype.h" +#include "info.h" + +#include "deh_defs.h" +#include "deh_main.h" + +static actionf_t codeptrs[NUMSTATES]; + +static void DEH_PointerInit(void) +{ + int i; + + // Initialise list of dehacked pointers + + for (i=0; i<NUMSTATES; ++i) + codeptrs[i] = states[i].action; +} + +static void *DEH_PointerStart(deh_context_t *context, char *line) +{ + int frame_number = 0; + + // FIXME: can the third argument here be something other than "Frame" + // or are we ok? + + sscanf(line, "%*s %*i (%*s %i)", &frame_number); + + // states are indexed from 1 in dehacked files + + --frame_number; + + if (frame_number < 0 || frame_number >= NUMSTATES) + return NULL; + + return &states[frame_number]; +} + +static void DEH_PointerEnd(deh_context_t *context, void *tag) +{ +} + +static void DEH_PointerParseLine(deh_context_t *context, char *line, void *tag) +{ + state_t *state; + char *variable_name, *value; + int ivalue; + + if (tag == NULL) + return; + + state = (state_t *) tag; + + // Parse the assignment + + if (!DEH_ParseAssignment(line, &variable_name, &value)) + { + // Failed to parse + + return; + } + +// printf("Set %s to %s for state\n", variable_name, value); + + // all values are integers + + ivalue = atoi(value); + + // set the appropriate field + + if (!strcasecmp(variable_name, "Codep frame")) + { + if (ivalue < 0 || ivalue >= NUMSTATES) + { + fprintf(stderr, "DEH_PointerParseLine: Invalid state %i\n", + ivalue); + } + else + { + state->action = codeptrs[ivalue]; + } + } + else + { + fprintf(stderr, "DEH_PointerParseLine: Unknown variable name '%s'\n", + variable_name); + } +} + +deh_section_t deh_section_pointer = +{ + "Pointer", + DEH_PointerInit, + DEH_PointerStart, + DEH_PointerParseLine, + DEH_PointerEnd, +}; + diff --git a/src/deh_text.c b/src/deh_text.c new file mode 100644 index 00000000..ae50d5bf --- /dev/null +++ b/src/deh_text.c @@ -0,0 +1,59 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id: deh_text.c 153 2005-10-02 23:49:01Z fraggle $ +// +// Copyright(C) 2005 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. +// +// $Log$ +// Revision 1.1 2005/10/02 23:49:01 fraggle +// The beginnings of dehacked support +// +// +//----------------------------------------------------------------------------- +// +// Parses Text substitution sections in dehacked files +// +//----------------------------------------------------------------------------- + +#include "doomdef.h" +#include "doomtype.h" +#include "deh_defs.h" + +static void *DEH_TextStart(deh_context_t *context, char *line) +{ + return NULL; +} + +static void DEH_TextEnd(deh_context_t *context, void *tag) +{ +} + +static void DEH_TextParseLine(deh_context_t *context, char *line, void *tag) +{ +} + +deh_section_t deh_section_text = +{ + "Text", + NULL, + DEH_TextStart, + DEH_TextParseLine, + DEH_TextEnd, +}; + diff --git a/src/deh_thing.c b/src/deh_thing.c new file mode 100644 index 00000000..f4c79f6c --- /dev/null +++ b/src/deh_thing.c @@ -0,0 +1,200 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id: deh_thing.c 153 2005-10-02 23:49:01Z fraggle $ +// +// Copyright(C) 2005 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. +// +// $Log$ +// Revision 1.1 2005/10/02 23:49:01 fraggle +// The beginnings of dehacked support +// +// +//----------------------------------------------------------------------------- +// +// Parses "Thing" sections in dehacked files +// +//----------------------------------------------------------------------------- + +#include <stdlib.h> + +#include "doomdef.h" +#include "doomtype.h" + +#include "deh_defs.h" +#include "deh_main.h" + +#include "info.h" + +static void *DEH_ThingStart(deh_context_t *context, char *line) +{ + int thing_number = 0; + mobjinfo_t *mobj; + + sscanf(line, "Thing %i", &thing_number); + + // dehacked files are indexed from 1 + --thing_number; + + if (thing_number < 0 || thing_number >= NUMMOBJTYPES) + return NULL; + + mobj = &mobjinfo[thing_number]; + + return mobj; +} + +static void DEH_ThingEnd(deh_context_t *context, void *tag) +{ +} + +static void DEH_ThingParseLine(deh_context_t *context, char *line, void *tag) +{ + mobjinfo_t *mobj; + char *variable_name, *value; + int ivalue; + + if (tag == NULL) + return; + + mobj = (mobjinfo_t *) tag; + + // Parse the assignment + + if (!DEH_ParseAssignment(line, &variable_name, &value)) + { + // Failed to parse + + return; + } + +// printf("Set %s to %s for mobj\n", variable_name, value); + + // all values are integers + + ivalue = atoi(value); + + // set the appropriate field + + if (!strcasecmp(variable_name, "ID #")) + { + mobj->doomednum = ivalue; + } + else if (!strcasecmp(variable_name, "Initial frame")) + { + mobj->spawnstate = ivalue; + } + else if (!strcasecmp(variable_name, "Hit points")) + { + mobj->spawnhealth = ivalue; + } + else if (!strcasecmp(variable_name, "First moving frame")) + { + mobj->seestate = ivalue; + } + else if (!strcasecmp(variable_name, "Alert sound")) + { + mobj->seesound = ivalue; + } + else if (!strcasecmp(variable_name, "Reaction time")) + { + mobj->reactiontime = ivalue; + } + else if (!strcasecmp(variable_name, "Attack sound")) + { + mobj->attacksound = ivalue; + } + else if (!strcasecmp(variable_name, "Injury frame")) + { + mobj->painstate = ivalue; + } + else if (!strcasecmp(variable_name, "Pain chance")) + { + mobj->painchance = ivalue; + } + else if (!strcasecmp(variable_name, "Pain sound")) + { + mobj->painsound = ivalue; + } + else if (!strcasecmp(variable_name, "Close attack frame")) + { + mobj->meleestate = ivalue; + } + else if (!strcasecmp(variable_name, "Far attack frame")) + { + mobj->missilestate = ivalue; + } + else if (!strcasecmp(variable_name, "Death frame")) + { + mobj->deathstate = ivalue; + } + else if (!strcasecmp(variable_name, "Exploding frame")) + { + mobj->xdeathstate = ivalue; + } + else if (!strcasecmp(variable_name, "Death sound")) + { + mobj->deathsound = ivalue; + } + else if (!strcasecmp(variable_name, "Speed")) + { + mobj->speed = ivalue; + } + else if (!strcasecmp(variable_name, "Width")) + { + mobj->radius = ivalue; + } + else if (!strcasecmp(variable_name, "Height")) + { + mobj->height = ivalue; + } + else if (!strcasecmp(variable_name, "Mass")) + { + mobj->mass = ivalue; + } + else if (!strcasecmp(variable_name, "Missile damage")) + { + mobj->damage = ivalue; + } + else if (!strcasecmp(variable_name, "Action sound")) + { + mobj->activesound = ivalue; + } + else if (!strcasecmp(variable_name, "Bits")) + { + mobj->flags = ivalue; + } + else if (!strcasecmp(variable_name, "Respawn frame")) + { + mobj->raisestate = ivalue; + } + else + { + printf("Unknown variable name %s\n", variable_name); + } +} + +deh_section_t deh_section_thing = +{ + "Thing", + NULL, + DEH_ThingStart, + DEH_ThingParseLine, + DEH_ThingEnd, +}; + diff --git a/src/deh_weapon.c b/src/deh_weapon.c new file mode 100644 index 00000000..682b865c --- /dev/null +++ b/src/deh_weapon.c @@ -0,0 +1,59 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// $Id: deh_weapon.c 153 2005-10-02 23:49:01Z fraggle $ +// +// Copyright(C) 2005 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. +// +// $Log$ +// Revision 1.1 2005/10/02 23:49:01 fraggle +// The beginnings of dehacked support +// +// +//----------------------------------------------------------------------------- +// +// Parses "Weapon" sections in dehacked files +// +//----------------------------------------------------------------------------- + +#include "doomdef.h" +#include "doomtype.h" +#include "deh_defs.h" + +static void *DEH_WeaponStart(deh_context_t *context, char *line) +{ + return NULL; +} + +static void DEH_WeaponEnd(deh_context_t *context, void *tag) +{ +} + +static void DEH_WeaponParseLine(deh_context_t *context, char *line, void *tag) +{ +} + +deh_section_t deh_section_weapon = +{ + "Weapon", + NULL, + DEH_WeaponStart, + DEH_WeaponParseLine, + DEH_WeaponEnd, +}; + |