From 548e8582ec183685bbd5bf52e9272681c387f65b Mon Sep 17 00:00:00 2001 From: mateuszb Date: Sat, 11 Aug 2007 14:58:07 +0000 Subject: [PATCH] * correct calculating blocked / vistable positions * some minor improvements / changes / fixes --- CAmbarCendamo.cpp | 23 +++++++ CDefObjInfoHandler.cpp | 6 +- CObjectHandler.h | 1 + global.h | 3 + int3.h | 16 ++--- mapHandler.cpp | 135 ++++++++++++++++++++++++++++++++++++----- mapHandler.h | 25 ++++---- 7 files changed, 172 insertions(+), 37 deletions(-) diff --git a/CAmbarCendamo.cpp b/CAmbarCendamo.cpp index fc8e77e2d..31db3389e 100644 --- a/CAmbarCendamo.cpp +++ b/CAmbarCendamo.cpp @@ -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 "<objh->objInstances.size(); ++ww) + { + for(int h=0; hdobjinfo->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 & defsToUnpack) creGenNames[F_NUMBER-1].push_back(CGI->dobjinfo->objs[453].defName); 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; bscenarioOps.playerInfos.size(); ++b) + { + if(CGI->scenarioOps.playerInfos[b].castle==-1) + CGI->scenarioOps.playerInfos[b].castle = rand()%F_NUMBER; + } //variables initialized for(int j=0; jobjh->objInstances.size(); ++j) diff --git a/CDefObjInfoHandler.cpp b/CDefObjInfoHandler.cpp index 6d5a727f3..f752c3a72 100644 --- a/CDefObjInfoHandler.cpp +++ b/CDefObjInfoHandler.cpp @@ -26,19 +26,21 @@ void CDefObjInfoHandler::load() } std::string mapStr; inp>>mapStr; + std::reverse(mapStr.begin(), mapStr.end()); for(int v=0; v> (v%6)); + nobj.blockMap[v/8] &= 255 - (128 >> (v%8)); } } inp>>mapStr; + std::reverse(mapStr.begin(), mapStr.end()); for(int v=0; v> (v%6)); + nobj.visitMap[v/8] |= (128 >> (v%8)); } } diff --git a/CObjectHandler.h b/CObjectHandler.h index 55c44bac1..15161c570 100644 --- a/CObjectHandler.h +++ b/CObjectHandler.h @@ -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 diff --git a/global.h b/global.h index b769b981b..b9bca9320 100644 --- a/global.h +++ b/global.h @@ -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 diff --git a/int3.h b/int3.h index c31ea12a3..d1bf7dd8d 100644 --- a/int3.h +++ b/int3.h @@ -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; diff --git a/mapHandler.cpp b/mapHandler.cpp index fa729bc94..80ec0680a 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -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=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; imap.width+Woff; i++) //jest po szerokości { for (int j=0; jmap.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 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; fyourImages[0].bitmap->h/32; ++fy) } //for(int fx=0; fxourImages[0].bitmap->w/32; ++fx) } // for(int f=0; fobjh->objInstances.size(); ++f) + for(int f=0; fobjh->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=0 && yValdobjinfo->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((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; bxreader->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; fw*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; fw*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; } diff --git a/mapHandler.h b/mapHandler.h index 1bf214f13..03f9b29b6 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -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 terbitmap; //frames of animation - std::vector rivbitmap; //frames of animation - std::vector roadbitmap; //frames of animation + std::vector terbitmap; //frames of terrain animation + std::vector rivbitmap; //frames of river animation + std::vector 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 > objects; - std::vector visitableObjects; + std::vector < std::pair > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen + std::vector visitableObjects; //pointers to objects hero is visiting being on this tile };