update: Reorder unit building and maintenance for fairness
The update visits ships, planes and land units in increasing order of country number. Within a country, it visits first ships, then planes, then land units, each in increasing order of unit number. The order is relevant when money, materials and work don't suffice to build everything. Money is charged to the owner, so only the relative order for the same owner matters there. One order is as good as any. Work and materials come from the sector, so only the relative order in each sector matters. The current order unfairly prefers countries with lower country numbers. Mitigating factor: the affected countries need to be friendly (ships only) or allied. The unfairness goes back to Chainsaw's option BUDGET. See the commit before previous for more detailed historical notes. The update test demonstrates the unfair behavior: sector 14,6 builds ships 95/97 owned by country#1, but not 96 owned by country#7. Likewise, planes 95/96/97 and land units 95/96/97. Go back to the the pre-BUDGET order: first ships, then planes, then land units, all in increasing order of unit number, regardless of owner. The update test now builds ship, plane and land unit 96 instead of 97. Bonus: speeds up both the update and budget by a similar absolute amount. For budget, this is roughly a factor of two in my testing. For the update, which does much more, it's around 10%. Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
parent
70f69640e1
commit
c5df505c98
11 changed files with 152 additions and 173 deletions
|
@ -54,7 +54,7 @@ static void landrepair(struct lndstr *, struct natstr *, struct bp *,
|
|||
int, struct budget *);
|
||||
static int feed_land(struct lndstr *, int);
|
||||
|
||||
void prep_lands(int etus, natid natnum)
|
||||
void prep_lands(int etus)
|
||||
{
|
||||
int mil, i;
|
||||
double mil_pay;
|
||||
|
@ -63,8 +63,6 @@ void prep_lands(int etus, natid natnum)
|
|||
for (i = 0; (lp = getlandp(i)); i++) {
|
||||
if (lp->lnd_own == 0)
|
||||
continue;
|
||||
if (lp->lnd_own != natnum)
|
||||
continue;
|
||||
if (CANT_HAPPEN(lp->lnd_effic < LAND_MINEFF)) {
|
||||
makelost(EF_LAND, lp->lnd_own, lp->lnd_uid,
|
||||
lp->lnd_x, lp->lnd_y);
|
||||
|
@ -74,14 +72,14 @@ void prep_lands(int etus, natid natnum)
|
|||
|
||||
mil = lp->lnd_item[I_MILIT];
|
||||
mil_pay = mil * etus * money_mil;
|
||||
nat_budget[natnum].mil.count += mil;
|
||||
nat_budget[natnum].mil.money += mil_pay;
|
||||
nat_budget[natnum].money += mil_pay;
|
||||
nat_budget[lp->lnd_own].mil.count += mil;
|
||||
nat_budget[lp->lnd_own].mil.money += mil_pay;
|
||||
nat_budget[lp->lnd_own].money += mil_pay;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prod_land(int etus, int natnum, struct bp *bp, int build)
|
||||
prod_land(int etus, struct bp *bp, int build)
|
||||
/* build = 1, maintain = 0 */
|
||||
{
|
||||
struct lndstr *lp;
|
||||
|
@ -90,8 +88,6 @@ prod_land(int etus, int natnum, struct bp *bp, int build)
|
|||
for (i = 0; (lp = getlandp(i)); i++) {
|
||||
if (lp->lnd_own == 0)
|
||||
continue;
|
||||
if (lp->lnd_own != natnum)
|
||||
continue;
|
||||
upd_land(lp, etus, bp, build);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,31 +94,26 @@ update_main(void)
|
|||
logerror("preparing sectors...");
|
||||
prepare_sects(etu, NULL);
|
||||
logerror("done preparing sectors.");
|
||||
for (i = 0; i < MAXNOC; i++) {
|
||||
prep_ships(etu, i);
|
||||
prep_planes(etu, i);
|
||||
prep_lands(etu, i);
|
||||
prep_ships(etu);
|
||||
prep_planes(etu);
|
||||
prep_lands(etu);
|
||||
for (i = 0; i < MAXNOC; i++)
|
||||
pay_reserve(getnatp(i), etu);
|
||||
}
|
||||
|
||||
logerror("producing for countries...");
|
||||
/* maintain units */
|
||||
for (i = 0; i < MAXNOC; i++) {
|
||||
prod_ship(etu, i, NULL, 0);
|
||||
prod_plane(etu, i, NULL, 0);
|
||||
prod_land(etu, i, NULL, 0);
|
||||
}
|
||||
prod_ship(etu, NULL, 0);
|
||||
prod_plane(etu, NULL, 0);
|
||||
prod_land(etu, NULL, 0);
|
||||
|
||||
/* produce all sects */
|
||||
for (i = 0; i < MAXNOC; i++)
|
||||
produce_sect(getnatp(i), etu, NULL);
|
||||
|
||||
/* build units */
|
||||
for (i = 0; i < MAXNOC; i++) {
|
||||
prod_ship(etu, i, NULL, 1);
|
||||
prod_plane(etu, i, NULL, 1);
|
||||
prod_land(etu, i, NULL, 1);
|
||||
}
|
||||
prod_ship(etu, NULL, 1);
|
||||
prod_plane(etu, NULL, 1);
|
||||
prod_land(etu, NULL, 1);
|
||||
logerror("done producing for countries.");
|
||||
|
||||
finish_sects(etu);
|
||||
|
|
|
@ -49,7 +49,7 @@ static void upd_plane(struct plnstr *, int, struct bp *, int);
|
|||
static void planerepair(struct plnstr *, struct natstr *, struct bp *,
|
||||
int, struct budget *);
|
||||
|
||||
void prep_planes(int etus, natid natnum)
|
||||
void prep_planes(int etus)
|
||||
{
|
||||
int mil, i;
|
||||
double mil_pay;
|
||||
|
@ -58,8 +58,6 @@ void prep_planes(int etus, natid natnum)
|
|||
for (i = 0; (pp = getplanep(i)); i++) {
|
||||
if (pp->pln_own == 0)
|
||||
continue;
|
||||
if (pp->pln_own != natnum)
|
||||
continue;
|
||||
if (pp->pln_effic < PLANE_MINEFF) {
|
||||
makelost(EF_PLANE, pp->pln_own, pp->pln_uid,
|
||||
pp->pln_x, pp->pln_y);
|
||||
|
@ -70,13 +68,13 @@ void prep_planes(int etus, natid natnum)
|
|||
mil = plchr[pp->pln_type].pl_mat[I_MILIT];
|
||||
/* flight pay is 5x the pay received by other military */
|
||||
mil_pay = mil * etus * money_mil * 5;
|
||||
nat_budget[natnum].bm[BUDG_PLN_MAINT].money += mil_pay;
|
||||
nat_budget[natnum].money += mil_pay;
|
||||
nat_budget[pp->pln_own].bm[BUDG_PLN_MAINT].money += mil_pay;
|
||||
nat_budget[pp->pln_own].money += mil_pay;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prod_plane(int etus, int natnum, struct bp *bp, int buildem)
|
||||
prod_plane(int etus, struct bp *bp, int buildem)
|
||||
/* Build = 1, maintain =0 */
|
||||
{
|
||||
struct plnstr *pp;
|
||||
|
@ -85,8 +83,6 @@ prod_plane(int etus, int natnum, struct bp *bp, int buildem)
|
|||
for (i = 0; (pp = getplanep(i)); i++) {
|
||||
if (pp->pln_own == 0)
|
||||
continue;
|
||||
if (pp->pln_own != natnum)
|
||||
continue;
|
||||
upd_plane(pp, etus, bp, buildem);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ static void shiprepair(struct shpstr *, struct natstr *, struct bp *,
|
|||
static void ship_produce(struct shpstr *, int, struct budget *);
|
||||
static int feed_ship(struct shpstr *, int);
|
||||
|
||||
void prep_ships(int etus, natid natnum)
|
||||
void prep_ships(int etus)
|
||||
{
|
||||
int mil, i;
|
||||
double mil_pay;
|
||||
|
@ -66,8 +66,6 @@ void prep_ships(int etus, natid natnum)
|
|||
for (i = 0; (sp = getshipp(i)); i++) {
|
||||
if (sp->shp_own == 0)
|
||||
continue;
|
||||
if (sp->shp_own != natnum)
|
||||
continue;
|
||||
if (CANT_HAPPEN(sp->shp_effic < SHIP_MINEFF)) {
|
||||
makelost(EF_SHIP, sp->shp_own, sp->shp_uid,
|
||||
sp->shp_x, sp->shp_y);
|
||||
|
@ -77,14 +75,14 @@ void prep_ships(int etus, natid natnum)
|
|||
|
||||
mil = sp->shp_item[I_MILIT];
|
||||
mil_pay = mil * etus * money_mil;
|
||||
nat_budget[natnum].mil.count += mil;
|
||||
nat_budget[natnum].mil.money += mil_pay;
|
||||
nat_budget[natnum].money += mil_pay;
|
||||
nat_budget[sp->shp_own].mil.count += mil;
|
||||
nat_budget[sp->shp_own].mil.money += mil_pay;
|
||||
nat_budget[sp->shp_own].money += mil_pay;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prod_ship(int etus, int natnum, struct bp *bp, int build)
|
||||
prod_ship(int etus, struct bp *bp, int build)
|
||||
/* build = 1, maintain = 0 */
|
||||
{
|
||||
struct shpstr *sp;
|
||||
|
@ -93,8 +91,6 @@ prod_ship(int etus, int natnum, struct bp *bp, int build)
|
|||
for (i = 0; (sp = getshipp(i)); i++) {
|
||||
if (sp->shp_own == 0)
|
||||
continue;
|
||||
if (sp->shp_own != natnum)
|
||||
continue;
|
||||
upd_ship(sp, etus, bp, build);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue