(loan_owed): New, factored out common code.
(coll, fina, repa, shark, disloan): Use it.
This commit is contained in:
parent
e502056dab
commit
e7c9da21e5
6 changed files with 49 additions and 147 deletions
|
@ -57,9 +57,6 @@ coll(void)
|
|||
struct lonstr loan;
|
||||
struct sctstr sect;
|
||||
coord x, y;
|
||||
long rdur;
|
||||
long xdur;
|
||||
double rate;
|
||||
double owed;
|
||||
double pay;
|
||||
s_char buf[1024];
|
||||
|
@ -79,33 +76,12 @@ coll(void)
|
|||
}
|
||||
/* If we got here, we check to see if it's been defaulted on. We
|
||||
already know it's owed to this player. */
|
||||
(void)time(&now);
|
||||
/*
|
||||
* split duration now - l_lastpay into regular (up to l_duedate)
|
||||
* and extended (beyond l_duedate)
|
||||
*/
|
||||
rdur = loan.l_duedate - loan.l_lastpay;
|
||||
xdur = now - loan.l_duedate;
|
||||
if (rdur < 0) {
|
||||
xdur += rdur;
|
||||
rdur = 0;
|
||||
}
|
||||
if (xdur <= 0) {
|
||||
owed = loan_owed(&loan, time(&now));
|
||||
if (now <= loan.l_duedate) {
|
||||
pr("There has been no default on loan %d\n", arg);
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
rate = loan.l_irate / (loan.l_ldur * 8.64e6);
|
||||
|
||||
/* changed following to avoid overflow 3/27/89 bailey@math-cs.kent.edu
|
||||
owed = ((rdur * rate) + (xdur * rate * 2.0) + 1.0) * loan.l_amtdue;
|
||||
Begin overflow fix */
|
||||
owed = ((rdur * rate) + (xdur * rate * 2.0) + 1.0);
|
||||
if (((1 << 30) / owed) < loan.l_amtdue)
|
||||
owed = (1 << 30);
|
||||
else
|
||||
owed *= loan.l_amtdue;
|
||||
/* End overflow fix */
|
||||
pr("You are owed $%.2f on that loan.\n", owed);
|
||||
if (!(p = getstarg(player->argp[2],
|
||||
"What sector do you wish to confiscate? ", buf)))
|
||||
|
@ -137,7 +113,7 @@ coll(void)
|
|||
}
|
||||
if (sect.sct_type == SCT_CAPIT || sect.sct_type == SCT_MOUNT)
|
||||
caploss(§, sect.sct_own, "that was %s's capital!\n");
|
||||
sect.sct_item[I_MILIT] = 1; /* FIXME no where did this guy come from? */
|
||||
sect.sct_item[I_MILIT] = 1; /* FIXME now where did this guy come from? */
|
||||
|
||||
/* Consider modifying takeover to take a "no che" argument and
|
||||
putting using it here again. */
|
||||
|
|
|
@ -52,10 +52,6 @@ fina(void)
|
|||
struct lonstr loan;
|
||||
struct nstr_item ni;
|
||||
time_t now;
|
||||
int rdur;
|
||||
int xdur;
|
||||
double rate;
|
||||
double amt;
|
||||
|
||||
if (!opt_LOANS) {
|
||||
pr("Loans are not enabled.\n");
|
||||
|
@ -71,40 +67,12 @@ fina(void)
|
|||
while (nxtitem(&ni, (s_char *)&loan)) {
|
||||
if (loan.l_status != LS_SIGNED)
|
||||
continue;
|
||||
/*
|
||||
* split duration now - l_lastpay into regular (up to l_duedate)
|
||||
* and extended (beyond l_duedate)
|
||||
*/
|
||||
rdur = loan.l_duedate - loan.l_lastpay;
|
||||
xdur = now - loan.l_duedate;
|
||||
if (rdur < 0) {
|
||||
xdur += rdur;
|
||||
rdur = 0;
|
||||
}
|
||||
if (xdur < 0) {
|
||||
rdur += xdur;
|
||||
xdur = 0;
|
||||
}
|
||||
|
||||
if (CANT_HAPPEN(loan.l_ldur == 0))
|
||||
continue;
|
||||
rate = loan.l_irate / (loan.l_ldur * 8640000.0);
|
||||
|
||||
/* changed following to avoid overflow 3/27/89 bailey@math-cs.kent.edu
|
||||
amt = (rdur * rate + xdur * rate * 2.0 + 1.0) * loan.l_amtdue;
|
||||
Begin overflow fix */
|
||||
amt = (rdur * rate + xdur * rate * 2.0 + 1.0);
|
||||
if (((1 << 30) / amt) < loan.l_amtdue)
|
||||
amt = (1 << 30);
|
||||
else
|
||||
amt *= loan.l_amtdue;
|
||||
/* End overflow fix */
|
||||
|
||||
pr(" %-2d (%3d) %-8.8s (%3d) %-8.8s ", ni.cur,
|
||||
loan.l_loner, cname(loan.l_loner),
|
||||
loan.l_lonee, cname(loan.l_lonee));
|
||||
pr("%3d%% %3d %5ld %7d",
|
||||
loan.l_irate, loan.l_ldur, loan.l_amtpaid, (int)amt);
|
||||
pr("%3d%% %3d %5ld %7ld",
|
||||
loan.l_irate, loan.l_ldur, loan.l_amtpaid,
|
||||
(long)loan_owed(&loan, now));
|
||||
if (now > loan.l_duedate)
|
||||
pr(" (in arrears)\n");
|
||||
else
|
||||
|
|
|
@ -50,11 +50,7 @@ repa(void)
|
|||
int loan_num;
|
||||
long payment;
|
||||
long owe;
|
||||
long normaltime;
|
||||
long doubletime;
|
||||
double rate_per_sec, amt;
|
||||
s_char *cp;
|
||||
time_t now;
|
||||
s_char buf[1024];
|
||||
|
||||
if (!opt_LOANS) {
|
||||
|
@ -73,36 +69,7 @@ repa(void)
|
|||
pr("You don't owe anything on that loan.\n");
|
||||
return RET_FAIL;
|
||||
}
|
||||
(void)time(&now);
|
||||
/*
|
||||
* split duration now - l_lastpay into regular (up to l_duedate)
|
||||
* and extended (beyond l_duedate)
|
||||
*/
|
||||
normaltime = loan.l_duedate - loan.l_lastpay;
|
||||
doubletime = now - loan.l_duedate;
|
||||
if (normaltime < 0) {
|
||||
doubletime += normaltime;
|
||||
normaltime = 0;
|
||||
}
|
||||
if (doubletime < 0) {
|
||||
normaltime += doubletime;
|
||||
doubletime = 0;
|
||||
}
|
||||
|
||||
rate_per_sec = loan.l_irate /
|
||||
((double)loan.l_ldur * SECS_PER_DAY * 100.0);
|
||||
|
||||
owe = (long)(loan.l_amtdue *
|
||||
((double)normaltime * rate_per_sec + 1.0 +
|
||||
(double)doubletime * rate_per_sec * 2.0) + 0.5);
|
||||
amt = ((double)normaltime * rate_per_sec + 1.0 +
|
||||
(double)doubletime * rate_per_sec * 2.0);
|
||||
if (((1 << 30) / amt) < loan.l_amtdue)
|
||||
owe = (1 << 30);
|
||||
else
|
||||
owe = (long)(loan.l_amtdue *
|
||||
((double)normaltime * rate_per_sec + 1.0 +
|
||||
(double)doubletime * rate_per_sec * 2.0) + 0.5);
|
||||
owe = (long)loan_owed(&loan, time(NULL));
|
||||
if ((cp = getstarg(player->argp[2], "amount? ", buf)) == 0)
|
||||
return RET_SYN;
|
||||
if (!check_loan_ok(&loan))
|
||||
|
|
|
@ -55,9 +55,6 @@ shark(void)
|
|||
struct lonstr loan;
|
||||
struct natstr *natp;
|
||||
struct natstr *oldie;
|
||||
long rdur;
|
||||
long xdur;
|
||||
double rate;
|
||||
double owed;
|
||||
long payment;
|
||||
s_char buf[1024];
|
||||
|
@ -82,29 +79,11 @@ shark(void)
|
|||
return RET_FAIL;
|
||||
}
|
||||
/* If we got here, we check to see if it's been defaulted on. */
|
||||
(void)time(&now);
|
||||
/*
|
||||
* split duration now - l_lastpay into regular (up to l_duedate)
|
||||
* and extended (beyond l_duedate)
|
||||
*/
|
||||
rdur = loan.l_duedate - loan.l_lastpay;
|
||||
xdur = now - loan.l_duedate;
|
||||
if (rdur < 0) {
|
||||
xdur += rdur;
|
||||
rdur = 0;
|
||||
}
|
||||
if (xdur <= 0) {
|
||||
owed = loan_owed(&loan, time(&now));
|
||||
if (now <= loan.l_duedate) {
|
||||
pr("There has been no default on loan %d\n", arg);
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
rate = loan.l_irate / (loan.l_ldur * 8.64e6);
|
||||
|
||||
owed = ((rdur * rate) + (xdur * rate * 2.0) + 1.0);
|
||||
if (((1 << 30) / owed) < loan.l_amtdue)
|
||||
owed = (1 << 30);
|
||||
else
|
||||
owed *= loan.l_amtdue;
|
||||
pr("That loan is worth $%.2f.\n", owed);
|
||||
natp = getnatp(player->cnum);
|
||||
payment = owed * (1.0 + loan.l_irate / 100.0);
|
||||
|
@ -120,7 +99,6 @@ shark(void)
|
|||
cname(player->cnum), arg, payment);
|
||||
pr("You now own loan #%d. Go break some legs.\n", arg);
|
||||
}
|
||||
/* NAT_DELTA(natp->nat_money, loan.l_loner, payment);*/
|
||||
oldie = getnatp(loan.l_loner);
|
||||
oldie->nat_money += payment;
|
||||
player->dolcost += payment;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue