1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

* minimap shows all flaggable objects (towns, mines, etc.)

* minor optimizations
This commit is contained in:
mateuszb 2008-09-26 14:16:01 +00:00
parent 6a3d0b666f
commit a4afdc7145
8 changed files with 162 additions and 119 deletions

View File

@ -39,14 +39,15 @@ CAdvMapInt::~CAdvMapInt()
}
CMinimap::CMinimap(bool draw)
{
int3 mapSizes = LOCPLINT->cb->getMapSize();
statusbarTxt = CGI->preth->zelp[291].first;
rcText = CGI->preth->zelp[291].second;
pos.x=630;
pos.y=26;
pos.h=pos.w=144;
int rx = (((float)19)/(CGI->mh->sizes.x))*((float)pos.w),
ry = (((float)18)/(CGI->mh->sizes.y))*((float)pos.h);
int rx = (((float)19)/(mapSizes.x))*((float)pos.w),
ry = (((float)18)/(mapSizes.y))*((float)pos.h);
radar = newSurface(rx,ry);
temps = newSurface(144,144);
@ -101,13 +102,14 @@ CMinimap::CMinimap(bool draw)
}
void CMinimap::draw()
{
int3 mapSizes = LOCPLINT->cb->getMapSize();
//draw terrain
blitAt(map[LOCPLINT->adventureInt->position.z],0,0,temps);
//draw heroes
std::vector <const CGHeroInstance *> hh = LOCPLINT->cb->getHeroesInfo(false);
int mw = map[0]->w, mh = map[0]->h,
wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y;
wo = mw/mapSizes.x, ho = mh/mapSizes.y;
for (int i=0; i<hh.size();i++)
{
@ -115,7 +117,7 @@ void CMinimap::draw()
if(hpos.z!=LOCPLINT->adventureInt->position.z)
continue;
//float zawx = ((float)hpos.x/CGI->mh->sizes.x), zawy = ((float)hpos.y/CGI->mh->sizes.y);
int3 maplgp ( (hpos.x*mw)/CGI->mh->sizes.x, (hpos.y*mh)/CGI->mh->sizes.y, hpos.z );
int3 maplgp ( (hpos.x*mw)/mapSizes.x, (hpos.y*mh)/mapSizes.y, hpos.z );
for (int ii=0; ii<wo; ii++)
{
for (int jj=0; jj<ho; jj++)
@ -124,18 +126,45 @@ void CMinimap::draw()
}
}
}
//draw flaggable objects
for(int x=0; x<mapSizes.x; ++x)
{
for(int y=0; y<mapSizes.y; ++y)
{
std::vector < const CGObjectInstance * > oo = LOCPLINT->cb->getFlaggableObjects(int3(x, y, LOCPLINT->adventureInt->position.z));
for(int v=0; v<oo.size(); ++v)
{
if(!dynamic_cast< const CGHeroInstance * >(oo[v])) //heroes have been printed
{
int3 maplgp ( (x*mw)/mapSizes.x, (y*mh)/mapSizes.y, LOCPLINT->adventureInt->position.z );
for (int ii=0; ii<wo; ii++)
{
for (int jj=0; jj<ho; jj++)
{
if(oo[v]->tempOwner == 255)
SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,graphics->neutralColor->r,graphics->neutralColor->g,graphics->neutralColor->b);
else
SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,graphics->playerColors[oo[v]->getOwner()].r,graphics->playerColors[oo[v]->getOwner()].g,graphics->playerColors[oo[v]->getOwner()].b);
}
}
}
}
}
}
blitAt(FoW[LOCPLINT->adventureInt->position.z],0,0,temps);
//draw radar
int bx = (((float)LOCPLINT->adventureInt->position.x)/(((float)CGI->mh->sizes.x)))*pos.w,
by = (((float)LOCPLINT->adventureInt->position.y)/(((float)CGI->mh->sizes.y)))*pos.h;
int bx = (((float)LOCPLINT->adventureInt->position.x)/(((float)mapSizes.x)))*pos.w,
by = (((float)LOCPLINT->adventureInt->position.y)/(((float)mapSizes.y)))*pos.h;
blitAt(radar,bx,by,temps);
blitAt(temps,pos.x,pos.y);
//SDL_UpdateRect(screen,pos.x,pos.y,pos.w,pos.h);
}
void CMinimap::redraw(int level)// (level==-1) => redraw all levels
{
(CGI);
int3 mapSizes = LOCPLINT->cb->getMapSize();
for (int i=0; i<CGI->mh->sizes.z; i++)
{
SDL_Surface * pom ;
@ -148,8 +177,8 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels
{
for (int y=0;y<pos.h;y++)
{
int mx=(CGI->mh->sizes.x*x)/pos.w;
int my=(CGI->mh->sizes.y*y)/pos.h;
int mx=(mapSizes.x*x)/pos.w;
int my=(mapSizes.y*y)/pos.h;
if (CGI->mh->ttiles[mx][my][i].tileInfo->blocked && (!CGI->mh->ttiles[mx][my][i].tileInfo->visitable))
SDL_PutPixel(pom,x,y,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colorsBlocked[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
else SDL_PutPixel(pom,x,y,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].r,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].g,colors[CGI->mh->ttiles[mx][my][i].tileInfo->tertype].b);
@ -161,7 +190,7 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels
//FoW
int mw = map[0]->w, mh = map[0]->h,
wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y;
wo = mw/mapSizes.x, ho = mh/mapSizes.y;
for(int d=0; d<CGI->mh->map->twoLevel+1; ++d)
{
if(level>=0 && d!=level)
@ -171,7 +200,7 @@ void CMinimap::redraw(int level)// (level==-1) => redraw all levels
{
for (int j=0; j<mh; j++)
{
int3 pp( ((i*CGI->mh->sizes.x)/mw), ((j*CGI->mh->sizes.y)/mh), d );
int3 pp( ((i*mapSizes.x)/mw), ((j*mapSizes.y)/mh), d );
if ( !LOCPLINT->cb->isVisible(pp) )
{
CSDL_Ext::SDL_PutPixelWithoutRefresh(pt,i,j,0,0,0);

View File

@ -150,24 +150,24 @@ void CCallback::endTurn()
*cl->serv << ui16(100); //report that we ended turn
cl->serv->wmx->unlock();
}
UpgradeInfo CCallback::getUpgradeInfo(const CArmedInstance *obj, int stackPos)
UpgradeInfo CCallback::getUpgradeInfo(const CArmedInstance *obj, int stackPos) const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->getUpgradeInfo(const_cast<CArmedInstance*>(obj),stackPos);
}
const StartInfo * CCallback::getStartInfo()
const StartInfo * CCallback::getStartInfo() const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->scenarioOps;
}
int CCallback::howManyTowns()
int CCallback::howManyTowns() const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->players[player].towns.size();
}
const CGTownInstance * CCallback::getTownInfo(int val, bool mode) //mode = 0 -> val = serial; mode = 1 -> val = ID
const CGTownInstance * CCallback::getTownInfo(int val, bool mode) const //mode = 0 -> val = serial; mode = 1 -> val = ID
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
if (!mode)
@ -186,12 +186,12 @@ const CGTownInstance * CCallback::getTownInfo(int val, bool mode) //mode = 0 ->
}
return NULL;
}
int CCallback::howManyHeroes()
int CCallback::howManyHeroes() const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->players[player].heroes.size();
}
const CGHeroInstance * CCallback::getHeroInfo(int val, int mode) //mode = 0 -> val = serial; mode = 1 -> val = ID
const CGHeroInstance * CCallback::getHeroInfo(int val, int mode) const //mode = 0 -> val = serial; mode = 1 -> val = ID
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
//if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info
@ -215,22 +215,22 @@ const CGHeroInstance * CCallback::getHeroInfo(int val, int mode) //mode = 0 -> v
return NULL;
}
int CCallback::getResourceAmount(int type)
int CCallback::getResourceAmount(int type) const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->players[player].resources[type];
}
std::vector<si32> CCallback::getResourceAmount()
std::vector<si32> CCallback::getResourceAmount() const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->players[player].resources;
}
int CCallback::getDate(int mode)
int CCallback::getDate(int mode) const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->getDate(mode);
}
std::vector < std::string > CCallback::getObjDescriptions(int3 pos)
std::vector < std::string > CCallback::getObjDescriptions(int3 pos) const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
std::vector<std::string> ret;
@ -240,7 +240,7 @@ std::vector < std::string > CCallback::getObjDescriptions(int3 pos)
ret.push_back(obj->hoverName);
return ret;
}
bool CCallback::verifyPath(CPath * path, bool blockSea)
bool CCallback::verifyPath(CPath * path, bool blockSea) const
{
for (int i=0;i<path->nodes.size();i++)
{
@ -273,20 +273,20 @@ bool CCallback::verifyPath(CPath * path, bool blockSea)
return true;
}
std::vector< std::vector< std::vector<unsigned char> > > & CCallback::getVisibilityMap()
std::vector< std::vector< std::vector<unsigned char> > > & CCallback::getVisibilityMap() const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->players[player].fogOfWarMap;
}
bool CCallback::isVisible(int3 pos, int Player)
bool CCallback::isVisible(int3 pos, int Player) const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->players[Player].fogOfWarMap[pos.x][pos.y][pos.z];
}
std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur)
std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur) const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
std::vector < const CGTownInstance *> ret = std::vector < const CGTownInstance *>();
@ -302,7 +302,7 @@ std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur)
} // for ( std::map<int, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
return ret;
}
std::vector < const CGHeroInstance *> CCallback::getHeroesInfo(bool onlyOur)
std::vector < const CGHeroInstance *> CCallback::getHeroesInfo(bool onlyOur) const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
std::vector < const CGHeroInstance *> ret;
@ -317,13 +317,13 @@ std::vector < const CGHeroInstance *> CCallback::getHeroesInfo(bool onlyOur)
return ret;
}
bool CCallback::isVisible(int3 pos)
bool CCallback::isVisible(int3 pos) const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return isVisible(pos,player);
}
bool CCallback::isVisible( CGObjectInstance *obj, int Player )
bool CCallback::isVisible( CGObjectInstance *obj, int Player ) const
{
//object is visible when at least one blocked tile is visible
for(int fx=0; fx<8; ++fx)
@ -339,11 +339,11 @@ bool CCallback::isVisible( CGObjectInstance *obj, int Player )
}
return false;
}
int CCallback::getMyColor()
int CCallback::getMyColor() const
{
return player;
}
int CCallback::getHeroSerial(const CGHeroInstance * hero)
int CCallback::getHeroSerial(const CGHeroInstance * hero) const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
for (int i=0; i<gs->players[player].heroes.size();i++)
@ -353,7 +353,7 @@ int CCallback::getHeroSerial(const CGHeroInstance * hero)
}
return -1;
}
const CCreatureSet* CCallback::getGarrison(const CGObjectInstance *obj)
const CCreatureSet* CCallback::getGarrison(const CGObjectInstance *obj) const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
if(!obj)
@ -399,7 +399,7 @@ bool CCallback::dismissHero(const CGHeroInstance *hero)
return true;
}
int CCallback::getMySerial()
int CCallback::getMySerial() const
{
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
return gs->players[player].serial;
@ -540,7 +540,7 @@ void CCallback::buyArtifact(const CGHeroInstance *hero, int aid)
*cl->serv << ui16(510) << hero->id << ui32(aid);
}
std::vector < const CGObjectInstance * > CCallback::getBlockingObjs( int3 pos )
std::vector < const CGObjectInstance * > CCallback::getBlockingObjs( int3 pos ) const
{
std::vector<const CGObjectInstance *> ret;
if(!gs->map->isInTheMap(pos))
@ -551,7 +551,7 @@ std::vector < const CGObjectInstance * > CCallback::getBlockingObjs( int3 pos )
return ret;
}
std::vector < const CGObjectInstance * > CCallback::getVisitableObjs( int3 pos )
std::vector < const CGObjectInstance * > CCallback::getVisitableObjs( int3 pos ) const
{
std::vector<const CGObjectInstance *> ret;
if(!gs->map->isInTheMap(pos))
@ -562,7 +562,7 @@ std::vector < const CGObjectInstance * > CCallback::getVisitableObjs( int3 pos )
return ret;
}
void CCallback::getMarketOffer( int t1, int t2, int &give, int &rec, int mode/*=0*/ )
void CCallback::getMarketOffer( int t1, int t2, int &give, int &rec, int mode/*=0*/ ) const
{
if(mode) return; //TODO - support
boost::shared_lock<boost::shared_mutex> lock(*gs->mx);
@ -581,6 +581,27 @@ void CCallback::getMarketOffer( int t1, int t2, int &give, int &rec, int mode/*=
}
}
std::vector < const CGObjectInstance * > CCallback::getFlaggableObjects(int3 pos) const
{
if(!isVisible(pos, LOCPLINT->playerID))
return std::vector < const CGObjectInstance * >();
std::vector < const CGObjectInstance * > ret;
std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > & objs = CGI->mh->ttiles[pos.x][pos.y][pos.z].objects;
for(int b=0; b<objs.size(); ++b)
{
if(objs[b].first->tempOwner!=254 && !((objs[b].first->defInfo->blockMap[pos.y - objs[b].first->pos.y + 5] >> (objs[b].first->pos.x - pos.x)) & 1))
ret.push_back(CGI->mh->ttiles[pos.x][pos.y][pos.z].objects[b].first);
}
return ret;
}
int3 CCallback::getMapSize() const
{
return CGI->mh->sizes;
}
void CCallback::trade( int mode, int id1, int id2, int val1 )
{
int p1, p2;

View File

@ -45,26 +45,28 @@ public:
virtual void setFormation(const CGHeroInstance * hero, bool tight)=0;
//get info
virtual bool verifyPath(CPath * path, bool blockSea)=0;
virtual int getDate(int mode=0)=0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
virtual std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap()=0; //returns visibility map (TODO: make it const)
virtual const CGHeroInstance * getHeroInfo(int val, int mode=2)=0; //mode = 0 -> val = serial; mode = 1 -> val = ID
virtual int getResourceAmount(int type)=0;
virtual int howManyHeroes()=0;
virtual const CGTownInstance * getTownInfo(int val, bool mode)=0; //mode = 0 -> val = serial; mode = 1 -> val = ID
virtual int howManyTowns()=0;
virtual std::vector < std::string > getObjDescriptions(int3 pos)=0; //returns descriptions of objects at pos in order from the lowest to the highest
virtual std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true)=0;
virtual bool isVisible(int3 pos)=0;
virtual int getMyColor()=0;
virtual int getMySerial()=0;
virtual int getHeroSerial(const CGHeroInstance * hero)=0;
virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)=0;
virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)=0;
virtual const StartInfo * getStartInfo()=0;
virtual std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos)=0;
virtual std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos)=0;
virtual void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0)=0;
virtual bool verifyPath(CPath * path, bool blockSea)const =0;
virtual int getDate(int mode=0)const =0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
virtual std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap()const =0; //returns visibility map (TODO: make it const)
virtual const CGHeroInstance * getHeroInfo(int val, int mode=2)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID
virtual int getResourceAmount(int type)const =0;
virtual int howManyHeroes()const =0;
virtual const CGTownInstance * getTownInfo(int val, bool mode)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID
virtual int howManyTowns()const =0;
virtual std::vector < std::string > getObjDescriptions(int3 pos)const =0; //returns descriptions of objects at pos in order from the lowest to the highest
virtual std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true)const =0;
virtual bool isVisible(int3 pos)const =0;
virtual int getMyColor()const =0;
virtual int getMySerial()const =0;
virtual int getHeroSerial(const CGHeroInstance * hero)const =0;
virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)const =0;
virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)const =0;
virtual const StartInfo * getStartInfo()const =0;
virtual std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos)const =0;
virtual std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos)const =0;
virtual void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0)const =0;
virtual std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const =0;
virtual int3 getMapSize() const =0; //returns size of map - z is 1 for one - level map and 2 for two level map
//battle
virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
@ -98,8 +100,8 @@ private:
CCallback(CGameState * GS, int Player, CClient *C):gs(GS),player(Player),cl(C){};
CGameState * gs;
CClient *cl;
bool isVisible(int3 pos, int Player);
bool isVisible(CGObjectInstance *obj, int Player);
bool isVisible(int3 pos, int Player) const;
bool isVisible(CGObjectInstance *obj, int Player) const;
protected:
int player;
@ -125,28 +127,30 @@ public:
void setFormation(const CGHeroInstance * hero, bool tight);
//get info
bool verifyPath(CPath * path, bool blockSea);
int getDate(int mode=0); //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap(); //returns visibility map (TODO: make it const)
const CGHeroInstance * getHeroInfo(int val, int mode=2); //mode = 0 -> val = serial; mode = 1 -> val = ID
int getResourceAmount(int type);
std::vector<si32> getResourceAmount();
int howManyHeroes();
const CGTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
std::vector < const CGTownInstance *> getTownsInfo(bool onlyOur=true);
int howManyTowns();
std::vector < std::string > getObjDescriptions(int3 pos); //returns descriptions of objects at pos in order from the lowest to the highest
std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true);
bool isVisible(int3 pos);
int getMyColor();
int getHeroSerial(const CGHeroInstance * hero);
int getMySerial();
const CCreatureSet* getGarrison(const CGObjectInstance *obj);
UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos);
const StartInfo * getStartInfo();
std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos);
std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos);
void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0);
bool verifyPath(CPath * path, bool blockSea) const;
int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap() const; //returns visibility map (TODO: make it const)
const CGHeroInstance * getHeroInfo(int val, int mode=2) const; //mode = 0 -> val = serial; mode = 1 -> val = ID
int getResourceAmount(int type) const;
std::vector<si32> getResourceAmount() const;
int howManyHeroes() const;
const CGTownInstance * getTownInfo(int val, bool mode) const; //mode = 0 -> val = serial; mode = 1 -> val = ID
std::vector < const CGTownInstance *> getTownsInfo(bool onlyOur=true) const;
int howManyTowns()const;
std::vector < std::string > getObjDescriptions(int3 pos) const; //returns descriptions of objects at pos in order from the lowest to the highest
std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true) const;
bool isVisible(int3 pos) const;
int getMyColor() const;
int getHeroSerial(const CGHeroInstance * hero) const;
int getMySerial() const;
const CCreatureSet* getGarrison(const CGObjectInstance *obj) const;
UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos) const;
const StartInfo * getStartInfo() const;
std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos) const;
std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos) const;
void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0) const;
std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
//battle
int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship

View File

@ -34,15 +34,14 @@ void CPCXConv::openPCX(char * PCX, int len)
}
void CPCXConv::fromFile(std::string path)
{
std::ifstream * is = new std::ifstream();
is -> open(path.c_str(),std::ios::binary);
is->seekg(0,std::ios::end); // to the end
pcxs = is->tellg(); // read length
is->seekg(0,std::ios::beg); // wracamy na poczatek
std::ifstream is;
is.open(path.c_str(),std::ios::binary);
is.seekg(0,std::ios::end); // to the end
pcxs = is.tellg(); // read length
is.seekg(0,std::ios::beg); // wracamy na poczatek
pcx = new unsigned char[pcxs]; // allocate memory
is->read((char*)pcx, pcxs); // read map file to buffer
is->close();
delete is;
is.read((char*)pcx, pcxs); // read map file to buffer
is.close();
}
void CPCXConv::saveBMP(std::string path)
{

View File

@ -95,6 +95,7 @@ CCreatureAnimation::CCreatureAnimation(std::string name) : RLEntries(NULL), RWEn
curFrame = 0;
type = -1;
frames = totalEntries;
RLEntries = new int[fullHeight];
}
int CCreatureAnimation::readNormalNr (int pos, int bytCon, unsigned char * str, bool cyclic)
@ -173,9 +174,8 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
long BaseOffset,
SpriteWidth, SpriteHeight, //sprite format
LeftMargin, RightMargin, TopMargin,BottomMargin,
i, add, FullHeight,FullWidth,
TotalRowLength, // length of read segment
RowAdd;
i, FullHeight,FullWidth,
TotalRowLength; // length of read segment
unsigned char SegmentType, SegmentLength;
i=BaseOffset=SEntries[SIndex].offset;
@ -189,8 +189,6 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
TopMargin = readNormalNr(i,4,FDef);i+=4;
RightMargin = FullWidth - SpriteWidth - LeftMargin;
BottomMargin = FullHeight - SpriteHeight - TopMargin;
add = 4 - FullWidth%4;
int BaseOffsetor = BaseOffset = i;
@ -202,10 +200,9 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
{
for (int i=0;i<TopMargin;i++)
{
ftcp+=FullWidth+add;
ftcp+=FullWidth;
}
}
RLEntries = new int[SpriteHeight];
for (int i=0;i<SpriteHeight;i++)
{
RLEntries[i]=readNormalNr(BaseOffset,4,FDef);BaseOffset+=4;
@ -226,8 +223,8 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
{
for (int k=0;k<=SegmentLength;k++)
{
int xB = (attacker ? ftcp%(FullWidth+add) : (FullWidth+add) - ftcp%(FullWidth+add) - 1) + x;
int yB = ftcp/(FullWidth+add) + y;
int xB = (attacker ? ftcp%FullWidth : FullWidth - ftcp%FullWidth - 1) + x;
int yB = ftcp/FullWidth + y;
if(xB>=0 && yB>=0 && xB<dest->w && yB<dest->h)
{
if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB))
@ -244,8 +241,8 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
{
for (int k=0;k<SegmentLength+1;k++)
{
int xB = (attacker ? ftcp%(FullWidth+add) : (FullWidth+add) - ftcp%(FullWidth+add) - 1) + x;
int yB = ftcp/(FullWidth+add) + y;
int xB = (attacker ? ftcp%FullWidth : FullWidth - ftcp%FullWidth - 1) + x;
int yB = ftcp/FullWidth + y;
if(xB>=0 && yB>=0 && xB<dest->w && yB<dest->h)
{
if(!destRect || (destRect->x <= xB && destRect->x + destRect->w > xB && destRect->y <= yB && destRect->y + destRect->h > yB))
@ -256,26 +253,17 @@ int CCreatureAnimation::nextFrame(SDL_Surface *dest, int x, int y, bool attacker
TotalRowLength+=SegmentLength+1;
}
}while(TotalRowLength<SpriteWidth);
RowAdd=SpriteWidth-TotalRowLength;
if (RightMargin>0)
{
ftcp+=RightMargin;
}
if (add>0)
{
ftcp+=add+RowAdd;
}
}
delete [] RLEntries;
RLEntries = NULL;
if (BottomMargin>0)
{
ftcp += BottomMargin * (FullWidth+add);
ftcp += BottomMargin * FullWidth;
}
}
//SDL_UpdateRect(dest, x, y, FullWidth+add, FullHeight);
return 0;
}

View File

@ -169,6 +169,8 @@ void CDefHandler::openFromMemory(unsigned char *table, std::string name)
{
SEntries[j].name = SEntries[j].name.substr(0, SEntries[j].name.find('.')+4);
}
RWEntries = new unsigned int[fullHeight];
RLEntries = new int[fullHeight];
for(int i=0; i<SEntries.size(); ++i)
{
Cimage nimg;
@ -337,7 +339,6 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef)
((char*)(ret->pixels))[ftcp++]='\0';
}
}
RLEntries = new int[SpriteHeight];
for (int i=0;i<SpriteHeight;i++)
{
RLEntries[i]=readNormalNr(BaseOffset,4,FDef);BaseOffset+=4;
@ -388,8 +389,6 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef)
((char*)(ret->pixels))[ftcp++]='\0';
}
}
delete [] RLEntries;
RLEntries = NULL;
if (BottomMargin>0)
{
for (int i=0;i<BottomMargin;i++)
@ -409,7 +408,6 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef)
((char*)(ret->pixels))[ftcp++]='\0';
}
}
RWEntries = new unsigned int[SpriteHeight];
for (int i=0;i<SpriteHeight;i++)
{
BaseOffset=BaseOffsetor+i*2*(SpriteWidth/32);
@ -457,8 +455,6 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef)
((char*)(ret->pixels))[ftcp++]='\0';
}
}
delete [] RWEntries;
RWEntries = NULL;
if (BottomMargin>0)
{
for (int i=0;i<BottomMargin;i++)
@ -480,7 +476,6 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef)
((char*)(ret->pixels))[ftcp++]='\0';
}
}
RWEntries = new unsigned int[SpriteHeight];
for (int i=0;i<SpriteHeight;i++)
{
BaseOffset=BaseOffsetor+i*2*(SpriteWidth/32);
@ -535,8 +530,6 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, unsigned char * FDef)
((char*)(ret->pixels))[ftcp++]='\0';
}
}
delete [] RWEntries;
RWEntries=NULL;
if (BottomMargin>0)
{
for (int i=0;i<BottomMargin;i++)

View File

@ -121,7 +121,7 @@ int CGObjectInstance::getHeight() const //returns height of object graphic in ti
{
return defInfo->width;
}
bool CGObjectInstance::visitableAt(int x, int y) const //returns true if ibject is visitable at location (x, y) form left top tile of image (x, y in tiles)
bool CGObjectInstance::visitableAt(int x, int y) const //returns true if object is visitable at location (x, y) form left top tile of image (x, y in tiles)
{
if(x<0 || y<0 || x>=getWidth() || y>=getHeight() || defInfo==NULL)
return false;
@ -129,6 +129,14 @@ bool CGObjectInstance::visitableAt(int x, int y) const //returns true if ibject
return true;
return false;
}
bool CGObjectInstance::blockingAt(int x, int y) const
{
if(x<0 || y<0 || x>=getWidth() || y>=getHeight() || defInfo==NULL)
return false;
if((defInfo->blockMap[y+6-getHeight()] >> (7-(8-getWidth()+x) )) & 1)
return true;
return false;
}
bool CGObjectInstance::operator<(const CGObjectInstance & cmp) const //screen printing priority comparing
{
if(defInfo->printPriority==1 && cmp.defInfo->printPriority==0)

View File

@ -62,7 +62,8 @@ public:
void setOwner(int ow);
int getWidth() const; //returns width of object graphic in tiles
int getHeight() const; //returns height of object graphic in tiles
bool visitableAt(int x, int y) const; //returns true if ibject is visitable at location (x, y) form left top tile of image (x, y in tiles)
bool visitableAt(int x, int y) const; //returns true if object is visitable at location (x, y) form left top tile of image (x, y in tiles)
bool blockingAt(int x, int y) const; //returns true if object is blocking location (x, y) form left top tile of image (x, y in tiles)
bool operator<(const CGObjectInstance & cmp) const; //screen printing priority comparing
CGObjectInstance();
virtual ~CGObjectInstance();