Commit graph

201 commits

Author SHA1 Message Date
40eb78eb74 Fix confused and buggy bridge splashing code
A bridge (span or tower) must be splashed when it gets damaged below
SCT_MINEFF.  Likewise when its last supporting sector (bridge head or
tower) gets damaged below SCT_MINEFF, unless EASY_BRIDGES is enabled.
We need to check this whenever a bridge head, span or tower gets
damaged.  This is done in three places, and all of them screw up:

* checksect() ignores damage to bridge heads.  It also leaves writing
  back the sector it checks to the caller, which never happens when
  it's called from sct_postread().

  Note that checksect() drowns all planes on bridges it splashes.
  Functions that need to exempt flying planes from such a fate have to
  splash bridges themselves.

* sect_damage() ignores damage to bridge towers, and damage to bridge
  spans unless EASY_BRIDGES is enabled.  It then runs checksect(),
  which compensates for these omissions, but happily drowns the planes
  sect_damage() attempts to protect.

* eff_bomb() ignores damage to bridge heads.  Collateral damage makes
  sect_damage() run, which compensates for the omission.

This causes the following bugs:

* Efficiency damage going through sect_damage() can drown planes it
  shouldn't.  This affects pinpoint bombing when collateral damage
  splashes a bridge, and strategic bombing.  The drowned planes then
  crash and burn when they attempt to land at their (just splashed)
  base.

* Efficiency damage to bridge heads not going through sect_damage()
  fails to collapse unsupported bridges.  This affects pin-bombing
  efficiency without collateral damage, and ground combat.  Also deity
  commands edit, setsector and add, but that could be regarded as a
  feature.

* If the sector file somehow ends up with an inefficient bridge span,
  it collapses on every read again and again, until it collapses on a
  write.  Related problems exist with other actions of checksect(),
  and they're not addressed here.

* If the sector file somehow ends up with adjacent inefficient bridge
  towers, checksect() on any of them recurses infinitely:

  - checksect() inefficient tower T1
    - knockdown() T1, but don't write that back to the sector file
    - bridgefall() T1; this reads all adjacent sectors, including
      inefficient towert T2
      - checksect() T2
        - knockdown() T2, but don't write that back to the sector file
	- bridgefall() T1; this reads adjacent sectors including T1
	  - checksect() T1
	    ...

This commit creates a new function bridge_damaged() to splash any
bridges that became inefficient or unsupported after damage to a
sector.  To avoid the inifinite recursion, we call it in
sct_prewrite() instead of checksect().

No uses knockdown() outside bridgefall.c remain, so give it internal
linkage.
2008-02-16 20:57:38 +01:00
b76e5a5eed Make conftab.c independent of the current directory
read_builtin_tables() wanted to run in builtindir, and
read_custom_tables() wanted to run in configdir.  Bothersome.  Use new
fopenat() to relax those requirements.

The chdir() satisfying them are now superflous, remove them.
2008-02-07 08:01:54 +01:00
4bb23dd1a6 Make econfig keys data and info work for relative names
File names in econfig need to be interpreted relative to configdir.
This wasn't the case everywhere for keys data and info.

Fix this by changing variables gamedir and infodir to hold absolute
names.  Change builtindir likewise, for consistency.  Store the values
from econfig in gamedir_conf, infodir_conf and builtindir_conf.

Uses new fnameat() to derive absolute names from possibly relative
ones.
2008-02-07 08:01:54 +01:00
77e95bd788 Clean up library dependencies
Move stuff to untangle the ugly cyclic dependencies between the
archives built for selected subdirectories of src/lib/:

* Move common/io.c to empthread/ because it requires empthread stuff

* Move parts of subs/nstr.c to common/nstreval.c to satisfy
  common/ef_verify.o

* Move getstarg.c getstring.c onearg.c from gen/ to subs/ because they
  require stuff from there

* Move bridgefall.c check.c damage.c empobj.c journal.c maps.c
  sectdamage.c from common/ to subs/ because they require stuff from
  there

* Move cnumb.c from subs/ to common/ to satisfy common/type.o

* Move log.c fsize.c from common/ to gen/ because they really belong
  there

* Move emp_config.c mapdist.c from gen/ to common/ because they really
  belong there, and require stuff from libglobal.a

Also package as/ as libas.a to satisfy common/path.o.

