]> git.pond.sub.org Git - empserver/blob - src/lib/subs/check.c
Clean up library dependencies
[empserver] / src / lib / subs / check.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  *  check.c: Check a sector, plane, land unit, ship or nuke
29  * 
30  *  Known contributors to this file:
31  *     Steve McClure, 1998
32  */
33
34 #include <config.h>
35
36 #include "commodity.h"
37 #include "file.h"
38 #include "land.h"
39 #include "loan.h"
40 #include "misc.h"
41 #include "nat.h"
42 #include "nsc.h"
43 #include "nuke.h"
44 #include "plane.h"
45 #include "player.h"
46 #include "prototypes.h"
47 #include "sect.h"
48 #include "ship.h"
49 #include "trade.h"
50 #include "xy.h"
51
52 /* Note that timestamps make things tricky.  And, we don't
53  * really care about the timestamp, we just care about the rest
54  * of the structure.  So, we make a copy, and zero the timestamps
55  * in both copies, and then compare. */
56
57 int
58 check_sect_ok(struct sctstr *sectp)
59 {
60     struct sctstr chksect;
61     struct sctstr tsect;
62
63     getsect(sectp->sct_x, sectp->sct_y, &chksect);
64     memcpy(&tsect, sectp, sizeof(struct sctstr));
65     tsect.sct_timestamp = chksect.sct_timestamp = 0;
66     if (memcmp(&tsect, &chksect, sizeof(struct sctstr))) {
67         pr("Sector %s has changed!\n",
68            xyas(sectp->sct_x, sectp->sct_y, player->cnum));
69         return 0;
70     }
71     return 1;
72 }
73
74 int
75 check_ship_ok(struct shpstr *shipp)
76 {
77     struct shpstr chkship;
78     struct shpstr tship;
79
80     getship(shipp->shp_uid, &chkship);
81     memcpy(&tship, shipp, sizeof(struct shpstr));
82     tship.shp_timestamp = chkship.shp_timestamp = 0;
83     if (memcmp(&tship, &chkship, sizeof(struct shpstr))) {
84         pr("Ship #%d has changed!\n", shipp->shp_uid);
85         return 0;
86     }
87     return 1;
88 }
89
90 int
91 check_plane_ok(struct plnstr *planep)
92 {
93     struct plnstr chkplane;
94     struct plnstr tplane;
95
96     getplane(planep->pln_uid, &chkplane);
97     memcpy(&tplane, planep, sizeof(struct plnstr));
98     tplane.pln_timestamp = chkplane.pln_timestamp = 0;
99     if (memcmp(&tplane, &chkplane, sizeof(struct plnstr))) {
100         pr("Plane #%d has changed!\n", planep->pln_uid);
101         return 0;
102     }
103     return 1;
104 }
105
106 int
107 check_land_ok(struct lndstr *landp)
108 {
109     struct lndstr chkland;
110     struct lndstr tland;
111
112     getland(landp->lnd_uid, &chkland);
113     memcpy(&tland, landp, sizeof(struct lndstr));
114     tland.lnd_timestamp = chkland.lnd_timestamp = 0;
115     if (memcmp(&tland, &chkland, sizeof(struct lndstr))) {
116         pr("Land unit #%d has changed!\n", landp->lnd_uid);
117         return 0;
118     }
119     return 1;
120 }
121
122 int
123 check_nuke_ok(struct nukstr *nukep)
124 {
125     struct nukstr chknuke;
126     struct nukstr tnuke;
127
128     getnuke(nukep->nuk_uid, &chknuke);
129     memcpy(&tnuke, nukep, sizeof(struct nukstr));
130     tnuke.nuk_timestamp = chknuke.nuk_timestamp = 0;
131     if (memcmp(&tnuke, &chknuke, sizeof(struct nukstr))) {
132         pr("Nuke %d has changed!\n", nukep->nuk_uid);
133         return 0;
134     }
135     return 1;
136 }
137
138 int
139 check_loan_ok(struct lonstr *loanp)
140 {
141     struct lonstr chkloan;
142
143     getloan(loanp->l_uid, &chkloan);
144     if (memcmp(loanp, &chkloan, sizeof(struct lonstr))) {
145         pr("Loan %d has changed!\n", loanp->l_uid);
146         return 0;
147     }
148     return 1;
149 }
150
151 int
152 check_comm_ok(struct comstr *commp)
153 {
154     struct comstr chkcomm;
155
156     getcomm(commp->com_uid, &chkcomm);
157     if (memcmp(commp, &chkcomm, sizeof(struct comstr))) {
158         pr("Commodity %d has changed!\n", commp->com_uid);
159         return 0;
160     }
161     return 1;
162 }
163
164 int
165 check_trade_ok(struct trdstr *tp)
166 {
167     struct trdstr chktrade;
168
169     gettrade(tp->trd_uid, &chktrade);
170     if (memcmp(tp, &chktrade, sizeof(struct trdstr))) {
171         pr("Trade lot #%d has changed!\n", tp->trd_uid);
172         return 0;
173     }
174     return 1;
175 }