mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
* improvements in recruitment window (slider won't allow to select more creatres than we can afford)
This commit is contained in:
parent
2f2169b71f
commit
5b077531cd
@ -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;i<RESOURCE_QUANTITY;i++)
|
||||
if (gs->players[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<int> 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 "<<hero->level<<std::endl;
|
||||
int r = rand()%100, pom=0, x=0;
|
||||
int std::pair<int,int>::*g=hero->level>9?&std::pair<int,int>::second:&std::pair<int,int>::first;
|
||||
int std::pair<int,int>::*g = (hero->level>9) ? (&std::pair<int,int>::second) : (&std::pair<int,int>::first);
|
||||
for(;x<PRIMARY_SKILLS;x++)
|
||||
{
|
||||
pom += hero->type->heroClass->primChance[x].*g;
|
||||
|
@ -92,6 +92,7 @@ public:
|
||||
PseudoV< PseudoV< PseudoV<unsigned char> > > & 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<int> 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);
|
||||
|
2
CMT.cpp
2
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
|
||||
|
||||
|
@ -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;j<creatures.size();j++)
|
||||
{
|
||||
@ -2496,7 +2502,8 @@ void CRecrutationWindow::show(SDL_Surface * to)
|
||||
for(int i=0;i<creatures.size();i++)
|
||||
{
|
||||
blitAt(CGI->creh->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<std::pair<int,int> > &Creatur
|
||||
{
|
||||
which = 0;
|
||||
creatures.resize(Creatures.size());
|
||||
amounts.resize(Creatures.size());
|
||||
for(int i=0;i<creatures.size();i++)
|
||||
{
|
||||
creatures[i].amount = Creatures[i].second;
|
||||
@ -2514,6 +2522,7 @@ CRecrutationWindow::CRecrutationWindow(std::vector<std::pair<int,int> > &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<std::pair<int,int> > &Creatur
|
||||
pos.y = screen->h/2 - bitmap->h/2;
|
||||
pos.w = bitmap->w;
|
||||
pos.h = bitmap->h;
|
||||
slider = new CSlider<CRecrutationWindow>(pos.x+176,pos.y+279,135,this,&CRecrutationWindow::sliderMoved,1,creatures[0].amount,0,true);
|
||||
slider = new CSlider<CRecrutationWindow>(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
|
||||
|
@ -462,6 +462,7 @@ public:
|
||||
CCreatureAnimation *anim;
|
||||
std::vector<std::pair<int,int> > res; //res_id - cost_per_unit
|
||||
};
|
||||
std::vector<int> amounts; //how many creatures we can afford
|
||||
std::vector<creinfo> creatures;
|
||||
IRecruit *rec;
|
||||
CSlider<CRecrutationWindow> *slider;
|
||||
|
@ -42,6 +42,15 @@ bool CCreature::isFlying()
|
||||
{
|
||||
return boost::algorithm::find_first(abilityRefs, "FLYING_ARMY");
|
||||
}
|
||||
int CCreature::maxAmount(const std::vector<int> &res) const //how many creatures can be bought
|
||||
{
|
||||
int ret = 2147483645;
|
||||
int resAmnt = std::min(res.size(),cost.size());
|
||||
for(int i=0;i<resAmnt;i++)
|
||||
if(cost[i])
|
||||
ret = std::min(ret,res[i]/cost[i]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CCreatureHandler::loadCreatures()
|
||||
{
|
||||
@ -1010,7 +1019,7 @@ void CCreatureAnimation::putPixel(SDL_Surface * dest, const int & ftcp, const BM
|
||||
p[2] = color.R;
|
||||
}
|
||||
else if(palc < 5) //shadow
|
||||
{
|
||||
{
|
||||
Uint16 alpha;
|
||||
switch(color.G)
|
||||
{
|
||||
|
@ -42,6 +42,7 @@ public:
|
||||
static int getQuantityID(int quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion
|
||||
bool isDoubleWide(); //returns true if unit is double wide on battlefield
|
||||
bool isFlying(); //returns true if it is a flying unit
|
||||
int maxAmount(const std::vector<int> &res) const; //how many creatures can be bought
|
||||
};
|
||||
|
||||
class CCreatureSet //seven combined creatures
|
||||
|
Loading…
Reference in New Issue
Block a user