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
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.
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.
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
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.
28 * xy.c: x-y related conversion routines
30 * Known contributors to this file:
46 * return pointer to a string containing the x,y
47 * coords as desired by a particular target country.
50 xyas(coord x, coord y, natid country)
54 np = getnatp(country);
55 return prbuf("%d,%d", xrel(np, x), yrel(np, y));
59 ownxy(struct sctstr *sp)
61 return xyas(sp->sct_x, sp->sct_y, sp->sct_own);
65 xrel(struct natstr *np, coord absx)
69 if ((np->nat_stat & STAT_ABS) == 0) {
70 x = XNORM(absx - np->nat_xorg);
76 else if (x < -WORLD_X / 2)
82 yrel(struct natstr *np, coord absy)
86 if ((np->nat_stat & STAT_ABS) == 0) {
87 y = YNORM(absy - np->nat_yorg);
93 else if (y < -WORLD_Y / 2)
99 xyrelrange(struct natstr *np, struct range *src, struct range *dst)
101 dst->lx = xrel(np, src->lx);
102 dst->hx = xrel(np, src->hx);
103 dst->ly = yrel(np, src->ly);
104 dst->hy = yrel(np, src->hy);
105 dst->width = src->width;
106 dst->height = src->height;
110 xyabsrange(struct natstr *np, struct range *src, struct range *dst)
112 dst->lx = xabs(np, src->lx);
113 dst->hx = xabs(np, src->hx);
114 dst->ly = yabs(np, src->ly);
115 dst->hy = yabs(np, src->hy);
116 dst->width = src->width;
117 dst->height = src->height;
121 inputxy(coord *xp, coord *yp, natid cn)
131 xabs(struct natstr *np, coord relx)
133 if ((np->nat_stat & STAT_ABS) == 0)
134 relx += np->nat_xorg;
139 yabs(struct natstr *np, coord rely)
141 if ((np->nat_stat & STAT_ABS) == 0)
142 rely += np->nat_yorg;
147 sctoff(coord x, coord y)
150 logerror("%d,%d is an invalid sector specification!\n", x, y);
153 return (YNORM(y) * WORLD_X + XNORM(x)) / 2;
157 xnorm(register coord x)
160 x = WORLD_X - (-x % WORLD_X);
165 ynorm(register coord y)
168 y = WORLD_Y - (-y % WORLD_Y);
173 xyinrange(coord x, coord y, struct range *rp)
175 if (rp->lx < rp->hx) {
176 /* xrange doesn't wrap */
177 if (x < rp->lx || x > rp->hx)
180 if (x < rp->lx && x > rp->hx)
183 if (rp->ly < rp->hy) {
184 /* yrange doesn't wrap */
185 if (y < rp->ly || y > rp->hy)
188 if (y < rp->ly && y > rp->hy)
196 prbuf(s_char *format, ...)
198 static int nbuf = -1;
199 static s_char buf[20][1024];
205 va_start(ap, format);
206 (void)vsprintf(buf[nbuf], format, ap);