- added null checks for map editor

This commit is contained in:
Mark Vejvoda 2011-01-29 21:44:09 +00:00
parent f2467faebe
commit d4370675be
2 changed files with 264 additions and 232 deletions

View File

@ -489,8 +489,10 @@ void MainWindow::onPaint(wxPaintEvent &event) {
if(panel) panel->Update(); if(panel) panel->Update();
if(menuBar) menuBar->Update(); if(menuBar) menuBar->Update();
program->renderMap(glCanvas->GetClientSize().x, glCanvas->GetClientSize().y); if(program && glCanvas) {
glCanvas->SwapBuffers(); program->renderMap(glCanvas->GetClientSize().x, glCanvas->GetClientSize().y);
glCanvas->SwapBuffers();
}
event.Skip(); event.Skip();
} }

View File

@ -155,15 +155,16 @@ Program::Program(int w, int h) {
Program::~Program() { Program::~Program() {
delete map; delete map;
map = NULL;
} }
int Program::getObject(int x, int y) { int Program::getObject(int x, int y) {
int i=(x - ofsetX) / cellSize; int i=(x - ofsetX) / cellSize;
int j= (y + ofsetY) / cellSize; int j= (y + ofsetY) / cellSize;
if (map->inside(i, j)) { if (map && map->inside(i, j)) {
return map->getObject(i,j); return map->getObject(i,j);
} }
else{ else {
return 0; return 0;
} }
} }
@ -171,37 +172,37 @@ int Program::getObject(int x, int y) {
int Program::getResource(int x, int y) { int Program::getResource(int x, int y) {
int i=(x - ofsetX) / cellSize; int i=(x - ofsetX) / cellSize;
int j= (y + ofsetY) / cellSize; int j= (y + ofsetY) / cellSize;
if (map->inside(i, j)) { if (map && map->inside(i, j)) {
return map->getResource(i,j); return map->getResource(i,j);
} }
else{ else {
return 0; return 0;
} }
} }
// TODO: move editor-specific code from shared_lib to here. // TODO: move editor-specific code from shared_lib to here.
void Program::glestChangeMapHeight(int x, int y, int Height, int radius) { void Program::glestChangeMapHeight(int x, int y, int Height, int radius) {
map->glestChangeHeight((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, Height, radius); if(map) map->glestChangeHeight((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, Height, radius);
} }
void Program::pirateChangeMapHeight(int x, int y, int Height, int radius) { void Program::pirateChangeMapHeight(int x, int y, int Height, int radius) {
map->pirateChangeHeight((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, Height, radius); if(map) map->pirateChangeHeight((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, Height, radius);
} }
void Program::changeMapSurface(int x, int y, int surface, int radius) { void Program::changeMapSurface(int x, int y, int surface, int radius) {
map->changeSurface((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, static_cast<MapSurfaceType>(surface), 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) { void Program::changeMapObject(int x, int y, int object, int radius) {
map->changeObject((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, object, radius); if(map) map->changeObject((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, object, radius);
} }
void Program::changeMapResource(int x, int y, int resource, int radius) { void Program::changeMapResource(int x, int y, int resource, int radius) {
map->changeResource((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, resource, radius); if(map) map->changeResource((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, resource, radius);
} }
void Program::changeStartLocation(int x, int y, int player) { void Program::changeStartLocation(int x, int y, int player) {
map->changeStartLocation((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, player); if(map) map->changeStartLocation((x - ofsetX) / cellSize, (y + ofsetY) / cellSize, player);
} }
void Program::setUndoPoint(ChangeType change) { void Program::setUndoPoint(ChangeType change) {
@ -240,309 +241,337 @@ bool Program::redo() {
} }
void Program::renderMap(int w, int h) { void Program::renderMap(int w, int h) {
renderer.renderMap(map, ofsetX, ofsetY, w, h, cellSize, grid); if(map) renderer.renderMap(map, ofsetX, ofsetY, w, h, cellSize, grid);
} }
void Program::setRefAlt(int x, int y) { void Program::setRefAlt(int x, int y) {
map->setRefAlt((x - ofsetX) / cellSize, (y + ofsetY) / cellSize); if(map) map->setRefAlt((x - ofsetX) / cellSize, (y + ofsetY) / cellSize);
} }
void Program::flipX() { void Program::flipX() {
map->flipX(); if(map) map->flipX();
} }
void Program::flipY() { void Program::flipY() {
map->flipY(); if(map) map->flipY();
} }
void Program::mirrorX() { // copy left to right void Program::mirrorX() { // copy left to right
int w=map->getW(); if(map) {
int h=map->getH(); int w=map->getW();
for (int i = 0; i < w/2; i++) { int h=map->getH();
for (int j = 0; j < h; j++) { for (int i = 0; i < w/2; i++) {
map->copyXY(w-i-1,j , i,j); for (int j = 0; j < h; j++) {
map->copyXY(w-i-1,j , i,j);
}
} }
}
// move players // move players
for (int i = 0; i < map->getMaxFactions(); ++i) // first remove players from target corner 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); if (map->getStartLocationX(i) >= w/2) map->changeStartLocation(0,0,i);
for (int i = 0; i < map->getMaxFactions(); ++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? 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) for (int ii = 0; ii < map->getMaxFactions(); ++ii)
if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii)==0) { // first free one if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii)==0) { // first free one
map->changeStartLocation(w-map->getStartLocationX(i)-1, map->getStartLocationY(i), ii); map->changeStartLocation(w-map->getStartLocationX(i)-1, map->getStartLocationY(i), ii);
break; break;
} }
}
} }
} }
void Program::mirrorY() { // copy top to bottom void Program::mirrorY() { // copy top to bottom
int w=map->getW(); if(map) {
int h=map->getH(); int w=map->getW();
for (int i = 0; i < w; i++) { int h=map->getH();
for (int j = 0; j < h/2; j++) { for (int i = 0; i < w; i++) {
map->copyXY(i,h-j-1 , i,j); for (int j = 0; j < h/2; j++) {
map->copyXY(i,h-j-1 , i,j);
}
} }
}
// move players // move players
for (int i = 0; i < map->getMaxFactions(); ++i) // first remove players from target corner 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); if (map->getStartLocationY(i) >= h/2) map->changeStartLocation(0,0,i);
for (int i = 0; i < map->getMaxFactions(); ++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? 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) for (int ii = 0; ii < map->getMaxFactions(); ++ii)
if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii)==0) { // first free one if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii)==0) { // first free one
map->changeStartLocation(map->getStartLocationX(i), h-map->getStartLocationY(i)-1, ii); map->changeStartLocation(map->getStartLocationX(i), h-map->getStartLocationY(i)-1, ii);
break; break;
} }
}
} }
} }
void Program::mirrorXY() { // copy leftbottom to topright, can handle non-sqaure maps void Program::mirrorXY() { // copy leftbottom to topright, can handle non-sqaure maps
int w=map->getW(); if(map) {
int h=map->getH(); int w=map->getW();
if (h==w) { int h=map->getH();
for (int i = 0; i < w-1; i++) { if (h==w) {
for (int j = i+1; j < h; j++) { for (int i = 0; i < w-1; i++) {
map->copyXY(j,i , i,j); for (int j = i+1; j < h; j++) {
} map->copyXY(j,i , i,j);
} }
} }
// Non-sqaure maps: }
else if (h < w) { // copy horizontal strips // Non-sqaure maps:
int s=w/h; // 2 if twice as wide as heigh else if (h < w) { // copy horizontal strips
for (int i = 0; i < w/s-1; i++) { int s=w/h; // 2 if twice as wide as heigh
for (int j = i+1; j < h; j++) { for (int i = 0; i < w/s-1; i++) {
for (int p = 0; p < s; p++) map->copyXY(j*s+p,i , i*s+p,j); 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 else { // copy vertical strips
for (int i = 0; i < w-1; i++) { int s=h/w; // 2 if twice as heigh as wide
for (int j = i+1; j < h/s; j++) { for (int i = 0; i < w-1; i++) {
for (int p = 0; p < s; p++) map->copyXY(j,i*s+p , i,j*s+p); 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 // move players
for (int i = 0; i < map->getMaxFactions(); ++i) // first remove players from target corner 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); if (map->getStartLocationX(i) > map->getStartLocationY(i)) map->changeStartLocation(0,0,i);
for (int i = 0; i < map->getMaxFactions(); ++i) { for (int i = 0; i < map->getMaxFactions(); ++i) {
if(map->getStartLocationX(i) < map->getStartLocationY(i)) // any startpositions to copy? if(map->getStartLocationX(i) < map->getStartLocationY(i)) // any startpositions to copy?
for (int ii = 0; ii < map->getMaxFactions(); ++ii) for (int ii = 0; ii < map->getMaxFactions(); ++ii)
if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii) == 0) { // first free one 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); map->changeStartLocation(map->getStartLocationY(i)*w/h, map->getStartLocationX(i)*h/w, ii);
break; break;
} }
}
} }
} }
void Program::rotatecopyX() { void Program::rotatecopyX() {
int w=map->getW(); if(map) {
int h=map->getH(); int w=map->getW();
for (int i = 0; i < w/2; i++) { int h=map->getH();
for (int j = 0; j < h; j++) { for (int i = 0; i < w/2; i++) {
map->copyXY(w-i-1,h-j-1 , i,j); for (int j = 0; j < h; j++) {
map->copyXY(w-i-1,h-j-1 , i,j);
}
} }
}
// move players // move players
for (int i = 0; i < map->getMaxFactions(); ++i) // first remove players from target corner 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); if (map->getStartLocationX(i) >= w/2) map->changeStartLocation(0,0,i);
for (int i = 0; i < map->getMaxFactions(); ++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? 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) for (int ii = 0; ii < map->getMaxFactions(); ++ii)
if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii)==0) { // first free one 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); map->changeStartLocation(w-map->getStartLocationX(i)-1, h-map->getStartLocationY(i)-1, ii);
break; break;
} }
}
} }
} }
void Program::rotatecopyY() { void Program::rotatecopyY() {
int w=map->getW(); if(map) {
int h=map->getH(); int w=map->getW();
for (int i = 0; i < w; i++) { int h=map->getH();
for (int j = 0; j < h/2; j++) { for (int i = 0; i < w; i++) {
map->copyXY(w-i-1,h-j-1 , i,j); for (int j = 0; j < h/2; j++) {
map->copyXY(w-i-1,h-j-1 , i,j);
}
} }
}
// move players // move players
for (int i = 0; i < map->getMaxFactions(); ++i) // first remove players from target corner 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); if (map->getStartLocationY(i) >= h/2) map->changeStartLocation(0,0,i);
for (int i = 0; i < map->getMaxFactions(); ++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? 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) for (int ii = 0; ii < map->getMaxFactions(); ++ii)
if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii)==0) { // first free one 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); map->changeStartLocation(w-map->getStartLocationX(i)-1, h-map->getStartLocationY(i)-1, ii);
break; break;
} }
}
} }
} }
void Program::rotatecopyXY() { void Program::rotatecopyXY() {
int w=map->getW(); if(map) {
int h=map->getH(); int w=map->getW();
int sw=w/h; if(sw<1) sw=1; // x-squares per y int h=map->getH();
int sh=h/w; if(sh<1) sh=1; // y-squares per x int sw=w/h; if(sw<1) sw=1; // x-squares per y
if (sh==1) int sh=h/w; if(sh<1) sh=1; // y-squares per x
for (int j = 0; j < h-1; j++) { // row by row! if (sh==1)
for (int i = j*sw; i < w; i++) { for (int j = 0; j < h-1; j++) { // row by row!
map->copyXY(i,j , w-i-1,h-j-1); 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! else
for (int j = h-1-i*sh; j >= 0; j--) { for (int i = 0; i <w; i++) { // column for colum!
map->copyXY(w-i-1,j , i,h-j-1); for (int j = h-1-i*sh; j >= 0; j--) {
} map->copyXY(w-i-1,j , i,h-j-1);
} }
}
// move players // move players
for (int i = 0; i < map->getMaxFactions(); ++i) // first remove players from target corner 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); if (map->getStartLocationX(i) > map->getStartLocationY(i)) map->changeStartLocation(0,0,i);
for (int i = 0; i < map->getMaxFactions(); ++i) { for (int i = 0; i < map->getMaxFactions(); ++i) {
if(map->getStartLocationX(i) < map->getStartLocationY(i)) // any startpositions to copy? if(map->getStartLocationX(i) < map->getStartLocationY(i)) // any startpositions to copy?
for (int ii = 0; ii < map->getMaxFactions(); ++ii) for (int ii = 0; ii < map->getMaxFactions(); ++ii)
if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii) == 0) { // first free one 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); map->changeStartLocation(w-map->getStartLocationX(i)-1, h-map->getStartLocationY(i)-1, ii);
break; break;
} }
}
} }
} }
void Program::rotatecopyCorner() { // rotate top left 1/4 to top right 1/4 void Program::rotatecopyCorner() { // rotate top left 1/4 to top right 1/4
int w=map->getW(); if(map) {
int h=map->getH(); int w=map->getW();
if (h==w) { int h=map->getH();
for (int i = 0; i < w/2; i++) { if (h==w) {
for (int j = 0; j < h/2; j++) { for (int i = 0; i < w/2; i++) {
map->copyXY(w-j-1,i , i,j); 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 // Non-sqaure maps:
int s=w/h; // 2 if twice as wide as heigh else if (h < w) { // copy horizontal strips
for (int i = 0; i < w/s/2; i++) { int s=w/h; // 2 if twice as wide as heigh
for (int j = 0; j < h/2; j++) { for (int i = 0; i < w/s/2; i++) {
for (int p = 0; p < s; p++) map->copyXY(w-j*s-1-p,i , i*s+p,j); 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 else { // copy vertical strips
for (int i = 0; i < w/2; i++) { int s=h/w; // 2 if twice as heigh as wide
for (int j = 0; j < h/s/2; j++) { for (int i = 0; i < w/2; i++) {
for (int p = 0; p < s; p++) map->copyXY(w-j-1,i*s+p , i,j*s+p); 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 // move players
for (int i = 0; i < map->getMaxFactions(); ++i) // first remove players from target corner 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); if (map->getStartLocationX(i) >= w/2 && map->getStartLocationY(i) < h/2) map->changeStartLocation(0,0,i);
for (int i = 0; i < map->getMaxFactions(); ++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? 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) for (int ii = 0; ii < map->getMaxFactions(); ++ii)
if(map->getStartLocationX(ii)==0 && map->getStartLocationY(ii)==0) { // first free one 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); map->changeStartLocation(w-map->getStartLocationY(i)*w/h-1, map->getStartLocationX(i)*h/w, ii);
break; break;
} }
}
} }
} }
void Program::shiftLeft() { void Program::shiftLeft() {
int w=map->getW()-1; if(map) {
int h=map->getH(); int w=map->getW()-1;
for (int i=0; i<w; i++) int h=map->getH();
for (int j=0; j<h; j++) for (int i=0; i<w; i++)
map->copyXY(i,j , i+1,j); for (int j=0; j<h; j++)
for (int i = 0; i < map->getMaxFactions(); ++i) // move players map->copyXY(i,j , i+1,j);
map->changeStartLocation(map->getStartLocationX(i)-1, map->getStartLocationY(i), i); // it allready check limits 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::shiftRight() { void Program::shiftRight() {
int w=map->getW()-1; if(map) {
int h=map->getH(); int w=map->getW()-1;
for (int i=w; i>0; i--) int h=map->getH();
for (int j=0; j<h; j++) for (int i=w; i>0; i--)
map->copyXY(i,j , i-1,j); for (int j=0; j<h; j++)
for (int i = 0; i < map->getMaxFactions(); ++i) // move players map->copyXY(i,j , i-1,j);
if (map->getStartLocationX(i) != 0 || map->getStartLocationY(i) != 0) // don't move the unset ones for (int i = 0; i < map->getMaxFactions(); ++i) // move players
map->changeStartLocation(map->getStartLocationX(i)+1, map->getStartLocationY(i), i); // it allready check limits 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() { void Program::shiftUp() {
int w=map->getW(); if(map) {
int h=map->getH()-1; int w=map->getW();
for (int i=0; i<w; i++) int h=map->getH()-1;
for (int j=0; j<h; j++) for (int i=0; i<w; i++)
map->copyXY(i,j , i,j+1); for (int j=0; j<h; j++)
for (int i = 0; i < map->getMaxFactions(); ++i) // move players map->copyXY(i,j , i,j+1);
map->changeStartLocation(map->getStartLocationX(i), map->getStartLocationY(i)-1, i); // it allready check limits 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() { void Program::shiftDown() {
int w=map->getW(); if(map) {
int h=map->getH()-1; int w=map->getW();
for (int i=0; i<w; i++) int h=map->getH()-1;
for (int j=h; j>0; j--) for (int i=0; i<w; i++)
map->copyXY(i,j , i,j-1); for (int j=h; j>0; j--)
for (int i = 0; i < map->getMaxFactions(); ++i) // move players map->copyXY(i,j , i,j-1);
if (map->getStartLocationX(i) != 0 || map->getStartLocationY(i) != 0) // don't move the unset ones for (int i = 0; i < map->getMaxFactions(); ++i) // move players
map->changeStartLocation(map->getStartLocationX(i), map->getStartLocationY(i)+1, i); // it allready check limits 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() { void Program::randomizeMapHeights() {
map->randomizeHeights(); if(map) map->randomizeHeights();
} }
void Program::randomizeMap() { void Program::randomizeMap() {
map->randomize(); if(map) map->randomize();
} }
void Program::switchMapSurfaces(int surf1, int surf2) { void Program::switchMapSurfaces(int surf1, int surf2) {
map->switchSurfaces(static_cast<MapSurfaceType>(surf1), static_cast<MapSurfaceType>(surf2)); if(map) map->switchSurfaces(static_cast<MapSurfaceType>(surf1), static_cast<MapSurfaceType>(surf2));
} }
void Program::reset(int w, int h, int alt, int surf) { void Program::reset(int w, int h, int alt, int surf) {
undoStack.clear(); undoStack.clear();
redoStack.clear(); redoStack.clear();
map->reset(w, h, (float) alt, static_cast<MapSurfaceType>(surf)); if(map) map->reset(w, h, (float) alt, static_cast<MapSurfaceType>(surf));
} }
void Program::resize(int w, int h, int alt, int surf) { void Program::resize(int w, int h, int alt, int surf) {
map->resize(w, h, (float) alt, static_cast<MapSurfaceType>(surf)); if(map) map->resize(w, h, (float) alt, static_cast<MapSurfaceType>(surf));
} }
void Program::resetFactions(int maxFactions) { void Program::resetFactions(int maxFactions) {
map->resetFactions(maxFactions); if(map) map->resetFactions(maxFactions);
} }
bool Program::setMapTitle(const string &title) { bool Program::setMapTitle(const string &title) {
if (map->getTitle() != title) { if(map) {
map->setTitle(title); if (map->getTitle() != title) {
return true; map->setTitle(title);
return true;
}
} }
return false; return false;
} }
bool Program::setMapDesc(const string &desc) { bool Program::setMapDesc(const string &desc) {
if (map->getDesc() != desc) { if(map) {
map->setDesc(desc); if (map->getDesc() != desc) {
return true; map->setDesc(desc);
return true;
}
} }
return false; return false;
} }
bool Program::setMapAuthor(const string &author) { bool Program::setMapAuthor(const string &author) {
if (map->getAuthor() != author) { if(map) {
map->setAuthor(author); if (map->getAuthor() != author) {
return true; map->setAuthor(author);
return true;
}
} }
return false; return false;
} }
@ -553,15 +582,16 @@ void Program::setOfset(int x, int y) {
} }
void Program::incCellSize(int i) { void Program::incCellSize(int i) {
if(map) {
int minInc = 2 - cellSize;
int minInc = 2 - cellSize; if (i < minInc) {
i = minInc;
if (i < minInc) { }
i = minInc; cellSize += i;
ofsetX -= (map->getW() * i) / 2;
ofsetY += (map->getH() * i) / 2;
} }
cellSize += i;
ofsetX -= (map->getW() * i) / 2;
ofsetY += (map->getH() * i) / 2;
} }
void Program::resetOfset() { void Program::resetOfset() {
@ -576,7 +606,7 @@ bool Program::setGridOnOff() {
} }
void Program::setMapAdvanced(int altFactor, int waterLevel) { void Program::setMapAdvanced(int altFactor, int waterLevel) {
map->setAdvanced(altFactor, waterLevel); if(map) map->setAdvanced(altFactor, waterLevel);
} }
void Program::loadMap(const string &path) { void Program::loadMap(const string &path) {
@ -586,7 +616,7 @@ void Program::loadMap(const string &path) {
} }
void Program::saveMap(const string &path) { void Program::saveMap(const string &path) {
map->saveToFile(path); if(map) map->saveToFile(path);
} }
}// end namespace }// end namespace