2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2009, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future 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:
47 static void expose_land(struct shpstr *s1, struct lndstr *l1);
52 struct nstr_item targets;
53 struct nstr_item tenders;
57 struct mchrstr *vbase;
58 struct lchrstr *lbase;
69 if (!(ip = whatitem(player->argp[1], "Transfer what commodity? ")))
72 if (!snxtitem(&tenders, EF_SHIP, player->argp[2], "Tender(s)? "))
74 while (nxtitem(&tenders, &tender)) {
78 getstarg(player->argp[3], "Amount to transfer? ", buf)) == 0)
80 if (!check_ship_ok(&tender))
82 if ((amt = atoi(p)) == 0)
84 ontender = tender.shp_item[ip->i_uid];
85 if (ontender == 0 && amt > 0) {
86 pr("No %s on %s\n", ip->i_name, prship(&tender));
89 vbase = &mchr[(int)tender.shp_type];
90 maxtender = vbase->m_item[ip->i_uid];
92 pr("A %s cannot hold any %s\n",
93 mchr[(int)tender.shp_type].m_name, 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)) {
106 if (target.lnd_ship != tender.shp_uid)
108 ontarget = target.lnd_item[ip->i_uid];
109 if (ontarget == 0 && amt < 0) {
111 ip->i_name, prland(&target));
114 lbase = &lchr[(int)target.lnd_type];
115 maxtarget = lbase->l_item[ip->i_uid];
120 /* take from target and give to tender */
121 transfer = MIN(ontarget, -amt);
122 transfer = MIN(maxtender - ontender, transfer);
125 target.lnd_item[ip->i_uid] = ontarget - transfer;
126 ontender += transfer;
129 /* give to target from tender */
130 transfer = MIN(ontender, amt);
131 transfer = MIN(transfer, maxtarget - ontarget);
134 target.lnd_item[ip->i_uid] = ontarget + transfer;
135 ontender -= transfer;
138 expose_land(&tender, &target);
139 putland(target.lnd_uid, &target);
140 if (amt > 0 && ontender == 0) {
141 pr("%s out of %s\n", prship(&tender), ip->i_name);
145 pr("%d total %s transferred %s %s\n",
146 total, ip->i_name, (amt > 0) ? "off of" : "to",
148 tender.shp_item[ip->i_uid] = ontender;
149 tender.shp_mission = 0;
150 putship(tender.shp_uid, &tender);
156 expose_land(struct shpstr *s1, struct lndstr *l1)
158 if (s1->shp_pstage == PLG_INFECT && l1->lnd_pstage == PLG_HEALTHY)
159 l1->lnd_pstage = PLG_EXPOSED;
160 if (l1->lnd_pstage == PLG_INFECT && s1->shp_pstage == PLG_HEALTHY)
161 s1->shp_pstage = PLG_EXPOSED;