forked from itslunaranyo/copper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item_backpack.qc
320 lines (274 loc) · 8.31 KB
/
item_backpack.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
/*
===============================================================================
BACKPACKS
===============================================================================
*/
/*
================================
print_quant
pretty-print a quantity to a client's buffer
================================
*/
void(float amt, string noun, entity to) print_quant =
{
string s;
if (amt == 1)
{
sprint (to, "1 ");
sprint (to, noun);
return;
}
s = ftos(amt);
sprint (to, s);
sprint (to, " ");
sprint (to, noun);
sprint (to, "s");
}
/*
================================
BackpackTouch
================================
*/
void() BackpackTouch =
{
if (!CheckValidTouch()) return;
// coop 1: players can only pick up their own backpacks
//if (coop == 1 && self.buddy && self.buddy != other) return;
// reverted:
// with no good way to indicate whose backpack is whose (because .colormap
// only works on players outside the original software renderer) this led to
// a lot of ignored mystery backpacks players kept obsessively touching.
// going out of your way for your own ammo is also a waste of time unless
// the level is extremely linear, which good quake levels never are
float acount;
other.ammo_shells = other.ammo_shells + self.ammo_shells;
other.ammo_nails = other.ammo_nails + self.ammo_nails;
other.ammo_rockets = other.ammo_rockets + self.ammo_rockets;
other.ammo_cells = other.ammo_cells + self.ammo_cells;
bound_ammo(other);
armor_give(other, self.armorvalue, 0, FALSE);
sprint (other, "You got ");
if (self.items && (other.items & self.items) == 0)
{
acount = TRUE;
other.items |= self.items;
sprint (other, "the ");
sprint (other, self.netname);
// change to the weapon
W_BetterWeapon(other, self.items);
}
if (self.armorvalue)
{
if (acount) sprint(other, ", ");
acount = 1;
sprint(other, ftos(self.armorvalue));
sprint(other, " armor");
}
if (self.ammo_shells)
{
if (acount) sprint(other, ", ");
acount = 2;
print_quant(self.ammo_shells, "shell", other);
}
if (self.ammo_nails)
{
if (acount) sprint(other, ", ");
acount = 2;
print_quant(self.ammo_nails, "nail", other);
}
if (self.ammo_rockets)
{
if (acount) sprint(other, ", ");
acount = 2;
print_quant(self.ammo_rockets, "rocket", other);
}
if (self.ammo_cells)
{
if (acount) sprint(other, ", ");
acount = 2;
print_quant(self.ammo_cells, "cell", other);
}
sprint (other, "\n");
// do this after because t_heal prints its own message
if (self.healamount)
T_Heal(other, self.healamount, 0);
// regular monster backpacks don't make the AWESOME NEW backpack sound
if (self.classname == "item_backpack")
{
if (acount == 2)
sound(other, CHAN_ITEM, "items/pack.wav", 1, ATTN_NORM);
else // only got armor, play armor sound instead
sound(other, CHAN_ITEM, "items/patch.wav", 1, ATTN_NORM);
}
else
sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
stuffcmd (other, "bf\n");
if ((coop == 1 && self.buddy && self.buddy == other)
|| (!other.weapon))
SUB_CallAsSelf(W_SelectBestWeapon, other);
else
SUB_CallAsSelf(W_SetCurrentAmmo, other);
ItemTouched();
}
/*
================================
BackpackAutoTouch
backpacks can always be picked up, so mapper-placed ammo backpacks should
give the player something else if they're maxxed out on any ammo types,
since they're little exploration rewards for hiding behind crates and etc
================================
*/
void() BackpackAutoTouch =
{
if (!CheckValidTouch()) return;
if (self.spawnflags & 1)
sprint (other, "You found a big backpack!\n");
else
sprint (other, "You found a backpack\n");
if (other.ammo_shells + self.ammo_shells > MAX_AMMO_SHELLS)
{
self.armorvalue += other.ammo_shells + self.ammo_shells - MAX_AMMO_SHELLS;
self.ammo_shells = MAX_AMMO_SHELLS - other.ammo_shells;
}
if (other.ammo_nails + self.ammo_nails > MAX_AMMO_NAILS)
{
self.armorvalue += ceil((other.ammo_nails + self.ammo_nails - MAX_AMMO_NAILS) / 2);
self.ammo_nails = MAX_AMMO_NAILS - other.ammo_nails;
}
if (other.ammo_rockets + self.ammo_rockets > MAX_AMMO_ROCKETS)
{
self.armorvalue += (other.ammo_rockets + self.ammo_rockets - MAX_AMMO_ROCKETS) * 3;
self.ammo_rockets = MAX_AMMO_ROCKETS - other.ammo_rockets;
}
if (other.ammo_cells + self.ammo_cells > MAX_AMMO_CELLS)
{
self.armorvalue += (other.ammo_cells + self.ammo_cells - MAX_AMMO_CELLS) * 3;
self.ammo_cells = MAX_AMMO_CELLS - other.ammo_cells;
}
self.armorvalue = floor(self.armorvalue / 2);
BackpackTouch();
if (self.wait > 0)
{
// reset all the values we may have just vandalized
self.ammo_shells = floor(3 * random() + 6);
self.ammo_nails = floor(5 * random() + 12);
if (self.spawnflags & 1)
{
self.ammo_shells *= 2;
self.ammo_nails *= 2;
self.ammo_rockets = 2;
self.ammo_cells = 3;
self.skin = 2;
}
self.armorvalue = 0;
}
}
/*QUAKED item_backpack (0 .5 .5) (-16 -16 0) (16 16 40) BIG ? SUSPENDED -
A forgotten explorer's backpack. Grants a paltry sum of shells and nails (about half a small pack of each). Grants armor instead of any ammo the player already has maxed.
Flags:
"big" doubles shells and nails, adds 2 rockets and 4 cells, appears red
Keys:
"target/2/3/4/k" - entity to trigger when picked up
"targetname" - will not spawn until triggered
"wait" - will respawn after 'wait' seconds. fires targets every time.
"count" - limit number of times to respawn
*/
/*FGD
@PointClass base(Item) size(-16 -16 0, 16 16 40) color(0 128 128)
model({ "path": ":progs/backpack.mdl" })
= item_backpack :
"A forgotten explorer's backpack. Grants a paltry sum of shells and nails (about half a small pack of each). Grants armor instead of any ammo the player already has maxed."
[
spawnflags(flags) = [
1 : "Big (2x, red, +2 rockets/4 cells)" : 0
]
]
*/
void() item_backpack =
{
if (!SUB_ShouldSpawn()) return;
precache_model_safe("progs/backpack.mdl");
precache_sound3("items/pack.wav"); // backpacks can play either of these
precache_sound3("items/patch.wav");
setmodel (self, "progs/backpack.mdl");
setsize (self, '-16 -16 0', '16 16 56');
self.skin = 1;
self.ammo_shells = floor(3 * random() + 6);
self.ammo_nails = floor(5 * random() + 12);
if (self.spawnflags & 1)
{
self.ammo_shells *= 2;
self.ammo_nails *= 2;
self.ammo_rockets = 2;
self.ammo_cells = 3;
self.skin = 2;
}
self.touch = BackpackAutoTouch;
StartItem ();
}
/*
===============
DropBackpack
===============
*/
void() DropBackpack =
{
entity item;
if (!(self.ammo_shells + self.ammo_nails + self.ammo_rockets + self.ammo_cells))
return; // nothing in it
item = spawn();
item.origin = self.origin - '0 0 24';
if (coop != 1)
{
item.items = self.weapon;
if (item.items == IT_AXE)
item.netname = string_null;
else if (item.items == IT_SHOTGUN)
item.netname = "Shotgun";
else if (item.items == IT_SUPER_SHOTGUN)
item.netname = "Double-Barrelled Shotgun";
else if (item.items == IT_NAILGUN)
item.netname = "Nailgun";
else if (item.items == IT_SUPER_NAILGUN)
item.netname = "Perforator";
else if (item.items == IT_GRENADE_LAUNCHER)
item.netname = "Grenade Launcher";
else if (item.items == IT_ROCKET_LAUNCHER)
item.netname = "Rocket Launcher";
else if (item.items == IT_LIGHTNING)
item.netname = "Thunderbolt";
else
item.netname = string_null;
}
if (coop == 1)
{
// keep half your shells and nails on respawn to make getting your backpack possible
self.ammo_shells = floor(self.ammo_shells / 2);
self.ammo_nails = floor(self.ammo_nails / 2);
}
item.ammo_shells = self.ammo_shells;
item.ammo_nails = self.ammo_nails;
item.ammo_rockets = self.ammo_rockets;
item.ammo_cells = self.ammo_cells;
item.velocity_z = 300;
item.velocity_x = -100 + (random() * 200);
item.velocity_y = -100 + (random() * 200);
item.flags = FL_ITEM;
item.solid = SOLID_TRIGGER;
item.movetype = MOVETYPE_TOSS;
setmodel (item, "progs/backpack.mdl");
setsize (item, '-16 -16 0', '16 16 56');
item.touch = BackpackTouch;
if (self.flags & FL_CLIENT)
{ // apply player's colormap to his backpack, although currently this only works in software
item.colormap = self.colormap;
item.skin = 3;
if (coop == 1)
{ // players can only pick up their own backpacks, which never despawn (body run rules)
item.buddy = self;
return;
}
}
item.nextthink = time + 116; // remove after 2 minutes
item.think = ItemDespawnBlink; // blink 4 times
}