Commit graph

163 commits

Author SHA1 Message Date
549561ff03 Include "file.h" where it's needed
Several headers define macros that use ef_ptr() without including
"file.h".  Fix that.  Drop redundant inclusions elsewhere.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 20:08:31 +02:00
e8b0e14d3d plnsub: Let crewless planes spread the plague, too
Commit 612ec62 (v4.3.31) made plane crew and cargo spread the plague.
This requires looking for crew in build materials.  Awkward if we ever
permit non-military crew.

Simply drop the "has crew" condition.  If a plane's cargo can spread
it, then servicing and refueling the plane can spread it, too.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 19:59:56 +02:00
da05484d8b config: Generalize unit build materials storage
Use a single array member instead of multiple scalar members.  Only
the array elements that replace scalar members are can be non-zero for
now.

This is a first step to permitting more build materials.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 14:05:11 +02:00
6157b6cbe4 plnsub: Make takeoff/landing in mountains consistent
One-way sorties (fly, recon and sweep) reject mountain destinations
with a "Nowhere to land" message.  However, planes can land there just
fine when they return to base (bomb, drop, paradrop, missions).
Already inconsistent in BSD Empire 1.1.

Fix the inconsistency by changing pln_where_to_land() to permit only
helicopters to land in mountains, and pln_airbase_ok() to permit only
helicopters and missiles to take off there, i.e. reject fixed-wing
aircraft.

The flying commands now reject fixed-wing planes based in mountains
with an "is in a mountain and can't take off" message.

Commands flying to a mountain now select only helicopters and silently
ignore the rest, exactly like they select only VTOL planes for flying
to a non-airfield.  If no planes can be selected, the command fails
with a "No planes could be equipped" message.  This is admittedly less
clear than the "Nowhere to land" message we got before.

Missions now ignore fixed-wing planes based in mountains, exactly like
they ignore non-VTOL planes outside airfields.  This may make players
wonder why the fixed-wing VTOL planes they transported up that
mountain don't obey missions.  Missions are always quiet unless they
execute.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 14:03:21 +02:00
3f2f201ddb plnsub: Add missing newline to two messages
The two "while it is carrying a nuclear weapon" messages lack
newlines.  Add them.  Screwed up in commit a269cdd, v4.3.23.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-08-06 14:03:09 +02:00
bae3f5447e Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2017-07-02 17:45:44 +02:00
eba87789ab Fix and clean up some comments
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-12-05 12:31:08 +01:00
9f25de3dce Change comment style to use @foo rather than FOO
... when referring to a function's parameter or a struct/union's
member.

The idea of using FOO comes from the GNU coding standards:

    The comment on a function is much clearer if you use the argument
    names to speak about the argument values.  The variable name
    itself should be lower case, but write it in upper case when you
    are speaking about the value rather than the variable itself.
    Thus, "the inode number NODE_NUM" rather than "an inode".

Upcasing names is problematic for a case-sensitive language like C,
because it can create ambiguity.  Moreover, it's too much shouting for
my taste.

GTK-Doc's convention to prefix the identifier with @ makes references
to variables stand out nicely.  The rest of the GTK-Doc conventions
make no sense for us, however.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-12-05 12:13:17 +01:00
820d755e59 subs: Change pln_damage()'s parameter noisy to string prefix
No functional change for now.  The next commit will put it to use.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-03-02 08:20:50 +01:00
b14f5276ab Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2015-02-28 16:21:34 +01:00
bb467c335d Update copyright notice
Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
2014-01-02 14:33:48 +01:00
8eb78a5a80 Move declarations for chance.c to new chance.h 2013-05-08 06:55:20 +02:00
df4925d696 Update copyright notice 2013-01-12 17:45:01 +01:00
612ec6257d Pilots and air cargo now spread the plague
Planes flying one-way with crew or cargo spread plague from their old
base to their new base.  Planes dropping cargo spread plague from
their base to the drop's target sector.
2012-07-13 20:15:33 +02:00
b4acb73fd1 Replace pln_oneway_to_carrier_ok() by pln_can_land_on_carrier()
Avoids reading the target ship again.
2012-07-13 20:15:33 +02:00
d9a915a05b Replace pln_onewaymission() by pln_where_to_land()
New function reads and returns target sector/ship.  Avoids reading the
target sector unnecessarily.  Callers receive the target ship, not
just its number.  Next commit will put it to use.
2012-07-13 20:14:10 +02:00
72f1e22b95 Drop could_be_on_ship()'s load count parameters
Just one caller wants them.  Inline that call, and simplify the
others.
2012-07-12 19:52:33 +02:00
665d0d723d Inline fit_plane_on_ship() and fit_plane_on_land()
Just one call site each.
2012-07-12 19:52:33 +02:00
b60e5be22c Don't let planes fly to a carrier without sufficient space
We test whether the the carrier has space for each plane individually
instead of whether it has space for all of them.  The planes that fit
land, the others abort and get teleported home.  Abusable.

pln_oneway_to_carrier_ok() was created in commit 1127762c (v4.2.17) to
fix almost the same bug.  It worked fine then, because
fit_plane_on_ship() worked with load counters, and incremented them.

Broken in commit 3e370da5 (v4.3.17), which made fit_plane_on_ship()
count the loaded planes, to permit the removal of load counters.  But
unlike load counters, loaded planes don't change during
pln_oneway_to_carrier_ok().  Thus, each plane is checked individually.

Fix by tallying all the planes before checking for space.
2012-07-12 19:51:57 +02:00
81efebd367 Factor inc_shp_nplane() out of could_be_on_ship() 2012-06-24 08:49:57 +02:00
ae279968b9 Factor ship_can_carry() out of could_be_on_ship() 2012-06-24 08:49:57 +02:00
1118f1c0ca Update copyright notice 2012-06-10 10:52:22 +02:00
786e2a99d5 Clean up superfluous includes 2012-04-26 19:57:19 +02:00
90a263d5ef drop and fly from carrier can fail to load last civ or mil
pln_equip() refuses to abandon its base sector.  Unfortunately, it
checks even when flying off carriers, and refuses to load the last
civilian or military depending on what happens to be in uninitialized
variable sect.

Broken in commit 91139692, v4.3.0.
2011-12-29 11:47:07 +01:00
617cb41f66 Don't let POGO (#0) navigate and march ghosts
POGO can navigate dead ships, and march dead land units.  The ghosts
even get sighted and interdicted, and can hit mines (landmines only
until commit fe372539, v4.3.27).  Noted for ships in commit 9100af0b.
Has always been broken.  Fix by making shp_sel() and lnd_sel()
explicitly reject ghosts.

Same code pattern also exists in pln_sel, but dead plains fail the
efficiency test, so it's harmless there.  Apply the same fix anyway.
2011-07-16 13:47:48 +02:00
98cd2a3a70 Update known contributors comments 2011-04-14 20:21:23 +02:00
7e2008e7f4 License upgrade to GPL version 3 or later
Why upgrade?  I'm not a lawyer, but here's my take on the differences
to version 2:

* Software patents: better protection against abuse of patents to
  prevent users from exercising the rights under the GPL.  I doubt
  we'll get hit with a patent suit, but it's a good move just on
  general principles.

* License compatibility: compatible with more free licenses, i.e. can
  "steal" more free software for use in Empire.  I don't expect to steal
  much, but it's nice to have the option.

* Definition of "source code": modernization of some details for today's
  networked world, to make it easier to distribute the software.  Not
  really relevant to us now, as we normally distribute full source code.

* Tivoization: this is about putting GPL-licensed software in hardware,
  then make the hardware refuse to run modified software.  "Neat" trick
  to effectively deny its users their rights under the GPL.  Abuse was
  "pioneered" by TiVo (popular digital video recorders).  GPLv3 forbids
  it.  Unlikely to become a problem for us.

* Internationalization: more careful wording, to harden the license
  outside the US.  The lawyers tell us it better be done that way.

* License violations: friendlier way to deal with license violations.
  This has come out of past experience enforcing the GPL.

* Additional permissions: Probably not relevant to us.

Also include myself in the list of principal authors.
2011-04-12 21:20:58 +02:00
8cb7b75557 Use relations_with() for getrel(getnatp(US), THEM) where US!=THEM
Replacing getrel(getnatp(US), THEM) by relations_with(US, THEM) makes
a difference only when US equals THEM.  Replace in places where it's
obvious that they're not equal.

Note: getsect() sets player->owner to "player is god or owns this
sector".  Thus, after getsect(..., &sect), sect.sct_own ==
player->cnum implies player->owner.  Conversely, !player->owner
implies sect.sct_own != player->cnum.  Similarly for getship(),
getplane() and nxtitem().
2011-02-16 07:52:25 +01:00
Markus Armbruster
8e75b22e0d Use relations_with() for US==THEM || getrel(getnatp(US), THEM)
Replacing getrel(getnatp(US), THEM) by relations_with(US, THEM) makes
a difference only when US equals THEM.

