]> git.pond.sub.org Git - empserver/blob - src/lib/subs/bigmap.c
7e1c2688b530a73bc9e03dc5347a3ad2ffd390b0
[empserver] / src / lib / subs / bigmap.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2017, 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  *  bigmap.c:  Updates a player's sector map using sector offsets and
28  *             simple overwrite rules.
29  *
30  *  Known contributors to this file:
31  *
32  */
33
34 #include <config.h>
35
36 #include "file.h"
37 #include "map.h"
38 #include "xy.h"
39
40 /* values of only_bmap:
41  * 0 = update both maps
42  * 1 = update only bmap
43  * 2 = update only bmap with force
44  */
45
46 static int do_map_set(char *map, coord x, coord y, char t, int force);
47
48 int
49 map_set(natid cnum, coord x, coord y, char t, int only_bmap)
50 {
51     int set = 0;
52
53     if (!t)
54         return 0;
55     if (!only_bmap)
56         set |= do_map_set(ef_ptr(EF_MAP, cnum), x, y, t, 0);
57     set |= do_map_set(ef_ptr(EF_BMAP, cnum), x, y, t, only_bmap > 1);
58
59     return set;
60 }
61
62
63 static int
64 do_map_set(char *map, coord x, coord y, char t, int force)
65 {
66     int id;
67
68     if ((id = sctoff(x, y)) < 0)
69         return 0;
70
71     if (((map[id] == 'x') || (map[id] == 'X')) && !force)
72         return 0;
73
74     if (t == '?') {
75         switch (map[id]) {
76         case '.':
77         case '-':
78         case ' ':
79         case 0:
80             map[id] = t;
81             break;
82         default:
83             break;
84         }
85     } else {
86         map[id] = t;
87     }
88     return 1;
89 }
90
91 void
92 writebmap(natid cnum)
93 {
94     ef_write(EF_BMAP, cnum, ef_ptr(EF_BMAP, cnum));
95 }
96
97 void
98 writemap(natid cnum)
99 {
100     ef_write(EF_MAP, cnum, ef_ptr(EF_MAP, cnum));
101     ef_write(EF_BMAP, cnum, ef_ptr(EF_BMAP, cnum));
102 }