]> git.pond.sub.org Git - empserver/blob - src/lib/subs/aswplnsubs.c
Fix trailing whitespace
[empserver] / src / lib / subs / aswplnsubs.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  aswplnsubs.c: Various subroutines used for ASW planes
29  *
30  *  Known contributors to this file:
31  *     Ron Koenderink, 2004
32  */
33
34 #include <config.h>
35
36 #include "file.h"
37 #include "misc.h"
38 #include "nat.h"
39 #include "plane.h"
40 #include "prototypes.h"
41 #include "ship.h"
42
43 int
44 on_shiplist(short uid, struct shiplist *head)
45 {
46     struct shiplist *s;
47
48     s = head;
49     while (s != NULL) {
50         if (s->uid == uid)
51             return 1;
52         s = s->next;
53     }
54     return 0;
55 }
56
57 void
58 add_shiplist(short uid, struct shiplist **head)
59 {
60     struct shiplist *s, *s2;
61
62     s = *head;
63     s2 = NULL;
64
65     while (s != NULL) {
66         if (s->uid == uid) {
67             return;
68         }
69         s2 = s;
70         s = s->next;
71     }
72
73     s = malloc(sizeof(struct shiplist));
74     if (s2 != NULL)
75         s2->next = s;
76     else
77         *head = s;
78     s->uid = uid;
79     s->next = NULL;
80 }
81
82 void
83 free_shiplist(struct shiplist **head)
84 {
85     struct shiplist *s, *s2;
86
87     s = *head;
88
89     while (s != NULL) {
90         s2 = s;
91         s = s->next;
92         free(s2);
93     }
94     *head = NULL;
95 }
96
97 void
98 print_shiplist(struct shiplist *head)
99 {
100     struct shiplist *s;
101     int first;
102     struct mchrstr *mp;
103     struct shpstr ship;
104
105     s = head;
106     first = 1;
107
108     while (s != NULL) {
109         getship(s->uid, &ship);
110         mp = &mchr[(int)ship.shp_type];
111         if (first) {
112             pr(" #          player->owner           eff        type\n");
113             first = 0;
114         }
115         pr("(#%3d) %10.10s  %12.12s  %s\n", ship.shp_uid,
116            cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
117         s = s->next;
118     }
119 }