From a9022b5972dc49d86f617a27940fafe9c4d0e7e7 Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 9 Jun 2011 13:46:28 +0000 Subject: Initial import of (very old) vidoom sources. --- flags.c | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 flags.c (limited to 'flags.c') diff --git a/flags.c b/flags.c new file mode 100644 index 0000000..08ed020 --- /dev/null +++ b/flags.c @@ -0,0 +1,203 @@ +/* + + 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 + + ------------------------------------------------------------------------- + + Generic flag handling. Used for THING and LINEDEF flags + +*/ +static const char rcs_id[]="$Id$"; + +#include "config.h" +#include "globals.h" + +#include "platgui.h" +#include "flags.h" +#include "mem.h" +#include "list.h" + + +/* ---------------------------------------- TYPES AND VARS +*/ +typedef struct + { + int group; + int mask1; + int mask2; + char *name; + char flag[2]; + } Flag; + +static List list[2][2]; + + +/* ---------------------------------------- PRIVATE FUNCTIONS +*/ +static int Index(int hexen) +{ + if (hexen) + return(1); + else + return(0); +} + +static int IsSet(Flag *f,int v) +{ + v&=f->mask1; + return(v==f->mask2); +} + + +/* ---------------------------------------- EXPORTED FUNCTIONS +*/ + +void FlagAdd(int hexen, int class, int group, + char *name, int mask1, int mask2, char flag) +{ + Flag f; + Iterator i; + Flag *pf; + + hexen=Index(hexen); + + if (!(list[hexen][class])) + list[hexen][class]=ListNew(sizeof(Flag)); + + f.name=Strdup(name); + f.mask1=mask1; + f.mask2=mask2; + f.flag[0]=flag; + f.flag[1]=0; + f.group=group; + + i=ListIterator(list[hexen][class]); + + while(i) + { + pf=IteratorData(i); + + if ((pf->mask1==mask1)&&(pf->mask2==mask2)) + { + Release(pf->name); + IteratorUpdate(i,&f); + IteratorClear(i); + return; + } + + i=IteratorNext(i); + } + + ListAppend(list[hexen][class],&f); +} + + +int SelectFlags(int hexen, int class, int *flags) +{ + static char *title[]={"THING FLAGS","LINEDEF FLAGS"}; + PLAT_MULTI *p; + Flag *pf; + int no; + int f; + Iterator i; + int res; + + hexen=Index(hexen); + + no=ListSize(list[hexen][class]); + p=Grab(sizeof(PLAT_MULTI)*(no+1)); + + i=ListIterator(list[hexen][class]); + + for(f=0;fname; + p[f].group=pf->group; + } + + p[f].text=NULL; + + if (GUI_multi_box(title[class],p)) + { + i=ListIterator(list[hexen][class]); + + for(f=0;fmask1); + } + + i=ListIterator(list[hexen][class]); + + for(f=0;fmask2; + } + + res=TRUE; + } + else + res=FALSE; + + Release(p); + return(res); +} + + +char *FlagText(int hexen, int class, int flags) +{ + static char s[128]; + Flag *pf; + Iterator i; + + hexen=Index(hexen); + + i=ListIterator(list[hexen][class]); + strcpy(s,""); + + while(i) + { + pf=IteratorData(i); + + if (IsSet(pf,flags)) + { + /* + if (s[0]) + strcat(s,","); + */ + + strcat(s,pf->flag); + } + + i=IteratorNext(i); + } + + return(s); +} + + +/* END OF FILE */ -- cgit v1.2.3