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 * deliver.c: Deliver commodities to neighboring sector
30 * Known contributors to this file:
46 deliver(register struct sctstr *from, struct ichrstr *ip, int dir, int thresh, int amt_src, int plague)
48 register struct sctstr *to;
49 int vtype; /* item vartype */
58 if (dir <= 0 || dir > DIR_UL)
62 if ((amt_moved = amt_src - thresh) <= 0)
65 * make sure delivery looks ok. Check where its going,
66 * where its coming from, and see if there is more than
67 * the threshold amount
69 if (!military_control(from))
71 to = getsectp(from->sct_x+diroff[dir][0], from->sct_y+diroff[dir][1]);
72 if (to->sct_own != from->sct_own) {
73 wu(0, from->sct_own, "%s delivery walkout at %s\n",
74 ip->i_name, ownxy(from));
77 dp = &dchr[from->sct_type];
79 pack_src = ip->i_pkg[dp->d_pkg];
80 mobility = from->sct_mobil / 2;
81 if (vtype == V_CIVIL && from->sct_own != from->sct_oldown) {
82 wu(0, from->sct_own, "The conquered populace in %s refuses to relocate!\n", ownxy(from));
86 * disallow delivery into prohibited sectors.
87 * calculate unit movement cost; decrease amount if
88 * there isn't enough mobility.
90 mcost = sector_mcost(to, MOB_ROAD)*ip->i_lbs/pack_src;
93 if (mobility < mcost * amt_moved) {
94 /* XXX can mcost be == 0? */
95 amt_moved = (int) (mobility / mcost);
99 amt_dst = getvar(vtype, (caddr_t)to, EF_SECTOR);
100 if (amt_moved + amt_dst > 9990) {
101 /* delivery backlog */
102 if ((amt_moved = 9990 - amt_dst) <= 0)
105 if (putvar(vtype, amt_moved + amt_dst, (s_char *)to, EF_SECTOR) < 0) {
106 /* "No room to deliver commodities */
107 wu(0, from->sct_own, "no room for %s in %s\n",
108 ip->i_name, ownxy(to));
111 /* deliver the plague too! */
112 if (plague == PLG_INFECT && getvar(V_PSTAGE, (s_char *)to,EF_SECTOR) == 0)
113 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)to, EF_SECTOR);
114 n = from->sct_mobil - (int) (mcost * amt_moved);