diff options
Diffstat (limited to 'src/money.c')
-rw-r--r-- | src/money.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/money.c b/src/money.c new file mode 100644 index 000000000..be64d9633 --- /dev/null +++ b/src/money.c @@ -0,0 +1,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); +} |