(produce_sect): Unless player->simulation, work directly on item

arrays instead of copies made by getvec().  This is safe, because the
old code made single copies and always flushed them back into the unit
structures.  Else make copies by hand, not with getvec.
(starv_sects): Replace getvec() by direct, read-only item access.
(upd_buildeff, enlist, materials_charge, materials_cost, produce,
grow_people, growfood, trunc_people, do_feed, feed_people): Change
argument type to match uncopied item arrays.
(growfood): Obey ITEM_MAX.
This commit is contained in:
Markus Armbruster 2004-03-11 22:00:58 +00:00
parent 61d57719c2
commit b62aca0ecd
5 changed files with 36 additions and 52 deletions

View file

@ -551,8 +551,8 @@ extern int dodistribute(struct sctstr *, int, s_char *, double, double);
extern void finish_sects(int); extern void finish_sects(int);
/* human.c */ /* human.c */
extern int do_feed(register struct sctstr *, register struct natstr *, extern int do_feed(register struct sctstr *, register struct natstr *,
int *, int *, int *, int); short *, int *, int *, int);
extern int feed_people(register int *, int, int *); extern int feed_people(short *, int, int *);
/* land.c */ /* land.c */
extern int prod_land(int, int, int *, int); extern int prod_land(int, int, int *, int);
extern int feed_land(struct lndstr *, int, int *, int); extern int feed_land(struct lndstr *, int, int *, int);
@ -605,7 +605,7 @@ extern int upd_slmilcosts(natid, int);
extern void prepare_sects(int, int *); extern void prepare_sects(int, int *);
extern int bank_income(struct sctstr *, int); extern int bank_income(struct sctstr *, int);
/* produce.c */ /* produce.c */
extern int produce(struct natstr *, struct sctstr *, int *, int, int, extern int produce(struct natstr *, struct sctstr *, short *, int, int,
int, int *, int *); int, int *, int *);
/* removewants.c */ /* removewants.c */
extern int update_removewants(void); extern int update_removewants(void);

View file

@ -103,7 +103,7 @@ starv_sects(s_char *range)
struct nstr_sect nstr; struct nstr_sect nstr;
struct sctstr sect; struct sctstr sect;
int nsect = 0; int nsect = 0;
int vec[I_MAX + 1], s, needed; int s, needed;
if (!snxtsct(&nstr, range)) if (!snxtsct(&nstr, range))
return; return;
@ -113,11 +113,10 @@ starv_sects(s_char *range)
if (sect.sct_type == SCT_SANCT) if (sect.sct_type == SCT_SANCT)
continue; continue;
getvec(VT_ITEM, vec, (s_char *)&sect, EF_SECTOR);
/* This next 2 lines were added to overcompensate for the needy */ /* This next 2 lines were added to overcompensate for the needy */
if (vec[I_FOOD]) if (sect.sct_item[I_FOOD])
vec[I_FOOD]--; sect.sct_item[I_FOOD]--;
s = feed_people(vec, etu_per_update, &needed); s = feed_people(sect.sct_item, etu_per_update, &needed);
if (s == 0) if (s == 0)
continue; continue;

View file

