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
|
// ==============================================================
// 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
// ==============================================================
#ifndef _MAPEDITOR_PROGRAM_H_
#define _MAPEDITOR_PROGRAM_H_
//#include "map.h"
#include "map_preview.h"
//#include "renderer.h"
#include "base_renderer.h"
#include <stack>
using std::stack;
using namespace Shared::Map;
using namespace Shared::Graphics;
namespace MapEditor {
class MainWindow;
enum ChangeType {
ctNone = -1,
ctHeight,
ctSurface,
ctObject,
ctResource,
ctLocation,
ctGradient,
ctAll
};
// =============================================
// class Undo Point
// A linked list class that is more of an extension / modification on
// the already existing Cell struct in map.h
// Provides the ability to only specify a certain property of the map to change
// =============================================
class UndoPoint {
private:
// Only keep a certain number of undo points in memory otherwise
// Big projects could hog a lot of memory
const static int MAX_UNDO_LIST_SIZE = 100;
static int undoCount;
ChangeType change;
// Pointers to arrays of each property
int *surface;
int *object;
int *resource;
float *height;
// Map width and height
static int w;
static int h;
public:
UndoPoint();
~UndoPoint();
void init(ChangeType change);
void revert();
inline ChangeType getChange() const { return change; }
};
class ChangeStack : public std::stack<UndoPoint> {
public:
static const unsigned int maxSize = 100;
ChangeStack() : std::stack<UndoPoint>() { }
void clear() { c.clear(); }
void push(UndoPoint p) {
if (c.size() >= maxSize) {
c.pop_front();
}
stack<UndoPoint>::push(p);
}
};
// ===============================================
// class Program
// ===============================================
class Program {
private:
//Renderer renderer;
BaseRenderer renderer;
int ofsetX, ofsetY;
int cellSize;
bool grid; // show grid option
bool heightmap;
bool hideWater;
//static Map *map;
static MapPreview *map;
friend class UndoPoint;
ChangeStack undoStack, redoStack;
void init();
public:
Program(int w, int h, string playerName);
~Program();
Program(const Program& obj) {
init();
throw runtime_error("class Program is NOT safe to copy!");
}
Program & operator=(const Program& obj) {
init();
throw runtime_error("class Program is NOT safe to assign!");
}
//map cell change
void glestChangeMapHeight(int x, int y, int Height, int radius);
void pirateChangeMapHeight(int x, int y, int Height, int radius);
void changeMapSurface(int x, int y, int surface, int radius);
void changeMapObject(int x, int y, int object, int radius);
void changeMapResource(int x, int y, int resource, int radius);
void changeStartLocation(int x, int y, int player);
void setUndoPoint(ChangeType change);
bool undo();
bool redo();
//map ops
void reset(int w, int h, int alt, int surf);
void resize(int w, int h, int alt, int surf);
void resetFactions(int maxFactions);
void setRefAlt(int x, int y);
void flipX();
void flipY();
void mirrorX();
void mirrorY();
void mirrorXY();
void rotatecopyX();
void rotatecopyY();
void rotatecopyXY();
void rotatecopyCorner();
void flipDiagonal();
void shiftLeft();
void shiftRight();
void shiftUp();
void shiftDown();
void randomizeMapHeights(bool withReset, int minimumHeight, int maximumHeight, int chanceDivider, int smoothRecursions);;
void randomizeFactions();
void switchMapSurfaces(int surf1, int surf2);
void loadMap(const string &path);
void saveMap(const string &path);
//map misc
bool setMapTitle(const string &title);
bool setMapDesc(const string &desc);
bool setMapAuthor(const string &author);
void setMapAdvanced(int altFactor, int waterLevel, int minimumCliffHeight, int cameraHeight);
//misc
void renderMap(int w, int h);
void setOfset(int x, int y);
void incCellSize(int i);
void resetOfset();
bool setGridOnOff();
bool setHeightMapOnOff();
bool setHideWaterOnOff();
int getObject(int x, int y);
int getResource(int x, int y);
int getCellX(int x);
int getCellY(int y);
static const MapPreview *getMap() {return map;}
};
}// end namespace
#endif
|