1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

* small changes

This commit is contained in:
mateuszb
2010-02-07 15:06:14 +00:00
parent 090cc602b6
commit 69bed4a8d6
17 changed files with 195 additions and 210 deletions

View File

@@ -905,50 +905,6 @@ void CCallback::calculatePaths( const CGHeroInstance *hero, CPathsInfo &out, int
gs->calculatePaths(hero, out, src, movement);
}
InfoAboutHero::InfoAboutHero()
{
details = NULL;
hclass = NULL;
portrait = -1;
}
InfoAboutHero::~InfoAboutHero()
{
delete details;
}
void InfoAboutHero::initFromHero( const CGHeroInstance *h, bool detailed )
{
owner = h->tempOwner;
hclass = h->type->heroClass;
name = h->name;
portrait = h->portrait;
army = h->army;
if(detailed)
{
//include details about hero
details = new Details;
details->luck = h->getCurrentLuck();
details->morale = h->getCurrentMorale();
details->mana = h->mana;
details->primskills.resize(PRIMARY_SKILLS);
for (int i = 0; i < PRIMARY_SKILLS ; i++)
{
details->primskills[i] = h->getPrimSkillLevel(i);
}
}
else
{
//hide info about hero stacks counts using descriptives names ids
for(std::map<si32,std::pair<ui32,si32> >::iterator i = army.slots.begin(); i != army.slots.end(); ++i)
{
i->second.second = CCreature::getQuantityID(i->second.second);
}
}
}
InfoAboutTown::InfoAboutTown()
{
tType = NULL;

View File

@@ -43,25 +43,6 @@ class CMapHeader;
struct CGPathNode;
struct CGPath;
struct InfoAboutHero
{
struct Details
{
std::vector<int> primskills;
int mana, luck, morale;
} *details;
char owner;
const CHeroClass *hclass;
std::string name;
int portrait;
CCreatureSet army; //numbers of creatures are exact numbers if detailed else they are quantity ids (0 - a few, 1 - several and so on)
InfoAboutHero();
~InfoAboutHero();
void initFromHero(const CGHeroInstance *h, bool detailed);
};
struct InfoAboutTown
{
struct Details

View File

@@ -22,7 +22,7 @@ class CDefEssential;
namespace config{struct ButtonInfo;}
class CButtonBase : public KeyShortcut//basic buttton class
class CButtonBase : public KeyShortcut//basic button class
{
public:
struct TextOverlay

View File

@@ -109,10 +109,10 @@ CHeroWindow::CHeroWindow(int playerColor):
expArea->pos = genRect(42, 136, pos.x+83, pos.y + 236);
expArea->hoverText = CGI->generaltexth->heroscrn[9];
morale = new LRClickableAreaWTextComp();
morale = new MoraleLuckBox();
morale->pos = genRect(45,53,pos.x+240,pos.y+187);
luck = new LRClickableAreaWTextComp();
luck = new MoraleLuckBox();
luck->pos = genRect(45,53,pos.x+298,pos.y+187);
spellPointsArea = new LRClickableAreaWText();
@@ -287,36 +287,8 @@ void CHeroWindow::setHero(const CGHeroInstance *hero)
formations->select(hero->army.formation,true);
formations->onChange = boost::bind(&CCallback::setFormation, LOCPLINT->cb, hero, _1);
//setting morale
std::vector<std::pair<int,std::string> > mrl = hero->getCurrentMoraleModifiers();
int mrlv = hero->getCurrentMorale();
int mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad morale, 0 - neutral, 1 - good
morale->hoverText = CGI->generaltexth->heroscrn[4 - mrlt];
morale->baseType = SComponent::morale;
morale->bonus = mrlv;
morale->text = CGI->generaltexth->arraytxt[88];
boost::algorithm::replace_first(morale->text,"%s",CGI->generaltexth->arraytxt[86-mrlt]);
if (!mrl.size())
morale->text += CGI->generaltexth->arraytxt[108];
else
for(int it=0; it < mrl.size(); it++)
morale->text += "\n" + mrl[it].second;
//setting luck
mrl = hero->getCurrentLuckModifiers();
mrlv = hero->getCurrentLuck();
mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad luck, 0 - neutral, 1 - good
luck->hoverText = CGI->generaltexth->heroscrn[7 - mrlt];
luck->baseType = SComponent::luck;
luck->bonus = mrlv;
luck->text = CGI->generaltexth->arraytxt[62];
boost::algorithm::replace_first(luck->text,"%s",CGI->generaltexth->arraytxt[60-mrlt]);
if (!mrl.size())
luck->text += CGI->generaltexth->arraytxt[77];
else
for(int it=0; it < mrl.size(); it++)
luck->text += "\n" + mrl[it].second;
morale->set(true, hero);
luck->set(false, hero);
//restoring pos
pos.x += 65;

View File

@@ -46,9 +46,8 @@ class CHeroWindow: public CWindowWithGarrison
std::vector<LRClickableAreaWTextComp *> primSkillAreas;
LRClickableAreaWText * expArea;
LRClickableAreaWText * spellPointsArea;
LRClickableAreaWTextComp * luck;
LRClickableAreaWText * specArea;//speciality
LRClickableAreaWTextComp * morale;
MoraleLuckBox * morale, * luck;
std::vector<LRClickableAreaWTextComp *> secSkillAreas;
public:
const CGHeroInstance * curHero;

View File

@@ -141,6 +141,7 @@ void CPlayerInterface::init(ICallback * CB)
}
void CPlayerInterface::yourTurn()
{
boost::unique_lock<boost::recursive_mutex> un(*pim);
LOCPLINT = this;
makingTurn = true;

View File

@@ -306,7 +306,7 @@ public:
int ID; //object ID, rarely used by some classes for identification / internal info
CIntObject();
virtual ~CIntObject();; //d-tor
virtual ~CIntObject(); //d-tor
//l-clicks handling
bool pressedL; //for determining if object is L-pressed
@@ -421,6 +421,11 @@ public:
SDL_Surface *bg;
bool freeSurf;
operator SDL_Surface*()
{
return bg;
}
CPicture(SDL_Surface *BG, int x, int y, bool Free = true);
CPicture(const std::string &bmpname, int x, int y);
~CPicture();

View File

@@ -353,7 +353,7 @@ void CGarrisonSlot::show(SDL_Surface * to)
char buf[15];
SDL_itoa(count,buf,10);
blitAt(imgs[creature->idNumber],pos,to);
printTo(buf, pos.x+pos.w, pos.y+pos.h+1, owner->smallIcons ? FONT_TINY : FONT_VERD, zwykly, to);
printTo(buf, pos.x+pos.w, pos.y+pos.h+1, owner->smallIcons ? FONT_TINY : FONT_MEDIUM, zwykly, to);
if((owner->highlighted==this)
|| (owner->splitting && owner->highlighted->creature == creature))
@@ -1125,8 +1125,8 @@ CStatusBar::CStatusBar(int x, int y, std::string name, int maxw)
{
bg=BitmapHandler::loadBitmap(name);
SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
pos.x=x;
pos.y=y;
pos.x += x;
pos.y += y;
if(maxw >= 0)
pos.w = std::min(bg->w,maxw);
else
@@ -4833,20 +4833,10 @@ void CArtMerchantWindow::Buy() {}
void CThievesGuildWindow::activate()
{
statusBar->activate();
exitb->activate();
resdatabar->activate();
CIntObject::activate();
LOCPLINT->statusbar = statusBar;
}
void CThievesGuildWindow::deactivate()
{
statusBar->deactivate();
exitb->deactivate();
resdatabar->deactivate();
}
void CThievesGuildWindow::show(SDL_Surface * to)
{
blitAt(background, pos.x, pos.y, to);
@@ -4870,10 +4860,12 @@ void CThievesGuildWindow::bexitf()
CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner)
:owner(_owner)
{
OBJ_CONSTRUCTION_CAPTURING_ALL;
SThievesGuildInfo tgi; //info to be displayed
LOCPLINT->cb->getThievesGuildInfo(tgi, owner);
pos = Rect( (conf.cc.resx - 800) / 2, (conf.cc.resy - 600) / 2, 800, 600 );
pos = center(Rect(0,0,800,600));// Rect( (conf.cc.resx - 800) / 2, (conf.cc.resy - 600) / 2, 800, 600 );
//loading backround and converting to more bpp form
SDL_Surface * bg = background = BitmapHandler::loadBitmap("TpRank.bmp", false);
@@ -4881,8 +4873,8 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner)
blitAt(bg, 0, 0, background);
SDL_FreeSurface(bg);
exitb = new AdventureMapButton (std::string(), std::string(), boost::bind(&CThievesGuildWindow::bexitf,this), 748 + pos.x, 556 + pos.y, "HSBTNS.def", SDLK_RETURN);
statusBar = new CStatusBar(pos.x + 3, pos.y + 555, "TStatBar.bmp", 742);
exitb = new AdventureMapButton (std::string(), std::string(), boost::bind(&CThievesGuildWindow::bexitf,this), 748, 556, "HSBTNS.def", SDLK_RETURN);
statusBar = new CStatusBar(3, 555, "TStatBar.bmp", 742);
resdatabar = new CMinorResDataBar();
resdatabar->pos.x += pos.x - 3;
@@ -4960,7 +4952,7 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner)
//printing best hero
int counter = 0;
for(std::map<ui8, SThievesGuildInfo::InfoAboutHero>::const_iterator it = tgi.colorToBestHero.begin(); it != tgi.colorToBestHero.end(); ++it)
for(std::map<ui8, InfoAboutHero>::const_iterator it = tgi.colorToBestHero.begin(); it != tgi.colorToBestHero.end(); ++it)
{
blitAt(graphics->portraitSmall[it->second.portrait], 260 + 66 * counter, 360, background);
counter++;
@@ -4979,12 +4971,53 @@ CThievesGuildWindow::CThievesGuildWindow(const CGObjectInstance * _owner)
CThievesGuildWindow::~CThievesGuildWindow()
{
SDL_FreeSurface(background);
delete exitb;
delete statusBar;
delete resdatabar;
// delete exitb;
// delete statusBar;
// delete resdatabar;
}
void MoraleLuckBox::set( bool morale, const CGHeroInstance *hero, int slot /*= -1*/ )
{
int mrlv = -9, mrlt = -9;
std::vector<std::pair<int,std::string> > mrl;
if(morale)
{
//setting morale
mrl = hero->getCurrentMoraleModifiers();
mrlv = hero->getCurrentMorale();
mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad morale, 0 - neutral, 1 - good
hoverText = CGI->generaltexth->heroscrn[4 - mrlt];
baseType = SComponent::morale;
bonus = mrlv;
text = CGI->generaltexth->arraytxt[88];
boost::algorithm::replace_first(text,"%s",CGI->generaltexth->arraytxt[86-mrlt]);
if (!mrl.size())
text += CGI->generaltexth->arraytxt[108];
else
for(int it=0; it < mrl.size(); it++)
text += "\n" + mrl[it].second;
}
else
{
//setting luck
mrl = hero->getCurrentLuckModifiers();
mrlv = hero->getCurrentLuck();
mrlt = (mrlv>0)-(mrlv<0); //signum: -1 - bad luck, 0 - neutral, 1 - good
hoverText = CGI->generaltexth->heroscrn[7 - mrlt];
baseType = SComponent::luck;
bonus = mrlv;
text = CGI->generaltexth->arraytxt[62];
boost::algorithm::replace_first(text,"%s",CGI->generaltexth->arraytxt[60-mrlt]);
if (!mrl.size())
text += CGI->generaltexth->arraytxt[77];
else
for(int it=0; it < mrl.size(); it++)
text += "\n" + mrl[it].second;
}
}

View File

@@ -408,32 +408,6 @@ public:
void sliderMoved(int to);
};
class CCreInfoWindow : public CIntObject
{
public:
//bool active; //TODO: comment me
int type;//0 - rclick popup; 1 - normal window
SDL_Surface *bitmap; //background
char anf; //animation counter
std::string count; //creature count in text format
boost::function<void()> dsm; //dismiss button callback
CCreaturePic *anim; //related creature's animation
CCreature *c; //related creature
std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
AdventureMapButton *dismiss, *upgrade, *ok;
CCreInfoWindow(int Cid, int Type, int creatureCount, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui); //c-tor
~CCreInfoWindow(); //d-tor
void activate();
void close();
void clickRight(tribool down, bool previousState); //call-in
void dismissF();
void keyPressed (const SDL_KeyboardEvent & key); //call-in
void deactivate();
void show(SDL_Surface * to);
};
class CLevelWindow : public CIntObject
{
public:
@@ -644,6 +618,13 @@ public:
virtual void clickRight(tribool down, bool previousState);
};
class MoraleLuckBox : public LRClickableAreaWTextComp
{
public:
void set(bool morale, const CGHeroInstance *hero, int slot = -1); //slot -1 means only hero modifiers
};
class LRClickableAreaOpenHero: public LRClickableAreaWTextComp
{
public:
@@ -661,6 +642,34 @@ public:
void clickRight(tribool down, bool previousState);
};
class CCreInfoWindow : public CIntObject
{
public:
//bool active; //TODO: comment me
int type;//0 - rclick popup; 1 - normal window
SDL_Surface *bitmap; //background
char anf; //animation counter
std::string count; //creature count in text format
boost::function<void()> dsm; //dismiss button callback
CCreaturePic *anim; //related creature's animation
CCreature *c; //related creature
std::vector<SComponent*> upgResCost; //cost of upgrade (if not possible then empty)
//MoraleLuckBox *luck, *morale;
AdventureMapButton *dismiss, *upgrade, *ok;
CCreInfoWindow(int Cid, int Type, int creatureCount, StackState *State, boost::function<void()> Upg, boost::function<void()> Dsm, UpgradeInfo *ui); //c-tor
~CCreInfoWindow(); //d-tor
void activate();
void close();
void clickRight(tribool down, bool previousState); //call-in
void dismissF();
void keyPressed (const SDL_KeyboardEvent & key); //call-in
void deactivate();
void show(SDL_Surface * to);
};
class CArtPlace: public LRClickableAreaWTextComp
{
private:
@@ -855,7 +864,6 @@ class CThievesGuildWindow : public CIntObject
public:
void activate();
void deactivate();
void show(SDL_Surface * to);
void bexitf();

View File

@@ -628,6 +628,13 @@ void OpenWindow::applyCl(CClient *cl)
INTERFACE_CALL_IF_PRESENT(sy->o->tempOwner, showShipyardDialog, sy);
}
break;
case THIEVES_GUILD:
{
//displays Thieves' Guild window (when hero enters Den of Thieves)
const CGObjectInstance *obj = cl->getObj(id1);
GH.pushInt( new CThievesGuildWindow(obj) );
}
break;
}
}
@@ -668,10 +675,3 @@ void TradeComponents::applyCl(CClient *cl)
tlog2 << "Shop type not supported! \n";
}
}
void SShowThievesGuildWindow::applyCl(CClient *cl)
{
//displays Thieves' Guild window (when hero enters Den of Thieves)
const CGObjectInstance *obj = cl->getObj(requestingObject);
GH.pushInt( new CThievesGuildWindow(obj) );
}

