convert line ends
[canaan.git] / prj / cam / src / sim / objtool.cpp
blob9ba5a2f88f097527fb42a2c4f2d89c9961c42f4f
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/sim/objtool.cpp,v 1.4 1999/05/23 01:33:00 mahk Exp $
7 #include <iobjsys.h>
8 #include <string.h>
9 #include <ctype.h>
10 #include <comtools.h>
11 #include <appagg.h>
12 #include <traitman.h>
13 #include <label.h>
14 #include <stdlib.h>
15 #include <linktype.h>
16 #include <objedit.h>
18 // Must be last header
19 #include <dbmem.h>
23 // "OBJECT TOOLS"
24 // Refugees from objedit that were needed for stand-alone game.
27 #define UNKNOWN_NAME "UNKNOWN"
30 static char* indef_article(const char* word)
32 static char vowels[] = "AEIOU";
34 if (strchr(vowels,toupper(word[0])) != NULL)
35 return "An";
36 else
37 return "A";
40 const char* ObjEditName(ObjID obj)
42 static char namebuf[1024];
44 if (obj == OBJ_NULL)
45 return "None (0)";
47 AutoAppIPtr_(ObjectSystem,objsys);
49 const char* name = UNKNOWN_NAME;
50 if (objsys->Exists(obj))
51 name = objsys->GetName(obj);
53 if (name == NULL)
55 AutoAppIPtr_(TraitManager,traitman);
57 ObjID arch = traitman->GetArchetype(obj);
58 name = objsys->GetName(arch);
60 if (name != NULL)
61 sprintf(namebuf,"%s %s",indef_article(name),name);
62 else
63 strcpy(namebuf,UNKNOWN_NAME);
66 else
67 strcpy(namebuf,name);
69 // append the ObjID
70 sprintf(namebuf+strlen(namebuf)," (%d)",obj);
72 return namebuf;
75 ////////////////////////////////////////
77 static char wildcard[] = "*";
79 ObjID EditGetObjNamed(const char* name)
81 // try integer id
82 ObjID obj = atoi(name);
83 if (obj != OBJ_NULL) return obj;
85 // try object name
86 AutoAppIPtr_(ObjectSystem,ObjSys);
87 obj = ObjSys->GetObjectNamed(name);
88 if (obj != OBJ_NULL) return obj;
90 // try wildcard
91 if (strncmp(name,wildcard,strlen(wildcard)) == 0)
92 return LINKOBJ_WILDCARD;
94 // look for (id)
95 char* r = strchr(name,'(');
96 if (r != NULL)
98 r++;
99 obj = atoi(r);
100 if (ObjSys->Exists(obj))
101 return obj;
104 // give up
105 return OBJ_NULL;