Replace patterns like "us == them || getrel(getnatp(us), them)..." by
"relations_with(us, them)...".
2011-02-16 07:51:39 +01:00
efd3940322 Clean up unobvious coordinate system use in pln_airbase_ok()
Use the obviously correct player->cnum instead of pp->pln_own.
They're actually equal here.
2010-07-25 17:48:53 +02:00
9e6b5a9133 Don't let deities fly foreign planes
Much code assumes that only the plane's owner can fly it.
pln_airbase_ok() oopses since commit 446f1991.  Before, flying planes
from carriers failed with a bogus "not valid for" message, and flying
from sectors had output misdirected to the plane's owner.

It would be nice to let deities fly foreign planes, but the assumption
is not trivial to remove, so just satisfy it for now.

Historical note: it looks like deities used to be able to fly foreign
planes just fine until Chainsaw 3 added missions.  The launch command
has always rejected foreign planes, even for deities.
2010-07-11 07:59:43 +02:00
e002bf207f Clean up misuse of mpr() in pln_damage()
Don't use multiple calls of mpr() to print a single line, because that
creates a separate bulletin for each part.  The read command normally
merges the bulletins, but if the bulletins are more than five seconds
apart (clock jumped somehow), we get a bulletin header in the middle
of a line.

While there, wrap long "blam" lines.  Can only happen for bomb loads
above 16.  Stock game needs a tech 406 jhb for that.

The mpr() misuse was introduced in Empire 2.
2010-07-11 07:59:34 +02:00
4773519c3c Fix sweep command to use correct coordinate system
When reporting sweeps, it reported the location in the plane owner's
coordinate system instead of the player's.  Fortunately, they're the
same in normal usage.  They can differ only when a deity flies foreign
planes.
2010-06-21 21:01:30 +02:00
162158fd4a Fix loading x-light missiles on ships without capability plane
These ships could only use their x-light slots for x-light planes, not
their plane slots.  For instance, agc (30 x-light slots, 32 plane
slots) could load only 30 sams, and mb (0 x-light slots, 10 plane
slots) could not load any sams.

Culprit is could_be_on_ship().  Broken in commit 3e370da5, v4.3.17.
2010-05-09 09:08:04 +02:00
6de86720b2 Fix fly and drop to report discarded cargo items correctly
When d of n cargo items are discarded for want of space, pln_dropoff()
reported -d items discarded and -d items unloaded.  Already broken in
BSD Empire 1.1.
2010-05-09 09:08:03 +02:00
876f3424b0 Nuclear-tipped missile exploding on launch could not damage base
Commit a269cdd7 (v4.3.23) removed the nuclear damage.  But it left the
nuke on the missile, which made pln_damage() oops and return zero
damage.

Fix by destroying the nuke separately.
2010-03-16 21:28:08 +01:00
9b62b35424 Fix oops on escort, recon, and launch of satellite
Broken in commit 528df9ac, v4.3.23.  pln_equip() recovered fine.
2010-01-19 08:40:17 +01:00
73e25ff21e Update copyright notice 2010-01-19 08:40:17 +01:00
a269cdd7e9 Limit nukes to strategic missions
Before Empire 2, nukes could be delivered only with bomb (special
mission 'n', airburst only) and launch (targeting sectors or
satellites only).

Empire 2 made nukes available for any kind of bombing, and for any
missile strike on sectors or ships.  This included interdiction and
support missions.  Nuclear-tipped anti-sats and bomb mission n were
removed.

Unfortunately, this was done in a messy way, which led to
inconsistencies and bugs.  The problem is that ordinary damage affects
just the target, while nuke damage affects an area.  Code dealing with
plane damage was designed for the former.  Instead of rewriting it to
cope with area damage cleanly, nuke damage got shoehorned into
pln_damage(), the function to compute conventional plane damage, as a
side effect: computing damage blasted sectors in the area.

If the plane carried a nuke, pln_damage() returned zero (conventional)
damage.  Without further logic, this simply bypassed the code to apply
damage to the target.  This worked out okay when the target already
got damaged correctly by the side effect.

However, some targets are immune to the side effect: when interdicting
a move or explore command, the commodities being moved are not in any
sector.

