(IPKG): New.

(ichr): Set IPKG packing bonus for all sectors to 1.
(move): Use it.  No functional change.
(deliver, dodistribute): Use it.  Inefficient sectors now get IPKG
instead of NPKG packing bonus, cutting civilian packing bonus from 10
to 1.

(dodistribute): Export uses the better of sector or distribution
center packing bonus.  Previously, it assumed that distribution center
WPKG packing is always best.  Which is currently true, but needlessly
breaks the abstraction.
This commit is contained in:
Markus Armbruster 2004-08-28 08:43:57 +00:00
parent 92799db17b
commit 5ec392227a
5 changed files with 52 additions and 59 deletions

View file

@ -35,6 +35,7 @@
#define _ITEM_H_ #define _ITEM_H_
typedef enum { typedef enum {
IPKG, /* "inefficient" packaging (eff<60) */
NPKG, /* no special packaging */ NPKG, /* no special packaging */
WPKG, /* "warehouse" packaging */ WPKG, /* "warehouse" packaging */
UPKG, /* "urban" packaging */ UPKG, /* "urban" packaging */

View file

@ -61,11 +61,9 @@ move(void)
int left; int left;
int mcost, dam; int mcost, dam;
int infected; int infected;
int stype;
int vtype; int vtype;
int amt_src; int amt_src;
int amt_dst; int amt_dst;
struct dchrstr *dp;
struct ichrstr *ip; struct ichrstr *ip;
int work; int work;
int loyal; int loyal;
@ -100,8 +98,6 @@ move(void)
return RET_FAIL; return RET_FAIL;
} }
} }
stype = sect.sct_type;
dp = &dchr[stype];
infected = sect.sct_pstage == PLG_INFECT; infected = sect.sct_pstage == PLG_INFECT;
amt_src = sect.sct_item[vtype]; amt_src = sect.sct_item[vtype];
if (!istest && amt_src <= 0) { if (!istest && amt_src <= 0) {
@ -155,10 +151,8 @@ move(void)
if (amount <= 0) if (amount <= 0)
return RET_SYN; return RET_SYN;
packing = ip->i_pkg[dp->d_pkg]; packing = sect.sct_effic >= 60 ? dchr[sect.sct_type].d_pkg : IPKG;
if (packing > 1 && sect.sct_effic < 60) weight = (double)amount * ip->i_lbs / ip->i_pkg[packing];
packing = 1;
weight = (double)amount *ip->i_lbs / packing;
/* /*
* First remove commodities from source sector * First remove commodities from source sector
*/ */

View file

@ -40,24 +40,23 @@
#include "item.h" #include "item.h"
struct ichrstr ichr[I_MAX + 2] = { struct ichrstr ichr[I_MAX + 2] = {
/* mnem vtype val sell lbs rg,wh,ur,bnk name */ /* mnem vtype val sell lbs {in rg wh ur bnk} name */
{'?', 0, 0, 0, 0, {0, 0, 0, 0}, "unused"}, {'?', I_NONE, 0, 0, 0, {0, 0, 0, 0, 0}, "unused"},
/* STM CHANGED HERE */ {'c', I_CIVIL, 1, 0, 1, {1, 10, 10, 10, 10}, "civilians"},
{'c', I_CIVIL, 1, 0, 1, {10, 10, 10, 10}, "civilians"}, {'m', I_MILIT, 0, 0, 1, {1, 1, 1, 1, 1}, "military"},
{'m', I_MILIT, 0, 0, 1, {1, 1, 1, 1}, "military"}, {'s', I_SHELL, 5, 1, 1, {1, 1, 10, 1, 1}, "shells"},
{'s', I_SHELL, 5, 1, 1, {1, 10, 1, 1}, "shells"}, {'g', I_GUN, 60, 1, 10, {1, 1, 10, 1, 1}, "guns"},
{'g', I_GUN, 60, 1, 10, {1, 10, 1, 1}, "guns"}, {'p', I_PETROL, 4, 1, 1, {1, 1, 10, 1, 1}, "petrol"},
{'p', I_PETROL, 4, 1, 1, {1, 10, 1, 1}, "petrol"}, {'i', I_IRON, 2, 1, 1, {1, 1, 10, 1, 1}, "iron ore"},
{'i', I_IRON, 2, 1, 1, {1, 10, 1, 1}, "iron ore"}, {'d', I_DUST, 20, 1, 5, {1, 1, 10, 1, 1}, "dust (gold)"},
{'d', I_DUST, 20, 1, 5, {1, 10, 1, 1}, "dust (gold)"}, {'b', I_BAR, 280, 1, 50, {1, 1, 5, 1, 4}, "bars of gold"},
{'b', I_BAR, 280, 1, 50, {1, 5, 1, 4}, "bars of gold"}, {'f', I_FOOD, 0, 1, 1, {1, 1, 10, 1, 1}, "food"},
{'f', I_FOOD, 0, 1, 1, {1, 10, 1, 1}, "food"}, {'o', I_OIL, 8, 1, 1, {1, 1, 10, 1, 1}, "oil"},
{'o', I_OIL, 8, 1, 1, {1, 10, 1, 1}, "oil"}, {'l', I_LCM, 2, 1, 1, {1, 1, 10, 1, 1}, "light products"},
{'l', I_LCM, 2, 1, 1, {1, 10, 1, 1}, "light products"}, {'h', I_HCM, 4, 1, 1, {1, 1, 10, 1, 1}, "heavy products"},
{'h', I_HCM, 4, 1, 1, {1, 10, 1, 1}, "heavy products"}, {'u', I_UW, 1, 1, 2, {1, 1, 2, 1, 1}, "uncompensated workers"},
{'u', I_UW, 1, 1, 2, {1, 2, 1, 1}, "uncompensated workers"}, {'r', I_RAD, 150, 1, 8, {1, 1, 10, 1, 1}, "radioactive materials"},
{'r', I_RAD, 150, 1, 8, {1, 10, 1, 1}, "radioactive materials"}, {0, I_NONE, 0, 0, 0, {0, 0, 0, 0, 0}, NULL}
{0, 0, 0, 0, 0, {0, 0, 0, 0}, 0}
}; };
int itm_maxno = (sizeof(ichr) / sizeof(struct ichrstr)) - 1; int itm_maxno = (sizeof(ichr) / sizeof(struct ichrstr)) - 1;

View file

@ -42,13 +42,14 @@
#include "subs.h" #include "subs.h"
#include "common.h" #include "common.h"
#define DELIVER_BONUS 4.0
static int static int
deliver(register struct sctstr *from, struct ichrstr *ip, int dir, deliver(register struct sctstr *from, struct ichrstr *ip, int dir,
int thresh, int amt_src, int plague) int thresh, int amt_src, int plague, i_packing packing)
{ {
register struct sctstr *to; register struct sctstr *to;
int vtype; /* item vartype */ int vtype; /* item vartype */
int pack_src;
int amt_moved; int amt_moved;
int amt_dst; int amt_dst;
int mobility; int mobility;
@ -78,7 +79,6 @@ deliver(register struct sctstr *from, struct ichrstr *ip, int dir,
} }
dp = &dchr[from->sct_type]; dp = &dchr[from->sct_type];
vtype = ip->i_vtype; vtype = ip->i_vtype;
pack_src = ip->i_pkg[from->sct_effic >= 60 ? dp->d_pkg : NPKG];
mobility = from->sct_mobil / 2; mobility = from->sct_mobil / 2;
if (vtype == I_CIVIL && from->sct_own != from->sct_oldown) { if (vtype == I_CIVIL && from->sct_own != from->sct_oldown) {
wu(0, from->sct_own, wu(0, from->sct_own,
@ -91,8 +91,8 @@ deliver(register struct sctstr *from, struct ichrstr *ip, int dir,
* calculate unit movement cost; decrease amount if * calculate unit movement cost; decrease amount if
* there isn't enough mobility. * there isn't enough mobility.
*/ */
mcost = sector_mcost(to, MOB_ROAD) * ip->i_lbs / pack_src; mcost = sector_mcost(to, MOB_ROAD) * ip->i_lbs / ip->i_pkg[packing];
mcost /= 4.0; mcost /= DELIVER_BONUS;
if (mobility < mcost * amt_moved) { if (mobility < mcost * amt_moved) {
/* XXX can mcost be == 0? */ /* XXX can mcost be == 0? */
@ -123,17 +123,20 @@ dodeliver(struct sctstr *sp)
int thresh; int thresh;
int dir; int dir;
int plague; int plague;
i_packing packing;
int n; int n;
if (sp->sct_mobil <= 0) if (sp->sct_mobil <= 0)
return; return;
plague = sp->sct_pstage; plague = sp->sct_pstage;
packing = sp->sct_effic >= 60 ? dchr[sp->sct_type].d_pkg : IPKG;
for (i = 1; i <= I_MAX; i++) { for (i = 1; i <= I_MAX; i++) {
if (sp->sct_del[i] == 0) if (sp->sct_del[i] == 0)
continue; continue;
thresh = sp->sct_del[i] & ~0x7; thresh = sp->sct_del[i] & ~0x7;
dir = sp->sct_del[i] & 0x7; dir = sp->sct_del[i] & 0x7;
n = deliver(sp, &ichr[i], dir, thresh, sp->sct_item[i], plague); n = deliver(sp, &ichr[i], dir, thresh, sp->sct_item[i],
plague, packing);
if (n > 0) { if (n > 0) {
sp->sct_item[i] -= n; sp->sct_item[i] -= n;
if (sp->sct_mobil <= 0) if (sp->sct_mobil <= 0)

View file

@ -47,6 +47,13 @@
#include "common.h" #include "common.h"
#include "prototypes.h" #include "prototypes.h"
#define EXPORT_BONUS 10.0
#define IMPORT_BONUS 10.0
#ifndef MAX
#define MAX(x,y) ((x) < (y) ? (y) : (x))
#endif
int int
dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost, dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost,
double dist_e_cost) double dist_e_cost)
@ -58,10 +65,9 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost,
int thresh; int thresh;
int amt_dist; int amt_dist;
int amt_sect; int amt_sect;
i_packing packing; i_packing sect_packing, dist_packing;
float imcost; int pack;
float excost; double mcost;
i_packing dist_packing;
int diff; int diff;
int item; int item;
int changed; int changed;
@ -81,18 +87,8 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost,
} }
dist = getsectp(sp->sct_dist_x, sp->sct_dist_y); dist = getsectp(sp->sct_dist_x, sp->sct_dist_y);
if (dist->sct_effic >= 60) dist_packing = dist->sct_effic >= 60 ? dchr[dist->sct_type].d_pkg : IPKG;
dist_packing = dchr[dist->sct_type].d_pkg; sect_packing = sp->sct_effic >= 60 ? dchr[sp->sct_type].d_pkg : IPKG;
else
dist_packing = NPKG; /* No packing */
if (sp->sct_effic >= 60)
packing = dchr[sp->sct_type].d_pkg;
else
packing = NPKG; /* No packing */
if ((dist->sct_effic >= 60) && dchr[dist->sct_type].d_pkg == WPKG)
packing = dchr[dist->sct_type].d_pkg;
lplague = rplague = changed = 0; lplague = rplague = changed = 0;
for (item = 1; item < I_MAX + 1; item++) { for (item = 1; item < I_MAX + 1; item++) {
@ -102,12 +98,10 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost,
thresh = sp->sct_dist[item]; thresh = sp->sct_dist[item];
/* /*
* calculate costs for importing and exporting. * calculate costs for importing and exporting.
* the div 10.0 is because delivering straight through * the mob bonus is because delivering straight through
* to the dist sect is cheaper than stopping at each * to the dist sect is cheaper than stopping at each
* sector along the way (processor-timewise) * sector along the way (processor-timewise)
*/ */
excost = (dist_e_cost / ip->i_pkg[packing] * ip->i_lbs) / 10.0;
imcost = (dist_i_cost / ip->i_pkg[dist_packing] * ip->i_lbs) / 10.0;
amt_sect = sp->sct_item[item]; amt_sect = sp->sct_item[item];
amt_dist = dist->sct_item[item]; amt_dist = dist->sct_item[item];
diff = amt_sect - thresh; diff = amt_sect - thresh;
@ -144,14 +138,15 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost,
if (amt_dist == 0) if (amt_dist == 0)
continue; continue;
} }
if (dist->sct_mobil < imcost * amt) pack = ip->i_pkg[dist_packing];
amt = dist->sct_mobil / imcost; mcost = dist_i_cost / pack * ip->i_lbs / IMPORT_BONUS;
if (dist->sct_mobil < mcost * amt)
amt = dist->sct_mobil / mcost;
lplague++; lplague++;
/* XXX replace with vector assign and putvec() */
dist->sct_item[item] -= amt; dist->sct_item[item] -= amt;
changed++; changed++;
dist->sct_mobil -= (int)(imcost * amt); dist->sct_mobil -= (int)(mcost * amt);
sp->sct_item[item] += amt; sp->sct_item[item] += amt;
} else { } else {
if (imex != EXPORT) if (imex != EXPORT)
@ -176,18 +171,19 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost,
amt = diff; amt = diff;
if (amt > amt_sect) if (amt > amt_sect)
amt = amt_sect; amt = amt_sect;
if (sp->sct_mobil < excost * amt) pack = MAX(ip->i_pkg[sect_packing], ip->i_pkg[dist_packing]);
amt = sp->sct_mobil / excost; mcost = dist_e_cost / pack * ip->i_lbs / EXPORT_BONUS;
if (sp->sct_mobil < mcost * amt)
amt = sp->sct_mobil / mcost;
if (amt > ITEM_MAX - amt_dist) if (amt > ITEM_MAX - amt_dist)
amt = ITEM_MAX - amt_dist; amt = ITEM_MAX - amt_dist;
if (amt == 0) if (amt == 0)
continue; continue;
/* XXX replace with vector assign and putvec() */
rplague++; rplague++;
sp->sct_item[item] -= amt; sp->sct_item[item] -= amt;
changed++; changed++;
sp->sct_mobil -= (int)(excost * amt); sp->sct_mobil -= (int)(mcost * amt);
dist->sct_item[item] += amt; dist->sct_item[item] += amt;
} }
} }