1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

* mostly done town infobox

* town daily income is properly calculated
* minor not done stuff
This commit is contained in:
Michał W. Urbańczyk 2008-02-18 21:14:28 +00:00
parent 3844c45441
commit e46d411643
10 changed files with 129 additions and 11 deletions

View File

@ -671,7 +671,12 @@ void CInfoBar::draw(const CGObjectInstance * specific)
{
if(LOCPLINT->heroWins.find(specific->subID)!=LOCPLINT->heroWins.end())
blitAt(LOCPLINT->heroWins[specific->subID],pos.x,pos.y);
}
else if (specific->ID == 98)
{
const CGTownInstance * t = static_cast<const CGTownInstance*>(specific);
if(LOCPLINT->townWins.find(t->identifier)!=LOCPLINT->townWins.end())
blitAt(LOCPLINT->townWins[t->identifier],pos.x,pos.y);
}
//SDL_Surface * todr = LOCPLINT->infoWin(specific);
@ -1006,6 +1011,7 @@ void CAdvMapInt::selectionChanged()
terrain.currentPath = NULL;
townList.draw();
heroList.draw();
infoBar.draw(NULL);
}
void CAdvMapInt::centerOn(int3 on)
{

View File

@ -351,6 +351,21 @@ bool CCallback::isVisible(int3 pos, int Player)
return gs->players[Player].fogOfWarMap[pos.x][pos.y][pos.z];
}
std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur)
{
std::vector < const CGTownInstance *> ret = std::vector < const CGTownInstance *>();
for ( std::map<int, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
{
for (int j=0;j<(*i).second.towns.size();j++)
{
if ( ( isVisible((*i).second.towns[j]->pos,player) ) || (*i).first==player)
{
ret.push_back((*i).second.towns[j]);
}
}
} // for ( std::map<int, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
return ret;
}
std::vector < const CGHeroInstance *> CCallback::getHeroesInfo(bool onlyOur)
{
std::vector < const CGHeroInstance *> ret = std::vector < const CGHeroInstance *>();

View File

@ -75,6 +75,7 @@ public:
int getResourceAmount(int type);
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);
int howManyTowns();
std::vector < std::string > getObjDescriptions(int3 pos); //returns descriptions of objects at pos in order from the lowest to the highest
std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true);

View File

@ -160,7 +160,6 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate)
cityBg = CGI->bitmaph->loadBitmap(getBgName(Town->subID));
hall = CGI->spriteh->giveDef("ITMTL.DEF");
fort = CGI->spriteh->giveDef("ITMCL.DEF");
bigTownPic = CGI->spriteh->giveDef("ITPT.DEF");
flag = CGI->spriteh->giveDef("CREST58.DEF");
townlist = new CTownList<CCastleInterface>(3,&genRect(128,48,744,414),744,414,744,526);
exit = new AdventureMapButton<CCastleInterface>
@ -262,7 +261,6 @@ CCastleInterface::~CCastleInterface()
delete split;
delete hall;
delete fort;
delete bigTownPic;
delete flag;
delete garr;
delete townlist;
@ -343,7 +341,7 @@ void CCastleInterface::showAll(SDL_Surface * to)
//print name and income
CSDL_Ext::printAt(town->name,85,389,GEOR13,zwykly,to);
char temp[10];
itoa(town->income,temp,10);
itoa(town->dailyIncome(),temp,10);
CSDL_Ext::printAtMiddle(temp,195,442,GEOR13,zwykly,to);
//blit town icon
@ -352,7 +350,7 @@ void CCastleInterface::showAll(SDL_Surface * to)
pom += F_NUMBER*2;
if(town->builded >= MAX_BUILDING_PER_TURN)
pom++;
blitAt(bigTownPic->ourImages[pom].bitmap,15,387,to);
blitAt(LOCPLINT->bigTownPic->ourImages[pom].bitmap,15,387,to);
//flag
if(town->getOwner()<PLAYER_LIMIT)

View File

@ -36,8 +36,7 @@ public:
unsigned char animval, count;
CDefHandler *hall,*fort,
*bigTownPic, *flag;
CDefHandler *hall,*fort, *flag;
CTownList<CCastleInterface> * townlist;

View File

@ -65,6 +65,7 @@ int internalFunc(void * callback)
{
SDL_Surface * temp = LOCPLINT->infoWin(NULL);
blitAtWR(temp,605,389);
SDL_FreeSurface(temp);
break;
}
case 'T': //test rect

View File