For other targets, damage has effects other than damaging the target:
offensive and defensive support don't apply the (conventional) damage
to the target sector.  Instead, they turn it into a combat bonus.
Without further logic, nuclear damage doesn't contribute to that.

To make all that work, pln_damage() returned the nuclear damage for
ground zero as well.  Because a plane does either conventional or
nuclear damage, one of them is always zero.

Most callers simply ignored the nuclear damage, and applied only the
conventional damage.

Bug: land units and ships failed to retreat when pin-bombed or
missiled with a nuke.  That's because they received zero conventional
damage.

The mission code flies planes and missiles and tallies their damage.
This mission damage included nuclear damage at ground zero (except for
missiles sometimes, see below), to make support and commodity
interdiction work.  Unfortunately, this broke other things.

Bug: when bombers interdicted ships or land units, nukes first damaged
the ships or land units by the side effect, then again through mission
damage.  Interdicting missiles had a special case to avoid this.

Bug: when interdicting move, explore or transport, nukes first damaged
the sector by the side effect, then again through mission damage's
collateral damage.

There may well be more bugs hiding in this mess.

The mess is not worth fixing.  While the idea of interdicting and
supporting with nukes sounds kind of cool, I believe it's pretty
irrelevant in actual play.

Instead, go back to a variation of the original rules: nukes can be
delivered only through bomb mission 's' and launch at sectors.

Make arm reject marine missiles in addition to satellites, ABMs and
SAMs, and clear the mission.  Make mission reject planes armed with
nukes.  Oops when they show up in mission_pln_equip() anyway.

Make pln_equip() allow planes with nukes only for missions 's' and
't'.

Clean up pln_damage() to just compute damage, without side effect.
Change strat_bomb() and launch_missile() to detonate nukes.  Simplify
the other callers.  Parameter mission of msl_launch_mindam() is now
unused, remove it.

Missiles exploding on launch no longer set off their nukes.  That was
pretty ridiculous anyway.
2009-12-13 07:46:00 +01:00
528df9acba Improve launch diagnostic messages, switch off supply
msl_equip() used mission_pln_equip(), which is for automatic defenses,
and therefore silent.  Its users launch_as(), launch_missile() and
launch_sat() printed failure diagnostics based on assumptions on what
could go wrong.

Switch to the appropriate function for commands, pln_equip(), and
remove the guesswork.  Implement mission 'i' there.  When launching
from a foreign base, its owner now gets informed.  Unimportant at this
time, as players can't easily deploy missiles in foreign bases.

This change also switches off automatic supply for launch.  Consistent
with bomb.
2009-12-12 16:28:52 +01:00
54b1c04686 Simplify how plane cargo is tracked
Fold struct plist members bombs (used for bombing runs) and misc (used
for everything else) into a single member load.
2009-12-12 16:28:52 +01:00
7b7fe69c46 Revise rules for cargo plane loads
There are three ways to fly cargo: transport (fly command with a
commodity argument), cargo drops (drop command that isn't a sea mine
drop), and paradrops.

A cargo flight can be either an airlift or an airdrop.  Airlifts carry
more cargo than airdrops.  A cargo drop or paradrop with a non-VTOL
plane is an airdrop.  Anything else is an airlift.

Before, paradrop always behaved like an airdrop, regardless of VTOL,
and drop always like an airlift.  This made little sense.

Effect of the change on the stock game: paradrop with tc carries twice
the punch, and np/tr/jt can drop less than they can fly.  In
particular, tr can't drop guns anymore, and jt can drop only one
instead of three.
2009-12-08 08:15:51 +01:00
b2107e5301 Simplify load computation in pln_equip(), mission_pln_equip() 2009-12-08 08:15:51 +01:00
fd4da5aab3 Make bomb require capability bomber or tactical
Before, bomb selected any plane, but planes with zero load could not
be equipped.  Cargo planes could be equipped fine, and they flew bombs
to the target, where they silently vanished.

Closes#1388263.
2009-12-08 08:15:51 +01:00
df1ca95a2a Clean up outmoded tests for paradrop capability
Initially, paradrop capability was implied both by capability cargo
and by capability VTOL.  Chainsaw changed para() to require cargo, and
added compile-time option PARAFLAG to additionally require new
capability para.  The optional PARAFLAG rule became mandatory in
Empire 2.

Chainsaw left the old tests for "cargo or VTOL" in place.  Because
para() checked "cargo and para" first, the old tests for "cargo or
VTOL" always passed, so they had no effect.

