convert line ends
[canaan.git] / prj / cam / src / shock / shkpsipr.cpp
blob75d21eee3dd0b7c0602d614444418b6151ffb64b
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // $Header: r:/t2repos/thief2/src/shock/shkpsipr.cpp,v 1.13 1999/11/19 14:58:39 adurant Exp $
8 #include <shkpsipr.h>
10 #include <propert_.h>
11 #include <dataops_.h>
12 #include <prophash.h>
14 #include <sdesc.h>
15 #include <sdesbase.h>
17 #include <relation.h>
18 #include <linkbase.h>
20 #include <shkplcst.h>
21 #include <nzprutil.h>
22 #include <shkpsibs.h>
23 #include <shkpsipw.h>
25 // for esnd cut 'n paste
26 #include <property.h>
27 #include <propbase.h>
28 #include <propface.h>
29 #include <propfac_.h>
30 #include <proplist.h>
31 #include <objnotif.h>
33 // must be last header
34 #include <dbmem.h>
36 ///////////////////////////////////////////////////////
37 // Teleport link
39 IRelation *g_pPsiTeleportLinks;
41 static sRelationDesc psiTeleportDesc = { "Teleport", 0, 0, 0 };
42 static sRelationDataDesc noDataDesc = { "None", 0 };
44 //////////////////////////////////////////////////
45 // Psi Power desc
48 IPsiPowerProperty *g_pPsiPowerProperty;
50 typedef cSpecificProperty<IPsiPowerProperty, &IID_IPsiPowerProperty, sPsiPower*, cHashPropertyStore<cClassDataOps<sPsiPower> > > cPsiPowerPropertyBase;
52 // property implementation class
53 class cPsiPowerProperty: public cPsiPowerPropertyBase
55 public:
56 cPsiPowerProperty(const sPropertyDesc* desc)
57 : cPsiPowerPropertyBase(desc)
61 STANDARD_DESCRIBE_TYPE(sPsiPower);
65 char* psiTypeNames[] =
67 "Shot",
68 "Shield",
69 "One-Shot",
70 "Sustained",
71 "Cursor Target"
74 static sFieldDesc psiPowerFields[] =
76 { "Power", kFieldTypeEnum, FieldLocation(sPsiPower, m_power), kFieldFlagUnsigned, 0, kPsiMax, kPsiMax, psiPowerNames},
77 { "Type", kFieldTypeEnum, FieldLocation(sPsiPower, m_type), kFieldFlagUnsigned, 0, kPsiTypeMax, kPsiTypeMax, psiTypeNames},
78 { "Start Cost", kFieldTypeInt, FieldLocation(sPsiPower, m_startCost), },
79 { "Data 1", kFieldTypeFloat, FieldLocation(sPsiPower, m_data[0]), },
80 { "Data 2", kFieldTypeFloat, FieldLocation(sPsiPower, m_data[1]), },
81 { "Data 3", kFieldTypeFloat, FieldLocation(sPsiPower, m_data[2]), },
82 { "Data 4", kFieldTypeFloat, FieldLocation(sPsiPower, m_data[3]), },
85 static sStructDesc psiPowerStructDesc =
86 StructDescBuild(sPsiPower, kStructFlagNone, psiPowerFields);
88 IPsiPowerProperty *CreatePsiPowerProperty(sPropertyDesc *desc,
89 ePropertyImpl impl)
91 StructDescRegister(&psiPowerStructDesc);
92 return new cPsiPowerProperty(desc);
95 static sPropertyDesc psiPowerDesc =
97 PROP_PSI_POWER_DESC,
98 kPropertyNoInherit,
99 NULL,
100 1, // version
102 {"Psi", "Power Description"},
105 void PsiPowerPropertyInit()
107 g_pPsiPowerProperty = CreatePsiPowerProperty(&psiPowerDesc, kPropertyImplDense);
110 //////////////////////////////////////////////////
111 // Psi Shield desc
114 IPsiShieldProperty *g_pPsiShieldProperty;
116 typedef cSpecificProperty<IPsiShieldProperty, &IID_IPsiShieldProperty, sPsiShield*, cHashPropertyStore<cClassDataOps<sPsiShield> > > cPsiShieldPropertyBase;
118 // property implementation class
119 class cPsiShieldProperty: public cPsiShieldPropertyBase
121 public:
122 cPsiShieldProperty(const sPropertyDesc* desc)
123 : cPsiShieldPropertyBase(desc)
127 STANDARD_DESCRIBE_TYPE(sPsiShield);
131 static sFieldDesc psiShieldFields[] =
133 {"Base Time", kFieldTypeInt, FieldLocation(sPsiShield, m_baseTime), },
134 {"Add Time", kFieldTypeInt, FieldLocation(sPsiShield, m_addTime), },
135 {"Base Int", kFieldTypeInt, FieldLocation(sPsiShield, m_baseInt), },
138 static sStructDesc psiShieldStructDesc =
139 StructDescBuild(sPsiShield, kStructFlagNone, psiShieldFields);
141 IPsiShieldProperty *CreatePsiShieldProperty(sPropertyDesc *desc,
142 ePropertyImpl impl)
144 StructDescRegister(&psiShieldStructDesc);
145 return new cPsiShieldProperty(desc);
148 static sPropertyDesc psiShieldDesc =
150 PROP_PSI_SHIELD_DESC,
151 kPropertyNoInherit,
152 NULL,
153 1, // version
155 {"Psi", "Shield Description"},
158 sPsiShield defaultPsiShield =
160 0, 0, 0,
163 void PsiShieldPropertyInit()
165 g_pPsiShieldProperty = CreatePsiShieldProperty(&psiShieldDesc, kPropertyImplDense);
168 //////////////////////////////////////////////////
169 // Psi State desc
172 IPsiStateProperty *g_pPsiStateProperty;
174 typedef cSpecificProperty<IPsiStateProperty, &IID_IPsiStateProperty, cPsiState*, cHashPropertyStore<cNoZeroDataOps<cPsiState> > > cPsiStatePropertyBase;
176 // property implementation class
177 class cPsiStateProperty: public cPsiStatePropertyBase
179 public:
180 cPsiStateProperty(const sPropertyDesc* desc)
181 : cPsiStatePropertyBase(desc)
185 STANDARD_DESCRIBE_TYPE(cPsiState);
189 static sFieldDesc psiStateFields[] =
191 { "", kFieldTypeEnum, FieldLocation(cPsiState, m_currentPower), kFieldFlagUnsigned|kFieldFlagNotEdit, 0, kPsiMax+1, kPsiMax+1, psiPowerNames},
192 {"Current Points", kFieldTypeInt, FieldLocation(cPsiState, m_points), },
193 {"Max Points", kFieldTypeInt, FieldLocation(cPsiState, m_maxPoints), },
196 static sStructDesc PsiStateStructDesc =
197 StructDescBuild(cPsiState, kStructFlagNone, psiStateFields);
199 IPsiStateProperty *CreatePsiStateProperty(sPropertyDesc *desc,
200 ePropertyImpl impl)
202 StructDescRegister(&PsiStateStructDesc);
203 return new cPsiStateProperty(desc);
206 static sPropertyDesc psiStateDesc =
208 PROP_PSI_STATE_DESC,
209 kPropertyInstantiate,
210 NULL,
211 1, // version
213 {"Psi", "State"},
216 sPsiState defaultPsiState =
218 kPsiNone,
223 cPsiState::cPsiState()
225 *this = *(cPsiState*)(&defaultPsiState);
228 void PsiStatePropertyInit()
230 g_pPsiStateProperty = CreatePsiStateProperty(&psiStateDesc, kPropertyImplDense);
233 sPsiState* PsiStateGet(ObjID objID)
235 cPsiState *pPsiState;
237 if (g_pPsiStateProperty->Get(objID, &pPsiState))
238 return pPsiState;
239 else
240 return &defaultPsiState;
243 void PsiStateSetCurrentPower(ObjID objID, ePsiPowers power)
245 cPsiState *pPsiState;
247 if (g_pPsiStateProperty->Get(objID, &pPsiState))
249 pPsiState->m_currentPower = power;
250 g_pPsiStateProperty->Set(objID, pPsiState);
254 void PsiStateSetPoints(ObjID objID, float points)
256 cPsiState *pPsiState;
257 if (g_pPsiStateProperty->Get(objID, &pPsiState))
259 pPsiState->m_points = points;
260 g_pPsiStateProperty->Set(objID, pPsiState);
264 void PsiStateSetMaxPoints(ObjID objID, float maxPoints)
266 cPsiState *pPsiState;
267 if (g_pPsiStateProperty->Get(objID, &pPsiState))
269 pPsiState->m_maxPoints = maxPoints;
270 g_pPsiStateProperty->Set(objID, pPsiState);
274 /////////////////////////////////////////////////
275 IIntProperty *g_PsiOverloadProperty;
276 IIntProperty *g_PsiOverload2Property;
278 BOOL PsiOverloaded(ObjID obj, ePsiPowers which)
280 int powers;
281 // this is kind of grody...
282 if (which < 32)
284 g_PsiOverloadProperty->Get(obj, &powers);
285 return(powers & (1 << which));
287 else
289 g_PsiOverload2Property->Get(obj, &powers);
290 return(powers & (1 << (which - 32)));
294 void PsiSetOverload(ObjID obj, ePsiPowers which, BOOL val)
296 int powers;
297 if (which < 32)
299 g_PsiOverloadProperty->Get(obj, &powers);
300 if (val)
301 powers = powers | (1 << which);
302 else
303 powers = powers & (~(1 << which));
304 g_PsiOverloadProperty->Set(obj, powers);
306 else
308 g_PsiOverload2Property->Get(obj, &powers);
309 if (val)
310 powers = powers | (1 << (which - 32));
311 else
312 powers = powers & (~(1 << which));
313 g_PsiOverload2Property->Set(obj, powers);
317 #define PROP_PSIOVERLOAD_DESC "PsiOverDesc"
318 static sPropertyDesc PsiOverloadDesc = { PROP_PSIOVERLOAD_DESC, 0, NULL, 1, 0, {"Player", "Overload State"}, };
319 #define PROP_PSIOVERLOAD2_DESC "PsiOver2Desc"
320 static sPropertyDesc PsiOverload2Desc = { PROP_PSIOVERLOAD2_DESC, 0, NULL, 1, 0, {"Player", "Overload State 2"}, };
322 /////////////////////////////////////////////////
323 IIntProperty *g_PsiRadarProperty;
324 #define PROP_PSIRADAR_DESC "PsiRadar"
325 static sPropertyDesc PsiRadarDesc = { PROP_PSIRADAR_DESC, 0, NULL, 1, 0, {"Psi", "Radar Type"}, };
327 static char* RadarNames[] =
329 "None","Enemy", "Powerup",
332 static sFieldDesc RadarFields[] =
334 { "", kFieldTypeEnum, sizeof(int), 0, kFieldFlagUnsigned, 0, 3, 3, RadarNames},
337 static sPropertyTypeDesc RadarTypeDesc = {PROP_PSIRADAR_DESC, sizeof(int)};
339 static sStructDesc RadarStructDesc =
341 PROP_PSIRADAR_DESC,
342 sizeof(int),
343 kStructFlagNone,
344 sizeof(RadarFields)/sizeof(RadarFields[0]),
345 RadarFields,
348 /////////////////////////////////////////////////
350 IFloatProperty *g_PsiAlchemyProperty;
351 #define PROP_PSIALCHEMY_DESC "Alchemy"
352 static sPropertyDesc PsiAlchemyDesc = { PROP_PSIALCHEMY_DESC, 0, NULL, 1, 0, {"Psi", "Alchemy Val"}, };
354 /////////////////////////////////////////////////
356 IIntProperty *g_PsiFabricateProperty;
357 #define PROP_PSIFabricate_DESC "Fabricate"
358 static sPropertyDesc PsiFabricateDesc = { PROP_PSIFabricate_DESC, 0, NULL, 1, 0, {"Psi", "Fabricate Quantity"}, };
360 /////////////////////////////////////////////////
362 IIntProperty *g_PsiFabCostProperty;
363 static sPropertyDesc PsiFabCostDesc = { "FabCost", 0, NULL, 1, 0, {"Psi", "Fabricate Cost"}, };
365 /////////////////////////////////////////////////
367 IBoolProperty *g_pPsiNotPullableProperty;
368 #define PROP_PSINOTPULL_DESC "NotPullable"
369 static sPropertyDesc PsiNotPullableDesc = { PROP_PSINOTPULL_DESC, 0, NULL, 1, 0, {"Psi", "NotPullable"}, };
371 /////////////////////////////////////////////////
373 static sFieldDesc g_Fields [] =
375 { "1: Tags", kFieldTypeString,
376 FieldLocation(sESndTagList, m_TagStrings) },
379 static sStructDesc g_ListStruct
380 = StructDescBuild(sESndTagList, kStructFlagNone, g_Fields);
382 static IESndTagProperty* g_pESndPsiProp = NULL;
384 struct sOpsList : public sESndTagList
386 sOpsList()
388 m_pTagSet = new cTagSet;
389 m_TagStrings[0] = '\0';
392 sOpsList(const sESndTagList& dat)
394 strncpy(m_TagStrings,dat.m_TagStrings,sizeof(m_TagStrings));
395 m_pTagSet = new cTagSet(m_TagStrings);
398 sOpsList(const sOpsList& dat)
400 strncpy(m_TagStrings,dat.m_TagStrings,sizeof(m_TagStrings));
401 m_pTagSet = new cTagSet(m_TagStrings);
404 sOpsList& operator=(const sOpsList& dat)
406 strncpy(m_TagStrings,dat.m_TagStrings,sizeof(m_TagStrings));
407 m_pTagSet->FromString(m_TagStrings);
408 return *this;
411 ~sOpsList()
413 delete m_pTagSet;
418 class cESndTagOps : public cClassDataOps<sOpsList>
420 typedef cClassDataOps<sOpsList> cParent;
421 public:
423 cESndTagOps() : cParent(kNoFlags) {} ;
424 STDMETHOD(Read)(THIS_ sDatum* dat, IDataOpsFile* file, int version)
426 if (!dat->value)
427 *dat = New();
428 sOpsList* list = (sOpsList*)dat->value;
429 sESndTagList tmp;
430 memset(&tmp,0,sizeof(tmp));
431 // we derive from cClassDataOps, thus version == size;
432 int sz = (version < sizeof(tmp)) ? version : sizeof(tmp);
433 Verify(file->Read(&tmp,sz) == sz);
434 *list = tmp;
435 return S_OK;
440 class cESndTagStore : public cListPropertyStore<cESndTagOps>
444 class cESndTagProperty : public cSpecificProperty<IESndTagProperty,
445 &IID_IESndTagProperty, sESndTagList*, cESndTagStore>
448 typedef cSpecificProperty<IESndTagProperty,
449 &IID_IESndTagProperty,
450 sESndTagList*,
451 cESndTagStore> cParent;
453 public:
454 cESndTagProperty(const sPropertyDesc* desc)
455 : cParent(desc)
459 STANDARD_DESCRIBE_TYPE(sESndTagList);
463 static sPropertyDesc g_PsiPropDesc =
465 PROP_ESND_PSI_NAME,
467 NULL,
468 0,0, // verison
469 { "Schema", "Psi Tags" },
472 EXTERN BOOL ObjGetESndPsi(ObjID obj, sESndTagList **pData)
474 Assert_(g_pESndPsiProp);
475 return g_pESndPsiProp->Get(obj, pData);
479 EXTERN BOOL ObjSetESndPsi(ObjID obj, sESndTagList *pData)
481 Assert_(g_pESndPsiProp);
482 return g_pESndPsiProp->Set(obj, pData);
485 /////////////////////////////////////////////////
487 void PsiPropertiesInit(void)
489 PsiPowerPropertyInit();
490 PsiStatePropertyInit();
491 PsiShieldPropertyInit();
492 g_PsiOverloadProperty = CreateIntProperty(&PsiOverloadDesc, kPropertyImplVerySparse);
493 g_PsiOverload2Property = CreateIntProperty(&PsiOverload2Desc, kPropertyImplVerySparse);
495 StructDescRegister(&RadarStructDesc);
496 g_PsiRadarProperty = CreateIntegralProperty(&PsiRadarDesc, &RadarTypeDesc, kPropertyImplLlist); // kPropertyImplDense);
498 g_PsiAlchemyProperty = CreateFloatProperty(&PsiAlchemyDesc, kPropertyImplDense);
499 g_PsiFabricateProperty = CreateIntProperty(&PsiFabricateDesc, kPropertyImplDense);
500 g_PsiFabCostProperty = CreateIntProperty(&PsiFabCostDesc, kPropertyImplDense);
501 g_pPsiNotPullableProperty = CreateBoolProperty(&PsiNotPullableDesc, kPropertyImplDense);
503 g_pESndPsiProp = new cESndTagProperty(&g_PsiPropDesc);
505 // links
506 g_pPsiTeleportLinks = CreateStandardRelation(&psiTeleportDesc, &noDataDesc, (kQCaseSetSourceKnown));
509 /////////////////////////////////////////////////
511 void PsiPropertiesTerm(void)
513 SafeRelease(g_pPsiPowerProperty);
514 SafeRelease(g_pPsiStateProperty);
515 SafeRelease(g_pPsiShieldProperty);
516 SafeRelease(g_PsiOverloadProperty);
517 SafeRelease(g_PsiOverload2Property);
518 SafeRelease(g_PsiRadarProperty);
519 SafeRelease(g_PsiAlchemyProperty);
520 SafeRelease(g_PsiFabricateProperty);
521 SafeRelease(g_pPsiTeleportLinks);
522 SafeRelease(g_pPsiNotPullableProperty);
523 SafeRelease(g_pESndPsiProp);