1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

* poprawa wyświetlania obiektów

* upiększenie fragmentów kodu
* przesuwanie mapy przejechaniem kursora na skraj wyświetlanego obszaru
* ładne ramki przykrywające obiekty
* ulepszenie obsługi defów i lodów
* przyspieszenie przewijania map
This commit is contained in:
mateuszb
2007-07-07 16:04:15 +00:00
parent dd24f5cd40
commit 051094abcc
14 changed files with 338 additions and 259 deletions

View File

@@ -408,7 +408,6 @@ void CAmbarCendamo::deh3m()
std::vector<std::string> defsToUnpack;
for (int idd = 0 ; idd<defAmount; idd++) // reading defs
{
std::cout<<'\r'<<"Reading defs: "<<(100.0*idd)/((float)(defAmount))<<"% ";
int nameLength = readNormalNr(i,4);i+=4;
DefInfo vinya; // info about new def
for (int cd=0;cd<nameLength;cd++)
@@ -449,10 +448,19 @@ void CAmbarCendamo::deh3m()
//teceDef();
}
std::vector<CDefHandler *> dhandlers = CGameInfo::mainObj->lodh->extractManyFiles(defsToUnpack, std::string("newh3sprite.lod"));
std::vector<CDefHandler *> dhandlers = CGameInfo::mainObj->spriteh->extractManyFiles(defsToUnpack, std::string("newh3sprite.lod"));
for (int i=0;i<dhandlers.size();i++)
map.defy[i].handler=dhandlers[i];
std::cout<<'\r'<<"Reading defs: 100% "<<std::endl;
for(int vv=0; vv<map.defy.size(); ++vv)
{
for(int yy=0; yy<map.defy[vv].handler->ourImages.size(); ++yy)
{
map.defy[vv].handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map.defy[vv].handler->ourImages[yy].bitmap);
SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(map.defy[vv].handler->ourImages[yy].bitmap, alphaTransSurf);
SDL_FreeSurface(map.defy[vv].handler->ourImages[yy].bitmap);
map.defy[vv].handler->ourImages[yy].bitmap = bufs;
}
}
SDL_FreeSurface(alphaTransSurf);
THC std::cout<<"Wczytywanie defow: "<<th.getDif()<<std::endl;
////loading objects

Binary file not shown.

Binary file not shown.

View File

@@ -33,7 +33,8 @@ public:
CMusicHandler * mush;
CSemiLodHandler * sspriteh;
CDefObjInfoHandler * dobjinfo;
CLodHandler * lodh;
CLodHandler * spriteh;
CLodHandler * bitmaph;
};
#endif //CGAMEINFO_H

View File

@@ -278,55 +278,56 @@ std::vector<CDefHandler *> CLodHandler::extractManyFiles(std::vector<std::string
{
std::transform(defNamesIn[hh].begin(), defNamesIn[hh].end(), defNamesIn[hh].begin(), (int(*)(int))toupper);
}
std::ifstream FLOD;
//std::ifstream FLOD;
std::ofstream FOut;
int i;
std::string Ts;
//std::cout<<"*** Loading FAT ... \n";
FLOD.open(lodName.c_str(),std::ios::binary);
//std::cout<<"*** Archive: "+FName+" loaded\n";
FLOD.seekg(8,std::ios_base::beg);
unsigned char temp[4];
FLOD.read((char*)temp,4);
totalFiles = readNormalNr(temp,4);
FLOD.seekg(0x5c,std::ios_base::beg);
entries.reserve(totalFiles);
//std::cout<<"*** Loading FAT ...\n";
for (int i=0; i<totalFiles; i++)
{
entries.push_back(Entry());
//FLOD.read((char*)entries[i].name,12);
char * bufc = new char;
bool appending = true;
for(int kk=0; kk<12; ++kk)
{
FLOD.read(bufc, 1);
if(appending)
{
entries[i].name[kk] = *bufc;
}
else
{
entries[i].name[kk] = 0;
appending = false;
}
}
delete bufc;
FLOD.read((char*)entries[i].hlam_1,4);
FLOD.read((char*)temp,4);
entries[i].offset=readNormalNr(temp,4);
FLOD.read((char*)temp,4);
entries[i].realSize=readNormalNr(temp,4);
FLOD.read((char*)entries[i].hlam_2,4);
FLOD.read((char*)temp,4);
entries[i].size=readNormalNr(temp,4);
}
//std::string Ts;
////std::cout<<"*** Loading FAT ... \n";
//FLOD.open(lodName.c_str(),std::ios::binary);
////std::cout<<"*** Archive: "+FName+" loaded\n";
//FLOD.seekg(8,std::ios_base::beg);
//unsigned char temp[4];
//FLOD.read((char*)temp,4);
//totalFiles = readNormalNr(temp,4);
//FLOD.seekg(0x5c,std::ios_base::beg);
//entries.reserve(totalFiles);
////std::cout<<"*** Loading FAT ...\n";
//for (int i=0; i<totalFiles; i++)
//{
// entries.push_back(Entry());
// //FLOD.read((char*)entries[i].name,12);
// char * bufc = new char;
// bool appending = true;
// for(int kk=0; kk<12; ++kk)
// {
// FLOD.read(bufc, 1);
// if(appending)
// {
// entries[i].name[kk] = *bufc;
// }
// else
// {
// entries[i].name[kk] = 0;
// appending = false;
// }
// }
// delete bufc;
// FLOD.read((char*)entries[i].hlam_1,4);
// FLOD.read((char*)temp,4);
// entries[i].offset=readNormalNr(temp,4);
// FLOD.read((char*)temp,4);
// entries[i].realSize=readNormalNr(temp,4);
// FLOD.read((char*)entries[i].hlam_2,4);
// FLOD.read((char*)temp,4);
// entries[i].size=readNormalNr(temp,4);
//}
//std::cout<<" done\n";
//std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper);
std::vector<char> found(defNamesIn.size(), 0);
for (int i=0;i<totalFiles;i++)
{
std::cout<<'\r'<<"Reading defs: "<<(100.0*i)/((float)(totalFiles))<<"% ";
std::string buf1 = std::string((char*)entries[i].name);
std::transform(buf1.begin(), buf1.end(), buf1.begin(), (int(*)(int))toupper);
bool exists = false;
@@ -397,7 +398,20 @@ std::vector<CDefHandler *> CLodHandler::extractManyFiles(std::vector<std::string
//FOut.close();
//std::cout<<"*** done\n";
}
//TODO: przypisywanie defhandler�w powtarzaj�cym si� defom
std::cout<<'\r'<<"Reading defs: 100% "<<std::endl;
for(int hh=0; hh<found.size(); ++hh)
{
if(!found[hh])
{
for(int ff=0; ff<hh; ++ff)
{
if(defNamesIn[ff]==defNamesIn[hh])
{
ret[hh]=ret[ff];
}
}
}
}
FLOD.close();
//std::cout<<"*** Archive: "+FName+" closed\n";
return ret;
@@ -564,50 +578,10 @@ int CLodHandler::infs2(unsigned char * in, int size, int realSize, unsigned char
void CLodHandler::extract(std::string FName)
{
std::ifstream FLOD;
std::ofstream FOut;
int i;
std::string Ts;
//std::cout<<"*** Loading FAT ... \n";
FLOD.open(FName.c_str(),std::ios::binary);
//std::cout<<"*** Archive: "+FName+" loaded\n";
FLOD.seekg(8,std::ios_base::beg);
unsigned char temp[4];
FLOD.read((char*)temp,4);
totalFiles = readNormalNr(temp,4);
FLOD.seekg(0x5c,std::ios_base::beg);
entries.reserve(totalFiles);
//std::cout<<"*** Loading FAT ...\n";
for (int i=0; i<totalFiles; i++)
{
entries.push_back(Entry());
//FLOD.read((char*)entries[i].name,12);
char * bufc = new char;
bool appending = true;
for(int kk=0; kk<12; ++kk)
{
FLOD.read(bufc, 1);
if(appending)
{
entries[i].name[kk] = *bufc;
}
else
{
entries[i].name[kk] = 0;
appending = false;
}
}
delete bufc;
FLOD.read((char*)entries[i].hlam_1,4);
FLOD.read((char*)temp,4);
entries[i].offset=readNormalNr(temp,4);
FLOD.read((char*)temp,4);
entries[i].realSize=readNormalNr(temp,4);
FLOD.read((char*)entries[i].hlam_2,4);
FLOD.read((char*)temp,4);
entries[i].size=readNormalNr(temp,4);
}
//std::cout<<" done\n";
for (int i=0;i<totalFiles;i++)
{
@@ -661,50 +635,50 @@ void CLodHandler::extract(std::string FName)
void CLodHandler::extractFile(std::string FName, std::string name)
{
std::ifstream FLOD;
//std::ifstream FLOD;
std::ofstream FOut;
int i;
std::string Ts;
//std::cout<<"*** Loading FAT ... \n";
FLOD.open(FName.c_str(),std::ios::binary);
//std::cout<<"*** Archive: "+FName+" loaded\n";
FLOD.seekg(8,std::ios_base::beg);
unsigned char temp[4];
FLOD.read((char*)temp,4);
totalFiles = readNormalNr(temp,4);
FLOD.seekg(0x5c,std::ios_base::beg);
entries.reserve(totalFiles);
//std::cout<<"*** Loading FAT ...\n";
for (int i=0; i<totalFiles; i++)
{
entries.push_back(Entry());
//FLOD.read((char*)entries[i].name,12);
char * bufc = new char;
bool appending = true;
for(int kk=0; kk<12; ++kk)
{
FLOD.read(bufc, 1);
if(appending)
{
entries[i].name[kk] = *bufc;
}
else
{
entries[i].name[kk] = 0;
appending = false;
}
}
delete bufc;
FLOD.read((char*)entries[i].hlam_1,4);
FLOD.read((char*)temp,4);
entries[i].offset=readNormalNr(temp,4);
FLOD.read((char*)temp,4);
entries[i].realSize=readNormalNr(temp,4);
FLOD.read((char*)entries[i].hlam_2,4);
FLOD.read((char*)temp,4);
entries[i].size=readNormalNr(temp,4);
}
//std::string Ts;
////std::cout<<"*** Loading FAT ... \n";
//FLOD.open(FName.c_str(),std::ios::binary);
////std::cout<<"*** Archive: "+FName+" loaded\n";
//FLOD.seekg(8,std::ios_base::beg);
//unsigned char temp[4];
//FLOD.read((char*)temp,4);
//totalFiles = readNormalNr(temp,4);
//FLOD.seekg(0x5c,std::ios_base::beg);
//entries.reserve(totalFiles);
////std::cout<<"*** Loading FAT ...\n";
//for (int i=0; i<totalFiles; i++)
//{
// entries.push_back(Entry());
// //FLOD.read((char*)entries[i].name,12);
// char * bufc = new char;
// bool appending = true;
// for(int kk=0; kk<12; ++kk)
// {
// FLOD.read(bufc, 1);
// if(appending)
// {
// entries[i].name[kk] = *bufc;
// }
// else
// {
// entries[i].name[kk] = 0;
// appending = false;
// }
// }
// delete bufc;
// FLOD.read((char*)entries[i].hlam_1,4);
// FLOD.read((char*)temp,4);
// entries[i].offset=readNormalNr(temp,4);
// FLOD.read((char*)temp,4);
// entries[i].realSize=readNormalNr(temp,4);
// FLOD.read((char*)entries[i].hlam_2,4);
// FLOD.read((char*)temp,4);
// entries[i].size=readNormalNr(temp,4);
//}
//std::cout<<" done\n";
std::transform(name.begin(), name.end(), name.begin(), (int(*)(int))toupper);
for (int i=0;i<totalFiles;i++)
@@ -779,5 +753,45 @@ int CLodHandler::readNormalNr (unsigned char* bufor, int bytCon, bool cyclic)
void CLodHandler::init(std::string lodFile)
{
extract(lodFile);
FLOD;
std::string Ts;
//std::cout<<"*** Loading FAT ... \n";
FLOD.open(lodFile.c_str(),std::ios::binary);
//std::cout<<"*** Archive: "+FName+" loaded\n";
FLOD.seekg(8,std::ios_base::beg);
unsigned char temp[4];
FLOD.read((char*)temp,4);
totalFiles = readNormalNr(temp,4);
FLOD.seekg(0x5c,std::ios_base::beg);
entries.reserve(totalFiles);
//std::cout<<"*** Loading FAT ...\n";
for (int i=0; i<totalFiles; i++)
{
entries.push_back(Entry());
//FLOD.read((char*)entries[i].name,12);
char * bufc = new char;
bool appending = true;
for(int kk=0; kk<12; ++kk)
{
FLOD.read(bufc, 1);
if(appending)
{
entries[i].name[kk] = *bufc;
}
else
{
entries[i].name[kk] = 0;
appending = false;
}
}
delete bufc;
FLOD.read((char*)entries[i].hlam_1,4);
FLOD.read((char*)temp,4);
entries[i].offset=readNormalNr(temp,4);
FLOD.read((char*)temp,4);
entries[i].realSize=readNormalNr(temp,4);
FLOD.read((char*)entries[i].hlam_2,4);
FLOD.read((char*)temp,4);
entries[i].size=readNormalNr(temp,4);
}
}

View File

@@ -48,6 +48,8 @@ public:
};
class CLodHandler
{
private:
std::ifstream FLOD;
public:
std::vector<Entry> entries;
unsigned int totalFiles;
@@ -58,9 +60,9 @@ public:
int infm(FILE *source, FILE *dest, int wBits = 15); //zlib handler
int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler
int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
std::vector<CDefHandler *> extractManyFiles(std::vector<std::string> defNamesIn, std::string lodName); //extrats given files
std::vector<CDefHandler *> extractManyFiles(std::vector<std::string> defNamesIn, std::string lodName); //extrats given files (defs only)
void extract(std::string FName);
void extractFile(std::string FName, std::string name);
void extractFile(std::string FName, std::string name); //extracts a specific file
void init(std::string lodFile);
};

187
CMT.cpp
View File

@@ -29,6 +29,11 @@
#include "CDefHandler.h"
#include "CSndHandler.h"
#include "CDefObjInfoHandler.h"
#include "CAmbarCendamo.h"
#include "mapHandler.h"
#include "global.h"
#include "CPreGame.h"
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
# include <io.h>
@@ -36,13 +41,10 @@
#else
# define SET_BINARY_MODE(file)
#endif
#define CHUNK 16384
#define pi 3.14159
const char * NAME = "VCMI 0.2";
#include "CAmbarCendamo.h"
#include "mapHandler.h"
#include "global.h"
#include "CPreGame.h"
/* Compress from file source to file dest until EOF on source.
def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_STREAM_ERROR if an invalid compression
@@ -107,63 +109,63 @@ int def(FILE *source, FILE *dest, int level, int winBits=15, int memLevel =8)
invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
the version of the library linked do not match, or Z_ERRNO if there
is an error reading or writing the files. */
int inf(FILE *source, FILE *dest, int wBits = 15)
{
int ret;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
/* allocate inflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
ret = inflateInit2(&strm, wBits);
if (ret != Z_OK)
return ret;
/* decompress until deflate stream ends or end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
if (strm.avail_in == 0)
break;
strm.next_in = in;
/* run inflate() on input until output buffer not full */
do {
strm.avail_out = CHUNK;
strm.next_out = out;
ret = inflate(&strm, Z_NO_FLUSH);
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
switch (ret) {
case Z_NEED_DICT:
ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR:
case Z_MEM_ERROR:
(void)inflateEnd(&strm);
return ret;
}
have = CHUNK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
/* done when inflate() says it's done */
} while (ret != Z_STREAM_END);
/* clean up and return */
(void)inflateEnd(&strm);
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}
//int inf(FILE *source, FILE *dest, int wBits = 15)
//{
// int ret;
// unsigned have;
// z_stream strm;
// unsigned char in[CHUNK];
// unsigned char out[CHUNK];
//
// /* allocate inflate state */
// strm.zalloc = Z_NULL;
// strm.zfree = Z_NULL;
// strm.opaque = Z_NULL;
// strm.avail_in = 0;
// strm.next_in = Z_NULL;
// ret = inflateInit2(&strm, wBits);
// if (ret != Z_OK)
// return ret;
//
// /* decompress until deflate stream ends or end of file */
// do {
// strm.avail_in = fread(in, 1, CHUNK, source);
// if (ferror(source)) {
// (void)inflateEnd(&strm);
// return Z_ERRNO;
// }
// if (strm.avail_in == 0)
// break;
// strm.next_in = in;
//
// /* run inflate() on input until output buffer not full */
// do {
// strm.avail_out = CHUNK;
// strm.next_out = out;
// ret = inflate(&strm, Z_NO_FLUSH);
// assert(ret != Z_STREAM_ERROR); /* state not clobbered */
// switch (ret) {
// case Z_NEED_DICT:
// ret = Z_DATA_ERROR; /* and fall through */
// case Z_DATA_ERROR:
// case Z_MEM_ERROR:
// (void)inflateEnd(&strm);
// return ret;
// }
// have = CHUNK - strm.avail_out;
// if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
// (void)inflateEnd(&strm);
// return Z_ERRNO;
// }
// } while (strm.avail_out == 0);
//
// /* done when inflate() says it's done */
// } while (ret != Z_STREAM_END);
//
// /* clean up and return */
// (void)inflateEnd(&strm);
// return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
//}
/* report a zlib or i/o error */
void zerr(int ret)
@@ -190,25 +192,6 @@ void zerr(int ret)
}
}
/*void SDL_PutPixel(SDL_Surface *ekran, int x, int y, Uint8 R, Uint8 G, Uint8 B)
{
Uint8 *p = (Uint8 *)ekran->pixels + y * ekran->pitch + x * ekran->format->BytesPerPixel;
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
{
p[0] = R;
p[1] = G;
p[2] = B;
}
else
{
p[0] = B;
p[1] = G;
p[2] = R;
}
SDL_UpdateRect(ekran, x, y, 1, 1);
}*/
int _tmain(int argc, _TCHAR* argv[])
{
THC timeHandler tmh;
@@ -323,7 +306,10 @@ int _tmain(int argc, _TCHAR* argv[])
cgi->objh = objh;
cgi->dobjinfo = new CDefObjInfoHandler;
cgi->dobjinfo->load();
cgi->lodh = new CLodHandler;
cgi->spriteh = new CLodHandler;
cgi->spriteh->init(std::string("newH3sprite.lod"));
cgi->bitmaph = new CLodHandler;
cgi->bitmaph->init(std::string("newH3bitmap.lod"));
THC std::cout<<"Inicjalizacja wszelakich handlerow: "<<tmh.getDif()<<std::endl;
std::string mapname;
@@ -435,6 +421,41 @@ int _tmain(int argc, _TCHAR* argv[])
}
}
}//keyup end
else if(sEvent.type==SDL_MOUSEMOTION)
{
if(sEvent.motion.x<5)
{
scrollingLeft = true;
}
else
{
scrollingLeft = false;
}
if(sEvent.motion.x>screen->w-5)
{
scrollingRight = true;
}
else
{
scrollingRight = false;
}
if(sEvent.motion.y<5)
{
scrollingUp = true;
}
else
{
scrollingUp = false;
}
if(sEvent.motion.y>screen->h-5)
{
scrollingDown = true;
}
else
{
scrollingDown = false;
}
}
} //event end
/////////////// scrolling terrain
@@ -464,7 +485,7 @@ int _tmain(int argc, _TCHAR* argv[])
}
if(scrollingDown)
{
if(yy<ac->map.height-18+8)
if(yy<ac->map.height-19+8)
{
yy++;
updateScreen = true;

View File

@@ -10,7 +10,7 @@ extern SDL_Surface * ekran;
extern TTF_Font * TNRB16, *TNR, *GEOR13;
SDL_Color genRGB(int r, int g, int b, int a=0);
void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=ekran);
void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran);
//void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2);
extern CPreGame * CPG;
void updateRect (SDL_Rect * rect, SDL_Surface * scr = ekran);
bool isItIn(const SDL_Rect * rect, int x, int y);

