-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
p_inventory.c
676 lines (616 loc) · 18 KB
/
p_inventory.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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
/* DE1: $Id: template.c 2645 2006-01-21 12:58:39Z skyjake $
* Copyright (C) 1999- Activision
*
* This program is covered by the HERETIC / HEXEN (LIMITED USE) source
* code license; you can redistribute it and/or modify it under the terms
* of the HERETIC / HEXEN source code license as published by Activision.
*
* THIS MATERIAL IS NOT MADE OR SUPPORTED BY ACTIVISION.
*
* WARRANTY INFORMATION.
* This program is provided as is. Activision and it's affiliates make no
* warranties of any kind, whether oral or written , express or implied,
* including any warranty of merchantability, fitness for a particular
* purpose or non-infringement, and no other representations or claims of
* any kind shall be binding on or obligate Activision or it's affiliates.
*
* LICENSE CONDITIONS.
* You shall not:
*
* 1) Exploit this Program or any of its parts commercially.
* 2) Use this Program, or permit use of this Program, on more than one
* computer, computer terminal, or workstation at the same time.
* 3) Make copies of this Program or any part thereof, or make copies of
* the materials accompanying this Program.
* 4) Use the program, or permit use of this Program, in a network,
* multi-user arrangement or remote access arrangement, including any
* online use, except as otherwise explicitly provided by this Program.
* 5) Sell, rent, lease or license any copies of this Program, without
* the express prior written consent of Activision.
* 6) Remove, disable or circumvent any proprietary notices or labels
* contained on or within the Program.
*
* You should have received a copy of the HERETIC / HEXEN source code
* license along with this program (Ravenlic.txt); if not:
* http://www.ravensoft.com/
*/
/*
* p_inventory.c: Common code for the player's inventory.
*
* Note:
* The visual representation of which is handled in the HUD code.
*
* Compiles for jHeretic and jHexen.
*/
#if __JHERETIC__ || __JHEXEN__
// HEADER FILES ------------------------------------------------------------
#if __JHERETIC__
# include "jheretic.h"
#elif __JHEXEN__
# include "jhexen.h"
# include "p_player.h" // for P_SetYellowMessage()
#endif
#include "d_net.h"
#include "p_inventory.h"
// MACROS ------------------------------------------------------------------
// TYPES -------------------------------------------------------------------
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
#if __JHEXEN__
boolean P_UsePuzzleItem(player_t *player, int itemType);
#endif
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
// PUBLIC DATA DEFINITIONS -------------------------------------------------
boolean usearti = true;
// PRIVATE DATA DEFINITIONS ------------------------------------------------
// CODE --------------------------------------------------------------------
/*
* Returns true if artifact accepted.
*/
boolean P_GiveArtifact(player_t *player, artitype_e arti, mobj_t *mo)
{
int i;
#if __JHEXEN__
int j;
boolean slidePointer = false;
#endif
if(!player || arti < arti_none + 1 || arti > NUMARTIFACTS - 1)
return false;
player->update |= PSF_INVENTORY;
i = 0;
while(player->inventory[i].type != arti && i < player->inventorySlotNum)
i++;
if(i == player->inventorySlotNum)
{
#if __JHEXEN__
if(arti < arti_firstpuzzitem)
{
i = 0;
while(player->inventory[i].type < arti_firstpuzzitem &&
i < player->inventorySlotNum)
{
i++;
}
if(i != player->inventorySlotNum)
{
for(j = player->inventorySlotNum; j > i; j--)
{
player->inventory[j].count =
player->inventory[j - 1].count;
player->inventory[j].type = player->inventory[j - 1].type;
slidePointer = true;
}
}
}
#endif
player->inventory[i].count = 1;
player->inventory[i].type = arti;
player->inventorySlotNum++;
}
else
{
#if __JHEXEN__
if(arti >= arti_firstpuzzitem && IS_NETGAME && !deathmatch)
{ // Can't carry more than 1 puzzle item in coop netplay
return false;
}
#endif
if(player->inventory[i].count >= MAXARTICOUNT)
{ // Player already has max number of this item
return false;
}
player->inventory[i].count++;
}
if(!player->artifactCount)
{
player->readyArtifact = arti;
}
#if __JHEXEN__
else if(slidePointer && i <= player->inv_ptr)
{
player->inv_ptr++;
player->curpos++;
if(player->curpos > 6)
{
player->curpos = 6;
}
}
#else
if(mo && (mo->flags & MF_COUNTITEM))
{
player->itemcount++;
}
#endif
player->artifactCount++;
return true;
}
# if __JHERETIC__
void P_InventoryCheckReadyArtifact(player_t *player)
{
if(!player)
return;
if(!player->inventory[player->inv_ptr].count)
{
// Set position markers and get next readyArtifact
player->inv_ptr--;
if(player->inv_ptr < 6)
{
player->curpos--;
if(player->curpos < 0)
{
player->curpos = 0;
}
}
if(player->inv_ptr >= player->inventorySlotNum)
{
player->inv_ptr = player->inventorySlotNum - 1;
}
if(player->inv_ptr < 0)
{
player->inv_ptr = 0;
}
player->readyArtifact = player->inventory[player->inv_ptr].type;
if(!player->inventorySlotNum)
player->readyArtifact = arti_none;
}
}
# endif
void P_InventoryNextArtifact(player_t *player)
{
if(!player)
return;
player->inv_ptr--;
if(player->inv_ptr < 6)
{
player->curpos--;
if(player->curpos < 0)
{
player->curpos = 0;
}
}
if(player->inv_ptr < 0)
{
player->inv_ptr = player->inventorySlotNum - 1;
if(player->inv_ptr < 6)
{
player->curpos = player->inv_ptr;
}
else
{
player->curpos = 6;
}
}
player->readyArtifact = player->inventory[player->inv_ptr].type;
}
void P_InventoryRemoveArtifact(player_t *player, int slot)
{
int i;
if(!player || slot < 0 || slot > NUMINVENTORYSLOTS)
return;
player->update |= PSF_INVENTORY;
player->artifactCount--;
if(!(--player->inventory[slot].count))
{
// Used last of a type - compact the artifact list
player->readyArtifact = arti_none;
player->inventory[slot].type = arti_none;
for(i = slot + 1; i < player->inventorySlotNum; i++)
{
player->inventory[i - 1] = player->inventory[i];
}
player->inventorySlotNum--;
// Set position markers and get next readyArtifact
player->inv_ptr--;
if(player->inv_ptr < 6)
{
player->curpos--;
if(player->curpos < 0)
player->curpos = 0;
}
if(player->inv_ptr >= player->inventorySlotNum)
player->inv_ptr = player->inventorySlotNum - 1;
if(player->inv_ptr < 0)
player->inv_ptr = 0;
player->readyArtifact = player->inventory[player->inv_ptr].type;
}
}
boolean P_InventoryUseArtifact(player_t *player, artitype_e arti)
{
int i;
boolean success = false;
# if __JHERETIC__
boolean play_sound = false;
# endif
if(!player || arti < arti_none + 1 || arti > NUMARTIFACTS - 1)
return false;
for(i = 0; i < player->inventorySlotNum; i++)
{
if(player->inventory[i].type == arti)
{
// Found match - try to use
if((success = P_UseArtifactOnPlayer(player, arti)) == true)
{
// Artifact was used - remove it from inventory
P_InventoryRemoveArtifact(player, i);
# if __JHERETIC__
play_sound = true;
# else
if(arti < arti_firstpuzzitem)
{
S_ConsoleSound(SFX_ARTIFACT_USE, NULL, player - players);
}
else
{
S_ConsoleSound(SFX_PUZZLE_SUCCESS, NULL, player - players);
}
# endif
ST_InventoryFlashCurrent(player);
}
else if(cfg.inventoryNextOnUnuse)
{
// Unable to use artifact, advance pointer?
# if __JHEXEN__
if(arti < arti_firstpuzzitem)
#endif
P_InventoryNextArtifact(player);
}
break;
}
}
# if __JHERETIC__
if(play_sound)
S_ConsoleSound(sfx_artiuse, NULL, player - players);
# endif
return success;
}
void P_InventoryResetCursor(player_t *player)
{
if(!player)
return;
player->inv_ptr = 0;
player->curpos = 0;
}
/*
* Returns true if the artifact was used.
*/
boolean P_UseArtifactOnPlayer(player_t *player, artitype_e arti)
{
mobj_t *mo;
angle_t angle;
# if __JHEXEN__
int i;
int count;
# endif
if(!player || arti < arti_none + 1 || arti > NUMARTIFACTS - 1)
return false;
switch (arti)
{
case arti_invulnerability:
if(!P_GivePower(player, pw_invulnerability))
{
return (false);
}
break;
# if __JHERETIC__
case arti_invisibility:
if(!P_GivePower(player, pw_invisibility))
{
return (false);
}
break;
# endif
case arti_health:
if(!P_GiveBody(player, 25))
{
return (false);
}
break;
case arti_superhealth:
if(!P_GiveBody(player, 100))
{
return (false);
}
break;
# if __JHEXEN__
case arti_healingradius:
if(!P_HealRadius(player))
{
return (false);
}
break;
# endif
# if __JHERETIC__
case arti_tomeofpower:
if(player->morphTics)
{ // Attempt to undo chicken
if(P_UndoPlayerMorph(player) == false)
{ // Failed
P_DamageMobj(player->plr->mo, NULL, NULL, 10000);
}
else
{ // Succeeded
player->morphTics = 0;
S_StartSound(sfx_wpnup, player->plr->mo);
}
}
else
{
if(!P_GivePower(player, pw_weaponlevel2))
{
return (false);
}
if(player->readyweapon == WP_FIRST)
{
P_SetPsprite(player, ps_weapon, S_STAFFREADY2_1);
}
else if(player->readyweapon == WP_EIGHTH)
{
P_SetPsprite(player, ps_weapon, S_GAUNTLETREADY2_1);
}
}
break;
# endif
case arti_torch:
if(!P_GivePower(player, pw_infrared))
{
return (false);
}
break;
# if __JHERETIC__
case arti_firebomb:
angle = player->plr->mo->angle >> ANGLETOFINESHIFT;
mo = P_SpawnMobj(player->plr->mo->pos[VX] + 24 * finecosine[angle],
player->plr->mo->pos[VY] + 24 * finesine[angle],
player->plr->mo->pos[VZ] - player->plr->mo->floorclip +
15 * FRACUNIT, MT_FIREBOMB);
mo->target = player->plr->mo;
break;
# endif
case arti_egg:
mo = player->plr->mo;
# if __JHEXEN__
P_SpawnPlayerMissile(mo, MT_EGGFX);
P_SPMAngle(mo, MT_EGGFX, mo->angle - (ANG45 / 6));
P_SPMAngle(mo, MT_EGGFX, mo->angle + (ANG45 / 6));
P_SPMAngle(mo, MT_EGGFX, mo->angle - (ANG45 / 3));
P_SPMAngle(mo, MT_EGGFX, mo->angle + (ANG45 / 3));
# else
P_SpawnMissile(mo, NULL, MT_EGGFX);
P_SpawnMissileAngle(mo, MT_EGGFX, mo->angle - (ANG45 / 6), -12345);
P_SpawnMissileAngle(mo, MT_EGGFX, mo->angle + (ANG45 / 6), -12345);
P_SpawnMissileAngle(mo, MT_EGGFX, mo->angle - (ANG45 / 3), -12345);
P_SpawnMissileAngle(mo, MT_EGGFX, mo->angle + (ANG45 / 3), -12345);
# endif
break;
case arti_teleport:
P_ArtiTele(player);
break;
case arti_fly:
if(!P_GivePower(player, pw_flight))
{
return (false);
}
# if __JHEXEN__
if(player->plr->mo->momz <= -35 * FRACUNIT)
{ // stop falling scream
S_StopSound(0, player->plr->mo);
}
# endif
break;
# if __JHEXEN__
case arti_summon:
mo = P_SpawnPlayerMissile(player->plr->mo, MT_SUMMON_FX);
if(mo)
{
mo->target = player->plr->mo;
mo->tracer = player->plr->mo;
mo->momz = 5 * FRACUNIT;
}
break;
case arti_teleportother:
P_ArtiTeleportOther(player);
break;
case arti_poisonbag:
angle = player->plr->mo->angle >> ANGLETOFINESHIFT;
if(player->class == PCLASS_CLERIC)
{
mo = P_SpawnMobj(player->plr->mo->pos[VX] + 16 * finecosine[angle],
player->plr->mo->pos[VY] + 24 * finesine[angle],
player->plr->mo->pos[VZ] - player->plr->mo->floorclip +
8 * FRACUNIT, MT_POISONBAG);
if(mo)
{
mo->target = player->plr->mo;
}
}
else if(player->class == PCLASS_MAGE)
{
mo = P_SpawnMobj(player->plr->mo->pos[VX] + 16 * finecosine[angle],
player->plr->mo->pos[VY] + 24 * finesine[angle],
player->plr->mo->pos[VZ] - player->plr->mo->floorclip +
8 * FRACUNIT, MT_FIREBOMB);
if(mo)
{
mo->target = player->plr->mo;
}
}
else // PCLASS_FIGHTER, obviously (also pig, not so obviously)
{
mo = P_SpawnMobj(player->plr->mo->pos[VX],
player->plr->mo->pos[VY],
player->plr->mo->pos[VZ] - player->plr->mo->floorclip +
35 * FRACUNIT, MT_THROWINGBOMB);
if(mo)
{
mo->angle =
player->plr->mo->angle + (((P_Random() & 7) - 4) << 24);
mo->momz =
4 * FRACUNIT +
(((int) player->plr->lookdir) << (FRACBITS - 4));
mo->pos[VZ] += ((int) player->plr->lookdir) << (FRACBITS - 4);
P_ThrustMobj(mo, mo->angle, mo->info->speed);
mo->momx += player->plr->mo->momx >> 1;
mo->momy += player->plr->mo->momy >> 1;
mo->target = player->plr->mo;
mo->tics -= P_Random() & 3;
P_CheckMissileSpawn(mo);
}
}
break;
case arti_speed:
if(!P_GivePower(player, pw_speed))
{
return (false);
}
break;
case arti_boostmana:
if(!P_GiveMana(player, MANA_1, MAX_MANA))
{
if(!P_GiveMana(player, MANA_2, MAX_MANA))
{
return false;
}
}
else
{
P_GiveMana(player, MANA_2, MAX_MANA);
}
break;
case arti_boostarmor:
count = 0;
for(i = 0; i < NUMARMOR; i++)
{
count += P_GiveArmor(player, i, 1); // 1 point per armor type
}
if(!count)
{
return false;
}
break;
case arti_blastradius:
P_BlastRadius(player);
break;
case arti_puzzskull:
case arti_puzzgembig:
case arti_puzzgemred:
case arti_puzzgemgreen1:
case arti_puzzgemgreen2:
case arti_puzzgemblue1:
case arti_puzzgemblue2:
case arti_puzzbook1:
case arti_puzzbook2:
case arti_puzzskull2:
case arti_puzzfweapon:
case arti_puzzcweapon:
case arti_puzzmweapon:
case arti_puzzgear1:
case arti_puzzgear2:
case arti_puzzgear3:
case arti_puzzgear4:
if(P_UsePuzzleItem(player, arti - arti_firstpuzzitem))
{
return true;
}
else
{
P_SetYellowMessage(player, TXT_USEPUZZLEFAILED, false);
return false;
}
break;
# endif
default:
return false;
}
return true;
}
/*
* Does not bother to check the validity of the params as the only
* caller is DEFCC(CCmdInventory) (bellow).
*/
static boolean P_InventoryMove(player_t *plr, int dir)
{
if(!ST_IsInventoryVisible())
{
ST_Inventory(true);
return false;
}
ST_Inventory(true); // reset the inventory auto-hide timer
if(dir == 0)
{
plr->inv_ptr--;
if(plr->inv_ptr < 0)
{
plr->inv_ptr = 0;
}
else
{
plr->curpos--;
if(plr->curpos < 0)
{
plr->curpos = 0;
}
}
}
else
{
plr->inv_ptr++;
if(plr->inv_ptr >= plr->inventorySlotNum)
{
plr->inv_ptr--;
if(plr->inv_ptr < 0)
plr->inv_ptr = 0;
}
else
{
plr->curpos++;
if(plr->curpos > 6)
{
plr->curpos = 6;
}
}
}
return true;
}
/*
* Move the inventory selector
*/
DEFCC(CCmdInventory)
{
int player = consoleplayer;
if(argc > 2)
{
Con_Printf("Usage: %s (player)\n", argv[0]);
Con_Printf("If player is not specified, will default to consoleplayer.\n");
return true;
}
if(argc == 2)
player = strtol(argv[1], NULL, 0);
if(player < 0)
player = 0;
if(player > MAXPLAYERS -1)
player = MAXPLAYERS -1;
P_InventoryMove(&players[player], !stricmp(argv[0], "invright"));
return true;
}
#endif