diff options
Diffstat (limited to 'editlump.c')
-rw-r--r-- | editlump.c | 330 |
1 files changed, 330 insertions, 0 deletions
diff --git a/editlump.c b/editlump.c new file mode 100644 index 0000000..f55d269 --- /dev/null +++ b/editlump.c @@ -0,0 +1,330 @@ +/* + + 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 + + ------------------------------------------------------------------------- + + Editor LUMP manipulations + +*/ +static const char rcs_id[]="$Id$"; + +#include "config.h" +#include "globals.h" +#include "editvar.h" +#include "platgui.h" +#include "runcmd.h" +#include "file.h" +#include "mem.h" +#include "util.h" + + +#define M_CANCEL -1 +#define M_SWITCH_DOOM 0 +#define M_SWITCH_HEXEN 1 +#define M_EDIT_MAPINFO 2 +#define M_EDIT_SCRIPTS 3 +#define M_MAKE_BEHAVIOR 4 + +static PLAT_MENU menu[6]; +static int no=0; + + +/* ---------------------------------------- PRIVATE UTILS +*/ +static void NewMenu(void) +{ + int f; + + for(f=0;f<no;f++) + { + Release(menu[f].text); + menu[f].text=NULL; + } + + no=0; +} + + +static void AddMenu(char *text, int id) +{ + menu[no].text=Strdup(text); + menu[no].client_index=id; + menu[no].child=NULL; + + menu[++no].text=NULL; +} + + +/* ---------------------------------------- ACS COMPILATION +*/ +static char *MakeArgs(void) +{ + static char s[PATH_MAX+1]=""; + char *p; + int i; + + if (s[0]) + return(s); + + p=acc_args; + i=0; + + while(*p) + if (*p=='%') + { + p++; + + switch(*p) + { + case 'S': + strcat(s,acc_script); + i=strlen(s); + p++; + break; + + case 'O': + strcat(s,acc_object); + i=strlen(s); + p++; + break; + + default: + s[i++]='%'; + s[i]=0; + break; + } + } + else + { + s[i++]=*p++; + s[i]=0; + } + + return(s); +} + + +static int WriteScript(void) +{ + FILE *fp; + + if (!(fp=fopen(acc_script,"w"))) + return(FALSE); + + fputs(scripts,fp); + fclose(fp); + return(TRUE); +} + + +static int ReadBehavior(void) +{ + FILE *fp; + + if (!(fp=fopen(acc_object,"rb"))) + return(FALSE); + + behavior_size=(int)FLen(fp); + behavior=ReGrab(behavior,behavior_size); + + FRead(fp,behavior,behavior_size); + fclose(fp); + + return(TRUE); +} + + +static void MakeBehavior(void) +{ + char cwd[PATH_MAX]; + char path[PATH_MAX]; + char *arg[3]; + int ok; + + strcpy(cwd,Pwd()); + + arg[0]=acc_cmd; + arg[1]=MakeArgs(); + arg[2]=NULL; + + Cd(acc_dir); + + if (!WriteScript()) + { + GuiInfoBox("ERROR","ACS compilation|Failed to write|%s",acc_script); + Cd(cwd); + return; + } + + if ((ok=RunCommand(arg,path))) + { + if ((acc_always_view)&&(path[0])) + GUI_view_file("ACS Compilation",path); + } + else + if (path[0]) + GUI_view_file("ACS Compilation FAILED",path); + else + GuiInfoBox("ERROR","ACS compiler|%s|failed|" + "(no results available)",acc_cmd); + + if (path[0]) + remove(path); + + if (ok) + if (!ReadBehavior()) + GuiInfoBox("ERROR","ACS Compilation|Failed to read|%s",acc_object); + + Cd(cwd); +} + + +/* ---------------------------------------- EXPORTED FUNCS +*/ + +void EditLumpMenu(void) +{ + int redraw; + + NewMenu(); + redraw=FALSE; + + if (mapinfo_lump) + AddMenu("Edit MAPINFO",M_EDIT_MAPINFO); + + if (hexen_mode) + { + AddMenu("Edit SCRIPTS",M_EDIT_SCRIPTS); + AddMenu("Create BEHAVIOR",M_MAKE_BEHAVIOR); + + AddMenu("Switch map to DOOM mode",M_SWITCH_DOOM); + } + else + AddMenu("Switch map to HEXEN mode",M_SWITCH_HEXEN); + + switch(GUI_menu("LUMP menu",ms.x,ms.y,menu,M_CANCEL)) + { + case M_SWITCH_DOOM: + if (YesNo("Switching to DOOM mode will lose any|" + "defined SCRIPTS and BEHAVIOR lumps| |" + "Also THING, LINEDEF and SECTOR types/specials|" + "will ALMOST CERTAINLY be incorrect.| |" + "SURE you want to proceed?")) + { + redraw=TRUE; + hexen_mode=FALSE; + + if (scripts) + Release(scripts); + + scripts=NULL; + scripts_size=0; + + if (behavior) + Release(behavior); + + behavior=NULL; + behavior_size=0; + } + break; + + case M_SWITCH_HEXEN: + if (YesNo("Switching to HEXEN mode will set all|" + "THING Z co-ordinates and special args|" + "to zero, sets LINEDEF special args to|" + "zero and and create empty SCRIPTS and|" + "BEHAVIOR lumps.| |" + "Also THING, LINEDEF and SECTOR types/specials|" + "will ALMOST CERTAINLY be incorrect.| |" + "SURE you want to proceed?")) + { + int f,r; + EditThing *t; + EditLine *l; + + redraw=TRUE; + hexen_mode=TRUE; + + for(f=0;f<MapSize(thing);f++) + if ((t=GETTHING(f))) + { + t->t.z=0; + + for(r=0;r<5;r++) + t->t.args[r]=0; + } + + for(f=0;f<MapSize(linedef);f++) + if ((l=GETLINE(f))) + { + l->l.tag=0; + + for(r=0;r<5;r++) + l->l.args[r]=0; + } + } + break; + + case M_EDIT_MAPINFO: + { + char *new; + + if (!mapinfo) + mapinfo=Strdup(""); + + if ((new=GUI_text_edit("MAPINFO lump",mapinfo))) + { + Release(mapinfo); + mapinfo=new; + } + break; + } + + case M_EDIT_SCRIPTS: + { + char *new; + + if (!scripts) + scripts=Strdup(""); + + if ((new=GUI_text_edit("SCRIPTS lump",scripts))) + { + Release(scripts); + scripts=new; + scripts_size=strlen(scripts); + } + break; + } + + case M_MAKE_BEHAVIOR: + if (!scripts) + GUI_alert("Error","Need to create a script by editing|" + "it before it can be compiled","OK"); + else + MakeBehavior(); + break; + } + + if (redraw) + FullRedraw(); +} + + +/* END OF FILE */ |