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 /things.c |
Initial import of (very old) vidoom sources.
Diffstat (limited to 'things.c')
-rw-r--r-- | things.c | 288 |
1 files changed, 288 insertions, 0 deletions
diff --git a/things.c b/things.c new file mode 100644 index 0000000..10e407b --- /dev/null +++ b/things.c @@ -0,0 +1,288 @@ +/* + + 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; + + +/* ---------------------------------------- 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;f<MapSize(thing_class);f++) + { + ThingClass *c; + + c=MapElem(thing_class,f); + + if (STREQ(c->name,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;f<no_classes;f++) + { + ThingClass *c; + + c=MapElem(thing_class,f); + thing_menu[f].text=c->name; + thing_menu[f].client_index=f; + } + + for(f=0;f<no_classes+1;f++) + picklist[f]=NULL; + + thing_menu[no_classes].text=NULL; + } + + GFX_mouse(&x,&y); + + if (no_classes<2) + class=0; + else + class=GUI_menu("Pick class of THING",x,y,thing_menu,THING_NULLID); + + if (class!=THING_NULLID) + class=GUI_image_picklist("THING",ThingPicklist(class),THING_NULLID); + + return(class); +} + + +int ThingRadius(int id, int *col) +{ + Iterator i; + ThingRad *r; + + i=ListIterator(rad_list); + + while(i) + { + r=IteratorData(i); + + if (r->id==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"); +} + + +/* END OF FILE */ |