File: city.cpp

package info (click to toggle)
opencity 0.0.6.5stable-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 13,348 kB
  • sloc: cpp: 26,622; sh: 11,267; xml: 4,453; ansic: 587; makefile: 521
file content (2360 lines) | stat: -rw-r--r-- 63,405 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
/***************************************************************************
						city.cpp  -  description
							-------------------
	begin                : may 28th, 2003
	copyright            : (C) 2003-2008 by Duong Khang NGUYEN
	email                : neoneurone @ gmail com

	$Id: city.cpp 448 2010-05-09 15:18:32Z neoneurone $
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   any later version.                                                    *
 *                                                                         *
 ***************************************************************************/

// Useful enumerations
#include "opencity_direction.h"
#include "opencity_structure_type.h"

// OpenCity headers
#include "city.h"
#include "vehicle.h"
#include "mainsim.h"				// Simulator
#include "structure.h"
#include "buildinglayer.h"
#include "guibar.h"					// RCI bar
#include "guibutton.h"				// Tool button
#include "guilabel.h"				// Status label
#include "guicontainer.h"			// GUI control container
#include "agentpolice.h"
#include "agentdemonstrator.h"
#include "agentrobber.h"

// Global settings
#include "globalvar.h"
extern GlobalVar gVars;

// Standard headers
#include <sstream>					// For text output with data conversion

using namespace std;

// Local defines
#define OC_ACTION_FACTOR 10
#define GUIBUTTON_POSITION_TOOL		85, 4, 24, 24


   /*=====================================================================*/
City::City
(
	const uint width,
	const uint length,
	const bool bGUIEnabled
):
_bGUIEnabled( bGUIEnabled ),
_bStatusVisible( true ),
_uiIncome( 0 ),
_liCityFund( OC_FUND_START ),
_uiPopulation( 0 ),

_uiDay( 1 ),
_uiMonth( 1 ),
_uiYear( 0 ),

_uiWidth( width ),
_uiLength( length ),

_bLMBPressed( false ),
_eCurrentLayer( OC_LAYER_BUILDING ),
_eSpeed( OC_SPEED_NORMAL ),
_eCurrentTool( OC_TOOL_NONE ),

_pctrMenu( NULL )
{
	OPENCITY_DEBUG( "City ctor - default parameters" );

// Set the windows's WH
	_iWinWidth = gVars.guiScreenWidth;
	_iWinHeight = gVars.guiScreenHeight;

// Registering our call-back interface for SDL events' treatment
	ocSetNewUI( this );

// Keyboard bool table's initialization
	int i;
	for (i = 0; i < KEY_NUMBER; i++)
		_abKeyPressed[i] = false;

// Initialize the statistics
	Ressource res = {0, 0, 0, 0, 0, 0, 0, 0};
	for (i = 0; i < OC_MAX_RESSOURCE_RECORD; i++) {
		_dqRessource.push_back(res);
	}

// Layers' initialization
	_apLayer[ OC_LAYER_BUILDING ] = new BuildingLayer( *this );
	gVars.gpMapMgr->SetLayer( _apLayer[OC_LAYER_BUILDING] );

// Put few trees on the building layer
	_CreateTree();

// Pathfinder initialization
	gVars.gpPathFinder = new PathFinder(
		gVars.gpmutexSim,
		(BuildingLayer*)_apLayer[ OC_LAYER_BUILDING ],
		gVars.gpMapMgr,
		_uiWidth, _uiLength );

// Simulators' initialization
	_CreateSimulator();

	if (_bGUIEnabled) {
	// Debug toolcircle
		boolPathGo = false;
		uiPathStartW = 0; uiPathStartH = 0;
		uiPathStopW = 0; uiPathStopH = 0;
		_pctrPath = new GUIContainer( 100, 100, 140, 140, ocDataDirPrefix( "graphism/gui/toolcircle_bg.png" ));
		pbtnPathStart = new GUIButton( 20,  20,  30, 30, ocDataDirPrefix( "graphism/gui/raise" ));
		pbtnPathStop1 = new GUIButton( 60,  0,   30, 30, ocDataDirPrefix( "graphism/gui/lower" ));
		pbtnPathStop2 = new GUIButton( 100, 20,  30, 30, ocDataDirPrefix( "graphism/gui/lower" ));
		pbtnTestBuilding = new GUIButton(  20,  70, 30, 30, ocDataDirPrefix( "graphism/gui/residential" ));
		_pctrPath->Add( pbtnPathStart );
		_pctrPath->Add( pbtnPathStop1 );
		_pctrPath->Add( pbtnPathStop2 );
		_pctrPath->Add( pbtnTestBuilding );
		pvehicle = NULL;

	// Create the GUI
		_CreateGUI();
	}
}


   /*=====================================================================*/
City::~City()
{
	OPENCITY_DEBUG( "City dtor" );

	if (_bGUIEnabled) {
	// Delete the GUI
		_DeleteGUI();

	// testing, delete the pathfinder
		delete _pctrPath;
		delete pbtnTestBuilding;
		delete pbtnPathStart;
		delete pbtnPathStop1;
		delete pbtnPathStop2;
	}

// delete all the simulators
	_DeleteSimulator();

// Delete the pathfinder
	delete gVars.gpPathFinder;
	gVars.gpPathFinder = NULL;

// delete only the OC_LAYER_BUILDING instead of delete [] _apLayer
	delete _apLayer[ OC_LAYER_BUILDING ];
	_apLayer[ OC_LAYER_BUILDING ] = NULL;

// this must be done AFTER deleting the layers
//	delete gVars.gpMapMgr;
}


   /*=====================================================================*/
void
City::SaveTo( std::fstream& rfs )
{
	OPENCITY_DEBUG( __PRETTY_FUNCTION__ << "saving" );

// Save the data
	rfs << _uiIncome << std::ends;
	rfs << _liCityFund << std::ends;
	rfs << _uiPopulation << std::ends;
	rfs << _uiDay << std::ends;
	rfs << _uiMonth << std::ends;
	rfs << _uiYear << std::ends;
	rfs << _uiWidth << std::ends;
	rfs << _uiLength << std::ends;

// Store the ressource statistics
	Ressource res;
	int i;
	for (i = 0; i < OC_MAX_RESSOURCE_RECORD; i++) {
		res = _dqRessource[i];

		rfs << res.fund << std::ends;
		rfs << res.population << std::ends;
		rfs << res.r << std::ends;
		rfs << res.c << std::ends;
		rfs << res.i << std::ends;
		rfs << res.w << std::ends;
		rfs << res.e << std::ends;
		rfs << res.g << std::ends;
	}
}


   /*=====================================================================*/
void
City::LoadFrom( std::fstream& rfs )
{
	OPENCITY_DEBUG( __PRETTY_FUNCTION__ << "loading" );

// Load the data
	rfs >> _uiIncome; rfs.ignore();
	rfs >> _liCityFund; rfs.ignore();
	rfs >> _uiPopulation; rfs.ignore();
	rfs >> _uiDay; rfs.ignore();
	rfs >> _uiMonth; rfs.ignore();
	rfs >> _uiYear; rfs.ignore();
	rfs >> _uiWidth; rfs.ignore();
	rfs >> _uiLength; rfs.ignore();

// Load the ressource statistics
	Ressource res;
	int i;
	for (i = 0; i < OC_MAX_RESSOURCE_RECORD; i++) {
		rfs >> res.fund; rfs.ignore();
		rfs >> res.population; rfs.ignore();
		rfs >> res.r; rfs.ignore();
		rfs >> res.c; rfs.ignore();
		rfs >> res.i; rfs.ignore();
		rfs >> res.w; rfs.ignore();
		rfs >> res.e; rfs.ignore();
		rfs >> res.g; rfs.ignore();

		_dqRessource[i] = res;
	}
}


   /*=====================================================================*/
void City::SetCurrentLayer( OPENCITY_CITY_LAYER enumNewLayer )
{}


   /*=====================================================================*/
void City::Run()
{
	static uint uiNumberFrame = 0;

// Send the movement manager the move order
	gVars.gpMoveMgr->Move();

// IF the audio is enable THEN autoplay the background music
// TODO: optimize this
	if (gVars.gboolUseAudio && !gVars.gpAudioMgr->PlayingMusic()) {
		gVars.gpAudioMgr->PlayNextMusic();
	}

// Do not process further if we are in pause mode
	if (_eSpeed == OC_SPEED_PAUSE)
		return;

// IF not new day THEN return
	if ( ++uiNumberFrame*gVars.guiMsPerFrame <= OC_MS_PER_DAY )
		return;

// New day
	uint r = _pMSim->GetValue(Simulator::OC_RESIDENTIAL);
	uint c = _pMSim->GetValue(Simulator::OC_COMMERCIAL);
	uint i = _pMSim->GetValue(Simulator::OC_INDUSTRIAL);

	if ( ++_uiDay > 30 ) {
	// New month
		_uiDay = 1;

	// Calculate the current population
		_uiPopulation = r + c/2 + i/3;

		if ( ++_uiMonth > 12 ) {
		// New year
			_uiMonth = 1;
			_uiYear++;

			_DoBill( OC_INCOME );
			_RecordRessource();
		}
		else {
			_DoBill( OC_MAINTENANCE_COST );
		}
	}
	uiNumberFrame = 0;

// IF the GUI is not enabled THEN do not update it
	if (!_bGUIEnabled)
		return;

// Update the GUI information every 3 days
	if ( _uiDay%3 == 0 ) {
		uint initialValue = 0;

	// Update the RCI bar value
		initialValue = (r+c+i) + 1;
		_pbarResidence->SetInitialValue( initialValue );
		_pbarCommerce->SetInitialValue( initialValue );
		_pbarIndustry->SetInitialValue( initialValue );
		_pbarResidence->SetValue( r );
		_pbarCommerce->SetValue( c );
		_pbarIndustry->SetValue( i );

	// Update the power bar value
		initialValue = _pMSim->GetMaxValue(Simulator::OC_ELECTRIC) + 1;
		_pbarPower->SetInitialValue( initialValue );
		uint p = _pMSim->GetValue(Simulator::OC_ELECTRIC) > 0 ? _pMSim->GetValue(Simulator::OC_ELECTRIC) : 0;
		_pbarPower->SetValue( p );

	// Request the renderer to update the minimap
		gVars.gpRenderer->bMinimapChange = true;
	}
}


   /*=====================================================================*/
void City::Display()
{
	static ostringstream ossStatus;
	static bool boolKeyDown;
	static int iMouseX, iMouseY;


// Process key events such as: up, down, left, right etc..
	boolKeyDown = _HandleKeyPressed();

// IF the mouse reach the border of the screen, translate the map
// NOTE: unused at the moment because it disturbs the GUI
//	_HandleMouseXY();

// NOTE: We can move the following part to City::uiMouseMotion
// however, in this case City::uiMouseMotion is called each time
// when the mouse moves, and this is no good.
// The user is dragging
	if ((_bLMBPressed == true) && (_eCurrentTool != OC_TOOL_NONE )) {
	// IF the user is dragging with the left mouse button THEN
		if ( SDL_GetMouseState( &iMouseX, &iMouseY ) & SDL_BUTTON(1) ) {
			gVars.gpRenderer->GetSelectedWLFrom(
				iMouseX, iMouseY,
				_uiMapW2, _uiMapL2,
				gVars.gpMapMgr, _apLayer[ _eCurrentLayer ] );

		// draw the map with the highlighted area
			gVars.gpRenderer->DisplayHighlight(
				gVars.gpMapMgr, _apLayer[ _eCurrentLayer ],
				_uiMapW1, _uiMapL1,
				_uiMapW2, _uiMapL2,
				_eCurrentTool );

			goto cityrun_swap;
		}
	}

// Display the screen as usual
	gVars.gpRenderer->Display( gVars.gpMapMgr, _apLayer[ _eCurrentLayer ] );

cityrun_swap:
// Display build preview
	_BuildPreview();

// Display the city's funds
	ossStatus.str("");
	ossStatus << _liCityFund;
	_plblFund->SetText( ossStatus.str() );

// Display the city population
	ossStatus.str("");
	ossStatus << _uiPopulation;
	_plblPopulation->SetText( ossStatus.str() );

// display the date
	ossStatus.str("");
	ossStatus << _uiDay << "/" << _uiMonth << "/" << _uiYear;
	_plblDate->SetText( ossStatus.str() );


// Display all the contained movements
//	gVars.gpMoveMgr->Move();		// called by Run()
	gVars.gpMoveMgr->Display();

// FIXME: buggy MAS environment
//	gVars.gpEnvironment->displayAgent();

// Display the status bar
	_pctrStatus->Display();

// Display the current container
	_pctr->Display();

// Display the menu
	if (_pctrMenu != NULL)
		_pctrMenu->Display();

// Swap the buffers and update the screen
	SDL_GL_SwapBuffers();
}


   /*=====================================================================*/
Layer*
City::GetLayer( OPENCITY_CITY_LAYER enumLayer ) const
{
	return _apLayer[ enumLayer ];
}


   /*=====================================================================*/
const void
City::GetWL(
	uint & w, uint & l ) const
{
	w = _uiWidth;
	l = _uiLength;
}


   /*=====================================================================*/
   /*                    BASE CLASS 'UI' IMPLEMENTATION                   */
   /*=====================================================================*/



   /*=====================================================================*/
void City::Keyboard( const SDL_KeyboardEvent& rcEvent )
{
//	OPENCITY_DEBUG( "Keydown event received" );

// SDL_KEYDOWN or SDL_PRESSED
	if (rcEvent.type == SDL_KEYDOWN) {
	// test if ALT is pressed
		if (rcEvent.keysym.mod & KMOD_ALT) {
			_abKeyPressed[KEY_ALT] = true;
		}

	// key symbols treatment
		switch (rcEvent.keysym.sym) {
		case SDLK_PAGEUP:
			_abKeyPressed[KEY_PAGEUP] = true;
			break;
		case SDLK_PAGEDOWN:
			_abKeyPressed[KEY_PAGEDOWN] = true;
			break;

		case SDLK_UP:
			_abKeyPressed[KEY_UP] = true;
			break;
		case SDLK_DOWN:
			_abKeyPressed[KEY_DOWN] = true;
			break;
		case SDLK_RIGHT:
			_abKeyPressed[KEY_RIGHT] = true;
			break;
		case SDLK_LEFT:
			_abKeyPressed[KEY_LEFT] = true;
			break;

	// Establish a connection to OCZen
		case SDLK_z:
			OPENCITY_NET_CODE netCode;
			netCode = gVars.gpNetworking->Open( gVars.gsZenServer );
			switch (netCode) {
				case OC_NET_CLIENT_CONNECTED:
					OPENCITY_INFO( "OpenCity is already connected to a server." );
					break;
				case OC_NET_CLIENT_ACCEPTED:
					OPENCITY_INFO( "The connection request has been accepted." );
					break;
				case OC_NET_CLIENT_REJECTED:
					OPENCITY_INFO( "The connection request has been rejected. Is the server full ?" );
					break;
				default:
					OPENCITY_INFO( "The connection to \"" << gVars.gsZenServer << "\" has failed." );
			}
			break;

		case SDLK_n:	// set the tool to "None"
			_SetCurrentTool(  OC_TOOL_NONE );
			break;
		case SDLK_r:	// set tool for "zone residential"
			_SetCurrentTool( OC_TOOL_ZONE_RES );
			break;
		case SDLK_c:	// set tool for "zone commercial"
			_SetCurrentTool( OC_TOOL_ZONE_COM );
			break;
		case SDLK_i:	// set tool for "zone industrial"
			_SetCurrentTool( OC_TOOL_ZONE_IND );
			break;

		case SDLK_p:	// set tool for "building road"
			_SetCurrentTool( OC_TOOL_ROAD );
			break;
		case SDLK_l:	// set tool for building electric lines
			_SetCurrentTool( OC_TOOL_ELINE );
			break;
		case SDLK_e:	// set tool for building electric plants
			_SetCurrentTool( OC_TOOL_EPLANT_NUCLEAR );
			break;

		case SDLK_u:	// height up
			_SetCurrentTool( OC_TOOL_HEIGHT_UP );
			break;
		case SDLK_d:	// height down
			_SetCurrentTool( OC_TOOL_HEIGHT_DOWN );
			break;
		case SDLK_q:	//query tool
			_SetCurrentTool( OC_TOOL_QUERY );
			break;
		case SDLK_x:	// destroy
			_SetCurrentTool( OC_TOOL_DESTROY );
			break;


		case SDLK_b:	// toggle structures on/off
			gVars.gpRenderer->ToggleStructure();
			break;
		case SDLK_f:	// toggle wireframe on/off
			gVars.gpRenderer->ToggleWireFrame();
			break;
		case SDLK_g:	// toggle grid on/off
			gVars.gpRenderer->ToggleGrid();
			break;
		case SDLK_k:	// toggle compass on/off
		// Do not mess up the menu
			if (_pctrMenu != NULL)
				break;

			_bStatusVisible = !_bStatusVisible;
			gVars.gpRenderer->ToggleCompass();
			if (_bStatusVisible)
				_pctrStatus->Set( OC_GUIMAIN_VISIBLE );
			else
				_pctrStatus->Unset( OC_GUIMAIN_VISIBLE );
			break;
		case SDLK_o:	// toggle projection mode
			gVars.gpRenderer->ToggleProjection();
			break;
		case SDLK_t:	// toggle terrain display
			gVars.gpRenderer->ToggleTerrain();
			break;
		case SDLK_w:	// toggle water display
			gVars.gpRenderer->ToggleWater();
			break;


		case SDLK_INSERT: // zoom in
			_abKeyPressed[KEY_INSERT] = true;
			break;
		case SDLK_DELETE: // zoom out
			_abKeyPressed[KEY_DELETE] = true;
			break;


	// manipulating the music player
		case SDLK_GREATER:
			gVars.gpAudioMgr->PlayNextMusic();
			break;
		case SDLK_LESS:
			gVars.gpAudioMgr->PlayPreviousMusic();
			break;
		case SDLK_s:
			gVars.gpAudioMgr->ToggleSound();
			break;
		case SDLK_m:
			gVars.gpAudioMgr->ToggleMusic();
			break;


	// Save and load
		case SDLK_F2:
			_Save( ocSaveDirPrefix( "opencity.save" ) );
			break;
		case SDLK_F6:
			_Load( ocSaveDirPrefix( "opencity.save" ) );
			break;


		case SDLK_h:
			gVars.gpRenderer->Home();
			break;


		case SDLK_ESCAPE:	// Open/close the main menu
			if (_pctrMenu == NULL) {
				_LoadMenu();
			}
			else {
				_UnloadMenu();
			}
			break;

#ifndef NDEBUG
	// Testing PathFinder
		case SDLK_a:
			_pctr->ResetAttribute( OC_GUIMAIN_CLICKED | OC_GUIMAIN_MOUSEOVER );

		// Toggle Main <-> Pathfinding toolcircle
			if (_pctr == _pctrPath ) {
				_pctr = _pctrMain;
			}
			else {
				_pctr = _pctrPath;
			}
			if ( _pctr->IsSet( OC_GUIMAIN_VISIBLE ) == false ) {
				_pctr->Set( OC_GUIMAIN_VISIBLE );
			}
			break;

	// MAS test toolcircle
		case SDLK_v:
			_pctr->ResetAttribute( OC_GUIMAIN_CLICKED | OC_GUIMAIN_MOUSEOVER );

		// Toggle Main <-> MAS toolcircle
			if ( _pctr == _pctrMAS ) {
				_pctr = _pctrMain;
			}
			else {
				_pctr = _pctrMAS;
			}
			if ( _pctr->IsSet( OC_GUIMAIN_VISIBLE ) == false ) {
				_pctr->Set( OC_GUIMAIN_VISIBLE );
			}
			break;
#endif

		default:
			break;
		}
	}
// SDL_KEYUP or SDL_RELEASED
	else {
	// test if ALT is released
		if (!(rcEvent.keysym.mod & KMOD_ALT)) {
			_abKeyPressed[KEY_ALT] = false;
		}

	// other key symbols treatment
		switch (rcEvent.keysym.sym) {

		case SDLK_PAGEUP:
			_abKeyPressed[KEY_PAGEUP] = false;
			break;
		case SDLK_PAGEDOWN:
			_abKeyPressed[KEY_PAGEDOWN] = false;
			break;

		case SDLK_UP:
			_abKeyPressed[KEY_UP] = false;
			break;
		case SDLK_DOWN:
			_abKeyPressed[KEY_DOWN] = false;
			break;
		case SDLK_RIGHT:
			_abKeyPressed[KEY_RIGHT] = false;
			break;
		case SDLK_LEFT:
			_abKeyPressed[KEY_LEFT] = false;
			break;

		case SDLK_INSERT: // zoom in
			_abKeyPressed[KEY_INSERT] = false;
			break;
		case SDLK_DELETE: // zoom out
			_abKeyPressed[KEY_DELETE] = false;
			break;

		default:
			break;
		} // switch
	} // key released

}


   /*=====================================================================*/
