diff --git a/CAmbarCendamo.cpp b/CAmbarCendamo.cpp index d271bf155..f4d54ed98 100644 --- a/CAmbarCendamo.cpp +++ b/CAmbarCendamo.cpp @@ -408,7 +408,6 @@ void CAmbarCendamo::deh3m() std::vector defsToUnpack; for (int idd = 0 ; idd dhandlers = CGameInfo::mainObj->lodh->extractManyFiles(defsToUnpack, std::string("newh3sprite.lod")); + std::vector dhandlers = CGameInfo::mainObj->spriteh->extractManyFiles(defsToUnpack, std::string("newh3sprite.lod")); for (int i=0;iourImages.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: "< CLodHandler::extractManyFiles(std::vector found(defNamesIn.size(), 0); for (int i=0;i CLodHandler::extractManyFiles(std::vector 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 extractManyFiles(std::vector defNamesIn, std::string lodName); //extrats given files + std::vector extractManyFiles(std::vector 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); }; diff --git a/CMT.cpp b/CMT.cpp index a03e48322..22244b5bd 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -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 # include @@ -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: "<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(yymap.height-18+8) + if(yymap.height-19+8) { yy++; updateScreen = true; @@ -493,7 +514,7 @@ int _tmain(int argc, _TCHAR* argv[]) } else { - printf("Coś poszło nie tak: %s/n",SDL_GetError()); + printf("Coś poszło nie tak: %s/n", SDL_GetError()); return -1; } } diff --git a/CMessage.cpp b/CMessage.cpp index c2e3179e0..effc28309 100644 --- a/CMessage.cpp +++ b/CMessage.cpp @@ -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); diff --git a/CPreGame.cpp b/CPreGame.cpp index cad7b7106..e2bc3913c 100644 Binary files a/CPreGame.cpp and b/CPreGame.cpp differ diff --git a/CSemiDefHandler.h b/CSemiDefHandler.h index 7b1eced21..db90b8596 100644 --- a/CSemiDefHandler.h +++ b/CSemiDefHandler.h @@ -8,6 +8,7 @@ struct Cimage { + int groupNumber; std::string imName; //name without extension SDL_Surface * bitmap; }; diff --git a/CSndHandler.h b/CSndHandler.h index d8b2ff7ca..f0994d870 100644 --- a/CSndHandler.h +++ b/CSndHandler.h @@ -1,3 +1,6 @@ +#ifndef CSNDHANDLER_H +#define CSNDHANDLER_H + #include #include 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 \ No newline at end of file diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index b9b2720b5..fb200b4e5 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -3,8 +3,6 @@ #include "SDL_TTF.h" #include -extern SDL_Surface * ekran; -extern SDL_Color tytulowy, tlo, zwykly ; bool isItIn(const SDL_Rect * rect, int x, int y) { if ((x>rect->x && xx+rect->w) && (y>rect->y && yy+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)); diff --git a/SDL_Extensions.h b/SDL_Extensions.h index 139fe30c8..d83bc83c8 100644 --- a/SDL_Extensions.h +++ b/SDL_Extensions.h @@ -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 \ No newline at end of file diff --git a/mapHandler.cpp b/mapHandler.cpp index f2965d948..391d622aa 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -79,48 +79,48 @@ void CMapHandler::init() for (int ii=0;iimap.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; imap.width+8; i++) //jest po szerokości + for (int i=0; imap.width+2*Woff; i++) //jest po szerokości { - for (int j=0; jmap.height+8;j++) //po wysokości + for (int j=0; jmap.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; kdefs.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;iimap.width+8;ii++) undTerrainBitmap[ii] = new SDL_Surface*[reader->map.height+8]; // allocate memory - for (int i=0; imap.width+8; i++) + for (int i=0; imap.width+2*Woff; i++) { - for (int j=0; jmap.height+8;j++) + for (int j=0; jmap.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; kdefs.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+xWoff-1 && by+y>Hoff-1 && bx+x3 && by+y>3 && bx+xWoff-1 && by+y>Hoff-1 && bx+xreader->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