Added increase_gold/bank funcs to prevent cash overflow

This commit is contained in:
JamDog
2010-11-26 14:08:54 +00:00
parent a95ac76ef7
commit 4892b22a51
13 changed files with 230 additions and 101 deletions

View File

@@ -20,6 +20,7 @@
#include "dg_scripts.h"
#include "class.h"
#include "fight.h"
#include "screen.h"
/* local file scope function prototypes */
static int graf(int grafage, int p0, int p1, int p2, int p3, int p4, int p5, int p6);
@@ -474,3 +475,63 @@ void point_update(void)
game_info("Happy hour has ended!");
}
}
/* Note: amt may be negative */
int increase_gold(struct char_data *ch, int amt)
{
int curr_gold;
curr_gold = GET_GOLD(ch);
if (amt < 0) {
GET_GOLD(ch) = MAX(0, curr_gold+amt);
/* Validate to prevent overflow */
if (GET_GOLD(ch) > curr_gold) GET_GOLD(ch) = 0;
} else {
GET_GOLD(ch) = MIN(MAX_GOLD, curr_gold+amt);
/* Validate to prevent overflow */
if (GET_GOLD(ch) < curr_gold) GET_GOLD(ch) = MAX_GOLD;
}
if (GET_GOLD(ch) == MAX_GOLD)
send_to_char(ch, "%sYou have reached the maximum gold!\r\n%sYou must spend it or bank it before you can gain any more.\r\n", QBRED, QNRM);
return (GET_GOLD(ch));
}
int decrease_gold(struct char_data *ch, int deduction)
{
int amt;
amt = (deduction * -1);
increase_gold(ch, amt);
return (GET_GOLD(ch));
}
int increase_bank(struct char_data *ch, int amt)
{
int curr_bank;
if (IS_NPC(ch)) return 0;
curr_bank = GET_BANK_GOLD(ch);
if (amt < 0) {
GET_BANK_GOLD(ch) = MAX(0, curr_bank+amt);
/* Validate to prevent overflow */
if (GET_BANK_GOLD(ch) > curr_bank) GET_BANK_GOLD(ch) = 0;
} else {
GET_BANK_GOLD(ch) = MIN(MAX_BANK, curr_bank+amt);
/* Validate to prevent overflow */
if (GET_BANK_GOLD(ch) < curr_bank) GET_BANK_GOLD(ch) = MAX_BANK;
}
if (GET_BANK_GOLD(ch) == MAX_BANK)
send_to_char(ch, "%sYou have reached the maximum bank balance!\r\n%sYou cannot put more into your account unless you withdraw some first.\r\n", QBRED, QNRM);
return (GET_BANK_GOLD(ch));
}
int decrease_bank(struct char_data *ch, int deduction)
{
int amt;
amt = (deduction * -1);
increase_bank(ch, amt);
return (GET_BANK_GOLD(ch));
}