void
City::MouseMotion( const SDL_MouseMotionEvent& rcEvent )
{
//	OPENCITY_DEBUG("Mouse moved");

// We process the menu first
	if (_pctrMenu != NULL) {
		_pctrMenu->MouseMotion( rcEvent );
	}
	else {
		_pctr->MouseMotion( rcEvent );
		_pctrStatus->MouseMotion( rcEvent );
	}
}


   /*=====================================================================*/
void
City::MouseButton( const SDL_MouseButtonEvent& rcsMBE )
{
//	OPENCITY_DEBUG("Mouse button event received" );

// IF the menu is opened THEN process the mouse click on the menu and return
	if (_pctrMenu != NULL ) {
		_pctrMenu->MouseButton( rcsMBE );
		if ( _pctrMenu->GetClick() != 0 ) {
			_HandleMenuClick();
			_bLMBPressed = false;
		}
		return;
	}

// Process the mouse click on the status bar
	_pctrStatus->MouseButton( rcsMBE );
	if ( _pctrStatus->GetClick() != 0 ) {
		_HandleStatusClick();
		_bLMBPressed = false;
		return;
	}

// Process the click concerning the GUI
	_pctr->MouseButton( rcsMBE );
	if ( _pctr->GetClick() != 0 ) {
		_HandleGUIClick();
		_bLMBPressed = false;
		return;
	}

// The user didn't click on a GUI object so we look for clicks on the map
	switch (rcsMBE.state) {
		case SDL_PRESSED: {
			_bLMBPressed = false;
			if ((rcsMBE.button == SDL_BUTTON_LEFT)
				and
				(gVars.gpRenderer->GetSelectedWLFrom(
					rcsMBE.x, rcsMBE.y, _uiMapW1, _uiMapL1,
					gVars.gpMapMgr, _apLayer[ _eCurrentLayer ]) == true))
			{
				_bLMBPressed = true;
			} //if
//debug begin
//SDL_GL_SwapBuffers(); // uncomment this if you want to know how it works
//SDL_Delay( 500 );
//debug end

		// RMB (right mouse button) close/open the toolcircle
			if (rcsMBE.button == SDL_BUTTON_RIGHT) {
			// IF the user has invoked "Query" THEN we destroy it first
				if (_pctr == _pctrQ) {
					_pctr = _pctrMain;
				// Enable the visible bit since, it is disabled later
				// the main toolcircle won't be displayed
					_pctr->Set( OC_GUIMAIN_VISIBLE );
				}

				if (_pctr->IsSet( OC_GUIMAIN_VISIBLE ) == true) {
					_pctr->Unset( OC_GUIMAIN_VISIBLE );
				}
				else {
					_pctr->SetLocation( rcsMBE.x - 70, _iWinHeight - rcsMBE.y - 70 );
					_pctr->Set( OC_GUIMAIN_VISIBLE );
				}
			}

		// Wheel button forward
			if (rcsMBE.button == 4) {
			// move right if CTRL pressed
				if (SDL_GetModState() & KMOD_CTRL)
					gVars.gpRenderer->MoveRight();

			// move up if SHIFT pressed
				if (SDL_GetModState() & KMOD_SHIFT)
					gVars.gpRenderer->MoveUp();

			// zoom in if nothing pressed
				if (!(SDL_GetModState() & (KMOD_SHIFT | KMOD_CTRL)))
					gVars.gpRenderer->ZoomIn();
			}

		// Wheel button backward
			if (rcsMBE.button == 5) {
			// move right if CTRL pressed
				if (SDL_GetModState() & KMOD_CTRL)
					gVars.gpRenderer->MoveLeft();

			// move up if SHIFT pressed
				if (SDL_GetModState() & KMOD_SHIFT)
					gVars.gpRenderer->MoveDown();

			// zoom in if nothing pressed
				if (!(SDL_GetModState() & (KMOD_SHIFT | KMOD_CTRL)))
					gVars.gpRenderer->ZoomOut();
			}

		break;
		} //case SDL_PRESSED

	   //-------------------------------------------------------
		case SDL_RELEASED: {
			// IF Ctrl not pressed,
			// AND dragging enabled
			// AND mouse button was correctly released in the map
			// THEN do tool
			if (not (SDL_GetModState() & KMOD_CTRL)
				and _bLMBPressed
				and gVars.gpRenderer->GetSelectedWLFrom(
					rcsMBE.x, rcsMBE.y,
					_uiMapW2, _uiMapL2,
					gVars.gpMapMgr,
					_apLayer[ _eCurrentLayer ] ))
			{
//debug
//cout << "W2: " << _uiMapW2 << "/" << "H2: "
//     << _uiMapL2 << endl;
//test pathfinding
				_TestPathfinding();
				_DoTool( rcsMBE );
			} //if
			_bLMBPressed = false;
			break;

		} //case SDL_RELEASED

	} // switch
}


   /*=====================================================================*/
void
City::Expose( const SDL_ExposeEvent& rcEvent )
{
	OPENCITY_DEBUG( "Expose event received" );

	gVars.gpRenderer->Display( gVars.gpMapMgr, _apLayer[ _eCurrentLayer ] );
	_pctr->Expose( rcEvent );
	_pctrStatus->Expose( rcEvent );
	if (_pctrMenu != NULL) {
		_pctrMenu->Expose( rcEvent );
	}

	SDL_GL_SwapBuffers();
}


   /*=====================================================================*/
void City::Resize( const SDL_ResizeEvent& rcEvent )
{
	OPENCITY_DEBUG( "Resize event received" );

// Set the new window's size
	_iWinWidth = rcEvent.w;
	_iWinHeight = rcEvent.h;
	gVars.gpRenderer->SetWinSize( _iWinWidth, _iWinHeight );

// Resize the main status bar and reposition it
	_pctrStatus->Resize( rcEvent );
	_pctrStatus->SetLocation( (_iWinWidth-512)/2, 0 );

// Tell the containers about the event
	_pctrMain->Resize( rcEvent );
	_pctrL->Resize( rcEvent );
	_pctrT->Resize( rcEvent );
	_pctrZ->Resize( rcEvent );
	_pctrG->Resize( rcEvent );
	_pctrN->Resize( rcEvent );
	_pctrS->Resize( rcEvent );
	_pctrPath->Resize( rcEvent );
	_pctrMAS->Resize( rcEvent );

	if (_pctrMenu != NULL) {
		_pctrMenu->Resize( rcEvent );
		_pctrMenu->SetSize( _iWinWidth, _iWinHeight );
		_CenterMenu();
	}

// IF the query tool is displayed THEN invoke the resize event
	if (_pctrQ != NULL) {
		_pctrQ->Resize( rcEvent );
	}
}














   /*=====================================================================*/
   /*                        PRIVATE     METHODS                          */
   /*=====================================================================*/






void City::_CreateTree()
{
// Create a new tree density map
	int* treeDensity = gVars.gpMapMaker->getTreeDensity();

// Build the trees according to the density map
	uint cost = 0;
	for (uint l = 0, linear = 0; l < _uiLength; l++)
	for (uint w = 0; w < _uiWidth; w++, linear++) {
		if (treeDensity[linear] > 0) {
			_apLayer[ OC_LAYER_BUILDING ]->BuildStructure( w, l, w, l, OC_STRUCTURE_FLORA, cost );
		}
	}

	delete [] treeDensity;
}


   /*=====================================================================*/
void City::_CreateSimulator()
{
// Simulators' initialization
	_pMSim = new MainSim( gVars.gpmutexSim, (BuildingLayer*)_apLayer[ OC_LAYER_BUILDING ], gVars.gpMapMgr );

// Now initialize simulators threads
	_pthreadMSim = SDL_CreateThread( Simulator::ThreadWrapper, _pMSim );

// Kept for future reference
// How can I put funcTSim into the TrafficSim class ?
//
//	int (*fn)(void*);
//	fn = reinterpret_cast<int (*)(void*)>(&TrafficSim::Run);
//	pthreadTSim = SDL_CreateThread( TrafficSim::Run, pTSim );
//

// Put all the simulators' threads into RUN state
	_pMSim->Run();
}


   /*=====================================================================*/
void
City::_DeleteSimulator()
{
	int iStatus;

// put all the simulators' threads into RETURN state
	_pMSim->Return();

// wait for simulator threads to end
	SDL_WaitThread( _pthreadMSim, &iStatus );

// delete simulators at the end
	delete _pMSim;
}


   /*=====================================================================*/
