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

Dzisiejsze zmiany (wyświetlanie obiektów)

This commit is contained in:
Michał W. Urbańczyk 2007-07-02 19:44:30 +00:00
parent 9ff9557ed2
commit 82308c10fe
6 changed files with 127 additions and 8 deletions

View File

@ -11,6 +11,7 @@
#include "CObjectHandler.h"
#include "CMusicHandler.h"
#include "CSemiLodHandler.h"
#include "CDefObjInfoHandler.h"
/*
CGameInfo class
@ -30,6 +31,7 @@ public:
CObjectHandler * objh;
CMusicHandler * mush;
CSemiLodHandler * sspriteh;
CDefObjInfoHandler * dobjinfo;
};
#endif //CGAMEINFO_H

12
CMT.cpp
View File

@ -27,6 +27,7 @@
#include "CSemiLodHandler.h"
#include "CLodHandler.h"
#include "CDefHandler.h"
#include "CDefObjInfoHandler.h"
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
# include <io.h>
@ -280,10 +281,10 @@ int _tmain(int argc, _TCHAR* argv[])
//CLodHandler * bitmapLod = new CLodHandler;
//bitmapLod->init(std::string("newH3bitmap.lod"));
CPCXConv * tconv = new CPCXConv;
tconv->fromFile(std::string("newh3bitmap\\ADOPBPNL.PCX"));
tconv->convert();
tconv->saveBMP(std::string("tesciczekConva.bmp"));
//CPCXConv * tconv = new CPCXConv;
//tconv->fromFile(std::string("newh3bitmap\\ADOPBPNL.PCX"));
//tconv->convert();
//tconv->saveBMP(std::string("tesciczekConva.bmp"));
CSemiDefHandler * semek = new CSemiDefHandler;
semek->openDef(std::string("EDG.DEF"), std::string("H3sprite.lod"));
@ -313,6 +314,9 @@ int _tmain(int argc, _TCHAR* argv[])
CObjectHandler * objh = new CObjectHandler;
objh->loadObjects();
cgi->objh = objh;
cgi->dobjinfo = new CDefObjInfoHandler;
cgi->dobjinfo->load();
std::string mapname;
//if (CPG) mapname = CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].filename;
//else mapname = "4gryf";

10
map.cpp
View File

@ -12,7 +12,15 @@ int readNormalNr (unsigned char * bufor, int pos, int bytCon = 4)
}
return ret;
}
bool DefInfo::isVisitable()
{
for (int i=6; i<12; i++)
{
if (bytes[i])
return true;
}
return false;
}
CMapHeader::CMapHeader(unsigned char *map)
{
this->version = (Eformat)map[0]; //wersja mapy

1
map.h
View File

@ -59,6 +59,7 @@ struct DefInfo //information from def declaration
int bytes [42];
//CSemiDefHandler * handler;
CDefHandler * handler;
bool isVisitable();
};
struct Location
{

View File

@ -5,8 +5,40 @@
#include "SDL_Extensions.h"
#include "CGameInfo.h"
#include "stdlib.h"
#include <algorithm>
extern SDL_Surface * ekran;
//
//bool ObjSorter::operator <(const ObjSorter & por) const
//{
// if(this->xpos>=por.xpos)
// return false;
// if(this->ypos>=por.ypos)
// return false;
// return true;
//};
class poX
{
public:
bool operator()(const ObjSorter & por2, const ObjSorter & por) const
{
if(por2.xpos>=por.xpos)
return false;
return true;
};
} pox;
class poY
{
public:
bool operator ()(const ObjSorter & por2, const ObjSorter & por) const
{
if(por2.ypos>=por.ypos)
return false;
return true;
};
} poy;
void CMapHandler::init()
{
fullHide = CGameInfo::mainObj->sspriteh->giveDef("TSHRC.DEF", 2);
@ -280,7 +312,72 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
}
}
////terrain printed; printing objects
std::vector<ObjSorter> lowPrObjs;
std::vector<ObjSorter> highPrObjs;
std::vector<ObjSorter> highPrObjsVis;
for(int gg=0; gg<CGameInfo::mainObj->objh->objInstances.size(); ++gg)
{
if(CGameInfo::mainObj->objh->objInstances[gg].x >= x-Woff-4 && CGameInfo::mainObj->objh->objInstances[gg].x < dx+x-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg].y >= y-Hoff-4 && CGameInfo::mainObj->objh->objInstances[gg].y < dy+y-Hoff+4 && CGameInfo::mainObj->objh->objInstances[gg].z == level)
{
std::vector<DefObjInfo>::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(),
CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].name);
if(pit->priority==0)
{
ObjSorter os;
os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap;
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+4)*32;
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+4)*32;
if (CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].isVisitable())
highPrObjsVis.push_back(os);
else
highPrObjs.push_back(os);
}
else
{
ObjSorter os;
os.bitmap = CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap;
os.xpos = (CGameInfo::mainObj->objh->objInstances[gg].x-x+4)*32;
os.ypos = (CGameInfo::mainObj->objh->objInstances[gg].y-y+4)*32;
lowPrObjs.push_back(os);
}
}
}
//std::stable_sort(lowPrObjs.begin(), lowPrObjs.end());
std::stable_sort(highPrObjs.begin(), highPrObjs.end(),pox);
std::stable_sort(highPrObjs.begin(), highPrObjs.end(),poy);
std::stable_sort(highPrObjsVis.begin(), highPrObjsVis.end(),pox);
std::stable_sort(highPrObjsVis.begin(), highPrObjsVis.end(),poy);
for(int yy=0; yy<lowPrObjs.size(); ++yy)
{
SDL_Rect * sr = new SDL_Rect;
sr->w = lowPrObjs[yy].bitmap->w;
sr->h = lowPrObjs[yy].bitmap->h;
sr->x = lowPrObjs[yy].xpos - lowPrObjs[yy].bitmap->w + 32;
sr->y = lowPrObjs[yy].ypos - lowPrObjs[yy].bitmap->h + 32;
SDL_BlitSurface(lowPrObjs[yy].bitmap, NULL, su, sr);
delete sr;
}
for(int yy=0; yy<highPrObjs.size(); ++yy)
{
SDL_Rect * sr = new SDL_Rect;
sr->w = highPrObjs[yy].bitmap->w;
sr->h = highPrObjs[yy].bitmap->h;
sr->x = highPrObjs[yy].xpos - highPrObjs[yy].bitmap->w + 32;
sr->y = highPrObjs[yy].ypos - highPrObjs[yy].bitmap->h + 32;
SDL_BlitSurface(highPrObjs[yy].bitmap, NULL, su, sr);
delete sr;
}
for(int yy=0; yy<highPrObjsVis.size(); ++yy)
{
SDL_Rect * sr = new SDL_Rect;
sr->w = highPrObjsVis[yy].bitmap->w;
sr->h = highPrObjsVis[yy].bitmap->h;
sr->x = highPrObjsVis[yy].xpos - highPrObjsVis[yy].bitmap->w + 32;
sr->y = highPrObjsVis[yy].ypos - highPrObjsVis[yy].bitmap->h + 32;
SDL_BlitSurface(highPrObjsVis[yy].bitmap, NULL, su, sr);
delete sr;
}
/*for(int gg=0; gg<CGameInfo::mainObj->objh->objInstances.size(); ++gg)
{
if(CGameInfo::mainObj->objh->objInstances[gg].x >= x-3 && CGameInfo::mainObj->objh->objInstances[gg].x < dx+x-3 && CGameInfo::mainObj->objh->objInstances[gg].y >= y-3 && CGameInfo::mainObj->objh->objInstances[gg].y < dy+y-3 && CGameInfo::mainObj->objh->objInstances[gg].z == level)
{
@ -292,7 +389,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
SDL_BlitSurface(CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages[anim%CGameInfo::mainObj->ac->map.defy[CGameInfo::mainObj->objh->objInstances[gg].defNumber].handler->ourImages.size()].bitmap, NULL, su, sr);
delete sr;
}
}
}*/
////objects printed, printing shadow
for (int bx=0; bx<dx; bx++)
{

View File

@ -5,8 +5,15 @@
#include "CSemiDefHandler.h"
#include "CGameInfo.h"
const unsigned int Woff = 4; //width of map's frame
const unsigned int Hoff = 4;
const int Woff = 4; //width of map's frame
const int Hoff = 4;
struct ObjSorter
{
SDL_Surface * bitmap;
int xpos, ypos;
bool operator<(const ObjSorter & por) const;
};
class CMapHandler
{