]> git.pond.sub.org Git - empserver/blob - src/lib/subs/sect.c
Fix trailing whitespace
[empserver] / src / lib / subs / sect.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  *  sect.c: Sector pre-write and post-read data massage
29  *
30  *  Known contributors to this file:
31  *     Dave Pare, 1989
32  *     Steve McClure, 1996
33  *     Markus Armbruster, 2004-2008
34  */
35
36 #include <config.h>
37
38 #include <ctype.h>
39 #include "file.h"
40 #include "land.h"
41 #include "lost.h"
42 #include "misc.h"
43 #include "nat.h"
44 #include "nsc.h"
45 #include "optlist.h"
46 #include "plane.h"
47 #include "player.h"
48 #include "prototypes.h"
49 #include "sect.h"
50 #include "xy.h"
51
52 void
53 sct_postread(int id, void *ptr)
54 {
55     struct sctstr *sp = ptr;
56
57     player->owner = (player->god || sp->sct_own == player->cnum);
58     if (opt_MOB_ACCESS)
59         sct_do_upd_mob(sp);
60 }
61
62 void
63 sct_prewrite(int id, void *old, void *new)
64 {
65     struct sctstr *oldsp = old;
66     struct sctstr *sp = new;
67     int mil, civs;
68     natid own;
69
70     bridge_damaged(sp);
71     item_prewrite(sp->sct_item);
72
73     mil = sp->sct_item[I_MILIT];
74     civs = sp->sct_item[I_CIVIL];
75     own = sp->sct_own;
76
77     if (own && !civs) {
78         sp->sct_work = 100;
79         sp->sct_oldown = own;
80     }
81
82     if (own && !civs && !mil && !has_units(sp->sct_x, sp->sct_y, own, NULL)
83         && !(sp->sct_flags & MOVE_IN_PROGRESS)) {
84         /* more cruft! */
85         own = 0;
86         sp->sct_mobil = 0;
87         if (sp->sct_type == SCT_CAPIT || sp->sct_type == SCT_MOUNT)
88             caploss(sp, own, "");
89     }
90
91     /* We've avoided assigning to sp->sct_own, in case oldsp == sp */
92     if (oldsp->sct_own != own)
93         lost_and_found(EF_SECTOR, oldsp->sct_own, own,
94                        0, sp->sct_x, sp->sct_y);
95
96     sp->sct_own = own;
97 }
98
99 void
100 item_prewrite(short *item)
101 {
102     i_type i;
103
104     for (i = I_NONE + 1; i <= I_MAX; ++i) {
105         if (CANT_HAPPEN(item[i] < 0))
106             item[i] = 0;
107         else if (CANT_HAPPEN(item[i] > ITEM_MAX))
108             item[i] = ITEM_MAX;
109     }
110 }
111
112 int
113 issector(char *arg)
114 {
115     char c;
116
117     while (0 != (c = *arg++))
118         if (!isdigit(c) && !isspace(c) && (c != '/'))
119             return 1;
120
121     return 0;
122 }