convert line ends
[canaan.git] / prj / cam / src / deepc / input / dpckey.cpp
blob5b0e009fea38de99d1ea2103964f855ccc217775
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 #include <appagg.h>
8 #include <iobjsys.h>
10 #include <sdesc.h>
11 #include <sdesbase.h>
13 #include <keyprop.h>
14 #include <contain.h>
16 #include <dpckey.h>
18 #include <playrobj.h>
19 #include <dpcplcst.h>
20 #include <dpcplayr.h>
22 #include <netmsg.h>
24 // structure descriptor fun
25 char *access_bit_names[] = {
26 "MED", "SCI", "R&D", "CREW", "CARGO",
27 "REC","HYD A","HYD B","HYD D","SHUTTLE",
28 "CRYO", "MED ANNEX", "SECURITY", "BRIDGE", "CARGO2",
29 "CREW2", "RICKENBACHER", "RICK ROOM","OPS OVERRIDE",
32 static sFieldDesc keyinfo_fields [] =
34 { "MasterBit", kFieldTypeBool, FieldLocation(sKeyInfo,master_bit) },
35 { "RegionID", kFieldTypeBits, FieldLocation(sKeyInfo,region_mask), FullFieldNames(access_bit_names) },
36 { "LockID", kFieldTypeInt, FieldLocation(sKeyInfo,lock_id), kFieldFlagUnsigned },
39 static sStructDesc keyinfo_struct = StructDescBuild(sKeyInfo,kStructFlagNone,keyinfo_fields);
41 ////////////////////
43 // NETWORK CODE
46 // The message that gets broadcast whenever a player gets a new key:
47 static cNetMsg *g_pAddKeyMsg = NULL;
49 // Some other player has gotten a key; I get it too...
50 void handleDPCAddKey(uint region_mask)
52 sKeyInfo *skip;
53 AutoAppIPtr(DPCPlayer);
54 ObjID keyring = pDPCPlayer->GetEquip(PlayerObject(), kEquipFakeKeys);
56 if (!KeySrcProp->IsRelevant(keyring)) {
57 Warning(("Object %d doesn't seem to be a key ring!\n", keyring));
58 return;
60 KeySrcProp->Get(keyring, &skip);
61 skip->region_mask |= region_mask;
62 KeySrcProp->Set(keyring, skip);
65 static sNetMsgDesc sAddKeyDesc =
67 kNMF_Broadcast,
68 "DPCAddKey",
69 "DPC Add Key",
70 NULL,
71 handleDPCAddKey,
72 {{kNMPT_UInt},
73 {kNMPT_End}}
76 ////////////////////
78 BOOL DPCKeyContainsListener(eContainsEvent event, ObjID containee, ObjID new_obj, eContainType, ContainCBData)
80 bool retval = TRUE;
81 sKeyInfo *skip1, *skip2;
83 // we only care about combining
84 if ((event != kContainQueryCombine) && (event != kContainCombine))
85 return(TRUE);
87 // we only care about keys
88 // is this better done after we filter on event?
89 if (!KeySrcProp->IsRelevant(containee) || !KeySrcProp->IsRelevant(new_obj))
90 return(TRUE);
92 KeySrcProp->Get(containee, &skip1);
93 KeySrcProp->Get(new_obj, &skip2);
95 switch (event)
97 case kContainQueryCombine:
98 // only let them merge if their lock_id's are non zero.
99 if ((skip1->lock_id != 0) || (skip2->lock_id != 0))
100 retval = FALSE;
101 break;
103 case kContainCombine:
104 // just binary OR in the bits of the doomed key
105 skip1->region_mask = skip2->region_mask | skip1->region_mask;
106 KeySrcProp->Set(containee, skip1);
107 g_pAddKeyMsg->Send(OBJ_NULL, skip2->region_mask);
108 break;
110 return(retval);
113 void DPCKeyInit(void)
115 AutoAppIPtr(ContainSys);
116 StructDescRegister(&keyinfo_struct);
118 pContainSys->Listen(OBJ_NULL,DPCKeyContainsListener,NULL);
119 g_pAddKeyMsg = new cNetMsg(&sAddKeyDesc);
122 void DPCKeyTerm(void)
124 delete g_pAddKeyMsg;