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:
Markus Armbruster 2016-07-10 23:08:57 +02:00
parent 70f69640e1
commit c5df505c98
11 changed files with 152 additions and 173 deletions

View file

@ -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);
}
}