From b29ac50dcbd319f93c93adc425dba3ae2cf0e0e1 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Mon, 21 Sep 2009 09:00:33 +0000 Subject: [PATCH] 1.Support for cage of Warlord, Temple of Valhalla, Wall of Knowledge, Order of Fire 2.Level-up from newly implemented School of War crashed the game. 3.A sketch of shops support --- client/GUIClasses.cpp | 24 ++++++++++++ client/GUIClasses.h | 21 +++++++++++ hch/CObjectHandler.cpp | 86 +++++++++++++++++++++++++++++++++++++----- hch/CObjectHandler.h | 43 +++++++++++++++++++-- lib/IGameCallback.h | 3 +- lib/NetPacks.h | 17 +++++++++ 6 files changed, 180 insertions(+), 14 deletions(-) diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index 48541a394..8c1dcc92a 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -4350,3 +4350,27 @@ void CPuzzleWindow::show(SDL_Surface * to) if(screen->w != 800 || screen->h !=600) CMessage::drawBorder(LOCPLINT->playerID,to,828,628,pos.x-14,pos.y-15); } + +bool CShopWindow::swapItem (ui16 which, bool choose) +{ + bool itemFound = false; + if (choose == true) //choose item + { + if (chosen.count(which)) + { + itemFound = true; + chosen[which] = avaliable[which]; + avaliable.erase(which); + } + } + else //return item to avaliable list + { + if (avaliable.count(which)) + { + itemFound = true; + avaliable[which] = chosen[which]; + chosen.erase(which); + } + } + return itemFound; +} \ No newline at end of file diff --git a/client/GUIClasses.h b/client/GUIClasses.h index 20eaa520a..e4204e584 100644 --- a/client/GUIClasses.h +++ b/client/GUIClasses.h @@ -762,4 +762,25 @@ public: ~CPuzzleWindow(); }; +class CShopWindow : public CIntObject +{ +public: + std::map avaliable, chosen, bought; + + bool swapItem (ui16 which, bool choose); +}; +class CArtMerchantWindow : public CShopWindow +{}; +class CUniversityWindow : public CShopWindow +{}; +class CAltarWindow : public CShopWindow +{}; +class CRefugeeCampWindow : public CShopWindow +{}; +class CWarMachineWindow : public CShopWindow +{}; +class CFreelancersWindow : public CShopWindow +{}; +class CHillFortWindow : public CIntObject //garrison dialog? shop? +{}; #endif //__GUICLASSES_H__ diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 4e42bc56c..5756ba11e 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -1392,6 +1392,16 @@ int CGTownInstance::getSightRadious() const //returns sight distance return 5; } +void CGTownInstance::setPropertyDer(ui8 what, ui32 val) +{ +///this is freakin' overcomplicated solution + switch (what) + { + case 11: //add visitor of town building + bonusingBuildings[val]->setProperty (4, visitingHero->id); + break; + } +} int CGTownInstance::fortLevel() const //0 - none, 1 - fort, 2 - citadel, 3 - castle { if((builtBuildings.find(9))!=builtBuildings.end()) @@ -1542,9 +1552,9 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const cb->setOwner(id, h->tempOwner); } } - for (std::vector::const_iterator i = bonusingBuildings.begin(); i != bonusingBuildings.end(); i++) - (*i)->onHeroVisit (h); //does not work cb->heroVisitCastle(id, h->id); + for (std::vector::const_iterator i = bonusingBuildings.begin(); i != bonusingBuildings.end(); i++) + (*i)->onHeroVisit (h); //put it inside heroVisitCastle call, make sure *visitingHero is set } void CGTownInstance::onHeroLeave(const CGHeroInstance * h) const @@ -1564,13 +1574,13 @@ void CGTownInstance::initObj() if(creatureDwelling(i,true)) creatures[i].second.push_back(town->upgradedCreatures[i]); } - switch (alignment) + switch (subID) { //add new visitable objects case 2: case 3: case 5: case 6: - bonusingBuildings.push_back(new CTownBonus(23, this)); + bonusingBuildings.push_back (new CTownBonus(23, this)); break; case 7: - bonusingBuildings.push_back(new CTownBonus(17, this)); + bonusingBuildings.push_back (new CTownBonus(17, this)); break; } } @@ -1923,6 +1933,12 @@ CTownBonus::CTownBonus (int index, CGTownInstance *TOWN) { ID = index; town = TOWN; + id = town->bonusingBuildings.size(); +} +void CTownBonus::setProperty (ui8 what, ui32 val) +{ + if(what == 4) + visitors.insert(val); } void CTownBonus::onHeroVisit (const CGHeroInstance * h) const { @@ -1933,7 +1949,7 @@ void CTownBonus::onHeroVisit (const CGHeroInstance * h) const switch (ID) { case 23: - switch(town->alignment) + switch(town->subID) { case 2: //wall cb->changePrimSkill (heroID, 3, 1); @@ -1954,7 +1970,7 @@ void CTownBonus::onHeroVisit (const CGHeroInstance * h) const } break; case 17: - switch(town->alignment) + switch(town->subID) { case 7: //cage of warlords cb->changePrimSkill (heroID, 1, 1); @@ -1964,10 +1980,10 @@ void CTownBonus::onHeroVisit (const CGHeroInstance * h) const break; } iw.player = cb->getOwner(heroID); - iw.text << std::pair(11,66); + iw.text << VLC->generaltexth->buildings[town->subID][ID].second; //iw.soundID = sound; cb->showInfoDialog(&iw); - cb->setObjProperty (id, 4, h->id); //add to visitors + cb->setObjProperty (town->id, 11, id); //add to visitors } } bool CArmedInstance::needsLastStack() const @@ -4540,3 +4556,55 @@ void CCartographer::buyMap (const CGHeroInstance *h, ui32 accept) const cb->setObjProperty (id, 10, h->tempOwner); } } + +void CShop::setPropertyDer (ui8 what, ui32 val) +{ + switch (what) + { + case 13: //sweep + avaliable.clear(); + chosen.clear(); + bought.clear(); + break; + case 14: //reset - get new items + reset(val); + break; + } +} +void CGArtMerchant::reset(ui32 val) +{ + std::vector::iterator index; + for (ui8 i = 0; i <= 6; i++) + { + int count = 0; + std::vector arts; //to avoid addition of different tiers + switch (i) + { + case 0: + cb->getAllowed (arts, CArtifact::ART_TREASURE); + count = 2; + break; + case 1: + cb->getAllowed (arts, CArtifact::ART_MINOR); + count = 2; + break; + case 2: + cb->getAllowed (arts, CArtifact::ART_MAJOR); + count = 1; + break; + case 3: + cb->getAllowed (arts, CArtifact::ART_RELIC); + count = 1; + break; + } + for (ui8 n = 0; n < count; n++) + { + + index = arts.begin() + val % arts.size(); + avaliable [avaliable.size()] = new Component (Component::ARTIFACT, (*index)->id, 0, 0); + arts.erase(index); + val *= (id + n * i); //randomize + } + } + +} \ No newline at end of file diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 0c2f11988..a9baba575 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -42,6 +42,7 @@ class CGDefInfo; class CSpecObjInfo; struct TerrainTile; struct InfoWindow; +struct Component; struct BankConfig; class CGBoat; @@ -355,25 +356,33 @@ public: h & visitors & ttype; } }; -class DLL_EXPORT CGTownBuilding : IObjectInterface +class DLL_EXPORT CGTownBuilding : public IObjectInterface { ///basic class for town structures handled as map objects public: + si32 ID; //from buildig list + si32 id; //identifies its index on towns vector CGTownInstance *town; - virtual void onHeroVisit (const CGHeroInstance * h) const {}; + template void serialize(Handler &h, const int version) + { + h & ID & id; + } }; -class DLL_EXPORT CTownBonus : public CGVisitableOPH, public CGTownBuilding +class DLL_EXPORT CTownBonus : public CGTownBuilding { ///used for one-time bonusing structures +///feel free to merge inheritance tree public: + std::set visitors; + void setProperty(ui8 what, ui32 val); void onHeroVisit (const CGHeroInstance * h) const; CTownBonus (int index, CGTownInstance *TOWN); CTownBonus (){ID = 0; town = NULL;}; template void serialize(Handler &h, const int version) { - h & static_cast(*this); + h & static_cast(*this); h & visitors; } }; @@ -417,6 +426,7 @@ public: int3 getSightCenter() const; //"center" tile from which the sight distance is calculated int getSightRadious() const; //returns sight distance void getOutOffsets(std::vector &offsets) const; //offsets to obj pos when we boat can be placed + void setPropertyDer(ui8 what, ui32 val); ////////////////////////////////////////////////////////////////////////// @@ -927,6 +937,31 @@ public: }; +class DLL_EXPORT CShop : public CGObjectInstance +{ +///base class for university, art merchant, slave market etc. +public: + std::map avaliable; + std::map chosen, bought; //redundant? + //keys are unique for all three maps + std::map price; + + void initObj() {}; + void setPropertyDer (ui8 what, ui32 val); + void newTurn() const {}; + virtual void reset (ui32 val) {}; + void onHeroVisit (const CGHeroInstance * h) const {}; + virtual void trade (const CGHeroInstance * h) const {}; + + template void serialize(Handler &h, const int version) + { + h & avaliable & chosen & bought & price; + } +}; +class DLL_EXPORT CGArtMerchant : public CShop +{ + void reset (ui32 val); +}; struct BankConfig { BankConfig() {level = chance = upgradeChance = combatValue = value = rewardDifficulty = easiest = 0; }; diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index 698f24424..e6d1c1cc4 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -26,6 +26,7 @@ struct InfoWindow; struct MetaString; struct ShowInInfobox; struct BattleResult; +struct Component; class CGameState; struct PlayerSettings; struct CPackForClient; @@ -94,7 +95,7 @@ public: virtual void sendAndApply(CPackForClient * info)=0; virtual void heroExchange(si32 hero1, si32 hero2)=0; //when two heroes meet on adventure map - + friend struct CPack; friend struct CPackForClient; friend struct CPackForServer; }; diff --git a/lib/NetPacks.h b/lib/NetPacks.h index d53fcb7e1..bb6f5f777 100644 --- a/lib/NetPacks.h +++ b/lib/NetPacks.h @@ -673,6 +673,22 @@ struct HeroLevelUp : public Query//2000 } }; +struct TradeComponents : public CPackForClient, public CPackForServer +{ +///used to handle info about components avaliable in shops + void applyCl(CClient *cl); + DLL_EXPORT void applyGs(CGameState *gs); + + si32 heroid; + ui32 objectid; + std::map avaliable, chosen, bought; + + template void serialize(Handler &h, const int version) + { + h & id & heroid & objectid & avaliable & chosen & bought; + } + +}; //A dialog that requires making decision by player - it may contain components to choose between or has yes/no options //Client responds with QueryReply, where answer: 0 - cancel pressed, choice doesn't matter; 1/2/... - first/second/... component selected and OK pressed //Until sending reply player won't be allowed to take any actions @@ -1042,6 +1058,7 @@ struct ShowInInfobox : public CPackForClient //107 } }; + /***********************************************************************************************************/ struct CloseServer : public CPackForServer