]> git.pond.sub.org Git - empserver/blob - src/lib/subs/border.c
1e79fb98d1afe40106ad5533831e1b1e864e057d
[empserver] / src / lib / subs / border.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2016, 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  *  border.c: Create a border around a map
28  *
29  *  Known contributors to this file:
30  *
31  */
32
33 #include <config.h>
34
35 #include "map.h"
36 #include "optlist.h"
37 #include "prototypes.h"
38 #include "xy.h"
39
40 /*
41  * space-fill a map or radar scan;
42  * null terminate
43  */
44 void
45 blankfill(char *ptr, struct range *range, int size)
46 {
47     char *p;
48     int row;
49     int col;
50
51     for (row = 0; row < range->height; row++) {
52         col = (range->width + 1) * (size + 1) / 2 - 1;
53         p = ptr;
54         while (--col >= 0)
55             *p++ = ' ';
56         *p = 0;
57         ptr += MAPWIDTH(size);
58     }
59 }
60
61 void
62 border(struct range *rp, char *prefstr, char *sep)
63
64                                 /* prefixes each line */
65                                 /* separates the numbers */
66 {
67     int posi, n, x;
68
69     if ((WORLD_X / 2) >= 100) {
70         if (rp->lx + rp->width > 100 || rp->hx - rp->width < -100) {
71             /*
72              * hundreds
73              */
74             pr("%s", prefstr);
75             for (x = rp->lx, n = 0; n < rp->width; n++, x++) {
76                 if (x >= WORLD_X / 2)
77                     x -= WORLD_X;
78                 pr("%s", sep);
79                 if (x < 0 && x > -100) {
80                     pr("-");
81                 } else {
82                     posi = (x < 0 ? -x : x) / 100;
83                     pr("%d", posi % 10);
84                 }
85             }
86             pr("\n");
87         }
88     }
89     /*
90      * tens
91      */
92     pr("%s", prefstr);
93     for (x = rp->lx, n = 0; n < rp->width; n++, x++) {
94         if (x >= WORLD_X / 2)
95             x -= WORLD_X;
96         pr("%s", sep);
97         if (x < 0 && x > -10) {
98             pr("-");
99         } else {
100             posi = (x < 0 ? -x : x) / 10;
101             pr("%d", posi % 10);
102         }
103     }
104     pr("\n");
105     /*
106      * units...
107      */
108     pr("%s", prefstr);
109     for (x = rp->lx, n = 0; n < rp->width; n++, x++) {
110         if (x >= WORLD_X / 2)
111             x -= WORLD_X;
112         posi = (x < 0 ? -x : x);
113         pr("%s%d", sep, posi % 10);
114     }
115     pr("\n");
116 }