void
City::_CreateGUI()
{
	ostringstream ossTemp;

// Load the buttons used by the status bar
	_apbtnCurrentTool[OC_TOOL_NONE]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/unknown" ));
	_apbtnCurrentTool[OC_TOOL_DESTROY]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/destroy" ));
	_apbtnCurrentTool[OC_TOOL_ZONE_RES]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/residential" ));
	_apbtnCurrentTool[OC_TOOL_ZONE_COM]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/commercial" ));
	_apbtnCurrentTool[OC_TOOL_ZONE_IND]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/industrial" ));
	_apbtnCurrentTool[OC_TOOL_HEIGHT_UP]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/raise" ));
	_apbtnCurrentTool[OC_TOOL_HEIGHT_DOWN]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/lower" ));
	_apbtnCurrentTool[OC_TOOL_ROAD]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/road" ));
	_apbtnCurrentTool[OC_TOOL_ELINE]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/power_line" ));
	_apbtnCurrentTool[OC_TOOL_EPLANT_COAL]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/power_plant_coal" ));
	_apbtnCurrentTool[OC_TOOL_EPLANT_NUCLEAR]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/power_plant_nuclear" ));
	_apbtnCurrentTool[OC_TOOL_PARK]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/park" ));
	_apbtnCurrentTool[OC_TOOL_FLORA]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/tree" ));
	_apbtnCurrentTool[OC_TOOL_FIRE]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/fire" ));

	_apbtnCurrentTool[OC_TOOL_POLICE]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/police" ));
	_apbtnCurrentTool[OC_TOOL_HOSPITAL]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/hospital" ));
	_apbtnCurrentTool[OC_TOOL_EDUCATION]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/education" ));
	_apbtnCurrentTool[OC_TOOL_QUERY]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/query" ));

	_apbtnCurrentTool[OC_TOOL_AGENT_POLICE]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/unknown" ));
	_apbtnCurrentTool[OC_TOOL_AGENT_DEMONSTRATOR]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/unknown" ));
	_apbtnCurrentTool[OC_TOOL_AGENT_ROBBER]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/unknown" ));
	_apbtnCurrentTool[OC_TOOL_TEST_BUILDING]
		= new GUIButton( GUIBUTTON_POSITION_TOOL, ocDataDirPrefix( "graphism/gui/status/unknown" ));

// The status bar
	_pbtnPause = new GUIButton( 54, 4, 24, 24, ocDataDirPrefix( "graphism/gui/status/speed_pause" ));
	_pbtnPlay  = new GUIButton( 54, 4, 24, 24, ocDataDirPrefix( "graphism/gui/status/speed_play" ));
	_pbtnPause->Unset( OC_GUIMAIN_VISIBLE );

	ossTemp << _liCityFund;
	_plblFund = new GUILabel( 125, 11, 80, 10, ossTemp.str() );
	_plblFund->SetAlign( GUILabel::OC_ALIGN_RIGHT );
	_plblFund->SetForeground( OPENCITY_PALETTE[Color::OC_WHITE] );

	ossTemp.str("");
	ossTemp << _uiPopulation;
	_plblPopulation = new GUILabel( 240, 11, 80, 10, ossTemp.str() );
	_plblPopulation->SetAlign( GUILabel::OC_ALIGN_RIGHT );
	_plblPopulation->SetForeground( OPENCITY_PALETTE[Color::OC_WHITE] );

	ossTemp.str("");
	ossTemp << _uiDay << "/" << _uiMonth << "/" << _uiYear;
	_plblDate = new GUILabel( 348, 11, 80, 10, ossTemp.str() );
	_plblDate->SetAlign( GUILabel::OC_ALIGN_CENTER );
	_plblDate->SetForeground( OPENCITY_PALETTE[Color::OC_WHITE] );

	_pbarResidence = new GUIBar( 5, 5, 7, 53 );
	_pbarResidence->SetForeground( OPENCITY_PALETTE[Color::OC_GREEN] );

	_pbarCommerce = new GUIBar( 18, 5, 7, 53 );
	_pbarCommerce->SetForeground( OPENCITY_PALETTE[Color::OC_BLUE] );

	_pbarIndustry = new GUIBar( 29, 5, 7, 53 );
	_pbarIndustry->SetForeground( OPENCITY_PALETTE[Color::OC_YELLOW] );

	_pbarPower = new GUIBar( 42, 5, 7, 53 );
	_pbarPower->SetForeground( OPENCITY_PALETTE[Color::OC_PINK] );

	_pctrStatus =
		new GUIContainer( (_iWinWidth-512)/2, 0, 512, 64, ocDataDirPrefix( "graphism/gui/main_status_bar.png" ) );
	_pctrStatus->Add( _pbtnPause );
	_pctrStatus->Add( _pbtnPlay );
	_pctrStatus->Add( _plblFund );
	_pctrStatus->Add( _plblPopulation );
	_pctrStatus->Add( _plblDate );
	_pctrStatus->Add( _pbarResidence );
	_pctrStatus->Add( _pbarCommerce );
	_pctrStatus->Add( _pbarIndustry );
	_pctrStatus->Add( _pbarPower );
	_pctrStatus->Set( OC_GUIMAIN_VISIBLE );

// The status bar buttons
	for (int i = 0; i < OC_TOOL_NUMBER; i++) {
		_apbtnCurrentTool[i]->Unset( OC_GUIMAIN_VISIBLE );
		_pctrStatus->Add( _apbtnCurrentTool[i] );
	}
	_apbtnCurrentTool[OC_TOOL_NONE]->Set( OC_GUIMAIN_VISIBLE );

// GUI main toolcircle
	pbtnZ = new GUIButton( GUIBUTTON_POSITION_1, ocDataDirPrefix( "graphism/gui/zone" ));
	pbtnS = new GUIButton( GUIBUTTON_POSITION_5, ocDataDirPrefix( "graphism/gui/save" ));
	pbtnL = new GUIButton( GUIBUTTON_POSITION_2, ocDataDirPrefix( "graphism/gui/power" ));
	pbtnP = new GUIButton( GUIBUTTON_POSITION_3, ocDataDirPrefix( "graphism/gui/road" ));
	pbtnX = new GUIButton( GUIBUTTON_POSITION_4, ocDataDirPrefix( "graphism/gui/bulldozer" ));
	pbtnG = new GUIButton( GUIBUTTON_POSITION_6, ocDataDirPrefix( "graphism/gui/government" ));

	_pctrMain = new GUIContainer( 100, 100, 140, 140, ocDataDirPrefix( "graphism/gui/toolcircle_bg.png" ) );
	_pctrMain->Add( pbtnZ );
	_pctrMain->Add( pbtnS );
	_pctrMain->Add( pbtnL );
	_pctrMain->Add( pbtnP );
	_pctrMain->Add( pbtnX );
	_pctrMain->Add( pbtnG );


// GUI Z toolcircle for RCI buttons
	pbtnZB = new GUIButton( GUIBUTTON_POSITION_1, ocDataDirPrefix( "graphism/gui/back" ));
	pbtnZR = new GUIButton( GUIBUTTON_POSITION_2, ocDataDirPrefix( "graphism/gui/residential" ));
	pbtnZC = new GUIButton( GUIBUTTON_POSITION_3, ocDataDirPrefix( "graphism/gui/commercial" ));
	pbtnZI = new GUIButton( GUIBUTTON_POSITION_4, ocDataDirPrefix( "graphism/gui/industrial" ));

	_pctrZ = new GUIContainer( 100, 100, 140, 140, ocDataDirPrefix( "graphism/gui/toolcircle_bg.png" ) );
	_pctrZ->Add( pbtnZB );
	_pctrZ->Add( pbtnZR );
	_pctrZ->Add( pbtnZC );
	_pctrZ->Add( pbtnZI );


// GUI L toolcircle ( electric lines, electric plants )
	pbtnLB = new GUIButton( GUIBUTTON_POSITION_2, ocDataDirPrefix( "graphism/gui/back" ));
	pbtnLL = new GUIButton( GUIBUTTON_POSITION_3, ocDataDirPrefix( "graphism/gui/power_line" ));
	pbtnLN = new GUIButton( GUIBUTTON_POSITION_4, ocDataDirPrefix( "graphism/gui/power_plant_nuclear" ));
	pbtnLC = new GUIButton( GUIBUTTON_POSITION_5, ocDataDirPrefix( "graphism/gui/power_plant_coal" ));

	_pctrL = new GUIContainer( 100, 100, 140, 140, ocDataDirPrefix( "graphism/gui/toolcircle_bg.png" ) );
	_pctrL->Add( pbtnLB );
	_pctrL->Add( pbtnLL );
	_pctrL->Add( pbtnLN );
	_pctrL->Add( pbtnLC );


// GUI T toolcircle ( raise, lower terrain )
	pbtnTU = new GUIButton( GUIBUTTON_POSITION_2, ocDataDirPrefix( "graphism/gui/raise" ));
	pbtnTD = new GUIButton( GUIBUTTON_POSITION_3, ocDataDirPrefix( "graphism/gui/lower" ));
	pbtnTB = new GUIButton( GUIBUTTON_POSITION_4, ocDataDirPrefix( "graphism/gui/back" ));
	pbtnTX = new GUIButton( GUIBUTTON_POSITION_1, ocDataDirPrefix( "graphism/gui/destroy" ));
	pbtnTQ = new GUIButton( GUIBUTTON_POSITION_5, ocDataDirPrefix( "graphism/gui/query" ));

	_pctrT = new GUIContainer( 100, 100, 140, 140, ocDataDirPrefix( "graphism/gui/toolcircle_bg.png" ) );
	_pctrT->Add( pbtnTB );
	_pctrT->Add( pbtnTU );
	_pctrT->Add( pbtnTD );
	_pctrT->Add( pbtnTX );
	_pctrT->Add( pbtnTQ );


// GUI Gouvernement toolcircle ( park, education, hospital, police and fire )
	pbtnGB = new GUIButton( GUIBUTTON_POSITION_6, ocDataDirPrefix( "graphism/gui/back" ));
	pbtnGP = new GUIButton( GUIBUTTON_POSITION_1, ocDataDirPrefix( "graphism/gui/park" ));
	pbtnGE = new GUIButton( GUIBUTTON_POSITION_5, ocDataDirPrefix( "graphism/gui/education" ));
	pbtnGH = new GUIButton( GUIBUTTON_POSITION_2, ocDataDirPrefix( "graphism/gui/hospital" ));
	pbtnGL = new GUIButton( GUIBUTTON_POSITION_3, ocDataDirPrefix( "graphism/gui/police" ));
	pbtnGF = new GUIButton( GUIBUTTON_POSITION_4, ocDataDirPrefix( "graphism/gui/fire" ));

	_pctrG = new GUIContainer( 100, 100, 140, 140, ocDataDirPrefix( "graphism/gui/toolcircle_bg.png" ) );
	_pctrG->Add( pbtnGB );
	_pctrG->Add( pbtnGP );
	_pctrG->Add( pbtnGE );
	_pctrG->Add( pbtnGH );
	_pctrG->Add( pbtnGL );
	_pctrG->Add( pbtnGF );


// Create the nature container
	pbtnNB = new GUIButton( GUIBUTTON_POSITION_1, ocDataDirPrefix( "graphism/gui/back" ));
	pbtnNP = new GUIButton( GUIBUTTON_POSITION_6, ocDataDirPrefix( "graphism/gui/park_city" ));
	pbtnNT = new GUIButton( GUIBUTTON_POSITION_5, ocDataDirPrefix( "graphism/gui/tree" ));

	_pctrN = new GUIContainer( 100, 100, 140, 140, ocDataDirPrefix( "graphism/gui/toolcircle_bg.png" ) );
	_pctrN->Add( pbtnNB );
	_pctrN->Add( pbtnNP );
	_pctrN->Add( pbtnNT );


// Create save/load buttons and the container
	pbtnSL = new GUIButton( GUIBUTTON_POSITION_1, ocDataDirPrefix( "graphism/gui/save_load" ));
	pbtnSS = new GUIButton( GUIBUTTON_POSITION_6, ocDataDirPrefix( "graphism/gui/save_save" ));
	pbtnSB = new GUIButton( GUIBUTTON_POSITION_5, ocDataDirPrefix( "graphism/gui/back" ));

	_pctrS = new GUIContainer( 100, 100, 140, 140, ocDataDirPrefix( "graphism/gui/toolcircle_bg.png" ) );
	_pctrS->Add( pbtnSB );
	_pctrS->Add( pbtnSS );
	_pctrS->Add( pbtnSL );


// MAS toolcircle
	_pctrMAS = new GUIContainer( 100, 100, 140, 140 );
	pbtnMASPolice = new GUIButton( 20,  20,  30, 30, ocDataDirPrefix( "graphism/gui/police" ));
	pbtnMASDemonstrator = new GUIButton( 60,  0,   30, 30, ocDataDirPrefix( "graphism/gui/demonstrator" ));
	pbtnMASRobber = new GUIButton( 100, 20,  30, 30, ocDataDirPrefix( "graphism/gui/robber" ));
	_pctrMAS->Add( pbtnMASPolice );
	_pctrMAS->Add( pbtnMASDemonstrator );
	_pctrMAS->Add( pbtnMASRobber );

	pbtnMASRobber->Unset( OC_GUIMAIN_VISIBLE );

// the current _pctr points to the MAIN one
	_pctr = _pctrMain;

// there isn't a query container
	_pctrQ = NULL;
}


   /*=====================================================================*/
