up to 36 units selectable; maps can set camera heigth now ( be careful with this for performance reasons! )

This commit is contained in:
Titus Tscharntke 2011-02-25 00:31:42 +00:00
parent 4cb2485cdf
commit 922df8e025
12 changed files with 65 additions and 17 deletions

View File

@ -552,7 +552,11 @@ void Game::init(bool initForPreviewOnly)
gameCamera.init(map->getW(), map->getH());
if(gameCamera.getCalculatedDefault()<map->getMaxMapHeight()+13.0f){
// camera default height calculation
if(map->getCameraHeight()>0 && gameCamera.getCalculatedDefault()<map->getCameraHeight()){
gameCamera.setCalculatedDefault(map->getCameraHeight());
}
else if(gameCamera.getCalculatedDefault()<map->getMaxMapHeight()+13.0f){
gameCamera.setCalculatedDefault(map->getMaxMapHeight()+13.0f);
}

View File

@ -3195,7 +3195,7 @@ void Renderer::renderDisplay(){
renderQuad(
metrics.getDisplayX()+display->computeUpX(i),
metrics.getDisplayY()+display->computeUpY(i),
Display::imageSize, Display::imageSize, display->getUpImage(i));
display->getUpImageSize(), display->getUpImageSize(), display->getUpImage(i));
}
}

View File