Binary file not shown.

View File

@@ -8,6 +8,7 @@
struct Cimage
{
int groupNumber;
std::string imName; //name without extension
SDL_Surface * bitmap;
};

View File

@@ -1,3 +1,6 @@
#ifndef CSNDHANDLER_H
#define CSNDHANDLER_H
#include <vector>
#include <fstream>
class CSndHandler
@@ -21,3 +24,5 @@ public:
void extract(int index, std::string dstfile); //saves selected file
unsigned char * extract (int index, int & size); //return selecte file - NIE TESTOWANE
};
#endif //CSNDHANDLER_H

View File

@@ -3,8 +3,6 @@
#include "SDL_TTF.h"
#include <iostream>
extern SDL_Surface * ekran;
extern SDL_Color tytulowy, tlo, zwykly ;
bool isItIn(const SDL_Rect * rect, int x, int y)
{
if ((x>rect->x && x<rect->x+rect->w) && (y>rect->y && y<rect->y+rect->h))
@@ -37,7 +35,7 @@ void updateRect (SDL_Rect * rect, SDL_Surface * scr = ekran)
{
SDL_UpdateRect(scr,rect->x,rect->y,rect->w,rect->h);
}
void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran)
void CSDL_Ext::printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor, SDL_Surface * dst, unsigned char quality)
{
SDL_Surface * temp = TTF_RenderText_Blended(font,text.c_str(),kolor);
SDL_BlitSurface(temp,NULL,dst,&genRect(temp->h,temp->w,x,y));

View File

@@ -1,7 +1,11 @@
#ifndef SDL_EXTENSIONS_H
#define SDL_EXTENSIONS_H
#include "SDL.h"
#include "SDL_ttf.h"
extern SDL_Surface * ekran;
extern SDL_Color tytulowy, tlo, zwykly ;
class CSDL_Ext
{
public:
@@ -16,6 +20,7 @@ public:
static SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details)
static SDL_Surface * secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha); //alpha is a surface we want to blit src to
static Uint32 colorToUint32(const SDL_Color * color); //little endian only
static void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest
};
#endif // SDL_EXTENSIONS_H