void
City::_DeleteGUI()
{
	_pctrQ = NULL;

// MAS toolcircle
	delete _pctrMAS;
	delete pbtnMASRobber;
	delete pbtnMASDemonstrator;
	delete pbtnMASPolice;

// Load/save toolcircle
	delete _pctrS;
	delete pbtnSB;
	delete pbtnSS;
	delete pbtnSL;

// Nature toolcircle
	delete _pctrN;
	delete pbtnNB;
	delete pbtnNP;
	delete pbtnNT;

// GUI G toolcircle ( park, education, hospital, police and fire )
	delete _pctrG;
	delete pbtnGB;
	delete pbtnGP;
	delete pbtnGE;
	delete pbtnGH;
	delete pbtnGL;
	delete pbtnGF;

// GUI T toolcircle ( raise, lower terrain )
	delete _pctrT;
	delete pbtnTB;
	delete pbtnTU;
	delete pbtnTD;
	delete pbtnTX;
	delete pbtnTQ;

// GUI L toolcircle ( electric lines, electric plants )
	delete _pctrL;
	delete pbtnLB;
	delete pbtnLL;
	delete pbtnLN;
	delete pbtnLC;

// GUI Z toolcircle
	delete _pctrZ;
	delete pbtnZB;
	delete pbtnZR;
	delete pbtnZC;
	delete pbtnZI;

// GUI main toolcircle
	delete _pctrMain;
	delete pbtnZ;
	delete pbtnS;
	delete pbtnL;
	delete pbtnP;
	delete pbtnX;
	delete pbtnG;

// Delete the status bar
	delete _pctrStatus;
	delete _pbarPower;
	delete _pbarIndustry;
	delete _pbarCommerce;
	delete _pbarResidence;
	delete _plblFund;
	delete _plblPopulation;
	delete _plblDate;
	delete _pbtnPlay;
	delete _pbtnPause;

// The status bar buttons
	for (int i = 0; i < OC_TOOL_NUMBER; i++) {
		delete _apbtnCurrentTool[i];
		_apbtnCurrentTool[i] = NULL;		// Safe
	}
}


   /*=====================================================================*/
void
City::_LoadMenu()
{
	_pbtnMenuNew  = new GUIButton( 0, 0, 128, 128, ocDataDirPrefix("graphism/gui/main_menu_new") );
	_pbtnMenuLoad = new GUIButton( 0, 0, 128, 128, ocDataDirPrefix("graphism/gui/main_menu_load") );
	_pbtnMenuSave = new GUIButton( 0, 0, 128, 128, ocDataDirPrefix("graphism/gui/main_menu_save") );
	_pbtnMenuQuit = new GUIButton( 0, 0, 128, 128, ocDataDirPrefix("graphism/gui/main_menu_quit") );

	_pctrMenu = new GUIContainer(
		0, 0, _iWinWidth, _iWinHeight, ocDataDirPrefix("graphism/gui/main_menu_bg.png")
	);
	_pctrMenu->Add( _pbtnMenuNew );
	_pctrMenu->Add( _pbtnMenuLoad );
	_pctrMenu->Add( _pbtnMenuSave );
	_pctrMenu->Add( _pbtnMenuQuit );
	_pctrMenu->Set( OC_GUIMAIN_VISIBLE );

// Hide the status bar and the compass
	if (_bStatusVisible) {
		gVars.gpRenderer->ToggleCompass();
		_pctrStatus->Unset( OC_GUIMAIN_VISIBLE );
	}

	_CenterMenu();
}


   /*=====================================================================*/
void
City::_CenterMenu()
{
	assert( _pctrMenu != NULL );

// Center the menu
	int x = _iWinWidth/2;
	int y = _iWinHeight/2;
	_pbtnMenuNew->SetLocation( x-264, y );
	_pbtnMenuLoad->SetLocation( x-64, y );
	_pbtnMenuSave->SetLocation( x+136, y );
	_pbtnMenuQuit->SetLocation( _iWinWidth-150, 22 );

// Push the mouse motion event to activate the over state if necessary
	SDL_Event event;
	int mouseX, mouseY;
	event.type = SDL_MOUSEMOTION;
	event.motion.type = SDL_MOUSEMOTION;
	event.motion.state = SDL_GetMouseState(&mouseX, &mouseY);
	event.motion.x = mouseX;
	event.motion.y = mouseY;
	event.motion.xrel = 0;
	event.motion.yrel = 0;
	SDL_PushEvent(&event);
}


   /*=====================================================================*/
void
City::_UnloadMenu()
{
	delete _pctrMenu;
	delete _pbtnMenuQuit;
	delete _pbtnMenuSave;
	delete _pbtnMenuLoad;
	delete _pbtnMenuNew;

	_pctrMenu = NULL;

// IF the status bar was visible THEN display it now
	if (_bStatusVisible) {
		gVars.gpRenderer->ToggleCompass();
		_pctrStatus->Set( OC_GUIMAIN_VISIBLE );
	}
}


   /*=====================================================================*/
void
City::_SetCurrentTool( const OPENCITY_TOOL_CODE& tool )
{
	_apbtnCurrentTool[ _eCurrentTool ]->Unset( OC_GUIMAIN_VISIBLE );
	_eCurrentTool = tool;
	_apbtnCurrentTool[ _eCurrentTool ]->Set( OC_GUIMAIN_VISIBLE );
}


   /*=====================================================================*/
