1 /* Pioneers - Implementation of the excellent Settlers of Catan board game.
2  *   Go buy a copy.
3  *
4  * Copyright (C) 1999 Dave Cole
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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  */
20 
21 #include "config.h"
22 #include <string.h>
23 #include <glib.h>
24 
25 #include "game.h"
26 #include "cost.h"
27 
cost_road(void)28 const gint *cost_road(void)
29 {
30 	static gint cost[NO_RESOURCE] = {
31 		1,		/* brick */
32 		0,		/* grain */
33 		0,		/* ore */
34 		0,		/* wool */
35 		1		/* lumber */
36 	};
37 	return cost;
38 }
39 
cost_ship(void)40 const gint *cost_ship(void)
41 {
42 	static gint cost[NO_RESOURCE] = {
43 		0,		/* brick */
44 		0,		/* grain */
45 		0,		/* ore */
46 		1,		/* wool */
47 		1		/* lumber */
48 	};
49 	return cost;
50 }
51 
cost_bridge(void)52 const gint *cost_bridge(void)
53 {
54 	static gint cost[NO_RESOURCE] = {
55 		1,		/* brick */
56 		0,		/* grain */
57 		0,		/* ore */
58 		1,		/* wool */
59 		1		/* lumber */
60 	};
61 	return cost;
62 }
63 
cost_settlement(void)64 const gint *cost_settlement(void)
65 {
66 	static gint cost[NO_RESOURCE] = {
67 		1,		/* brick */
68 		1,		/* grain */
69 		0,		/* ore */
70 		1,		/* wool */
71 		1		/* lumber */
72 	};
73 	return cost;
74 }
75 
cost_upgrade_settlement(void)76 const gint *cost_upgrade_settlement(void)
77 {
78 	static gint cost[NO_RESOURCE] = {
79 		0,		/* brick */
80 		2,		/* grain */
81 		3,		/* ore */
82 		0,		/* wool */
83 		0		/* lumber */
84 	};
85 	return cost;
86 }
87 
cost_city(void)88 const gint *cost_city(void)
89 {
90 	static gint cost[NO_RESOURCE] = {
91 		1,		/* brick */
92 		3,		/* grain */
93 		3,		/* ore */
94 		1,		/* wool */
95 		1		/* lumber */
96 	};
97 	return cost;
98 }
99 
cost_city_wall(void)100 const gint *cost_city_wall(void)
101 {
102 	static gint cost[NO_RESOURCE] = {
103 		2,		/* brick */
104 		0,		/* grain */
105 		0,		/* ore */
106 		0,		/* wool */
107 		0		/* lumber */
108 	};
109 	return cost;
110 }
111 
cost_development(void)112 const gint *cost_development(void)
113 {
114 	static gint cost[NO_RESOURCE] = {
115 		0,		/* brick */
116 		1,		/* grain */
117 		1,		/* ore */
118 		1,		/* wool */
119 		0		/* lumber */
120 	};
121 	return cost;
122 }
123 
cost_buy(const gint * cost,gint * assets)124 gboolean cost_buy(const gint * cost, gint * assets)
125 {
126 	gint idx;
127 
128 	for (idx = 0; idx < NO_RESOURCE; idx++) {
129 		assets[idx] -= cost[idx];
130 		if (assets[idx] < 0)
131 			return FALSE;
132 	}
133 	return TRUE;
134 }
135 
cost_refund(const gint * cost,gint * assets)136 void cost_refund(const gint * cost, gint * assets)
137 {
138 	gint idx;
139 
140 	for (idx = 0; idx < NO_RESOURCE; idx++)
141 		assets[idx] += cost[idx];
142 }
143 
cost_can_afford(const gint * cost,const gint * assets)144 gboolean cost_can_afford(const gint * cost, const gint * assets)
145 {
146 	gint tmp[NO_RESOURCE];
147 
148 	gint idx;
149 
150 	for (idx = 0; idx < NO_RESOURCE; idx++)
151 		tmp[idx] = assets[idx];
152 
153 	return cost_buy(cost, tmp);
154 }
155