From a9022b5972dc49d86f617a27940fafe9c4d0e7e7 Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 9 Jun 2011 13:46:28 +0000 Subject: Initial import of (very old) vidoom sources. --- globals.c | 1375 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1375 insertions(+) create mode 100644 globals.c (limited to 'globals.c') diff --git a/globals.c b/globals.c new file mode 100644 index 0000000..86a0add --- /dev/null +++ b/globals.c @@ -0,0 +1,1375 @@ +/* + + viDOOM - level editor for DOOM + + Copyright (C) 2000 Ian Cowburn (ianc@noddybox.demon.co.uk) + + 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 + + ------------------------------------------------------------------------- + + Global data + + All the stuff from INI file and from the config files. Note this object + also drives other objects so that the list of things they maintain is + initialised. + +*/ +static const char rcs_id[]="$Id$"; + +#include "config.h" +#include "globals.h" + +#include +#include +#include + +#include "ini.h" +#include "gfx.h" +#include "mem.h" +#include "texture.h" +#include "things.h" +#include "linedefs.h" +#include "sectors.h" +#include "genlines.h" +#include "gensect.h" +#include "specials.h" +#include "flags.h" + + +/* Constants +*/ +#define MAXLEN 1024 + +#define M_NONE -1 +#define M_THING_TYPES 0 +#define M_SECTOR_TYPES 1 +#define M_LINEDEF_FLAGS 2 +#define M_INCLUDE 3 +#define M_THING_FLAGS 4 +#define M_LINEDEF_TYPES 5 +#define M_LINEDEF_DEFAULTS 6 +#define M_SECTOR_STYLES 7 +#define M_LINEDEF_FLAGS_EXTRA 8 +#define M_EMPTY_TEXTURE_NAME 9 +#define M_THING_CLASSES 10 +#define M_LINEDEF_CLASSES 11 +#define M_SECTOR_CLASSES 12 +#define M_NORMAL_TYPES 13 +#define M_LINEDEF_CHECK_DEFAULT 14 +#define M_LINEDEF_GEN_BITMASKS 15 +#define M_LINEDEF_GEN_TYPES 16 +#define M_SECTOR_GEN_BITMASKS 17 +#define M_SECTOR_GEN_TYPES 18 +#define M_HEXEN_ACTION_CLASSES 19 +#define M_HEXEN_ACTION_SPECIALS 20 + +/* Masks for edit mode +*/ +#define DOOM_EDIT_MASK 0x01 +#define HEXEN_EDIT_MASK 0x02 + + +/* INI sections +*/ +#define GAME_INI "Game" +#define EDITOR_INI "Editor" +#define VIDOOM_INI "viDOOM" +#define CLINEDEF_INI "Check LINEDEF" +#define BUILD_INI "Node Builder" +#define ACC_INI "ACS" + +#define DOOM_INI "Doom" +#define ULT_DOOM_INI "Ultimate Doom" +#define DOOM2_INI "Doom 2" +#define FINAL_TNT_INI "TNT:Evilution" +#define FINAL_PLUT_INI "Plutonia Experiment" +#define ZDOOM_INI "ZDoom" + +/* ------------------------------ Game type +*/ +GameType game=DOOM_2; +LevelStyle level_style=DOOM_2_LEVELS; +int ask_for_game_type=FALSE; + + +/* ------------------------------ Paths +*/ +char IWAD_path[PATH_MAX+1]="." DIRSEP "DOOM2.WAD"; +char PWAD_dir[PATH_MAX+1]="." DIRSEP; +char PWAD_preload[MAX_PRELOAD_LEN]=""; +static char config_file[PATH_MAX+1]="doom2.cfg"; + + +/* ------------------------------ Editor configuration +*/ +int disp_width=640; +int disp_height=480; +int grid_onoff=TRUE; +int grid_lock=TRUE; +int grid_size=64; +double gfx_brighten=1.0; +int vertex_rad=5; +Hover hover_select=HOVER_NONE; +int clear_on_move=TRUE; +int clear_on_menu=FALSE; +Hover insert_select=HOVER_NONE; +SectorMoveMode sector_move=MOVE_RIGHT; +int ask_middle_on_2sided=TRUE; +int default_light_level=200; +int default_floor_height=0; +int default_ceiling_height=256; +NewSelect new_2sided_select=NEWSELECT_ASK; +LinedefMerge merge_linedef=MERGE_ASK; +int auto_block_linedefs=TRUE; +int default_scale=10; +DefaultEdit default_edit_mode=EDIT_SECTOR; +int left_click_move=FALSE; +int linedef_select=2; +int tag_highlight=TRUE; +int show_full_linedef_info=FALSE; + + +/* ------------------------------ viDOOM configuration +*/ +char auto_loadmap[PATH_MAX+1]=""; +int sort_textures=TRUE; +int sort_flats=TRUE; +int show_titlepic=TRUE; +int load_textures=TRUE; +int load_flats=TRUE; +int load_sprites=TRUE; +int map_warn=TRUE; +int map_exit_warn=TRUE; +int mapinfo_lump=FALSE; /* Only for ZDOOM/BOOM */ +GenericYNA create_hexen=GEN_NO; /* Only for ZDOOM/BOOM */ +int initial_empty_map=FALSE; +int overwrite_warning=TRUE; + +/* ------------------------------ Linedef flags bit and mask +*/ +int side2_bit=-1; +int side2_mask; +int block_bit=-1; +int block_mask; +int lower_peg_bit=-1; +int lower_peg_mask; +int upper_peg_bit=-1; +int upper_peg_mask; + +/* ------------------------------ Normal values +*/ +int normal_linedef=0; +int normal_sector=0; + +/* ------------------------------ LINEDEF checking +*/ +int check_line_assume_yes=FALSE; +int check_1side_lower=TRUE; +int check_1side_middle=TRUE; +int check_1side_upper=TRUE; +int check_2side_lower=TRUE; +int check_2side_middle=TRUE; +int check_2side_same_sector=TRUE; +int check_2side_upper=TRUE; + +/* ------------------------------ Node Builder config +*/ +int use_build=FALSE; +char build_cmd[PATH_MAX+1]="bsp.exe"; +char build_ignore[PATH_MAX+1]=""; +char build_in[PATH_MAX+1]="%"; +char build_out[PATH_MAX+1]="%"; +int build_in_before_out=TRUE; +int build_always_view=TRUE; + + +/* ------------------------------ ACC config +*/ +char acc_cmd[PATH_MAX+1]="acc.exe"; +char acc_dir[PATH_MAX+1]="."; +char acc_script[PATH_MAX+1]="vidoom.acc"; +char acc_object[PATH_MAX+1]="vidoom.o"; +char acc_args[PATH_MAX+1]="%S %O"; +int acc_always_view=TRUE; + + +/* ------------------------------ Texture names +*/ +char empty_texture[256]="-"; +char linedef_check_default[256]="-"; + + +/* ------------------------------ INI tables to data +*/ + +#define INI_FOR_GAME(g) { \ + INI_STR, g, "iwad", \ + IWAD_path, NULL \ + }, \ + { \ + INI_STR, g, "pwad_dir", \ + PWAD_dir, NULL \ + }, \ + { \ + INI_TOK, g, "level_style", \ + &level_style, level_style_tok \ + }, \ + { \ + INI_STR, g, "preload", \ + PWAD_preload, NULL \ + }, \ + { \ + INI_STR, g, "vidoom_config", \ + config_file, NULL \ + } + + +static TokenTable game_type_tok[]= + { + {"Doom",DOOM}, + {"Ultimate Doom",ULTIMATE_DOOM}, + {"Doom 2",DOOM_2}, + {"TNT:Evilution",FINAL_TNT}, + {"Plutonia Experiment",FINAL_PLUTONIA}, + {"ZDoom",ZDOOM}, + {NULL,0} + }; + +static TokenTable level_style_tok[]= + { + {"Doom",DOOM_LEVELS}, + {"Ultimate Doom",ULTIMATE_DOOM_LEVELS}, + {"Doom 2",DOOM_2_LEVELS}, + {NULL,0} + }; + +static TokenTable hover_type_tok[]= + { + {"none",HOVER_NONE}, + {"add",HOVER_ADD}, + {"single",HOVER_SINGLE}, + {NULL,0} + }; + +static TokenTable smove_type_tok[]= + { + {"all",MOVE_ALL}, + {"left",MOVE_LEFT}, + {"right",MOVE_RIGHT}, + {NULL,0} + }; + +static TokenTable new_select_tok[]= + { + {"never",NEWSELECT_NEVER}, + {"ask",NEWSELECT_ASK}, + {"select",NEWSELECT_SELECT}, + {NULL,0} + }; + +static TokenTable merge_mode_tok[]= + { + {"never",MERGE_NEVER}, + {"ask",MERGE_ASK}, + {"always",MERGE_ALWAYS}, + {NULL,0} + }; + +static TokenTable edit_mode_tok[]= + { + {"sector",EDIT_SECTOR}, + {"vertex",EDIT_VERTEX}, + {"linedef",EDIT_LINEDEF}, + {"thing",EDIT_THING}, + {"multi",EDIT_MULTI}, + {NULL,0} + }; + +static TokenTable YNA_tok[]= + { + {"no",GEN_NO}, + {"yes",GEN_YES}, + {"ask",GEN_ASK}, + {NULL,0} + }; + + +static INI_Table part1_ini[]= + { + /* Game type + */ + { + INI_TOK, GAME_INI, "game", + &game, game_type_tok + }, + { + INI_TOK, GAME_INI, "ask", + &ask_for_game_type, ini_yesno + }, + { + INI_INT, EDITOR_INI, "width", + &disp_width, NULL + }, + { + INI_INT, EDITOR_INI, "height", + &disp_height, NULL + }, + }; + +static INI_Table part2_ini[]= + { + /* Editor + */ + { + INI_TOK, EDITOR_INI, "grid", + &grid_onoff, ini_yesno + }, + { + INI_TOK, EDITOR_INI, "grid_lock", + &grid_lock, ini_yesno + }, + { + INI_INT, EDITOR_INI, "grid_size", + &grid_size, NULL + }, + { + INI_DOUBLE, EDITOR_INI, "bright", + &gfx_brighten, NULL + }, + { + INI_INT, EDITOR_INI, "vertex_radius", + &vertex_rad, NULL + }, + { + INI_TOK, EDITOR_INI, "hover_select", + &hover_select, hover_type_tok + }, + { + INI_TOK, EDITOR_INI, "clear_on_move", + &clear_on_move, ini_yesno + }, + { + INI_TOK, EDITOR_INI, "clear_on_menu", + &clear_on_menu, ini_yesno + }, + { + INI_TOK, EDITOR_INI, "insert_select", + &insert_select, hover_type_tok + }, + { + INI_TOK, EDITOR_INI, "sector_move", + §or_move, smove_type_tok + }, + { + INI_TOK, EDITOR_INI, "ask_middle_on_2sided", + &ask_middle_on_2sided, ini_yesno + }, + { + INI_INT, EDITOR_INI, "default_light_level", + &default_light_level, NULL + }, + { + INI_INT, EDITOR_INI, "default_floor_height", + &default_floor_height, NULL + }, + { + INI_INT,EDITOR_INI,"default_ceiling_height", + &default_ceiling_height, NULL + }, + { + INI_TOK, EDITOR_INI, "new_2sided_select", + &new_2sided_select, new_select_tok + }, + { + INI_TOK, EDITOR_INI, "merge_linedef", + &merge_linedef, merge_mode_tok + }, + { + INI_TOK, EDITOR_INI, "auto_block_linedefs", + &auto_block_linedefs, ini_yesno + }, + { + INI_INT, EDITOR_INI, "default_scale", + &default_scale, NULL + }, + { + INI_TOK, EDITOR_INI, "default_edit_mode", + &default_edit_mode, edit_mode_tok + }, + { + INI_TOK, EDITOR_INI, "left_click_move", + &left_click_move, ini_yesno + }, + { + INI_INT, EDITOR_INI, "linedef_select", + &linedef_select, NULL + }, + { + INI_TOK, EDITOR_INI,"tag_highlight", + &tag_highlight, ini_yesno + }, + { + INI_TOK,EDITOR_INI,"show_full_linedef_info", + &show_full_linedef_info, ini_yesno + }, + + /* viDOOM + */ + { + INI_TOK, VIDOOM_INI, "sort_texture_names", + &sort_textures, ini_yesno + }, + { + INI_TOK, VIDOOM_INI, "sort_flat_names", + &sort_flats, ini_yesno + }, + { + INI_TOK, VIDOOM_INI, "show_titlepic", + &show_titlepic, ini_yesno + }, + { + INI_TOK, VIDOOM_INI, "load_textures", + &load_textures, ini_yesno + }, + { + INI_TOK, VIDOOM_INI, "load_flats", + &load_flats, ini_yesno + }, + { + INI_TOK, VIDOOM_INI, "load_sprites", + &load_sprites, ini_yesno + }, + { + INI_TOK, VIDOOM_INI, "map_clear_warning", + &map_warn, ini_yesno + }, + { + INI_TOK, VIDOOM_INI, "map_exit_warning", + &map_exit_warn, ini_yesno + }, + { + INI_TOK, VIDOOM_INI, "initial_empty_map", + &initial_empty_map, ini_yesno + }, + { + INI_TOK, VIDOOM_INI, "overwrite_warning", + &overwrite_warning, ini_yesno + }, + { + INI_STR, VIDOOM_INI, "auto_loadmap", + auto_loadmap, NULL + }, + + /* Check LINEDEF + */ + { + INI_TOK, CLINEDEF_INI, "assume_yes", + &check_line_assume_yes, ini_yesno + }, + { + INI_TOK, CLINEDEF_INI, "check_1side_lower", + &check_1side_lower, ini_yesno + }, + { + INI_TOK, CLINEDEF_INI, "check_1side_middle", + &check_1side_middle, ini_yesno + }, + { + INI_TOK, CLINEDEF_INI, "check_1side_upper", + &check_1side_upper, ini_yesno + }, + { + INI_TOK, CLINEDEF_INI, "check_2side_lower", + &check_2side_lower, ini_yesno + }, + { + INI_TOK, CLINEDEF_INI, "check_2side_middle", + &check_2side_middle, ini_yesno + }, + { + INI_TOK, CLINEDEF_INI, + "check_2side_same_sector", + &check_2side_same_sector, ini_yesno + }, + { + INI_TOK, CLINEDEF_INI, "check_2side_upper", + &check_2side_upper, ini_yesno + }, + + /* Node builder + */ + { + INI_TOK, BUILD_INI, "use", + &use_build, ini_yesno + }, + { + INI_STR, BUILD_INI, "command", + build_cmd, NULL + }, + { + INI_STR, BUILD_INI, "ignore", + build_ignore, NULL + }, + { + INI_STR, BUILD_INI, "infile", + build_in, NULL + }, + { + INI_STR, BUILD_INI, "outfile", + build_out, NULL + }, + { + INI_TOK, BUILD_INI, "in_before_out", + &build_in_before_out, ini_yesno + }, + { + INI_TOK, BUILD_INI, "always_view_output", + &build_always_view, ini_yesno + }, + + /* ACC + */ + { + INI_STR, ACC_INI, "command", + acc_cmd, NULL + }, + { + INI_STR, ACC_INI, "dir", + acc_dir, NULL + }, + { + INI_STR, ACC_INI, "script", + acc_script, NULL + }, + { + INI_STR, ACC_INI, "object", + acc_object, NULL + }, + { + INI_STR, ACC_INI, "args", + acc_args, NULL + }, + { + INI_TOK, ACC_INI, "always_view_output", + &acc_always_view, ini_yesno + }, + }; + +static INI_Table doom_ini[]={INI_FOR_GAME(DOOM_INI)}; +static INI_Table ult_doom_ini[]={INI_FOR_GAME(ULT_DOOM_INI)}; +static INI_Table doom_2_ini[]={INI_FOR_GAME(DOOM2_INI)}; +static INI_Table tnt_ini[]={INI_FOR_GAME(FINAL_TNT_INI)}; +static INI_Table plut_ini[]={INI_FOR_GAME(FINAL_PLUT_INI)}; + +static INI_Table zdoom_ini[]= + { + INI_FOR_GAME(ZDOOM_INI), + { + INI_TOK, ZDOOM_INI, "mapinfo_lump", + &mapinfo_lump, ini_yesno + }, + { + INI_TOK, ZDOOM_INI, "create_hexen", + &create_hexen, YNA_tok + } + }; + + + +/* ------------------------------ TYPES +*/ +typedef struct + { + char *str; + int val; + } StrList; + + +/* ------------------------------ PRIVATE FUNCTIONS +*/ + +static void CheckVals(void) +{ + FILE *fp; + + grid_size=MAX(grid_size,2); + default_light_level=default_light_level%256; + linedef_select=MAX(linedef_select,1); + + /* Check config file exists + */ + if (!(fp=fopen(config_file,"r"))) + GFX_exit(EXIT_FAILURE,"Couldn't open config file %s\n",config_file); + + fclose(fp); +} + + +static int StrToInt(StrList s[],char *val,int def) +{ + int f; + int m; + + f=0; + m=def; + + while((s[f].str)&&(m==def)) + { + if (STREQ(s[f].str,val)) + m=s[f].val; + f++; + } + + return(m); +} + + +static char *GetLine(FILE *fp) +{ + static char s[MAXLEN+1]; + int l,f; + + fgets(s,MAXLEN,fp); + + if (feof(fp)) + return(FALSE); + + l=strlen(s)-1; + + if ((l>=0)&&(s[l]=='\n')) + s[l]=0; + + l=strlen(s)-1; + + if ((l>=0)&&(s[l]=='\r')) + s[l]=0; + + l=strlen(s); + for(f=0;f