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

* improvements in the town view

This commit is contained in:
Michał W. Urbańczyk 2008-01-27 13:18:18 +00:00
parent 70bf415eb6
commit 19c1fee418
4 changed files with 124 additions and 36 deletions

View File

@ -157,14 +157,52 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
exit = new AdventureMapButton<CCastleInterface>
(CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,false);
exit->bitmapOffset = 4;
std::set< std::pair<int,int> > s; //group - id
for (std::set<int>::const_iterator i=town->builtBuildings.begin();i!=town->builtBuildings.end();i++)
{
if(CGI->townh->structures.find(town->subID) != CGI->townh->structures.end())
if(CGI->townh->structures.find(town->subID) != CGI->townh->structures.end()) //we have info about structures in this town
{
if(CGI->townh->structures[town->subID].find(*i)!=CGI->townh->structures[town->subID].end())
if(CGI->townh->structures[town->subID].find(*i)!=CGI->townh->structures[town->subID].end()) //we have info about that structure
{
buildings.push_back(new CBuildingRect(CGI->townh->structures[town->subID][*i]));
Structure * st = CGI->townh->structures[town->subID][*i];
if(st->group<0) //no group - just add it
{
buildings.push_back(new CBuildingRect(st));
}
else
{
std::set< std::pair<int,int> >::iterator obecny=s.end();
for(std::set< std::pair<int,int> >::iterator seti = s.begin(); seti!=s.end(); seti++) //check if we have already building from same group
{
if(seti->first == st->group)
{
obecny = seti;
break;
}
}
if(obecny != s.end())
{
if(obecny->second < st->ID) //we have to replace old building with current one
{
for(int itpb = 0; itpb<buildings.size(); itpb++)
{
if(buildings[itpb]->str->ID == obecny->second)
{
buildings.erase(buildings.begin() + itpb);
obecny->second = st->ID;
buildings.push_back(new CBuildingRect(st));
}
}
}
}
else
{
buildings.push_back(new CBuildingRect(st));
s.insert(std::pair<int,int>(st->group,st->ID));
}
}
}
else continue;
}

View File

@ -14,6 +14,11 @@ CASTLE 0
30
37
16
6
18
19
34
41
END
EOD

View File

@ -50,6 +50,7 @@ void CTownHandler::loadNames()
while(!of.eof())
{
Structure *vinya = new Structure;
vinya->group = -1;
of >> vinya->townID;
of >> vinya->ID;
of >> vinya->defName;
@ -94,6 +95,7 @@ void CTownHandler::loadNames()
of.close();
of.clear();
//read borders and areas names
of.open("config/buildings3.txt");
while(!of.eof())
{
@ -118,37 +120,80 @@ void CTownHandler::loadNames()
of.close();
of.clear();
//of.open("config/buildings4.txt");
//of >> format;
//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 << "Warning1: No building "<<buildingID<<" in the castle "<<castleID<<std::endl;
// else
// std::cout << "Warning1: Castle "<<castleID<<" not defined."<<std::endl;
// }
//}
//of.close();
//of.clear();
//read groups
itr = 0;
of.open("config/buildings4.txt");
of >> format;
if(format!=1)
{
std::cout << "Unhandled format of buildings4.txt \n";
}
else
{
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")
{
of >> castleID;
}
else if(s == "ALL")
{
castleID = -1;
}
else
{
break;
}
of >> s;
while(1) //read groups for castle
{
if (s == "GROUP")
{
while(1)
{
of >> s;
if((s == "GROUP") || (s == "EOD")) //
break;
buildingID = atoi(s.c_str());
if(castleID>=0)
{
if((i=structures.find(castleID))!=structures.end())
if((i2=(i->second.find(buildingID)))!=(i->second.end()))
i2->second->group = itr;
else
std::cout << "Warning3: No building "<<buildingID<<" in the castle "<<castleID<<std::endl;
else
std::cout << "Warning3: Castle "<<castleID<<" not defined."<<std::endl;
}
else //set group for selected building in ALL castles
{
for(i=structures.begin();i!=structures.end();i++)
{
for(i2=i->second.begin(); i2!=i->second.end(); i2++)
{
if(i2->first == buildingID)
{
i2->second->group = itr;
break;
}
}
}
}
}
itr++;
}//if (s == "GROUP")
else if(s == "EOD")
break;
}
}
of.close();
of.clear();
}
}
SDL_Surface * CTownHandler::getPic(int ID, bool fort, bool builded)
{

View File

@ -28,7 +28,7 @@ struct Structure
int ID;
int3 pos;
std::string defName, borderName, areaName;
int townID;
int townID, group;
};
class CTownHandler
@ -43,7 +43,7 @@ public:
SDL_Surface * getPic(int ID, bool fort=true, bool builded=false); //ID=-1 - blank; -2 - border; -3 - random
static int getTypeByDefName(std::string name);
std::map<int,std::map<int, Structure*> > structures;
std::map<int,std::map<int, Structure*> > structures; // <town ID, <structure ID, structure>>
std::vector<CGTownInstance *> townInstances;