1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* correct calculating blocked / vistable positions

* some minor improvements / changes / fixes
This commit is contained in:
mateuszb 2007-08-11 14:58:07 +00:00
parent cc0a4c5d09
commit 548e8582ec
7 changed files with 172 additions and 37 deletions

View File

@ -469,6 +469,7 @@ void CAmbarCendamo::deh3m()
nobj->pos.y = bufor[i++];
nobj->pos.z = bufor[i++];
nobj->defNumber = readNormalNr(i, 4); i+=4;
nobj->defObjInfoNumber = -1;
//if (((nobj.x==0)&&(nobj.y==0)) || nobj.x>map.width || nobj.y>map.height || nobj.z>1 || nobj.defNumber>map.defy.size())
// std::cout << "Alarm!!! Obiekt "<<ww<<" jest kopniety (lub wystaje poza mape)\n";
@ -1718,6 +1719,22 @@ void CAmbarCendamo::deh3m()
}
SDL_FreeSurface(alphaTransSurf);
//assigning defobjinfos
for(int ww=0; ww<CGI->objh->objInstances.size(); ++ww)
{
for(int h=0; h<CGI->dobjinfo->objs.size(); ++h)
{
if(CGI->dobjinfo->objs[h].defName==CGI->ac->map.defy[CGI->objh->objInstances[ww]->defNumber].name)
{
CGI->objh->objInstances[ww]->defObjInfoNumber = h;
break;
}
}
}
//assigned
//loading events
int numberOfEvents = readNormalNr(i); i+=4;
for(int yyoo=0; yyoo<numberOfEvents; ++yyoo)
@ -2057,6 +2074,12 @@ void CAmbarCendamo::processMap(std::vector<std::string> & defsToUnpack)
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[458].defName);
creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[459].defName);
for(int b=0; b<CGI->scenarioOps.playerInfos.size(); ++b)
{
if(CGI->scenarioOps.playerInfos[b].castle==-1)
CGI->scenarioOps.playerInfos[b].castle = rand()%F_NUMBER;
}
//variables initialized
for(int j=0; j<CGI->objh->objInstances.size(); ++j)
{

View File

@ -26,19 +26,21 @@ void CDefObjInfoHandler::load()
}
std::string mapStr;
inp>>mapStr;
std::reverse(mapStr.begin(), mapStr.end());
for(int v=0; v<mapStr.size(); ++v)
{
if(mapStr[v]=='0')
{
nobj.blockMap[v/6] ^= (128 >> (v%6));
nobj.blockMap[v/8] &= 255 - (128 >> (v%8));
}
}
inp>>mapStr;
std::reverse(mapStr.begin(), mapStr.end());
for(int v=0; v<mapStr.size(); ++v)
{
if(mapStr[v]=='1')
{
nobj.visitMap[v/6] ^= (128 >> (v%6));
nobj.visitMap[v/8] |= (128 >> (v%8));
}
}

View File

