diff options
author | DizzyEggg <jajkodizzy@wp.pl> | 2017-09-09 00:45:25 +0200 |
---|---|---|
committer | DizzyEggg <jajkodizzy@wp.pl> | 2017-09-09 00:45:25 +0200 |
commit | 307278374b57d11b85b419df9ac994967781657b (patch) | |
tree | c825e584a82f41e4298f00985b8665b56c3158d9 /src | |
parent | 5eff1d5bdb69eda1e322dfe2f6df7e2e16c393b3 (diff) |
start money.s decomp
Diffstat (limited to 'src')
-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); +} |