From e4fcfd70445313134ce24a1efc7d1ca6493a55f3 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 3 Jul 2010 12:00:53 +0000 Subject: [PATCH] - Skeleton transformer implemented --- client/CCastleInterface.cpp | 13 ++++- client/CCastleInterface.h | 1 + client/GUIClasses.cpp | 96 +++++++++++++++++++++++++++++++++++++ client/GUIClasses.h | 32 +++++++++++++ global.h | 3 +- hch/CObjectHandler.cpp | 2 + server/CGameHandler.cpp | 30 ++++++++++++ server/CGameHandler.h | 1 + server/NetPacksServer.cpp | 2 + 9 files changed, 177 insertions(+), 3 deletions(-) diff --git a/client/CCastleInterface.cpp b/client/CCastleInterface.cpp index 73043765d..41a6e577c 100644 --- a/client/CCastleInterface.cpp +++ b/client/CCastleInterface.cpp @@ -742,8 +742,17 @@ void CCastleInterface::buildingClicked(int building) break; } /*Necropolis*/ case 4: //Skeleton Transformer - tlog4<<"Skeleton Transformer not handled\n"; - break; + const CGHeroInstance *hero; + if (town->visitingHero) + hero = town->visitingHero; + else if (town->garrisonHero) + hero = town->garrisonHero; + else + hero = NULL;//no hero - will trade with town garrison + + GH.pushInt ( new CTransformerWindow(hero, town) ); + break; + /*Dungeon*/ case 5: //Portal of Summoning tlog4<<"Portal of Summoning not handled\n"; break; diff --git a/client/CCastleInterface.h b/client/CCastleInterface.h index c2f041172..7fb26b9b8 100644 --- a/client/CCastleInterface.h +++ b/client/CCastleInterface.h @@ -18,6 +18,7 @@ class CResDataBar; class CStatusBar; class CTownList; class CRecruitmentWindow; +class CTransformerWindow; class CCreaturePic; class CMinorResDataBar; diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index 0d193f504..7471c183f 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -5219,6 +5219,102 @@ void CPuzzleWindow::show(SDL_Surface * to) CMessage::drawBorder(LOCPLINT->playerID,to,828,628,pos.x-14,pos.y-15); } +void CTransformerWindow::CItem::showAll(SDL_Surface * to) +{ + SDL_Surface * backgr = graphics->bigImgs[parent->army->getCreature(id)->idNumber]; + blitAt(backgr, pos.x, pos.y, to); + printAtMiddle(boost::lexical_cast(size),pos.x+28, pos.y+76,FONT_SMALL,zwykly,to);//stack size +} + +void CTransformerWindow::CItem::move() +{ + if (left) + pos.x += 289; + else + pos.x -= 289; + left = !left; +} + +void CTransformerWindow::CItem::clickLeft(tribool down, bool previousState) +{ + if(previousState && (!down)) + { + move(); + parent->showAll(screen2); + } +} + +CTransformerWindow::CItem::CItem(CTransformerWindow * _parent, int _size, int _id): + parent(_parent), id(_id), size(_size) +{ + used = LCLICK; + left=true; + pos.w = 58; + pos.h = 64; + + pos.x += 45 + (id%3)*83 + id/6*83; + pos.y += 109 + (id/3)*98; +} + +CTransformerWindow::CItem::~CItem() +{ + +} + +void CTransformerWindow::showAll(SDL_Surface * to) +{ + CIntObject::showAll(to); + printAtMiddleLoc( CGI->generaltexth->allTexts[485], 153, 29,FONT_SMALL, tytulowy,to);//holding area + printAtMiddleLoc( CGI->generaltexth->allTexts[486], 153+295, 29,FONT_SMALL, tytulowy,to);//transformer + printAtMiddleWBLoc(CGI->generaltexth->allTexts[487], 153, 75,FONT_MEDIUM, 32,tytulowy,to);//move creatures to create skeletons + printAtMiddleWBLoc(CGI->generaltexth->allTexts[488], 153+295, 75,FONT_MEDIUM, 32,tytulowy,to);//creatures here will become skeletons +} + +void CTransformerWindow::makeDeal() +{ + for (int i=0; ileft) + LOCPLINT->cb->trade(town, CREATURE_UNDEAD, items[i]->id, 0, 0, hero); +} + +void CTransformerWindow::addAll() +{ + for (int i=0; ileft) + items[i]->move(); + showAll(screen2); +} + +CTransformerWindow::CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town):hero(_hero),town(_town) +{ + OBJ_CONSTRUCTION_CAPTURING_ALL; + used = LCLICK; + pos.x = screen->w/2 - 300; + pos.y = screen->h/2 - 242; + bg = new CPicture ("SKTRNBK.PCX"); + bg->colorizeAndConvert(LOCPLINT->playerID); + pos.w = bg->bg->w; + pos.h = bg->bg->h; + + if (hero) + army = hero; + else + army = town; + + for (int i=0; i<7; i++ ) + if ( army->getCreature(i) ) + items.push_back(new CItem(this, army->getAmount(i), i)); + + all = new AdventureMapButton(CGI->generaltexth->zelp[590],boost::bind(&CTransformerWindow::addAll,this), 146,416,"ALTARMY.DEF",SDLK_a); + convert= new AdventureMapButton(CGI->generaltexth->zelp[591],boost::bind(&CTransformerWindow::makeDeal,this), 269,416,"ALTSACR.DEF",SDLK_RETURN); + cancel = new AdventureMapButton(CGI->generaltexth->zelp[592],boost::bind(&CGuiHandler::popIntTotally,&GH, this),392,416,"ICANCEL.DEF",SDLK_ESCAPE); +} + +CTransformerWindow::~CTransformerWindow() +{ + +} + bool CShopWindow::swapItem (ui16 which, bool choose) { bool itemFound = false; diff --git a/client/GUIClasses.h b/client/GUIClasses.h index 94f4bbb64..c003bfdc3 100644 --- a/client/GUIClasses.h +++ b/client/GUIClasses.h @@ -956,6 +956,38 @@ public: ~CPuzzleWindow(); }; +class CTransformerWindow : public CIntObject +{ +public: + class CItem : public CIntObject + { + public: + int id;//position of creature in hero army + bool left;//position of the item + int size; //size of creature stack + CTransformerWindow * parent; + + void move(); + void showAll(SDL_Surface * to); + void clickLeft(tribool down, bool previousState); + CItem(CTransformerWindow * _parent, int _size, int _id); + ~CItem(); + }; + + const CArmedInstance *army;//object with army for transforming (hero or town) + const CGHeroInstance *hero;//only if we have hero in town + const CGTownInstance *town;//market, town garrison is used if hero == NULL + CPicture *bg; //background + std::vector items; + + AdventureMapButton *all, *convert, *cancel; + void showAll(SDL_Surface * to); + void makeDeal(); + void addAll(); + CTransformerWindow(const CGHeroInstance * _hero, const CGTownInstance * _town); //c-tor + ~CTransformerWindow(); //d-tor +}; + class CShopWindow : public CIntObject { public: diff --git a/global.h b/global.h index 4b2e2087e..3465955bb 100644 --- a/global.h +++ b/global.h @@ -109,7 +109,8 @@ const int WEEKLY_GROWTH = 10; //percent enum EMarketMode { - RESOURCE_RESOURCE, RESOURCE_PLAYER, CREATURE_RESOURCE, RESOURCE_ARTIFACT, ARTIFACT_RESOURCE, ARTIFACT_EXP, CREATURE_EXP, + RESOURCE_RESOURCE, RESOURCE_PLAYER, CREATURE_RESOURCE, RESOURCE_ARTIFACT, + ARTIFACT_RESOURCE, ARTIFACT_EXP, CREATURE_EXP, CREATURE_UNDEAD, MARTKET_AFTER_LAST_PLACEHOLDER }; diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 3ac0b97dc..f17554542 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -1954,6 +1954,8 @@ bool CGTownInstance::allowsTrade(EMarketMode mode) const return (subID == 2 || subID == 5 || subID == 8) && vstd::contains(builtBuildings, 17);//artifact merchants case CREATURE_RESOURCE: return subID == 6 && vstd::contains(builtBuildings, 21); //Freelancer's guild + case CREATURE_UNDEAD: + return subID == 4 && vstd::contains(builtBuildings, 22);//Skeleton transformer default: assert(0); return false; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index c686d1248..70f83e274 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -3185,6 +3185,36 @@ bool CGameHandler::sellCreatures(ui32 count, const IMarket *market, const CGHero return true; } +bool CGameHandler::transformInUndead(const IMarket *market, const CGHeroInstance * hero, ui32 slot) +{ + const CArmedInstance *army = NULL; + if (hero) + army = hero; + else + { + army = dynamic_cast(market->o); + } + if (!army) + COMPLAIN_RET("Incorrect call to transform in undead!"); + tlog1<<"test2\n"; + if(!vstd::contains(army->Slots(), slot)) + COMPLAIN_RET("Army doesn't have any creature in that slot!"); + tlog1<<"test3\n"; + const CStackInstance &s = army->getStack(slot); + int resCreature;//resulting creature - bone dragons or skeletons + + if (s.hasBonusOfType(Bonus::KING1)) + resCreature = 68; + else + resCreature = 56; + tlog1<<"test4\n"; + SetGarrisons sg; + sg.garrs[army->id] = army->getArmy(); + sg.garrs[army->id].setCreature(slot, resCreature, s.count); + sendAndApply(&sg); + return true; +} + bool CGameHandler::sendResources(ui32 val, ui8 player, ui32 r1, ui32 r2) { const PlayerState *p2 = gs->getPlayer(r2, false); diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 1d58f89be..f26a92720 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -172,6 +172,7 @@ public: bool tradeResources(const IMarket *market, ui32 val, ui8 player, ui32 id1, ui32 id2); bool sendResources(ui32 val, ui8 player, ui32 r1, ui32 r2); bool sellCreatures(ui32 count, const IMarket *market, const CGHeroInstance * hero, ui32 slot, ui32 resourceID); + bool transformInUndead(const IMarket *market, const CGHeroInstance * hero, ui32 slot); bool assembleArtifacts (si32 heroID, ui16 artifactSlot, bool assemble, ui32 assembleTo); bool buyArtifact( ui32 hid, si32 aid ); //for blacksmith and mage guild only -> buying for gold in common buildings bool buyArtifact( const IMarket *m, const CGHeroInstance *h, int rid, int aid); //for artifact merchant and black market -> buying for any resource in special building / advobject diff --git a/server/NetPacksServer.cpp b/server/NetPacksServer.cpp index 9f9f2df66..8d6e70d3b 100644 --- a/server/NetPacksServer.cpp +++ b/server/NetPacksServer.cpp @@ -156,6 +156,8 @@ bool TradeOnMarketplace::applyGh( CGameHandler *gh ) if(!hero) COMPLAIN_AND_RETURN("Only hero can buy artifacts!"); return gh->buyArtifact(m, hero, r1, r2); + case CREATURE_UNDEAD: + return gh->transformInUndead(m, hero, r1); default: COMPLAIN_AND_RETURN("Unknown exchange mode!"); }