]> git.pond.sub.org Git - empserver/blob - src/lib/subs/aswplnsubs.c
937b71af07f2a660c05f96d4abfc5b32a1bfaa0e
[empserver] / src / lib / subs / aswplnsubs.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 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, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  aswplnsubs.c: Various subroutines used for ASW planes
28  *
29  *  Known contributors to this file:
30  *     Ron Koenderink, 2004
31  */
32
33 #include <config.h>
34
35 #include "misc.h"
36 #include "nat.h"
37 #include "plane.h"
38 #include "prototypes.h"
39 #include "ship.h"
40
41 int
42 on_shiplist(int uid, struct shiplist *head)
43 {
44     struct shiplist *s;
45
46     s = head;
47     while (s != NULL) {
48         if (s->uid == uid)
49             return 1;
50         s = s->next;
51     }
52     return 0;
53 }
54
55 void
56 add_shiplist(int uid, struct shiplist **head)
57 {
58     struct shiplist *s, *s2;
59
60     s = *head;
61     s2 = NULL;
62
63     while (s != NULL) {
64         if (s->uid == uid) {
65             return;
66         }
67         s2 = s;
68         s = s->next;
69     }
70
71     s = malloc(sizeof(struct shiplist));
72     if (s2 != NULL)
73         s2->next = s;
74     else
75         *head = s;
76     s->uid = uid;
77     s->next = NULL;
78 }
79
80 void
81 free_shiplist(struct shiplist **head)
82 {
83     struct shiplist *s, *s2;
84
85     s = *head;
86
87     while (s != NULL) {
88         s2 = s;
89         s = s->next;
90         free(s2);
91     }
92     *head = NULL;
93 }