Remaining dependencies:

    lib             needs
    --------------------------------------------
    libas.a         libglobal.a
    libcommon.a     libas.a libglobal.a libgen.a
    libgen.a
    libglobal.a
    liblwp.a        libgen.a
    libw32.a[*]     libgen.a

    [*] Except for service.o, which can only be linked into the server

Link order now: liblwp.a libcommon.a libas.a libgen.a libglobal.a
libw32.a.  The position of libw32.a is not quite right, but works
anyway.
2008-02-03 08:11:13 +01:00
3d2518a724 Get rid of src/lib/common/land.c
There are several files with land unit subroutines.  This one is in an
awkward place: it depends on stuff from ../subs, which contributes to
libcommon.a's ugly dependencies.  Move its contents to logical places
(use internal linkage where possible), and remove it.
2008-02-03 07:37:16 +01:00
db02dda32f Update copyright notice 2008-01-19 10:15:37 +01:00
2b5ebf1f3f (player_set_nstat): New, factored out of init_nats().
(init_nats): Use it.  No functional change.

(status): Use it.  This sets player->nstat from scratch, not just
MONEY and CAP.
(brea): Don't bother to update player->nstat, status() will.
2007-12-08 19:27:41 +00:00
90631d56ed Record raw arguments, to be used in the next changesets:
(player): New member comtail.
(parse): New parameter tail.  Reorder parameter list.
(command, execute): Pass player->comtail.
(player_login, emp_config, do_unit_move): Pass NULL.  No functional
change.
2007-11-25 13:55:52 +00:00
836833e321 (carrier_planes): New parameter msl.
(carriersatxy, pln_onewaymission): Pass zero.  No functional change.
(pln_airbase_ok): Pass whether the plane is a missile.  This fixes
non-x-light missiles on ships without capability M_FLY.  Broken in
rev. 1.76.  Launch and interdict weren't affected.  Air defense was,
but the stock game has only x-light SAMs.
2007-11-22 19:33:14 +00:00
a98bac5146 (sendmessage): Internal linkage. 2007-11-18 11:58:30 +00:00
6992bcfe9a (carriersatxy): Remove parameters wantflags, nowantflags, and use
carrier_planes() instead, ignoring carriers that can only operate
x-light planes.  No functional change.
(carrier_planes): External linkage.
2007-11-04 16:05:06 +00:00
4ced91fe3f (pln_airbase_ok): New parameter noisy to allow suppressing messages.
Check player->cnum only when noisy.  Update existing caller to pass 1.
No functional change.

(mission_pln_airbase_ok): Remove, use pln_airbase_ok() instead.  No
functional change.
2007-11-03 09:29:45 +00:00
4d663ddbd6 (pln_wanted, pln_capable): Rename. 2007-11-02 19:13:10 +00:00
98105c9561 (mission_pln_wanted): Broken like its cousin pln_wanted() was, only
more so: additionally, any of P_E, P_K, P_L satisfied any subset of
P_E, P_K, P_L.  Chainsaw fixed this one in plnsub.c, but not here.
Remove, use the fixed pln_wanted() instead.
(pln_wanted): External linkage.
2007-11-01 19:50:37 +00:00
d3fcc89f56 (can_be_on_ship, could_be_on_ship): Take pointer rather than UID
arguments.  Rename.  Callers changed.
2007-10-31 06:39:37 +00:00
51165cf3fc Collect the test whether a plane fits on a carrier in one place:
(fit_plane_on_ship, fit_plane_on_land): New.
(pln_oneway_to_carrier_ok, put_plane_on_ship, count_planes)
(put_plane_on_land, count_land_planes): Use them.  No functional
change.
(fit_plane_off_ship, fit_plane_off_land): New.
(take_plane_off_ship, take_plane_off_land): Use them.  This oopses
when the carriers plane counter underflows.

(take_plane_off_ship): Document that carrier's plane counters may be
screwed up.

(take_plane_off_ship, take_plane_off_land): Oops when the plane isn't
on the carrier.

(take_plane_off_ship, take_plane_off_land): Don't fail when the plane
to be taken off can't go on this type of carrier, just take it off.
No error condition left, so return void.  Callers couldn't do anything
useful with the status anyway, and most didn't bother.  Change those
that did.
2007-10-30 07:09:31 +00:00
9c94a23709 Keep log open, rotate it just like the journal:
(logfd, logopen): New.
(loginit): Set logfd, return success.
(logerror): Use logfd.
(logreopen): New.
(relo, main): Use it.
2007-10-27 15:49:45 +00:00
Ron Koenderink
ec484e17a7 (main, init_server, emp_server.6): Add -R command line option to set
a seed for the random function.

