summaryrefslogtreecommitdiff
path: root/src/money.c
diff options
context:
space:
mode:
authorDiegoisawesome <diego@domoreaweso.me>2017-09-09 20:54:41 -0500
committerDiegoisawesome <diego@domoreaweso.me>2017-09-09 20:54:41 -0500
commita1368c545df5d49c2cde32c09c14aba8d4bdc967 (patch)
tree0dd69e9a676d0d4872e51552d465cbc0364e2a55 /src/money.c
parentf29fc55796cc5500f954b396264edc863f96f486 (diff)
parenteb280768a48eba5332468b463aab962e1eafb18e (diff)
Merge remote-tracking branch 'pret/master'
Diffstat (limited to 'src/money.c')
-rw-r--r--src/money.c55
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);
+}