From 2e25e040d5a5646260fc98eaa03e93c5a9913b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Sat, 19 Jan 2008 11:55:04 +0000 Subject: [PATCH] Fixing buildings in castle and related improvements. --- CCastleInterface.cpp | 91 +++++++++++++++++++++++++++++++++---------- CCastleInterface.h | 16 ++++++-- config/buildings.txt | 2 +- config/buildings2.txt | 38 ++++++++++++++++++ hch/CAmbarCendamo.cpp | 12 ++++++ hch/CObjectHandler.h | 2 +- hch/CTownHandler.cpp | 41 +++++++++++++++++-- hch/CTownHandler.h | 4 +- 8 files changed, 177 insertions(+), 29 deletions(-) create mode 100644 config/buildings2.txt diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index 5794376ef..0d34c4aac 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -8,6 +8,57 @@ #include "hch/CTownHandler.h" #include "AdventureMapButton.h" #include + +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 *a , - const boost::tuples::tuple *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(CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,Activate); + exit = new AdventureMapButton + (CGI->townh->tcommands[8],"",&CCastleInterface::close,744,544,"TSBTNS.DEF",this,Activate); exit->bitmapOffset = 4; for (std::set::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 *t - = new boost::tuples::tuple - (*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 *t + // = new boost::tuples::tuple + // (*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;iget<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 >::const_iterator i=town->garrison.slots.begin();i!=town->garrison.slots.end();i++) + for( + std::map >::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;iget<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;iactivate(); } void CCastleInterface::deactivate() { diff --git a/CCastleInterface.h b/CCastleInterface.h index bf85ee5f2..745514e0d 100644 --- a/CCastleInterface.h +++ b/CCastleInterface.h @@ -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 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 * exit; - std::vector *> buildings; //building id, building def, structure struct, border, filling + std::vector buildings; //building id, building def, structure struct, border, filling CCastleInterface(const CGTownInstance * Town, bool Activate=true); ~CCastleInterface(); diff --git a/config/buildings.txt b/config/buildings.txt index b0a4c8911..ec31cfc0e 100644 --- a/config/buildings.txt +++ b/config/buildings.txt @@ -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 diff --git a/config/buildings2.txt b/config/buildings2.txt new file mode 100644 index 000000000..fd0793d32 --- /dev/null +++ b/config/buildings2.txt @@ -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. \ No newline at end of file diff --git a/hch/CAmbarCendamo.cpp b/hch/CAmbarCendamo.cpp index fbf649667..3f2b8b075 100644 --- a/hch/CAmbarCendamo.cpp +++ b/hch/CAmbarCendamo.cpp @@ -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<h3mbuildings.insert(byte*8+bit); + } + } + } } else { diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 936ee0074..6f47ecdff 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -431,7 +431,7 @@ public: int income; //TODO: - std::set possibleBuildings, builtBuildings; + std::set possibleBuildings, builtBuildings, h3mbuildings; std::vector creatureIncome; //vector by level std::vector creaturesLeft; //that can be recruited diff --git a/hch/CTownHandler.cpp b/hch/CTownHandler.cpp index 38d59fcf7..7bd5e8838 100644 --- a/hch/CTownHandler.cpp +++ b/hch/CTownHandler.cpp @@ -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 >::iterator i; + std::map::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 "<