1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00
vcmi/mapHandler.cpp

146 lines
4.0 KiB
C++

#include "stdafx.h"
#include "mapHandler.h"
#include "CSemiDefHandler.h"
#include "SDL_rotozoom.h"
#include "SDL_Extensions.h"
extern SDL_Surface * ekran;
void mapHandler::init()
{
terrainBitmap = new SDL_Surface **[reader->map.width];
for (int ii=0;ii<reader->map.width;ii++)
terrainBitmap[ii] = new SDL_Surface*[reader->map.height]; // allocate memory
for (int i=0; i<reader->map.width; i++)
{
for (int j=0; j<reader->map.height;j++)
{
TerrainTile zz = reader->map.terrain[i][j];
std::string name = CSemiDefHandler::nameFromType(reader->map.terrain[i][j].tertype);
for (unsigned int k=0; k<reader->defs.size(); k++)
{
try
{
if (reader->defs[k]->defName != name)
continue;
else
{
SDL_Surface * n;
int ktora = reader->map.terrain[i][j].terview;
terrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
//TODO: odwracanie
switch ((reader->map.terrain[i][j].siodmyTajemniczyBajt)%4)
{
case 1:
{
terrainBitmap[i][j] = CSDL_Ext::rotate01(terrainBitmap[i][j]);
break;
}
case 2:
{
terrainBitmap[i][j] = CSDL_Ext::hFlip(terrainBitmap[i][j]);
break;
}
case 3:
{
terrainBitmap[i][j] = CSDL_Ext::rotate03(terrainBitmap[i][j]);
break;
}
}
//SDL_BlitSurface(terrainBitmap[i][j],NULL,ekran,NULL); SDL_Flip(ekran);SDL_Delay(50);
break;
}
}
catch (...)
{ continue; }
}
}
}
if (reader->map.twoLevel)
{
undTerrainBitmap = new SDL_Surface **[reader->map.width];
for (int ii=0;ii<reader->map.width;ii++)
undTerrainBitmap[ii] = new SDL_Surface*[reader->map.height]; // allocate memory
for (int i=0; i<reader->map.width; i++)
{
for (int j=0; j<reader->map.height;j++)
{
TerrainTile zz = reader->map.undergroungTerrain[i][j];
std::string name = CSemiDefHandler::nameFromType(reader->map.undergroungTerrain[i][j].tertype);
for (unsigned int k=0; k<reader->defs.size(); k++)
{
try
{
if (reader->defs[k]->defName != name)
continue;
else
{
SDL_Surface * n;
int ktora = reader->map.undergroungTerrain[i][j].terview;
undTerrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
//TODO: odwracanie
switch ((reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt)%4)
{
case 1:
{
undTerrainBitmap[i][j] = CSDL_Ext::rotate01(undTerrainBitmap[i][j]);
break;
}
case 2:
{
undTerrainBitmap[i][j] = CSDL_Ext::hFlip(undTerrainBitmap[i][j]);
break;
}
case 3:
{
undTerrainBitmap[i][j] = CSDL_Ext::rotate03(undTerrainBitmap[i][j]);
break;
}
}
//SDL_BlitSurface(undTerrainBitmap[i][j],NULL,ekran,NULL); SDL_Flip(ekran);SDL_Delay(50);
break;
}
}
catch (...)
{ continue; }
}
}
}
}
}
SDL_Surface * mapHandler::terrainRect(int x, int y, int dx, int dy, int level)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
int rmask = 0xff000000;
int gmask = 0x00ff0000;
int bmask = 0x0000ff00;
int amask = 0x000000ff;
#else
int rmask = 0x000000ff;
int gmask = 0x0000ff00;
int bmask = 0x00ff0000;
int amask = 0xff000000;
#endif
SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32,
rmask, gmask, bmask, amask);
if (((dx+x)>((reader->map.width)) || (dy+y)>((reader->map.height))) || ((x<0)||(y<0) ) )
throw new std::string("Poza zakresem");
for (int bx=0; bx<dx; bx++)
{
for (int by=0; by<dy; by++)
{
SDL_Rect * sr = new SDL_Rect;
sr->y=by*32;
sr->x=bx*32;
sr->h=sr->w=32;
if (!level)
SDL_BlitSurface(terrainBitmap[bx+x][by+y],NULL,su,sr);
else
SDL_BlitSurface(undTerrainBitmap[bx+x][by+y],NULL,su,sr);
delete sr;
//SDL_BlitSurface(su,NULL,ekran,NULL);SDL_Flip(ekran);
}
}
return su;
}