forked from dumptruckDS/progs_dump_qc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keydata.qc
222 lines (173 loc) · 5.29 KB
/
keydata.qc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
========================================================================
FUNCTIONS WHICH DEAL WITH KEY ITEM BITFLAGS AND NAMES
========================================================================
This file was created for progs_dump by Ian "iw" Walshaw, January 2020.
It defines functions which deal with the bitflags and names which refer
to the key items, including the new item_key_custom.
These functions are a dependency of the updated code for the key items
(in items.qc) and also the updated code for unlockable entities (in
keylock.qc).
========================================================================
*/
string() SilverKeyName;
string() GoldKeyName;
float(string key_name) CustomKeyFlag;
entity(string key_name) SpawnCustomKeyDef;
entity(string key_name) FindCustomKeyDef;
float(entity client, float item_flags, float customkey_flags) HasKeys;
void(entity client, float item_flags, float customkey_flags) GiveKeys;
void(entity client) GiveAllKeys;
void(entity client, float item_flags, float customkey_flags) RemoveKeys;
// The highest bitflag that will be assigned to a custom key.
float FINAL_CUSTOM_KEY = 4194304;
// The highest bitflag that has been assigned to a custom key.
float highest_custom_key;
/*
============
SilverKeyName
Return the name that should be used for the silver key as per
world.worldtype. -- iw
============
*/
string() SilverKeyName =
{
if (world.worldtype == WORLDTYPE_BASE)
return "silver keycard";
if (world.worldtype == WORLDTYPE_METAL)
return "silver runekey";
return "silver key";
};
/*
============
GoldKeyName
Return the name that should be used for the gold key as per
world.worldtype. -- iw
============
*/
string() GoldKeyName =
{
if (world.worldtype == WORLDTYPE_BASE)
return "gold keycard";
if (world.worldtype == WORLDTYPE_METAL)
return "gold runekey";
return "gold key";
};
/*
================
CustomKeyFlag
Return the bitflag that should be used to represent the custom key named
key_name.
More specifically, if this is the first time that this function has been
called for the specified key_name, then return a bitflag which has not
previously been returned by this function for any key_name. Otherwise,
return the same bitflag that was previously returned for the specified
key_name. -- iw
================
*/
float(string key_name) CustomKeyFlag =
{
local entity key_def;
key_def = FindCustomKeyDef (key_name);
if (key_def == world)
key_def = SpawnCustomKeyDef (key_name);
return key_def.customkeys;
};
/*
================
SpawnCustomKeyDef
Spawn and return a new custom_key_def entity which will define the
custom key named key_name.
The value of the entity's customkeys field will be a bitflag which has
not yet been used to represent a custom key. -- iw
================
*/
entity(string key_name) SpawnCustomKeyDef =
{
local entity key_def;
if (highest_custom_key == FINAL_CUSTOM_KEY)
error ("too many custom keys");
if (highest_custom_key == 0)
highest_custom_key = 1;
else
highest_custom_key = highest_custom_key * 2;
key_def = spawn ();
key_def.classname = "custom_key_def";
key_def.netname = key_name;
key_def.customkeys = highest_custom_key;
return key_def;
};
/*
================
FindCustomKeyDef
If a custom_key_def entity exists which defines the custom key named
key_name, then find and return it, otherwise return world.
If a custom_key_def entity is returned, then the value of its customkeys
field will be the bitflag that should be used to represent the custom
key named key_name. -- iw
================
*/
entity(string key_name) FindCustomKeyDef =
{
local entity key_def;
key_def = find (world, classname, "custom_key_def");
while (key_def != world)
{
if (key_def.netname == key_name)
return key_def;
key_def = find (key_def, classname, "custom_key_def");
}
return world;
};
/*
================
HasKeys
Return TRUE if the specified client has all of the non-custom keys
represented by the item_flags and all of the custom keys represented by
the customkey_flags, otherwise return FALSE. -- iw
================
*/
float(entity client, float item_flags, float customkey_flags) HasKeys =
{
return (client.items & item_flags) == item_flags &&
(client.customkeys & customkey_flags) == customkey_flags;
};
/*
================
GiveKeys
Give the specified client all of the non-custom keys represented by the
item_flags and all of the custom keys represented by the
customkey_flags. -- iw
================
*/
void(entity client, float item_flags, float customkey_flags) GiveKeys =
{
client.items = client.items | item_flags;
client.customkeys = client.customkeys | customkey_flags;
};
/*
================
GiveAllKeys
Give the specified client the silver key, the gold key, and all of the
custom keys that have been defined for the current map. -- iw
================
*/
void(entity client) GiveAllKeys =
{
GiveKeys (client, IT_KEY1 | IT_KEY2, highest_custom_key * 2 - 1);
};
/*
================
RemoveKeys
Remove all of the non-custom keys represented by the item_flags and all
of the custom keys represented by the customkey_flags from the specified
client's inventory. -- iw
================
*/
void(entity client, float item_flags, float customkey_flags) RemoveKeys =
{
client.items = client.items -
(client.items & item_flags);
client.customkeys = client.customkeys -
(client.customkeys & customkey_flags);
};