From 5ec392227ac52c2ee25fca0563a0480949bc35b2 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 28 Aug 2004 08:43:57 +0000 Subject: [PATCH] (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. --- include/item.h | 1 + src/lib/commands/move.c | 10 ++------ src/lib/global/item.c | 35 +++++++++++++------------- src/lib/update/deliver.c | 15 ++++++----- src/lib/update/distribute.c | 50 +++++++++++++++++-------------------- 5 files changed, 52 insertions(+), 59 deletions(-) diff --git a/include/item.h b/include/item.h index 52d98fa83..b6691af03 100644 --- a/include/item.h +++ b/include/item.h @@ -35,6 +35,7 @@ #define _ITEM_H_ typedef enum { + IPKG, /* "inefficient" packaging (eff<60) */ NPKG, /* no special packaging */ WPKG, /* "warehouse" packaging */ UPKG, /* "urban" packaging */ diff --git a/src/lib/commands/move.c b/src/lib/commands/move.c index 92dbfbd5e..7ba4879c7 100644 --- a/src/lib/commands/move.c +++ b/src/lib/commands/move.c @@ -61,11 +61,9 @@ move(void) int left; int mcost, dam; int infected; - int stype; int vtype; int amt_src; int amt_dst; - struct dchrstr *dp; struct ichrstr *ip; int work; int loyal; @@ -100,8 +98,6 @@ move(void) return RET_FAIL; } } - stype = sect.sct_type; - dp = &dchr[stype]; infected = sect.sct_pstage == PLG_INFECT; amt_src = sect.sct_item[vtype]; if (!istest && amt_src <= 0) { @@ -155,10 +151,8 @@ move(void) if (amount <= 0) return RET_SYN; - packing = ip->i_pkg[dp->d_pkg]; - if (packing > 1 && sect.sct_effic < 60) - packing = 1; - weight = (double)amount *ip->i_lbs / packing; + packing = sect.sct_effic >= 60 ? dchr[sect.sct_type].d_pkg : IPKG; + weight = (double)amount * ip->i_lbs / ip->i_pkg[packing]; /* * First remove commodities from source sector */ diff --git a/src/lib/global/item.c b/src/lib/global/item.c index 35b194378..3603229de 100644 --- a/src/lib/global/item.c +++ b/src/lib/global/item.c @@ -40,24 +40,23 @@ #include "item.h" struct ichrstr ichr[I_MAX + 2] = { -/* mnem vtype val sell lbs rg,wh,ur,bnk name */ - {'?', 0, 0, 0, 0, {0, 0, 0, 0}, "unused"}, -/* STM CHANGED HERE */ - {'c', I_CIVIL, 1, 0, 1, {10, 10, 10, 10}, "civilians"}, - {'m', I_MILIT, 0, 0, 1, {1, 1, 1, 1}, "military"}, - {'s', I_SHELL, 5, 1, 1, {1, 10, 1, 1}, "shells"}, - {'g', I_GUN, 60, 1, 10, {1, 10, 1, 1}, "guns"}, - {'p', I_PETROL, 4, 1, 1, {1, 10, 1, 1}, "petrol"}, - {'i', I_IRON, 2, 1, 1, {1, 10, 1, 1}, "iron ore"}, - {'d', I_DUST, 20, 1, 5, {1, 10, 1, 1}, "dust (gold)"}, - {'b', I_BAR, 280, 1, 50, {1, 5, 1, 4}, "bars of gold"}, - {'f', I_FOOD, 0, 1, 1, {1, 10, 1, 1}, "food"}, - {'o', I_OIL, 8, 1, 1, {1, 10, 1, 1}, "oil"}, - {'l', I_LCM, 2, 1, 1, {1, 10, 1, 1}, "light products"}, - {'h', I_HCM, 4, 1, 1, {1, 10, 1, 1}, "heavy products"}, - {'u', I_UW, 1, 1, 2, {1, 2, 1, 1}, "uncompensated workers"}, - {'r', I_RAD, 150, 1, 8, {1, 10, 1, 1}, "radioactive materials"}, - {0, 0, 0, 0, 0, {0, 0, 0, 0}, 0} +/* mnem vtype val sell lbs {in rg wh ur bnk} name */ + {'?', I_NONE, 0, 0, 0, {0, 0, 0, 0, 0}, "unused"}, + {'c', I_CIVIL, 1, 0, 1, {1, 10, 10, 10, 10}, "civilians"}, + {'m', I_MILIT, 0, 0, 1, {1, 1, 1, 1, 1}, "military"}, + {'s', I_SHELL, 5, 1, 1, {1, 1, 10, 1, 1}, "shells"}, + {'g', I_GUN, 60, 1, 10, {1, 1, 10, 1, 1}, "guns"}, + {'p', I_PETROL, 4, 1, 1, {1, 1, 10, 1, 1}, "petrol"}, + {'i', I_IRON, 2, 1, 1, {1, 1, 10, 1, 1}, "iron ore"}, + {'d', I_DUST, 20, 1, 5, {1, 1, 10, 1, 1}, "dust (gold)"}, + {'b', I_BAR, 280, 1, 50, {1, 1, 5, 1, 4}, "bars of gold"}, + {'f', I_FOOD, 0, 1, 1, {1, 1, 10, 1, 1}, "food"}, + {'o', I_OIL, 8, 1, 1, {1, 1, 10, 1, 1}, "oil"}, + {'l', I_LCM, 2, 1, 1, {1, 1, 10, 1, 1}, "light products"}, + {'h', I_HCM, 4, 1, 1, {1, 1, 10, 1, 1}, "heavy products"}, + {'u', I_UW, 1, 1, 2, {1, 1, 2, 1, 1}, "uncompensated workers"}, + {'r', I_RAD, 150, 1, 8, {1, 1, 10, 1, 1}, "radioactive materials"}, + {0, I_NONE, 0, 0, 0, {0, 0, 0, 0, 0}, NULL} }; int itm_maxno = (sizeof(ichr) / sizeof(struct ichrstr)) - 1; diff --git a/src/lib/update/deliver.c b/src/lib/update/deliver.c index 853815f0d..e58cd6dcc 100644 --- a/src/lib/update/deliver.c +++ b/src/lib/update/deliver.c @@ -42,13 +42,14 @@ #include "subs.h" #include "common.h" +#define DELIVER_BONUS 4.0 + static int 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; int vtype; /* item vartype */ - int pack_src; int amt_moved; int amt_dst; int mobility; @@ -78,7 +79,6 @@ deliver(register struct sctstr *from, struct ichrstr *ip, int dir, } dp = &dchr[from->sct_type]; vtype = ip->i_vtype; - pack_src = ip->i_pkg[from->sct_effic >= 60 ? dp->d_pkg : NPKG]; mobility = from->sct_mobil / 2; if (vtype == I_CIVIL && from->sct_own != from->sct_oldown) { 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 * there isn't enough mobility. */ - mcost = sector_mcost(to, MOB_ROAD) * ip->i_lbs / pack_src; - mcost /= 4.0; + mcost = sector_mcost(to, MOB_ROAD) * ip->i_lbs / ip->i_pkg[packing]; + mcost /= DELIVER_BONUS; if (mobility < mcost * amt_moved) { /* XXX can mcost be == 0? */ @@ -123,17 +123,20 @@ dodeliver(struct sctstr *sp) int thresh; int dir; int plague; + i_packing packing; int n; if (sp->sct_mobil <= 0) return; plague = sp->sct_pstage; + packing = sp->sct_effic >= 60 ? dchr[sp->sct_type].d_pkg : IPKG; for (i = 1; i <= I_MAX; i++) { if (sp->sct_del[i] == 0) continue; thresh = 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) { sp->sct_item[i] -= n; if (sp->sct_mobil <= 0) diff --git a/src/lib/update/distribute.c b/src/lib/update/distribute.c index ef147b9ea..ac958623d 100644 --- a/src/lib/update/distribute.c +++ b/src/lib/update/distribute.c @@ -47,6 +47,13 @@ #include "common.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 dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_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 amt_dist; int amt_sect; - i_packing packing; - float imcost; - float excost; - i_packing dist_packing; + i_packing sect_packing, dist_packing; + int pack; + double mcost; int diff; int item; 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); - if (dist->sct_effic >= 60) - dist_packing = dchr[dist->sct_type].d_pkg; - 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; + dist_packing = dist->sct_effic >= 60 ? dchr[dist->sct_type].d_pkg : IPKG; + sect_packing = sp->sct_effic >= 60 ? dchr[sp->sct_type].d_pkg : IPKG; lplague = rplague = changed = 0; 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]; /* * 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 * 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_dist = dist->sct_item[item]; 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) continue; } - if (dist->sct_mobil < imcost * amt) - amt = dist->sct_mobil / imcost; + pack = ip->i_pkg[dist_packing]; + mcost = dist_i_cost / pack * ip->i_lbs / IMPORT_BONUS; + if (dist->sct_mobil < mcost * amt) + amt = dist->sct_mobil / mcost; lplague++; - /* XXX replace with vector assign and putvec() */ dist->sct_item[item] -= amt; changed++; - dist->sct_mobil -= (int)(imcost * amt); + dist->sct_mobil -= (int)(mcost * amt); sp->sct_item[item] += amt; } else { if (imex != EXPORT) @@ -176,18 +171,19 @@ dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost, amt = diff; if (amt > amt_sect) amt = amt_sect; - if (sp->sct_mobil < excost * amt) - amt = sp->sct_mobil / excost; + pack = MAX(ip->i_pkg[sect_packing], ip->i_pkg[dist_packing]); + 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) amt = ITEM_MAX - amt_dist; if (amt == 0) continue; - /* XXX replace with vector assign and putvec() */ rplague++; sp->sct_item[item] -= amt; changed++; - sp->sct_mobil -= (int)(excost * amt); + sp->sct_mobil -= (int)(mcost * amt); dist->sct_item[item] += amt; } } -- 2.43.0