Commit graph

218 commits

Author SHA1 Message Date
fa5fa4abcc Don't store RAILWAYS track in sectors
Storing track in sectors is problematic, because we need to update
adjacent sectors when updating a sector in a way that changes its
capability to extend railway into its neighbors.  This invalidates
cached adjacent sectors, and calling code may not be prepared for
that.  Specifically, bridge building caches the bridge head, and
writes it back later, wiping out the track update.

Replace struct sctstr member sct_track by new sct_rail_track().  Make
selector track virtual.  Remove the code to keep sct_track up-to-date:
set_railway(), update_railway().

Unfortunately, this causes cyclic dependencies between link libraries:
the virtual selector needs to be referenced from src/lib/global/nsc.c,
and it needs to reference stuff from src/lib/common/file.c.  Hack
around it in Make.mk for now.
2008-05-07 10:33:41 +02:00
Markus Armbruster
5d0f5e69ee Rebase of Hvy Metal I final version
Straightforward forward port.  Drop the code to reset track on
startup.  It's not necessary, and it breaks linking of empdump.
2008-05-07 10:33:41 +02:00
6709931d51 Give try_supply_commod() internal linkage 2008-04-22 21:56:35 +02:00
15fab1c9a5 Fix launch to require petrol for launching satellites
launch_sat() failed to call msl_equip().  Change msl_equip() to take
the mission character as argument, because the old hardcoded 'p' isn't
appropriate for satellites.  Best fit for satellites is 'r' for
reconnaissance, but mission_pln_equip() doesn't accept that
(pln_equip() does).  Fix that as well.
2008-03-26 22:13:00 +01:00
7ca4f412b1 Fix tracking of planes flying a sortie
Planes normally sit in their base (sector or carrier), where they can
be spied, damaged, captured, loaded, unloaded, upgraded and so forth.
All this must not be possible while they fly.  There are two kinds of
flying planes: satellites in orbit, and planes flying a sortie.

Satellites in orbit have always been marked with flag PLN_LAUNCHED.
Works.  What didn't work was tracking planes flying a sortie.

If you look at one sortie in isolation, up to three groups of planes
can be flying at any point of time: the primary group, which carries
out the sortie's mission (bomb, transport, ...), their escorts, and a
group of hostile planes flying interception or air defense.

The old code attempted to track these planes by passing those groups
to the places that need to know whether a plane is flying.  This was
complex and incomplete, and broke down completely for the pin-bombing
command.

It was complex, because the plane code needs to keep track of all the
call chains that can lead to a place that needs to know whether a
plane flies, and pass the groups down the call chains.  This leads to
a rather ugly passing of plane groups all over the place.

It was incomplete, because it generally failed to pass the escorts.

And the whole scheme broke down for the pin-bombing command.  That's
because pin-bombing asks the player for targets while his planes are
loitering above the target sector.  This yields the processor and lets
other code run.  Which does not get the flying planes passed.

The new code marks planes and SAMs (but not other missiles) flying a
sortie with flag PLN_LAUNCHED (the previous commit laid the groundwork
for that), and does away with passing around groups of flying planes.

This fixes the following bugs:

* Many commands could interact with foreign planes flying for a
  pin-bombing command as if they were sitting in their base.  This
  includes spying, damaging, capturing, loading, or upgrading them,
  and even getting intercepted by them.  Any changes to those planes
  were wiped out when they landed.  Abusable.

* The bomb command could bomb its own escorts, directly (pin-bomb
  planes) or through collateral damage, strategic sector damage,
  collapsing bridges or nuke damage.  The damage to the escorts was
  wiped out when they landed.

* If you asked for a plane to fly both in the primary group and the
  escort group, you got charged fuel for two sorties instead of one.

* pln_put1() and pln_put() now recognize planes that didn't take off,
  and refrain from making them land.  Intercept (since commit
  c64e2149) and air defense can do that.  Making them land had no
  ill-effects, but it was still wrong.

