summaryrefslogtreecommitdiff
path: root/sectors.c
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2011-06-09 13:57:32 +0000
committerIan C <ianc@noddybox.co.uk>2011-06-09 13:57:32 +0000
commitec32cf41f916fc34c03d2844684631bee39005ad (patch)
tree0ecd4b3a8602ba76df3b9395eb6c71c350d510df /sectors.c
Added copies of old numbered releases.0.02
Diffstat (limited to 'sectors.c')
-rw-r--r--sectors.c318
1 files changed, 318 insertions, 0 deletions
diff --git a/sectors.c b/sectors.c
new file mode 100644
index 0000000..0c6ce40
--- /dev/null
+++ b/sectors.c
@@ -0,0 +1,318 @@
+/*
+
+ 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 SECTORS
+
+*/
+static const char rcs_id[]="$Id$";
+
+#include "config.h"
+#include "globals.h"
+
+#include "sectors.h"
+#include "mem.h"
+#include "list.h"
+#include "map.h"
+
+
+/* ---------------------------------------- TYPES AND VARS
+*/
+typedef struct
+ {
+ char *name;
+ }
+ SectorClass;
+
+typedef struct
+ {
+ int class;
+ int id;
+ char *long_name;
+ char *short_name;
+ } SectorInfo;
+
+typedef struct
+ {
+ int flags;
+ char *name;
+ DirName upper;
+ DirName middle;
+ DirName lower;
+ DirName floor;
+ DirName ceiling;
+ } SectorStyle;
+
+static int no_classes=0;
+
+static Map sect_class=NULL;
+static List sect_list=NULL;
+static Map sect_style=NULL;
+
+static PLAT_MENU *menu=NULL;
+static PLAT_PICKLIST **picklist=NULL;
+
+static char **sect_style_plist=NULL;
+
+
+/* ---------------------------------------- PRIVATE FUNCTIONS
+*/
+static PLAT_PICKLIST *SectorPicklist(int class)
+{
+ SectorInfo *si;
+ Iterator i;
+ int no;
+ int f;
+
+ if (picklist[class])
+ return(picklist[class]);
+
+ no=0;
+ i=ListIterator(sect_list);
+
+ while(i)
+ {
+ si=IteratorData(i);
+
+ if (si->class==class)
+ no++;
+
+ i=IteratorNext(i);
+ }
+
+ picklist[class]=Grab(sizeof(PLAT_PICKLIST)*(no+1));
+
+ i=ListIterator(sect_list);
+
+ f=0;
+ while(i)
+ {
+ si=IteratorData(i);
+
+ if (si->class==class)
+ {
+ picklist[class][f].text=si->long_name;
+ picklist[class][f].client_index=si->id;
+ f++;
+ }
+
+ i=IteratorNext(i);
+ }
+
+ picklist[class][f].text=NULL;
+
+ return(picklist[class]);
+}
+
+
+/* ---------------------------------------- EXPORTED FUNCTIONS
+*/
+void SectorNewClass(char *class)
+{
+ SectorClass c;
+
+ if (!sect_class)
+ sect_class=MapNew(sizeof(SectorClass));
+
+ c.name=Strdup(class);
+
+ MapAdd(sect_class,no_classes++,&c);
+}
+
+
+void SectorAdd(char *class,int id,char *long_name,char *short_name)
+{
+ SectorInfo *s;
+ int i_class;
+ int f;
+
+ if (!sect_list)
+ sect_list=ListNew(sizeof(SectorInfo));
+
+ s=Grab(sizeof(SectorInfo));
+
+ i_class=-1;
+
+ for(f=0;f<MapSize(sect_class);f++)
+ {
+ SectorClass *c;
+
+ c=MapElem(sect_class,f);
+
+ if (STREQ(c->name,class))
+ i_class=f;
+ }
+
+ if (i_class==-1)
+ i_class=0;
+
+ s->class=i_class;
+ s->id=id;
+ s->long_name=Strdup(long_name);
+ s->short_name=Strdup(short_name);
+ ListAppend(sect_list,s);
+}
+
+
+int SelectSector(void)
+{
+ int class;
+ int f;
+ int x,y;
+
+ if (!menu)
+ {
+ menu=Grab(sizeof(PLAT_MENU)*(no_classes+1));
+ picklist=Grab(sizeof(PLAT_IMG_PICKLIST *)*(no_classes+1));
+
+ for(f=0;f<no_classes;f++)
+ {
+ SectorClass *c;
+
+ c=MapElem(sect_class,f);
+ menu[f].text=c->name;
+ menu[f].client_index=f;
+ }
+
+ for(f=0;f<no_classes+1;f++)
+ picklist[f]=NULL;
+
+ menu[no_classes].text=NULL;
+ }
+
+ GFX_mouse(&x,&y);
+
+ if (no_classes<2)
+ class=0;
+ else
+ class=GUI_menu("Pick class of SECTOR",x,y,menu,SECTOR_NULLID);
+
+ if (class!=SECTOR_NULLID)
+ class=GUI_client_picklist("SECTOR",SectorPicklist(class),SECTOR_NULLID);
+
+ return(class);
+}
+
+
+char *SectorName(int id)
+{
+ SectorInfo *si;
+ Iterator i;
+
+ i=ListIterator(sect_list);
+
+ while(i)
+ {
+ si=IteratorData(i);
+
+ if (si->id==id)
+ {
+ IteratorClear(i);
+ return(si->short_name);
+ }
+
+ i=IteratorNext(i);
+ }
+
+ return("UNKNOWN");
+}
+
+
+void StartSectorStyles(void)
+{
+ SectorStyle *s;
+ int f;
+
+ if (!sect_style)
+ {
+ for(f=0;f<MapSize(sect_style);f++)
+ {
+ s=MapElem(sect_style,f);
+ Release(s->name);
+ }
+
+ sect_style=MapNew(sizeof(SectorStyle));
+ }
+ else
+ MapEmpty(sect_style);
+}
+
+
+void AddSectorStyle(char *name, int flags, DirName upper, DirName middle,
+ DirName lower, DirName floor, DirName ceiling)
+{
+ SectorStyle s;
+
+ s.flags=flags;
+ s.name=Strdup(name);
+ strcpy(s.upper,upper);
+ strcpy(s.middle,middle);
+ strcpy(s.lower,lower);
+ strcpy(s.floor,floor);
+ strcpy(s.ceiling,ceiling);
+
+ MapAdd(sect_style,-1,&s);
+}
+
+
+int ChooseSectorStyle(int *flags, DirName upper,DirName middle,DirName lower,
+ DirName floor,DirName ceiling)
+{
+ SectorStyle *s;
+ int f;
+
+ if (!sect_style_plist)
+ {
+ sect_style_plist=Grab(sizeof(char *)*(MapSize(sect_style)+1));
+
+ for(f=0;f<MapSize(sect_style);f++)
+ {
+ s=MapElem(sect_style,f);
+ sect_style_plist[f]=s->name;
+ }
+
+ sect_style_plist[MapSize(sect_style)]=NULL;
+ }
+
+ f=GUI_picklist("SECTOR STYLE",sect_style_plist);
+
+ if (f!=-1)
+ {
+ s=MapElem(sect_style,f);
+ *flags=s->flags;
+ strcpy(lower,s->lower);
+ strcpy(middle,s->middle);
+ strcpy(upper,s->upper);
+ strcpy(floor,s->floor);
+ strcpy(ceiling,s->ceiling);
+ return(TRUE);
+ }
+ else
+ return(FALSE);
+}
+
+int NoSectorStyles(void)
+{
+ return(MapSize(sect_style));
+}
+
+
+/* END OF FILE */