@ -291,6 +291,7 @@ class CObjectInstance //instance of object
{
public:
int defNumber; //specifies number of def file with animation of this object
int defObjInfoNumber; //number of this object's def's additional informations in CDefObjInfo's vector
int id; //number of object in CObjectHandler's vector
int3 pos; // position
CSpecObjInfo * info; //pointer to something with additional information

View File

@ -33,6 +33,9 @@ const int SKILL_QUANTITY=28;
const int ARTIFACTS_QUANTITY=171;
const int HEROES_QUANTITY=156;
#define MARK_BLOCKED_POSITIONS false
#define MARK_VISITABLE_POSITIONS false
#define DEFBYPASS

16
int3.h
View File

@ -6,17 +6,17 @@ class int3
public:
int x,y,z;
inline int3():x(0),y(0),z(0){}; //c-tor, x/y/z initialized to 0
inline int3(const int X, const int Y, const int Z):x(X),y(Y),z(Z){}; //c-tor
inline int3(const int & X, const int & Y, const int & Z):x(X),y(Y),z(Z){}; //c-tor
inline ~int3(){} // d-tor - does nothing
inline int3 operator+(const int3 & i)
inline int3 operator+(const int3 & i) const
{return int3(x+i.x,y+i.y,z+i.z);}
inline int3 operator+(const int i) //increases all components by int
inline int3 operator+(const int i) const //increases all components by int
{return int3(x+i,y+i,z+i);}
inline int3 operator-(const int3 & i)
inline int3 operator-(const int3 & i) const
{return int3(x-i.x,y-i.y,z-i.z);}
inline int3 operator-(const int i)
inline int3 operator-(const int i) const
{return int3(x-i,y-i,z-i);}
inline int3 operator-() //increases all components by int
inline int3 operator-() const //increases all components by int
{return int3(-x,-y,-z);}
inline void operator+=(const int3 & i)
{
@ -24,7 +24,7 @@ public:
y+=i.y;
z+=i.z;
}
inline void operator+=(const int i)
inline void operator+=(const int & i)
{
x+=i;
y+=i;
@ -36,7 +36,7 @@ public:
y-=i.y;
z-=i.z;
}
inline void operator-=(const int i)
inline void operator-=(const int & i)
{
x+=i;
y+=i;

View File

@ -144,14 +144,45 @@ void CMapHandler::init()
{
ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::rotate01(ttiles[i][j][k].roadbitmap[0]);
}
ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::alphaTransform(ttiles[i][j][k].roadbitmap[0]);
ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::secondAlphaTransform(ttiles[i][j][k].roadbitmap[0], su);
if(rotH || rotV)
{
ttiles[i][j][k].roadbitmap[0] = CSDL_Ext::alphaTransform(ttiles[i][j][k].roadbitmap[0]);
SDL_Surface * buf = CSDL_Ext::secondAlphaTransform(ttiles[i][j][k].roadbitmap[0], su);
SDL_FreeSurface(ttiles[i][j][k].roadbitmap[0]);
ttiles[i][j][k].roadbitmap[0] = buf;
}
}
}
}
}
}
//initializing simple values
for (int i=0; i<ttiles.size(); i++) //jest po szerokoœci
{
for (int j=0; j<ttiles[0].size();j++) //po wysokoœci
{
for(int k=0; k<ttiles[0][0].size(); ++k)
{
ttiles[i][j][k].pos = int3(i, j, k);
ttiles[i][j][k].blocked = false;
ttiles[i][j][k].visitable = false;
if(i<Woff || j<Hoff || i>=CGI->ac->map.width+Woff || j>=CGI->ac->map.height+Hoff)
{
ttiles[i][j][k].blocked = true;
continue;
}
ttiles[i][j][k].terType = (k==0 ? CGI->ac->map.terrain[i-Woff][j-Hoff].tertype : CGI->ac->map.undergroungTerrain[i-Woff][j-Hoff].tertype);
ttiles[i][j][k].malle = (k==0 ? CGI->ac->map.terrain[i-Woff][j-Hoff].malle : CGI->ac->map.undergroungTerrain[i-Woff][j-Hoff].malle);
ttiles[i][j][k].nuine = (k==0 ? CGI->ac->map.terrain[i-Woff][j-Hoff].nuine : CGI->ac->map.undergroungTerrain[i-Woff][j-Hoff].nuine);
ttiles[i][j][k].rivdir = (k==0 ? CGI->ac->map.terrain[i-Woff][j-Hoff].rivDir : CGI->ac->map.undergroungTerrain[i-Woff][j-Hoff].rivDir);
ttiles[i][j][k].roaddir = (k==0 ? CGI->ac->map.terrain[i-Woff][j-Hoff].roadDir : CGI->ac->map.undergroungTerrain[i-Woff][j-Hoff].roadDir);
}
}
}
//simple values initialized
for (int i=0; i<reader->map.width+Woff; i++) //jest po szerokoœci
{
for (int j=0; j<reader->map.height+Hoff;j++) //po wysokoœci
@ -195,8 +226,13 @@ void CMapHandler::init()
{
ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::rotate01(ttiles[i][j][k].rivbitmap[0]);
}
ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::alphaTransform(ttiles[i][j][k].rivbitmap[0]);
ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::secondAlphaTransform(ttiles[i][j][k].rivbitmap[0], su);
if(rotH || rotV)
{
ttiles[i][j][k].rivbitmap[0] = CSDL_Ext::alphaTransform(ttiles[i][j][k].rivbitmap[0]);
SDL_Surface * buf = CSDL_Ext::secondAlphaTransform(ttiles[i][j][k].rivbitmap[0], su);
SDL_FreeSurface(ttiles[i][j][k].rivbitmap[0]);
ttiles[i][j][k].rivbitmap[0] = buf;
}
}
}
}
@ -308,7 +344,6 @@ void CMapHandler::init()
break;
}
}
//SDL_BlitSurface(terrainBitmap[i][j],NULL,ekran,NULL); SDL_Flip(ekran);SDL_Delay(50);
break;
}
@ -335,12 +370,38 @@ void CMapHandler::init()
cr.x = fx*32;
cr.y = fy*32;
std::pair<CObjectInstance *, SDL_Rect> toAdd = std::make_pair(CGI->objh->objInstances[f], cr);
if((CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+Woff)>=0 && (CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+Woff)<=ttiles[0].size() && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+Hoff)>=0 && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+Hoff)<=ttiles[0].size())
if((CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+Woff)>=0 && (CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+Woff)<=ttiles.size() && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+Hoff)>=0 && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+Hoff)<=ttiles[0].size())
{
TerrainTile2 & curt = ttiles[CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+Woff][CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+Hoff][CGI->objh->objInstances[f]->pos.z];
ttiles[CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+Woff][CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+Hoff][CGI->objh->objInstances[f]->pos.z].objects.push_back(toAdd);
}
} // for(int fy=0; fy<curd->ourImages[0].bitmap->h/32; ++fy)
} //for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx)
} // for(int f=0; f<CGI->objh->objInstances.size(); ++f)
for(int f=0; f<CGI->objh->objInstances.size(); ++f) //calculationg blocked / visitable positions
{
if(CGI->objh->objInstances[f]->defObjInfoNumber == -1)
continue;
CDefHandler * curd = CGI->ac->map.defy[CGI->objh->objInstances[f]->defNumber].handler;
for(int fx=0; fx<8; ++fx)
{
for(int fy=0; fy<6; ++fy)
{
int xVal = CGI->objh->objInstances[f]->pos.x + Woff + fx - 7;
int yVal = CGI->objh->objInstances[f]->pos.y + Hoff + fy - 5;
int zVal = CGI->objh->objInstances[f]->pos.z;
if(xVal>=0 && xVal<ttiles.size() && yVal>=0 && yVal<ttiles[0].size())
{
TerrainTile2 & curt = ttiles[xVal][yVal][zVal];
if(((CGI->dobjinfo->objs[CGI->objh->objInstances[f]->defObjInfoNumber].visitMap[fy] >> (7 - fx)) & 1))
curt.visitable = true;
if(!((CGI->dobjinfo->objs[CGI->objh->objInstances[f]->defObjInfoNumber].blockMap[fy] >> (7 - fx)) & 1))
curt.blocked = true;
}
}
}
}
for(int ix=0; ix<ttiles.size(); ++ix)
{
for(int iy=0; iy<ttiles[0].size(); ++iy)
@ -370,7 +431,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
SDL_Surface * su = SDL_CreateRGBSurface(SDL_SWSURFACE, dx*32, dy*32, 32,
rmask, gmask, bmask, amask);
if (((dx+x)>((reader->map.width+8)) || (dy+y)>((reader->map.height+8))) || ((x<0)||(y<0) ) )
throw new std::string("Poza zakresem");
throw new std::string("terrainRect: out of range");
////printing terrain
for (int bx=0; bx<dx; bx++)
{
@ -480,23 +541,67 @@ 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 bx=(x==0 ? 0 : -1); bx<dx; bx++)
{
for (int by=0; by<dy; by++)
for (int by=(y==0 ? 0 : -1); 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;
SDL_Rect * sr = new SDL_Rect;
sr->y=by*32;
sr->x=bx*32;
sr->h=sr->w=32;
SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],NULL,su,sr);
SDL_BlitSurface(ttiles[x+bx][y+by][level].terbitmap[anim%ttiles[x+bx][y+by][level].terbitmap.size()],NULL,su,sr);
delete sr;
delete sr;
}
else
{
if(MARK_BLOCKED_POSITIONS && ttiles[x+bx][y+by][level].blocked) //temporary hiding blocked positions
{
SDL_Rect * sr = new SDL_Rect;
sr->y=by*32;
sr->x=bx*32;
sr->h=sr->w=32;
SDL_Surface * ns = SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32,
rmask, gmask, bmask, amask);
for(int f=0; f<ns->w*ns->h*4; ++f)
{
*((unsigned char*)(ns->pixels) + f) = 128;
}
SDL_BlitSurface(ns,NULL,su,sr);
SDL_FreeSurface(ns);
delete sr;
}
if(MARK_VISITABLE_POSITIONS && ttiles[x+bx][y+by][level].visitable) //temporary hiding visitable positions
{
SDL_Rect * sr = new SDL_Rect;
sr->y=by*32;
sr->x=bx*32;
sr->h=sr->w=32;
SDL_Surface * ns = SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32,
rmask, gmask, bmask, amask);
for(int f=0; f<ns->w*ns->h*4; ++f)
{
*((unsigned char*)(ns->pixels) + f) = 128;
}
SDL_BlitSurface(ns,NULL,su,sr);
SDL_FreeSurface(ns);
delete sr;
}
}
}
}
CSDL_Ext::update(su);
//borders printed
return su;
}

View File

@ -11,23 +11,24 @@ const int Hoff = 4;
struct TerrainTile2
{
int3 pos;
EterrainType typ;
int3 pos; //this tile's position
EterrainType terType; //type of terrain tile
Eroad malle;
unsigned char roaddir;
Eroad malle; //type of road
unsigned char roaddir; //type of road tile
Eriver nuine;
unsigned char rivdir;
Eriver nuine; //type of river
unsigned char rivdir; //type of river tile
std::vector<SDL_Surface *> terbitmap; //frames of animation
std::vector<SDL_Surface *> rivbitmap; //frames of animation
std::vector<SDL_Surface *> roadbitmap; //frames of animation
std::vector<SDL_Surface *> terbitmap; //frames of terrain animation
std::vector<SDL_Surface *> rivbitmap; //frames of river animation
std::vector<SDL_Surface *> roadbitmap; //frames of road animation
boost::logic::tribool state; //false = free; true = blocked; middle = visitable
bool visitable; //false = not visitable; true = visitable
bool blocked; //false = free; true = blocked;
std::vector < std::pair<CObjectInstance*,SDL_Rect> > objects;
std::vector <CObjectInstance*> visitableObjects;
std::vector < std::pair<CObjectInstance*,SDL_Rect> > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen
std::vector <CObjectInstance*> visitableObjects; //pointers to objects hero is visiting being on this tile
};