00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <config.h>
00035
00036 #include "item.h"
00037 #include "path.h"
00038 #include "plague.h"
00039 #include "update.h"
00040
00041 #define DELIVER_BONUS 4.0
00042
00043 static int
00044 deliver(struct sctstr *from, struct ichrstr *ip, int dir,
00045 int thresh, int amt_src, int plague, i_packing packing)
00046 {
00047 struct sctstr *to;
00048 i_type vtype;
00049 int amt_moved;
00050 int amt_dst;
00051 int mobility;
00052 double mcost;
00053 struct dchrstr *dp;
00054 int n;
00055
00056 if (dir <= 0 || dir > DIR_UL)
00057 return 0;
00058 if (amt_src <= 0)
00059 return 0;
00060 if ((amt_moved = amt_src - thresh) <= 0)
00061 return 0;
00062
00063
00064
00065
00066
00067 if (!military_control(from))
00068 return 0;
00069 to = getsectp(from->sct_x + diroff[dir][0],
00070 from->sct_y + diroff[dir][1]);
00071 if (to->sct_own != from->sct_own) {
00072 wu(0, from->sct_own, "%s delivery walkout at %s\n",
00073 ip->i_name, ownxy(from));
00074 return 0;
00075 }
00076 dp = &dchr[from->sct_type];
00077 vtype = ip->i_uid;
00078 mobility = from->sct_mobil / 2;
00079 if (vtype == I_CIVIL) {
00080 if (from->sct_own != from->sct_oldown) {
00081 wu(0, from->sct_own,
00082 "The conquered populace in %s refuses to relocate!\n",
00083 ownxy(from));
00084 return 0;
00085 }
00086 if (to->sct_own != to->sct_oldown) {
00087 wu(0, from->sct_own,
00088 "Citizens in %s refuse to relocate!\n", ownxy(from));
00089 return 0;
00090 }
00091 }
00092
00093
00094
00095
00096
00097 mcost = sector_mcost(to, MOB_MOVE) * ip->i_lbs / ip->i_pkg[packing];
00098 mcost /= DELIVER_BONUS;
00099
00100 if (mobility < mcost * amt_moved) {
00101
00102 amt_moved = (int)(mobility / mcost);
00103 if (amt_moved <= 0)
00104 return 0;
00105 }
00106 amt_dst = to->sct_item[vtype];
00107 if (amt_moved > ITEM_MAX - amt_dst) {
00108
00109 amt_moved = ITEM_MAX - amt_dst;
00110 }
00111 to->sct_item[vtype] = amt_moved + amt_dst;
00112
00113 if (plague == PLG_INFECT && to->sct_pstage == PLG_HEALTHY)
00114 to->sct_pstage = PLG_EXPOSED;
00115 n = from->sct_mobil - (int)(mcost * amt_moved);
00116 if (n < 0)
00117 n = 0;
00118 from->sct_mobil = n;
00119 return amt_moved;
00120 }
00121
00122 void
00123 dodeliver(struct sctstr *sp)
00124 {
00125 i_type i;
00126 int thresh;
00127 int dir;
00128 int plague;
00129 i_packing packing;
00130 int n;
00131
00132 if (sp->sct_mobil <= 0)
00133 return;
00134 plague = sp->sct_pstage;
00135 packing = sp->sct_effic >= 60 ? dchr[sp->sct_type].d_pkg : IPKG;
00136 for (i = I_NONE + 1; i <= I_MAX; i++) {
00137 if (sp->sct_del[i] == 0)
00138 continue;
00139 thresh = sp->sct_del[i] & ~0x7;
00140 dir = sp->sct_del[i] & 0x7;
00141 n = deliver(sp, &ichr[i], dir, thresh, sp->sct_item[i],
00142 plague, packing);
00143 if (n > 0) {
00144 sp->sct_item[i] -= n;
00145 if (sp->sct_mobil <= 0)
00146 break;
00147 }
00148 }
00149 }