View File

@@ -3191,12 +3191,9 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
if(g->second.color == 255)
continue;
const CGHeroInstance * best = HLP::findBestHero(this, g->second.color);
SThievesGuildInfo::InfoAboutHero iah;
iah.portrait = best->portrait;
for(int c=0; c<PRIMARY_SKILLS; ++c)
{
iah.primSkills[c] = -1; //mark as unknown
}
InfoAboutHero iah;
iah.initFromHero(best, level >= 8);
iah.army.slots.clear();
tgi.colorToBestHero[g->second.color] = iah;
}
}
@@ -3230,18 +3227,7 @@ void CGameState::obtainPlayersStats(SThievesGuildInfo & tgi, int level)
}
if(level >= 8) //best hero's stats
{
for(std::map<ui8, PlayerState>::const_iterator g = players.begin(); g != players.end(); ++g)
{
if(g->second.color == 255) //do nothing for neutral player
continue;
const CGHeroInstance * best = HLP::findBestHero(this, g->second.color);
for(int k=0; k<ARRAY_COUNT(tgi.colorToBestHero[g->second.color].primSkills); ++k)
{
//getting prim skills with all bonuses
tgi.colorToBestHero[g->second.color].primSkills[k] = best->getPrimSkillLevel(k);
}
}
//already set in lvl 1 handling
}
if(level >= 9) //personality
{
@@ -3619,3 +3605,48 @@ PlayerState::PlayerState()
{
}
InfoAboutHero::InfoAboutHero()
{
details = NULL;
hclass = NULL;
portrait = -1;
}
InfoAboutHero::~InfoAboutHero()
{
delete details;
}
void InfoAboutHero::initFromHero( const CGHeroInstance *h, bool detailed )
{
owner = h->tempOwner;
hclass = h->type->heroClass;
name = h->name;
portrait = h->portrait;
army = h->army;
if(detailed)
{
//include details about hero
details = new Details;
details->luck = h->getCurrentLuck();
details->morale = h->getCurrentMorale();
details->mana = h->mana;
details->primskills.resize(PRIMARY_SKILLS);
for (int i = 0; i < PRIMARY_SKILLS ; i++)
{
details->primskills[i] = h->getPrimSkillLevel(i);
}
}
else
{
//hide info about hero stacks counts using descriptives names ids
for(std::map<si32,std::pair<ui32,si32> >::iterator i = army.slots.begin(); i != army.slots.end(); ++i)
{
i->second.second = CCreature::getQuantityID(i->second.second);
}
}
}

View File

@@ -52,39 +52,50 @@ struct MetaString;
struct CPack;
class CSpell;
struct TerrainTile;
class CHeroClass;
namespace boost
{
class shared_mutex;
}
struct DLL_EXPORT InfoAboutHero
{
struct DLL_EXPORT Details
{
std::vector<int> primskills;
int mana, luck, morale;
} *details;
char owner;
const CHeroClass *hclass;
std::string name;
int portrait;
CCreatureSet army; //numbers of creatures are exact numbers if detailed else they are quantity ids (0 - a few, 1 - several and so on)
InfoAboutHero();
~InfoAboutHero();
void initFromHero(const CGHeroInstance *h, bool detailed);
};
struct DLL_EXPORT SThievesGuildInfo
{
std::vector<ui8> playerColors; //colors of players that are in-game
std::vector< std::list< ui8 > > numOfTowns, numOfHeroes, gold, woodOre, mercSulfCrystGems, obelisks, artifacts, army, income; // [place] -> [colours of players]
struct InfoAboutHero
{
ui32 portrait;
si32 primSkills[PRIMARY_SKILLS]; //-1 if not available; otherwise values
template <typename Handler> void serialize(Handler &h, const int version)
{
h & portrait & primSkills;
}
};
std::map<ui8, InfoAboutHero> colorToBestHero; //maps player's color to his best heros'
std::map<ui8, si8> personality; // color to personality // -1 - human, AI -> (00 - random, 01 - warrior, 02 - builder, 03 - explorer)
std::map<ui8, si32> bestCreature; // color to ID // id or -1 if not known
template <typename Handler> void serialize(Handler &h, const int version)
{
h & playerColors & numOfTowns & numOfHeroes & gold & woodOre & mercSulfCrystGems & obelisks & artifacts & army & income;
h & colorToBestHero & personality & bestCreature;
}
// template <typename Handler> void serialize(Handler &h, const int version)
// {
// h & playerColors & numOfTowns & numOfHeroes & gold & woodOre & mercSulfCrystGems & obelisks & artifacts & army & income;
// h & colorToBestHero & personality & bestCreature;
// }
};

View File

@@ -573,7 +573,7 @@ struct OpenWindow : public CPackForClient //517
OpenWindow(){type = 517;};
void applyCl(CClient *cl);
enum EWindow {EXCHANGE_WINDOW, RECRUITMENT_FIRST, RECRUITMENT_ALL, SHIPYARD_WINDOW};
enum EWindow {EXCHANGE_WINDOW, RECRUITMENT_FIRST, RECRUITMENT_ALL, SHIPYARD_WINDOW, THIEVES_GUILD};
ui8 window;
ui32 id1, id2;
@@ -1425,19 +1425,6 @@ struct CenterView : public CPackForClient//515
{
h & pos & player & focusTime;
}
};
struct SShowThievesGuildWindow : public CPackForClient //516
{
SShowThievesGuildWindow(){CPackForClient::type = 516;};
void applyCl(CClient *cl);
si32 requestingObject;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & requestingObject;
}
};

