File: program.cpp

package info (click to toggle)
megaglest 3.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 12,904 kB
  • ctags: 18,215
  • sloc: cpp: 144,232; ansic: 11,860; sh: 2,949; perl: 1,899; python: 1,751; objc: 142; asm: 42; makefile: 24
file content (678 lines) | stat: -rw-r--r-- 18,860 bytes parent folder | download
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
// ==============================================================
//	This file is part of Glest (www.glest.org)
//
//	Copyright (C) 2001-2008 MartiƱo Figueroa
//
//	You can redistribute this code 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 (at your option) any later version
// ==============================================================


#include "program.h"
#include "util.h"
#include <iostream>
#include "platform_util.h"

using namespace Shared::Util;

namespace MapEditor {

////////////////////////////
// class UndoPoint
////////////////////////////
int UndoPoint::w = 0;
int UndoPoint::h = 0;

UndoPoint::UndoPoint()
		: change(ctNone)
		, surface(0)
		, object(0)
		, resource(0)
		, height(0) {
	w = Program::map->getW();
	h = Program::map->getH();
}
/*
UndoPoint::UndoPoint(ChangeType change) {
	w = Program::map->getW();
	h = Program::map->getH();

	init(change);
}*/

void UndoPoint::init(ChangeType change) {
	this->change = change;
	switch (change) {
		// Back up everything
		case ctAll:
		// Back up heights
		case ctHeight:
		case ctGradient:
			// Build an array of heights from the map
			//std::cout << "Building an array of heights to use for our UndoPoint" << std::endl;
			height = new float[w * h];
			for (int i = 0; i < w; ++i) {
				for (int j = 0; j < h; ++j) {
					 height[j * w + i] = Program::map->getHeight(i, j);
				}
			}
			//std::cout << "Built the array" << std::endl;
			if (change != ctAll) break;
		// Back up surfaces
		case ctSurface:
			surface = new int[w * h];
			for (int i = 0; i < w; ++i) {
				for (int j = 0; j < h; ++j) {
					 surface[j * w + i] = Program::map->getSurface(i, j);
				}
			}
			if (change != ctAll) break;
		// Back up both objects and resources if either changes
		case ctObject:
		case ctResource:
			object = new int[w * h];
			for (int i = 0; i < w; ++i) {
				for (int j = 0; j < h; ++j) {
					 object[j * w + i] = Program::map->getObject(i, j);
				}
			}
			resource = new int[w * h];
			for (int i = 0; i < w; ++i) {
				for (int j = 0; j < h; ++j) {
					 resource[j * w + i] = Program::map->getResource(i, j);
				}
			}
			break;
	}
}

UndoPoint::~UndoPoint() {
	delete [] height;
	delete [] resource;
	delete [] object;
	delete [] surface;
}

void UndoPoint::revert() {
	//std::cout << "attempting to revert last changes to " << undoID << std::endl;
	switch (change) {
		// Revert Everything
		case ctAll:
		// Revert Heights
		case ctHeight:
		case ctGradient:
			// Restore the array of heights to the map
			//std::cout << "attempting to restore the height array" << std::endl;
			for (int i = 0; i < w; i++) {
				for (int j = 0; j < h; j++) {
					 Program::map->setHeight(i, j, height[j * w + i]);
				}
			}
			if (change != ctAll) break;
		// Revert surfaces
		case ctSurface:
			//std::cout << "attempting to restore the surface array" << std::endl;
			for (int i = 0; i < w; i++) {
				for (int j = 0; j < h; j++) {
					 Program::map->setSurface(i, j, static_cast<MapSurfaceType>(surface[j * w + i]));
				}
			}
			if (change != ctAll) break;
		// Revert objects and resources
		case ctObject:
		case ctResource:
			for (int i = 0; i < w; i++) {
				for (int j = 0; j < h; j++) {
					 Program::map->setObject(i, j, object[j * w + i]);
				}
			}
			for (int i = 0; i < w; i++) {
				for (int j = 0; j < h; j++) {
					 Program::map->setResource(i, j, resource[j * w + i]);
				}
			}
			break;
	}
	//std::cout << "reverted changes (we hope)" << std::endl;
}

// ===============================================
//	class Program
// ===============================================

MapPreview *Program::map = NULL;

Program::Program(int w, int h, string playerName) {
	cellSize = 5;
	grid=false;
	heightmap=false;
	hideWater=false;
	ofsetX = 0;
	ofsetY = 0;

	map = new MapPreview();
	resetFactions(8);
	renderer.initMapSurface(w, h);
	map->setAuthor(playerName);
}

void Program::init() {
	undoStack = ChangeStack();
	redoStack = ChangeStack();
	cellSize = 5;
	grid=false;
	heightmap=false;
	hideWater=false;
	ofsetX = 0;
	ofsetY = 0;
	map = NULL;
}

Program::~Program() {
	delete map;
	map = NULL;
}

int Program::getObject(int x, int y) {
	int i=(x - ofsetX) / cellSize;
	int j= (y + ofsetY) / cellSize;
	if (map && map->inside(i, j)) {
		return map->getObject(i,j);
	}
	else {
		return 0;
	}
}

int Program::getCellX(int x) {
	return (x - ofsetX) / cellSize;
}

int Program::getCellY(int y) {
	return (y + ofsetY) / cellSize;
}

int Program::getResource(int x, int y) {
	int i=(x - ofsetX) / cellSize;
	int j= (y + ofsetY) / cellSize;
	if (map && map->inside(i, j)) {
		return map->getResource(i,j);
	}
	else {
		return 0;
	}
}

void Program::glestChangeMapHeight(int x, int y, int Height, int radius) {
	if(map) map->glestChangeHeight((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, Height, radius);
}

void Program::pirateChangeMapHeight(int x, int y, int Height, int radius) {
	if(map) map->pirateChangeHeight((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, Height, radius);
}

void Program::changeMapSurface(int x, int y, int surface, int radius) {
	if(map) map->changeSurface((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, static_cast<MapSurfaceType>(surface), radius);
}

void Program::changeMapObject(int x, int y, int object, int radius) {
	if(map) map->changeObject((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, object, radius);
}

void Program::changeMapResource(int x, int y, int resource, int radius) {
	if(map) map->changeResource((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, resource, radius);
}

void Program::changeStartLocation(int x, int y, int player) {
	if(map) map->changeStartLocation((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, player);
}

void Program::setUndoPoint(ChangeType change) {
	if (change == ctLocation) return;

	undoStack.push(UndoPoint());
	undoStack.top().init(change);

	redoStack.clear();
}

bool Program::undo() {
	if (undoStack.empty()) {
		return false;
	}
	// push current state onto redo stack
	redoStack.push(UndoPoint());
	redoStack.top().init(undoStack.top().getChange());

	undoStack.top().revert();
	undoStack.pop();
	return true;
}

bool Program::redo() {
	if (redoStack.empty()) {
		return false;
	}
	// push current state onto undo stack
	undoStack.push(UndoPoint());
	undoStack.top().init(redoStack.top().getChange());

	redoStack.top().revert();
	redoStack.pop();
	return true;
}

void Program::renderMap(int w, int h) {
	//printf("Rendering map\n");
	if(map) renderer.renderMap(map, ofsetX, ofsetY, w, h, cellSize, grid,heightmap,hideWater);
}

void Program::setRefAlt(int x, int y) {
	if(map) map->setRefAlt((x - ofsetX) / cellSize, (y + ofsetY) / cellSize);
}

void Program::flipX() {
	if(map) map->flipX();
}

void Program::flipY() {
	if(map) map->flipY();
}

void Program::mirrorX() { // copy left to right
	if(map) {
		int w=map->getW();
		int h=map->getH();
		for (int i = 0; i < w/2; i++) {
			for (int j = 0; j < h; j++) {
				map->copyXY(w-i-1,j  ,  i,j);
			}
		}

		// move players
		for (int i = 0; i < map->getMaxFactions(); ++i)     // first remove players from target corner
			if (map->getStartLocationX(i) >= w/2) map->changeStartLocation(0,0,i);
		for (int i = 0; i < map->getMaxFactions(); ++i) {
			if((map->getStartLocationX(i) < w/2) && (map->getStartLocationX(i)!=0 || map->getStartLocationY(i)!=0)) // any startpositions to copy?
				for (int ii = 0; ii < map->getMaxFactions(); ++ii)
					if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii)==0) { // first free one
						map->changeStartLocation(w-map->getStartLocationX(i)-1, map->getStartLocationY(i), ii);
						break;
					}
		}
	}
}

void Program::mirrorY() { // copy top to bottom
	if(map) {
		int w=map->getW();
		int h=map->getH();
		for (int i = 0; i < w; i++) {
			for (int j = 0; j < h/2; j++) {
				map->copyXY(i,h-j-1  ,  i,j);
			}
		}

		// move players
		for (int i = 0; i < map->getMaxFactions(); ++i)     // first remove players from target corner
			if (map->getStartLocationY(i) >= h/2) map->changeStartLocation(0,0,i);
		for (int i = 0; i < map->getMaxFactions(); ++i) {
			if((map->getStartLocationY(i) < h/2) && (map->getStartLocationX(i)!=0 || map->getStartLocationY(i)!=0)) // any startpositions to copy?
				for (int ii = 0; ii < map->getMaxFactions(); ++ii)
					if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii)==0) { // first free one
						map->changeStartLocation(map->getStartLocationX(i), h-map->getStartLocationY(i)-1, ii);
						break;
					}
		}
	}
}

void Program::mirrorXY() { // copy leftbottom to topright, can handle non-sqaure maps
	if(map) {
		int w=map->getW();
		int h=map->getH();
		if (h==w) {
			for (int i = 0; i < w-1; i++) {
				for (int j = i+1; j < h; j++) {
					map->copyXY(j,i  ,  i,j);
				}
			}
		}
		// Non-sqaure maps:
		else if (h < w) { // copy horizontal strips
			int s=w/h; // 2 if twice as wide as heigh
			for (int i = 0; i < w/s-1; i++) {
				for (int j = i+1; j < h; j++) {
					for (int p = 0; p < s; p++) map->copyXY(j*s+p,i  ,  i*s+p,j);
				}
			}
		}
		else { // copy vertical strips
			int s=h/w; // 2 if twice as heigh as wide
			for (int i = 0; i < w-1; i++) {
				for (int j = i+1; j < h/s; j++) {
					for (int p = 0; p < s; p++) map->copyXY(j,i*s+p  ,  i,j*s+p);
				}
			}
		}

		// move players
		for (int i = 0; i < map->getMaxFactions(); ++i)     // first remove players from target corner
			if (map->getStartLocationX(i) > map->getStartLocationY(i)) map->changeStartLocation(0,0,i);
		for (int i = 0; i < map->getMaxFactions(); ++i) {
			if(map->getStartLocationX(i) < map->getStartLocationY(i)) // any startpositions to copy?
				for (int ii = 0; ii < map->getMaxFactions(); ++ii)
					if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii) == 0) { // first free one
						map->changeStartLocation(map->getStartLocationY(i)*w/h, map->getStartLocationX(i)*h/w, ii);
						break;
					}
		}
	}
}

void Program::rotatecopyX() {
	if(map) {
		int w=map->getW();
		int h=map->getH();
		for (int i = 0; i < w/2; i++) {
			for (int j = 0; j < h; j++) {
				map->copyXY(w-i-1,h-j-1  ,  i,j);
			}
		}

		// move players
		for (int i = 0; i < map->getMaxFactions(); ++i)     // first remove players from target corner
			if (map->getStartLocationX(i) >= w/2) map->changeStartLocation(0,0,i);
		for (int i = 0; i < map->getMaxFactions(); ++i) {
			if((map->getStartLocationX(i) < w/2) && (map->getStartLocationX(i)!=0 || map->getStartLocationY(i)!=0)) // any startpositions to copy?
				for (int ii = 0; ii < map->getMaxFactions(); ++ii)
					if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii)==0) { // first free one
						map->changeStartLocation(w-map->getStartLocationX(i)-1, h-map->getStartLocationY(i)-1, ii);
						break;
					}
		}
	}
}

