From b8f65697ca5866588142e73c20dfdcdd687dcdd1 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 1 Jan 2011 20:26:39 +0000 Subject: [PATCH] - fixes for several bugs: #639 #656 #135 #646 #638 #94 #629 - re-enabled console on Linux to allow disabling AI --- CConsoleHandler.cpp | 2 - client/CAnimation.cpp | 18 ++++---- client/CAnimation.h | 31 +++++++------ client/CCastleInterface.cpp | 2 + client/CCreatureAnimation.cpp | 39 ++++------------ client/CKingdomInterface.cpp | 20 ++++----- client/CKingdomInterface.h | 4 +- client/CMessage.cpp | 84 ++++++++++++++++++++--------------- client/GUIClasses.cpp | 5 ++- config/AC_desc.txt | 2 +- config/buildings.txt | 4 +- hch/CVideoHandler.cpp | 7 +++ lib/map.h | 4 ++ server/CGameHandler.cpp | 16 +++++-- 14 files changed, 127 insertions(+), 111 deletions(-) diff --git a/CConsoleHandler.cpp b/CConsoleHandler.cpp index 2249364c8..0f238d8eb 100644 --- a/CConsoleHandler.cpp +++ b/CConsoleHandler.cpp @@ -232,7 +232,5 @@ void CConsoleHandler::end() void CConsoleHandler::start() { -#ifdef _WIN32 thread = new boost::thread(boost::bind(&CConsoleHandler::run,console)); -#endif } diff --git a/client/CAnimation.cpp b/client/CAnimation.cpp index 8620e7999..0274c084c 100644 --- a/client/CAnimation.cpp +++ b/client/CAnimation.cpp @@ -298,14 +298,16 @@ BMPPalette * CDefFile::getPalette() CDefFile::CDefFile(std::string Name):data(NULL),colors(NULL) { - static SDL_Color H3Palette[8] = {{ 0, 0, 0, 255}, - { 0, 0, 0, 192}, - /* 5 shadow colors */ { 0, 0, 0, 128}, - { 0, 0, 0, 64}, - { 0, 0, 0, 32}, - {255, 255, 0, 255}, - /* 3 selection highlight color */{255, 255, 0, 255}, - {255, 255, 0, 255}}; + //First 8 colors in def palette used for transparency + static SDL_Color H3Palette[8] = { + { 0, 0, 0, 255},// 100% - transparency + { 0, 0, 0, 192},// 75% - shadow border, + { 0, 0, 0, 128},// TODO: find exact value + { 0, 0, 0, 128},// TODO: for transparency + { 0, 0, 0, 128},// 50% - shadow body + { 0, 0, 0, 255},// 100% - selection highlight + { 0, 0, 0, 128},// 50% - shadow body below selection + { 0, 0, 0, 192}};// 75% - shadow border below selection data = spriteh->giveFile(Name, FILE_ANIMATION, &datasize); if (!data) diff --git a/client/CAnimation.h b/client/CAnimation.h index eb8f0b94e..529e7346c 100644 --- a/client/CAnimation.h +++ b/client/CAnimation.h @@ -42,17 +42,16 @@ private: ui32 TopMargin; }; - unsigned int type; - unsigned char * data; - int datasize; - BMPPalette * colors; - //offset[group][frame] - offset of frame data in file std::vector< std::vector > offset; //sorted list of offsets used to determine size std::set offList; + unsigned char * data; + BMPPalette * colors; + int datasize; + unsigned int type; public: CDefFile(std::string Name); @@ -88,33 +87,33 @@ private: //surface for this entry SDL_Surface * surf; - //bitfield, location of image data: 1 - def, 2 - file#9.*, 4 - file#9#2.* - unsigned char source; + //data for CompressedAnim + unsigned char * data; //reference count, changed by loadFrame \ unloadFrame size_t refCount; - //data for CompressedAnim - unsigned char * data; - //size of compressed data, unused for def files size_t dataSize; + //bitfield, location of image data: 1 - def, 2 - file#9.*, 4 - file#9#2.* + unsigned char source; + AnimEntry(); }; - //animation file name - std::string name; - - //if true all frames will be stored in compressed state - const bool compressed; - //palette from def file, used only for compressed anim BMPPalette * defPalette; //entries[group][position], store all info regarding frames std::vector< std::vector > entries; + //animation file name + std::string name; + + //if true all frames will be stored in compressed state + const bool compressed; + //loader, will be called by load(), require opened def file for loading from it. Returns true if image is loaded bool loadFrame(CDefFile * file, size_t frame, size_t group); diff --git a/client/CCastleInterface.cpp b/client/CCastleInterface.cpp index 54d5f15ea..ec636bfed 100644 --- a/client/CCastleInterface.cpp +++ b/client/CCastleInterface.cpp @@ -801,6 +801,8 @@ void CCastleInterface::townChange() { const CGTownInstance * nt = LOCPLINT->towns[townlist->selected]; int tpos = townlist->selected - townlist->from; + if ( nt == town ) + return; GH.popIntTotally(this); GH.pushInt(new CCastleInterface(nt, tpos)); } diff --git a/client/CCreatureAnimation.cpp b/client/CCreatureAnimation.cpp index 487535471..2d3f7ca0d 100644 --- a/client/CCreatureAnimation.cpp +++ b/client/CCreatureAnimation.cpp @@ -308,54 +308,33 @@ inline void CCreatureAnimation::putPixel( const unsigned char & animCount ) const { - if(palc!=0) + if(palc!=0) { Uint8 * p = (Uint8*)dest->pixels + ftcp*dest->format->BytesPerPixel; if(palc > 7) //normal color { ColorPutter::PutColor(p, color.R, color.G, color.B); } - else if((yellowBorder || blueBorder) && (palc == 6 || palc == 7)) //dark yellow border + else if((yellowBorder || blueBorder) && (palc == 6 || palc == 7)) //selection highlight { if(blueBorder) ColorPutter::PutColor(p, 0, 0x0f + animCount, 0x0f + animCount); else ColorPutter::PutColor(p, 0x0f + animCount, 0x0f + animCount, 0); } - else if((yellowBorder || blueBorder) && (palc == 5)) //yellow border + else if (palc == 5) //selection highlight or transparent { if(blueBorder) ColorPutter::PutColor(p, color.B, color.G - 0xf0 + animCount, color.R - 0xf0 + animCount); //shouldnt it be reversed? its bgr instead of rgb - else + else if (yellowBorder) ColorPutter::PutColor(p, color.R - 0xf0 + animCount, color.G - 0xf0 + animCount, color.B); } - else if(palc < 5) //shadow - { + else //shadow + { + //determining transparency value, 255 or 0 should be already filtered Uint16 alpha; - switch(color.G) - { - case 0: - alpha = 128; - break; - case 50: - alpha = 50+32; - break; - case 100: - alpha = 100+64; - break; - case 125: - alpha = 125+64; - break; - case 128: - alpha = 128+64; - break; - case 150: - alpha = 150+64; - break; - default: - alpha = 255; - break; - } + static Uint16 colToAlpha[8] = {255,192,128,128,128,255,128,192}; + alpha = colToAlpha[palc]; if(bpp != 3 && bpp != 4) { diff --git a/client/CKingdomInterface.cpp b/client/CKingdomInterface.cpp index cf73e64ad..11ddf8ce3 100644 --- a/client/CKingdomInterface.cpp +++ b/client/CKingdomInterface.cpp @@ -740,7 +740,7 @@ CKingdomInterface::CHeroItem::CHeroItem(int num, CKingdomInterface * Owner) secondarySkills[i]->pos = genRect(32, 32, pos.x+410+i*37, pos.y+5); secondarySkills[i]->baseType = 1; }; - +/* for (int i=0; i<18;i++) { artifacts.push_back(new CArtPlace(this)); @@ -753,7 +753,7 @@ CKingdomInterface::CHeroItem::CHeroItem(int num, CKingdomInterface * Owner) backpack.push_back(new CArtPlace(this)); backpack[i]->pos = genRect(44, 44, pos.x+293+(i%9)*48, pos.y+66); backpack[i]->baseType = SComponent::artifact; - }; + };*/ } @@ -911,21 +911,21 @@ void CKingdomInterface::CHeroItem::showAll(SDL_Surface * to) {//arts case 1:iter = 9;//misc. arts, spellbook, war machines case 0://equipped arts - for (int i = iter ; igetArtAtPos(i)->id; if (artID>=0) blitAt(graphics->artDefs->ourImages[artID].bitmap,pos.x+268+48*(i%9),pos.y+66,to); - } + }*/ break; case 2: artLeft->show(to); artRight->show(to); int max = hero->artifacts.size(); iter = std::min(8, max); - for (size_t it = 0 ; itartDefs->ourImages[hero->artifacts[(it+backpackPos)%max]->id].bitmap,pos.x+293+48*it,pos.y+66,to); - break; + */break; } show(to); } @@ -946,7 +946,7 @@ void CKingdomInterface::CHeroItem::activate() if (!hero) return; artButtons->activate(); - garr->activate(); + garr->activate();/* if ( artGroup == 2 ) { artLeft->activate(); @@ -958,7 +958,7 @@ void CKingdomInterface::CHeroItem::activate() { for (size_t i=artGroup*9; i<9+artGroup*9;i++) artifacts[i]->activate(); - } + }*/ portrait->activate(); experience->activate(); morale->activate(); @@ -978,7 +978,7 @@ void CKingdomInterface::CHeroItem::deactivate() if (!hero) return; artButtons->deactivate(); - garr->deactivate(); + garr->deactivate();/* if ( artGroup == 2 ) { artLeft->deactivate(); @@ -990,7 +990,7 @@ void CKingdomInterface::CHeroItem::deactivate() { for (size_t i=artGroup*9; i<9+artGroup*9;i++) artifacts[i]->deactivate(); - } + }*/ portrait->deactivate(); experience->deactivate(); diff --git a/client/CKingdomInterface.h b/client/CKingdomInterface.h index 675ff4610..4ef49a8b2 100644 --- a/client/CKingdomInterface.h +++ b/client/CKingdomInterface.h @@ -81,8 +81,8 @@ class CKingdomInterface : public CGarrisonHolder LRClickableAreaWText * speciality; std::vector primarySkills; std::vector secondarySkills; - std::vector artifacts; - std::vector backpack; + std::vector artifacts; + std::vector backpack; CHighlightableButtonsGroup * artButtons; void setHero(const CGHeroInstance * newHero);//change hero and update info void scrollArts(int move);//moving backpack, receiving distance diff --git a/client/CMessage.cpp b/client/CMessage.cpp index 4f5aa66d7..4e1193489 100644 --- a/client/CMessage.cpp +++ b/client/CMessage.cpp @@ -102,11 +102,13 @@ SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor) //draws box for { //prepare surface SDL_Surface * ret = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask); - for (int i=0; ih)//background + for (int i=0; iw)//background { - for (int j=0; jw) + for (int j=0; jh) { - CSDL_Ext::blitSurface(background,&genRect(background->h,background->w,0,0),ret,&genRect(h,w,j,i)); //FIXME taking address of temporary + Rect srcR(0,0,background->w, background->h); + Rect dstR(i,j,w,h); + CSDL_Ext::blitSurface(background, &srcR, ret, &dstR); } } drawBorder(playerColor, ret, w, h); @@ -486,31 +488,41 @@ void CMessage::drawIWindow(CInfoWindow * ret, std::string text, int player) void CMessage::drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x, int y) { + std::vector &box = piecesOfBox[playerColor]; //obwodka I-szego rzedu pozioma //border of 1st series, horizontal - for (int i=0; iw; i+=piecesOfBox[playerColor][6]->w) + for (int i=0; iw; i+=box[6]->w) { - CSDL_Ext::blitSurface - (piecesOfBox[playerColor][6],NULL,ret,&genRect(piecesOfBox[playerColor][6]->h,piecesOfBox[playerColor][6]->w,x+i,y+0)); - CSDL_Ext::blitSurface - (piecesOfBox[playerColor][7],NULL,ret,&genRect(piecesOfBox[playerColor][7]->h,piecesOfBox[playerColor][7]->w,x+i,y+h-piecesOfBox[playerColor][7]->h+1)); + Rect dstR(x+i, y, box[6]->w, box[6]->h); + CSDL_Ext::blitSurface(box[6], NULL, ret, &dstR); + + int currY = y+h-box[7]->h+1; + dstR=Rect(x+i, currY, box[7]->w, box[7]->h); + + CSDL_Ext::blitSurface(box[7], NULL, ret, &dstR); } //obwodka I-szego rzedu pionowa //border of 1st series, vertical - for (int i=0; ih; i+=piecesOfBox[playerColor][4]->h) + for (int i=0; ih; i+=box[4]->h) { - CSDL_Ext::blitSurface - (piecesOfBox[playerColor][4],NULL,ret,&genRect(piecesOfBox[playerColor][4]->h,piecesOfBox[playerColor][4]->w,x+0,y+i)); - CSDL_Ext::blitSurface - (piecesOfBox[playerColor][5],NULL,ret,&genRect(piecesOfBox[playerColor][5]->h,piecesOfBox[playerColor][5]->w,x+w-piecesOfBox[playerColor][5]->w,y+i)); + Rect dstR(x, y+i, box[4]->w, box[4]->h); + CSDL_Ext::blitSurface(box[4], NULL, ret, &dstR); + + int currX = x+w-box[5]->w; + dstR=Rect(currX, y+i, box[5]->w, box[5]->h); + + CSDL_Ext::blitSurface(box[5], NULL, ret, &dstR); } //corners - CSDL_Ext::blitSurface - (piecesOfBox[playerColor][0],NULL,ret,&genRect(piecesOfBox[playerColor][0]->h,piecesOfBox[playerColor][0]->w,x+0,y+0)); - CSDL_Ext::blitSurface - (piecesOfBox[playerColor][1],NULL,ret,&genRect(piecesOfBox[playerColor][1]->h,piecesOfBox[playerColor][1]->w,x+w-piecesOfBox[playerColor][1]->w,y+0)); - CSDL_Ext::blitSurface - (piecesOfBox[playerColor][2],NULL,ret,&genRect(piecesOfBox[playerColor][2]->h,piecesOfBox[playerColor][2]->w,x+0,y+h-piecesOfBox[playerColor][2]->h+1)); - CSDL_Ext::blitSurface - (piecesOfBox[playerColor][3],NULL,ret,&genRect(piecesOfBox[playerColor][3]->h,piecesOfBox[playerColor][3]->w,x+w-piecesOfBox[playerColor][3]->w,y+h-piecesOfBox[playerColor][3]->h+1)); + Rect dstR(x, y, box[0]->w, box[0]->h); + CSDL_Ext::blitSurface(box[0], NULL, ret, &dstR); + + dstR=Rect(x+w-box[1]->w, y, box[1]->w, box[1]->h); + CSDL_Ext::blitSurface(box[1], NULL, ret, &dstR); + + dstR=Rect(x, y+h-box[2]->h+1, box[2]->w, box[2]->h); + CSDL_Ext::blitSurface(box[2], NULL, ret, &dstR); + + dstR=Rect(x+w-box[3]->w, y+h-box[3]->h+1, box[3]->w, box[3]->h); + CSDL_Ext::blitSurface(box[3], NULL, ret, &dstR); } ComponentResolved::ComponentResolved() @@ -526,7 +538,7 @@ ComponentResolved::ComponentResolved( SComponent *Comp ) comp = Comp; img = comp->getImg(); std::vector brtext = CMessage::breakText(comp->subtitle,13); //text - txt = CMessage::drawText(&brtext,txtFontHeight,FONT_MEDIUM); + txt = CMessage::drawText(&brtext,txtFontHeight,FONT_SMALL); //calculate dimensions std::pair textSize = CMessage::getMaxSizes(txt, txtFontHeight); @@ -610,26 +622,25 @@ void ComponentsToBlit::blitCompsOnSur( SDL_Surface * _or, int inter, int &curh, { totalw += (inter) * ((comps)[i].size() - 1); } - - curh+=maxh/2; - int compX, compY; - + + int middleh = curh + maxh/2;//axis for image aligment int curw = (ret->w/2)-(totalw/2); + for(size_t j=0;j<(comps)[i].size();j++) { ComponentResolved *cur = (comps)[i][j]; //blit img - compX = curw + ( cur->comp->pos.w - cur->comp->getImg()->w ) / 2; - compY = curh - cur->comp->getImg()->h / 2; - blitAt(cur->img, compX, compY, ret); - cur->comp->pos.x = compX; - cur->comp->pos.y = compY; + int imgX = curw + ( cur->comp->pos.w - cur->comp->getImg()->w ) / 2; + int imgY = middleh - cur->comp->getImg()->h / 2; + blitAt(cur->img, imgX, imgY, ret); + cur->comp->pos.x = imgX; + cur->comp->pos.y = imgY; //blit subtitle - compX += cur->comp->getImg()->w/2; - compY = curh + maxh / 2 + COMPONENT_TO_SUBTITLE; - CMessage::blitTextOnSur(cur->txt, cur->txtFontHeight, compY, ret, compX ); + int textX = imgX + cur->comp->getImg()->w/2; + int textY = middleh + cur->comp->getImg()->h /2 + COMPONENT_TO_SUBTITLE; + CMessage::blitTextOnSur(cur->txt, cur->txtFontHeight, textY, ret, textX ); //if there is subsequent component blit "or" curw += cur->comp->pos.w; @@ -638,12 +649,13 @@ void ComponentsToBlit::blitCompsOnSur( SDL_Surface * _or, int inter, int &curh, if(_or) { curw+=inter; - blitAt(_or,curw,curh-(_or->h/2),ret); + blitAt(_or,curw,middleh-(_or->h/2),ret); curw+=_or->w; } curw+=inter; } + amax(curh, textY); } - curh = compY+BETWEEN_COMPS_ROWS; + curh += BETWEEN_COMPS_ROWS; } } diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index 91104676e..c787a6fbc 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -3487,7 +3487,7 @@ CAltarWindow::CAltarWindow(const IMarket *Market, const CGHeroInstance *Hero /*= { BLOCK_CAPTURING; - arts = new CArtifactsOfHero(Point(-267,-10)); + arts = new CArtifactsOfHero(Point(pos.x-363, pos.y-12)); arts->commonInfo = new CArtifactsOfHero::SCommonPart; arts->commonInfo->participants.insert(arts); arts->setHero(Hero); @@ -5858,7 +5858,10 @@ void CUniversityWindow::CItem::showAll(SDL_Surface * to) break; case 2: bar = parent->green; break; + default:bar = NULL; + break; } + assert(bar); blitAtLoc(bar->bg, -28, -22, to); blitAtLoc(bar->bg, -28, 48, to); diff --git a/config/AC_desc.txt b/config/AC_desc.txt index 80569edb3..81da9015e 100644 --- a/config/AC_desc.txt +++ b/config/AC_desc.txt @@ -73,7 +73,7 @@ 71 1 SP01_.DEF 72 1 SP04_.DEF 73 1 SP03_.DEF -74 1 SP06_.DEF +74 1 SP12_.DEF 75 1 SP07_A.DEF 76 1 SP07_B.DEF 77 1 SP08_.DEF diff --git a/config/buildings.txt b/config/buildings.txt index d62891980..57c6ef335 100644 --- a/config/buildings.txt +++ b/config/buildings.txt @@ -116,8 +116,8 @@ 2 43 TBTWUP_6.def 75 91 2 8 TBTWCAS2.def 301 0 3 16 TBINBLAK.def 684 253 -3 9 TBINCAS3.def 223 18 -3 7 TBINCSTL.def 223 44 +3 9 TBINCAS3.def 222 18 +3 7 TBINCSTL.def 222 44 3 30 TBINDW_0.def 614 256 3 31 TBINDW_1.def 187 248 3 32 TBINDW_2.def 9 325 diff --git a/hch/CVideoHandler.cpp b/hch/CVideoHandler.cpp index 944a8a1ba..eb7cf9e55 100644 --- a/hch/CVideoHandler.cpp +++ b/hch/CVideoHandler.cpp @@ -555,6 +555,13 @@ bool CVideoPlayer::playVideo(int x, int y, SDL_Surface *dst, bool stopOnKey) #else +//Workaround for compile error in ffmpeg (UINT_64C was not declared) +#define __STDC_CONSTANT_MACROS +#ifdef _STDINT_H +#undef _STDINT_H +#endif +#include + #include <../client/SDL_framerate.h> extern "C" { diff --git a/lib/map.h b/lib/map.h index 210c42296..01f81100a 100644 --- a/lib/map.h +++ b/lib/map.h @@ -212,6 +212,10 @@ public: { return firstOccurence < b.firstOccurence; } + bool operator<=(const CMapEvent &b) const + { + return firstOccurence <= b.firstOccurence; + } }; class DLL_EXPORT CCastleEvent: public CMapEvent diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 9850dfcb7..b4a4c8f5d 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -4554,8 +4554,13 @@ void CGameHandler::handleTimeEvents() if(ev->nextOccurence) { + gs->map->events.pop_front(); + ev->firstOccurence += ev->nextOccurence; - gs->map->events.sort(evntCmp); + std::list::iterator it = gs->map->events.begin(); + while ( it !=gs->map->events.end() && **it <= *ev ) + it++; + gs->map->events.insert(it, ev); } else { @@ -4615,9 +4620,14 @@ void CGameHandler::handleTownEvents(CGTownInstance * town, NewTurn &n, std::map< } if(ev->nextOccurence) - { + { + town->events.pop_front(); + ev->firstOccurence += ev->nextOccurence; - town->events.sort(evntCmp); + std::list::iterator it = town->events.begin(); + while ( it !=town->events.end() && **it <= *ev ) + it++; + town->events.insert(it, ev); } else {