2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, 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 * deliver.c: Deliver commodities to neighboring sector
29 * Known contributors to this file:
40 #define DELIVER_BONUS 4.0
43 deliver(struct sctstr *from, struct ichrstr *ip, int dir,
44 int thresh, int amt_src, int plague, enum i_packing packing)
47 i_type vtype; /* item vartype */
54 if (dir <= 0 || dir > DIR_UL)
58 if ((amt_moved = amt_src - thresh) <= 0)
61 * make sure delivery looks ok. Check where its going,
62 * where its coming from, and see if there is more than
63 * the threshold amount
65 if (!military_control(from))
67 to = getsectp(from->sct_x + diroff[dir][0],
68 from->sct_y + diroff[dir][1]);
69 if (to->sct_own != from->sct_own) {
70 wu(0, from->sct_own, "%s delivery walkout at %s\n",
71 ip->i_name, ownxy(from));
75 mobility = from->sct_mobil / 2;
76 if (vtype == I_CIVIL) {
77 if (from->sct_own != from->sct_oldown) {
79 "The conquered populace in %s refuses to relocate!\n",
83 if (to->sct_own != to->sct_oldown) {
85 "Citizens in %s refuse to relocate!\n", ownxy(from));
90 * disallow delivery into prohibited sectors.
91 * calculate unit movement cost; decrease amount if
92 * there isn't enough mobility.
94 mcost = sector_mcost(to, MOB_MOVE) * ip->i_lbs / ip->i_pkg[packing];
95 mcost /= DELIVER_BONUS;
97 if (mobility < mcost * amt_moved) {
98 /* XXX can mcost be == 0? */
99 amt_moved = (int)(mobility / mcost);
103 amt_dst = to->sct_item[vtype];
104 if (amt_moved > ITEM_MAX - amt_dst) {
105 /* delivery backlog */
106 amt_moved = ITEM_MAX - amt_dst;
108 to->sct_item[vtype] = amt_moved + amt_dst;
109 /* deliver the plague too! */
110 if (plague == PLG_INFECT && to->sct_pstage == PLG_HEALTHY)
111 to->sct_pstage = PLG_EXPOSED;
112 n = from->sct_mobil - (int)(mcost * amt_moved);
120 dodeliver(struct sctstr *sp)
126 enum i_packing packing;
129 if (sp->sct_mobil <= 0)
131 plague = sp->sct_pstage;
132 packing = sp->sct_effic >= 60 ? dchr[sp->sct_type].d_pkg : IPKG;
133 for (i = I_NONE + 1; i <= I_MAX; i++) {
134 if (sp->sct_del[i] == 0)
136 thresh = sp->sct_del[i] & ~0x7;
137 dir = sp->sct_del[i] & 0x7;
138 n = deliver(sp, &ichr[i], dir, thresh, sp->sct_item[i],
141 sp->sct_item[i] -= n;
142 if (sp->sct_mobil <= 0)