(getminleft): Parameter hours unused since the previous rev., remove.
Change parameter mpd from int * to int, because its only use is *mpd
as r-value. Callers changed.
(kw_read, kw_find, kwtab, kw_list): Were used to evaluate the hours
file until 4.2.7. Since then kw_read() is unused, and kw_find()
always returns NULL. Remove. kw_find() callers changed.
Selector rewrite: values other than long, interpret identifiers
according to context, to make `lstat * ?type#spy&spy>1' work. Closes
bug#825363, #905809, #905814 and #922968.
(nsc_type, packed_nsc_type, nsc_cat, packed_nsc_cat, nsc_flags): New.
(valstr): New. Old code encoded values in type long, which was
somewhat hard to read and could only support signed integer values.
(nscstr): Redesign. Use valstr. Typed operator.
(castr): Split ca_code into ca_type, ca_flags, ca_off. Tables
changed.
(nstr_comp, nstr_exec): Redesign and rewrite. Callers changed. They
used the old design incorrectly, which let players smash the stack
by supplying more than NCOND conditions.
(encode, nstr_comp_val, decode, nstr_exec_val): Rename, redesign, and
rewrite. Callers changed.
(nstr_coerce_val): New.
(var_ca, sect_ca, ship_ca, land_ca): Checking both var_ca[] and the
object's ca complicates proper recognition of unique abbreviations.
Copy contents of var_ca[] into the ca of objects, remove var_ca[].
(surv): Reject values with category other than NSC_OFF and types that
can't be coerced to NSC_LONG. Old code happily passed values with
category NSC_VAL to code_char(). The previous version interpreted
them correctly, but earlier versions interpreted them as NSC_OFF, then
logged `bad type in decode: 0' and evaluated them into zero.
(code_char): Used to test category NSC_VAR to decide whether to
display tens or hundreds. NSC_VAR no longer exists. Test type
instead. Makes more sense anyway.
(RANDOM, SRANDOM): New, to allow overriding the PRNG on the compiler
command line for reproducible automated tests. This is expected to be
a temporary solution until we get more capable system configuration.
Callers of random(), srandom() changed. From Marc Olzheim.
(main, write_newcap_script): Don't warn when resources were added,
that's expected nowadays. Warn when resources were not added. Don't
mention the ore program, as it doesn't work and we no longer
distribute it.
(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.
(do_fallout, meltitems): 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.
(meltitems): Don't claim more items were lost than existed.
(upd_ship, upd_land, do_plague): Work directly on item arrays instead
of copies made by getvec(). This is safe, because the new code
changes the item array precisely when the old code writes back a
changed copy.
(starv_ships, starv_units): Replace getvec() by direct, read-only item
access.
(feed_ship, feed_land): Remove parameter vec, work with sp->shp_item[]
and lp->lnd_item[] instead.
(plague_people): Change argument type to match uncopied item arrays.
(infect_people): Remove parameters vec, eff, mobil and work with
sp->sct_item, sp->sct_effic, sp->sct_mobil instead. This is safe,
because the only caller passed a copy of sp->sct_item created with
getvec(), and infect_people() doesn't change it. Caller changed.
(infect_people): Rewrite plague risk computation for clarity.
(feed_land): Simplify. Amount of food taken from ship could be off by
one due to rounding, fix. However, the fixed code is currently
unreachable, as caller runs resupply_commod() before feed_land().
(feed_ship): Simplify. No functional changes.
(shiprepair): Remove parameter vec, work with ship->shp_item[]
instead. This is safe, because the only caller passed a copy of the
latter created with getvec(), and shiprepair() doesn't change it.
Caller changed.
(feed_ship): Work directly on land item arrays instead of copies made
by getvec(). This is safe, because the new code changes the item
array precisely when the old code writes back a changed copy.
(feed_land): Work directly on ship item arrays instead of copies made
by getvec(). This is safe, because the new code changes the item
array precisely when the old code writes back a changed copy.
(set_option, delete_option): Gripe about unknown options. If multiple
options have identical names in Options[], all but the first are
ignored. This should never happen.
(get_materials): Work directly on item arrays instead of copies made
by getvec(). This is safe, because the new code changes the item
array precisely when the old code writes back a changed copy.
(dodistribute): 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.
(dodeliver): Remove parameter vec, work with sp->sct_item[] instead.
This is safe, because the only caller passed a copy of the latter
created with getvec(), and dodeliver() doesn't change it. Caller
changed. Return value no longer needed, remove.
(populace): Remove parameter vec, work with sp->sct_item[] instead.
This is safe, because the only caller passed a copy of the latter
created with getvec(), and populace() doesn't change it.
(tax): Replace getvec() by direct, read-only item access.
(pln_equip, mission_pln_equip): 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
before flushing those. Simplify.
(pln_equip, mission_pln_equip): Rename item to itype. Use struct
ichrstr member i_vtype instead of pointer arithmetic to map from
`struct ichrstr *' to item type. No functional changes.
(sd, shp_missile_defense): Replace getvec() by direct, read-only item
access. This is correct, because the old code doesn't use the copy
after it changes the original in the unit structure.
(dd): Remove call of getvec() that has no effect.
(quiet_bigdef): 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 before flushing
those, in use_ammo(), or discarded both the copy and the unit
structure.
(scra): 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 before flushing
those. To do: obey ITEM_MAX.
(grin): Stop grinding before grind puts more than ITEM_MAX bar
constituents in sector. 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
before flushing those.
(improve, shoo, spy, buildeff): 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
before flushing those.
(buil): 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 before flushing
those.
(build_ship, build_land, build_bridge, build_nuke, build_plane,
build_tower): Change parameter type to match uncopied item arrays.
Utility programs `land', `ore' and `perfect' haven't been built by
default for ages (at least 4.2.0 '98). Unsurprisingly, they don't
compile anymore. Remove them.
Use gcc function attribute `format' to catch bad format strings. Fix
them. From Marc Olzheim.
Type modifier 'l' was missing in many places, probably rendering the
server useless on 64-bit hosts.
(ef_flush, ef_write, ef_extend, lwpCreate, lwpDestroy): Use conversion
specifier 'p' to print pointers.
(check_market): Fix display of loan amount.
(doland): Fix unescaped '%' (undefined behavior).
(ldump, ndump, pdump, sdump): Don't use flag '0' with conversion
specifier 's' (undefined behavior).
(dump, ldump, lost, ndump, pdump, sdump, empth_create, update_sched):
Cast time_t and pthread_t to long for printing.
(lwpStackCheck, lwpStackCheckUsed, finish_sects): Insert cast to fix
argument type on all platforms.
(prod): Remove extra argument.
(perform_mission, airdamage, retreat_land1, lwpReschedule): Format
string missed arguments.
From Ron Koenderink:
(pr_land): Fix display of attack and defense value.
(dounit): New parameter farg. Callers changed. Use it to implement
attack and defense value editing. Closes #872271.
(pr_ship): More space efficient display.
(pr_ship): Display defense value.
(doship): Implement defense value editing.
(resupply_commod, s_commod, use_supply, has_supply): 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 before flushing those.
(use_supply): Fix the trickery designed to avoid resupply from itself.
Currently, use_supply() is only called for artillery, where the
trickery is not needed, so this fix isn't observable. Not sure whether
it would be needed if use_supply() were called for supply units.
(has_supply): Fix the trickery designed to avoid resupply from itself.
Not sure the trickery is needed. Also avoid `might be used
uninitialized' warning.
(s_commod): When !ACTUALLY_DOIT, recursive land unit resupply didn't
work, because the effect of the resupply was immediately undone by an
untimely getvec().
(s_commod): Don't zap supply unit fuel on recursive resupply. No idea
why it was coded that way; it doesn't make sense. No supply units
using fuel exist in the stock game.
(s_commod): Clarify and comment the trickery required to make the
recursion work. By the way, resuppling from supply units in unit id
order is a greedy algorithm, which is quite inappropriate for the
problem.
(gen_power, addtopow): Call addtopow() directly on item arrays instead
of copies made by getvec(). This is obviously correct, since there
are no writes.
(sctstr, shpstr, lndstr): Use `short' instead of `unsigned short' for
item storage. Rationale: Permitted values are 0..M, where M depends
on the container. The largest M is ITEM_MAX (9999). Benign
overflow/underflow occurs at those limits. Catastrophic
overflow/underflow occurs at the limits of the underlying data type.
For `unsigned short', any underflow is catastrophic. For `short',
benign undeflow happens long before catastrophic underflow. Moreover,
unsigned arithmetic tends to trip up unwary programmers.
(deli, do_demo, lnd_sweep, guerrilla): Saturate items at ITEM_MAX.
With variables, item increases beyond the capacity of variables
(65535) were ignored here.
This should cover all item changes not going through putvec().
(ITEM_MAX): New, value 9999.
(give, deliver_it): Use it instead of 9990.
(load_comm_ship, load_comm_land, rese): Use it instead of 9999.
(thre): Use it instead of 10000.
(check_market, explore, move, pln_dropoff): Use it instead of 32767.
(unload_it): Use it instead of 99999 (which couldn't possibly work,
but what do you expect from the autonav code).
(FALLOUT_MAX): New.
(doland, detonate, spread_fallout): Use it. With variables, fallout
beyond the capacity of variables (65535) was ignored, except in
doland(), where it saturated at 9999, and spread_fallout, where it
could overflow. Now it always saturates at FALLOUT_MAX.