void Program::rotatecopyY() {
	if(map) {
		int w=map->getW();
		int h=map->getH();
		for (int i = 0; i < w; i++) {
			for (int j = 0; j < h/2; j++) {
				map->copyXY(w-i-1,h-j-1  ,  i,j);
			}
		}

		// move players
		for (int i = 0; i < map->getMaxFactions(); ++i)     // first remove players from target corner
			if (map->getStartLocationY(i) >= h/2) map->changeStartLocation(0,0,i);
		for (int i = 0; i < map->getMaxFactions(); ++i) {
			if((map->getStartLocationY(i) < h/2) && (map->getStartLocationX(i)!=0 || map->getStartLocationY(i)!=0)) // any startpositions to copy?
				for (int ii = 0; ii < map->getMaxFactions(); ++ii)
					if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii)==0) { // first free one
						map->changeStartLocation(w-map->getStartLocationX(i)-1, h-map->getStartLocationY(i)-1, ii);
						break;
					}
		}
	}
}

void Program::rotatecopyXY() {
	if(map) {
		int w=map->getW();
		int h=map->getH();
		int sw=w/h; if(sw<1) sw=1; // x-squares per y
		int sh=h/w; if(sh<1) sh=1; // y-squares per x
		if (sh==1)
			for (int j = 0; j < h-1; j++) { // row by row!
				for (int i = j*sw; i < w; i++) {
					map->copyXY(i,j  ,  w-i-1,h-j-1);
				}
			}
		else
			for (int i = 0; i <w; i++) { // column for colum!
				for (int j = h-1-i*sh; j >= 0; j--) {
					map->copyXY(w-i-1,j  ,  i,h-j-1);
				}
			}

		// move players
		for (int i = 0; i < map->getMaxFactions(); ++i)     // first remove players from target corner
			if (map->getStartLocationX(i) > map->getStartLocationY(i)) map->changeStartLocation(0,0,i);
		for (int i = 0; i < map->getMaxFactions(); ++i) {
			if(map->getStartLocationX(i) < map->getStartLocationY(i)) // any startpositions to copy?
				for (int ii = 0; ii < map->getMaxFactions(); ++ii)
					if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii) == 0) { // first free one
						map->changeStartLocation(w-map->getStartLocationX(i)-1, h-map->getStartLocationY(i)-1, ii);
						break;
					}
		}
	}
}

