summaryrefslogtreecommitdiff
path: root/specials.c
diff options
context:
space:
mode:
Diffstat (limited to 'specials.c')
-rw-r--r--specials.c319
1 files changed, 319 insertions, 0 deletions
diff --git a/specials.c b/specials.c
new file mode 100644
index 0000000..44bb5e7
--- /dev/null
+++ b/specials.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 ACTION SPECIALS
+
+*/
+static const char rcs_id[]="$Id$";
+
+#include "config.h"
+#include "globals.h"
+
+#include "platgui.h"
+#include "gui.h"
+#include "gfx.h"
+#include "specials.h"
+#include "mem.h"
+#include "list.h"
+#include "map.h"
+
+
+/* ---------------------------------------- TYPES AND VARS
+*/
+typedef struct
+ {
+ char *name;
+ } SpecialClass;
+
+typedef struct
+ {
+ int class;
+ int id;
+ char *name;
+ int no_args;
+ char *arg[5];
+ } SpecialInfo;
+
+static int no_classes=0;
+
+static Map special_class=NULL;
+static List special_list=NULL;
+
+static PLAT_PICKLIST **picklist=NULL;
+
+static PLAT_MENU *special_menu=NULL;
+
+
+/* ---------------------------------------- PRIVATE FUNCTIONS
+*/
+static PLAT_PICKLIST *SpecialPicklist(int class)
+{
+ SpecialInfo *si;
+ Iterator i;
+ int no;
+ int f;
+
+ if (picklist[class])
+ return(picklist[class]);
+ else
+ {
+ no=0;
+ i=ListIterator(special_list);
+
+ while(i)
+ {
+ si=IteratorData(i);
+
+ if (si->class==class)
+ no++;
+
+ i=IteratorNext(i);
+ }
+
+ picklist[class]=Grab(sizeof(PLAT_PICKLIST)*(no+1));
+
+ i=ListIterator(special_list);
+
+ f=0;
+ while(i)
+ {
+ si=IteratorData(i);
+
+ if (si->class==class)
+ {
+ picklist[class][f].text=si->name;
+ picklist[class][f].client_index=si->id;
+ f++;
+ }
+
+ i=IteratorNext(i);
+ }
+
+ picklist[class][f].text=NULL;
+
+ return(picklist[class]);
+ }
+}
+
+
+
+
+/* ---------------------------------------- EXPORTED FUNCTIONS
+*/
+void SpecialNewClass(char *class)
+{
+ SpecialClass c;
+
+ if (!special_class)
+ special_class=MapNew(sizeof(SpecialClass));
+
+ c.name=Strdup(class);
+
+ MapAdd(special_class,no_classes++,&c);
+}
+
+
+void SpecialAdd(char *class,char *name,int id, char *arg[5])
+{
+ SpecialInfo *si;
+ int i_class;
+ int f;
+
+ if (!special_list)
+ special_list=ListNew(sizeof(SpecialInfo));
+
+ i_class=-1;
+
+ for(f=0;f<MapSize(special_class);f++)
+ {
+ SpecialClass *c;
+
+ c=MapElem(special_class,f);
+
+ if (STREQ(c->name,class))
+ i_class=f;
+ }
+
+ if (i_class==-1)
+ i_class=0;
+
+ si=Grab(sizeof(SpecialInfo));
+
+ si->class=i_class;
+ si->name=Strdup(name);
+ si->id=id;
+ si->no_args=0;
+
+ for(f=0;(f<5)&&(arg[f]);f++)
+ {
+ si->arg[f]=Strdup(arg[f]);
+ si->no_args++;
+ }
+
+ ListAppend(special_list,si);
+}
+
+
+int SelectSpecial(void)
+{
+ int class;
+ int f;
+ int x,y;
+
+ if (!special_menu)
+ {
+ special_menu=Grab(sizeof(PLAT_MENU)*(no_classes+1));
+ picklist=Grab(sizeof(PLAT_PICKLIST *)*(no_classes+1));
+
+ for(f=0;f<no_classes;f++)
+ {
+ SpecialClass *c;
+
+ c=MapElem(special_class,f);
+ special_menu[f].text=c->name;
+ special_menu[f].client_index=f;
+ }
+
+ for(f=0;f<no_classes+1;f++)
+ picklist[f]=NULL;
+
+ special_menu[no_classes].text=NULL;
+ }
+
+ GFX_mouse(&x,&y);
+
+ if (no_classes<2)
+ class=0;
+ else
+ class=GUI_menu("Pick class of ACTION SPECIAL",x,y,
+ special_menu,SPECIAL_NULLID);
+
+ if (class!=SPECIAL_NULLID)
+ class=GUI_client_picklist("ACTION SPECIAL",SpecialPicklist(class),
+ SPECIAL_NULLID);
+
+ return(class);
+}
+
+
+char *SpecialName(int id, char *arg[5])
+{
+ SpecialInfo *si;
+ Iterator i;
+ int f;
+
+ for(f=0;f<5;f++)
+ arg[f]=NULL;
+
+ i=ListIterator(special_list);
+
+ while(i)
+ {
+ si=IteratorData(i);
+
+ if (si->id==id)
+ {
+ IteratorClear(i);
+
+ if (arg)
+ for(f=0;f<si->no_args;f++)
+ arg[f]=si->arg[f];
+
+ return(si->name);
+ }
+
+ i=IteratorNext(i);
+ }
+
+ return("UNKNOWN");
+}
+
+
+int SpecialArgDialog(char *prompt, int id, int arg[5])
+{
+ PLAT_DIALOG d[5];
+ SpecialInfo *si;
+ Iterator i;
+ char *pd;
+ int f;
+
+ i=ListIterator(special_list);
+
+ while(i)
+ {
+ si=IteratorData(i);
+
+ if (si->id==id)
+ {
+ IteratorClear(i);
+
+ if (si->no_args)
+ {
+ for(f=0;f<si->no_args;f++)
+ {
+ d[f].text=si->arg[f];
+ d[f].type=PLAT_DIAL_INTEGER;
+ d[f].data.i=arg[f];
+ }
+
+ if (!prompt)
+ pd=Strdup(si->name);
+ else
+ {
+ pd=Grab(strlen(si->name)+strlen(prompt)+4);
+ sprintf(pd,"%s - %s",si->name,prompt);
+ }
+
+ if (GUI_dialog(pd,si->no_args,d))
+ {
+ for(f=0;f<5;f++)
+ arg[f]=0;
+
+ for(f=0;f<si->no_args;f++)
+ arg[f]=d[f].data.i;
+
+ Release(pd);
+ return(TRUE);
+ }
+ else
+ {
+ Release(pd);
+ return(FALSE);
+ }
+ }
+ else
+ {
+ GuiInfoBox("ACTION SPECIAL ARGUMENTS",
+ "Special '%s'|has no arguments",si->name);
+ return(FALSE);
+ }
+ }
+
+ i=IteratorNext(i);
+ }
+
+ GuiInfoBox("ACTION SPECIAL ARGUMENTS","Passed in type %s unknown",id);
+ return(FALSE);
+}
+
+
+/* END OF FILE */