]> git.pond.sub.org Git - empserver/blob - src/lib/subs/coastal.c
(coastal_sea_to_land, coastal_land_to_sea): Remove unused parameter
[empserver] / src / lib / subs / coastal.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, 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  *  coastal.c: Routines to calculate the coastal flag
29  * 
30  *  Known contributors to this file:
31  *     Ron Koenderink, 2005
32  */
33
34 #include <config.h>
35
36 #include "prototypes.h"
37 #include "file.h"
38 #include "path.h"
39
40 static void
41 update_coastal_flag(struct sctstr *sp, struct sctstr *sectp)
42 {
43     int n;
44     struct sctstr sect;
45
46     for (n = 1; n <= 6; n++) {  /* Directions */
47         getsect(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1], &sect);
48         if (sectp && sectp->sct_x == sect.sct_x &&
49             sectp->sct_y == sect.sct_y)
50             continue;
51         if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_BTOWER ||
52             sect.sct_type == SCT_BSPAN) {
53             if (!sp->sct_coastal) {
54                 sp->sct_coastal = 1;
55                 putsect(sp);
56             }
57             return;
58         }
59     }
60     if (sp->sct_coastal) {
61         sp->sct_coastal = 0;
62         putsect(sp);
63     }
64 }
65
66 static void
67 coastal_sea_to_land(struct sctstr *sp)
68 {
69     int n;
70     struct sctstr sect;
71
72     update_coastal_flag(sp, NULL);
73
74     for (n = 1; n <= 6; n++) {  /* Directions */
75         getsect(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1], &sect);
76         update_coastal_flag(&sect, sp);
77     }
78 }
79
80 static void
81 coastal_land_to_sea(struct sctstr *sp)
82 {
83     int n;
84     struct sctstr sect;
85
86     sp->sct_coastal = 1;
87     putsect(sp);
88
89     for (n = 1; n <= 6; ++n) {  /* Directions */
90         getsect(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1], &sect);
91         if (!sect.sct_coastal) {
92             sect.sct_coastal = 1;
93             putsect(&sect);
94         }
95     }
96 }
97
98 void
99 set_coastal(struct sctstr *sp, int des)
100 {
101     int old_water = 0;
102     int new_water = 0;
103
104     if (sp->sct_type == SCT_WATER || sp->sct_type == SCT_BTOWER ||
105         sp->sct_type == SCT_BSPAN)
106         old_water = 1;
107
108     if (des == SCT_WATER || des == SCT_BTOWER || des== SCT_BSPAN)
109         new_water = 1;
110
111     if (new_water == old_water)
112         return;
113     else if (new_water)
114         coastal_land_to_sea(sp);
115     else
116         coastal_sea_to_land(sp);
117 }