View File

@@ -59,6 +59,7 @@ void registerTypes1(Serializer &s)
s.template registerType<CCartographer>();
s.template registerType<CGObjectInstance>();
s.template registerType<COPWBonus>();
s.template registerType<CGDenOfthieves>();
}
template<typename Serializer> DLL_EXPORT
@@ -123,7 +124,6 @@ void registerTypes2(Serializer &s)
s.template registerType<SetSelection>();
s.template registerType<PlayerMessage>();
s.template registerType<CenterView>();
s.template registerType<SShowThievesGuildWindow>();
}
template<typename Serializer> DLL_EXPORT

View File

@@ -762,7 +762,7 @@ void Mapa::loadTown( CGObjectInstance * &nobj, const unsigned char * bufor, int
nt->identifier = 0;
if(version>RoE)
{
readNormalNr(bufor,i); i+=4;
nt->identifier = readNormalNr(bufor,i); i+=4;
}
nt->tempOwner = bufor[i]; ++i;
if(readChar(bufor,i)) //has name

View File

@@ -47,7 +47,7 @@ class DLL_EXPORT CCreGenObjInfo : public CSpecObjInfo
public:
unsigned char player; //owner
bool asCastle;
int identifier;
ui32 identifier;
unsigned char castles[2]; //allowed castles
};
class DLL_EXPORT CCreGen2ObjInfo : public CSpecObjInfo
@@ -55,7 +55,7 @@ class DLL_EXPORT CCreGen2ObjInfo : public CSpecObjInfo
public:
unsigned char player; //owner
bool asCastle;
int identifier;
ui32 identifier;
unsigned char castles[2]; //allowed castles
unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6>
};

View File

@@ -3460,9 +3460,10 @@ void CGameHandler::showGarrisonDialog( int upobj, int hid, bool removableUnits,
void CGameHandler::showThievesGuildWindow(int requestingObjId)
{
SShowThievesGuildWindow sthg;
sthg.requestingObject = requestingObjId;
sendAndApply(&sthg);
OpenWindow ow;
ow.window = OpenWindow::THIEVES_GUILD;
ow.id1 = requestingObjId;
sendAndApply(&ow);
}
bool CGameHandler::isAllowedExchange( int id1, int id2 )
@@ -3638,7 +3639,7 @@ void CGameHandler::checkLossVictory( ui8 player )
setOwner((**i).id,NEUTRAL_PLAYER);
}
//eliminating one player may cause victory of anoother:
//eliminating one player may cause victory of another:
winLoseHandle(ALL_PLAYERS & ~(1<<player));
}