(nightlybuild.sh): Add the -R 1 for the server.
(nightlybuild.sh): Switch to -R 1 for the fairland as 1 is safer.
Some systems might generate lousy randomness from a
zero seed.

(prng.patch): Not required anymore, -R 1 is used instead.

(main, emp_server.6): Rename -r and -R to -u and -U.  "-R" is now used for random seed.
2007-10-23 03:05:56 +00:00
971515ccc9 (xundump): Count lines in a saner way: pass line number in and out.
Callers changed.
2007-08-05 16:22:41 +00:00
f2d96f466a Fix include missing since misc.h rev. 1.69. 2007-08-01 05:30:37 +00:00
286dda725e Store update disable flag in the game table to make it visible in
xdump:
(gamestr): New member game_upd_disable.
(game_ca): Update accordingly.
(game_ctrl_update): New.
(disa, enab): Use it.
(updates_disabled): Rewrite and move to game.c
(disablefil): Remove.
2007-07-27 05:58:40 +00:00
a57645340c New command show updates:
(show): New sub-command.
(player_coms): Update its c_form.
(show_updates, fmttime2822): New.

(vers): Show game_days and game_hours.

(upda): Mark obsolete and point to show updates.
(vers): Point to show rather than update.

Rewrite much of info zdone.
2007-07-15 13:34:22 +00:00
4bd19812af Use the new Empire clock for implementing MOB_ACCESS:
(lndstr, plnstr, sctstr, shpstr): Change timestamp members lnd_access,
pln_access, sct_access, shp_access from real time (time_t) to ETUs
within a turn (short).
(land_ca, plane_ca, sect_ca, ship_ca): Update accordingly.
(build_ship, build_land, build_bridge, build_plane, build_tower)
(explore, check_trade, bsanct, takeover, takeover_ship)
(takeover_land): Use game_tick_to_now() instead of time() to update
the timestamp.  Change check_trade(), takeover_ship(), takeover_land()
to do that only when MOB_ACCESS is enabled, for consistency.
(lupgr, supgr, pupgr, takeover_ship): Don't touch the timestamp where
mobility isn't touched either.
(sct_do_upd_mob, shp_do_upd_mob, lnd_do_upd_mob, pln_do_upd_mob): Use
game_tick_to_now() instead of increase_mob() to compute ETUs since
the timestamp and update the timestamp.  Closes #1012699.
(increase_mob): Remove.
(mob_sect, mob_ship, mob_land, mob_plane): sct_do_upd_mob() & friends
no longer do the right thing at the update.  Use game_reset_tick() and
pass its result directly to do_mob_sect() & friends.  This is only
correct when argument is etu_per_update, which it always is.  Remove
parameter.  Callers changed.
(do_mob_sect, do_mob_ship, do_mob_land, do_mob_plane): Oops on
negative argument.

(mob_acc_globals, timestampfil, mobupdate, updating_mob)
(update_all_mob, timestamp_fixing, update_timestamps, mobility_check):
The mobupdate command was important to let deities manually
synchronize mobility updating with updates.  That's no longer needed.
The code behind it is somewhat hairy and ugly, and updating it to work
with the Empire clock is just not worth it.  Remove.  Users changed.
(player_coms): Update accordingly.
(upda): Remove display of mobility updating state.

(mobility_init): No need to fix up mobility on startup, as the Empire
clock runs normally even when the server is down.  Remove.  Caller
changed.
2007-07-15 09:43:57 +00:00
ae9a759527 (relo): New command. 2007-07-13 06:04:03 +00:00
71320ed67f New update scheduler:
(schedulefil): New.
(set_dirs, set_paths): Rename.  Initialize schedulfil.
(read_schedule): New.  Can read several updates, which will be used in
later changesets.
(update_time): Change to array.  Will be used in later changesets.
(update_schedule_anchor): New.
(update_init): Initialize it.
(update_get_schedule): New.
(update_init): Call it to initialize update_time[].
(update_sched): Rewrite.
(update_forced, update_wanted): Replace.
(update_reschedule): New.
(main): Call it on SIGHUP to reload the schedule.
(update_trigger, update_force, force, player_coms): Drop force's
capability to schedule updates in the future, because it's not worth
the trouble to implement again.  Deities can simply edit the schedule
file to schedule updates.  Remove update_force() and
update_trigger()'s parameter.
(upda): Update for new scheduler.  Take care to keep output the same
as far as possible, even though it's ugly, to avoid breaking clients.
(update_policy, adj_update, update_times, hourslop, blitz_time):
econfig keys removed.
(update_demand, UPD_DEMAND_NONE, UPD_DEMAND_SCHED, UPD_DEMAND_ASYNC)
(update_demandpolicy, UDP_NORMAL, UDP_TIMES, UDP_NORMAL, UDP_BLITZ)
(UDP_MAX, UDP_DEFAULT, UDDEM_TMCHECK, UDDEM_COMSET, UDDEM_DISABLE)
(UDDEM_MAX, UDDEM_DEFAULT): econfig key and values replaced.  Users
changed.  wantupd.h is now empty, remove.
(demand_check): External linkage.
(update_policy_check): Now pointless, remove.
(is_daytime_near, min_to_next_daytime, regular_update_time)
(scheduled_update_time, next_scheduled_time, updatetime)
(next_update_time, next_update_check_time): Unused, Remove.

