2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program 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 2 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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * lten.c: Transfer commodity from a ship to a land unit the ship is
31 * Known contributors to this file:
49 static void expose_land(struct shpstr *s1, struct lndstr *l1);
54 struct nstr_item targets;
55 struct nstr_item tenders;
59 struct mchrstr *vbase;
60 struct lchrstr *lbase;
71 if (!(ip = whatitem(player->argp[1], "Transfer what commodity? ")))
74 if (!snxtitem(&tenders, EF_SHIP,
75 getstarg(player->argp[2], "Tender(s)? ", buf)))
77 while (nxtitem(&tenders, (s_char *)&tender)) {
81 getstarg(player->argp[3], "Amount to transfer? ", buf)) == 0)
83 if (!check_ship_ok(&tender))
85 if ((amt = atoi(p)) == 0)
87 ontender = tender.shp_item[ip->i_vtype];
88 if (ontender == 0 && amt > 0) {
89 pr("No %s on %s\n", ip->i_name, prship(&tender));
92 vbase = &mchr[(int)tender.shp_type];
93 maxtender = vbase->m_item[ip->i_vtype];
95 pr("A %s cannot hold any %s\n",
96 mchr[(int)tender.shp_type].m_name, ip->i_name);
99 if (!snxtitem(&targets, EF_LAND,
100 getstarg(player->argp[4], "Units to be tended? ",
103 if (!check_ship_ok(&tender))
106 while (nxtitem(&targets, (s_char *)&target)) {
110 if (target.lnd_ship != tender.shp_uid)
112 ontarget = target.lnd_item[ip->i_vtype];
113 if (ontarget == 0 && amt < 0) {
115 ip->i_name, prship((struct shpstr *)&target));
118 lbase = &lchr[(int)target.lnd_type];
119 maxtarget = lbase->l_item[ip->i_vtype];
124 /* take from target and give to tender */
125 transfer = min(ontarget, -amt);
126 transfer = min(maxtender - ontender, transfer);
129 target.lnd_item[ip->i_vtype] = ontarget - transfer;
130 ontender += transfer;
133 /* give to target from tender */
134 transfer = min(ontender, amt);
135 transfer = min(transfer, maxtarget - ontarget);
138 target.lnd_item[ip->i_vtype] = ontarget + transfer;
139 ontender -= transfer;
142 expose_land(&tender, &target);
143 putland(target.lnd_uid, &target);
144 if (amt > 0 && ontender == 0) {
145 pr("%s out of %s\n", prship(&tender), ip->i_name);
149 pr("%d total %s transferred %s %s\n",
150 total, ip->i_name, (amt > 0) ? "off of" : "to",
152 tender.shp_item[ip->i_vtype] = ontender;
153 tender.shp_mission = 0;
154 putship(tender.shp_uid, &tender);
160 expose_land(struct shpstr *s1, struct lndstr *l1)
162 if (s1->shp_pstage == PLG_INFECT && l1->lnd_pstage == PLG_HEALTHY)
163 l1->lnd_pstage = PLG_EXPOSED;
164 if (l1->lnd_pstage == PLG_INFECT && s1->shp_pstage == PLG_HEALTHY)
165 s1->shp_pstage = PLG_EXPOSED;