void Program::rotatecopyCorner() { // rotate top left 1/4 to top right 1/4
	if(map) {
		int w=map->getW();
		int h=map->getH();
		if (h==w) {
			for (int i = 0; i < w/2; i++) {
				for (int j = 0; j < h/2; j++) {
					map->copyXY(w-j-1,i  ,  i,j);
				}
			}
		}
		// Non-sqaure maps:
		else if (h < w) { // copy horizontal strips
			int s=w/h; // 2 if twice as wide as heigh
			for (int i = 0; i < w/s/2; i++) {
				for (int j = 0; j < h/2; j++) {
					for (int p = 0; p < s; p++) map->copyXY(w-j*s-1-p,i  ,  i*s+p,j);
				}
			}
		}
		else { // copy vertical strips
			int s=h/w; // 2 if twice as heigh as wide
			for (int i = 0; i < w/2; i++) {
				for (int j = 0; j < h/s/2; j++) {
					for (int p = 0; p < s; p++) map->copyXY(w-j-1,i*s+p  ,  i,j*s+p);
				}
			}
		}

		// move players
		for (int i = 0; i < map->getMaxFactions(); ++i)     // first remove players from target corner
			if (map->getStartLocationX(i) >= w/2 && map->getStartLocationY(i) < h/2) map->changeStartLocation(0,0,i);
		for (int i = 0; i < map->getMaxFactions(); ++i) {
			if((map->getStartLocationX(i) < w/2 && map->getStartLocationY(i) < h/2) && (map->getStartLocationX(i)!=0 || map->getStartLocationY(i)!=0)) // any startpositions to copy?
				for (int ii = 0; ii < map->getMaxFactions(); ++ii)
					if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii)==0) { // first free one
						map->changeStartLocation(w-map->getStartLocationY(i)*w/h-1, map->getStartLocationX(i)*h/w, ii);
						break;
					}
		}
	}
}


