diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index e7fc6358b..a215e8a77 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -221,6 +221,11 @@ void CHeroList::hover (bool on) void CHeroList::keyPressed (SDL_KeyboardEvent & key) { } +void CHeroList::updateHList() +{ + items.clear(); + genList(); +} void CHeroList::updateMove(const CGHeroInstance* which) //draws move points bar { int ser = LOCPLINT->cb->getHeroSerial(which); diff --git a/CCallback.cpp b/CCallback.cpp index 62039c344..e167186eb 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -396,6 +396,17 @@ int CCallback::swapCreatures(const CCreatureSet *s1, const CCreatureSet *s2, int } return -1; } + +bool CCallback::dismissHero(const CGHeroInstance *hero) +{ + CGHeroInstance * Vhero = const_cast(hero); + CGI->mh->removeObject(Vhero); + std::vector::iterator nitr = find(CGI->state->players[player].heroes.begin(), CGI->state->players[player].heroes.end(), Vhero); + CGI->state->players[player].heroes.erase(nitr); + LOCPLINT->adventureInt->heroList.updateHList(); + return false; +} + int CCallback::getMySerial() { return gs->players[player].serial; diff --git a/CCallback.h b/CCallback.h index 75d24308f..04399468a 100644 --- a/CCallback.h +++ b/CCallback.h @@ -35,6 +35,7 @@ public: virtual int getMySerial()=0; virtual int getHeroSerial(const CGHeroInstance * hero)=0; virtual int swapCreatures(const CCreatureSet *s1, const CCreatureSet *s2, int p1, int p2)=0;//swaps creatures between two posiibly different garrisons // TODO: AI-unsafe code - fix it! + virtual bool dismissHero(const CGHeroInstance * hero)=0; //dismisses diven hero; true - successfuly, false - not successfuly }; struct HeroMoveDetails @@ -80,6 +81,7 @@ public: int getHeroSerial(const CGHeroInstance * hero); int getMySerial(); int swapCreatures(const CCreatureSet *s1, const CCreatureSet *s2, int p1, int p2); + bool dismissHero(const CGHeroInstance * hero); //friends friend int _tmain(int argc, _TCHAR* argv[]); diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index 93fb0b3e4..c77bde787 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -56,12 +56,27 @@ CHeroWindow::CHeroWindow(int playerColor): artFeet(0), artHead(0), artLHand(0), skillpics = CGI->spriteh->giveDef("pskil42.def"); flags = CGI->spriteh->giveDef("CREST58.DEF"); //areas - portraitArea = new LClickableAreaWText(); + portraitArea = new LRClickableAreaWText(); portraitArea->pos.x = 83; portraitArea->pos.y = 26; portraitArea->pos.w = 58; portraitArea->pos.h = 64; - + for(int v=0; v<4; ++v) + { + primSkillAreas.push_back(new LRClickableAreaWTextComp()); + primSkillAreas[v]->pos.x = 95 + 70*v; + primSkillAreas[v]->pos.y = 111; + primSkillAreas[v]->pos.w = 42; + primSkillAreas[v]->pos.h = 42; + primSkillAreas[v]->text = CGI->generaltexth->arraytxt[2+v].substr(1, CGI->generaltexth->arraytxt[2+v].size()-2); + primSkillAreas[v]->type = v; + primSkillAreas[v]->bonus = -1; // to be initilized when hero is being set + } + expArea = new LRClickableAreaWText(); + expArea->pos.x = 83; + expArea->pos.y = 236; + expArea->pos.w = 136; + expArea->pos.h = 42; } CHeroWindow::~CHeroWindow() @@ -112,6 +127,11 @@ CHeroWindow::~CHeroWindow() backpack.clear(); delete portraitArea; + delete expArea; + for(int v=0; vtext = hero->biography; + for(int g=0; gbonus = hero->primSkills[g]; + } + + char * th = new char[200]; + sprintf(th, CGI->generaltexth->allTexts[2].substr(1, CGI->generaltexth->allTexts[2].size()-2).c_str(), hero->level, CGI->heroh->reqExp(hero->level+1)-hero->exp, hero->exp); + expArea->text = std::string(th); + delete [] th; + delete artFeet; delete artHead; delete artLHand; @@ -355,6 +385,12 @@ void CHeroWindow::activate() leftArtRoll->activate(); rightArtRoll->activate(); portraitArea->activate(); + expArea->activate(); + for(int v=0; vactivate(); + } + for(int g=0; gactivate(); @@ -424,6 +460,12 @@ void CHeroWindow::deactivate() leftArtRoll->deactivate(); rightArtRoll->deactivate(); portraitArea->deactivate(); + expArea->deactivate(); + for(int v=0; vdeactivate(); + } + for(int g=0; gdeactivate(); @@ -480,6 +522,8 @@ void CHeroWindow::deactivate() void CHeroWindow::dismissCurrent() { + LOCPLINT->cb->dismissHero(curHero); + quit(); } void CHeroWindow::questlog() @@ -749,13 +793,43 @@ void LClickableArea::clickLeft(boost::logic::tribool down) } } -void LClickableAreaWText::clickLeft(boost::logic::tribool down) +void RClickableArea::activate() +{ + ClickableR::activate(); +} +void RClickableArea::deactivate() +{ + ClickableR::deactivate(); +} +void RClickableArea::clickRight(boost::logic::tribool down) +{ + if(!down) + { + LOCPLINT->showInfoDialog("TEST TEST AAA", std::vector()); + } +} + +void LRClickableAreaWText::clickLeft(boost::logic::tribool down) { if(!down) { LOCPLINT->showInfoDialog(text, std::vector()); } } +void LRClickableAreaWText::clickRight(boost::logic::tribool down) +{ + LOCPLINT->adventureInt->handleRightClick(text, down, this); +} +void LRClickableAreaWText::activate() +{ + LClickableArea::activate(); + RClickableArea::activate(); +} +void LRClickableAreaWText::deactivate() +{ + LClickableArea::deactivate(); + RClickableArea::deactivate(); +} void LClickableAreaHero::clickLeft(boost::logic::tribool down) { @@ -768,3 +842,26 @@ void LClickableAreaHero::clickLeft(boost::logic::tribool down) owner->activate(); } } + +void LRClickableAreaWTextComp::clickLeft(boost::logic::tribool down) +{ + if(!down) + { + LOCPLINT->showInfoDialog(text, std::vector(1, new SComponent(SComponent::Etype::primskill, type, bonus))); + } +} +void LRClickableAreaWTextComp::clickRight(boost::logic::tribool down) +{ + LOCPLINT->adventureInt->handleRightClick(text, down, this); +} +void LRClickableAreaWTextComp::activate() +{ + LClickableArea::activate(); + RClickableArea::activate(); +} +void LRClickableAreaWTextComp::deactivate() +{ + LClickableArea::deactivate(); + RClickableArea::deactivate(); +} + diff --git a/CHeroWindow.h b/CHeroWindow.h index bee36ba17..1e6d1cb3e 100644 --- a/CHeroWindow.h +++ b/CHeroWindow.h @@ -17,6 +17,14 @@ public: virtual void deactivate(); }; +class RClickableArea: public ClickableR +{ +public: + virtual void clickRight (tribool down); + virtual void activate(); + virtual void deactivate(); +}; + class LClickableAreaHero : public LClickableArea { public: @@ -25,11 +33,25 @@ public: virtual void clickLeft (tribool down); }; -class LClickableAreaWText: public LClickableArea +class LRClickableAreaWText: public virtual LClickableArea, public virtual RClickableArea { public: std::string text; + virtual void activate(); + virtual void deactivate(); virtual void clickLeft (tribool down); + virtual void clickRight (tribool down); +}; + +class LRClickableAreaWTextComp: public virtual LClickableArea, public virtual RClickableArea +{ +public: + std::string text; + int bonus, type; + virtual void activate(); + virtual void deactivate(); + virtual void clickLeft (tribool down); + virtual void clickRight (tribool down); }; class CArtPlace: public ClickableL, public IShowable @@ -69,7 +91,9 @@ class CHeroWindow: public IActivable, public IShowable, public virtual CIntObjec std::vector backpack; //hero's visible backpack (only 5 elements!) int backpackPos; //unmber of first art visible in backpack (in hero's vector) //clickable areas - LClickableAreaWText * portraitArea; + LRClickableAreaWText * portraitArea; + std::vector primSkillAreas; + LRClickableAreaWText * expArea; public: int player; CHeroWindow(int playerColor); //c-tor diff --git a/hch/CGeneralTextHandler.cpp b/hch/CGeneralTextHandler.cpp index f61ab2e89..7e25bc79c 100644 --- a/hch/CGeneralTextHandler.cpp +++ b/hch/CGeneralTextHandler.cpp @@ -49,148 +49,6 @@ void CGeneralTextHandler::load() CGeneralTextHandler::loadToIt(tmp, strin2, itr, 3); jktexts.push_back(tmp); } - - //std::ofstream ofs("arraytxts.txt"); - //for (int i=0;i20600) + // return 12; + // else if (experience>17500) + // return 11; + // else return 10; + //} + //else //>12 + //{ + // int lvl=12; + // int xp = 24320; //xp needed for 13 lvl + // int td = 4464; //diff 14-13 + // float mp = 1.2; + // while (experience>xp) + // { + // xp+=td; + // td*=mp; + // lvl++; + // } + // return lvl; + //} + int add=0; + while(experience>=expPerLevel[expPerLevel.size()-1]) { - return (-500+20*sqrt((float)experience+1025))/(200); + experience/=1.2; + add+1; } - else if (experience<24320) //10 - 12 + for(int i=expPerLevel.size()-1; i>=0; --i) { - if (experience>20600) - return 12; - else if (experience>17500) - return 11; - else return 10; + if(experience>=expPerLevel[i]) + return i+add; } - else //>12 +} + +unsigned int CHeroHandler::reqExp(unsigned int level) +{ + level-=1; + if(level<=expPerLevel.size()) + return expPerLevel[level]; + else { - int lvl=12; - int xp = 24320; //xp needed for 13 lvl - int td = 4464; //diff 14-13 - float mp = 1.2; - while (experience>xp) + unsigned int exp = expPerLevel[expPerLevel.size()-1]; + level-=expPerLevel.size(); + while(level>0) { - xp+=td; - td*=mp; - lvl++; + --level; + exp*=1.2; } - return lvl; } } diff --git a/hch/CHeroHandler.h b/hch/CHeroHandler.h index 69d877160..d93c08cb9 100644 --- a/hch/CHeroHandler.h +++ b/hch/CHeroHandler.h @@ -92,7 +92,9 @@ public: CDefHandler * pskillsb, *resources; //82x93 CDefHandler * un44; //many things std::vector pskillsn; + std::vector expPerLevel; //expPerLEvel[i] is amount of exp needed to reach level i; if it is not in this vector, multiplicate last value by 1,2 to get next value unsigned int level(unsigned int experience); + unsigned int reqExp(unsigned int level); void loadHeroes(); void loadSpecialAbilities(); void loadBiographies();