mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Dzisiejsze zmiany (wyświetlanie obiektów)
This commit is contained in:
parent
9ff9557ed2
commit
82308c10fe
@ -11,6 +11,7 @@
|
|||||||
#include "CObjectHandler.h"
|
#include "CObjectHandler.h"
|
||||||
#include "CMusicHandler.h"
|
#include "CMusicHandler.h"
|
||||||
#include "CSemiLodHandler.h"
|
#include "CSemiLodHandler.h"
|
||||||
|
#include "CDefObjInfoHandler.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
CGameInfo class
|
CGameInfo class
|
||||||
@ -30,6 +31,7 @@ public:
|
|||||||
CObjectHandler * objh;
|
CObjectHandler * objh;
|
||||||
CMusicHandler * mush;
|
CMusicHandler * mush;
|
||||||
CSemiLodHandler * sspriteh;
|
CSemiLodHandler * sspriteh;
|
||||||
|
CDefObjInfoHandler * dobjinfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //CGAMEINFO_H
|
#endif //CGAMEINFO_H
|
12
CMT.cpp
12
CMT.cpp
@ -27,6 +27,7 @@
|
|||||||
#include "CSemiLodHandler.h"
|
#include "CSemiLodHandler.h"
|
||||||
#include "CLodHandler.h"
|
#include "CLodHandler.h"
|
||||||
#include "CDefHandler.h"
|
#include "CDefHandler.h"
|
||||||
|
#include "CDefObjInfoHandler.h"
|
||||||
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
|
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
|
||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
@ -280,10 +281,10 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||||||
//CLodHandler * bitmapLod = new CLodHandler;
|
//CLodHandler * bitmapLod = new CLodHandler;
|
||||||
//bitmapLod->init(std::string("newH3bitmap.lod"));
|
//bitmapLod->init(std::string("newH3bitmap.lod"));
|
||||||
|
|
||||||
CPCXConv * tconv = new CPCXConv;
|
//CPCXConv * tconv = new CPCXConv;
|
||||||
tconv->fromFile(std::string("newh3bitmap\\ADOPBPNL.PCX"));
|
//tconv->fromFile(std::string("newh3bitmap\\ADOPBPNL.PCX"));
|
||||||
tconv->convert();
|
//tconv->convert();
|
||||||
tconv->saveBMP(std::string("tesciczekConva.bmp"));
|
//tconv->saveBMP(std::string("tesciczekConva.bmp"));
|
||||||
|
|
||||||
CSemiDefHandler * semek = new CSemiDefHandler;
|
CSemiDefHandler * semek = new CSemiDefHandler;
|
||||||
semek->openDef(std::string("EDG.DEF"), std::string("H3sprite.lod"));
|
semek->openDef(std::string("EDG.DEF"), std::string("H3sprite.lod"));
|
||||||
@ -313,6 +314,9 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||||||
CObjectHandler * objh = new CObjectHandler;
|
CObjectHandler * objh = new CObjectHandler;
|
||||||
objh->loadObjects();
|
objh->loadObjects();
|
||||||
cgi->objh = objh;
|
cgi->objh = objh;
|
||||||
|
cgi->dobjinfo = new CDefObjInfoHandler;
|
||||||
|
cgi->dobjinfo->load();
|
||||||
|
|
||||||
std::string mapname;
|
std::string mapname;
|
||||||
//if (CPG) mapname = CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].filename;
|
//if (CPG) mapname = CPG->ourScenSel->mapsel.ourMaps[CPG->ourScenSel->mapsel.selected].filename;
|
||||||
//else mapname = "4gryf";
|
//else mapname = "4gryf";
|
||||||
|
10
map.cpp
10
map.cpp
@ -12,7 +12,15 @@ int readNormalNr (unsigned char * bufor, int pos, int bytCon = 4)
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
bool DefInfo::isVisitable()
|
||||||
|
{
|
||||||
|
for (int i=6; i<12; i++)
|
||||||
|
{
|
||||||
|
if (bytes[i])
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
CMapHeader::CMapHeader(unsigned char *map)
|
CMapHeader::CMapHeader(unsigned char *map)
|
||||||
{
|
{
|
||||||
this->version = (Eformat)map[0]; //wersja mapy
|
this->version = (Eformat)map[0]; //wersja mapy
|
||||||
|
1
map.h
1
map.h
@ -59,6 +59,7 @@ struct DefInfo //information from def declaration
|
|||||||
int bytes [42];
|
int bytes [42];
|
||||||
//CSemiDefHandler * handler;
|
//CSemiDefHandler * handler;
|
||||||
CDefHandler * handler;
|
CDefHandler * handler;
|
||||||
|
bool isVisitable();
|
||||||
};
|
};
|
||||||
struct Location
|
struct Location
|
||||||
{
|
{
|
||||||
|
@ -5,8 +5,40 @@
|
|||||||
#include "SDL_Extensions.h"
|
#include "SDL_Extensions.h"
|
||||||
#include "CGameInfo.h"
|
#include "CGameInfo.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
extern SDL_Surface * ekran;
|
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()
|
void CMapHandler::init()
|
||||||
{
|
{
|
||||||
fullHide = CGameInfo::mainObj->sspriteh->giveDef("TSHRC.DEF", 2);
|
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
|
////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)
|
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)
|
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);
|
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;
|
delete sr;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
////objects printed, printing shadow
|
////objects printed, printing shadow
|
||||||
for (int bx=0; bx<dx; bx++)
|
for (int bx=0; bx<dx; bx++)
|
||||||
{
|
{
|
||||||
|
11
mapHandler.h
11
mapHandler.h
@ -5,8 +5,15 @@
|
|||||||
#include "CSemiDefHandler.h"
|
#include "CSemiDefHandler.h"
|
||||||
#include "CGameInfo.h"
|
#include "CGameInfo.h"
|
||||||
|
|
||||||
const unsigned int Woff = 4; //width of map's frame
|
const int Woff = 4; //width of map's frame
|
||||||
const unsigned int Hoff = 4;
|
const int Hoff = 4;
|
||||||
|
|
||||||
|
struct ObjSorter
|
||||||
|
{
|
||||||
|
SDL_Surface * bitmap;
|
||||||
|
int xpos, ypos;
|
||||||
|
bool operator<(const ObjSorter & por) const;
|
||||||
|
};
|
||||||
|
|
||||||
class CMapHandler
|
class CMapHandler
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user