forked from fabiolimamp/alkaline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapvar.qc
179 lines (142 loc) · 4.91 KB
/
mapvar.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
/*======================================================================
Client Map Variables
--------------------
Allows for binary (0/1) map variables to be stored with the map save
system (parm1-16) by the engine. The top 6 parm variables are never used
and can easily be turned into variables for the map to use.
Adapted from AD
======================================================================*/
// Setup the bitflag array (used in world.qc)
void() mapvar_setuparray = {
local float bitindex, bitpow;
// Setup loop and first bit
bitindex = 0; bitpow = 1;
while (bitindex < 24) {
bitflags[bitindex] = bitpow;
bitpow = bitpow * 2;
bitindex = bitindex + 1;
}
};
//----------------------------------------------------------------------
// Reset all map variable banks to zero (used in client.qc)
void() mapvar_reset = {
local float mapv_bank;
mapv_bank = 0;
while (mapv_bank < MAPV_BLCK) {
mapvars[mapv_bank] = 0;
mapv_bank = mapv_bank + 1;
}
};
//----------------------------------------------------------------------
// Read map variable from block/bits parms and return value
float(float mapv_indx) read_mapvar = {
local float mapv_bank, mapv_cell, mapv_bit;
// Work out parm and bitflag index
mapv_bank = floor(mapv_indx/MAPV_BITS);
mapv_cell = mapv_indx - (mapv_bank*MAPV_BITS);
// Error check return value
if (mapv_bank < 0 || mapv_bank >= MAPV_BLCK) mapv_bank = 0;
if (mapv_cell < 0 || mapv_cell >= MAPV_BITS) mapv_cell = 0;
// Find bitflag mask value
mapv_bit = mapvars[mapv_bank] & bitflags[mapv_cell];
if (mapv_bit > 0) return TRUE;
else return FALSE;
};
//----------------------------------------------------------------------
// Update map variable from block/bits parms
void(float mapv_indx, float mapv_val) write_mapvar =
{
local float mapv_bank, mapv_cell, curr_bits;
// Work out parm and bitflag index
mapv_bank = floor(mapv_indx/MAPV_BITS);
mapv_cell = mapv_indx - (mapv_bank*MAPV_BITS);
// Error check return value
if (mapv_bank < 0 || mapv_bank >= MAPV_BLCK) mapv_bank = 0;
if (mapv_cell < 0 || mapv_cell >= MAPV_BITS) mapv_cell = 0;
// get the current flag value
curr_bits = mapvars[mapv_bank] & bitflags[mapv_cell];
if (mapv_val == MAPV_WRITE_ON || (mapv_val == MAPV_WRITE_TOGGLE && !curr_bits)) {
mapvars[mapv_bank] = mapvars[mapv_bank] | bitflags[mapv_cell];
dprint3("Set mapvar #", ftos(mapv_indx), " to 1\n");
}
else {
mapvars[mapv_bank] = mapvars[mapv_bank] - (mapvars[mapv_bank] & bitflags[mapv_cell]);
dprint3("Set mapvar #", ftos(mapv_indx), " to 0\n");
}
};
//----------------------------------------------------------------------
// Display the value of all map variable parm blocks
void() display_mapvar = {
local float loopbank, loopcell, loopspace, loopval;
// Default return conditions (must be player and developer)
if ( !(self.flags & FL_CLIENT) ) return;
if (developer == 0) {
sprint(self,"\b[IMPULSE]\b Only works in developer mode!\n");
return;
}
// Has the map variable system been setup?
if (!mapvar_cvar) {
sprint(self,"\b[MAPVAR]\b System has not been setup yet!\n");
return;
}
// Reset impulse and initialize variables
self.impulse = 0;
loopbank = loopcell = 0;
dprint("\n\b[MAPVAR]\b Current System Values\n");
dprint("--------------------------------------\n");
while (loopbank < MAPV_BLCK) {
dprint("Bank "); dprint(ftos(loopbank)); dprint(" - ");
loopcell = 0; loopspace = 4;
while (loopcell < MAPV_BITS) {
loopval = read_mapvar((loopbank*MAPV_BITS)+loopcell);
dprint(ftos(loopval));
loopcell = loopcell+1;
if (loopcell == loopspace) {
dprint(" ");
loopspace = loopspace+4;
}
}
dprint("\n");
loopbank = loopbank+1;
}
dprint("--------------------------------------\n");
};
void() trigger_mapvar_write_use = {
write_mapvar(self.count, self.style);
};
void() trigger_mapvar_write = {
if (!self.count)
objerror("Mapvar id not selected");
if (self.count < 1 || self.count > MAPV_TOTAL)
objerror("Mapvar id out of range");
self.style = defaultFl(self.style, MAPV_WRITE_ON);
self.use = trigger_mapvar_write_use;
};
void() trigger_mapvar_read_use = {
float mapvar_val;
mapvar_val = read_mapvar(self.count);
if ((self.style == MAPV_READ_ON && mapvar_val) || (self.style == MAPV_READ_OFF && !mapvar_val)) {
SUB_UseTargets();
}
};
void() trigger_mapvar_read_start = {
entity pl;
dprint3("trigger_mapvar_read fired automatically at (", vtos(self.origin), ")\n");
pl = find(world, classname, "player");
if (!pl) return;
activator = pl;
trigger_mapvar_read_use();
};
void() trigger_mapvar_read = {
if (!self.count)
objerror("Mapvar id not selected");
if (self.count < 1 || self.count > MAPV_TOTAL)
objerror("Mapvar id out of range");
self.style = defaultFl(self.style, MAPV_READ_ON);
self.use = trigger_mapvar_read_use;
// if it doesn't have a targetname, runs automatically at startup
if (!self.targetname) {
self.think = trigger_mapvar_read_start;
self.nextthink = time + 0.5;
}
};