blob: be64d9633158bc49f11116574cfdca1279f36400 (
plain)
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
|
#include "global.h"
#include "money.h"
#define MAX_MONEY 999999
u32 GetMoney(u32* moneyPtr)
{
return *moneyPtr ^ gSaveBlock2Ptr->encryptionKey;
}
void SetMoney(u32* moneyPtr, u32 newValue)
{
*moneyPtr = gSaveBlock2Ptr->encryptionKey ^ newValue;
}
bool8 IsEnoughMoney(u32* moneyPtr, u32 cost)
{
if (GetMoney(moneyPtr) >= cost)
return TRUE;
else
return FALSE;
}
void AddMoney(u32* moneyPtr, u32 toAdd)
{
u32 toSet = GetMoney(moneyPtr);
// can't have more money than MAX
if (toSet + toAdd > MAX_MONEY)
{
toSet = MAX_MONEY;
}
else
{
toSet += toAdd;
// check overflow, can't have less money after you receive more
if (toSet < GetMoney(moneyPtr))
toSet = MAX_MONEY;
}
SetMoney(moneyPtr, toSet);
}
void SubtractMoney(u32* moneyPtr, u32 toSub)
{
u32 toSet = GetMoney(moneyPtr);
// can't subtract more than you already have
if (toSet < toSub)
toSet = 0;
else
toSet -= toSub;
SetMoney(moneyPtr, toSet);
}
|