-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathforcefield.qc
246 lines (190 loc) · 6.53 KB
/
forcefield.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
misc_forcefield by bmFbr
Based on particle effects QuickC program
By Jim Dose' 9/19/96
Copyright (c)1996 Hipnotic Interactive, Inc.
All rights reserved.
Do not distribute.
*/
float FORCEFIELD_START_ON = 1;
float FORCEFIELD_PULSE = 2;
float FORCEFIELD_SOLID = 4;
float FORCEFIELD_ANGLE_XZ = 1;
float FORCEFIELD_ANGLE_YZ = 2;
float FORCEFIELD_ANGLE_XY = 3;
void(entity e) forcefield_XZ = {
local vector pos;
local vector start;
local vector end;
e.ltime = time + 0.25;
start = e.dest1 + e.origin;
end = e.dest2 + e.origin;
pos_y = start_y;
pos_z = start_z;
while (pos_z <= end_z) {
pos_x = start_x;
while (pos_x <= end_x) {
particle(pos, '0 0 0', e.color, e.count);
pos_x = pos_x + 16;
}
pos_z = pos_z + 16;
}
};
void(entity e) forcefield_YZ = {
local vector pos;
local vector start;
local vector end;
e.ltime = time + 0.25;
start = e.dest1 + e.origin;
end = e.dest2 + e.origin;
pos_x = start_x;
pos_z = start_z;
while (pos_z < end_z) {
pos_y = start_y;
while (pos_y < end_y) {
particle(pos, '0 0 0', e.color, e.count);
pos_y = pos_y + 16;
}
pos_z = pos_z + 16;
}
};
void(entity e) forcefield_XY = {
local vector pos;
local vector start;
local vector end;
start = e.dest1 + e.origin;
end = e.dest2 + e.origin;
pos_x = start_x;
pos_z = start_z;
while (pos_x < end_x) {
pos_y = start_y;
while (pos_y < end_y) {
particle(pos, '0 0 0', e.color, e.count);
pos_y = pos_y + 16;
}
pos_x = pos_x + 16;
}
};
void() forcefield_pulse = {
// Only show particles if client is visible.
// This helps to keep network traffic down to a minimum.
if (!checkclient() )
return;
if(self.fixangle == FORCEFIELD_ANGLE_XZ) forcefield_XZ(self);
else if(self.fixangle == FORCEFIELD_ANGLE_YZ) forcefield_YZ(self);
else if(self.fixangle == FORCEFIELD_ANGLE_XY) forcefield_XY(self);
else return;
if (self.spawnflags & FORCEFIELD_PULSE) return;
if (self.state && !(self.spawnflags & FORCEFIELD_PULSE)) self.nextthink = self.ltime + 0.1;
}
void() forcefield_touch = {
if (!self.dmg)
return;
if (time > self.ltime)
return;
if (time < self.attack_finished)
return;
self.attack_finished = self.ltime + 0.5;
T_Damage(other, self, self, self.dmg, DMGTYPE_ENERGY);
};
void() forcefield_use = {
if (self.noise != "") sound(self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
if(self.spawnflags & FORCEFIELD_PULSE) {
forcefield_pulse();
}
else {
if (!self.state) {
self.state = 1;
self.nextthink = self.ltime + 0.1;
if (self.spawnflags & FORCEFIELD_SOLID) {
self.movetype = MOVETYPE_PUSH;
self.solid = SOLID_BSP;
}
}
else {
self.state = 0;
self.nextthink = -1;
self.movetype = MOVETYPE_NONE;
self.solid = SOLID_NOT;
}
}
}
/*QUAKED misc_forcefield (0 .5 .8) ? FORCEFIELD_START_ON FORCEFIELD_PULSE FORCEFIELD_SOLID X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
Creates a force field particle effect roughly the size of the defining brush. Can be toggled on/off by targeting it.
FORCEFIELD_START_ON Force field will spawn in the active state.
FORCEFIELD_PULSE Instead of a constant effect, the entity will generate a single pulse of the field effect each time it's triggered.
FORCEFIELD_SOLID Blocks movement when the field is active.
"color" is the color of the particles. Default is 192 (yellow).
"count" is the density of the particles. Default is 2.
"noise" is the sound to play when triggered. Do not use a looping sound here.
"dmg" is the amount of damage to cause when touched.
*/
/*FGD
@SolidClass base(Appearflags, Targetname) = misc_forcefield : "Creates a force field particle effect roughly the size of the defining brush. Can be toggled on/off by targeting it.
FORCEFIELD_START_ON Force field will spawn in the active state.
FORCEFIELD_PULSE Instead of a constant effect, the entity will generate a single pulse of the field effect each time it's triggered.
FORCEFIELD_SOLID Blocks movement when the field is active.
color is the color of the particles. Default is 192 (yellow).
count is the density of the particles. Default is 2.
noise is the sound to play when triggered. Do not use a looping sound here.
dmg is the amount of damage to cause when touched."
[
color(integer) : "Palette index for color" : 192
count(integer) : "Density of particles" : 2
dmg(integer) : "Amount of damage when touched" : 0
spawnflags(flags) =
[
1 : "FORCEFIELD_START_ON" : 0
2 : "FORCEFIELD_PULSE" : 0
4 : "FORCEFIELD_SOLID" : 0
]
]
*/
void() misc_forcefield = {
if (!SUB_InitEntity()) return;
if ( !self.color )
self.color = 192;
if ( self.count == 0 )
self.count = 2;
self.classname = "forcefield";
self.solid = SOLID_NOT;
self.movetype = MOVETYPE_NONE;
//self.solid = SOLID_BSP;
//self.movetype = MOVETYPE_PUSH;
self.state = 0;
setmodel (self, self.model);
self.model = string_null;
//self.origin = ( self.mins + self.maxs ) * 0.5;
setorigin (self, self.origin);
self.dest = self.maxs - self.mins - '16 16 16';
self.dest1 = self.mins + '8 8 8' - self.origin;
self.dest2 = self.maxs + '7.9 7.9 7.9' - self.origin;
setsize (self, self.mins, self.maxs);
if(!(self.spawnflags & FORCEFIELD_PULSE)) self.think = forcefield_pulse;
self.touch = forcefield_touch;
self.use = forcefield_use;
// dprint( vtos( self.dest ) );
// dprint( " " );
if (self.dest_x > self.dest_z) {
if (self.dest_y > self.dest_z ) {
self.fixangle = FORCEFIELD_ANGLE_XY;
self.dest1_z = (self.dest1_z + self.dest2_z) / 2;
}
else {
self.fixangle = FORCEFIELD_ANGLE_XZ;
self.dest1_y = ( self.dest1_y + self.dest2_y ) / 2;
}
}
else {
if (self.dest_y > self.dest_x) {
self.fixangle = FORCEFIELD_ANGLE_YZ;
self.dest1_x = ( self.dest1_x + self.dest2_x ) / 2;
}
else {
self.fixangle = FORCEFIELD_ANGLE_XZ;
self.dest1_y = ( self.dest1_y + self.dest2_y ) / 2;
}
}
if (self.noise != "") precache_sound( self.noise );
self.ltime = time;
};