Clean them up anyway.
2009-12-08 08:15:51 +01:00
062a42fb7b Make passing paradrop & mine cargo to pln_arm() & friends optional
These missions imply the cargo type, just like bombing missions.  Use
the implied type instead of cargo type parameter ip there.  Parameter
ip is now optional except for missions 't' (transport) and 'd' (drop).

Simplify para() not to pass the optional cargo type.  Leave drop()
alone, because always passing the type is simpler there.
2009-12-08 08:15:51 +01:00
0fe43096bc Simplify calling of pln_arm() & friends
pln_arm(), pln_equip(), mission_pln_arm() mission_pln_equip() took a
mission parameter encoding the kind of sortie (strategic bomb,
pinpoint bomb, transport, ...), a flag parameter to further specify
the plane's role, and a parameter ip to specify the load.

The flags argument was always either P_F (intercept), P_F | P_ESC
(escort), or zero (any other role).

With non-zero flags, mission and ip argument were not used in any way.

Use mission 'e' and null load for escorts, and remove flags.
Intercept can still be identified by mission zero.

Also change pln_mobcost() to take a mission parameter instead of
flags, so that pln_arm() and mission_pln_arm() can simply pass on
their mission.
2009-12-08 08:15:51 +01:00
b1dd82fa61 Fix pln_equip()'s check for foreign civilians
Check the true load instead of the ip parameter.  Makes a difference
only when callers pass a bogus ip that isn't actually used.  Happens
for escorts, but then the call can only be reached for deities,
because for mortals the transports fail before the escorts.
2009-12-08 08:15:50 +01:00
3722bafaf7 Fix confusion of landmines with seamines
Seamines and landmines share storage.  Sea and bridge span sectors can
hold only sea mines, other sector types only landmines.  Sector type
checks were missing or incorrect in several places:

* Seamines under bridge spans were mistaken for landmines in several
  places:

  - ground combat mine defense bonus, in get_mine_dsupport() and
    stre(),

  - land units retreating from bombs, in retreat_land1(),

  - non-land unit ground movement (commands explore, move, transport,
    and INTERDICT_ATT of military), in check_lmines(),

  Fix them to check the sector type with new SCT_MINES_ARE_SEAMINES(),
  SCT_LANDMINES().

* plane_sweep() mistook landmines for seamines in harbors.  Bug could
  not bite, because it's only called for sea sectors.  Drop the bogus
  check for harbor.

* Collapsing a bridge tower magically converted landmines into
  seamines.  Make knockdown() clear landmines.

Also use SCT_MINES_ARE_SEAMINES() and SCT_LANDMINES() in mine(),
landmine(), lnd_sweep() and lnd_check_mines().  No functional change
there.

Keep checking only for sea in pln_mine(), plane_sweep(),
retreat_ship1(), shp_sweep() and shp_check_one_mines().  This means
seamines continue not to work under bridges.  Making them work there
is tempting, but as long as finding seamines clobbers the sector
designation in the bmap, it's better to have them in sea sectors only.

Historical notes:

Mines started out simple enough: you could mine sea and bridge spans,
and ships hit and swept mines in foreign sectors.

Chainsaw 2 introduced aerial mining and sweeping.  Unlike ships,
planes could not mine bridge spans.  plane_sweep() could sweep
harbors, which was wrong, but it was never called there, so the bug
could not bite.

Chainsaw 3 introduced landmines.  The idea was to permit only seamines
in some sector types, and only landmines in the others, so they can
share storage.  To figure out whether a sector has a particular kind
of mines, you need to check the sector type.  Such checks already
existed in mine, drop and sweep, and they were kept unchanged.  The
new lmine command also got the check.  Everything else did not.
Ground movement and combat could hit and sweep seamines in bridge
spans.  Ships could hit and sweep landmines in harbors.

Empire 2 fixed land unit movement (march, INTERDICT_ATT) not to
mistake seamines for landmines on bridge spans.  It fixed ships not to
mistake landmines for seamines.  The fix also neutered seamines under
bridge spans: ships could neither hit nor sweep them anymore.  Both
fixes missed retreat.

Commit 5663713b (v4.3.1) made ship retreat consistent with other ship
movement.
2009-03-31 22:52:03 +02:00
6ae4eca045 Don't use 0 as null pointer constant, part 3
This part replaces E == 0 by !E, where E has pointer type.
2009-03-24 21:46:01 +01:00