@ -739,6 +739,8 @@ CPlayerInterface::CPlayerInterface(int Player, int serial)
human=true;
hInfo = CGI->bitmaph->loadBitmap("HEROQVBK.bmp");
SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255));
tInfo = CGI->bitmaph->loadBitmap("TOWNQVBK.bmp");
SDL_SetColorKey(tInfo,SDL_SRCCOLORKEY,SDL_MapRGB(tInfo->format,0,255,255));
slotsPos.push_back(std::pair<int,int>(44,82));
slotsPos.push_back(std::pair<int,int>(80,82));
slotsPos.push_back(std::pair<int,int>(116,82));
@ -755,6 +757,9 @@ CPlayerInterface::CPlayerInterface(int Player, int serial)
morale30 = CGI->spriteh->giveDefEss("IMRL30.DEF");
morale42 = CGI->spriteh->giveDefEss("IMRL42.DEF");
morale82 = CGI->spriteh->giveDefEss("IMRL82.DEF");
halls = CGI->spriteh->giveDefEss("ITMTLS.DEF");
forts = CGI->spriteh->giveDefEss("ITMCLS.DEF");
bigTownPic = CGI->spriteh->giveDefEss("ITPT.DEF");
}
void CPlayerInterface::init(ICallback * CB)
@ -769,6 +774,12 @@ void CPlayerInterface::init(ICallback * CB)
SDL_Surface * pom = infoWin(hh[i]);
heroWins.insert(std::pair<int,SDL_Surface*>(hh[i]->subID,pom));
}
std::vector<const CGTownInstance*> tt = cb->getTownsInfo(false);
for(int i=0;i<tt.size();i++)
{
SDL_Surface * pom = infoWin(tt[i]);
townWins.insert(std::pair<int,SDL_Surface*>(tt[i]->identifier,pom));
}
}
void CPlayerInterface::yourTurn()
{
@ -1403,7 +1414,34 @@ SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh)
SDL_Surface * CPlayerInterface::drawTownInfoWin(const CGTownInstance * curh)
{
return NULL;
char * buf = new char[10];
SDL_Surface * ret = SDL_DisplayFormat(tInfo);
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
blueToPlayersAdv(ret,playerID,1);
printAt(curh->name,75,15,GEOR13,zwykly,ret);
int pom = curh->fortLevel() - 1; if(pom<0) pom = 3;
blitAt(halls->ourImages[curh->hallLevel()].bitmap,77,42,ret);
blitAt(forts->ourImages[pom].bitmap,115,42,ret);
itoa(curh->dailyIncome(),buf,10);
printAtMiddle(buf,167,70,GEORM,zwykly,ret);
for (std::map<int,std::pair<CCreature*,int> >::const_iterator i=curh->garrison.slots.begin(); i!=curh->garrison.slots.end();i++)
{
blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret);
itoa((*i).second.second,buf,10);
printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret);
}
//blit town icon
pom = curh->subID*2;
if (!curh->hasFort())
pom += F_NUMBER*2;
if(curh->builded >= MAX_BUILDING_PER_TURN)
pom++;
blitAt(bigTownPic->ourImages[pom].bitmap,13,13,ret);
delete[] buf;
return ret;
}
void CPlayerInterface::openTownWindow(const CGTownInstance * town)
@ -1424,6 +1462,9 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe
case 34:
return drawHeroInfoWin(dynamic_cast<const CGHeroInstance*>(specific));
break;
case 98:
return drawTownInfoWin(dynamic_cast<const CGTownInstance*>(specific));
break;
default:
return NULL;
break;
@ -1725,6 +1766,12 @@ void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj)
}
else if (obj->ID == 98) //town
{
const CGTownInstance * tt;
if(tt = dynamic_cast<const CGTownInstance*>(obj))
{
SDL_FreeSurface(heroWins[tt->identifier]);
heroWins[tt->identifier] = infoWin(tt);
}
}
}
void CPlayerInterface::showComp(SComponent comp)

View File

@ -148,6 +148,15 @@ public:
void close();
CSelWindow(){};
};
class CRClickPopup : public IShowable, public ClickableR
{
virtual void activate()=0;
virtual void deactivate()=0;
virtual void close()=0;
virtual void show()=0;
};
class SComponent : public ClickableR
{
public:
@ -257,12 +266,13 @@ public:
std::vector<TimeInterested*> timeinterested;
std::vector<IShowable*> objsToBlit;
SDL_Surface * hInfo;
SDL_Surface * hInfo, *tInfo;
std::vector<std::pair<int, int> > slotsPos;
CDefEssential *luck22, *luck30, *luck42, *luck82,
*morale22, *morale30, *morale42, *morale82;
*morale22, *morale30, *morale42, *morale82,
*halls, *forts, *bigTownPic;
std::map<int,SDL_Surface*> heroWins;
//std::map<int,SDL_Surface*> townWins;
std::map<int,SDL_Surface*> townWins;
//overloaded funcs from Interface
void yourTurn();

View File

@ -224,6 +224,43 @@ int CGTownInstance::getSightDistance() const //returns sight distance
{
return 10;
}
int CGTownInstance::fortLevel() const //0 - none, 1 - fort, 2 - citadel, 3 - castle
{
if((builtBuildings.find(9))!=builtBuildings.end())
return 3;
if((builtBuildings.find(8))!=builtBuildings.end())
return 2;
if((builtBuildings.find(7))!=builtBuildings.end())
return 1;
return 0;
}
int CGTownInstance::hallLevel() const // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
{
if ((builtBuildings.find(13))!=builtBuildings.end())
return 3;
if ((builtBuildings.find(12))!=builtBuildings.end())
return 2;
if ((builtBuildings.find(11))!=builtBuildings.end())
return 1;
if ((builtBuildings.find(10))!=builtBuildings.end())
return 0;
return -1;
}
int CGTownInstance::dailyIncome() const
{
int ret = 0;
if ((builtBuildings.find(26))!=builtBuildings.end())
ret+=5000;
if ((builtBuildings.find(13))!=builtBuildings.end())
ret+=4000;
else if ((builtBuildings.find(12))!=builtBuildings.end())
ret+=2000;
else if ((builtBuildings.find(11))!=builtBuildings.end())
ret+=1000;
else if ((builtBuildings.find(10))!=builtBuildings.end())
ret+=500;
return ret;
}
bool CGTownInstance::hasFort() const
{
return (builtBuildings.find(7))!=builtBuildings.end();

View File

@ -394,6 +394,10 @@ public:
std::vector<CSpell *> possibleSpells, obligatorySpells, availableSpells;
int getSightDistance() const; //returns sight distance
int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle
int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
bool hasFort() const;
bool hasCapitol() const;
int dailyIncome() const;