From 221e88f106ea28a2ed282b2edec410f5cc7460c3 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 11 May 2008 10:48:30 +0200 Subject: [PATCH] Distinguish between sacking and obliterating a capital Make caploss() transfer money, loans and market lots to the player only if he actually took the capital, not if he obliterated it to deity. To make this work, caploss() needs to be called after the sector is updated for damage and change of ownership. Change callers accordingly. Closes #914049. --- src/lib/commands/coll.c | 4 ++-- src/lib/subs/caploss.c | 22 +++++++++++++--------- src/lib/subs/sect.c | 7 ++++--- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/lib/commands/coll.c b/src/lib/commands/coll.c index e2d648cb..d9af0e1c 100644 --- a/src/lib/commands/coll.c +++ b/src/lib/commands/coll.c @@ -106,8 +106,6 @@ coll(void) pr("That is more than is owed!\n"); return RET_FAIL; } - 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 now where did this guy come from? */ /* Consider modifying takeover to take a "no che" argument and @@ -123,6 +121,8 @@ coll(void) sect.sct_dist_x = sect.sct_x; sect.sct_dist_y = sect.sct_y; + if (sect.sct_type == SCT_CAPIT || sect.sct_type == SCT_MOUNT) + caploss(§, loan.l_lonee, "that was %s's capital!\n"); putsect(§); nreport(player->cnum, N_SEIZE_SECT, loan.l_lonee, 1); owed = loan_owed(&loan, time(&now)); diff --git a/src/lib/subs/caploss.c b/src/lib/subs/caploss.c index 6cb50ad3..c3eca1a8 100644 --- a/src/lib/subs/caploss.c +++ b/src/lib/subs/caploss.c @@ -51,8 +51,10 @@ caploss(struct sctstr *sp, natid coun, char *msg) struct comstr comm; long lose; long gain; - int loan_num = 0; - int comm_num = 0; + char *verb; + int loan_num, comm_num; + + CANT_HAPPEN(sp->sct_own && sp->sct_own != player->cnum); natp = getnatp(coun); if (natp->nat_stat != STAT_ACTIVE) @@ -71,18 +73,20 @@ caploss(struct sctstr *sp, natid coun, char *msg) lose = 3000; natp->nat_money -= lose; putnat(natp); - wu(0, coun, "* %s just sacked your capital! *\n", cname(player->cnum)); - - if (gain >= 0) { + if (gain >= 0 && sp->sct_own) { gain = (0.2 + 0.8 * (sp->sct_effic / 100.0)) * gain; player->dolcost -= gain; } else gain = 0; + verb = sp->sct_own ? "sacked" : "obliterated"; + wu(0, coun, "* %s just %s your capital! *\n", + cname(player->cnum), verb); wu(0, coun, "You lost $%ld and they gained $%ld\n", lose, gain); wu(0, coun, "You need to use 'capital' to activate a new capital.\n"); - wu(0, 0, "%s just took %s's capital and gained $%d\n", - cname(player->cnum), cname(coun), -(int)(player->dolcost)); - if (opt_LOANS) { + wu(0, 0, "%s just %s %s's capital and gained $%ld\n", + cname(player->cnum), verb, cname(coun), gain); + + if (opt_LOANS && sp->sct_own) { for (loan_num = 0; getloan(loan_num, &loan); loan_num++) { if (loan.l_status == LS_SIGNED && loan.l_loner == coun) { loan.l_loner = player->cnum; @@ -91,7 +95,7 @@ caploss(struct sctstr *sp, natid coun, char *msg) } } } - if (opt_MARKET) { + if (opt_MARKET && sp->sct_own) { for (comm_num = 0; getcomm(comm_num, &comm); comm_num++) { if (comm.com_owner == 0) continue; diff --git a/src/lib/subs/sect.c b/src/lib/subs/sect.c index 541b9b9b..5674c799 100644 --- a/src/lib/subs/sect.c +++ b/src/lib/subs/sect.c @@ -91,6 +91,7 @@ static int checksect(struct sctstr *sp) { int mil, civs, loyalcivs; + natid own; item_prewrite(sp->sct_item); @@ -113,9 +114,7 @@ checksect(struct sctstr *sp) if (sp->sct_own && !loyalcivs && !(sp->sct_flags & MOVE_IN_PROGRESS)) { if (!mil && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) { /* more cruft! */ - if (sp->sct_type == SCT_CAPIT || sp->sct_type == SCT_MOUNT) - caploss(sp, sp->sct_own, ""); - + own = sp->sct_own; if (sp->sct_oldown == sp->sct_own) { makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); sp->sct_own = 0; @@ -123,6 +122,8 @@ checksect(struct sctstr *sp) } else takeover(sp, sp->sct_oldown); sp->sct_mobil = 0; + if (sp->sct_type == SCT_CAPIT || sp->sct_type == SCT_MOUNT) + caploss(sp, own, ""); } } return 1;