View File

@@ -79,48 +79,48 @@ void CMapHandler::init()
for (int ii=0;ii<reader->map.width+2*Woff;ii++)
terrainBitmap[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory
CSemiDefHandler * bord = CGameInfo::mainObj->sspriteh->giveDef("EDG.DEF");
for (int i=0; i<reader->map.width+8; i++) //jest po szeroko�ci
for (int i=0; i<reader->map.width+2*Woff; i++) //jest po szeroko�ci
{
for (int j=0; j<reader->map.height+8;j++) //po wysoko�ci
for (int j=0; j<reader->map.height+2*Hoff;j++) //po wysoko�ci
{
if(i < 4 || i > (reader->map.width+3) || j < 4 || j > (reader->map.height+3))
if(i < Woff || i > (reader->map.width+Woff-1) || j < Hoff || j > (reader->map.height+Hoff-1))
{
if(i==3 && j==3)
if(i==Woff-1 && j==Hoff-1)
{
terrainBitmap[i][j] = bord->ourImages[16].bitmap;
continue;
}
else if(i==3 && j==(reader->map.height+4))
else if(i==Woff-1 && j==(reader->map.height+Hoff))
{
terrainBitmap[i][j] = bord->ourImages[19].bitmap;
continue;
}
else if(i==(reader->map.width+4) && j==3)
else if(i==(reader->map.width+Woff) && j==Hoff-1)
{
terrainBitmap[i][j] = bord->ourImages[17].bitmap;
continue;
}
else if(i==(reader->map.width+4) && j==(reader->map.height+4))
else if(i==(reader->map.width+Woff) && j==(reader->map.height+Hoff))
{
terrainBitmap[i][j] = bord->ourImages[18].bitmap;
continue;
}
else if(j == 3 && i > 3 && i < reader->map.height+4)
else if(j == Hoff-1 && i > Woff-1 && i < reader->map.height+Woff)
{
terrainBitmap[i][j] = bord->ourImages[22+rand()%2].bitmap;
continue;
}
else if(i == 3 && j > 3 && j < reader->map.height+4)
else if(i == Woff-1 && j > Hoff-1 && j < reader->map.height+Hoff)
{
terrainBitmap[i][j] = bord->ourImages[33+rand()%2].bitmap;
continue;
}
else if(j == reader->map.height+4 && i > 3 && i < reader->map.width+4)
else if(j == reader->map.height+Hoff && i > Woff-1 && i < reader->map.width+Woff)
{
terrainBitmap[i][j] = bord->ourImages[29+rand()%2].bitmap;
continue;
}
else if(i == reader->map.width+4 && j > 3 && j < reader->map.height+4)
else if(i == reader->map.width+Woff && j > Hoff-1 && j < reader->map.height+Hoff)
{
terrainBitmap[i][j] = bord->ourImages[25+rand()%2].bitmap;
continue;
@@ -131,8 +131,8 @@ void CMapHandler::init()
continue;
}
}
TerrainTile zz = reader->map.terrain[i-4][j-4];
std::string name = CSemiDefHandler::nameFromType(reader->map.terrain[i-4][j-4].tertype);
TerrainTile zz = reader->map.terrain[i-Woff][j-Hoff];
std::string name = CSemiDefHandler::nameFromType(reader->map.terrain[i-Woff][j-Hoff].tertype);
for (unsigned int k=0; k<reader->defs.size(); k++)
{
try
@@ -141,10 +141,10 @@ void CMapHandler::init()
continue;
else
{
int ktora = reader->map.terrain[i-4][j-4].terview;
int ktora = reader->map.terrain[i-Woff][j-Hoff].terview;
terrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
//TODO: odwracanie
switch ((reader->map.terrain[i-4][j-4].siodmyTajemniczyBajt)%4)
switch ((reader->map.terrain[i-Woff][j-Hoff].siodmyTajemniczyBajt)%4)
{
case 1:
{
@@ -177,48 +177,48 @@ void CMapHandler::init()
undTerrainBitmap = new SDL_Surface **[reader->map.width+8];
for (int ii=0;ii<reader->map.width+8;ii++)
undTerrainBitmap[ii] = new SDL_Surface*[reader->map.height+8]; // allocate memory
for (int i=0; i<reader->map.width+8; i++)
for (int i=0; i<reader->map.width+2*Woff; i++)
{
for (int j=0; j<reader->map.height+8;j++)
for (int j=0; j<reader->map.height+2*Hoff;j++)
{
if(i < 4 || i > (reader->map.width+3) || j < 4 || j > (reader->map.height+3))
if(i < Woff || i > (reader->map.width+Woff-1) || j < Hoff || j > (reader->map.height+Hoff-1))
{
if(i==3 && j==3)
if(i==Woff-1 && j==Hoff-1)
{
undTerrainBitmap[i][j] = bord->ourImages[16].bitmap;
continue;
}
else if(i==3 && j==(reader->map.height+4))
else if(i==Woff-1 && j==(reader->map.height+Hoff))
{
undTerrainBitmap[i][j] = bord->ourImages[19].bitmap;
continue;
}
else if(i==(reader->map.width+4) && j==3)
else if(i==(reader->map.width+Woff) && j==Hoff-1)
{
undTerrainBitmap[i][j] = bord->ourImages[17].bitmap;
continue;
}
else if(i==(reader->map.width+4) && j==(reader->map.height+4))
else if(i==(reader->map.width+Woff) && j==(reader->map.height+Hoff))
{
undTerrainBitmap[i][j] = bord->ourImages[18].bitmap;
continue;
}
else if(j == 3 && i > 3 && i < reader->map.height+4)
else if(j == Hoff-1 && i > Woff-1 && i < reader->map.width+Woff)
{
undTerrainBitmap[i][j] = bord->ourImages[22+rand()%2].bitmap;
continue;
}
else if(i == 3 && j > 3 && j < reader->map.height+4)
else if(i == Woff-1 && j > Hoff-1 && j < reader->map.height+Hoff)
{
undTerrainBitmap[i][j] = bord->ourImages[33+rand()%2].bitmap;
continue;
}
else if(j == reader->map.height+4 && i > 3 && i < reader->map.width+4)
else if(j == reader->map.height+Hoff && i > Woff-1 && i < reader->map.width+Woff)
{
undTerrainBitmap[i][j] = bord->ourImages[29+rand()%2].bitmap;
continue;
}
else if(i == reader->map.width+4 && j > 3 && j < reader->map.height+4)
else if(i == reader->map.width+Woff && j > Hoff-1 && j < reader->map.height+Hoff)
{
undTerrainBitmap[i][j] = bord->ourImages[25+rand()%2].bitmap;
continue;
@@ -229,8 +229,8 @@ void CMapHandler::init()
continue;
}
}
TerrainTile zz = reader->map.undergroungTerrain[i-4][j-4];
std::string name = CSemiDefHandler::nameFromType(reader->map.undergroungTerrain[i-4][j-4].tertype);
TerrainTile zz = reader->map.undergroungTerrain[i-Woff][j-Hoff];
std::string name = CSemiDefHandler::nameFromType(reader->map.undergroungTerrain[i-Woff][j-Hoff].tertype);
for (unsigned int k=0; k<reader->defs.size(); k++)
{
try
@@ -239,10 +239,10 @@ void CMapHandler::init()
continue;
else
{
int ktora = reader->map.undergroungTerrain[i-4][j-4].terview;
int ktora = reader->map.undergroungTerrain[i-Woff][j-Hoff].terview;
undTerrainBitmap[i][j] = reader->defs[k]->ourImages[ktora].bitmap;
//TODO: odwracanie
switch ((reader->map.undergroungTerrain[i-4][j-4].siodmyTajemniczyBajt)%4)
switch ((reader->map.undergroungTerrain[i-Woff][j-Hoff].siodmyTajemniczyBajt)%4)
{
case 1:
{
@@ -323,8 +323,8 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
{
ObjSorter os;
os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap;
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+4)*32;
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+4)*32;
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+Woff)*32;
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+Hoff)*32;
highPrObjsVis.push_back(os);
}
else if(CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].printPriority==0)
@@ -336,8 +336,8 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
os.bitmap = CGameInfo::mainObj->ac->map.defy[defyod].handler->ourImages[ourimagesod].bitmap;
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+4)*32;
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+4)*32;
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+Woff)*32;
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+Hoff)*32;
if (CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].isVisitable())
highPrObjsVis.push_back(os);
else
@@ -347,8 +347,8 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
{
ObjSorter os;
os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap;
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+4)*32;
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+4)*32;
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+Woff)*32;
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+Hoff)*32;
lowPrObjs.push_back(os);
}
}
@@ -414,7 +414,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
if (!level)
{
if( bx+x>3 && by+y>3 && bx+x<visibility.size()-3 && by+y<visibility[0].size()-3 && !visibility[bx+x][by+y])
if( bx+x>Woff-1 && by+y>Hoff-1 && bx+x<visibility.size()-(Woff-1) && by+y<visibility[0].size()-(Hoff-1) && !visibility[bx+x][by+y])
{
SDL_Surface * hide = getVisBitmap(bx+x, by+y, visibility);
SDL_Surface * hide2 = CSDL_Ext::secondAlphaTransform(hide, su);
@@ -424,7 +424,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
}
else
{
if( bx+x>3 && by+y>3 && bx+x<undVisibility.size()-3 && by+y<undVisibility[0].size()-3 && !undVisibility[bx+x][by+y])
if( bx+x>Woff-1 && by+y>Hoff-1 && bx+x<undVisibility.size()-(Woff-1) && by+y<undVisibility[0].size()-(Hoff-1) && !undVisibility[bx+x][by+y])
{
SDL_Surface * hide = getVisBitmap(bx+x, by+y, undVisibility);
SDL_Surface * hide2 = CSDL_Ext::secondAlphaTransform(hide, su);
@@ -436,6 +436,30 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
}
}
////shadow printed
//printing borders
for (int bx=0; bx<dx; bx++)
{
for (int by=0; by<dy; by++)
{
if(bx+x<Woff || by+y<Hoff || bx+x>reader->map.width+(Woff-1) || by+y>reader->map.height+(Hoff-1))
{
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;
}
}
}
//borders printed
return su;
}
@@ -650,10 +674,10 @@ SDL_Surface * CMapHandler::getVisBitmap(int x, int y, std::vector< std::vector<c
char & CMapHandler::visAccess(int x, int y)
{
return visibility[x+4][y+4];
return visibility[x+Woff][y+Hoff];
}
char & CMapHandler::undVisAccess(int x, int y)
{
return undVisibility[x+4][y+4];
return undVisibility[x+Woff][y+Hoff];
}