void
City::_DoTool(
	const SDL_MouseButtonEvent & sdlMBEvent )
{
	if ( _eCurrentTool == OC_TOOL_NONE )
		return;

	static uint cost;
	static OPENCITY_ERR_CODE enumErrCode;
	static int w1, h1, w2, h2;

	Structure* pstruct = NULL;		// for MAS

	cost = 0;
	w1 = _uiMapW1;
	h1 = _uiMapL1;
	w2 = _uiMapW2;
	h2 = _uiMapL2;
	OPENCITY_SWAP( w1, w2, int );
	OPENCITY_SWAP( h1, h2, int );


// we return if we don't have enough funds
	if (_liCityFund < 0)
		return;


// block all the sim threads while modifying the game datas
	SDL_LockMutex( gVars.gpmutexSim );

	switch (_eCurrentTool) {
	case OC_TOOL_ZONE_RES:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_RES, cost )) == OC_ERR_FREE) {
			gVars.gpAudioMgr->PlaySound( OC_SOUND_RCI );
		}
		break;

	case OC_TOOL_ZONE_COM:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_COM, cost )) == OC_ERR_FREE) {
			gVars.gpAudioMgr->PlaySound( OC_SOUND_RCI );
		}
		break;

	case OC_TOOL_ZONE_IND:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_IND, cost )) == OC_ERR_FREE) {
			gVars.gpAudioMgr->PlaySound( OC_SOUND_RCI );
		}
		break;

	case OC_TOOL_ROAD:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_ROAD, cost )) == OC_ERR_FREE) {
			gVars.gpAudioMgr->PlaySound( OC_SOUND_ROAD );
		}
		break;

	case OC_TOOL_ELINE:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_ELINE, cost )) == OC_ERR_FREE) {
			gVars.gpAudioMgr->PlaySound( OC_SOUND_ELINE );
		}
		break;

	case OC_TOOL_EPLANT_COAL:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_EPLANT_COAL, cost )) == OC_ERR_FREE) {
			_pMSim->AddStructure( _uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2, Simulator::OC_ELECTRIC );
			gVars.gpAudioMgr->PlaySound( OC_SOUND_EPLANT );
		}
		break;

	case OC_TOOL_EPLANT_NUCLEAR:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_EPLANT_NUCLEAR, cost )) == OC_ERR_FREE) {
			_pMSim->AddStructure( _uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2, Simulator::OC_ELECTRIC );
			gVars.gpAudioMgr->PlaySound( OC_SOUND_EPLANT );
		}
		break;

	case OC_TOOL_PARK:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_PARK, cost )) == OC_ERR_FREE) {
			gVars.gpAudioMgr->PlaySound( OC_SOUND_PARK );
		}
		break;

	case OC_TOOL_FLORA:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_FLORA, cost )) == OC_ERR_FREE) {
			gVars.gpAudioMgr->PlaySound( OC_SOUND_PARK );
		}
		break;

	case OC_TOOL_FIRE:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_FIREDEPT, cost )) == OC_ERR_FREE) {
// not used			_pMSim->AddStructure( _uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2, MainSim::OC_MICROSIM_ELE );
			gVars.gpAudioMgr->PlaySound( OC_SOUND_EPLANT );
		}
		break;

	case OC_TOOL_POLICE:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_POLICEDEPT, cost )) == OC_ERR_FREE) {
// not used			_pMSim->AddStructure( _uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2, MainSim::OC_MICROSIM_ELE );
			gVars.gpAudioMgr->PlaySound( OC_SOUND_EPLANT );
		}
		break;

	case OC_TOOL_HOSPITAL:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_HOSPITALDEPT, cost )) == OC_ERR_FREE) {
// not used			_pMSim->AddStructure( _uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2, MainSim::OC_MICROSIM_ELE );
			gVars.gpAudioMgr->PlaySound( OC_SOUND_EPLANT );
		}
		break;

	case OC_TOOL_EDUCATION:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_EDUCATIONDEPT, cost )) == OC_ERR_FREE) {
// not used			_pMSim->AddStructure( _uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2, MainSim::OC_MICROSIM_ELE );
			gVars.gpAudioMgr->PlaySound( OC_SOUND_EPLANT );
		}
		break;

	case OC_TOOL_TEST_BUILDING:
		if ((enumErrCode = _apLayer[ _eCurrentLayer ]->
			BuildStructure(
				_uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2,
				OC_STRUCTURE_TEST, cost )) == OC_ERR_FREE) {
			gVars.gpAudioMgr->PlaySound( OC_SOUND_EPLANT );
		}
		break;

	case OC_TOOL_AGENT_POLICE:
		assert( gVars.gpKernel != NULL );
		assert( gVars.gpEnvironment != NULL );
		pstruct = _apLayer[ OC_LAYER_BUILDING ]->GetStructure( _uiMapW1, _uiMapL1 );
		if ((pstruct != NULL) && (pstruct->GetCode() == OC_STRUCTURE_ROAD))
		new AgentPolice(*gVars.gpKernel, *gVars.gpEnvironment, _uiMapW1, _uiMapL1);
		break;

	case OC_TOOL_AGENT_DEMONSTRATOR:
		assert( gVars.gpKernel != NULL );
		assert( gVars.gpEnvironment != NULL );
		pstruct = _apLayer[ OC_LAYER_BUILDING ]->GetStructure( _uiMapW1, _uiMapL1 );
		if ((pstruct != NULL) && (pstruct->GetCode() == OC_STRUCTURE_ROAD))
		new AgentDemonstrator(*gVars.gpKernel, *gVars.gpEnvironment, _uiMapW1, _uiMapL1);
		break;

	case OC_TOOL_AGENT_ROBBER:
		assert( gVars.gpKernel != NULL );
		assert( gVars.gpEnvironment != NULL );
		pstruct = _apLayer[ OC_LAYER_BUILDING ]->GetStructure( _uiMapW1, _uiMapL1 );
		if ((pstruct != NULL) && (pstruct->GetCode() == OC_STRUCTURE_ROAD))
		new AgentRobber(*gVars.gpKernel, *gVars.gpEnvironment, _uiMapW1, _uiMapL1);
		break;

//FIXME: cost
	case OC_TOOL_HEIGHT_UP:
		enumErrCode = gVars.gpMapMgr->ChangeHeight( _uiMapW1, _uiMapL1, OC_MAP_UP );
		if ( enumErrCode == OC_ERR_FREE ) {
			gVars.gpRenderer->bHeightChange = true;
			gVars.gpAudioMgr->PlaySound( OC_SOUND_TERRAIN );
			cost = 5;		// Quick hack
		}
		break;

	case OC_TOOL_HEIGHT_DOWN:
		enumErrCode = gVars.gpMapMgr->ChangeHeight( _uiMapW1, _uiMapL1, OC_MAP_DOWN );
		if ( enumErrCode == OC_ERR_FREE ) {
			gVars.gpRenderer->bHeightChange = true;
			gVars.gpAudioMgr->PlaySound( OC_SOUND_TERRAIN );
			cost = 5;		// Quick hack
		}
		break;

	case OC_TOOL_QUERY:
	// Get the new query container
		_pctrQ = _apLayer[ _eCurrentLayer ]->QueryStructure( _uiMapW1, _uiMapL1 );

	// Reset the old container
		_pctr->ResetAttribute( OC_GUIMAIN_CLICKED | OC_GUIMAIN_MOUSEOVER );
		_pctr->Unset( OC_GUIMAIN_VISIBLE );

	// Show the informations queried
		_pctr = _pctrQ;
		_pctr->SetLocation( sdlMBEvent.x - 70, _iWinHeight - sdlMBEvent.y - 70 );
		_pctr->Set( OC_GUIMAIN_VISIBLE );
		enumErrCode = OC_ERR_SOMETHING;		// avoid to calculate the cost
		break;

	case OC_TOOL_DESTROY:
	// If it is a part of a bigger structure (an EPLANT for example),
	// the whole structure will be then destroyed
	// The following part tell the simulators to remove the collected data concerning
	// the structures which are going to be destroyed
		_pMSim->RemoveStructure( _uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2 );
		enumErrCode = _apLayer[ _eCurrentLayer ]->
			DestroyStructure( _uiMapW1, _uiMapL1, _uiMapW2, _uiMapL2, cost );
		if (enumErrCode == OC_ERR_FREE) {
			gVars.gpAudioMgr->PlaySound( OC_SOUND_DESTROY );
		}
		break;

	default:
		enumErrCode = OC_ERR_SOMETHING;// which tool is this ?
	} // switch

// now unlock the mutex and let the sims run
	SDL_UnlockMutex( gVars.gpmutexSim );

	if (enumErrCode == OC_ERR_FREE) {
		_liCityFund -= cost;
	}
}


   /*=====================================================================*/
bool
City::_HandleKeyPressed()
{
	int actionFactor = 1;
	int key;
	bool boolKeyDown = false;		// There is no key pressed

// Key multiplier
	if (_abKeyPressed[KEY_ALT] == true)
		actionFactor = OC_ACTION_FACTOR;
	else
		actionFactor = 1;

// Look for pressed keys
	for (key = KEY_UP; key < KEY_NUMBER; key++) {
		if (_abKeyPressed[key] == true) {
			switch (key) {
			case KEY_UP:
				gVars.gpRenderer->MoveDown(actionFactor);
				break;
			case KEY_DOWN:
				gVars.gpRenderer->MoveUp(actionFactor);
				break;
			case KEY_RIGHT:
				gVars.gpRenderer->MoveLeft(actionFactor);
				break;
			case KEY_LEFT:
				gVars.gpRenderer->MoveRight(actionFactor);
				break;

			case KEY_PAGEUP:
				gVars.gpRenderer->RotateLeft(actionFactor);
				break;
			case KEY_PAGEDOWN:
				gVars.gpRenderer->RotateRight(actionFactor);
				break;

			case KEY_INSERT: // zoom in
				gVars.gpRenderer->ZoomIn();
				break;
			case KEY_DELETE: // zoom out
				gVars.gpRenderer->ZoomOut();
				break;
			} // switch

		// There's at least one key pressed
			boolKeyDown = true;
		} // if
	} // for

// Tell the caller that there's whether at least a key pressed or not
	return boolKeyDown;
}


   /*=====================================================================*/
void
City::_RecordRessource()
{
// Accumulate the income each month
	uint r, c, i;
	uint w = 0, e = 0, g = 0;
	r = _pMSim->GetValue(Simulator::OC_RESIDENTIAL);
	c = _pMSim->GetValue(Simulator::OC_COMMERCIAL);
	i = _pMSim->GetValue(Simulator::OC_INDUSTRIAL);

// Create a new record
	Ressource res;
	res.fund = _liCityFund;
	res.population = _uiPopulation;
	res.r = r;
	res.c = c;
	res.i = i;
	res.w = w;
	res.e = e;
	res.g = g;

// Pop the oldest record if available (safe)
	if (!_dqRessource.empty())
		_dqRessource.pop_front();
	_dqRessource.push_back(res);
}


   /*=====================================================================*/
