/* 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;fname,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;fname; menu[hexen][f].client_index=f; } for(f=0;fid==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;fname; } 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 */