/* 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 "things.h" #include "mem.h" #include "list.h" #include "map.h" /* ---------------------------------------- TYPES AND VARS */ #define DEFAULT_RAD 20 #define DEFAULT_COL V_RGB(0xff,0x80,0x80) typedef struct { char *name; int col; } ThingClass; typedef struct { int class; int id; char *name; GFX_IMAGE img; } ThingInfo; typedef struct { int id; int rad; int col; } ThingRad; static int no_classes=0; static Map thing_class=NULL; static List thing_list=NULL; static List rad_list=NULL; static PLAT_IMG_PICKLIST **picklist=NULL; static PLAT_MENU *thing_menu=NULL; static char *thing_flags[17]= {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; static char *thing_flags_sh[17]= {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; /* ---------------------------------------- PRIVATE FUNCTIONS */ static PLAT_IMG_PICKLIST *ThingPicklist(int class) { ThingInfo *ti; Iterator i; int no; int f; if (picklist[class]) return(picklist[class]); else { no=0; i=ListIterator(thing_list); while(i) { ti=IteratorData(i); if (ti->class==class) no++; i=IteratorNext(i); } picklist[class]=Grab(sizeof(PLAT_IMG_PICKLIST)*(no+1)); i=ListIterator(thing_list); f=0; while(i) { ti=IteratorData(i); if (ti->class==class) { picklist[class][f].text=ti->name; picklist[class][f].img=ti->img; picklist[class][f].client_index=ti->id; f++; } i=IteratorNext(i); } picklist[class][f].text=NULL; picklist[class][f].img=NULL; return(picklist[class]); } } /* ---------------------------------------- EXPORTED FUNCTIONS */ void ThingNewClass(char *class, int col) { ThingClass c; if (!thing_class) thing_class=MapNew(sizeof(ThingClass)); c.name=Strdup(class); c.col=col; MapAdd(thing_class,no_classes++,&c); } void ThingAdd(char *class,char *name,int id,int rad,GFX_IMAGE sprite) { ThingInfo *ti; ThingRad *tr; int i_class; int col; int f; if (!thing_list) { thing_list=ListNew(sizeof(ThingInfo)); rad_list=ListNew(sizeof(ThingInfo)); } i_class=-1; col=DEFAULT_COL; for(f=0;fname,class)) { i_class=f; col=c->col; } } if (i_class==-1) i_class=0; ti=Grab(sizeof(ThingInfo)); ti->class=i_class; ti->name=Strdup(name); ti->id=id; ti->img=sprite; ListAppend(thing_list,ti); tr=Grab(sizeof(ThingRad)); tr->id=id; tr->rad=rad; tr->col=col; ListAppend(rad_list,tr); } int SelectThing(void) { int class; int f; int x,y; if (!thing_menu) { thing_menu=Grab(sizeof(PLAT_MENU)*(no_classes+1)); picklist=Grab(sizeof(PLAT_IMG_PICKLIST *)*(no_classes+1)); for(f=0;fname; thing_menu[f].client_index=f; } for(f=0;fid==id) { IteratorClear(i); if (col) *col=r->col; return(r->rad); } i=IteratorNext(i); } if (col) *col=DEFAULT_COL; return(DEFAULT_RAD); } char *ThingName(int id) { ThingInfo *ti; Iterator i; i=ListIterator(thing_list); while(i) { ti=IteratorData(i); if (ti->id==id) { IteratorClear(i); return(ti->name); } i=IteratorNext(i); } return("UNKNOWN"); } void ThingFlag(int bit,char *s,char *sh) { thing_flags[bit]=Strdup(s); thing_flags_sh[bit]=Strdup(sh); } char **ThingFlagArray(void) { return(thing_flags); } char *ThingFlagText(int flags) { static char s[512]; int b; s[0]=0; for(b=0;b<16;b++) if (flags&(1<