void
City::_DoBill(
	const OPENCITY_PROPERTY_CODE & enumProperty )
{
	uint maintenance;
	uint index, surface;
	Structure* pStruct;
	uint r, c, i;

	surface = _uiWidth * _uiLength;
	maintenance = 0;
	for (index = 0; index < surface; index++) {
		pStruct = _apLayer[ OC_LAYER_BUILDING ]->GetLinearStructure( index );
		if (pStruct != NULL)
			maintenance +=
				gVars.gpPropertyMgr->Get(OC_MAINTENANCE_COST, pStruct->GetCode());
	}

	_liCityFund -= maintenance;

// Accumulate the income each month
	r = _pMSim->GetValue(Simulator::OC_RESIDENTIAL);
	c = _pMSim->GetValue(Simulator::OC_COMMERCIAL);
	i = _pMSim->GetValue(Simulator::OC_INDUSTRIAL);

	_uiIncome += (r*OC_R_INCOME_TAX + c*OC_C_INCOME_TAX + i*OC_I_INCOME_TAX) / 100;

// Add the income only if we reach the end of the year
	if (enumProperty == OC_INCOME ) {
	// Here is the gouvernment's help for this year :D
		_uiIncome += _uiIncome * OC_INCOME_HELP/100;
		_liCityFund += _uiIncome;
		OPENCITY_INFO(
			"Happy new year ! " <<
			"Income: " << _uiIncome <<
			" d/m/y: " << _uiDay << "/" << _uiMonth << "/" << _uiYear <<
			" R/C/I: " << r << "/" << c << "/" << i
		);

		_uiIncome = 0;
	}
}


   /*=====================================================================*/
void
City::_HandleMenuClick()
{
	assert( _pctrMenu != NULL );

	uint uiObject = _pctrMenu->GetClick();

	switch (uiObject) {
		case 1:
			ocRestart();
			break;

		case 2:		// Load
			_Load( ocSaveDirPrefix( "opencity.save" ) );
			break;
		case 3:		// Save
			_Save( ocSaveDirPrefix( "opencity.save" ) );
			break;

		case 4:		// Quit button
			ocQuit();
			break;

		default:
			OPENCITY_DEBUG( "Menu design error");
			assert(0);
	}

	_UnloadMenu();
}


   /*=====================================================================*/
void
City::_HandleStatusClick()
{
	uint uiObject = _pctrStatus->GetClick();

// WARNING: the GUI button displays the current speed
	switch (uiObject) {
		case 1:		// Pause button
			OPENCITY_DEBUG( "Normal speed mode" );
			_pbtnPause->Unset( OC_GUIMAIN_VISIBLE );
			_pbtnPlay->Set( OC_GUIMAIN_VISIBLE );
			_eSpeed = OC_SPEED_NORMAL;
			_pMSim->Run();
			break;
		case 2:		// Play button
			OPENCITY_DEBUG( "Pause mode" );
			_pbtnPlay->Unset( OC_GUIMAIN_VISIBLE );
			_pbtnPause->Set( OC_GUIMAIN_VISIBLE );
			_eSpeed = OC_SPEED_PAUSE;
			_pMSim->Stop();
			break;

		default:
			OPENCITY_DEBUG( "WARNING: What's this control -> " << uiObject);
			//assert(0);
			break;
	}

	_pctrStatus->ResetAttribute( OC_GUIMAIN_CLICKED | OC_GUIMAIN_MOUSEOVER );
}


   /*=====================================================================*/
void
City::_HandleGUIClick()
{
	uint uiObject;
	GUIContainer* pOldContainer;
	int iX, iY;

	pOldContainer = _pctr;
	uiObject = _pctr->GetClick();

// is this the main container ?
	if (_pctr == _pctrMain)
	switch (uiObject) {
		case 1: // switch to Z toolcircle
			_pctr = _pctrZ;
			_pctr->Set( 1, OC_GUIMAIN_MOUSEOVER );
			break;
		case 2: // load/save toolcircle
			_pctr = _pctrS;
			_pctr->Set( 1, OC_GUIMAIN_MOUSEOVER );
			break;
		case 3:  // L button, open the L toolcircle
			_pctr = _pctrL;
			_pctr->Set( 1, OC_GUIMAIN_MOUSEOVER );
			break;
		case 4:  // P button, set tool for "building road"
			_SetCurrentTool( OC_TOOL_ROAD );
			break;
		case 5: // T button, open the "Terrain" toolcircle
			_pctr = _pctrT;
			_pctr->Set( 1, OC_GUIMAIN_MOUSEOVER );
			break;
		case 6: // G button, open the government toolcircle
			_pctr = _pctrG;
			_pctr->Set( 1, OC_GUIMAIN_MOUSEOVER );
			break;

		default: // never reached
			OPENCITY_DEBUG( "WARNING: What's going wrong ?" );
			assert(0);
			break;
	}

// the user clicked on the Zone toolcircle
	else if (_pctr == _pctrZ )
	switch (uiObject) {
		case 1: // back button, open the main toolcircle
			_pctr = _pctrMain;
			_pctr->Set( 1, OC_GUIMAIN_MOUSEOVER );
			break;
		case 2: // R button
			_SetCurrentTool( OC_TOOL_ZONE_RES );
			break;
		case 3:  // C button, set tool for "zone commercial"
			_SetCurrentTool( OC_TOOL_ZONE_COM );
			break;
		case 4:  // I button, set tool for "zone industrial"
			_SetCurrentTool( OC_TOOL_ZONE_IND );
			break;

		default:
			OPENCITY_DEBUG("Design error");
			assert( 0 );
			break;
	}

// the user clicked on the eLectric toolcircle
	else if (_pctr == _pctrL)
	switch (uiObject) {
		case 1: // back button, open the main toolcircle
			_pctr = _pctrMain;
		// highlight the previous button under the mouse cursor
			_pctr->Set( 3, OC_GUIMAIN_MOUSEOVER );
			break;
		case 2:  // L button, set tool for building electric lines
			_SetCurrentTool( OC_TOOL_ELINE );
			break;
		case 3:  // set tool for building nuclear power plant
			_SetCurrentTool( OC_TOOL_EPLANT_NUCLEAR );
			break;
		case 4:  // set tool for building coal power plant
			_SetCurrentTool( OC_TOOL_EPLANT_COAL );
			break;

		default:
			OPENCITY_DEBUG( "WARNING: What's going wrong ?" );
			assert(0);
			break;
	}

// the user clicked on the Terrain toolcircle
	else if (_pctr == _pctrT)
	switch (uiObject) {
		case 1: // back button, open the main toolcircle
			_pctr = _pctrMain;
			_pctr->Set( 5, OC_GUIMAIN_MOUSEOVER );
			break;
		case 2:  // height up
			_SetCurrentTool( OC_TOOL_HEIGHT_UP );
			break;
		case 3:  // height down
			_SetCurrentTool( OC_TOOL_HEIGHT_DOWN );
			break;
		case 4:  // destroy tool
			_SetCurrentTool( OC_TOOL_DESTROY );
			break;
		case 5: // query tool
			_SetCurrentTool( OC_TOOL_QUERY );
			break;

		default:
			OPENCITY_DEBUG( "WARNING: What's going wrong ?" );
			assert(0);
			break;
	}

// the user clicked on the government toolcircle
	else if (_pctr == _pctrG)
	switch (uiObject) {
		case 1: // back button, open the main toolcircle
			_pctr = _pctrMain;
			_pctr->Set( 6, OC_GUIMAIN_MOUSEOVER );
			break;
		case 2:  // nature toolcircle
			_pctr = _pctrN;
			_pctr->Set( 1, OC_GUIMAIN_MOUSEOVER );
			break;
		case 3:
			_SetCurrentTool( OC_TOOL_EDUCATION );
			break;
		case 4:
			_SetCurrentTool( OC_TOOL_HOSPITAL );
			break;
		case 5:
			_SetCurrentTool( OC_TOOL_POLICE );
			break;
		case 6:
			_SetCurrentTool( OC_TOOL_FIRE );
			break;

		default:
			OPENCITY_DEBUG( "WARNING: Unknown command" );
			assert(0);
			break;
	}

// the user clicked on the "nature" toolcircle
	else if (_pctr == _pctrN)
	switch (uiObject) {
		case 1: // back button, open the government toolcircle
			_pctr = _pctrG;
			_pctr->Set( 2, OC_GUIMAIN_MOUSEOVER );
			break;
		case 2:  // build park
			_SetCurrentTool( OC_TOOL_PARK );
			break;
		case 3:  // build tree
			_SetCurrentTool( OC_TOOL_FLORA );
			break;

		default:
			OPENCITY_DEBUG( "WARNING: Unknown tool" );
			assert(0);
			break;
	}

// the user clicked on the load/save toolcircle
	else if (_pctr == _pctrS)
	switch (uiObject) {
		case 1: // back button, open the main toolcircle
			_pctr = _pctrMain;
			_pctr->Set( 2, OC_GUIMAIN_MOUSEOVER );
			break;
		case 2:  // save
			_Save( ocSaveDirPrefix( "opencity.save" ) );
			break;
		case 3:  // load
			_Load( ocSaveDirPrefix( "opencity.save" ) );
			break;

		default:
			OPENCITY_DEBUG( "WARNING: Unknown command" );
			assert(0);
			break;
	}

// the user clicked on the Path toolcircle
	else if (_pctr == _pctrPath)
	switch (uiObject) {
		case 1: // start button
			_SetCurrentTool( OC_TOOL_NONE );
			boolPathGo = false;
//debug cout << "changed to false" << endl;
			break;
		case 2: // stop button
			_SetCurrentTool( OC_TOOL_NONE );
			boolPathGo = true;
			this->uiVehicleType = Vehicle::VEHICLE_BUS;
			break;
		case 3: // stop button
			_SetCurrentTool( OC_TOOL_NONE );
			boolPathGo = true;
			this->uiVehicleType = Vehicle::VEHICLE_SPORT;
//debug cout << "changed to true" << endl;
			break;
		case 4: // build test building
			_SetCurrentTool( OC_TOOL_TEST_BUILDING );
			break;
		default:
			break;
	}

// The user has clicked on the MAS toolcircle
	else if (_pctr == _pctrMAS)
	switch (uiObject) {
		case 1: // start button
			_SetCurrentTool( OC_TOOL_AGENT_POLICE );
			break;
		case 2: // stop button
			_SetCurrentTool( OC_TOOL_AGENT_DEMONSTRATOR );
			break;
		case 3: // stop button
			_SetCurrentTool( OC_TOOL_AGENT_ROBBER );
			break;

		default:
			break;
	}


// IF the container has been changed then we reset
// the MouseOver & Clicked attributes
// otherwise we reset only the Clicked attribute
	if (_pctr != pOldContainer) {
		pOldContainer->ResetAttribute( OC_GUIMAIN_CLICKED | OC_GUIMAIN_MOUSEOVER );
		pOldContainer->GetLocation( iX, iY );
		_pctr->SetLocation( iX, iY );
		_pctr->Set( OC_GUIMAIN_VISIBLE );
	}
	else {
		pOldContainer->ResetAttribute( OC_GUIMAIN_CLICKED );
	}
	pOldContainer->Unset( OC_GUIMAIN_VISIBLE );
}


   /*=====================================================================*/
