Factor ship_can_carry() out of could_be_on_ship()
This commit is contained in:
parent
5424142f62
commit
ae279968b9
1 changed files with 31 additions and 20 deletions
|
@ -30,7 +30,7 @@
|
||||||
* Dave Pare, 1986
|
* Dave Pare, 1986
|
||||||
* Ken Stevens, 1995
|
* Ken Stevens, 1995
|
||||||
* Steve McClure, 1998-2000
|
* Steve McClure, 1998-2000
|
||||||
* Markus Armbruster, 2004-2010
|
* Markus Armbruster, 2004-2012
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -814,29 +814,16 @@ pln_put1(struct plist *plp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Can PP be loaded on a ship of SP's type?
|
* Can a carrier of SP's type carry this load of planes?
|
||||||
* Assume that it already carries N planes, of which NCH are choppers,
|
* The load consists of N planes, of which NCH are choppers, NXL
|
||||||
* NXL xlight, NMSL light missiles, and the rest are light fixed-wing
|
* xlight, NMSL light missiles, and the rest are light fixed-wing
|
||||||
* planes.
|
* planes.
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
could_be_on_ship(struct plnstr *pp, struct shpstr *sp,
|
ship_can_carry(struct shpstr *sp, int n, int nch, int nxl, int nmsl)
|
||||||
int n, int nch, int nxl, int nmsl)
|
|
||||||
{
|
{
|
||||||
struct plchrstr *pcp = &plchr[pp->pln_type];
|
|
||||||
struct mchrstr *mcp = &mchr[sp->shp_type];
|
struct mchrstr *mcp = &mchr[sp->shp_type];
|
||||||
int nfw;
|
int nfw = n - nch - nxl - nmsl;
|
||||||
|
|
||||||
if (pcp->pl_flags & P_K)
|
|
||||||
nch++;
|
|
||||||
else if (pcp->pl_flags & P_E)
|
|
||||||
nxl++;
|
|
||||||
else if (!(pcp->pl_flags & P_L))
|
|
||||||
return 0;
|
|
||||||
else if (pcp->pl_flags & P_M)
|
|
||||||
nmsl++;
|
|
||||||
n++;
|
|
||||||
nfw = n - nch - nxl - nmsl;
|
|
||||||
|
|
||||||
if (nch > mcp->m_nchoppers) /* overflow into fixed-wing slots */
|
if (nch > mcp->m_nchoppers) /* overflow into fixed-wing slots */
|
||||||
nfw += nch - mcp->m_nchoppers;
|
nfw += nch - mcp->m_nchoppers;
|
||||||
|
@ -849,6 +836,30 @@ could_be_on_ship(struct plnstr *pp, struct shpstr *sp,
|
||||||
return nfw + nmsl <= mcp->m_nplanes;
|
return nfw + nmsl <= mcp->m_nplanes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Can PP be loaded on a ship of SP's type?
|
||||||
|
* Assume that it already carries N planes, of which NCH are choppers,
|
||||||
|
* NXL xlight, NMSL light missiles, and the rest are light fixed-wing
|
||||||
|
* planes.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
could_be_on_ship(struct plnstr *pp, struct shpstr *sp,
|
||||||
|
int n, int nch, int nxl, int nmsl)
|
||||||
|
{
|
||||||
|
struct plchrstr *pcp = &plchr[pp->pln_type];
|
||||||
|
|
||||||
|
if (pcp->pl_flags & P_K)
|
||||||
|
nch++;
|
||||||
|
else if (pcp->pl_flags & P_E)
|
||||||
|
nxl++;
|
||||||
|
else if (!(pcp->pl_flags & P_L))
|
||||||
|
return 0;
|
||||||
|
else if (pcp->pl_flags & P_M)
|
||||||
|
nmsl++;
|
||||||
|
|
||||||
|
return ship_can_carry(sp, n + 1, nch, nxl, nmsl);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fit a plane of PP's type on ship SP.
|
* Fit a plane of PP's type on ship SP.
|
||||||
* Updating the plane accordingly is the caller's job.
|
* Updating the plane accordingly is the caller's job.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue