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.
This commit is contained in:
parent
41b2fa433f
commit
d9a915a05b
4 changed files with 41 additions and 40 deletions
|
@ -504,7 +504,7 @@ extern void pln_prewrite(int, void *, void *);
|
||||||
extern int get_planes(struct nstr_item *, struct nstr_item *,
|
extern int get_planes(struct nstr_item *, struct nstr_item *,
|
||||||
char *, char *);
|
char *, char *);
|
||||||
extern struct sctstr *get_assembly_point(char *, struct sctstr *, char *);
|
extern struct sctstr *get_assembly_point(char *, struct sctstr *, char *);
|
||||||
extern int pln_onewaymission(struct sctstr *, int *, int *);
|
extern int pln_where_to_land(coord, coord, union empobj_storage *, int *);
|
||||||
extern int pln_oneway_to_carrier_ok(struct emp_qelem *,
|
extern int pln_oneway_to_carrier_ok(struct emp_qelem *,
|
||||||
struct emp_qelem *, int);
|
struct emp_qelem *, int);
|
||||||
extern void pln_newlanding(struct emp_qelem *, coord, coord, int);
|
extern void pln_newlanding(struct emp_qelem *, coord, coord, int);
|
||||||
|
|
|
@ -29,12 +29,13 @@
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Dave Pare, 1986
|
* Dave Pare, 1986
|
||||||
* Steve McClure, 2000
|
* Steve McClure, 2000
|
||||||
* Markus Armbruster, 2004-2011
|
* Markus Armbruster, 2004-2012
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
#include "empobj.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "plane.h"
|
#include "plane.h"
|
||||||
|
@ -50,7 +51,7 @@ fly(void)
|
||||||
int cno;
|
int cno;
|
||||||
struct nstr_item ni_bomb;
|
struct nstr_item ni_bomb;
|
||||||
struct nstr_item ni_esc;
|
struct nstr_item ni_esc;
|
||||||
struct sctstr target;
|
union empobj_storage target;
|
||||||
struct emp_qelem bomb_list;
|
struct emp_qelem bomb_list;
|
||||||
struct emp_qelem esc_list;
|
struct emp_qelem esc_list;
|
||||||
int wantflags;
|
int wantflags;
|
||||||
|
@ -74,14 +75,14 @@ fly(void)
|
||||||
ip = whatitem(player->argp[5], "transport what? ");
|
ip = whatitem(player->argp[5], "transport what? ");
|
||||||
if (player->aborted)
|
if (player->aborted)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
getsect(tx, ty, &target);
|
|
||||||
|
|
||||||
cno = -1;
|
if (pln_where_to_land(tx, ty, &target, &wantflags) < 0)
|
||||||
if (pln_onewaymission(&target, &cno, &wantflags) < 0)
|
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
|
cno = target.gen.ef_type == EF_SHIP ? target.gen.uid : -1;
|
||||||
|
|
||||||
if (ip && ip->i_uid == I_CIVIL
|
if (ip && ip->i_uid == I_CIVIL
|
||||||
&& cno < 0 && target.sct_own != target.sct_oldown) {
|
&& target.gen.ef_type == EF_SECTOR
|
||||||
|
&& target.sect.sct_own != target.sect.sct_oldown) {
|
||||||
pr("Can't fly civilians into occupied sectors.\n");
|
pr("Can't fly civilians into occupied sectors.\n");
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,13 @@
|
||||||
*
|
*
|
||||||
* Known contributors to this file:
|
* Known contributors to this file:
|
||||||
* Dave Pare, 1986
|
* Dave Pare, 1986
|
||||||
* Markus Armbruster, 2004-2011
|
* Markus Armbruster, 2004-2012
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
#include "empobj.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "plane.h"
|
#include "plane.h"
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ reco(void)
|
||||||
int cno;
|
int cno;
|
||||||
struct nstr_item ni_bomb;
|
struct nstr_item ni_bomb;
|
||||||
struct nstr_item ni_esc;
|
struct nstr_item ni_esc;
|
||||||
struct sctstr target;
|
union empobj_storage target;
|
||||||
struct emp_qelem bomb_list;
|
struct emp_qelem bomb_list;
|
||||||
struct emp_qelem esc_list;
|
struct emp_qelem esc_list;
|
||||||
int wantflags;
|
int wantflags;
|
||||||
|
@ -69,10 +70,11 @@ reco(void)
|
||||||
ty = ay;
|
ty = ay;
|
||||||
(void)pathtoxy(flightpath, &tx, &ty, fcost);
|
(void)pathtoxy(flightpath, &tx, &ty, fcost);
|
||||||
pr("target is %s\n", xyas(tx, ty, player->cnum));
|
pr("target is %s\n", xyas(tx, ty, player->cnum));
|
||||||
getsect(tx, ty, &target);
|
|
||||||
cno = -1;
|
if (pln_where_to_land(tx, ty, &target, &wantflags) < 0)
|
||||||
if (pln_onewaymission(&target, &cno, &wantflags) < 0)
|
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
|
cno = target.gen.ef_type == EF_SHIP ? target.gen.uid : -1;
|
||||||
|
|
||||||
ap_to_target = strlen(flightpath);
|
ap_to_target = strlen(flightpath);
|
||||||
if (flightpath[ap_to_target - 1] == 'h')
|
if (flightpath[ap_to_target - 1] == 'h')
|
||||||
ap_to_target--;
|
ap_to_target--;
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
|
#include "empobj.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "land.h"
|
#include "land.h"
|
||||||
|
@ -116,20 +117,25 @@ get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find out whether planes can fly one-way to X,Y.
|
||||||
|
* Offer the player any carriers there. If he chooses one, read it
|
||||||
|
* into TARGET->ship. Else read the target sector into TARGET->sect.
|
||||||
|
* If planes can land there, set required plane flags in *FLAGSP, and
|
||||||
|
* return 0. Else return -1.
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
|
pln_where_to_land(coord x, coord y,
|
||||||
|
union empobj_storage *target, int *flagsp)
|
||||||
{
|
{
|
||||||
int nships;
|
int nships;
|
||||||
int cno;
|
int cno;
|
||||||
int flags, fl;
|
int fl;
|
||||||
struct shpstr ship;
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
flags = *flagp;
|
|
||||||
|
|
||||||
/* offer carriers */
|
/* offer carriers */
|
||||||
nships = carriersatxy(target->sct_x, target->sct_y, player->cnum);
|
nships = carriersatxy(x, y, player->cnum);
|
||||||
if (nships) {
|
if (nships) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
p = getstring("Carrier #? ", buf);
|
p = getstring("Carrier #? ", buf);
|
||||||
|
@ -138,50 +144,42 @@ pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
|
||||||
if (!*p)
|
if (!*p)
|
||||||
break;
|
break;
|
||||||
cno = atoi(p);
|
cno = atoi(p);
|
||||||
if (cno < 0
|
if (!getship(cno, &target->ship)
|
||||||
|| !getship(cno, &ship)
|
|
||||||
|| (!player->owner
|
|| (!player->owner
|
||||||
&& (relations_with(ship.shp_own, player->cnum)
|
&& (relations_with(target->ship.shp_own, player->cnum)
|
||||||
!= ALLIED))) {
|
!= ALLIED))) {
|
||||||
pr("Not yours\n");
|
pr("Not yours\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
|
if (target->ship.shp_x != x || target->ship.shp_y != y) {
|
||||||
pr("Ship #%d not in %s\n", cno,
|
pr("Ship #%d not in %s\n", cno, xyas(x, y, player->cnum));
|
||||||
xyas(target->sct_x, target->sct_y, player->cnum));
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
fl = carrier_planes(&ship, 0);
|
fl = carrier_planes(&target->ship, 0);
|
||||||
if (fl == 0) {
|
if (fl == 0) {
|
||||||
pr("Can't land on %s.\n", prship(&ship));
|
pr("Can't land on %s.\n", prship(&target->ship));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* clear to land on ship#CNO */
|
/* clear to land on ship#CNO */
|
||||||
pr("landing on carrier %d\n", cno);
|
pr("landing on carrier %d\n", cno);
|
||||||
flags |= fl;
|
*flagsp |= fl;
|
||||||
*shipno = cno;
|
|
||||||
*flagp = flags;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* try to land at sector */
|
/* try to land at sector */
|
||||||
if (relations_with(target->sct_own, player->cnum) != ALLIED) {
|
getsect(x, y, &target->sect);
|
||||||
pr("Nowhere to land at sector %s!\n",
|
if (relations_with(target->sect.sct_own, player->cnum) != ALLIED) {
|
||||||
xyas(target->sct_x, target->sct_y, player->cnum));
|
pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (target->sct_type == SCT_MOUNT) {
|
if (target->sect.sct_type == SCT_MOUNT) {
|
||||||
pr("Nowhere to land at sector %s!\n",
|
pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
|
||||||
xyas(target->sct_x, target->sct_y, player->cnum));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
|
|
||||||
flags |= P_V;
|
|
||||||
|
|
||||||
/* clear to land at sector */
|
/* clear to land at sector */
|
||||||
*shipno = -1;
|
if (target->sect.sct_type != SCT_AIRPT || target->sect.sct_effic < 60)
|
||||||
*flagp = flags;
|
*flagsp |= P_V;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue