1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-05 00:49:09 +02:00

* animation of water tiles

* minor changes
This commit is contained in:
Michał W. Urbańczyk
2008-11-30 00:15:38 +00:00
parent 447e5babda
commit c6bcd61aba
15 changed files with 195 additions and 181 deletions

View File

@ -1253,6 +1253,7 @@ void CAdvMapInt::update()
} }
if(updateScreen) if(updateScreen)
{ {
CGI->mh->updateWater();
terrain.show(); terrain.show();
for(int i=0;i<4;i++) for(int i=0;i<4;i++)
blitAt(gems[i]->ourImages[LOCPLINT->playerID].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i]); blitAt(gems[i]->ourImages[LOCPLINT->playerID].bitmap,ADVOPT.gemX[i],ADVOPT.gemY[i]);

View File

@ -1392,12 +1392,12 @@ int CGameState::battleGetStack(int pos)
return -1; return -1;
for(int g=0; g<curB->stacks.size(); ++g) for(int g=0; g<curB->stacks.size(); ++g)
{ {
if(curB->stacks[g]->position == pos || if((curB->stacks[g]->position == pos
( curB->stacks[g]->creature->isDoubleWide() && || (curB->stacks[g]->creature->isDoubleWide()
( (curB->stacks[g]->attackerOwned && curB->stacks[g]->position-1 == pos) || &&( (curB->stacks[g]->attackerOwned && curB->stacks[g]->position-1 == pos)
(!curB->stacks[g]->attackerOwned && curB->stacks[g]->position+1 == pos) || (!curB->stacks[g]->attackerOwned && curB->stacks[g]->position+1 == pos) )
) ))
) && curB->stacks[g]->alive()
) )
return curB->stacks[g]->ID; return curB->stacks[g]->ID;
} }

View File

@ -269,7 +269,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
artWorn[g] = new CArtPlace(hero->getArt(g)); artWorn[g] = new CArtPlace(hero->getArt(g));
artWorn[g]->pos = slotPos[g]; artWorn[g]->pos = slotPos[g];
if(hero->getArt(g)) if(hero->getArt(g))
artWorn[g]->text = hero->getArt(g)->description; artWorn[g]->text = hero->getArt(g)->Description();
artWorn[g]->ourWindow = this; artWorn[g]->ourWindow = this;
} }
@ -278,7 +278,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
artWorn[g]->slotID = g; artWorn[g]->slotID = g;
if(artWorn[g]->ourArt) if(artWorn[g]->ourArt)
{ {
sprintf(bufor, CGI->generaltexth->heroscrn[1].c_str(), artWorn[g]->ourArt->name.c_str()); sprintf(bufor, CGI->generaltexth->heroscrn[1].c_str(), artWorn[g]->ourArt->Name().c_str());
artWorn[g]->hoverText = std::string(bufor); artWorn[g]->hoverText = std::string(bufor);
} }
else else
@ -293,7 +293,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
if( s < curHero->artifacts.size() ) if( s < curHero->artifacts.size() )
{ {
add = new CArtPlace(&CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]]); add = new CArtPlace(&CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]]);
sprintf(bufor, CGI->generaltexth->heroscrn[1].c_str(), add->ourArt->name.c_str()); sprintf(bufor, CGI->generaltexth->heroscrn[1].c_str(), add->ourArt->Name().c_str());
add->hoverText = bufor; add->hoverText = bufor;
} }
else else
@ -305,7 +305,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
add->pos.y = pos.y + 365; add->pos.y = pos.y + 365;
add->pos.h = add->pos.w = 44; add->pos.h = add->pos.w = 44;
if(s<hero->artifacts.size() && hero->artifacts[s]) if(s<hero->artifacts.size() && hero->artifacts[s])
add->text = hero->getArt(19+s)->description; add->text = hero->getArt(19+s)->Description();
else else
add->text = std::string(); add->text = std::string();
add->ourWindow = this; add->ourWindow = this;
@ -468,7 +468,7 @@ void CHeroWindow::leftArtRoller()
{ {
backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]]; backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]];
if(backpack[s]->ourArt) if(backpack[s]->ourArt)
backpack[s]->text = backpack[s]->ourArt->description; backpack[s]->text = backpack[s]->ourArt->Description();
else else
backpack[s]->text = std::string(); backpack[s]->text = std::string();
} }
@ -485,7 +485,7 @@ void CHeroWindow::rightArtRoller()
{ {
backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ] ]; backpack[s]->ourArt = &CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ] ];
if(backpack[s]->ourArt) if(backpack[s]->ourArt)
backpack[s]->text = backpack[s]->ourArt->description; backpack[s]->text = backpack[s]->ourArt->Description();
else else
backpack[s]->text = std::string(); backpack[s]->text = std::string();
} }
@ -719,11 +719,11 @@ void CArtPlace::clickLeft(boost::logic::tribool down)
//set texts //set texts
if(pmh) if(pmh)
ourWindow->activeArtPlace->text = pmh->description; ourWindow->activeArtPlace->text = pmh->Description();
else else
ourWindow->activeArtPlace->text = std::string(); ourWindow->activeArtPlace->text = std::string();
if(ourArt) if(ourArt)
text = ourArt->description; text = ourArt->Description();
else else
text = std::string(); text = std::string();

View File

@ -114,6 +114,7 @@ int main(int argc, char** argv)
cgi->bitmaph->init("Data" PATHSEPARATOR "H3bitmap.lod","Data"); cgi->bitmaph->init("Data" PATHSEPARATOR "H3bitmap.lod","Data");
tlog0<<"Loading .lod files: "<<tmh.getDif()<<std::endl; tlog0<<"Loading .lod files: "<<tmh.getDif()<<std::endl;
initDLL(cgi->bitmaph,::console,logfile); initDLL(cgi->bitmaph,::console,logfile);
CGI->generaltexth = VLC->generaltexth;
CGI->arth = VLC->arth; CGI->arth = VLC->arth;
CGI->creh = VLC->creh; CGI->creh = VLC->creh;
CGI->townh = VLC->townh; CGI->townh = VLC->townh;
@ -122,7 +123,6 @@ int main(int argc, char** argv)
CGI->spellh = VLC->spellh; CGI->spellh = VLC->spellh;
CGI->dobjinfo = VLC->dobjinfo; CGI->dobjinfo = VLC->dobjinfo;
CGI->buildh = VLC->buildh; CGI->buildh = VLC->buildh;
CGI->generaltexth = VLC->generaltexth;
tlog0<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl; tlog0<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl;
pomtime.getDif(); pomtime.getDif();
cgi->curh = new CCursorHandler; cgi->curh = new CCursorHandler;

View File

