extern struct plchrstr plchr[];
extern int pln_maxno;
-struct shiplook {
+struct shiplist {
short uid;
- u_char looked;
- u_char found;
- struct shiplook *next;
+ struct shiplist *next;
};
#define PLN_ATTDEF(b, t) (b + ((b?1:0) * ((t/20)>10?10:(t/20))))
extern int can_fly(int);
/* src/lib/subs/aswplnsubs.c */
-extern int have_looked(u_char, struct shiplook *);
-extern int have_found(u_char, struct shiplook *);
-extern void set_have_looked(u_char, struct shiplook *);
-extern void set_have_found(u_char, struct shiplook *);
-extern int print_found(struct shiplook *);
+extern int on_shiplist(short, struct shiplist *);
+extern void add_shiplist(short, struct shiplist **);
+extern void free_shiplist(struct shiplist **);
+extern void print_shiplist(struct shiplist *);
#endif /* _PLANE_H_ */
extern void resnoise(struct sctstr *sptr, int public_amt, s_char *name,
int old, int new);
extern int line_of_sight(char **rad, int ax, int ay, int bx, int by);
-extern void plane_sona(struct emp_qelem *, int, int, struct shiplook *);
+extern void plane_sona(struct emp_qelem *, int, int, struct shiplist **);
extern int tend_nxtitem(struct nstr_item *, void *);
extern s_char *prsub(struct shpstr *);
extern int check_trade(void);
extern int unitsatxy(coord, coord, int, int);
extern int planesatxy(coord, coord, int, int, struct emp_qelem *);
extern int asw_shipsatxy(coord, coord, int, int, struct plnstr *,
- struct shiplook *);
+ struct shiplist **);
extern int num_shipsatxy(coord, coord, int, int);
extern int islist(s_char *);
/* src/lib/subs/mission.c */
int ignore;
struct shpstr ship;
int nships = 0;
- struct shiplook head, *s, *s2;
+ struct shiplist *head = NULL;
s_char buf[1024];
s_char prompt[128];
s_char msg[128];
int gun;
int shell;
- memset(&head, 0, sizeof(struct shiplook));
- head.uid = -1;
for (qp = list->q_forw; qp != list && !player->aborted;
qp = qp->q_forw) {
- if (head.uid != -1) {
- s = head.next;
- while (s != (struct shiplook *)0) {
- s2 = s;
- s = s->next;
- free(s2);
- }
- }
- memset(&head, 0, sizeof(struct shiplook));
- head.uid = -1;
+ free_shiplist(&head);
plp = (struct plist *)qp;
if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
continue;
}
if (*q == '?') {
if (plp->pcp->pl_flags & P_A)
- print_found(&head);
+ print_shiplist(head);
else
shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
continue;
next:
;
}
- s = head.next;
- while (s != (struct shiplook *)0) {
- s2 = s;
- s = s->next;
- free(s2);
- }
+ free_shiplist(&head);
}
static void
void
plane_sona(struct emp_qelem *plane_list, int x, int y,
- struct shiplook *head)
+ struct shiplist **head)
{
struct plnstr *pp;
struct plchrstr *pcp;
targ = &s;
if (targ->shp_own == pp->pln_own || targ->shp_own == 0)
continue;
-/*
- if (have_looked(targ->shp_uid,head))
- continue;
-*/
- if (have_found(targ->shp_uid, head))
+ if (on_shiplist(targ->shp_uid, *head))
continue;
- set_have_looked(targ->shp_uid, head);
tmcp = &mchr[(int)targ->shp_type];
if (!(tmcp->m_flags & M_SUB))
continue;
}
if ((dist > vrange))
continue;
- set_have_found(targ->shp_uid, head);
+ add_shiplist(targ->shp_uid, head);
if (!found) {
mpr(pp->pln_own,
"\nSonar contact in %s\n", xyas(x, y, pp->pln_own));
struct natstr *over, *mynatp;
struct plist *plp;
int evaded;
- struct shiplook head;
- struct shiplook *s, *s2;
+ struct shiplist *head = NULL;
int changed = 0;
int intown = 0; /* Last owner to intercept */
/* We want to only intercept once per sector per owner. So, if we overfly
a sector, and then overfly some land units or ships, we don't want to
potentially intercept 3 times. */
- memset(&head, 0, sizeof(struct shiplook));
- head.uid = -1;
-
plp = (struct plist *)bomb_list->q_forw;
plane_owner = plp->plane.pln_own;
writemap(player->cnum);
/* Now, if the bomber and escort lists are empty, we are done */
if (QEMPTY(bomb_list) && QEMPTY(esc_list)) {
- if (mission_flags & P_A) {
- s = head.next;
- while (s != (struct shiplook *)0) {
- s2 = s;
- s = s->next;
- free(s2);
- }
- }
+ if (mission_flags & P_A)
+ free_shiplist(&head);
return;
}
}
}
}
-
- if ((mission_flags & P_A) && (head.uid != -1)) {
- s = head.next;
- while (s != (struct shiplook *)0) {
- s2 = s;
- s = s->next;
- free(s2);
- }
- }
+ if (mission_flags & P_A)
+ free_shiplist(&head);
}
static int
* aswplnsubs.c: Various subroutines used for ASW planes
*
* Known contributors to this file:
+ * Ron Koenderink, 2004
*
*/
#include "misc.h"
-#include "player.h"
-#include "xy.h"
-#include "ship.h"
-#include "nsc.h"
-#include "nat.h"
-#include "path.h"
#include "file.h"
#include "plane.h"
-#include <fcntl.h>
-#include <ctype.h>
-#include "prototypes.h"
int
-have_looked(u_char uid, struct shiplook *head)
+on_shiplist(short uid, struct shiplist *head)
{
- struct shiplook *s;
+ struct shiplist *s;
s = head;
- if (s->uid == -1)
- return 0;
-
- while (s != ((struct shiplook *)0)) {
- if (s->uid == uid)
- return s->looked;
- s = s->next;
- }
-
- return 0;
-}
-
-int
-have_found(u_char uid, struct shiplook *head)
-{
- struct shiplook *s;
-
- s = head;
- if (s->uid == -1)
- return 0;
-
- while (s != ((struct shiplook *)0)) {
+ while (s != NULL) {
if (s->uid == uid)
- return s->found;
+ return 1;
s = s->next;
}
-
return 0;
}
void
-set_have_looked(u_char uid, struct shiplook *head)
+add_shiplist(short uid, struct shiplist **head)
{
- struct shiplook *s, *s2;
+ struct shiplist *s, *s2;
- s = head;
- if (s->uid == -1) {
- s->uid = uid;
- s->looked = 1;
- s->found = 0;
- s->next = (struct shiplook *)0;
- }
+ s = *head;
+ s2 = NULL;
- while (s != ((struct shiplook *)0)) {
+ while (s != NULL) {
if (s->uid == uid) {
- s->looked = 1;
return;
}
s2 = s;
s = s->next;
}
- s = (struct shiplook *)malloc(sizeof(struct shiplook));
- memset(s, 0, sizeof(struct shiplook));
- s2->next = s;
+ s = malloc(sizeof(struct shiplist));
+ if (s2 != NULL)
+ s2->next = s;
+ else
+ *head = s;
s->uid = uid;
- s->looked = 1;
- s->next = (struct shiplook *)0;
+ s->next = NULL;
}
void
-set_have_found(u_char uid, struct shiplook *head)
+free_shiplist(struct shiplist **head)
{
- struct shiplook *s, *s2;
+ struct shiplist *s, *s2;
- s = head;
- if (s->uid == -1) {
- s->uid = uid;
- s->looked = 0;
- s->found = 1;
- s->next = (struct shiplook *)0;
- }
+ s = *head;
-
- while (s != ((struct shiplook *)0)) {
- if (s->uid == uid) {
- s->found = 1;
- return;
- }
+ while (s != NULL) {
s2 = s;
s = s->next;
+ free(s2);
}
-
- s = (struct shiplook *)malloc(sizeof(struct shiplook));
- memset(s, 0, sizeof(struct shiplook));
- s2->next = s;
- s->uid = uid;
- s->found = 1;
- s->next = (struct shiplook *)0;
+ *head = NULL;
}
-int
-print_found(struct shiplook *head)
+void
+print_shiplist(struct shiplist *head)
{
- struct shiplook *s;
+ struct shiplist *s;
int first;
struct mchrstr *mp;
struct shpstr ship;
s = head;
first = 1;
- if (s->uid == -1)
- return 0;
- while (s != ((struct shiplook *)0)) {
+ while (s != NULL) {
getship(s->uid, &ship);
mp = &mchr[(int)ship.shp_type];
if (first) {
cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
s = s->next;
}
-
- return 1;
}
int
asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags,
- struct plnstr *pp, struct shiplook *head)
+ struct plnstr *pp, struct shiplist **head)
{
int first;
int ships;
shp_hardtarget(&ship), EF_SHIP))
continue;
}
- set_have_found(ship.shp_uid, head);
+ add_shiplist(ship.shp_uid, head);
if (first) {
pr(" # owner eff type\n");
first = 0;