summaryrefslogtreecommitdiff
path: root/linedefs.c
diff options
context:
space:
mode:
Diffstat (limited to 'linedefs.c')
-rw-r--r--linedefs.c371
1 files changed, 371 insertions, 0 deletions
diff --git a/linedefs.c b/linedefs.c
new file mode 100644
index 0000000..bfeb6bc
--- /dev/null
+++ b/linedefs.c
@@ -0,0 +1,371 @@
+/*
+
+ 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
+
+ -------------------------------------------------------------------------
+
+ Handles definition and storage of the supported THINGS
+
+*/
+static const char rcs_id[]="$Id$";
+
+#include "config.h"
+#include "globals.h"
+
+#include "platgui.h"
+#include "gfx.h"
+#include "linedefs.h"
+#include "mem.h"
+#include "list.h"
+#include "map.h"
+
+
+/* ---------------------------------------- TYPES AND VARS
+*/
+typedef struct
+ {
+ char *name;
+ } LineClass;
+
+typedef struct
+ {
+ int class;
+ int id;
+ char *name;
+ } LineInfo;
+
+typedef struct
+ {
+ char *name;
+ int id;
+ int two;
+ } LineDefault;
+
+
+static int no_classes=0;
+
+static Map line_class=NULL;
+static List line_list=NULL;
+static Map line_def=NULL;
+
+static PLAT_PICKLIST **picklist=NULL;
+
+static PLAT_MENU *line_menu=NULL;
+
+static char *line_flags[17]=
+ {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
+ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
+
+static char line_flags_sh[16]=
+ {'?','?','?','?','?','?','?','?',
+ '?','?','?','?','?','?','?','?'};
+
+static int line_flags_max=-1;
+
+
+static char **line_def_plist=NULL;
+
+
+/* ---------------------------------------- PRIVATE FUNCTIONS
+*/
+static PLAT_PICKLIST *LinedefPicklist(int class)
+{
+ LineInfo *li;
+ Iterator i;
+ int no;
+ int f;
+
+ if (picklist[class])
+ return(picklist[class]);
+ else
+ {
+ no=0;
+ i=ListIterator(line_list);
+
+ while(i)
+ {
+ li=IteratorData(i);
+
+ if (li->class==class)
+ no++;
+
+ i=IteratorNext(i);
+ }
+
+ picklist[class]=Grab(sizeof(PLAT_PICKLIST)*(no+1));
+
+ i=ListIterator(line_list);
+
+ f=0;
+ while(i)
+ {
+ li=IteratorData(i);
+
+ if (li->class==class)
+ {
+ picklist[class][f].text=li->name;
+ picklist[class][f].client_index=li->id;
+ f++;
+ }
+
+ i=IteratorNext(i);
+ }
+ picklist[class][f].text=NULL;
+
+ return(picklist[class]);
+ }
+}
+
+
+
+
+/* ---------------------------------------- EXPORTED FUNCTIONS
+*/
+void LinedefNewClass(char *class)
+{
+ LineClass c;
+
+ if (!line_class)
+ line_class=MapNew(sizeof(LineClass));
+
+ c.name=Strdup(class);
+
+ MapAdd(line_class,no_classes++,&c);
+}
+
+
+void LinedefAdd(char *class,char *name,int id)
+{
+ LineInfo *li;
+ int i_class;
+ int f;
+
+ if (!line_list)
+ line_list=ListNew(sizeof(LineInfo));
+
+ i_class=-1;
+
+ for(f=0;f<MapSize(line_class);f++)
+ {
+ LineClass *c;
+
+ c=MapElem(line_class,f);
+
+ if (STREQ(c->name,class))
+ i_class=f;
+ }
+
+ if (i_class==-1)
+ i_class=0;
+
+ li=Grab(sizeof(LineInfo));
+
+ li->class=i_class;
+ li->name=Strdup(name);
+ li->id=id;
+ ListAppend(line_list,li);
+}
+
+
+int SelectLinedef(void)
+{
+ int class;
+ int f;
+ int x,y;
+
+ if (!line_menu)
+ {
+ line_menu=Grab(sizeof(PLAT_MENU)*(no_classes+1));
+ picklist=Grab(sizeof(PLAT_PICKLIST *)*(no_classes+1));
+
+ for(f=0;f<no_classes;f++)
+ {
+ LineClass *c;
+
+ c=MapElem(line_class,f);
+ line_menu[f].text=c->name;
+ line_menu[f].client_index=f;
+ }
+
+ for(f=0;f<no_classes+1;f++)
+ picklist[f]=NULL;
+
+ line_menu[no_classes].text=NULL;
+ }
+
+ GFX_mouse(&x,&y);
+
+ if (no_classes<2)
+ class=0;
+ else
+ class=GUI_menu("Pick class of LINEDEF",x,y,line_menu,LINEDEF_NULLID);
+
+ if (class!=LINEDEF_NULLID)
+ class=GUI_client_picklist("LINEDEF",LinedefPicklist(class),
+ LINEDEF_NULLID);
+
+ return(class);
+}
+
+
+char *LinedefName(int id)
+{
+ LineInfo *li;
+ Iterator i;
+
+ i=ListIterator(line_list);
+
+ while(i)
+ {
+ li=IteratorData(i);
+
+ if (li->id==id)
+ {
+ IteratorClear(i);
+ return(li->name);
+ }
+
+ i=IteratorNext(i);
+ }
+
+ return("UNKNOWN");
+}
+
+
+char *LinedefClass(int id)
+{
+ LineInfo *li;
+ LineClass *lc;
+ Iterator i;
+
+ if (no_classes==0)
+ return("NO CLASSES!");
+
+ i=ListIterator(line_list);
+
+ while(i)
+ {
+ li=IteratorData(i);
+
+ if (li->id==id)
+ {
+ IteratorClear(i);
+ lc=MapElem(line_class,li->class);
+ return(lc->name);
+ }
+
+ i=IteratorNext(i);
+ }
+
+ return("UNKNOWN");
+}
+
+
+void LinedefFlag(int bit,char *s,char sh)
+{
+ line_flags[bit]=Strdup(s);
+ line_flags_sh[bit]=sh;
+
+ if (bit>line_flags_max)
+ line_flags_max=bit;
+}
+
+
+char **LinedefFlagArray(void)
+{
+ return(line_flags);
+}
+
+
+char *LinedefFlagText(int flags)
+{
+ static char s[32];
+ int b;
+ char *p;
+
+ s[0]=0;
+ p=s;
+
+ for(b=line_flags_max;b>=0;b--)
+ {
+ if (flags&(1<<b))
+ *p++=line_flags_sh[b];
+ else
+ *p++='-';
+
+ *p=0;
+ }
+
+ return(s);
+}
+
+
+void AddLinedefType(char *name,int flags,int two_sided)
+{
+ LineDefault l;
+
+ if (!line_def)
+ line_def=MapNew(sizeof(LineDefault));
+
+ l.name=Grab(strlen(name)+20);
+ strcpy(l.name,name);
+ strcat(l.name," [");
+ strcat(l.name,LinedefFlagText(flags));
+ strcat(l.name,"]");
+
+ l.id=flags;
+ l.two=two_sided;
+
+ MapAdd(line_def,-1,&l);
+}
+
+
+int ChooseLinedefType(int *flag, int *two)
+{
+ LineDefault *l;
+ int f;
+
+ if (!line_def_plist)
+ {
+ line_def_plist=Grab(sizeof(char *)*(MapSize(line_def)+1));
+
+ for(f=0;f<MapSize(line_def);f++)
+ {
+ l=MapElem(line_def,f);
+ line_def_plist[f]=l->name;
+ }
+
+ line_def_plist[MapSize(line_def)]=NULL;
+ }
+
+ f=GUI_picklist("LINEDEF TYPE",line_def_plist);
+
+ if (f!=-1)
+ {
+ l=MapElem(line_def,f);
+ *flag=l->id;
+ *two=l->two;
+ return(TRUE);
+ }
+ else
+ return(FALSE);
+}
+
+
+/* END OF FILE */