void Program::shiftLeft() {
	if(map) {
		int w=map->getW()-1;
		int h=map->getH();
		for (int i=0; i<w; i++)
			for (int j=0; j<h; j++)
				map->copyXY(i,j  ,  i+1,j);
		for (int i = 0; i < map->getMaxFactions(); ++i)     // move players
			map->changeStartLocation(map->getStartLocationX(i)-1, map->getStartLocationY(i), i); // it allready check limits
	}
}

void Program::flipDiagonal() {
	if(map) {
		int w=map->getW();
		int h=map->getH();
		for (int i=0; i<w; i++)
			for (int j=i; j<h; j++){
				map->swapXY(i,j ,  j,i);
			}
		for (int i = 0; i < map->getMaxFactions(); ++i)     // move players
			if (map->getStartLocationX(i) != 0 || map->getStartLocationY(i) != 0) // don't move the unset ones
				map->changeStartLocation(map->getStartLocationY(i), map->getStartLocationX(i), i); // it allready check limits
	}
}


void Program::shiftRight() {
	if(map) {
		int w=map->getW()-1;
		int h=map->getH();
		for (int i=w; i>0; i--)
			for (int j=0; j<h; j++)
				map->copyXY(i,j  ,  i-1,j);
		for (int i = 0; i < map->getMaxFactions(); ++i)     // move players
			if (map->getStartLocationX(i) != 0 || map->getStartLocationY(i) != 0) // don't move the unset ones
				map->changeStartLocation(map->getStartLocationX(i)+1, map->getStartLocationY(i), i); // it allready check limits
	}
}
void Program::shiftUp() {
	if(map) {
		int w=map->getW();
		int h=map->getH()-1;
		for (int i=0; i<w; i++)
			for (int j=0; j<h; j++)
				map->copyXY(i,j  ,  i,j+1);
		for (int i = 0; i < map->getMaxFactions(); ++i)     // move players
			map->changeStartLocation(map->getStartLocationX(i), map->getStartLocationY(i)-1, i); // it allready check limits
	}
}
void Program::shiftDown() {
	if(map) {
		int w=map->getW();
		int h=map->getH()-1;
		for (int i=0; i<w; i++)
			for (int j=h; j>0; j--)
				map->copyXY(i,j  ,  i,j-1);
		for (int i = 0; i < map->getMaxFactions(); ++i)     // move players
			if (map->getStartLocationX(i) != 0 || map->getStartLocationY(i) != 0) // don't move the unset ones
				map->changeStartLocation(map->getStartLocationX(i), map->getStartLocationY(i)+1, i); // it allready check limits
	}
}


