src/lib/subs/aswplnsubs.c

Go to the documentation of this file.
00001 /*
00002  *  Empire - A multi-player, client/server Internet based war game.
00003  *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
00004  *                           Ken Stevens, Steve McClure
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  *  ---
00021  *
00022  *  See files README, COPYING and CREDITS in the root of the source
00023  *  tree for related information and legal notices.  It is expected
00024  *  that future projects/authors will amend these files as needed.
00025  *
00026  *  ---
00027  *
00028  *  aswplnsubs.c: Various subroutines used for ASW planes
00029  * 
00030  *  Known contributors to this file:
00031  *  Ron Koenderink, 2004
00032  */
00033 
00034 #include <config.h>
00035 
00036 #include "file.h"
00037 #include "misc.h"
00038 #include "nat.h"
00039 #include "plane.h"
00040 #include "prototypes.h"
00041 #include "ship.h"
00042 
00043 int
00044 on_shiplist(short uid, struct shiplist *head)
00045 {
00046     struct shiplist *s;
00047 
00048     s = head;
00049     while (s != NULL) {
00050         if (s->uid == uid)
00051             return 1;
00052         s = s->next;
00053     }
00054     return 0;
00055 }
00056 
00057 void
00058 add_shiplist(short uid, struct shiplist **head)
00059 {
00060     struct shiplist *s, *s2;
00061 
00062     s = *head;
00063     s2 = NULL;
00064 
00065     while (s != NULL) {
00066         if (s->uid == uid) {
00067             return;
00068         }
00069         s2 = s;
00070         s = s->next;
00071     }
00072 
00073     s = malloc(sizeof(struct shiplist));
00074     if (s2 != NULL) 
00075         s2->next = s;
00076     else
00077         *head = s;
00078     s->uid = uid;
00079     s->next = NULL;
00080 }
00081 
00082 void
00083 free_shiplist(struct shiplist **head)
00084 {
00085     struct shiplist *s, *s2;
00086 
00087     s = *head;
00088 
00089     while (s != NULL) {
00090         s2 = s;
00091         s = s->next;
00092         free(s2);
00093     }
00094     *head = NULL;
00095 }
00096 
00097 void
00098 print_shiplist(struct shiplist *head)
00099 {
00100     struct shiplist *s;
00101     int first;
00102     struct mchrstr *mp;
00103     struct shpstr ship;
00104 
00105     s = head;
00106     first = 1;
00107 
00108     while (s != NULL) {
00109         getship(s->uid, &ship);
00110         mp = &mchr[(int)ship.shp_type];
00111         if (first) {
00112             pr(" #          player->owner           eff        type\n");
00113             first = 0;
00114         }
00115         pr("(#%3d) %10.10s  %12.12s  %s\n", ship.shp_uid,
00116            cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship));
00117         s = s->next;
00118     }
00119 }

Generated on Fri Mar 28 11:01:15 2008 for empserver by  doxygen 1.5.2