diff options
author | yenatch <yenatch@gmail.com> | 2017-10-08 23:54:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-08 23:54:46 -0400 |
commit | b0d49dbbfbfcf39c2a9f88572437b6af77c8f709 (patch) | |
tree | be0dadd4cb3a6c36e27233836a6f104359d49949 /src/field/coins.c | |
parent | b21c159b08c57a948edb268ac9b9b5baf6b4332d (diff) | |
parent | 3776a9fb4f0531535b0b5879dab7b3b6bd231736 (diff) |
Merge branch 'master' into scaninc
Diffstat (limited to 'src/field/coins.c')
-rw-r--r-- | src/field/coins.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/field/coins.c b/src/field/coins.c new file mode 100644 index 000000000..91a4b508d --- /dev/null +++ b/src/field/coins.c @@ -0,0 +1,84 @@ +#include "global.h" +#include "coins.h" +#include "menu.h" +#include "string_util.h" +#include "strings.h" + +#define MAX_COINS 9999 + +void UpdateCoinsWindow(s32 coins, u8 x, u8 y) +{ + PrintCoins(coins, 4, x + 2, y + 1); +} + +void ShowCoinsWindow(u32 coins, u8 x, u8 y) +{ + MenuDrawTextWindow(x, y, x + 9, y + 3); + UpdateCoinsWindow(coins, x, y); +} + +void HideCoinsWindow(u8 x, u8 y) +{ + MenuZeroFillWindowRect(x, y, x + 9, y + 3); +} + +void PrintCoins(s32 coins, u8 b, u8 x, u8 y) +{ + u8 string[16]; + u8 *ptr; + u8 r1; + u8 foo; + + ConvertIntToDecimalString(string, coins); + r1 = (b * 6 + 0x21 - 8 * (b + 2)); + x = x - r1 / 8; + foo = r1 % 8; + ptr = gStringVar1; + if (foo) + { + ptr[0] = EXT_CTRL_CODE_BEGIN; + ptr[1] = 0x11; + ptr[2] = 8 - (foo); + ptr += 3; + } + ptr[0] = EXT_CTRL_CODE_BEGIN; + ptr[1] = 0x11; + ptr[2] = (b - StringLength(string)) * 6; + ptr += 3; + StringCopy(ptr, string); + MenuPrint(gOtherText_Coins2, x, y); +} + +u16 GetCoins(void) +{ + return gSaveBlock1.coins; +} + +bool8 GiveCoins(u16 coins) +{ + u32 newCoins; + + if (GetCoins() >= MAX_COINS) + return FALSE; + newCoins = coins + gSaveBlock1.coins; + if (gSaveBlock1.coins > (u16)newCoins) + gSaveBlock1.coins = MAX_COINS; + else + { + gSaveBlock1.coins = newCoins; + if ((u16)newCoins > MAX_COINS) + gSaveBlock1.coins = MAX_COINS; + } + return TRUE; +} + +bool8 TakeCoins(u16 coins) +{ + if (GetCoins() >= coins) + { + gSaveBlock1.coins -= coins; + return TRUE; + } + else + return FALSE; +} |