// Unused at the moment because it disturbs the GUI
void
City::_HandleMouseXY()
{
	#define OC_MOUSE_AUTOSCROLL 15

	static int mouseX, mouseY;

// return immediately if the app doesn't have mouse focus
	if (!(SDL_GetAppState() & SDL_APPMOUSEFOCUS ))
		return;

	SDL_GetMouseState( &mouseX, &mouseY );

// handle horizontal automatic map translation
	if ((mouseX < OC_MOUSE_AUTOSCROLL) && !(mouseY < OC_MOUSE_AUTOSCROLL))
		gVars.gpRenderer->MoveRight();
	if ((mouseX >= _iWinWidth-OC_MOUSE_AUTOSCROLL) && !(mouseY < OC_MOUSE_AUTOSCROLL))
		gVars.gpRenderer->MoveLeft();

// handle vertical automatic map translation
	if (!(mouseX < OC_MOUSE_AUTOSCROLL)
	  &&!(mouseX >= _iWinWidth-OC_MOUSE_AUTOSCROLL) && (mouseY < OC_MOUSE_AUTOSCROLL))
		gVars.gpRenderer->MoveDown();
	if ((mouseY >= _iWinHeight-OC_MOUSE_AUTOSCROLL))
		gVars.gpRenderer->MoveUp();

// handle map rotation
	if ((mouseX < OC_MOUSE_AUTOSCROLL) && (mouseY < OC_MOUSE_AUTOSCROLL))
		gVars.gpRenderer->RotateLeft();

	if ((mouseY < OC_MOUSE_AUTOSCROLL) && (mouseX >= _iWinWidth-OC_MOUSE_AUTOSCROLL))
		gVars.gpRenderer->RotateRight();
}


   /*=====================================================================*/
void
City::_TestPathfinding() {
	if (_pctr == _pctrPath) {
		if (this->boolPathGo == false) {
			this->uiPathStartW = _uiMapW2;
			this->uiPathStartH = _uiMapL2;
		}
		else {
		//TODO: put this somewhere else
			vector<Destination> vdest;

			this->uiPathStopW = _uiMapW2;
			this->uiPathStopH = _uiMapL2;

		// Buses prefer short distance
			if (this->uiVehicleType == Vehicle::VEHICLE_BUS) {
				gVars.gpPathFinder->findShortestPath(
					uiPathStartW, uiPathStartH,
					uiPathStopW, uiPathStopH,
					vdest,
					PathFinder::OC_DISTANCE );
			}
		// Sport vehicle prefer less traffic
			else if (this->uiVehicleType == Vehicle::VEHICLE_SPORT) {
				gVars.gpPathFinder->findShortestPath(
					uiPathStartW, uiPathStartH,
					uiPathStopW, uiPathStopH,
					vdest,
					PathFinder::OC_TRAFFIC );
			}

		// Now create the new vehicle if a path was found
			if ( vdest.size() > 0 ) {
				pvehicle = new Vehicle(
					(Vehicle::VEHICLE_TYPE)this->uiVehicleType );
				pvehicle->SetPath( vdest );	// path init
				pvehicle->Start();		// vehicle init
				if (gVars.gpMoveMgr->Add( pvehicle ) < 0) {
					OPENCITY_DEBUG("MoveMgr full");
					delete pvehicle;
				}
			}
		}
	}
//debug: pathfinding
/*
cout << "StW: " << uiPathStartW << " / " << " StH: " << uiPathStartH
     << " SpW: " << uiPathStopW << " / " << "SpH: " << uiPathStopH << endl;
*/
}


   /*=====================================================================*/
void
City::_BuildPreview()
{
	static OPENCITY_STRUCTURE_CODE scode = OC_STRUCTURE_UNDEFINED;
	static OPENCITY_GRAPHIC_CODE gcode = OC_EMPTY;
	static OPENCITY_TOOL_CODE tcode = OC_TOOL_NONE;
	static OPENCITY_ERR_CODE ecode = OC_ERR_FREE;


// Get the corresponding structure code of the tool
	if (tcode != _eCurrentTool) {
		tcode = _eCurrentTool;
		switch (tcode) {
		/* not implemented yet
			case OC_TOOL_ZONE_RES:
				scode = OC_STRUCTURE_RES;
				break;
			case OC_TOOL_ZONE_COM:
				scode = OC_STRUCTURE_COM;
				break;
			case OC_TOOL_ZONE_IND:
				scode = OC_STRUCTURE_IND;
				break;
			case OC_TOOL_ROAD:
				scode = OC_STRUCTURE_ROAD;
				break;
			case OC_TOOL_ELINE:
				scode = OC_STRUCTURE_ELINE;
				break;
		*/

			case OC_TOOL_EPLANT_COAL:
				scode = OC_STRUCTURE_EPLANT_COAL;
				break;
			case OC_TOOL_EPLANT_NUCLEAR:
				scode = OC_STRUCTURE_EPLANT_NUCLEAR;
				break;
			case OC_TOOL_PARK:
				scode = OC_STRUCTURE_PARK;
				break;
			case OC_TOOL_FLORA:
				scode = OC_STRUCTURE_FLORA;
				break;
			case OC_TOOL_FIRE:
				scode = OC_STRUCTURE_FIREDEPT;
				break;
			case OC_TOOL_POLICE:
				scode = OC_STRUCTURE_POLICEDEPT;
				break;
			case OC_TOOL_HOSPITAL:
				scode = OC_STRUCTURE_HOSPITALDEPT;
				break;
			case OC_TOOL_EDUCATION:
				scode = OC_STRUCTURE_EDUCATIONDEPT;
				break;

			case OC_TOOL_TEST_BUILDING:
				scode = OC_STRUCTURE_TEST;
				break;

			default:
				scode = OC_STRUCTURE_UNDEFINED;
				break;
		} // switch
	} // if

// Get the corresponding graphic code
	if ((scode != OC_STRUCTURE_UNDEFINED)
	 && (_bLMBPressed == true)) {
		ecode = _apLayer[ _eCurrentLayer ]->
			BuildPreview( _uiMapW1, _uiMapL1, scode, gcode );

		if (ecode == OC_ERR_FREE) {
			gVars.gpRenderer->DisplayBuildPreview(
				_uiMapW1, _uiMapL1, OC_GREEN_COLOR, gcode );
		}
		else {
			gVars.gpRenderer->DisplayBuildPreview(
				_uiMapW1, _uiMapL1, OC_RED_COLOR, gcode );
		}
	}
}


   /*=====================================================================*/
bool
City::_Save( const string& strFilename )
{
	fstream fs;

	fs.open( strFilename.c_str(), ios_base::out | ios_base::binary | ios_base::trunc );
	if (!fs.good()) {
		OPENCITY_DEBUG( "File opening error: " << strFilename );
		return false;
	}

// Save the signature and version
	fs << "OpenCity_" << ocStrVersion() << std::endl;
	fs << ocLongVersion() << std::ends;

// Lock the simulator
	SDL_LockMutex( gVars.gpmutexSim );

// Save city data
	this->SaveTo( fs );

// Save map data
	gVars.gpMapMgr->SaveTo( fs );

// Save layers's data
	_apLayer[ OC_LAYER_BUILDING ]->SaveTo( fs );

// Save simulators data
	_pMSim->SaveTo( fs );

// Unlock the simulator
	SDL_UnlockMutex( gVars.gpmutexSim );

	fs.close();
	return true;
}


   /*=====================================================================*/
bool
City::_Load( const string& strFilename )
{
	fstream fs;
	uint w, l;

	fs.open( strFilename.c_str(), ios_base::in | ios_base::binary );
	if (!fs.good()) {
		OPENCITY_DEBUG( "File opening error in: " << strFilename );
		return false;
	}

// Load the signature and version
	string strSignature;
	long currentVersion = ocLongVersion();
	long lVersion;

	getline( fs, strSignature );
	fs >> lVersion; fs.ignore();

// Version checking
	if (lVersion > currentVersion) {
		OPENCITY_INFO( "Failed to load a more recent save file: " << strFilename );
		OPENCITY_INFO( "Current OpenCity version is: " << currentVersion );
		OPENCITY_INFO( "The save file version is : " << lVersion );
		return false;
	}

// Lock the simulator
	SDL_LockMutex( gVars.gpmutexSim );

// Remove all moving objects
	gVars.gpMoveMgr->Remove();

// Load city data
	OPENCITY_INFO( "Loading save file from " << strSignature );
	this->LoadFrom( fs );

// Load map data
	gVars.gpMapMgr->LoadFrom( fs );
	gVars.gpRenderer->bHeightChange = true;
	gVars.gpRenderer->bMinimapChange = true;

// Load layers' data
	_apLayer[ OC_LAYER_BUILDING ]->LoadFrom( fs );

// Load simulators' data
	_pMSim->LoadFrom( fs );

// Manually add the structures to the simulators
	for ( w = 0; w < _uiWidth; w++ ) {
		for ( l = 0; l < _uiLength; l++ ) {
			_pMSim->AddStructure( w, l, w, l );
		}
	}

// Refresh/recalculate the simulators' value
	_pMSim->RefreshSimValue();

// Unlock the simulator
	SDL_UnlockMutex( gVars.gpmutexSim );

	fs.close();
	return true;
}