1 /*
2 #include "a_pickups.h"
3 #include "a_strifeglobal.h"
4 #include "gstrings.h"
5 */
6 
7 // Coin ---------------------------------------------------------------------
8 
IMPLEMENT_CLASS(ACoin) const9 IMPLEMENT_CLASS (ACoin)
10 
11 const char *ACoin::PickupMessage ()
12 {
13 	if (Amount == 1)
14 	{
15 		return Super::PickupMessage();
16 	}
17 	else
18 	{
19 		static char msg[64];
20 
21 		mysnprintf (msg, countof(msg), GStrings("TXT_XGOLD"), Amount);
22 		return msg;
23 	}
24 }
25 
HandlePickup(AInventory * item)26 bool ACoin::HandlePickup (AInventory *item)
27 {
28 	if (item->IsKindOf (RUNTIME_CLASS(ACoin)))
29 	{
30 		if (Amount < MaxAmount)
31 		{
32 			if (MaxAmount - Amount < item->Amount)
33 			{
34 				Amount = MaxAmount;
35 			}
36 			else
37 			{
38 				Amount += item->Amount;
39 			}
40 			item->ItemFlags |= IF_PICKUPGOOD;
41 		}
42 		return true;
43 	}
44 	if (Inventory != NULL)
45 	{
46 		return Inventory->HandlePickup (item);
47 	}
48 	return false;
49 }
50 
CreateCopy(AActor * other)51 AInventory *ACoin::CreateCopy (AActor *other)
52 {
53 	if (GetClass() == RUNTIME_CLASS(ACoin))
54 	{
55 		return Super::CreateCopy (other);
56 	}
57 	AInventory *copy = Spawn<ACoin> (0,0,0, NO_REPLACE);
58 	copy->Amount = Amount;
59 	copy->BecomeItem ();
60 	GoAwayAndDie ();
61 	return copy;
62 }
63 
64 //===========================================================================
65 //
66 // ACoin :: CreateTossable
67 //
68 // Gold drops in increments of 50 if you have that much, less if you don't.
69 //
70 //===========================================================================
71 
CreateTossable()72 AInventory *ACoin::CreateTossable ()
73 {
74 	ACoin *tossed;
75 
76 	if ((ItemFlags & IF_UNDROPPABLE) || Owner == NULL || Amount <= 0)
77 	{
78 		return NULL;
79 	}
80 	if (Amount >= 50)
81 	{
82 		Amount -= 50;
83 		tossed = static_cast<ACoin*>(Spawn("Gold50", Owner->Pos(), NO_REPLACE));
84 	}
85 	else if (Amount >= 25)
86 	{
87 		Amount -= 25;
88 		tossed = static_cast<ACoin*>(Spawn("Gold25", Owner->Pos(), NO_REPLACE));
89 	}
90 	else if (Amount >= 10)
91 	{
92 		Amount -= 10;
93 		tossed = static_cast<ACoin*>(Spawn("Gold10", Owner->Pos(), NO_REPLACE));
94 	}
95 	else if (Amount > 1 || (ItemFlags & IF_KEEPDEPLETED))
96 	{
97 		Amount -= 1;
98 		tossed = static_cast<ACoin*>(Spawn("Coin", Owner->Pos(), NO_REPLACE));
99 	}
100 	else // Amount == 1 && !(ItemFlags & IF_KEEPDEPLETED)
101 	{
102 		BecomePickup ();
103 		tossed = this;
104 	}
105 	tossed->flags &= ~(MF_SPECIAL|MF_SOLID);
106 	tossed->DropTime = 30;
107 	if (tossed != this && Amount <= 0)
108 	{
109 		Destroy ();
110 	}
111 	return tossed;
112 }
113