(demand_check, demandupdatecheck): Move call of demand_update_time()
from demand_check(), which controls all demand updates, to
demandupdatecheck(), which controls only unscheduled ones.  Fixes
update command not to lie about the next scheduled demand update.

(demandupdatecheck): Check updates_disabled() so that zdone no longer
claims to trigger an update when it can't.
2007-07-11 22:27:29 +00:00
3788676530 Clean up after removal of wait command:
(player_wakeup_all, player_wakeup): Remove.  Callers changed.
(player): Remove member waiting.
2007-01-31 06:08:39 +00:00
Ron Koenderink
7434da679e (unit_view): New, create by expanding shp_view() to work for
land_unit as well.
(do_unit_move): Add view option for land units using unit_view().
Combine ship and land viewing using the unit_view().
(shp_view): Remove, not used any more, replaced by unit_view().
2007-01-27 02:04:27 +00:00
Ron Koenderink
aee2bc78e2 (unit_path): New, create by combining shp_path() and lnd_path().
(do_unit_move): Replace shp_path() and lnd_path() with unit_path().
(shp_path, lnd_path): Remove shp_path() and lnd_path(),
not used any more.
2007-01-24 23:24:37 +00:00
Ron Koenderink
d94d269769 (unit_put): New, create by combining shp_put() and lnd_put().
(sail_nav_fleet, shp_nav_one_sector): Replace shp_put() with unit_put().
(lnd_mar_one_sector, att_fight, move_in_land): Replace lnd_put() with unit_put().
(shp_put, lnd_put): Remove.
2007-01-23 23:51:02 +00:00
Ron Koenderink
038cc74d4e (unit_list): New, create by combining shp_list() and lnd_list().
(do_unit_move): Replace call to shp_list() and lnd_list() with unit_list().
(shp_list, lnd_list): Remove, not needed, replaced by unit_list().
2007-01-23 01:41:37 +00:00
Ron Koenderink
e8f74e0f7e (do_look): Make public.
(do_unit_move): Switch look() and llook() to use
do_look() instead.
2007-01-21 11:48:14 +00:00
Ron Koenderink
0fda2a608a (do_unit_move): New, create from common code in navi() and march().
(navi, move): Use do_unit_move(), remove unneeded code.

(switch_leader, pr_leader_change, get_leader): Make static as only called
from marc.c.
2007-01-20 02:21:10 +00:00
94267b2fe4 Remove the wait command, it's been broken and restricted to deity
since Empire 2, ca. 1995:
(wai): Remove.
(player_coms): Update accordingly.
2007-01-17 20:04:03 +00:00
502e283ea0 (do_feed, produce_sect): Move bp_put_item() calls from do_feed() to
produce_sect(), for consistency with the other update functions that
update sct_item[].  Parameter bp is now unused, remove.
2007-01-14 10:03:19 +00:00
5507e8a1dc Replace the revolting build pointer data structure by a proper data
type.  Make it abstract because that's possible.  Change data layout
so that the slots belonging to a sector are together in memory, it's
nicer to the cache.
(bp): The new type.  Users changed.
(get_wp): Update accordingly.
(alloc_bp): New.
(update_main, calc_all): Use it.  Before, calc_all() allocated 1/7
more than necessary.
2007-01-13 09:07:59 +00:00
63bdc89835 Update copyright notice. 2007-01-09 19:09:31 +00:00
6b70720318 New option AUTO_POWER; closes #1009993:
(opt_AUTO_POWER, update_power): New.
(update_main): Implement AUTO_POWER.
(powe): Disable power new when AUTO_POWER is on.

