2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 // $Header: r:/t2repos/thief2/src/shock/shkpsipr.cpp,v 1.13 1999/11/19 14:58:39 adurant Exp $
25 // for esnd cut 'n paste
33 // must be last header
36 ///////////////////////////////////////////////////////
39 IRelation
*g_pPsiTeleportLinks
;
41 static sRelationDesc psiTeleportDesc
= { "Teleport", 0, 0, 0 };
42 static sRelationDataDesc noDataDesc
= { "None", 0 };
44 //////////////////////////////////////////////////
48 IPsiPowerProperty
*g_pPsiPowerProperty
;
50 typedef cSpecificProperty
<IPsiPowerProperty
, &IID_IPsiPowerProperty
, sPsiPower
*, cHashPropertyStore
<cClassDataOps
<sPsiPower
> > > cPsiPowerPropertyBase
;
52 // property implementation class
53 class cPsiPowerProperty
: public cPsiPowerPropertyBase
56 cPsiPowerProperty(const sPropertyDesc
* desc
)
57 : cPsiPowerPropertyBase(desc
)
61 STANDARD_DESCRIBE_TYPE(sPsiPower
);
65 char* psiTypeNames
[] =
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
,
91 StructDescRegister(&psiPowerStructDesc
);
92 return new cPsiPowerProperty(desc
);
95 static sPropertyDesc psiPowerDesc
=
102 {"Psi", "Power Description"},
105 void PsiPowerPropertyInit()
107 g_pPsiPowerProperty
= CreatePsiPowerProperty(&psiPowerDesc
, kPropertyImplDense
);
110 //////////////////////////////////////////////////
114 IPsiShieldProperty
*g_pPsiShieldProperty
;
116 typedef cSpecificProperty
<IPsiShieldProperty
, &IID_IPsiShieldProperty
, sPsiShield
*, cHashPropertyStore
<cClassDataOps
<sPsiShield
> > > cPsiShieldPropertyBase
;
118 // property implementation class
119 class cPsiShieldProperty
: public cPsiShieldPropertyBase
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
,
144 StructDescRegister(&psiShieldStructDesc
);
145 return new cPsiShieldProperty(desc
);
148 static sPropertyDesc psiShieldDesc
=
150 PROP_PSI_SHIELD_DESC
,
155 {"Psi", "Shield Description"},
158 sPsiShield defaultPsiShield
=
163 void PsiShieldPropertyInit()
165 g_pPsiShieldProperty
= CreatePsiShieldProperty(&psiShieldDesc
, kPropertyImplDense
);
168 //////////////////////////////////////////////////
172 IPsiStateProperty
*g_pPsiStateProperty
;
174 typedef cSpecificProperty
<IPsiStateProperty
, &IID_IPsiStateProperty
, cPsiState
*, cHashPropertyStore
<cNoZeroDataOps
<cPsiState
> > > cPsiStatePropertyBase
;
176 // property implementation class
177 class cPsiStateProperty
: public cPsiStatePropertyBase
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
,
202 StructDescRegister(&PsiStateStructDesc
);
203 return new cPsiStateProperty(desc
);
206 static sPropertyDesc psiStateDesc
=
209 kPropertyInstantiate
,
216 sPsiState defaultPsiState
=
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
))
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
)
281 // this is kind of grody...
284 g_PsiOverloadProperty
->Get(obj
, &powers
);
285 return(powers
& (1 << which
));
289 g_PsiOverload2Property
->Get(obj
, &powers
);
290 return(powers
& (1 << (which
- 32)));
294 void PsiSetOverload(ObjID obj
, ePsiPowers which
, BOOL val
)
299 g_PsiOverloadProperty
->Get(obj
, &powers
);
301 powers
= powers
| (1 << which
);
303 powers
= powers
& (~(1 << which
));
304 g_PsiOverloadProperty
->Set(obj
, powers
);
308 g_PsiOverload2Property
->Get(obj
, &powers
);
310 powers
= powers
| (1 << (which
- 32));
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
=
344 sizeof(RadarFields
)/sizeof(RadarFields
[0]),
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
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
);
418 class cESndTagOps
: public cClassDataOps
<sOpsList
>
420 typedef cClassDataOps
<sOpsList
> cParent
;
423 cESndTagOps() : cParent(kNoFlags
) {} ;
424 STDMETHOD(Read
)(THIS_ sDatum
* dat
, IDataOpsFile
* file
, int version
)
428 sOpsList
* list
= (sOpsList
*)dat
->value
;
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
);
440 class cESndTagStore
: public cListPropertyStore
<cESndTagOps
>
444 class cESndTagProperty
: public cSpecificProperty
<IESndTagProperty
,
445 &IID_IESndTagProperty
, sESndTagList
*, cESndTagStore
>
448 typedef cSpecificProperty
<IESndTagProperty
,
449 &IID_IESndTagProperty
,
451 cESndTagStore
> cParent
;
454 cESndTagProperty(const sPropertyDesc
* desc
)
459 STANDARD_DESCRIBE_TYPE(sESndTagList
);
463 static sPropertyDesc g_PsiPropDesc
=
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
);
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
);