2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2018, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * lten.c: Transfer commodity from a ship to a land unit the ship is
30 * Known contributors to this file:
35 * Markus Armbruster, 2004-2017
46 static void expose_land(struct shpstr *s1, struct lndstr *l1);
51 struct nstr_item targets;
52 struct nstr_item tenders;
56 struct mchrstr *vbase;
57 struct lchrstr *lbase;
68 if (!(ip = whatitem(player->argp[1], "Transfer what commodity? ")))
71 if (!snxtitem(&tenders, EF_SHIP, player->argp[2], "Tender(s)? "))
73 while (nxtitem(&tenders, &tender)) {
75 if (tenders.sel == NS_LIST)
76 pr("You don't own ship #%d!\n", tender.shp_uid);
79 if (!(p = getstarg(player->argp[3], "Amount to transfer? ", buf)))
81 if (!check_ship_ok(&tender))
83 if ((amt = atoi(p)) == 0)
85 ontender = tender.shp_item[ip->i_uid];
86 if (ontender == 0 && amt > 0) {
87 pr("No %s on %s\n", ip->i_name, prship(&tender));
90 vbase = &mchr[(int)tender.shp_type];
91 maxtender = vbase->m_item[ip->i_uid];
93 pr("%s cannot hold any %s\n", prship(&tender), ip->i_name);
96 if (!snxtitem(&targets, EF_LAND,
97 player->argp[4], "Units to be tended? "))
99 if (!check_ship_ok(&tender))
102 while (nxtitem(&targets, &target)) {
103 if (!player->owner) {
104 if (targets.sel == NS_LIST)
105 pr("You don't own land unit #%d!\n", target.lnd_uid);
108 if (target.lnd_ship != tender.shp_uid) {
109 if (targets.sel == NS_LIST)
110 pr("%s is not on %s!\n",
111 prland(&target), prship(&tender));
114 ontarget = target.lnd_item[ip->i_uid];
115 if (ontarget == 0 && amt < 0) {
116 pr("No %s on %s\n", ip->i_name, prland(&target));
119 lbase = &lchr[(int)target.lnd_type];
120 maxtarget = lbase->l_item[ip->i_uid];
125 /* take from target and give to tender */
126 transfer = MIN(ontarget, -amt);
127 transfer = MIN(maxtender - ontender, transfer);
130 target.lnd_item[ip->i_uid] = ontarget - transfer;
131 ontender += transfer;
134 /* give to target from tender */
135 transfer = MIN(ontender, amt);
136 transfer = MIN(transfer, maxtarget - ontarget);
139 target.lnd_item[ip->i_uid] = ontarget + transfer;
140 ontender -= transfer;
143 expose_land(&tender, &target);
144 putland(target.lnd_uid, &target);
145 if (amt > 0 && ontender == 0) {
146 pr("%s out of %s\n", prship(&tender), ip->i_name);
150 pr("%d total %s transferred %s %s\n",
151 total, ip->i_name, (amt > 0) ? "off of" : "to",
153 tender.shp_item[ip->i_uid] = ontender;
154 tender.shp_mission = 0;
155 putship(tender.shp_uid, &tender);
161 expose_land(struct shpstr *s1, struct lndstr *l1)
163 if (s1->shp_pstage == PLG_INFECT && l1->lnd_pstage == PLG_HEALTHY)
164 l1->lnd_pstage = PLG_EXPOSED;
165 if (l1->lnd_pstage == PLG_INFECT && s1->shp_pstage == PLG_HEALTHY)
166 s1->shp_pstage = PLG_EXPOSED;