]> git.pond.sub.org Git - empserver/blob - src/lib/common/check.c
Import of Empire 4.2.12
[empserver] / src / lib / common / check.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  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 "misc.h"
35 #include "player.h"
36 #include "xy.h"
37 #include "file.h"
38 #include "var.h"
39 #include "sect.h"
40 #include "ship.h"
41 #include "plane.h"      
42 #include "nuke.h"
43 #include "land.h"       
44 #include "item.h"
45 #include "nsc.h"
46 #include "nat.h"
47 #include "commodity.h"
48 #include "loan.h"
49 #include "optlist.h"
50 #include "commands.h"
51 #include "trade.h"
52
53 /* Note that timestamps make things tricky.  And, we don't
54  * really care about the timestamp, we just care about the rest
55  * of the structure.  So, we make a copy, and zero the timestamps
56  * in both copies, and then compare. */
57
58 int
59 check_sect_ok(struct sctstr *sectp)
60 {
61     struct sctstr chksect;
62     struct sctstr tsect;
63
64     getsect(sectp->sct_x, sectp->sct_y, &chksect);
65     memcpy(&tsect, sectp, sizeof(struct sctstr));
66     tsect.sct_timestamp = chksect.sct_timestamp = 0;
67     if (memcmp(&tsect, &chksect, sizeof(struct sctstr))) {
68         pr("Sector %s has changed!\n",
69            xyas(sectp->sct_x, sectp->sct_y, player->cnum));
70         return 0;
71     }
72     return 1;
73 }
74
75 int
76 check_ship_ok(struct shpstr *shipp)
77 {
78     struct shpstr chkship;
79     struct shpstr tship;
80
81     getship(shipp->shp_uid, &chkship);
82     memcpy(&tship, shipp, sizeof(struct shpstr));
83     tship.shp_timestamp = chkship.shp_timestamp = 0;
84     if (memcmp(&tship, &chkship, sizeof(struct shpstr))) {
85         pr("Ship #%d has changed!\n", shipp->shp_uid);
86         return 0;
87     }
88     return 1;
89 }
90
91 int
92 check_plane_ok(struct plnstr *planep)
93 {
94     struct plnstr chkplane;
95     struct plnstr tplane;
96
97     getplane(planep->pln_uid, &chkplane);
98     memcpy(&tplane, planep, sizeof(struct plnstr));
99     tplane.pln_timestamp = chkplane.pln_timestamp = 0;
100     if (memcmp(&tplane, &chkplane, sizeof(struct plnstr))) {
101         pr("Plane #%d has changed!\n", planep->pln_uid);
102         return 0;
103     }
104     return 1;
105 }
106
107 int
108 check_land_ok(struct lndstr *landp)
109 {
110     struct lndstr chkland;
111     struct lndstr tland;
112
113     getland(landp->lnd_uid, &chkland);
114     memcpy(&tland, landp, sizeof(struct lndstr));
115     tland.lnd_timestamp = chkland.lnd_timestamp = 0;
116     if (memcmp(&tland, &chkland, sizeof(struct lndstr))) {
117         pr("Land unit #%d has changed!\n", landp->lnd_uid);
118         return 0;
119     }
120     return 1;
121 }
122
123 int
124 check_nuke_ok(struct nukstr *nukep)
125 {
126     struct nukstr chknuke;
127     struct nukstr tnuke;
128
129     getnuke(nukep->nuk_uid, &chknuke);
130     memcpy(&tnuke, nukep, sizeof(struct nukstr));
131     tnuke.nuk_timestamp = chknuke.nuk_timestamp = 0;
132     if (memcmp(&tnuke, &chknuke, sizeof(struct nukstr))) {
133         pr("Nuclear stockpile %d has changed!\n", nukep->nuk_uid);
134         return 0;
135     }
136     return 1;
137 }
138
139 int
140 check_loan_ok(struct lonstr *loanp)
141 {
142     struct lonstr chkloan;
143
144     getloan(loanp->l_uid, &chkloan);
145     if (memcmp(loanp, &chkloan, sizeof(struct lonstr))) {
146         pr("Loan %d has changed!\n", loanp->l_uid);
147         return 0;
148     }
149     return 1;
150 }
151
152 int
153 check_comm_ok(struct comstr *commp)
154 {
155     struct comstr chkcomm;
156
157     getcomm(commp->com_uid, &chkcomm);
158     if (memcmp(commp, &chkcomm, sizeof(struct comstr))) {
159         pr("Commodity %d has changed!\n", commp->com_uid);
160         return 0;
161     }
162     return 1;
163 }
164
165