(powe): New power update.
(gen_power): Compute power into buffer passed by caller, make write to
power file optional.
2006-12-31 16:56:34 +00:00
Ron Koenderink
c6577ef2c5 (get_leader, pr_leader_change): New.
(set_leader, set_flagship): Replace with get_leader() and
pr_leader_change().
2006-12-31 12:31:18 +00:00
Ron Koenderink
fd49704a74 (switch_leader): Generalize the code, no functional changes.
(navi): Change switch_flagship() to call switch_leader() instead.
(switch_flagship): Remove, not needed, replaced with switch_leader().
2006-10-10 20:23:19 +00:00
Ron Koenderink
a9a9957a27 (radar): New, moved functionality from rada() except ef_type determination.
(rada): Call radar() with EF_SHIP.
(lrad): New, call radar() with EF_LAND.
(empmod[]): Call lrad() for lradar command.
(march, navi): Call radar() with appropriate type.
2006-08-16 01:16:30 +00:00
Ron Koenderink
f246f86542 (gift): Remove the type argument, can be determined from the ptr
argument. Replace prship/prland/prplane/prnuke code with
obj_nameof().
2006-08-02 13:07:09 +00:00
6db2e6ec63 (swaps): Failed to update coastal flags. Was missed in the changeset
containing coastal.c rev. 1.1.
(set_coastal): New parameter olddes, to simplify fixing swaps().
Callers changed.
2006-07-21 18:10:09 +00:00
Ron Koenderink
51275c753f (do_map): New. map() was split into two parts map() and do_map().
(map): Call new function do_map().
(display_region_map): Modify to use do_map() instead of map().
(tran_nmap, tran_pmap, cmd_move_map): Modify to accomodate
the modified display_region_map() function.
2006-07-12 18:14:31 +00:00
Ron Koenderink
6d90861aae (obj_nameof): New.
(nameofitem): Remove, switch callers to to obj_nameof().
(mission, show_mission): Convert functions to use obj_nameof()
instead of nameofitem().
2006-07-10 23:14:26 +00:00
e42053d928 Break inclusion cycle: prototypes.h and commands.h included each
other.  Ensure headers in include/ can be included in any order
(except for econfig-spec.h, which is special).  New header types.h to
help avoid inclusion cycles.  Sort include directives.  Remove some
superflous includes.
2006-07-10 06:37:23 +00:00
Ron Koenderink
df8dc6ab5a (tran_map, tran_nmap, tran_pmap): Split tran_map() into tran_nmap()
and tran_pmap() so that unit number arguments are interpreted
sensibly.  Users changed.

(display_region_map): New.
(cmd_move_map, tran_nmap, tran_pmap): Use it.
2006-07-09 18:24:31 +00:00
Ron Koenderink
5ea9060132 (mission, build_mission_list_type, show_mission, oprange): Remove the
type parameter as it can be determined from the empobj parameter.

(oprange): Remove getting the unit information again as it is contained
in the empobj parameter passed in.
2006-07-09 10:57:24 +00:00
Ron Koenderink
79ee88f7c6 (nxtitemp, trade_getitem, trade_desc, trade_check_item_ok, nxtitem,
oprange, show_mission, nameofitem, build_mission_list_type,
unit_map, xdvisible, trdswitchown, ontradingblock, trad, check_trade,
unit_type_name, start_stop_unit, scut, scra, mission, multifire,
perform_mission, fuel, NSC_GENITEM): Replace struct genitem with
struct empobj.  Remove genitem.h and create a new file empobj.h.
Replace multiple instances of unions of ef_type structures with
one standard union empobj_storage which is a superset of the individual
instances.
2006-07-07 15:15:43 +00:00
cdfb17d28a (satdisp, satdisp_sect, satdisp_units): Split satdisp() into
satdisp_sect() and satdisp_units().
(satmap): Call only satdisp_sect().  No functional change.
(aircombat): Call both, and call satdisp_units() even over sea.  This
lets spy planes spot surface ships at sea.  Closes #906035.
2006-06-14 17:38:16 +00:00
f900ac68cb (shp_sweep): New parameter takemob. Charge mobility only if it's
true.
(shp_nav_one_sector): Pass false.  This lets minesweepers move at the
speed their stats indicate.  Closes #1498801.
(navi): Pass true.  This ensures sweeping without moving still costs
mobility.
2006-06-11 18:09:09 +00:00