mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Fixing buildings in castle and related improvements.
This commit is contained in:
parent
4b772315bb
commit
2e25e040d5
@ -8,6 +8,57 @@
|
||||
#include "hch/CTownHandler.h"
|
||||
#include "AdventureMapButton.h"
|
||||
#include <sstream>
|
||||
|
||||
CBuildingRect::CBuildingRect(Structure *Str)
|
||||
:str(Str)
|
||||
{
|
||||
def = CGI->spriteh->giveDef(Str->defName);
|
||||
border = area = NULL;
|
||||
pos.x = str->pos.x;
|
||||
pos.y = str->pos.y;
|
||||
pos.w = def->ourImages[0].bitmap->w;
|
||||
pos.h = def->ourImages[0].bitmap->h;
|
||||
}
|
||||
|
||||
CBuildingRect::~CBuildingRect()
|
||||
{
|
||||
delete def;
|
||||
if(border)
|
||||
SDL_FreeSurface(border);
|
||||
if(area)
|
||||
SDL_FreeSurface(area);
|
||||
}
|
||||
void CBuildingRect::activate()
|
||||
{
|
||||
MotionInterested::activate();
|
||||
ClickableL::activate();
|
||||
ClickableR::activate();
|
||||
}
|
||||
void CBuildingRect::deactivate()
|
||||
{
|
||||
MotionInterested::deactivate();
|
||||
ClickableL::deactivate();
|
||||
ClickableR::deactivate();
|
||||
}
|
||||
bool CBuildingRect::operator<(const CBuildingRect & p2) const
|
||||
{
|
||||
if(str->pos.z != p2.str->pos.z)
|
||||
return (str->pos.z) < (p2.str->pos.z);
|
||||
else
|
||||
return (str->ID) < (p2.str->ID);
|
||||
}
|
||||
void CBuildingRect::mouseMoved (SDL_MouseMotionEvent & sEvent)
|
||||
{
|
||||
//todo - handle
|
||||
}
|
||||
void CBuildingRect::clickLeft (tribool down)
|
||||
{
|
||||
//todo - handle
|
||||
}
|
||||
void CBuildingRect::clickRight (tribool down)
|
||||
{
|
||||
//todo - handle
|
||||
}
|
||||
std::string getBgName(int type) //TODO - co z tym zrobiæ?
|
||||
{
|
||||
switch (type)
|
||||
@ -38,10 +89,10 @@ class SORTHELP
|
||||
{
|
||||
public:
|
||||
bool operator ()
|
||||
(const boost::tuples::tuple<int,CDefHandler*,Structure*,SDL_Surface*,SDL_Surface*> *a ,
|
||||
const boost::tuples::tuple<int,CDefHandler*,Structure*,SDL_Surface*,SDL_Surface*> *b)
|
||||
(const CBuildingRect *a ,
|
||||
const CBuildingRect *b)
|
||||
{
|
||||
return (a->get<0>())<(b->get<0>());
|
||||
return (*a)<(*b);
|
||||
}
|
||||
} srthlp ;
|
||||
|
||||
@ -55,7 +106,8 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
|
||||
bigTownPic = CGI->spriteh->giveDef("ITPT.DEF");
|
||||
flag = CGI->spriteh->giveDef("CREST58.DEF");
|
||||
CSDL_Ext::blueToPlayersAdv(townInt,LOCPLINT->playerID);
|
||||
exit = new AdventureMapButton<CCastleInterface>(CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,Activate);
|
||||
exit = new AdventureMapButton<CCastleInterface>
|
||||
(CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,Activate);
|
||||
exit->bitmapOffset = 4;
|
||||
|
||||
for (std::set<int>::const_iterator i=town->builtBuildings.begin();i!=town->builtBuildings.end();i++)
|
||||
@ -64,12 +116,13 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
|
||||
{
|
||||
if(CGI->townh->structures[town->subID].find(*i)!=CGI->townh->structures[town->subID].end())
|
||||
{
|
||||
CDefHandler *b = CGI->spriteh->giveDef(CGI->townh->structures[town->subID][*i]->defName);
|
||||
boost::tuples::tuple<int,CDefHandler*,Structure*,SDL_Surface*,SDL_Surface*> *t
|
||||
= new boost::tuples::tuple<int,CDefHandler*,Structure*,SDL_Surface*,SDL_Surface*>
|
||||
(*i,b,CGI->townh->structures[town->subID][*i],NULL,NULL);
|
||||
//TODO: obwódki i pola
|
||||
buildings.push_back(t);
|
||||
//CDefHandler *b = CGI->spriteh->giveDef(CGI->townh->structures[town->subID][*i]->defName);
|
||||
buildings.push_back(new CBuildingRect(CGI->townh->structures[town->subID][*i]));
|
||||
//boost::tuples::tuple<int,CDefHandler*,Structure*,SDL_Surface*,SDL_Surface*> *t
|
||||
// = new boost::tuples::tuple<int,CDefHandler*,Structure*,SDL_Surface*,SDL_Surface*>
|
||||
// (*i,b,CGI->townh->structures[town->subID][*i],NULL,NULL);
|
||||
////TODO: obwódki i pola
|
||||
//buildings.push_back(t);
|
||||
}
|
||||
else continue;
|
||||
}
|
||||
@ -97,14 +150,6 @@ CCastleInterface::~CCastleInterface()
|
||||
|
||||
for(int i=0;i<buildings.size();i++)
|
||||
{
|
||||
if (buildings[i]->get<1>())
|
||||
delete (buildings[i]->get<1>());
|
||||
//if (buildings[i]->get<2>())
|
||||
// delete (buildings[i]->get<2>());
|
||||
if (buildings[i]->get<3>())
|
||||
SDL_FreeSurface(buildings[i]->get<3>());
|
||||
if (buildings[i]->get<4>())
|
||||
SDL_FreeSurface(buildings[i]->get<4>());
|
||||
delete buildings[i];
|
||||
}
|
||||
|
||||
@ -185,7 +230,11 @@ void CCastleInterface::show()
|
||||
//flag
|
||||
blitAt(flag->ourImages[town->getOwner()].bitmap,241,387);
|
||||
//print garrison
|
||||
for(std::map<int,std::pair<CCreature*,int> >::const_iterator i=town->garrison.slots.begin();i!=town->garrison.slots.end();i++)
|
||||
for(
|
||||
std::map<int,std::pair<CCreature*,int> >::const_iterator i=town->garrison.slots.begin();
|
||||
i!=town->garrison.slots.end();
|
||||
i++
|
||||
)
|
||||
{
|
||||
blitAt(CGI->creh->bigImgs[i->second.first->idNumber],305+(62*(i->first)),387);
|
||||
itoa(i->second.second,temp,10);
|
||||
@ -195,12 +244,14 @@ void CCastleInterface::show()
|
||||
//blit buildings
|
||||
for(int i=0;i<buildings.size();i++)
|
||||
{
|
||||
blitAt(buildings[i]->get<1>()->ourImages[0].bitmap,buildings[i]->get<2>()->x,buildings[i]->get<2>()->y);
|
||||
blitAt(buildings[i]->def->ourImages[0].bitmap,buildings[i]->pos.x,buildings[i]->pos.y);
|
||||
}
|
||||
|
||||
}
|
||||
void CCastleInterface::activate()
|
||||
{
|
||||
//for(int i=0;i<buildings.size();i++)
|
||||
// buildings[i]->activate();
|
||||
}
|
||||
void CCastleInterface::deactivate()
|
||||
{
|
||||
|
@ -2,16 +2,26 @@
|
||||
#include "global.h"
|
||||
#include "SDL.h"
|
||||
#include "CPlayerInterface.h"
|
||||
#include "boost/tuple/tuple.hpp"
|
||||
//#include "boost/tuple/tuple.hpp"
|
||||
class CGTownInstance;
|
||||
class CTownHandler;
|
||||
struct Structure;
|
||||
template <typename T> class AdventureMapButton;
|
||||
class CBuildingRect : public MotionInterested, public ClickableL, public ClickableR//, public TimeInterested
|
||||
{
|
||||
|
||||
public:
|
||||
Structure* str;
|
||||
CDefHandler* def;
|
||||
SDL_Surface* border;
|
||||
SDL_Surface* area;
|
||||
CBuildingRect(Structure *Str);
|
||||
~CBuildingRect();
|
||||
void activate();
|
||||
void deactivate();
|
||||
bool operator<(const CBuildingRect & p2) const;
|
||||
void mouseMoved (SDL_MouseMotionEvent & sEvent);
|
||||
void clickLeft (tribool down);
|
||||
void clickRight (tribool down);
|
||||
};
|
||||
|
||||
class CCastleInterface
|
||||
@ -26,7 +36,7 @@ public:
|
||||
|
||||
AdventureMapButton<CCastleInterface> * exit;
|
||||
|
||||
std::vector<boost::tuples::tuple<int,CDefHandler*,Structure*,SDL_Surface*,SDL_Surface*> *> buildings; //building id, building def, structure struct, border, filling
|
||||
std::vector<CBuildingRect*> buildings; //building id, building def, structure struct, border, filling
|
||||
|
||||
CCastleInterface(const CGTownInstance * Town, bool Activate=true);
|
||||
~CCastleInterface();
|
||||
|
@ -5,7 +5,7 @@
|
||||
0 6 TBCSDOCK.def 478 134
|
||||
0 30 TBCSDW_0.def 304 92
|
||||
0 31 TBCSDW_1.def 360 130
|
||||
0 32 TBCSDW_2.def 363 130
|
||||
0 32 TBCSDW_2.def 76 57
|
||||
0 33 TBCSDW_3.def 176 101
|
||||
0 34 TBCSDW_4.def 563 211
|
||||
0 35 TBCSDW_5.def 174 190
|
||||
|
38
config/buildings2.txt
Normal file
38
config/buildings2.txt
Normal file
@ -0,0 +1,38 @@
|
||||
0 0
|
||||
CASTLE 0
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
5
|
||||
22
|
||||
30
|
||||
37
|
||||
END
|
||||
EOD
|
||||
|
||||
------------------------------------------------------------------
|
||||
|
||||
//File format:
|
||||
|
||||
0 0 //for further use - format version and ID mode
|
||||
|
||||
|
||||
CASTLE [Castle ID]
|
||||
[ID] //Building showed on the top (blitted later)
|
||||
[ID] //Building showed later...
|
||||
...
|
||||
[ID] //even later...
|
||||
END //end of buildings for this castle
|
||||
|
||||
|
||||
[...] //info for more castles
|
||||
|
||||
EOD
|
||||
|
||||
Buildings not mentioned in the file will be blitted as first. File can contain data for any count of castles.
|
@ -1794,6 +1794,18 @@ void CAmbarCendamo::deh3m()
|
||||
}//else if (ir==5)
|
||||
}
|
||||
}
|
||||
|
||||
//testowe zczytywanie h3mowych ID
|
||||
for(int byte=0;byte<6;byte++)
|
||||
{
|
||||
for(int bit=0;bit<8;bit++)
|
||||
{
|
||||
if(spec->buildingSettings[byte] & (1<<bit))
|
||||
{
|
||||
nt->h3mbuildings.insert(byte*8+bit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -431,7 +431,7 @@ public:
|
||||
int income;
|
||||
|
||||
//TODO:
|
||||
std::set<int> possibleBuildings, builtBuildings;
|
||||
std::set<int> possibleBuildings, builtBuildings, h3mbuildings;
|
||||
std::vector<int> creatureIncome; //vector by level
|
||||
std::vector<int> creaturesLeft; //that can be recruited
|
||||
|
||||
|
@ -45,7 +45,7 @@ void CTownHandler::loadNames()
|
||||
tcommands.push_back(tmp);
|
||||
}
|
||||
|
||||
|
||||
//read buildings coords
|
||||
std::ifstream of("config/buildings.txt");
|
||||
while(!of.eof())
|
||||
{
|
||||
@ -53,10 +53,45 @@ void CTownHandler::loadNames()
|
||||
of >> vinya->townID;
|
||||
of >> vinya->ID;
|
||||
of >> vinya->defName;
|
||||
of >> vinya->x;
|
||||
of >> vinya->y;
|
||||
of >> vinya->pos.x;
|
||||
of >> vinya->pos.y;
|
||||
vinya->pos.z = 0;
|
||||
structures[vinya->townID][vinya->ID] = vinya;
|
||||
}
|
||||
of.close();
|
||||
of.clear();
|
||||
|
||||
//read building priorities
|
||||
of.open("config/buildings2.txt");
|
||||
int format, idt;
|
||||
std::string s;
|
||||
of >> format >> idt;
|
||||
while(!of.eof())
|
||||
{
|
||||
std::map<int,std::map<int, Structure*> >::iterator i;
|
||||
std::map<int, Structure*>::iterator i2;
|
||||
int itr=1, buildingID;
|
||||
int castleID;
|
||||
of >> s;
|
||||
if (s != "CASTLE")
|
||||
break;
|
||||
of >> castleID;
|
||||
while(1)
|
||||
{
|
||||
of >> s;
|
||||
if (s == "END")
|
||||
break;
|
||||
else
|
||||
if((i=structures.find(castleID))!=structures.end())
|
||||
if((i2=(i->second.find(buildingID=atoi(s.c_str()))))!=(i->second.end()))
|
||||
i2->second->pos.z=itr++;
|
||||
else
|
||||
std::cout << "Warning: No building "<<buildingID<<" in the castle "<<castleID<<std::endl;
|
||||
else
|
||||
std::cout << "Warning: Castle "<<castleID<<" not defined."<<std::endl;
|
||||
}
|
||||
}
|
||||
of.close();
|
||||
|
||||
}
|
||||
SDL_Surface * CTownHandler::getPic(int ID, bool fort, bool builded)
|
||||
|
@ -25,8 +25,10 @@ public:
|
||||
|
||||
struct Structure
|
||||
{
|
||||
int ID;
|
||||
int3 pos;
|
||||
std::string defName;
|
||||
int ID, townID, x, y;
|
||||
int townID;
|
||||
};
|
||||
|
||||
class CTownHandler
|
||||
|
Loading…
Reference in New Issue
Block a user