diff --git a/CCallback.cpp b/CCallback.cpp index c8131ed0b..bb5751d53 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -266,6 +266,9 @@ void CCallback::recruitCreatures(const CGObjectInstance *obj, int ID, int amount if(!found) //no such creature return; + if(amount > CGI->creh->creatures[ID].maxAmount(gs->players[player].resources)) + return; //not enough resources + for(int i=0;iplayers[player].resources[i] < (CGI->creh->creatures[ID].cost[i] * amount)) return; //not enough resources @@ -349,7 +352,10 @@ int CCallback::getResourceAmount(int type) { return gs->players[player].resources[type]; } - +std::vector CCallback::getResourceAmount() +{ + return gs->players[player].resources; +} int CCallback::getDate(int mode) { int temp; @@ -785,7 +791,7 @@ void CScriptCallback::changePrimSkill(int ID, int which, int val) hero->level++; std::cout << hero->name <<" got level "<level<::*g=hero->level>9?&std::pair::second:&std::pair::first; + int std::pair::*g = (hero->level>9) ? (&std::pair::second) : (&std::pair::first); for(;xtype->heroClass->primChance[x].*g; diff --git a/CCallback.h b/CCallback.h index 9817acf92..69a2198ae 100644 --- a/CCallback.h +++ b/CCallback.h @@ -92,6 +92,7 @@ public: PseudoV< PseudoV< PseudoV > > & getVisibilityMap(); //returns visibility map (TODO: make it const) const CGHeroInstance * getHeroInfo(int player, int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID int getResourceAmount(int type); + std::vector getResourceAmount(); int howManyHeroes(); const CGTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID std::vector < const CGTownInstance *> getTownsInfo(bool onlyOur=true); diff --git a/CMT.cpp b/CMT.cpp index f434afd01..6245a5cfc 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -62,7 +62,7 @@ CGameInfo* CGI; #endif #define CHUNK 16384 -const char * NAME = "VCMI 0.58"; +const char * NAME = "VCMI 0.59"; SDL_Color playerColorPalette[256]; //palette to make interface colors good diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index d1717f32b..71eb9a6c5 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -2434,6 +2434,12 @@ void CRecrutationWindow::clickLeft(tribool down) if(isItIn(&genRect(132,102,pos.x+curx,pos.y+64),LOCPLINT->current->motion.x,LOCPLINT->current->motion.y)) { which = i; + int newAmount = std::min(amounts[i],creatures[i].amount); + slider->amount = newAmount; + if(slider->value > newAmount) + slider->moveTo(newAmount); + else + slider->moveTo(slider->value); curx = 192 + 51 - (102*creatures.size()/2) - (18*(creatures.size()-1)/2); for(int j=0;jcreh->backgrounds[CGI->creh->creatures[creatures[i].ID].faction],curx-50,pos.y+130-65); - creatures[i].anim->nextFrameMiddle(screen,curx+20,pos.y+110,true,!(c%2),false); + SDL_Rect dst = genRect(130,100,curx-50,pos.y+130-65); + creatures[i].anim->nextFrameMiddle(screen,curx+20,pos.y+110,true,!(c%2),&dst); curx += 120; } c++; @@ -2506,6 +2513,7 @@ CRecrutationWindow::CRecrutationWindow(std::vector > &Creatur { which = 0; creatures.resize(Creatures.size()); + amounts.resize(Creatures.size()); for(int i=0;i > &Creatur if(CGI->creh->creatures[Creatures[i].first].cost[j]) creatures[i].res.push_back(std::make_pair(j,CGI->creh->creatures[Creatures[i].first].cost[j])); creatures[i].anim = new CCreatureAnimation(CGI->creh->creatures[Creatures[i].first].animDefName); + amounts[i] = CGI->creh->creatures[Creatures[i].first].maxAmount(LOCPLINT->cb->getResourceAmount()); } SDL_Surface *hhlp = CGI->bitmaph->loadBitmap("TPRCRT.bmp"); blueToPlayersAdv(hhlp,LOCPLINT->playerID); @@ -2524,7 +2533,7 @@ CRecrutationWindow::CRecrutationWindow(std::vector > &Creatur pos.y = screen->h/2 - bitmap->h/2; pos.w = bitmap->w; pos.h = bitmap->h; - slider = new CSlider(pos.x+176,pos.y+279,135,this,&CRecrutationWindow::sliderMoved,1,creatures[0].amount,0,true); + slider = new CSlider(pos.x+176,pos.y+279,135,this,&CRecrutationWindow::sliderMoved,1,std::min(amounts[0],creatures[0].amount),0,true); std::string pom; printAtMiddle(CGI->generaltexth->allTexts[346],113,231,GEOR13,zwykly,bitmap); //cost per troop t printAtMiddle(CGI->generaltexth->allTexts[465],205,231,GEOR13,zwykly,bitmap); //available t diff --git a/CPlayerInterface.h b/CPlayerInterface.h index abd4cf0a3..6d8bd735b 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -462,6 +462,7 @@ public: CCreatureAnimation *anim; std::vector > res; //res_id - cost_per_unit }; + std::vector amounts; //how many creatures we can afford std::vector creatures; IRecruit *rec; CSlider *slider; diff --git a/hch/CCreatureHandler.cpp b/hch/CCreatureHandler.cpp index 131c4446a..3e795dc51 100644 --- a/hch/CCreatureHandler.cpp +++ b/hch/CCreatureHandler.cpp @@ -42,6 +42,15 @@ bool CCreature::isFlying() { return boost::algorithm::find_first(abilityRefs, "FLYING_ARMY"); } +int CCreature::maxAmount(const std::vector &res) const //how many creatures can be bought +{ + int ret = 2147483645; + int resAmnt = std::min(res.size(),cost.size()); + for(int i=0;i &res) const; //how many creatures can be bought }; class CCreatureSet //seven combined creatures