There's one new problem: if PLN_LAUNCHED doesn't get reset properly,
due to game crash during flight or some other bug, the plane gets
stuck in the air.  Catch and fix that on game start in ef_verify().
2008-03-26 22:10:13 +01:00
8006543878 Distinguish between planes "in orbit" and "launched"
Use new pln_is_in_orbit() when we want to test for orbit specifically,
and test PLN_LAUNCHED when we want to test whether the plane not
sitting in the sector (because it is flying).  This distinction is
pointless at this time, because the only way PLN_LAUNCHED gets set is
when a satellite goes into orbit.  It will become useful in a later
commit, which will use PLN_LAUNCHED to mark flying planes.
2008-03-26 22:09:09 +01:00
5e930f5fdf Factor out a single plane's end of sortie into new pln_put1()
Use it in pln_put() and ac_planedamage().

This changes ac_planedamage() to deal with a destroyed airbase.
Before, aborted planes happily landed there.  This bug could not
actually bite, because the code neither yields nor does damage to
potential airbases between checking the landing airbase before takeoff
and aborting planes in ac_planedamage().

It changes pln_put() to cope with dead planes.  Before, it made them
land as if they lived, fortunately without ill effects (complaints
about not being able to land were suppressed for dead planes).
ac_planedamage() removes dead planes, but pinflak_planedamage()
doesn't, and these end up in pln_put().  pinflak_planedamage() no
longer has to take shot down planes off their carriers, because
pln_put() now takes care of that.
2008-03-26 22:09:09 +01:00
06a0036c63 Replace some typedef names by enum tags.
Also get rid of some mildly silly manual packing of enum types.
2008-03-14 20:25:42 +01:00
4c746b5e73 Make xdump code available for future use outside the server
Move the bits useful there from src/lib/commands/xdump.c to new
include/xdump.h and src/lib/common/xdump.c.
2008-03-14 20:25:42 +01:00
ffab089c61 Give effrange() internal linkage. 2008-03-14 20:25:39 +01:00
055c80a41f use_supply() is now unused, remove 2008-03-14 20:25:38 +01:00
f6c87d21ff Factor out common land unit fire code into lnd_fire()
This takes care of a number of bugs / inconsistencies:

* Resupply before fire: fire command did not require unit to be in
  supply, and resupplied shells.  Everywhere else (return fire,
  support and interdiction) the land unit had to be in supply after
  resupply of everything.  Unify not to resupply anything and not to
  require being in supply.  This is consistent with ships and sectors.

* Resupply after fire: fire command resupplied shells after active
  fire.  Unify not to do that.  This is consistent with ships and
  sectors.

* When a land unit returned fire to multiple attackers, quiet_bigdef()
  charged it ammo for each one.  Finally, it was charged one shell
  more by use_ammo().  Except only the first land unit got charged
  there in fact, because buggy add_to_fired_queue() entered only the
  first land unit into the defender list.  Fix add_to_fired_queue()
  and change quiet_bigdef() not to charge ammo, just like for ships
  and sectors.  This charges only one shell instead of the true ammo
  use, which is wrong, but consistent with ships.

* lnd_support() tallied support damage unrounded.  Unify to round
  before tally.
2008-03-14 20:25:38 +01:00
e8595066d1 Factor out common fortress fire code into fort_fire()
This takes care of a number of bugs / inconsistencies:

* sb() fired support even when there were not enough mil.

* Shell resupply bugs: multifire() and quiet_bigdef() resupplied
  shells before checking all other requirements and could thus get
  more shells than actually needed.

Rename landgun() to fortgun() for consistency.
2008-03-14 20:25:37 +01:00
61d632fc96 Give logx() internal linkage 2008-03-14 20:25:10 +01:00
6b89127d5b shp_init(), lnd_init(), pln_init(), nuk_init() are now empty, remove 2008-03-05 22:48:24 +01:00
dd2d2d361a Give unit_map() internal linkage 2008-02-26 21:07:58 +01:00
44f6656e2f Remove unused check_cost() 2008-02-17 08:47:51 +01:00
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