]> git.pond.sub.org Git - empserver/blob - src/lib/subs/sect.c
Update known contributors comments
[empserver] / src / lib / subs / sect.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2011, 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  *  sect.c: Sector pre-write and post-read data massage
28  *
29  *  Known contributors to this file:
30  *     Dave Pare, 1989
31  *     Steve McClure, 1996
32  *     Markus Armbruster, 2004-2010
33  */
34
35 #include <config.h>
36
37 #include <ctype.h>
38 #include "file.h"
39 #include "land.h"
40 #include "lost.h"
41 #include "misc.h"
42 #include "nat.h"
43 #include "nsc.h"
44 #include "optlist.h"
45 #include "plane.h"
46 #include "player.h"
47 #include "prototypes.h"
48 #include "sect.h"
49 #include "xy.h"
50
51 void
52 sct_postread(int id, void *ptr)
53 {
54     struct sctstr *sp = ptr;
55
56     player->owner = (player->god || sp->sct_own == player->cnum);
57     if (opt_MOB_ACCESS)
58         sct_do_upd_mob(sp);
59 }
60
61 void
62 sct_prewrite(int id, void *old, void *new)
63 {
64     struct sctstr *oldsp = old;
65     struct sctstr *sp = new;
66     int mil, civs;
67     natid own, prev_own;
68
69     bridge_damaged(sp);
70     item_prewrite(sp->sct_item);
71
72     mil = sp->sct_item[I_MILIT];
73     civs = sp->sct_item[I_CIVIL];
74     own = sp->sct_own;
75     prev_own = oldsp->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 = sp->sct_own = 0;
86         sp->sct_mobil = 0;
87         if (sp->sct_type == SCT_CAPIT || sp->sct_type == SCT_MOUNT)
88             caploss(sp, prev_own, "");
89     }
90
91     if (prev_own != own)
92         lost_and_found(EF_SECTOR, prev_own, own, 0, sp->sct_x, sp->sct_y);
93 }
94
95 void
96 item_prewrite(short *item)
97 {
98     i_type i;
99
100     for (i = I_NONE + 1; i <= I_MAX; ++i) {
101         if (CANT_HAPPEN(item[i] < 0))
102             item[i] = 0;
103         else if (CANT_HAPPEN(item[i] > ITEM_MAX))
104             item[i] = ITEM_MAX;
105     }
106 }
107
108 int
109 issector(char *arg)
110 {
111     char c;
112
113     while (0 != (c = *arg++))
114         if (!isdigit(c) && !isspace(c) && (c != '/'))
115             return 1;
116
117     return 0;
118 }