From fbaef4794ed00e25bee26c577a64836dc26f3d5b Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 14 Feb 2009 10:02:47 +0100 Subject: [PATCH] Fix lmine for engineers that don't use ammo landmine() used resupply_commod() to get shells, but that doesn't get any unless the engineer uses ammo. Use supply_commod() instead. --- src/lib/commands/mine.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/lib/commands/mine.c b/src/lib/commands/mine.c index 7cdd63b67..3d97136a0 100644 --- a/src/lib/commands/mine.c +++ b/src/lib/commands/mine.c @@ -93,9 +93,8 @@ landmine(void) { struct lndstr land; struct sctstr sect; - struct lchrstr *lp; struct nstr_item ni; - int shells; + int shells, todo; int mines_wanted; int mines_laid; int total_mines_laid; @@ -106,8 +105,7 @@ landmine(void) while (nxtitem(&ni, &land)) { if (!player->owner) continue; - lp = &lchr[(int)land.lnd_type]; - if (!(lp->l_flags & L_ENGINEER)) + if (!(lchr[land.lnd_type].l_flags & L_ENGINEER)) continue; if (land.lnd_ship >= 0 || land.lnd_land >= 0) { pr("%s is on a %s\n", prland(&land), @@ -118,11 +116,6 @@ landmine(void) pr("%s is out of mobility\n", prland(&land)); continue; } - resupply_commod(&land, I_SHELL); - putland(land.lnd_uid, &land); - if (!(shells = land.lnd_item[I_SHELL])) - continue; - shells = MIN(shells, land.lnd_mobil); if (!getsect(land.lnd_x, land.lnd_y, §) || sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN || sect.sct_own != land.lnd_own) { @@ -141,18 +134,23 @@ landmine(void) if (!check_land_ok(&land) || !check_sect_ok(§)) continue; land.lnd_mission = 0; + todo = MIN(mines_wanted, land.lnd_mobil); total_mines_laid = 0; - while (shells > 0 && total_mines_laid < mines_wanted) { - mines_laid = MIN(shells, mines_wanted - total_mines_laid); + do { + shells = land.lnd_item[I_SHELL]; + if (shells < todo) + shells += supply_commod(land.lnd_own, + land.lnd_x, land.lnd_y, I_SHELL, + todo - shells); + mines_laid = MIN(todo, shells); land.lnd_item[I_SHELL] = shells - mines_laid; land.lnd_mobil -= mines_laid; putland(land.lnd_uid, &land); - resupply_commod(&land, I_SHELL); /* Get more shells */ - putland(land.lnd_uid, &land); total_mines_laid += mines_laid; - shells = land.lnd_item[I_SHELL]; - shells = MIN(shells, land.lnd_mobil); - } + todo -= mines_laid; + } while (todo && mines_laid); + resupply_commod(&land, I_SHELL); + putland(land.lnd_uid, &land); getsect(sect.sct_x, sect.sct_y, §); sect.sct_mines = MIN(sect.sct_mines + total_mines_laid, MINES_MAX); putsect(§); -- 2.43.0