diff --git a/AdventureMapButton.cpp b/AdventureMapButton.cpp index 700dd13aa..dc1505dcb 100644 --- a/AdventureMapButton.cpp +++ b/AdventureMapButton.cpp @@ -81,12 +81,14 @@ void AdventureMapButton::clickLeft (tribool down) if (actOnDown && down) { pressedL=state; - callback(); + if(!callback.empty()) + callback(); } else if (pressedL && (down==false)) { pressedL=state; - callback(); + if(!callback.empty()) + callback(); } else { @@ -243,12 +245,9 @@ CSlider::CSlider(int x, int y, int totalw, boost::function Moved, int left.pos.y = slider.pos.y = right.pos.y = pos.y = y; left.pos.x = pos.x = x; right.pos.x = x + totalw - 16; - - //left.owner = right.owner = slider.owner = this; - //left.function = &CSlider::moveLeft; - //right.function = &CSlider::moveRight; - //slider.function = &CSlider::sliderClicked; left.callback = boost::bind(&CSlider::moveLeft,this); + right.callback = boost::bind(&CSlider::moveRight,this); + slider.callback = boost::bind(&CSlider::sliderClicked,this); left.pos.w = left.pos.h = right.pos.w = right.pos.h = slider.pos.w = slider.pos.h = pos.h = 16; pos.w = totalw; left.imgs.resize(1); right.imgs.resize(1); slider.imgs.resize(1); diff --git a/CCallback.cpp b/CCallback.cpp index bb5751d53..6235a41e2 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -303,6 +303,20 @@ void CCallback::recruitCreatures(const CGObjectInstance *obj, int ID, int amount } } + +bool CCallback::dismissCreature(const CArmedInstance *obj, int stackPos) +{ + return false; +} +bool CCallback::upgradeCreature(const CArmedInstance *obj, int stackPos) +{ + return false; +} +UpgradeInfo CCallback::getUpgradeInfo(const CArmedInstance *obj, int stackPos) +{ + return UpgradeInfo(); +} + int CCallback::howManyTowns() { return gs->players[gs->currentPlayer].towns.size(); diff --git a/CCallback.h b/CCallback.h index 69a2198ae..35155fd8a 100644 --- a/CCallback.h +++ b/CCallback.h @@ -14,6 +14,15 @@ class CSelectableComponent; struct BattleAction; typedef struct lua_State lua_State; +//structure gathering info about upgrade possibilites +struct UpgradeInfo +{ + int oldID; //creature to be upgraded + std::vector newID; //possible upgrades + std::vector > > cost; // cost[upgrade_serial] -> set of pairs + UpgradeInfo(){oldID = -1;}; +}; + class ICallback { public: @@ -25,6 +34,8 @@ public: virtual bool dismissHero(const CGHeroInstance * hero)=0; //dismisses diven hero; true - successfuly, false - not successfuly virtual bool swapArifacts(const CGHeroInstance * hero1, bool worn1, int pos1, const CGHeroInstance * hero2, bool worn2, int pos2)=0; //swaps artifacts between two given heroes virtual void recruitCreatures(const CGObjectInstance *obj, int ID, int amount)=0; + virtual bool dismissCreature(const CArmedInstance *obj, int stackPos)=0; + virtual bool upgradeCreature(const CArmedInstance *obj, int stackPos)=0; //get info virtual bool verifyPath(CPath * path, bool blockSea)=0; @@ -42,6 +53,7 @@ public: virtual int getMySerial()=0; virtual int getHeroSerial(const CGHeroInstance * hero)=0; virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)=0; + virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)=0; //battle virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship @@ -83,7 +95,15 @@ public: bool moveHero(int ID, CPath * path, int idtype, int pathType=0);//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero //pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos void selectionMade(int selection, int asker); + int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2); + int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2); //first goes to the second + int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val); + bool dismissHero(const CGHeroInstance * hero); + bool swapArifacts(const CGHeroInstance * hero1, bool worn1, int pos1, const CGHeroInstance * hero2, bool worn2, int pos2); + bool buildBuilding(const CGTownInstance *town, int buildingID); void recruitCreatures(const CGObjectInstance *obj, int ID, int amount); + bool dismissCreature(const CArmedInstance *obj, int stackPos); + bool upgradeCreature(const CArmedInstance *obj, int stackPos); //get info @@ -103,13 +123,9 @@ public: int getMyColor(); int getHeroSerial(const CGHeroInstance * hero); int getMySerial(); - int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2); - int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2); //first goes to the second - int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val); - bool dismissHero(const CGHeroInstance * hero); const CCreatureSet* getGarrison(const CGObjectInstance *obj); - bool swapArifacts(const CGHeroInstance * hero1, bool worn1, int pos1, const CGHeroInstance * hero2, bool worn2, int pos2); - bool buildBuilding(const CGTownInstance *town, int buildingID); + UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos); + //battle int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship int battleGetObstaclesAtTile(int tile); //returns bitfield diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index e38970b32..b3c2f7bf7 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -24,6 +24,7 @@ #include "hch\CPreGameTextHandler.h" #include "CBattleInterface.h" #include "CLua.h" +#include using namespace CSDL_Ext; extern TTF_Font * GEOR16; @@ -102,10 +103,30 @@ void CGarrisonSlot::hover (bool on) LOCPLINT->statusbar->clear(); } } + +const CGObjectInstance * CGarrisonSlot::getObj() +{ + return (!upg)?(owner->oup):(owner->odown); +} + void CGarrisonSlot::clickRight (tribool down) { - //if(down && creature) - //(new CCreInfoWindow(creature->idNumber,0))->activate(); + StackState *pom = NULL; + if(down && creature) + { + if(getObj()->ID == 34) + { + pom = new StackState(); + const CGHeroInstance *h = static_cast(getObj()); + pom->attackBonus = h->primSkills[0]; + pom->defenseBonus = h->primSkills[1]; + pom->luck = h->getCurrentLuck(); + pom->morale = h->getCurrentMorale(); + } + (new CCreInfoWindow(creature->idNumber,0,pom,boost::function(),boost::function())) + ->activate(); + } + delete pom; } void CGarrisonSlot::clickLeft(tribool down) { @@ -2906,20 +2927,84 @@ CCreInfoWindow::CCreInfoWindow(int Cid, int Type, StackState *State, boost::func pos.y = screen->h/2 - bitmap->h/2; pos.w = bitmap->w; pos.h = bitmap->h; + blueToPlayersAdv(bitmap,LOCPLINT->playerID); SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255)); anim = new CCreatureAnimation(c->animDefName); anim->setType(1); - printAtMiddle(c->namePl,149,30,GEOR13,zwykly,bitmap); + char pom[25];int hlp=0; + printAtMiddle(c->namePl,149,30,GEOR13,zwykly,bitmap); //creature name + //atttack printAt(CGI->preth->zelp[435].first,155,48,GEOR13,zwykly,bitmap); + itoa(c->attack,pom,10); + if(State && State->attackBonus) + { + int hlp = log10f(c->attack)+2; + pom[hlp-1] = ' '; pom[hlp] = '('; + itoa(c->attack+State->attackBonus,pom+hlp+1,10); + pom[hlp+2+(int)log10f(State->attackBonus+c->attack)] = ')'; + } + printTo(pom,276,61,GEOR13,zwykly,bitmap); + + //defense printAt(CGI->preth->zelp[436].first,155,67,GEOR13,zwykly,bitmap); + itoa(c->defence,pom,10); + if(State && State->defenseBonus) + { + int hlp = log10f(c->defence)+2; + pom[hlp-1] = ' '; pom[hlp] = '('; + itoa(c->defence+State->defenseBonus,pom+hlp+1,10); + pom[hlp+2+(int)log10f(State->defenseBonus+c->defence)] = ')'; + } + printTo(pom,276,80,GEOR13,zwykly,bitmap); + + //shots if(c->shots) - printAt(CGI->preth->zelp[437].first,155,86,GEOR13,zwykly,bitmap); + { + printAt(CGI->generaltexth->allTexts[198],155,86,GEOR13,zwykly,bitmap); + itoa(c->shots,pom,10); + printTo(pom,276,99,GEOR13,zwykly,bitmap); + } + + //damage printAt(CGI->generaltexth->allTexts[199],155,105,GEOR13,zwykly,bitmap); + itoa(c->damageMin,pom,10); + hlp=log10f(c->damageMin)+2; + pom[hlp-1]=' '; pom[hlp]='-'; pom[hlp+1]=' '; + itoa(c->damageMax,pom+hlp+2,10); + printTo(pom,276,118,GEOR13,zwykly,bitmap); + + //health printAt(CGI->preth->zelp[439].first,155,124,GEOR13,zwykly,bitmap); + itoa(c->hitPoints,pom,10); + printTo(pom,276,137,GEOR13,zwykly,bitmap); + + //remaining health - TODO: show during the battles //printAt(CGI->preth->zelp[440].first,155,143,GEOR13,zwykly,bitmap); + + //speed printAt(CGI->preth->zelp[441].first,155,162,GEOR13,zwykly,bitmap); + itoa(c->speed,pom,10); + printTo(pom,276,175,GEOR13,zwykly,bitmap); + + + //luck and morale + blitAt(LOCPLINT->morale42->ourImages[(State)?(State->morale+3):(3)].bitmap,24,189,bitmap); + blitAt(LOCPLINT->luck42->ourImages[(State)?(State->luck+3):(3)].bitmap,77,189,bitmap); + + //print abilities text - if r-click popup + if(type) + { + if(Upg) + upgrade = new AdventureMapButton("",CGI->preth->zelp[446].second,Upg,76,237,"IVIEWCR.DEF"); + if(Dsm) + dismiss = new AdventureMapButton("",CGI->preth->zelp[445].second,Upg,21,237,"IVIEWCR2.DEF"); + } + else + { + printAtWB(c->abilityText,17,231,GEOR13,35,zwykly,bitmap); + } } CCreInfoWindow::~CCreInfoWindow() { @@ -2940,14 +3025,12 @@ void CCreInfoWindow::activate() void CCreInfoWindow::close() { deactivate(); + CCastleInterface *c = dynamic_cast(LOCPLINT->curint); + if(c) c->showAll(); + if(type) + LOCPLINT->curint->activate(); delete this; - if(type) - { - LOCPLINT->curint->activate(); - CCastleInterface *c = dynamic_cast(LOCPLINT->curint); - if(c) c->showAll(); - } } void CCreInfoWindow::clickRight(boost::logic::tribool down) { diff --git a/CPlayerInterface.h b/CPlayerInterface.h index 49f07a4a5..c7fb124c4 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -245,6 +245,7 @@ public: bool active; virtual void hover (bool on); + const CGObjectInstance * getObj(); void clickRight (boost::logic::tribool down); void clickLeft(boost::logic::tribool down); void activate(); diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index 8eee68bd5..4118af496 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -93,6 +93,25 @@ void CSDL_Ext::printAtMiddleWB(std::string text, int x, int y, TTF_Font * font, } + for (int i=0;i * ws = CMessage::breakText(text,charpr); + std::vector wesu; + wesu.resize(ws->size()); + for (int i=0;ih; + } + for (int i=0;ispriteh->giveDef(defName); - else - creatures[s].battleAnimation = NULL; - i+=2; - } + // befi=i; + // for(i; ispriteh->giveDef(defName); + // else + // creatures[s].battleAnimation = NULL; + // i+=2; + //} } int CCreatureAnimation::getType() const diff --git a/hch/CCreatureHandler.h b/hch/CCreatureHandler.h index 5037ed13e..3d67cef3d 100644 --- a/hch/CCreatureHandler.h +++ b/hch/CCreatureHandler.h @@ -16,7 +16,8 @@ public: std::string namePl, nameSing, nameRef; //name in singular and plural form; and reference name std::vector cost; //cost[res_id] - amount of that resource int fightValue, AIValue, growth, hordeGrowth, hitPoints, speed, attack, defence, shots, spells; - int low1, low2, high1, high2; //TODO - co to w ogóle jest??? + int damageMin, damageMax; + int ammMin, ammMax; int level; // 0 - unknown std::string abilityText; //description of abilities std::string abilityRefs; //references to abilities, in textformat @@ -36,7 +37,7 @@ public: int indefLevel; //only if indefinite bool indefUpgraded; //onlu if inddefinite //end - CDefHandler * battleAnimation; + //CDefHandler * battleAnimation; //TODO - zdolności - na typie wyliczeniowym czy czymś static int getQuantityID(int quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion @@ -60,7 +61,7 @@ public: std::map smallImgs; //creature ID -> small 32x32 img of creature; //ID=-2 is for blank (black) img; -1 for the border std::map bigImgs; //creature ID -> big 58x64 img of creature; //ID=-2 is for blank (black) img; -1 for the border std::map backgrounds; //castle ID -> 100x130 background creature image // -1 is for neutral - std::vector creatures; + std::vector creatures; //creature ID -> creature info std::map > levelCreatures; //level -> list of creatures std::map nameToID; void loadCreatures();