diff --git a/CGameInfo.h b/CGameInfo.h index 1eaa93a37..7462f71c8 100644 --- a/CGameInfo.h +++ b/CGameInfo.h @@ -14,6 +14,8 @@ #include "CDefObjInfoHandler.h" #include "CLodHandler.h" #include "CGeneralTextHandler.h" +#include "SDL.h" +#include /* CGameInfo class @@ -37,6 +39,8 @@ public: CLodHandler * spriteh; CLodHandler * bitmaph; CGeneralTextHandler * generaltexth; + std::vector playerColors; + SDL_Color neutralColor; }; #endif //CGAMEINFO_H \ No newline at end of file diff --git a/CMT.cpp b/CMT.cpp index 4b9863ca6..b5bf44f8c 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -230,22 +230,7 @@ int _tmain(int argc, _TCHAR* argv[]) screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); ekran = screen; - //FILE * zr = fopen("mal.txt","r"); - //FILE * ko = fopen("wyn.txt","w"); - //FILE * kodd = fopen("kod.txt","r"); - //FILE * deko = fopen("dekod.txt","w"); - //def(zr,ko,1); - //inf(kodd, deko); - //fclose(ko);fclose(zr); - //for (int i=0;i<=20;i++) - //{ - // zr = fopen("kod2.txt","r"); - // char c [200]; - // sprintf(c,"wyn%d.txt",i); - // ko = fopen(c,"w"); - // def(zr,ko,i); - // fclose(ko);fclose(zr); - //} + SDL_WM_SetCaption(NAME,""); //set window title CGameInfo * cgi = new CGameInfo; //contains all global informations about game (texts, lodHandlers, map handler itp.) CGameInfo::mainObj = cgi; @@ -255,6 +240,30 @@ int _tmain(int argc, _TCHAR* argv[]) cgi->spriteh->init(std::string("newH3sprite.lod")); cgi->bitmaph = new CLodHandler; cgi->bitmaph->init(std::string("newH3bitmap.lod")); + + //colors initialization + SDL_Color p; + p.unused = 0; + p.r = 0xff; p.g = 0x0; p.b = 0x0; //red + cgi->playerColors.push_back(p); //red + p.r = 0x31; p.g = 0x52; p.b = 0xff; //blue + cgi->playerColors.push_back(p); //blue + p.r = 0x9c; p.g = 0x73; p.b = 0x52;//tan + cgi->playerColors.push_back(p);//tan + p.r = 0x42; p.g = 0x94; p.b = 0x29; //green + cgi->playerColors.push_back(p); //green + p.r = 0xff; p.g = 0x84; p.b = 0x0; //orange + cgi->playerColors.push_back(p); //orange + p.r = 0x8c; p.g = 0x29; p.b = 0xa5; //purple + cgi->playerColors.push_back(p); //purple + p.r = 0x09; p.g = 0x9c; p.b = 0xa5;//teal + cgi->playerColors.push_back(p);//teal + p.r = 0xc6; p.g = 0x7b; p.b = 0x8c;//pink + cgi->playerColors.push_back(p);//pink + p.r = 0x84; p.g = 0x84; p.b = 0x84;//gray + cgi->neutralColor = p;//gray + //colors initialized + THC std::cout<<"Loading .lods: "< +#include +#include bool isItIn(const SDL_Rect * rect, int x, int y) { @@ -438,3 +441,86 @@ void CSDL_Ext::update(SDL_Surface * what) { SDL_UpdateRect(what, 0, 0, what->w, what->h); } + +void CSDL_Ext::blueToPlayers(SDL_Surface * sur, int player) +{ + if(sur->format->BitsPerPixel == 8) + { + for(int i=0; iformat->palette->ncolors; ++i) + { + SDL_Color * cc = sur->format->palette->colors+i; + if(cc->r==0 && cc->g==0 && cc->b==255) + { + cc->r = CGameInfo::mainObj->playerColors[player].r; + cc->g = CGameInfo::mainObj->playerColors[player].g; + cc->b = CGameInfo::mainObj->playerColors[player].b; + } + } + } + else if(sur->format->BitsPerPixel == 24) + { + for(int y=0; yh; ++y) + { + for(int x=0; xw; ++x) + { + Uint8* cp = (Uint8*)sur->pixels + y+sur->pitch + x*3; + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + { + if(cp[0]==0 && cp[1]==0 && cp[2]==255) + { + cp[0] = CGameInfo::mainObj->playerColors[player].r; + cp[1] = CGameInfo::mainObj->playerColors[player].g; + cp[2] = CGameInfo::mainObj->playerColors[player].b; + } + } + else + { + + if(cp[0]==255 && cp[1]==0 && cp[2]==0) + { + cp[0] = CGameInfo::mainObj->playerColors[player].b; + cp[1] = CGameInfo::mainObj->playerColors[player].g; + cp[2] = CGameInfo::mainObj->playerColors[player].r; + } + } + } + } + } +} + +void CSDL_Ext::blueToPlayersAdv(SDL_Surface * sur, int player) +{ + if(sur->format->BitsPerPixel == 8) + { + for(int i=0; iformat->palette->ncolors; ++i) + { + SDL_Color * cc = sur->format->palette->colors+i; + if(cc->b>cc->g && cc->b>cc->r) + { + std::vector sort1; + sort1.push_back(cc->r); + sort1.push_back(cc->g); + sort1.push_back(cc->b); + std::vector< std::pair > sort2; + sort2.push_back(std::make_pair(CGameInfo::mainObj->playerColors[player].r, &(cc->r))); + sort2.push_back(std::make_pair(CGameInfo::mainObj->playerColors[player].g, &(cc->g))); + sort2.push_back(std::make_pair(CGameInfo::mainObj->playerColors[player].b, &(cc->b))); + std::sort(sort1.begin(), sort1.end()); + if(sort2[0].first>sort2[1].first) + std::swap(sort2[0], sort2[1]); + if(sort2[1].first>sort2[2].first) + std::swap(sort2[1], sort2[2]); + if(sort2[0].first>sort2[1].first) + std::swap(sort2[0], sort2[1]); + for(int hh=0; hh<3; ++hh) + { + (*sort2[hh].second) = (sort1[hh] + sort2[hh].first)/2; + } + } + } + } + else if(sur->format->BitsPerPixel == 24) + { + } +} + diff --git a/SDL_Extensions.h b/SDL_Extensions.h index b9ed56093..08ab53160 100644 --- a/SDL_Extensions.h +++ b/SDL_Extensions.h @@ -22,6 +22,8 @@ namespace CSDL_Ext void printAtMiddle(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 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 void update(SDL_Surface * what = ekran); //updates whole surface (default - main screen) + void blueToPlayers(SDL_Surface * sur, int player); //simple color substitution + void blueToPlayersAdv(SDL_Surface * sur, int player); //substitute blue color by another one, makes it nicer keeping nuances }; #endif // SDL_EXTENSIONS_H \ No newline at end of file