@ -626,8 +626,8 @@ void SComponent::init(Etype Type, int Subtype, int Val)
switch (Type) switch (Type)
{ {
case artifact: case artifact:
description = CGI->arth->artifacts[Subtype].description; description = CGI->arth->artifacts[Subtype].Description();
subtitle = CGI->arth->artifacts[Subtype].name; subtitle = CGI->arth->artifacts[Subtype].Name();
break; break;
case primskill: case primskill:
description = CGI->generaltexth->arraytxt[2+Subtype]; description = CGI->generaltexth->arraytxt[2+Subtype];
@ -2255,36 +2255,7 @@ void CPlayerInterface::heroArtifactSetChanged(const CGHeroInstance*hero)
void CPlayerInterface::updateWater() void CPlayerInterface::updateWater()
{ {
//updating water tiles
//int wnumber = -1;
//for(int s=0; s<CGI->mh->reader->defs.size(); ++s)
//{
// if(CGI->mh->reader->defs[s]->defName==std::string("WATRTL.DEF"))
// {
// wnumber = s;
// break;
// }
//}
//if(wnumber>=0)
//{
// for(int g=0; g<CGI->mh->reader->defs[wnumber]->ourImages.size(); ++g)
// {
// SDL_Color tab[32];
// for(int i=0; i<32; ++i)
// {
// tab[i] = CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[160 + (i+1)%32];
// }
// //SDL_SaveBMP(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap,"t1.bmp");
// for(int i=0; i<32; ++i)
// {
// CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap->format->palette->colors[160 + i] = tab[i];
// }
// //SDL_SaveBMP(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap,"t2.bmp");
// CSDL_Ext::update(CGI->mh->reader->defs[wnumber]->ourImages[g].bitmap);
// }
//}
//water tiles updated
//CGI->screenh->updateScreen();
} }
void CPlayerInterface::availableCreaturesChanged( const CGTownInstance *town ) void CPlayerInterface::availableCreaturesChanged( const CGTownInstance *town )
@ -2643,7 +2614,8 @@ CTownList::CTownList(int Size, int x, int y, std::string arrupg, std::string arr
arrdo = CDefHandler::giveDef(arrdog); arrdo = CDefHandler::giveDef(arrdog);
pos.x = x; pos.x = x;
pos.y = y; pos.y = y;
pos.w = std::max(arrdo->width, arrup->height); pos.w = std::max(arrdo->width, arrup->width);
pos.h = arrdo->height + arrup->height + Size*32;
arrupp.x=x; arrupp.x=x;
arrupp.y=y; arrupp.y=y;

View File

@ -1,11 +1,19 @@
0.64 -> 0.next (???) [as for r639] 0.64 -> 0.next (???) [as for r651]
GENERAL: GENERAL:
* move some settings to the config/settings.txt file * move some settings to the config/settings.txt file
* partial support for new screen resolutions * partial support for new screen resolutions
* /Data and /Sprites subfolders can be used for adding files not present in .lod archives * /Data and /Sprites subfolders can be used for adding files not present in .lod archives
* fixed crashbug occuring when hero levelled above 15 level * fixed crashbug occuring when hero levelled above 15 level
ADVENTURE INTERFACE:
* added water animation
TOWN INTERFACE:
* the scroll tab won't remain hanged to our mouse position if we move the mouse away from the scroll bar
* fixed cloning creatures bug in garrisons (and related issues)
BATTLES BATTLES
* support for the Wait command
* magic arrow *really* works * magic arrow *really* works
* war machines support partially added * war machines support partially added
* queue of stacks narrowed * queue of stacks narrowed
@ -17,6 +25,10 @@ BATTLES
c) ice bolt c) ice bolt
d) slow d) slow
e) implosion e) implosion
f) forgetfulness
AI:
* Genius AI (first VCMI AI) will control computer creatures during the combat.
GENERAL: GENERAL:
* started making external settings file (will be used for support for non 800x600 screen resolutions) * started making external settings file (will be used for support for non 800x600 screen resolutions)

View File

@ -272,14 +272,7 @@ SDL_Surface * CSDL_Ext::rotate01(SDL_Surface * toRot)
{ {
{ {
Uint8 *p = (Uint8 *)toRot->pixels + j * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel; Uint8 *p = (Uint8 *)toRot->pixels + j * toRot->pitch + (ret->w - i - 1) * toRot->format->BytesPerPixel;
/*
#if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
CSDL_Ext::SDL_PutPixelWithoutRefresh(ret, i, j, p[0], p[1], p[2]);
#else
*/
CSDL_Ext::SDL_PutPixelWithoutRefresh(ret, i, j, p[2], p[1], p[0]); CSDL_Ext::SDL_PutPixelWithoutRefresh(ret, i, j, p[2], p[1], p[0]);
//#endif
} }
} }
} }
@ -493,6 +486,54 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src)
} }
return src; return src;
} }
// <=>
void CSDL_Ext::blitWithRotate1(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24bpp dests
{
Uint8 *dp, *sp = (Uint8 *)src->pixels;
for(int i=0; i<dstRect->h; i++)
{
dp = (Uint8 *)dst->pixels + (i+dstRect->y)*dst->pitch + (dstRect->x+dstRect->w)*dst->format->BytesPerPixel;
for(int j=0; j<dstRect->w; j++, sp++)
{
const SDL_Color * const color = src->format->palette->colors+(*sp);
*(--dp) = color->r;
*(--dp) = color->g;
*(--dp) = color->b;
}
}
}
void CSDL_Ext::blitWithRotate2(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24bpp dests
{
Uint8 *dp, *sp = (Uint8 *)src->pixels;
for(int i=0; i<dstRect->h; i++)
{
dp = (Uint8 *)dst->pixels + (dstRect->y + dstRect->h - 1 - i)*dst->pitch + dstRect->x*dst->format->BytesPerPixel;
for(int j=0; j<dstRect->w; j++, sp++)
{
const SDL_Color * const color = src->format->palette->colors+(*sp);
*(dp++) = color->b;
*(dp++) = color->g;
*(dp++) = color->r;
}
}
}
void CSDL_Ext::blitWithRotate3(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)//srcRect is not used, works with 8bpp sources and 24bpp dests
{
Uint8 *dp, *sp = (Uint8 *)src->pixels;
for(int i=0; i<dstRect->h; i++)
{
dp = (Uint8 *)dst->pixels + (dstRect->y + dstRect->h - 1 - i)*dst->pitch + (dstRect->x+dstRect->w)*dst->format->BytesPerPixel;
for(int j=0; j<dstRect->w; j++, sp++)
{
const SDL_Color * const color = src->format->palette->colors+(*sp);
*(--dp) = color->r;
*(--dp) = color->g;
*(--dp) = color->b;
}
}
}
int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect) int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect)
{ {
@ -518,7 +559,8 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su
} }
/* clip the source rectangle to the source surface */ /* clip the source rectangle to the source surface */
if(srcRect) { if(srcRect)
{
int maxw, maxh; int maxw, maxh;
srcx = srcRect->x; srcx = srcRect->x;
@ -543,7 +585,9 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Su
if(maxh < h) if(maxh < h)
h = maxh; h = maxh;
} else { }
else
{
srcx = srcy = 0; srcx = srcy = 0;
w = src->w; w = src->w;
h = src->h; h = src->h;

View File

@ -34,6 +34,9 @@ namespace CSDL_Ext
Uint32 SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte = false); Uint32 SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte = false);
SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y); SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y);
SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details) SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details)
void blitWithRotate1(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests
void blitWithRotate2(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests
void blitWithRotate3(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests
int blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface int blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface
Uint32 colorToUint32(const SDL_Color * color); //little endian only Uint32 colorToUint32(const SDL_Color * color); //little endian only
void printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y) void printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)

View File

@ -36,7 +36,7 @@ std::string toString(MetaString &ms)
ser = ms.texts[-ms.message[i]-1].second; ser = ms.texts[-ms.message[i]-1].second;
if(type == 5) if(type == 5)
{ {
ret += CGI->arth->artifacts[ser].name; ret += CGI->arth->artifacts[ser].Name();
continue; continue;
} }
else if(type == 7) else if(type == 7)

View File

@ -2,6 +2,7 @@
#include "../stdafx.h" #include "../stdafx.h"
#include "CArtHandler.h" #include "CArtHandler.h"
#include "CLodHandler.h" #include "CLodHandler.h"
#include "CGeneralTextHandler.h"
#include <boost/assign/std/vector.hpp> #include <boost/assign/std/vector.hpp>
#include <boost/assign/list_of.hpp> #include <boost/assign/list_of.hpp>
#include "../lib/VCMI_Lib.h" #include "../lib/VCMI_Lib.h"
@ -23,10 +24,12 @@ void CArtHandler::loadArtifacts()
{ {
loadToIt(dump,buf,it,3); loadToIt(dump,buf,it,3);
} }
VLC->generaltexth->artifNames.resize(ARTIFACTS_QUANTITY);
VLC->generaltexth->artifDescriptions.resize(ARTIFACTS_QUANTITY);
for (int i=0; i<ARTIFACTS_QUANTITY; i++) for (int i=0; i<ARTIFACTS_QUANTITY; i++)
{ {
CArtifact nart; CArtifact nart;
loadToIt(nart.name,buf,it,4); loadToIt(VLC->generaltexth->artifNames[i],buf,it,4);
loadToIt(pom,buf,it,4); loadToIt(pom,buf,it,4);
nart.price=atoi(pom.c_str()); nart.price=atoi(pom.c_str());
for(int j=0;j<slots.size();j++) for(int j=0;j<slots.size();j++)
@ -37,7 +40,7 @@ void CArtHandler::loadArtifacts()
} }
loadToIt(pom,buf,it,4); loadToIt(pom,buf,it,4);
nart.aClass = classes[pom[0]]; nart.aClass = classes[pom[0]];
loadToIt(nart.description,buf,it,3); loadToIt(VLC->generaltexth->artifDescriptions[i],buf,it,3);
nart.id=i; nart.id=i;
artifacts.push_back(nart); artifacts.push_back(nart);
} }
@ -96,3 +99,19 @@ void CArtHandler::sortArts()
} }
} }
} }
const std::string & CArtifact::Name() const
{
if(name.size())
return name;
else
return VLC->generaltexth->artifNames[id];
}
const std::string & CArtifact::Description() const
{
if(description.size())
return description;
else
return VLC->generaltexth->artifDescriptions[id];
}

View File

@ -9,10 +9,11 @@ class CDefHandler;
class DLL_EXPORT CArtifact //container for artifacts class DLL_EXPORT CArtifact //container for artifacts
{ {
std::string name, description; //set if custom
public: public:
const std::string &Name() const;
const std::string &Description() const;
bool isAllowed; //true if we can use this artifact (map information) bool isAllowed; //true if we can use this artifact (map information)
std::string name;
std::string description;
//std::string desc2; //std::string desc2;
unsigned int price; unsigned int price;
std::vector<ui16> possibleSlots; //ids of slots where artifact can be placed std::vector<ui16> possibleSlots; //ids of slots where artifact can be placed

View File

@ -22,6 +22,8 @@ public:
std::vector<std::string> jktexts; std::vector<std::string> jktexts;
std::vector<std::string> heroscrn; std::vector<std::string> heroscrn;
std::vector<std::string> artifEvents; std::vector<std::string> artifEvents;
std::vector<std::string> artifNames;
std::vector<std::string> artifDescriptions;
std::vector<std::pair<std::string,std::string> > zelp; std::vector<std::pair<std::string,std::string> > zelp;
std::string lossCondtions[4]; std::string lossCondtions[4];

View File

@ -29,6 +29,11 @@ DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *
bitmaph=b; bitmaph=b;
VLC = new LibClasses; VLC = new LibClasses;
VLC->generaltexth = new CGeneralTextHandler;
VLC->generaltexth->loadTexts();
VLC->generaltexth->load();
tlog0<<"\tGeneral text handler: "<<pomtime.getDif()<<std::endl;
CHeroHandler * heroh = new CHeroHandler; CHeroHandler * heroh = new CHeroHandler;
heroh->loadHeroes(); heroh->loadHeroes();
VLC->heroh = heroh; VLC->heroh = heroh;
@ -65,11 +70,6 @@ DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *
spellh->loadSpells(); spellh->loadSpells();
VLC->spellh = spellh; VLC->spellh = spellh;
tlog0<<"\tSpell handler: "<<pomtime.getDif()<<std::endl; tlog0<<"\tSpell handler: "<<pomtime.getDif()<<std::endl;
VLC->generaltexth = new CGeneralTextHandler;
VLC->generaltexth->loadTexts();
VLC->generaltexth->load();
tlog0<<"\tGeneral text handler: "<<pomtime.getDif()<<std::endl;
} }
DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode) DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode)

View File

@ -16,9 +16,9 @@
#include "map.h" #include "map.h"
#include "hch/CDefHandler.h" #include "hch/CDefHandler.h"
extern SDL_Surface * screen; extern SDL_Surface * screen;
std::string nameFromType (EterrainType typ) std::string nameFromType (int typ)
{ {
switch(typ) switch((EterrainType)typ)
{ {
case dirt: case dirt:
{ {
@ -139,28 +139,6 @@ void CMapHandler::prepareFOWDefs()
{ {
CSDL_Ext::alphaTransform(partialHide->ourImages[i].bitmap); CSDL_Ext::alphaTransform(partialHide->ourImages[i].bitmap);
} }
//visibility.resize(map->width+2*Woff);
//for(int gg=0; gg<map->width+2*Woff; ++gg)
//{
// visibility[gg].resize(map->height+2*Hoff);
// for(int jj=0; jj<map->height+2*Hoff; ++jj)
// visibility[gg][jj] = true;
//}
//visibility.resize(CGI->mh->map->width, Woff);
//for (int i=0-Woff;i<visibility.size()-Woff;i++)
//{
// visibility[i].resize(CGI->mh->map->height,Hoff);
//}
//for (int i=0-Woff; i<visibility.size()-Woff; ++i)
//{
// for (int j=0-Hoff; j<CGI->mh->map->height+Hoff; ++j)
// {
// visibility[i][j].resize(CGI->mh->map->twoLevel+1,0);
// for(int k=0; k<CGI->mh->map->twoLevel+1; ++k)
// visibility[i][j][k]=true;
// }
//}
hideBitmap.resize(CGI->mh->map->width); hideBitmap.resize(CGI->mh->map->width);
for (int i=0;i<hideBitmap.size();i++) for (int i=0;i<hideBitmap.size();i++)
@ -297,6 +275,17 @@ void CMapHandler::borderAndTerrainBitmapInit()
{ {
CDefHandler * bord = CDefHandler::giveDef("EDG.DEF"); CDefHandler * bord = CDefHandler::giveDef("EDG.DEF");
bord->notFreeImgs = true; bord->notFreeImgs = true;
terrainGraphics.resize(10);
for (int i = 0; i < 10 ; i++)
{
CDefHandler *hlp = CDefHandler::giveDef(nameFromType(i));
terrainGraphics[i].resize(hlp->ourImages.size());
hlp->notFreeImgs = true;
for(int j=0; j<hlp->ourImages.size();j++)
terrainGraphics[i][j] = hlp->ourImages[j].bitmap;
delete hlp;
}
for (int i=0-Woff; i<map->width+Woff; i++) //jest po szeroko�ci for (int i=0-Woff; i<map->width+Woff; i++) //jest po szeroko�ci
{ {
for (int j=0-Hoff; j<map->height+Hoff;j++) //po wysoko�ci for (int j=0-Hoff; j<map->height+Hoff;j++) //po wysoko�ci
@ -307,99 +296,47 @@ void CMapHandler::borderAndTerrainBitmapInit()
{ {
if(i==-1 && j==-1) if(i==-1 && j==-1)
{ {
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[16].bitmap); ttiles[i][j][k].terbitmap = bord->ourImages[16].bitmap;
continue; continue;
} }
else if(i==-1 && j==(map->height)) else if(i==-1 && j==(map->height))
{ {
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[19].bitmap); ttiles[i][j][k].terbitmap = bord->ourImages[19].bitmap;
continue; continue;
} }
else if(i==(map->width) && j==-1) else if(i==(map->width) && j==-1)
{ {
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[17].bitmap); ttiles[i][j][k].terbitmap = bord->ourImages[17].bitmap;
continue; continue;
} }
else if(i==(map->width) && j==(map->height)) else if(i==(map->width) && j==(map->height))
{ {
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[18].bitmap); ttiles[i][j][k].terbitmap = bord->ourImages[18].bitmap;
continue; continue;
} }
else if(j == -1 && i > -1 && i < map->height) else if(j == -1 && i > -1 && i < map->height)
{ {
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[22+rand()%2].bitmap); ttiles[i][j][k].terbitmap = bord->ourImages[22+rand()%2].bitmap;
continue; continue;
} }
else if(i == -1 && j > -1 && j < map->height) else if(i == -1 && j > -1 && j < map->height)
{ {
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[33+rand()%2].bitmap); ttiles[i][j][k].terbitmap = bord->ourImages[33+rand()%2].bitmap;
continue; continue;
} }
else if(j == map->height && i >-1 && i < map->width) else if(j == map->height && i >-1 && i < map->width)
{ {
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[29+rand()%2].bitmap); ttiles[i][j][k].terbitmap = bord->ourImages[29+rand()%2].bitmap;
continue; continue;
} }
else if(i == map->width && j > -1 && j < map->height) else if(i == map->width && j > -1 && j < map->height)
{ {
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[25+rand()%2].bitmap); ttiles[i][j][k].terbitmap = bord->ourImages[25+rand()%2].bitmap;
continue; continue;
} }
else else
{ {
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[rand()%16].bitmap); ttiles[i][j][k].terbitmap = bord->ourImages[rand()%16].bitmap;
continue;
}
}
//TerrainTile zz = map->terrain[i-Woff][j-Hoff];
std::string name;
if (k>0)
name = nameFromType(map->terrain[i][j][1].tertype);
else
name = nameFromType(map->terrain[i][j][0].tertype);
for (unsigned int m=0; m<defs.size(); m++)
{
try
{
if (defs[m]->defName != name)
continue;
else
{
int ktora;
if (k==0)
ktora = map->terrain[i][j][0].terview;
else
ktora = map->terrain[i][j][1].terview;
ttiles[i][j][k].terbitmap.push_back(defs[m]->ourImages[ktora].bitmap);
int zz;
if (k==0)
zz = (map->terrain[i][j][0].siodmyTajemniczyBajt)%4;
else
zz = (map->terrain[i][j][1].siodmyTajemniczyBajt)%4;
switch (zz)
{
case 1:
{
ttiles[i][j][k].terbitmap[0] = CSDL_Ext::rotate01(ttiles[i][j][k].terbitmap[0]);
break;
}
case 2:
{
ttiles[i][j][k].terbitmap[0] = CSDL_Ext::hFlip(ttiles[i][j][k].terbitmap[0]);
break;
}
case 3:
{
ttiles[i][j][k].terbitmap[0] = CSDL_Ext::rotate03(ttiles[i][j][k].terbitmap[0]);
break;
}
}
break;
}
}
catch (...)
{
continue; continue;
} }
} }
@ -491,8 +428,6 @@ void CMapHandler::init()
{ {
timeHandler th; timeHandler th;
th.getDif(); th.getDif();
loadDefs(); //loading castles' defs
tlog0<<"Reading terrain defs: "<<th.getDif()<<std::endl;
std::ifstream ifs("config/townsDefs.txt"); std::ifstream ifs("config/townsDefs.txt");
int ccc; int ccc;
@ -553,7 +488,6 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
{ {
if(!otherHeroAnim) if(!otherHeroAnim)
heroAnim = anim; //the same, as it should be heroAnim = anim; //the same, as it should be
//setting surface to blit at //setting surface to blit at
SDL_Surface * su = NULL; //blitting surface CSDL_Ext::newSurface(dx*32, dy*32, CSDL_Ext::std32bppSurface); SDL_Surface * su = NULL; //blitting surface CSDL_Ext::newSurface(dx*32, dy*32, CSDL_Ext::std32bppSurface);
if(extSurf) if(extSurf)
@ -572,12 +506,38 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
{ {
for (int by=0; by<dy; by++) for (int by=0; by<dy; by++)
{ {
const TerrainTile2 & tile = ttiles[x+bx][y+by][level];
SDL_Rect sr; SDL_Rect sr;
sr.y=by*32; sr.y=by*32;
sr.x=bx*32; sr.x=bx*32;
sr.h=sr.w=32; sr.h=sr.w=32;
validateRectTerr(&sr, extRect); validateRectTerr(&sr, extRect);
SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],&genRect(sr.h, sr.w, 0, 0),su,&sr); if(tile.terbitmap)
{
SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap, &genRect(sr.h, sr.w, 0, 0), su, &sr);
}
else
{
switch(tile.tileInfo->siodmyTajemniczyBajt%4)
{
case 0:
SDL_BlitSurface(terrainGraphics[tile.tileInfo->tertype][tile.tileInfo->terview],
&genRect(sr.h, sr.w, 0, 0),su,&sr);
break;
case 1:
CSDL_Ext::blitWithRotate1(terrainGraphics[tile.tileInfo->tertype][tile.tileInfo->terview],
&genRect(sr.h, sr.w, 0, 0),su,&sr);
break;
case 2:
CSDL_Ext::blitWithRotate2(terrainGraphics[tile.tileInfo->tertype][tile.tileInfo->terview],
&genRect(sr.h, sr.w, 0, 0),su,&sr);
break;
default:
CSDL_Ext::blitWithRotate3(terrainGraphics[tile.tileInfo->tertype][tile.tileInfo->terview],
&genRect(sr.h, sr.w, 0, 0),su,&sr);
break;
}
}
} }
} }
////terrain printed ////terrain printed
@ -736,8 +696,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
sr.x=bx*32; sr.x=bx*32;
sr.h=sr.w=32; sr.h=sr.w=32;
validateRectTerr(&sr, extRect); validateRectTerr(&sr, extRect);
SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap,&genRect(sr.h, sr.w, 0, 0),su,&sr);
SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],&genRect(sr.h, sr.w, 0, 0),su,&sr);
} }
else else
{ {
@ -1286,26 +1245,24 @@ unsigned char CMapHandler::getDir(const int3 &a, const int3 &b)
return -2; //shouldn't happen return -2; //shouldn't happen
} }
void CMapHandler::updateWater() //shift colors in palettes of water tiles
{
SDL_Color palette[14];
for(int j=0; j<terrainGraphics[8].size(); j++)
{
for(int i=0; i<12; ++i)
{
palette[(i+1)%12] = terrainGraphics[8][j]->format->palette->colors[229 + i];
}
SDL_SetColors(terrainGraphics[8][j],palette,229,12);
for(int i=0; i<14; ++i)
{
palette[(i+1)%14] = terrainGraphics[8][j]->format->palette->colors[242 + i];
}
SDL_SetColors(terrainGraphics[8][j],palette,242,14);
}
}
void CMapHandler::loadDefs() TerrainTile2::TerrainTile2()
{ :terbitmap(0),tileInfo(0)
std::set<int> loadedTypes; {}
for (int i=0; i<map->width; i++)
{
for (int j=0; j<map->width; j++)
{
if (loadedTypes.find(map->terrain[i][j][0].tertype)==loadedTypes.end())
{
CDefHandler *sdh = CDefHandler::giveDef(nameFromType(map->terrain[i][j][0].tertype).c_str());
loadedTypes.insert(map->terrain[i][j][0].tertype);
defs.push_back(sdh);
}
if (map->twoLevel && loadedTypes.find(map->terrain[i][j][1].tertype)==loadedTypes.end())
{
CDefHandler *sdh = CDefHandler::giveDef(nameFromType(map->terrain[i][j][1].tertype).c_str());
loadedTypes.insert(map->terrain[i][j][1].tertype);
defs.push_back(sdh);
}
}
}
}

View File

@ -20,11 +20,12 @@ struct TerrainTile2
{ {
int3 pos; int3 pos;
const TerrainTile *tileInfo; const TerrainTile *tileInfo;
std::vector<SDL_Surface *> terbitmap; //frames of terrain animation SDL_Surface * terbitmap; //frames of terrain animation
std::vector<SDL_Surface *> rivbitmap; //frames of river animation std::vector<SDL_Surface *> rivbitmap; //frames of river animation
std::vector<SDL_Surface *> roadbitmap; //frames of road animation std::vector<SDL_Surface *> roadbitmap; //frames of road animation
std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen
TerrainTile2();
}; };
//pathfinder //pathfinder
@ -75,6 +76,7 @@ public:
CDefHandler * fullHide; CDefHandler * fullHide;
CDefHandler * partialHide; CDefHandler * partialHide;
std::vector<std::vector<SDL_Surface *> > terrainGraphics; // [terrain id] [view type] [rotation type]
std::vector<CDefHandler *> roadDefs; std::vector<CDefHandler *> roadDefs;
std::vector<CDefHandler *> staticRiverDefs; std::vector<CDefHandler *> staticRiverDefs;
std::vector<CDefHandler*> defs; std::vector<CDefHandler*> defs;
@ -103,6 +105,7 @@ public:
void prepareFOWDefs(); void prepareFOWDefs();
SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap = NULL, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap = NULL, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it
void updateWater();
unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function
void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper
static unsigned char getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b] static unsigned char getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b]