convert line ends
[canaan.git] / prj / cam / src / engfeat / contain.h
blobc0398b9d9a899dcdbb3a9d690740bdb8994bc479
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/engfeat/contain.h,v 1.15 2000/01/29 13:19:22 adurant Exp $
7 #pragma once
9 #ifndef __CONTAIN_H
10 #define __CONTAIN_H
12 #include <comtools.h>
13 #include <objtype.h>
14 #include <linktype.h>
15 #include <propface.h>
17 // containtype is basically an arbitrary sorting field that the app can
18 // use however it sees fit, if it has sorting-oriented needs
19 typedef int eContainType;
20 #define ECONTAIN_NULL (0x7FFFFFFF)
22 #define IGNORE_TYPES ECONTAIN_NULL
24 // eventually add level-change events?
25 typedef enum eContainsEvent {
27 // Query messages get sent before the actual event occurs.
28 // If you want to veto the event, this is your chance.
29 kContainQueryAdd,
30 kContainQueryCombine,
32 // there is no query remove.
34 // These messages are sent upon COMPLETION of the event in question.
35 // No sense cryin' about it now.
36 kContainAdd,
37 kContainRemove,
38 kContainCombine,
39 // to force 4 byte compiler independant storage
40 kContainWatcomMSVCSilliness=0xffffffff
41 } eContainsEvent;
43 #define CTF_NONE 0x0000
44 #define CTF_COMBINE 0x0001
46 // user callback data
47 typedef void* ContainCBData;
48 // returns FALSE to mean "DONT ALLOW THIS"
49 typedef BOOL (*pContainCallback)(eContainsEvent event, ObjID container, ObjID containee, eContainType ctype, ContainCBData data);
52 // name of the sdesc for the contain relation name
53 #define CONTAIN_SDESC_NAME "ContainRelType"
55 ///////////////////////////
56 // Iterators for Containment
58 typedef struct {
59 BOOL finished; // is this iter finished
60 eContainType type; // what is my ordinal
61 LinkID link_id; // linkID of this link
62 ObjID containee; // ObjID of this object
63 short index; // this is the index-th element of iter
64 // internal to iter rep
65 void *dont_use; // internal rep data
66 eContainType min, max; // contain type range
67 } sContainIter; // 28 bytes
69 ///////////////////////////
70 // Flags for stack remove
72 enum eStackRemoveFlags
74 kStackRemoveNoDecrement = 1 << 0, // don't actually decrement the stack count
75 kStackRemoveAllowInfinite = 1 << 1, // treat "no stack count" as infinite
76 kStackRemoveLeaveEmpty = 1 << 2, // leave a zero stack count behind if needed
79 enum eStackIncFlags
81 kStackAddDestroyIfZero = 1 << 0, // if stack count goes to zero, delete
82 kStackAddAllowInfinite = 1 << 1, // if no stack count, count as infinite
86 ////////////////////////////////////////////////////////////
87 // Contain System Interface
91 F_DECLARE_INTERFACE(IContainSys);
93 #undef INTERFACE
94 #define INTERFACE IContainSys
96 DECLARE_INTERFACE_(IContainSys,IUnknown)
98 DECLARE_UNKNOWN_PURE();
100 //////////////////////////////
101 // Callback management
103 // adds this callback as a listener to contains changes on the container obj
104 // listen to OBJ_NULL in order to listen on every object always
105 STDMETHOD(Listen)(ObjID obj, pContainCallback ContListen, ContainCBData data) PURE;
107 // try out the callback. returns the value returned by the callback
108 STDMETHOD_(BOOL,CheckCallback)(ObjID cbobj, eContainsEvent event, ObjID container, ObjID containee,
109 eContainType type) PURE;
111 //////////////////////////////
112 // Basic Add/Remove sort of stuff
114 // the add to container call, if combine false, will not try to
115 STDMETHOD(Add)(ObjID container, ObjID containee, eContainType type, uint flags) PURE;
117 // Remove containee from container
118 // returns whether successful (ie whether containee actually was in container)
119 // note that doesn't care about stack count -- if you want to remove just one of a stack use CombineAdd
120 STDMETHOD(Remove)(ObjID container, ObjID containee) PURE;
122 // Mutates the containment type for an object
123 STDMETHOD(SetContainType)(ObjID container, ObjID containee, eContainType newctype) PURE;
125 // is containee in container
126 // returns type of containment or ECONTAIN_NULL if not contained
127 STDMETHOD_(eContainType,IsHeld)(ObjID container, ObjID containee) PURE;
129 // is containee in container, or in a containee of container, recursively
130 STDMETHOD_(BOOL,Contains)(ObjID container, ObjID containee) PURE;
132 // Get an object's container, OBJ_NULL if not contained
133 STDMETHOD_(ObjID,GetContainer)(ObjID containee) PURE;
135 // Move all contents
136 STDMETHOD(MoveAllContents)(ObjID targ, ObjID src, int addflags) PURE;
138 //////////////////////////////
139 // Combine-related functions
141 // for attempting to merge an object only (and going and doing it)
142 // will merge new_obj into combinee -- if succesfull, new_obj will cease to exist
143 STDMETHOD(CombineTry)(ObjID combinee, ObjID new_obj, int type) PURE;
145 // How many items of combine type foo do I contain, in total?
146 // ctype is the archetype of the obj you want to check into
147 // (maybe should be string name of the CombineType?)
148 // does this want a flags option for specifying a contain type value to search within?
149 STDMETHOD_(int,CombineCount)(ObjID container, ObjID ctype) PURE;
151 // accumulate / deduct to combineable
152 // ctype is archetype of combineable obj
153 // use negative quantity to deduct
154 // returns whether or not it succeeded -- failure cases include nonexistant object of
155 // that type (hmm, maybe should just instantiate one in inv? ick) or insufficient amount
156 // to remove
157 // Flags are "stack" add flags
158 STDMETHOD(CombineAdd)(ObjID container, ObjID ctype, int quantity, ulong flags DEFAULT_TO(kStackAddAllowInfinite)) PURE;
160 // Can these two objects be combined? Checks properties and callbacks
161 // Takes no actions, though.
162 STDMETHOD_(BOOL, CanCombine)(ObjID combinee, ObjID new_obj, eContainType type) PURE;
164 // Scan through the contents of container, and find whether new_obj would
165 // hypothetically combine with any of the elements within.
166 // Takes no actions.
167 STDMETHOD_(BOOL, CanCombineContainer)(ObjID container, ObjID new_obj, eContainType type) PURE;
170 // Remove some objects from a stack, possibly making a new object
171 // that is a clone
173 STDMETHOD_(ObjID,RemoveFromStack)(THIS_ ObjID stack, ulong flags DEFAULT_TO(0), ulong how_many DEFAULT_TO(1)) PURE;
176 // Add a quantity to a stack, analagous to combine add, but with
177 // no intervening container or combine type. Returns amount actually
178 // added
180 STDMETHOD_(int,StackAdd)(THIS_ ObjID stack, int how_many DEFAULT_TO(1), ulong flags DEFAULT_TO(kStackAddAllowInfinite)) PURE;
182 // Return the "stack count" property
183 STDMETHOD_(IIntProperty*,StackCountProp)(THIS) PURE;
185 ///////////////////////////
186 // contain iter functions
187 // simple iteration over all elements
188 STDMETHOD_(sContainIter *,IterStart)(ObjID container) PURE;
189 // setup an iteration from min->max on container
190 STDMETHOD_(sContainIter *,IterStartType)(ObjID container, eContainType min_type, eContainType max_type) PURE;
191 // iteration over elements including all ancestors
192 STDMETHOD_(sContainIter *,IterStartInherits)(ObjID container) PURE;
193 // iteration over ancestores from min->max on container
194 STDMETHOD_(sContainIter *,IterStartInheritsType)(ObjID container, eContainType min_Type, eContainType max_type) PURE;
195 // get next iter element
196 STDMETHOD_(BOOL,IterNext)(sContainIter *iter) PURE;
197 // finish query process
198 STDMETHOD_(void,IterEnd)(sContainIter *iter) PURE;
200 // Handle database messages
201 STDMETHOD(DatabaseMessage)(ulong msg, IUnknown* file) PURE;
204 #undef INTERFACE
206 EXTERN void ContainSysCreate(void);
209 #endif // __CONTAIN_H