void Program::randomizeMapHeights(bool withReset,int minimumHeight, int maximumHeight, int chanceDevider, int smoothRecursions) {
	if(map) map->randomizeHeights(withReset, minimumHeight,  maximumHeight,  chanceDevider,  smoothRecursions);
}

void Program::randomizeFactions() {
	if(map) map->randomizeFactions();
}

void Program::switchMapSurfaces(int surf1, int surf2) {
	if(map) map->switchSurfaces(static_cast<MapSurfaceType>(surf1), static_cast<MapSurfaceType>(surf2));
}

void Program::reset(int w, int h, int alt, int surf) {
	undoStack.clear();
	redoStack.clear();
	if(map) map->reset(w, h, (float) alt, static_cast<MapSurfaceType>(surf));
}

void Program::resize(int w, int h, int alt, int surf) {
	if(map) map->resize(w, h, (float) alt, static_cast<MapSurfaceType>(surf));
}

void Program::resetFactions(int maxFactions) {
	if(map) map->resetFactions(maxFactions);
	randomizeFactions();
}

bool Program::setMapTitle(const string &title) {
	if(map) {
		if (map->getTitle() != title) {
			map->setTitle(title);
			return true;
		}
	}
	return false;
}

bool Program::setMapDesc(const string &desc) {
	if(map) {
		if (map->getDesc() != desc) {
			map->setDesc(desc);
			return true;
		}
	}
	return false;
}

bool Program::setMapAuthor(const string &author) {
	if(map) {
		if (map->getAuthor() != author) {
			map->setAuthor(author);
			return true;
		}
	}
	return false;
}

void Program::setOfset(int x, int y) {
	ofsetX += x;
	ofsetY -= y;
}

void Program::incCellSize(int i) {
	if(map) {
		int minInc = 2 - cellSize;

		if (i < minInc) {
			i = minInc;
		}
		cellSize += i;
		ofsetX -= (map->getW() * i) / 2;
		ofsetY += (map->getH() * i) / 2;
	}
}

void Program::resetOfset() {
	ofsetX = 0;
	ofsetY = 0;
	cellSize = 5;
}

bool Program::setGridOnOff() {
    grid=!grid;
    return grid;
}
bool Program::setHeightMapOnOff() {
    heightmap=!heightmap;
    return heightmap;
}
bool Program::setHideWaterOnOff() {
    hideWater=!hideWater;
    return hideWater;
}

void Program::setMapAdvanced(int altFactor, int waterLevel, int cliffLevel , int cameraHeight) {
	if(map) map->setAdvanced(altFactor, waterLevel, cliffLevel, cameraHeight);
}

void Program::loadMap(const string &path) {
	undoStack.clear();
	redoStack.clear();

	std::string encodedPath = path;
	map->loadFromFile(encodedPath);
}

void Program::saveMap(const string &path) {
	if(map) {
		std::string encodedPath = path;

		map->saveToFile(encodedPath);
	}
}

}// end namespace