-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathp_pickup.c
389 lines (349 loc) · 6.76 KB
/
p_pickup.c
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
// new pickup handling
// by kgsws
#include "doomdef.h"
#include "doomstat.h"
#include "p_local.h"
#include "p_inter.h"
#include "p_pickup.h"
#include "s_sound.h"
#include "sounds.h"
#ifdef SERVER
#include <netinet/in.h>
#include "network.h"
#include "sv_cmds.h"
#endif
#include "dstrings.h"
// pickup types; returned by pickup function
#define SPECIAL_DONTPICKUP -1
#define SPECIAL_ITEM 0
#define SPECIAL_WEAPON 1
#define SPECIAL_KEY 2
#define SPECIAL_POWER 3
#define SPECIAL_SUPERPOWER 4
// [kg] decide to remove or hide item
void P_RemoveSpecial(mobj_t* th, int rt)
{
int respawntime;
if(th->flags & MF_DROPPED)
{
#ifdef SERVER
P_RemoveMobj(th, true);
#else
P_RemoveMobj(th);
#endif
return;
}
switch(rt)
{
case SPECIAL_ITEM:
respawntime = sv_itemrespawn;
break;
case SPECIAL_WEAPON:
respawntime = sv_weaponrespawn;
break;
case SPECIAL_KEY:
respawntime = netgame ? -1 : 0;
break;
case SPECIAL_POWER:
respawntime = sw_powerrespawn;
break;
case SPECIAL_SUPERPOWER:
respawntime = sv_superrespawn;
break;
default:
respawntime = 0;
break;
}
if(!respawntime)
{
#ifdef SERVER
P_RemoveMobj(th, true);
#else
P_RemoveMobj(th);
#endif
return;
}
if(respawntime < 0)
return;
// hide item
P_UnsetThingPosition(th);
th->flags |= MF_NOSECTOR | MF_NOBLOCKMAP;
P_SetMobjState(th, S_ITEMRESPAWN0);
// set respawn time
th->tics = respawntime;
#ifdef SERVER
// tell clients about this
// client th->tics is -1, which is good
SV_UpdateMobj(th, SV_MOBJF_FLAGS | SV_MOBJF_STATE);
#endif
}
// [kg] unhide item and spawn IFOG
void A_RespawnSpecial(mobj_t* th)
{
#ifndef SERVER
if(netgame)
return;
#endif
subsector_t* ss;
mobj_t* mo;
fixed_t x = th->x;
fixed_t y = th->y;
// spawn a teleport fog at the new spot
ss = R_PointInSubsector (x,y);
mo = P_SpawnMobj (x, y, ss->sector->floorheight , MT_IFOG);
if(mo->info->seesound)
S_StartSound (mo, mo->info->seesound, SOUND_BODY);
#ifdef SERVER
// tell clients about this
SV_SpawnMobj(mo, SV_MOBJF_SOUND_SEE);
#endif
// unhide item
P_SetMobjState(th, th->info->spawnstate);
th->flags &= ~(MF_NOSECTOR | MF_NOBLOCKMAP);
P_SetThingPosition(th);
#ifdef SERVER
// tell clients about this
SV_UpdateMobj(th, SV_MOBJF_FLAGS | SV_MOBJF_STATE);
#endif
}
// [kg] new touch handler
void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher)
{
int sound, type;
player_t *pl;
if(toucher->z > special->z + special->info->height)
// out of reach
return;
if(toucher->z + toucher->info->height < special->z)
// out of reach
return;
if(!special->info->action.acp2i)
return;
sound = special->info->activesound;
pl = toucher->player;
if(!pl || pl->health <= 0)
// only alive players can do this
return;
type = special->info->action.acp2i(pl, special);
if(type == SPECIAL_DONTPICKUP)
return;
if(special->flags & MF_COUNTITEM)
pl->itemcount++;
P_RemoveSpecial(special, type);
#ifdef SERVER
// tell client about it
SV_PlayerPickup(pl, special);
SV_PlayerInventory(pl);
#else
if(special->info->arg)
pl->message = (char *)special->info->arg;
pl->bonuscount += BONUSADD;
if(pl == &players[consoleplayer] && sound)
S_StartSound(toucher, sound, SOUND_PICKUP);
#endif
}
//
// item pickup functions
int A_PickGreenArmor(player_t *pl, mobj_t *mo)
{
#ifndef SERVER
if(!netgame)
#endif
{
if(!P_GiveArmor(pl, 1))
return SPECIAL_DONTPICKUP;
}
return SPECIAL_ITEM;
}
int A_PickBlueArmor(player_t *pl, mobj_t *mo)
{
#ifndef SERVER
if(!netgame)
#endif
{
if(!P_GiveArmor(pl, 2))
return SPECIAL_DONTPICKUP;
}
return SPECIAL_ITEM;
}
int A_PickHealthBonus(player_t *pl, mobj_t *mo)
{
#ifndef SERVER
if(!netgame)
#endif
{
pl->health++;
if(pl->health > 200)
pl->health = 200;
pl->mo->health = pl->health;
}
return SPECIAL_ITEM;
}
int A_PickArmorBonus(player_t *pl, mobj_t *mo)
{
#ifndef SERVER
if(!netgame)
#endif
{
pl->armorpoints++;
if(pl->armorpoints > 200)
pl->armorpoints = 200;
if(!pl->armortype)
pl->armortype = 1;
}
return SPECIAL_ITEM;
}
int A_PickKey(player_t *pl, mobj_t *mo)
{
#ifndef SERVER
if(!netgame)
#endif
{
int key = mo->info->damage;
if(pl->cards[key])
return SPECIAL_DONTPICKUP;
pl->cards[key] = true;
}
return SPECIAL_KEY;
}
int A_PickHealth10(player_t *pl, mobj_t *mo)
{
#ifndef SERVER
if(!netgame)
#endif
{
if(pl->health >= MAXHEALTH)
return SPECIAL_DONTPICKUP;
pl->health += 10;
if(pl->health > MAXHEALTH)
pl->health = MAXHEALTH;
pl->mo->health = pl->health;
}
return SPECIAL_ITEM;
}
int A_PickHealth25(player_t *pl, mobj_t *mo)
{
int oldhp = pl->health;
#ifndef SERVER
if(!netgame)
#endif
{
if(pl->health >= MAXHEALTH)
return SPECIAL_DONTPICKUP;
pl->health += 25;
if(pl->health > MAXHEALTH)
pl->health = MAXHEALTH;
pl->mo->health = pl->health;
}
if(oldhp < 25)
pl->message = GOTMEDINEED;
else
pl->message = GOTMEDIKIT;
return SPECIAL_ITEM;
}
int A_PickSoulSphere(player_t *pl, mobj_t *mo)
{
#ifndef SERVER
if(!netgame)
#endif
{
pl->health += 100;
if(pl->health > 200)
pl->health = 200;
pl->mo->health = pl->health;
}
return SPECIAL_POWER;
}
int A_PickPower(player_t *pl, mobj_t *mo)
{
#ifndef SERVER
if(!netgame)
#endif
{
if(!P_GivePower(pl, mo->info->damage))
return SPECIAL_DONTPICKUP;
}
if(mo->info->speed)
return SPECIAL_SUPERPOWER;
else
return SPECIAL_POWER;
}
int A_PickMegaSphere(player_t *pl, mobj_t *mo)
{
#ifndef SERVER
if(!netgame)
#endif
{
pl->health = 200;
pl->mo->health = pl->health;
P_GiveArmor(pl,2);
}
return SPECIAL_POWER;
}
int A_PickAmmo(player_t *pl, mobj_t *mo)
{
#ifndef SERVER
if(!netgame)
#endif
{
int count = mo->info->speed;
if(mo->flags & MF_DROPPED)
count /= 2;
if(!P_GiveAmmo(pl, mo->info->damage, count))
return SPECIAL_DONTPICKUP;
}
return SPECIAL_ITEM;
}
int A_PickBackpack(player_t *pl, mobj_t *mo)
{
#ifndef SERVER
if(!netgame)
#endif
{
int i;
if(!pl->backpack)
{
for(i = 0; i < NUMAMMO; i++)
pl->maxammo[i] *= 2;
pl->backpack = true;
}
for(i = 0; i < NUMAMMO; i++)
P_GiveAmmo(pl, i, 0);
}
return SPECIAL_ITEM;
}
int A_PickWeapon(player_t *pl, mobj_t *mo)
{
#ifndef SERVER
if(!netgame)
#endif
{
int weapon = mo->info->damage;
int ammo = weaponinfo[weapon].ammo;
boolean nope = true;
if(!(mo->flags & MF_DROPPED) && sv_weaponrespawn < 0 && pl->weaponowned[weapon])
// weird deathmatch type; pickup only once
return SPECIAL_DONTPICKUP;
if(!pl->weaponowned[weapon])
nope = false;
if(ammo < NUMAMMO)
{
int count = mo->info->speed;
if(mo->flags & MF_DROPPED)
count /= 2;
else
if(sv_weaponrespawn < 0)
count = (count / 2) * 5;
if(P_GiveAmmo(pl, ammo, count))
nope = false;
}
#ifndef SERVER
if(!pl->weaponowned[weapon])
pl->pendingweapon = weapon;
#endif
pl->weaponowned[weapon] = true;
if(nope)
return SPECIAL_DONTPICKUP;
}
return SPECIAL_WEAPON;
}