2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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:
53 static void expose_land(struct shpstr *s1, struct lndstr *l1);
58 struct nstr_item targets;
59 struct nstr_item tenders;
63 struct mchrstr *vbase;
64 struct lchrstr *lbase;
75 if (!(ip = whatitem(player->argp[1], "Transfer what commodity? ")))
79 (&tenders, EF_SHIP, getstarg(player->argp[2], "Tender(s)? ", buf)))
81 while (nxtitem(&tenders, (s_char *)&tender)) {
85 getstarg(player->argp[3], "Amount to transfer? ", buf)) == 0)
87 if (!check_ship_ok(&tender))
89 if ((amt = atoi(p)) == 0)
91 ontender = getvar(ip->i_vtype, (s_char *)&tender, EF_SHIP);
92 if (ontender == 0 && amt > 0) {
93 pr("No %s on %s\n", ip->i_name, prship(&tender));
96 vbase = &mchr[(int)tender.shp_type];
97 maxtender = vl_find(ip->i_vtype, vbase->m_vtype,
98 vbase->m_vamt, (int)vbase->m_nv);
100 pr("A %s cannot hold any %s\n",
101 mchr[(int)tender.shp_type].m_name, ip->i_name);
104 if (!snxtitem(&targets, EF_LAND,
105 getstarg(player->argp[4], "Units to be tended? ",
108 if (!check_ship_ok(&tender))
111 while (tend_nxtitem(&targets, (s_char *)&target)) {
115 if (target.lnd_ship != tender.shp_uid)
117 ontarget = getvar(ip->i_vtype, (s_char *)&target, EF_LAND);
118 if (ontarget == 0 && amt < 0) {
120 ip->i_name, prship((struct shpstr *)&target));
123 lbase = &lchr[(int)target.lnd_type];
124 maxtarget = vl_find(ip->i_vtype, lbase->l_vtype,
125 lbase->l_vamt, (int)lbase->l_nv);
130 /* take from target and give to tender */
131 transfer = min(ontarget, -amt);
132 transfer = min(maxtender - ontender, transfer);
135 putvar(ip->i_vtype, ontarget - transfer,
136 (s_char *)&target, EF_LAND);
137 ontender += transfer;
140 /* give to target from tender */
141 transfer = min(ontender, amt);
142 transfer = min(transfer, maxtarget - ontarget);
145 putvar(ip->i_vtype, ontarget + transfer,
146 (s_char *)&target, EF_LAND);
147 ontender -= transfer;
150 expose_land(&tender, &target);
151 putland(target.lnd_uid, &target);
152 if (amt > 0 && ontender == 0) {
153 pr("%s out of %s\n", prship(&tender), ip->i_name);
157 pr("%d total %s transferred %s %s\n",
158 total, ip->i_name, (amt > 0) ? "off of" : "to",
160 putvar(ip->i_vtype, ontender, (s_char *)&tender, EF_SHIP);
161 tender.shp_mission = 0;
162 putship(tender.shp_uid, &tender);
168 expose_land(struct shpstr *s1, struct lndstr *l1)
170 if (getvar(V_PSTAGE, (s_char *)s1, EF_SHIP) == PLG_INFECT &&
171 getvar(V_PSTAGE, (s_char *)l1, EF_LAND) == PLG_HEALTHY)
172 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)l1, EF_LAND);
173 if (getvar(V_PSTAGE, (s_char *)l1, EF_LAND) == PLG_INFECT &&
174 getvar(V_PSTAGE, (s_char *)s1, EF_SHIP) == PLG_HEALTHY)
175 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)s1, EF_SHIP);