@ -51,18 +51,18 @@
static int grow_people(struct sctstr *, register int, static int grow_people(struct sctstr *, register int,
register struct natstr *, int *, int, register struct natstr *, int *, int,
register int *); short *);
static int growfood(struct sctstr *, register int *, int, int); static int growfood(struct sctstr *, short *, int, int);
static void starvation(struct sctstr *); static void starvation(struct sctstr *);
static void trunc_people(struct sctstr *, register struct natstr *, static void trunc_people(struct sctstr *, register struct natstr *,
register int *); short *);
/* /*
* feed the individual sector * feed the individual sector
* *
*/ */
int int
do_feed(register struct sctstr *sp, register struct natstr *np, int *vec, do_feed(struct sctstr *sp, struct natstr *np, short *vec,
int *workp, int *bp, int etu) int *workp, int *bp, int etu)
{ {
int people; int people;
@ -150,7 +150,7 @@ do_feed(register struct sctstr *sp, register struct natstr *np, int *vec,
} }
static int static int
growfood(struct sctstr *sp, register int *vec, int work, int etu) growfood(struct sctstr *sp, short *vec, int work, int etu)
{ {
double food_fertil; double food_fertil;
double food_workers; double food_workers;
@ -174,8 +174,8 @@ growfood(struct sctstr *sp, register int *vec, int work, int etu)
vec[I_FOOD] += (int)food; vec[I_FOOD] += (int)food;
if (vec[I_FOOD] == 0) if (vec[I_FOOD] == 0)
vec[I_FOOD] = 1; vec[I_FOOD] = 1;
if (vec[I_FOOD] > 9999) if (vec[I_FOOD] > ITEM_MAX)
vec[I_FOOD] = 9999; vec[I_FOOD] = ITEM_MAX;
work_used = (int)food / fcrate; work_used = (int)food / fcrate;
return work_used; return work_used;
} }
@ -184,7 +184,7 @@ growfood(struct sctstr *sp, register int *vec, int work, int etu)
* returns the number who starved, if any. * returns the number who starved, if any.
*/ */
int int
feed_people(register int *vec, int etu, int *needed) feed_people(short *vec, int etu, int *needed)
{ {
double food_eaten; double food_eaten;
int ifood_eaten; int ifood_eaten;
@ -241,7 +241,7 @@ feed_people(register int *vec, int etu, int *needed)
*/ */
static void static void
trunc_people(struct sctstr *sp, register struct natstr *np, trunc_people(struct sctstr *sp, register struct natstr *np,
register int *vec) short *vec)
{ {
int maxpop = max_pop(np->nat_level[NAT_RLEV], sp); int maxpop = max_pop(np->nat_level[NAT_RLEV], sp);
@ -260,7 +260,7 @@ trunc_people(struct sctstr *sp, register struct natstr *np,
static int static int
grow_people(struct sctstr *sp, register int etu, grow_people(struct sctstr *sp, register int etu,
register struct natstr *np, int *workp, int sctwork, register struct natstr *np, int *workp, int sctwork,
register int *vec) short *vec)
{ {
int newciv; int newciv;
int newuw; int newuw;

View file

@ -46,15 +46,14 @@
#include "optlist.h" #include "optlist.h"
#include "budg.h" #include "budg.h"
static void materials_charge(struct pchrstr *, register int *, static void materials_charge(struct pchrstr *, short *, int);
register int); static int materials_cost(struct pchrstr *, short *, int *);
static int materials_cost(struct pchrstr *, register int *, int *);
s_char *levelnames[] = s_char *levelnames[] =
{ "Technology", "Research", "Education", "Happiness" }; { "Technology", "Research", "Education", "Happiness" };
int int
produce(struct natstr *np, struct sctstr *sp, int *vec, int work, produce(struct natstr *np, struct sctstr *sp, short *vec, int work,
int desig, int neweff, int *cost, int *amount) int desig, int neweff, int *cost, int *amount)
{ {
register struct pchrstr *product; register struct pchrstr *product;
@ -190,7 +189,7 @@ produce(struct natstr *np, struct sctstr *sp, int *vec, int work,
} }
static int static int
materials_cost(struct pchrstr *product, register int *vec, int *costp) materials_cost(struct pchrstr *product, short *vec, int *costp)
{ {
register u_char *vp; register u_char *vp;
register u_short *ap; register u_short *ap;
@ -216,8 +215,7 @@ materials_cost(struct pchrstr *product, register int *vec, int *costp)
} }
static void static void
materials_charge(struct pchrstr *product, register int *vec, materials_charge(struct pchrstr *product, short *vec, int count)
register int count)
{ {
register u_char *vp; register u_char *vp;
register u_short *ap; register u_short *ap;

View file

@ -88,7 +88,7 @@ dodeliver(struct sctstr *sp)
*/ */
static int static int
upd_buildeff(struct natstr *np, register struct sctstr *sp, int *workp, upd_buildeff(struct natstr *np, register struct sctstr *sp, int *workp,
int *vec, int etu, int *desig, int sctwork, int *cost) short *vec, int etu, int *desig, int sctwork, int *cost)
{ {
register int work_cost = 0; register int work_cost = 0;
int buildeff_work = (int)(*workp / 2); int buildeff_work = (int)(*workp / 2);
@ -171,7 +171,7 @@ upd_buildeff(struct natstr *np, register struct sctstr *sp, int *workp,
* some mil initially. * some mil initially.
*/ */
static int static int
enlist(register int *vec, int etu, int *cost) enlist(short *vec, int etu, int *cost)
{ {
int maxmil; int maxmil;
int enlisted; int enlisted;
@ -327,7 +327,8 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
{ {
register struct sctstr *sp; register struct sctstr *sp;
register struct natstr *np; register struct natstr *np;
int vec[I_MAX + 1]; short buf[I_MAX + 1];
short *vec;
int work, cost, ecost, pcost, sctwork; int work, cost, ecost, pcost, sctwork;
int n, desig, maxpop, neweff, amount; int n, desig, maxpop, neweff, amount;
@ -346,8 +347,13 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
p_sect[SCT_CAPIT][1] += etu; p_sect[SCT_CAPIT][1] += etu;
} }
if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) if (player->simulation) {
continue; /* work on a copy, which will be discarded */
memcpy(buf, sp->sct_item, sizeof(buf));
vec = buf;
} else
vec = sp->sct_item;
/* If everybody is dead, the sector reverts to unowned. /* If everybody is dead, the sector reverts to unowned.
* This is also checked at the end of the production in * This is also checked at the end of the production in
* they all starved or were plagued off. * they all starved or were plagued off.
@ -375,10 +381,8 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
bp_clear_cachepath(); bp_clear_cachepath();
if (sp->sct_off || np->nat_money < 0) { if (sp->sct_off || np->nat_money < 0) {
if (!player->simulation) { if (!player->simulation)
putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
sp->sct_off = 0; sp->sct_off = 0;
}
continue; continue;
} }
if ((np->nat_priorities[sp->sct_type] == 0) && if ((np->nat_priorities[sp->sct_type] == 0) &&
@ -386,7 +390,6 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
((pchr[dchr[sp->sct_type].d_prd].p_cost != 0) || ((pchr[dchr[sp->sct_type].d_prd].p_cost != 0) ||
(sp->sct_type == SCT_ENLIST))) { (sp->sct_type == SCT_ENLIST))) {
if (!player->simulation) { if (!player->simulation) {
putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
logerror("Skipping %s production for country %s\n", logerror("Skipping %s production for country %s\n",
dchr[sp->sct_type].d_name, np->nat_cnam); dchr[sp->sct_type].d_name, np->nat_cnam);
} }
@ -401,28 +404,14 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) && if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) &&
np->nat_money > 0) { np->nat_money > 0) {
neweff = neweff = upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork,
upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork, &cost);
&cost);
pt_bg_nmbr(bp, sp, I_LCM, vec[I_LCM]); pt_bg_nmbr(bp, sp, I_LCM, vec[I_LCM]);
pt_bg_nmbr(bp, sp, I_HCM, vec[I_HCM]); pt_bg_nmbr(bp, sp, I_HCM, vec[I_HCM]);
p_sect[SCT_EFFIC][0]++; p_sect[SCT_EFFIC][0]++;
p_sect[SCT_EFFIC][1] += cost; p_sect[SCT_EFFIC][1] += cost;
if (!player->simulation) { if (!player->simulation) {
np->nat_money -= cost; np->nat_money -= cost;
/* No longer tear down infrastructure
if (sp->sct_type != desig) {
sp->sct_road = 0;
sp->sct_defense = 0;
} else if (neweff < sp->sct_effic) {
sp->sct_road -= (sp->sct_road * (sp->sct_effic - neweff) / 100.0);
sp->sct_defense -= (sp->sct_defense * (sp->sct_effic - neweff) / 100.0);
if (sp->sct_road < 0)
sp->sct_road = 0;
if (sp->sct_defense < 0)
sp->sct_defense = 0;
}
*/
sp->sct_type = desig; sp->sct_type = desig;
sp->sct_effic = neweff; sp->sct_effic = neweff;
if (!opt_DEFENSE_INFRA) if (!opt_DEFENSE_INFRA)
@ -434,7 +423,6 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
((pchr[dchr[desig].d_prd].p_cost != 0) || ((pchr[dchr[desig].d_prd].p_cost != 0) ||
(desig == SCT_ENLIST))) { (desig == SCT_ENLIST))) {
if (!player->simulation) { if (!player->simulation) {
putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
logerror("Skipping %s production for country %s\n", logerror("Skipping %s production for country %s\n",
dchr[sp->sct_type].d_name, np->nat_cnam); dchr[sp->sct_type].d_name, np->nat_cnam);
} }
@ -468,7 +456,6 @@ produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2],
vec[I_CIVIL] = maxpop; vec[I_CIVIL] = maxpop;
if (vec[I_UW] > maxpop) if (vec[I_UW] > maxpop)
vec[I_UW] = maxpop; vec[I_UW] = maxpop;
putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
sp->sct_avail = work; sp->sct_avail = work;
np->nat_money -= pcost; np->nat_money -= pcost;
} }