1 /* Pioneers - Implementation of the excellent Settlers of Catan board game.
2 * Go buy a copy.
3 *
4 * Copyright (C) 1999 Dave Cole
5 * Copyright (C) 2003 Bas Wijnen <shevek@fmf.nl>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "config.h"
23 #include <ctype.h>
24
25 #include "game.h"
26 #include "cards.h"
27 #include "map.h"
28 #include "network.h"
29 #include "log.h"
30 #include "client.h"
31
32 static gboolean double_setup;
33
is_setup_double(void)34 gboolean is_setup_double(void)
35 {
36 return double_setup;
37 }
38
setup_can_build_road(void)39 gboolean setup_can_build_road(void)
40 {
41 if (game_params->num_build_type[BUILD_ROAD] == 0)
42 return FALSE;
43 if (double_setup) {
44 if (build_count_edges() == 2)
45 return FALSE;
46 return build_count_settlements() < 2
47 || map_can_place_road(callbacks.get_map(),
48 my_player_num());
49 } else {
50 if (build_count_edges() == 1)
51 return FALSE;
52 return build_count_settlements() < 1
53 || map_can_place_road(callbacks.get_map(),
54 my_player_num());
55 }
56 }
57
setup_can_build_ship(void)58 gboolean setup_can_build_ship(void)
59 {
60 if (game_params->num_build_type[BUILD_SHIP] == 0)
61 return FALSE;
62 if (double_setup) {
63 if (build_count_edges() == 2)
64 return FALSE;
65 return build_count_settlements() < 2
66 || map_can_place_ship(callbacks.get_map(),
67 my_player_num());
68 } else {
69 if (build_count_edges() == 1)
70 return FALSE;
71 return build_count_settlements() < 1
72 || map_can_place_ship(callbacks.get_map(),
73 my_player_num());
74 }
75 }
76
setup_can_build_bridge(void)77 gboolean setup_can_build_bridge(void)
78 {
79 if (game_params->num_build_type[BUILD_BRIDGE] == 0)
80 return FALSE;
81 if (double_setup) {
82 if (build_count_edges() == 2)
83 return FALSE;
84 return build_count_settlements() < 2
85 || map_can_place_bridge(callbacks.get_map(),
86 my_player_num());
87 } else {
88 if (build_count_edges() == 1)
89 return FALSE;
90 return build_count_settlements() < 1
91 || map_can_place_bridge(callbacks.get_map(),
92 my_player_num());
93 }
94 }
95
setup_can_build_settlement(void)96 gboolean setup_can_build_settlement(void)
97 {
98 if (game_params->num_build_type[BUILD_SETTLEMENT] == 0)
99 return FALSE;
100 if (double_setup)
101 return build_count_settlements() < 2;
102 else
103 return build_count_settlements() < 1;
104 }
105
setup_can_finish(void)106 gboolean setup_can_finish(void)
107 {
108 if (double_setup)
109 return build_count_edges() == 2
110 && build_count_settlements() == 2 && build_is_valid();
111 else
112 return build_count_edges() == 1
113 && build_count_settlements() == 1 && build_is_valid();
114 }
115
116 /* Place some restrictions on road placement during setup phase
117 */
setup_check_road(const Edge * edge)118 gboolean setup_check_road(const Edge * edge)
119 {
120 return build_can_setup_road(edge, double_setup);
121 }
122
123 /* Place some restrictions on ship placement during setup phase
124 */
setup_check_ship(const Edge * edge)125 gboolean setup_check_ship(const Edge * edge)
126 {
127 return build_can_setup_ship(edge, double_setup);
128 }
129
130 /* Place some restrictions on bridge placement during setup phase
131 */
setup_check_bridge(const Edge * edge)132 gboolean setup_check_bridge(const Edge * edge)
133 {
134 return build_can_setup_bridge(edge, double_setup);
135 }
136
137 /* Place some restrictions on settlement placement during setup phase
138 */
setup_check_settlement(const Node * node)139 gboolean setup_check_settlement(const Node * node)
140 {
141 return build_can_setup_settlement(node, double_setup);
142 }
143
setup_begin(gint player_num)144 void setup_begin(gint player_num)
145 {
146 log_message(MSG_INFO, _("Setup for %s.\n"),
147 player_name(player_num, FALSE));
148 player_set_current(player_num);
149 if (player_num != my_player_num())
150 return;
151
152 double_setup = FALSE;
153 build_clear();
154 }
155
setup_begin_double(gint player_num)156 void setup_begin_double(gint player_num)
157 {
158 log_message(MSG_INFO, _("Double setup for %s.\n"),
159 player_name(player_num, FALSE));
160 player_set_current(player_num);
161 if (player_num != my_player_num())
162 return;
163
164 double_setup = TRUE;
165 build_clear();
166 }
167