diff options
author | Ian C <ianc@noddybox.co.uk> | 2011-06-09 13:46:28 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2011-06-09 13:46:28 +0000 |
commit | a9022b5972dc49d86f617a27940fafe9c4d0e7e7 (patch) | |
tree | 61405aa4ade91ed1057f863ddf118ceb38e14f8e /sectors.c |
Initial import of (very old) vidoom sources.
Diffstat (limited to 'sectors.c')
-rw-r--r-- | sectors.c | 319 |
1 files changed, 319 insertions, 0 deletions
diff --git a/sectors.c b/sectors.c new file mode 100644 index 0000000..63331de --- /dev/null +++ b/sectors.c @@ -0,0 +1,319 @@ +/* + + 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[2]={0,0}; + +static Map sect_class[2]={NULL,NULL}; +static List sect_list[2]={NULL,NULL}; +static Map sect_style=NULL; + +static PLAT_MENU *menu[2]={NULL,NULL}; +static PLAT_PICKLIST **picklist[2]={NULL,NULL}; + +static char **sect_style_plist=NULL; + + +/* ---------------------------------------- PRIVATE FUNCTIONS +*/ +static int Index(int flag) +{ + if (flag) + return(1); + else + return(0); +} + + +static PLAT_PICKLIST *SectorPicklist(int index, int class) +{ + SectorInfo *si; + Iterator i; + int no; + int f; + + if (picklist[index][class]) + return(picklist[index][class]); + + no=0; + i=ListIterator(sect_list[index]); + + while(i) + { + si=IteratorData(i); + + if (si->class==class) + no++; + + i=IteratorNext(i); + } + + picklist[index][class]=Grab(sizeof(PLAT_PICKLIST)*(no+1)); + + i=ListIterator(sect_list[index]); + + f=0; + while(i) + { + si=IteratorData(i); + + if (si->class==class) + { + picklist[index][class][f].text=si->long_name; + picklist[index][class][f].client_index=si->id; + f++; + } + + i=IteratorNext(i); + } + + picklist[index][class][f].text=NULL; + + return(picklist[index][class]); +} + + +/* ---------------------------------------- EXPORTED FUNCTIONS +*/ +void SectorNewClass(int hexen, char *class) +{ + SectorClass c; + + hexen=Index(hexen); + + if (!sect_class[hexen]) + sect_class[hexen]=MapNew(sizeof(SectorClass)); + + c.name=Strdup(class); + + MapAdd(sect_class[hexen],no_classes[hexen]++,&c); +} + + +void SectorAdd(int hexen, char *class,int id,char *long_name,char *short_name) +{ + SectorInfo *s; + int i_class; + int f; + + hexen=Index(hexen); + + if (!sect_list[hexen]) + sect_list[hexen]=ListNew(sizeof(SectorInfo)); + + s=Grab(sizeof(SectorInfo)); + + i_class=-1; + + for(f=0;f<MapSize(sect_class[hexen]);f++) + { + SectorClass *c; + + c=MapElem(sect_class[hexen],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[hexen],s); +} + + +int SelectSector(int hexen) +{ + int class; + int f; + int x,y; + + hexen=Index(hexen); + + if (!menu[hexen]) + { + menu[hexen]=Grab(sizeof(PLAT_MENU)*(no_classes[hexen]+1)); + picklist[hexen]=Grab(sizeof(PLAT_IMG_PICKLIST *)*(no_classes[hexen]+1)); + + for(f=0;f<no_classes[hexen];f++) + { + SectorClass *c; + + c=MapElem(sect_class[hexen],f); + menu[hexen][f].text=c->name; + menu[hexen][f].client_index=f; + } + + for(f=0;f<no_classes[hexen]+1;f++) + picklist[hexen][f]=NULL; + + menu[hexen][no_classes[hexen]].text=NULL; + } + + GFX_mouse(&x,&y); + + if (no_classes[hexen]<2) + class=0; + else + class=GUI_menu("Pick class of SECTOR",x,y,menu[hexen],SECTOR_NULLID); + + if (class!=SECTOR_NULLID) + class=GUI_client_picklist("SECTOR",SectorPicklist(hexen,class), + SECTOR_NULLID); + + return(class); +} + + +char *SectorName(int hexen, int id) +{ + SectorInfo *si; + Iterator i; + + hexen=Index(hexen); + + i=ListIterator(sect_list[hexen]); + + while(i) + { + si=IteratorData(i); + + if (si->id==id) + { + IteratorClear(i); + return(si->short_name); + } + + i=IteratorNext(i); + } + + return("UNKNOWN"); +} + + +void AddSectorStyle(char *name, int flags, DirName upper, DirName middle, + DirName lower, DirName floor, DirName ceiling) +{ + SectorStyle s; + + if (!sect_style) + sect_style=MapNew(sizeof(SectorStyle)); + + 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 */ |