@ -39,12 +39,21 @@ Display::Display(){
colors[8]= Vec4f(1.0f, 1.0f, 1.0f, 1.0f);
currentColor= 0;
clear();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}
void Display::calculateUpDimensions(int index) {
if(index>maxUpIndex){
maxUpIndex=index;
if(maxUpIndex+1>upCellSideCount*upCellSideCount){
upCellSideCount=upCellSideCount+1;
upImageSize=imageSize*cellSideCount/upCellSideCount+0.9f;
}
}
}
Vec4f Display::getColor() const {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] currentColor = %d\n",__FILE__,__FUNCTION__,__LINE__,currentColor);
if(currentColor < 0 || currentColor >= colorCount) {
@ -54,6 +63,13 @@ Vec4f Display::getColor() const {
return colors[currentColor];
}
void Display::setUpImage(int i, const Texture2D *image)
{
if(i>=upCellCount) throw runtime_error("i>=upCellCount in Display::setUpImage");
upImages[i]= image;
calculateUpDimensions(i);
}
//misc
void Display::clear(){
for(int i=0; i<upCellCount; ++i){
@ -71,6 +87,10 @@ void Display::clear(){
title.clear();
text.clear();
progressBar= -1;
upCellSideCount=cellSideCount;
upImageSize=imageSize;
maxUpIndex= 0;
}
void Display::switchColor(){
currentColor= (currentColor+1) % colorCount;
@ -103,11 +123,11 @@ int Display::computeDownY(int index) const{
}
int Display::computeUpX(int index) const{
return (index % cellSideCount) * imageSize;
return (index % upCellSideCount) * upImageSize;
}
int Display::computeUpY(int index) const{
return Metrics::getInstance().getDisplayH() - (index/cellSideCount)*imageSize - imageSize;
return Metrics::getInstance().getDisplayH() - (index/upCellSideCount)*upImageSize - upImageSize;
}
}}//end namespace

View File

@ -37,7 +37,7 @@ namespace Glest{ namespace Game{
class Display{
public:
static const int cellSideCount= 4;
static const int upCellCount= cellSideCount*cellSideCount;
static const int upCellCount= 36;
static const int downCellCount= cellSideCount*cellSideCount;
static const int colorCount= 9;
static const int imageSize= 32;
@ -58,6 +58,10 @@ private:
int downSelectedPos;
Vec4f colors[colorCount];
int currentColor;
int upCellSideCount;
int upImageSize;
int maxUpIndex;
public:
@ -75,12 +79,14 @@ public:
Vec4f getColor() const;
int getProgressBar() const {return progressBar;}
int getDownSelectedPos() const {return downSelectedPos;}
int getUpCellSideCount() const {return upCellSideCount;}
int getUpImageSize() const {return upImageSize;}
//set
void setTitle(const string title) {this->title= formatString(title);}
void setText(const string &text) {this->text= formatString(text);}
void setInfoText(const string infoText) {this->infoText= formatString(infoText);}
void setUpImage(int i, const Texture2D *image) {upImages[i]= image;}
void setUpImage(int i, const Texture2D *image);
void setDownImage(int i, const Texture2D *image) {downImages[i]= image;}
void setCommandType(int i, const CommandType *ct) {commandTypes[i]= ct;}
void setCommandClass(int i, const CommandClass cc) {commandClasses[i]= cc;}
@ -96,6 +102,9 @@ public:
int computeDownY(int index) const;
int computeUpX(int index) const;
int computeUpY(int index) const;
private:
void calculateUpDimensions(int index);
};
}}//end namespace

View File

@ -35,7 +35,7 @@ public:
public:
static const int maxGroups= 10;
static const int maxUnits= 16;
static const int maxUnits= 36;
private:
int factionIndex;

View File

@ -106,6 +106,7 @@ Map::Map() {
waterLevel=0;
heightFactor=0;
cliffLevel=0;
cameraHeight=0;
w=0;
h=0;
surfaceW=0;
@ -204,6 +205,7 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
w= surfaceW*cellScale;
h= surfaceH*cellScale;
cliffLevel = 0;
cameraHeight = 0;
if(header.version==1){
//desc = header.description;
}
@ -212,8 +214,9 @@ Checksum Map::load(const string &path, TechTree *techTree, Tileset *tileset) {
if(header.version2.cliffLevel>0){
cliffLevel=static_cast<float>((header.version2.cliffLevel-0.01f)/(heightFactor));
}
else {
cliffLevel=0;
if(header.version2.cameraHeight>0)
{
cameraHeight = header.version2.cameraHeight;
}
}

View File

@ -157,6 +157,7 @@ private:
float waterLevel;
float heightFactor;
float cliffLevel;
int cameraHeight;
int w;
int h;
int surfaceW;
@ -195,6 +196,7 @@ public:
float getHeightFactor() const {return heightFactor;}
float getWaterLevel() const {return waterLevel;}
float getCliffLevel() const {return cliffLevel;}
int getCameraHeight() const {return cameraHeight;}
float getMaxMapHeight() const {return maxMapHeight;}
Vec2i getStartLocation(int locationIndex) const;
bool getSubmerged(const SurfaceCell *sc) const {return sc->getHeight()<waterLevel;}

View File

@ -726,13 +726,15 @@ void MainWindow::onMenuEditAdvanced(wxCommandEvent &event) {
simpleDialog.addValue("Height Factor", intToStr(program->getMap()->getHeightFactor()),"(lower means map is more more zoomed in)");
simpleDialog.addValue("Water Level", intToStr(program->getMap()->getWaterLevel()),"(water is visible below this, and walkable until 1.5 less)");
simpleDialog.addValue("Cliff Level", intToStr(program->getMap()->getCliffLevel()),"(neighboring fields with at least this heights difference are cliffs)");
simpleDialog.addValue("Camera Height", intToStr(program->getMap()->getCameraHeight()),"(you can give a camera heigth here default is 0 ;ignored if <20)");
if (!simpleDialog.show("Advanced")) return;
try {
program->setMapAdvanced(
strToInt(simpleDialog.getValue("Height Factor")),
strToInt(simpleDialog.getValue("Water Level")),
strToInt(simpleDialog.getValue("Cliff Level")));
strToInt(simpleDialog.getValue("Cliff Level")),
strToInt(simpleDialog.getValue("Camera Height")));
}
catch (const exception &e) {
MsgDialog(this, ToUnicode(e.what()), wxT("Exception"), wxOK | wxICON_ERROR).ShowModal();

View File

@ -605,8 +605,8 @@ bool Program::setGridOnOff() {
return grid;
}
void Program::setMapAdvanced(int altFactor, int waterLevel, int cliffLevel) {
if(map) map->setAdvanced(altFactor, waterLevel, cliffLevel);
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) {

View File

@ -148,7 +148,7 @@ public:
bool setMapTitle(const string &title);
bool setMapDesc(const string &desc);
bool setMapAuthor(const string &author);
void setMapAdvanced(int altFactor, int waterLevel, int minimumCliffHeight);
void setMapAdvanced(int altFactor, int waterLevel, int minimumCliffHeight, int cameraHeight);
//misc
void renderMap(int w, int h);

View File

@ -75,7 +75,8 @@ struct MapFileHeader {
int8 short_desc[MAX_DESCRIPTION_LENGTH_VERSION2];
int32 magic; // 0x01020304 for meta
int32 cliffLevel;
int8 meta[120];
int32 cameraHeight;
int8 meta[116];
} version2;
};
};
@ -113,6 +114,7 @@ private:
int heightFactor;
int waterLevel;
int cliffLevel;
int cameraHeight;
//Cell **cells;
std::vector<std::vector<Cell> > cells;
@ -136,10 +138,12 @@ public:
int getHeightFactor() const{return heightFactor;}
int getWaterLevel() const{return waterLevel;}
int getCliffLevel() const{return cliffLevel;}
int getCameraHeight() const{return cameraHeight;}
bool inside(int x, int y);
void setRefAlt(int x, int y);
void setAdvanced(int heightFactor, int waterLevel, int cliffLevel);
void setAdvanced(int heightFactor, int waterLevel, int cliffLevel, int cameraHeight);
void setTitle(const string &title);
void setDesc(const string &desc);
void setAuthor(const string &author);

View File

@ -32,6 +32,7 @@ MapPreview::MapPreview() {
heightFactor = DEFAULT_MAP_CELL_HEIGHT_FACTOR;
waterLevel = DEFAULT_MAP_WATER_DEPTH;
cliffLevel = DEFAULT_CLIFF_HEIGHT;
cameraHeight = 0;
//cells = NULL;
cells.clear();
//startLocations = NULL;
@ -630,10 +631,11 @@ void MapPreview::setAuthor(const string &author) {
this->author = author;
}
void MapPreview::setAdvanced(int heightFactor, int waterLevel, int cliffLevel) {
void MapPreview::setAdvanced(int heightFactor, int waterLevel, int cliffLevel, int cameraHeight) {
this->heightFactor = heightFactor;
this->waterLevel = waterLevel;
this->cliffLevel = cliffLevel;
this->cameraHeight = cameraHeight;
}
void MapPreview::randomizeHeights() {
@ -697,6 +699,7 @@ void MapPreview::loadFromFile(const string &path) {
else if(header.version==2){
desc = header.version2.short_desc;
cliffLevel=header.version2.cliffLevel;
cameraHeight=header.version2.cameraHeight;
}
//read start locations
@ -764,6 +767,7 @@ void MapPreview::saveToFile(const string &path) {
strncpy(header.version2.short_desc, desc.c_str(), MAX_DESCRIPTION_LENGTH_VERSION2);
header.version2.magic= 0x01020304;
header.version2.cliffLevel= cliffLevel;
header.version2.cameraHeight= cameraHeight;
fwrite(&header, sizeof(MapFileHeader), 1, f1);